nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 rocmUpdateScript,
6 symlinkJoin,
7 cmake,
8 clang,
9 clr,
10 aqlprofile,
11 rocm-core,
12 rocm-runtime,
13 rocm-device-libs,
14 roctracer,
15 rocdbgapi,
16 numactl,
17 libpciaccess,
18 libxml2,
19 llvm,
20 elfutils,
21 mpi,
22 gtest,
23 python3Packages,
24 gpuTargets ? clr.gpuTargets,
25}:
26
27let
28 rocmtoolkit-merged = symlinkJoin {
29 name = "rocmtoolkit-merged";
30
31 paths = [
32 rocm-core
33 rocm-runtime
34 rocm-device-libs
35 roctracer
36 rocdbgapi
37 clr
38 ];
39
40 postBuild = ''
41 rm -rf $out/nix-support
42 '';
43 };
44in
45stdenv.mkDerivation (finalAttrs: {
46 pname = "rocprofiler";
47 version = "7.1.1";
48
49 src = fetchFromGitHub {
50 owner = "ROCm";
51 repo = "rocprofiler";
52 rev = "rocm-${finalAttrs.version}";
53 hash = "sha256-V+E+6D/mBW/NVdHSBVUVMG5Z/QOF73vfZ5rryW2VBtI=";
54 fetchSubmodules = true;
55 };
56
57 nativeBuildInputs = [
58 cmake
59 clang
60 clr
61 python3Packages.lxml
62 python3Packages.cppheaderparser
63 python3Packages.pyyaml
64 python3Packages.barectf
65 python3Packages.pandas
66 ];
67
68 buildInputs = [
69 llvm.clang-unwrapped
70 llvm.llvm
71 numactl
72 libpciaccess
73 libxml2
74 elfutils
75 mpi
76 gtest
77 aqlprofile
78 ];
79
80 propagatedBuildInputs = [ rocmtoolkit-merged ];
81
82 #HACK: rocprofiler's cmake doesn't add these deps properly
83 env.CXXFLAGS = "-I${libpciaccess}/include -I${numactl.dev}/include -I${rocmtoolkit-merged}/include -I${elfutils.dev}/include -w";
84
85 cmakeFlags = [
86 "-DCMAKE_MODULE_PATH=${clr}/lib/cmake/hip"
87 "-DHIP_ROOT_DIR=${clr}"
88 "-DGPU_TARGETS=${lib.concatStringsSep ";" gpuTargets}"
89 # Manually define CMAKE_INSTALL_<DIR>
90 # See: https://github.com/NixOS/nixpkgs/pull/197838
91 "-DCMAKE_INSTALL_BINDIR=bin"
92 "-DCMAKE_INSTALL_LIBDIR=lib"
93 "-DCMAKE_INSTALL_INCLUDEDIR=include"
94 ];
95
96 postPatch = ''
97 patchShebangs .
98
99 substituteInPlace cmake_modules/rocprofiler_utils.cmake \
100 --replace-fail 'function(ROCPROFILER_CHECKOUT_GIT_SUBMODULE)' 'function(ROCPROFILER_CHECKOUT_GIT_SUBMODULE)
101 return()'
102
103 substituteInPlace CMakeLists.txt \
104 --replace-fail 'set(ROCPROFILER_BUILD_TESTS ON)' ""
105
106 substituteInPlace tests-v2/featuretests/profiler/CMakeLists.txt \
107 --replace "--build-id=sha1" "--build-id=sha1 --rocm-path=${clr} --rocm-device-lib-path=${rocm-device-libs}/amdgcn/bitcode"
108
109 substituteInPlace test/CMakeLists.txt \
110 --replace "\''${ROCM_ROOT_DIR}/amdgcn/bitcode" "${rocm-device-libs}/amdgcn/bitcode"
111 '';
112
113 postInstall = ''
114 # Why do these have the executable bit set?
115 chmod -x $out/libexec/rocprofiler/counters/*.xml
116 # rocprof shell script wants to find it in the same bin dir, easiest to symlink in
117 ln -s ${clr}/bin/rocm_agent_enumerator $out/bin/rocm_agent_enumerator
118 '';
119
120 postFixup = ''
121 patchelf $out/lib/*.so \
122 --add-rpath ${aqlprofile}/lib \
123 --add-needed libhsa-amd-aqlprofile64.so
124 '';
125
126 passthru.updateScript = rocmUpdateScript {
127 name = finalAttrs.pname;
128 inherit (finalAttrs.src) owner;
129 inherit (finalAttrs.src) repo;
130 };
131 passthru.rocmtoolkit-merged = rocmtoolkit-merged;
132
133 meta = {
134 description = "Profiling with perf-counters and derived metrics";
135 homepage = "https://github.com/ROCm/rocprofiler";
136 license = with lib.licenses; [ mit ]; # mitx11
137 teams = [ lib.teams.rocm ];
138 platforms = lib.platforms.linux;
139 };
140})