1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 fetchpatch,
6 rocmUpdateScript,
7 pkg-config,
8 cmake,
9 ninja,
10 xxd,
11 rocm-device-libs,
12 elfutils,
13 libdrm,
14 numactl,
15 valgrind,
16 libxml2,
17 rocm-merged-llvm,
18}:
19
20stdenv.mkDerivation (finalAttrs: {
21 pname = "rocm-runtime";
22 version = "6.3.3";
23
24 src = fetchFromGitHub {
25 owner = "ROCm";
26 repo = "ROCR-Runtime";
27 rev = "rocm-${finalAttrs.version}";
28 hash = "sha256-du20+5VNYgwchGO7W7FIVebBqLPtfSBnmPVbPpgEZjo=";
29 };
30
31 env.CFLAGS = "-I${numactl.dev}/include -I${elfutils.dev}/include -w";
32 env.CXXFLAGS = "-I${numactl.dev}/include -I${elfutils.dev}/include -w";
33
34 nativeBuildInputs = [
35 pkg-config
36 cmake
37 ninja
38 xxd
39 rocm-merged-llvm
40 ];
41
42 buildInputs = [
43 elfutils
44 libdrm
45 numactl
46 # without valgrind, additional work for "kCodeCopyAligned11" is done in the installPhase
47 valgrind
48 libxml2
49 ];
50
51 cmakeFlags = [
52 "-DBUILD_SHARED_LIBS=ON"
53 "-DCMAKE_INSTALL_BINDIR=bin"
54 "-DCMAKE_INSTALL_LIBDIR=lib"
55 "-DCMAKE_INSTALL_INCLUDEDIR=include"
56 ];
57
58 patches = [
59 # Patches for UB at runtime https://github.com/ROCm/ROCR-Runtime/issues/272
60 (fetchpatch {
61 # [PATCH] hsa-runtime: set underlying type of hsa_region_info_t and hsa_amd_region_info_t to int
62 url = "https://github.com/ROCm/ROCR-Runtime/commit/39a6a168fa07e289a10f6e20e6ead4e303e99ba0.patch";
63 hash = "sha256-CshJJDvII1nNyNmt+YjwMwfBHUTlrdsxkhwfgBwO+WE=";
64 })
65 (fetchpatch {
66 # [PATCH] rocr: refactor of runtime.cpp based on Coverity
67 url = "https://github.com/ROCm/ROCR-Runtime/commit/441bd9fe6c7bdb5c4c31f71524ed642786bc923e.patch";
68 hash = "sha256-7bQXxGkipzgT2aXRxCuh3Sfmo/zc/IOmA0x1zB+fMb0=";
69 })
70 (fetchpatch {
71 # [PATCH] queues: fix UB due to 1 << 31
72 url = "https://github.com/ROCm/ROCR-Runtime/commit/9b8a0f5dbee1903fa990a7d8accc1c5fbc549636.patch";
73 hash = "sha256-KlZWjfngH8yKly08iwC+Bzpvp/4dkaTpRIKdFYwRI+U=";
74 })
75 (fetchpatch {
76 # [PATCH] topology: fix UB due to 1 << 31
77 url = "https://github.com/ROCm/ROCR-Runtime/commit/d1d00bfee386d263e13c2b64fb6ffd1156deda7c.patch";
78 hash = "sha256-u70WEZaphQ7qTfgQPFATwdKWtHytu7CFH7Pzv1rOM8w=";
79 })
80 (fetchpatch {
81 # [PATCH] kfd_ioctl: fix UB due to 1 << 31
82 url = "https://github.com/ROCm/ROCR-Runtime/commit/41bfc66aef437a5b349f71105fa4b907cc7e17d5.patch";
83 hash = "sha256-A7VhPR3eSsmjq2cTBSjBIz9i//WiNjoXm0EsRKtF+ns=";
84 })
85 ./remove-hsa-aqlprofile-dep.patch
86 ];
87
88 postPatch = ''
89 patchShebangs --build \
90 runtime/hsa-runtime/core/runtime/trap_handler/create_trap_handler_header.sh \
91 runtime/hsa-runtime/core/runtime/blit_shaders/create_blit_shader_header.sh \
92 runtime/hsa-runtime/image/blit_src/create_hsaco_ascii_file.sh
93 patchShebangs --host image core runtime
94
95 substituteInPlace CMakeLists.txt \
96 --replace 'hsa/include/hsa' 'include/hsa'
97
98 export HIP_DEVICE_LIB_PATH="${rocm-device-libs}/amdgcn/bitcode"
99 '';
100
101 passthru.updateScript = rocmUpdateScript {
102 name = finalAttrs.pname;
103 inherit (finalAttrs.src) owner;
104 inherit (finalAttrs.src) repo;
105 };
106
107 meta = with lib; {
108 description = "Platform runtime for ROCm";
109 homepage = "https://github.com/ROCm/ROCR-Runtime";
110 license = with licenses; [ ncsa ];
111 maintainers = with maintainers; [ lovesegfault ];
112 teams = [ teams.rocm ];
113 platforms = platforms.linux;
114 };
115})