nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 fetchpatch,
6 rocmUpdateScript,
7 pkg-config,
8 cmake,
9 xxd,
10 rocm-device-libs,
11 elfutils,
12 libdrm,
13 numactl,
14 llvm,
15}:
16
17stdenv.mkDerivation (finalAttrs: {
18 pname = "rocm-runtime";
19 version = "7.1.1";
20
21 src = fetchFromGitHub {
22 owner = "ROCm";
23 repo = "ROCR-Runtime";
24 rev = "rocm-${finalAttrs.version}";
25 hash = "sha256-gqe1trGc/Cu1XFA4aYjOzFurUgebLbdTHEJi4iw2+kk=";
26 };
27
28 cmakeBuildType = "RelWithDebInfo";
29 separateDebugInfo = true;
30 __structuredAttrs = true;
31 strictDeps = true;
32
33 nativeBuildInputs = [
34 pkg-config
35 cmake
36 xxd # used by create_hsaco_ascii_file.sh
37 llvm.rocm-toolchain
38 ];
39
40 buildInputs = [
41 llvm.clang-unwrapped
42 llvm.llvm
43 elfutils
44 libdrm
45 numactl
46 ];
47
48 cmakeFlags = [
49 "-DBUILD_SHARED_LIBS=ON"
50 "-DCMAKE_INSTALL_BINDIR=bin"
51 "-DCMAKE_INSTALL_LIBDIR=lib"
52 "-DCMAKE_INSTALL_INCLUDEDIR=include"
53 ];
54
55 patches = [
56 # Vendored upstream PR for fix for segfault when queue allocation fails
57 # https://github.com/ROCm/rocm-systems/pull/2850
58 ./queue-failure.patch
59 (fetchpatch {
60 # [PATCH] rocr: Extend HIP ISA compatibility check
61 sha256 = "sha256-8r2Lb5lBfFaZC3knCxfXGcnkzNv6JxOKyJn2rD5gus4=";
62 url = "https://github.com/GZGavinZhao/rocm-systems/commit/c13cd118fcc8e0bc9ae8de62897542dca7352b71.patch";
63 relative = "projects/rocr-runtime";
64 })
65 (fetchpatch {
66 # [PATCH] kfd_ioctl: fix UB due to 1 << 31
67 url = "https://github.com/ROCm/ROCR-Runtime/commit/41bfc66aef437a5b349f71105fa4b907cc7e17d5.patch";
68 hash = "sha256-A7VhPR3eSsmjq2cTBSjBIz9i//WiNjoXm0EsRKtF+ns=";
69 })
70 # This causes a circular dependency, aqlprofile relies on hsa-runtime64
71 # which is part of rocm-runtime
72 # Worked around by having rocprofiler load aqlprofile directly
73 ./remove-hsa-aqlprofile-dep.patch
74 ];
75
76 postPatch = ''
77 patchShebangs --build \
78 runtime/hsa-runtime/core/runtime/trap_handler/create_trap_handler_header.sh \
79 runtime/hsa-runtime/core/runtime/blit_shaders/create_blit_shader_header.sh \
80 runtime/hsa-runtime/image/blit_src/create_hsaco_ascii_file.sh
81 patchShebangs --host image core runtime
82
83 substituteInPlace CMakeLists.txt \
84 --replace 'hsa/include/hsa' 'include/hsa'
85
86 substituteInPlace runtime/hsa-runtime/image/blit_src/CMakeLists.txt \
87 --replace-fail 'COMMAND clang' "COMMAND ${llvm.rocm-toolchain}/bin/clang"
88
89 export HIP_DEVICE_LIB_PATH="${rocm-device-libs}/amdgcn/bitcode"
90 '';
91
92 passthru.updateScript = rocmUpdateScript {
93 name = finalAttrs.pname;
94 inherit (finalAttrs.src) owner;
95 inherit (finalAttrs.src) repo;
96 };
97
98 meta = {
99 description = "Platform runtime for ROCm";
100 homepage = "https://github.com/ROCm/ROCR-Runtime";
101 license = with lib.licenses; [ ncsa ];
102 maintainers = with lib.maintainers; [ lovesegfault ];
103 teams = [ lib.teams.rocm ];
104 platforms = lib.platforms.linux;
105 };
106})