1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
|
;;; Copyright © 2023 Advanced Micro Devices, Inc.
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
(define-module (amd packages rocm-base)
#:use-module (amd packages rocm-origin)
#:use-module (amd packages logging)
#:use-module (guix gexp)
#:use-module (guix build-system cmake)
#:use-module (guix build-system trivial)
#:use-module (guix download)
#:use-module (guix git-download)
#:use-module (guix packages)
#:use-module (guix utils)
#:use-module (srfi srfi-1)
#:use-module (gnu packages)
#:use-module (gnu packages base)
#:use-module (gnu packages xml)
#:use-module (gnu packages libffi)
#:use-module (gnu packages elf)
#:use-module (gnu packages mpi)
#:use-module (gnu packages pkg-config)
#:use-module (gnu packages gcc)
#:use-module (gnu packages llvm)
#:use-module (gnu packages compression)
#:use-module (gnu packages pretty-print)
#:use-module (gnu packages python)
#:use-module (gnu packages perl)
#:use-module (gnu packages crypto)
#:use-module ((guix licenses)
#:prefix license:)
#:use-module (gnu packages linux)
#:use-module (gnu packages xdisorg)
#:use-module (gnu packages vim))
;; This package is needed only for the clan/llvm ROCm stack. Don't
;; export its symbol publicly as it might conflict with upstream
;; libffi (same package name and version).
(define-public libffi-shared
(package
(inherit libffi)
(arguments
(list
#:phases #~(modify-phases %standard-phases
(add-after 'unpack 'set-CFLAGS
(lambda _
(setenv "CFLAGS" " -fPIC"))))))
(properties `((hidden? . #t) ,@(package-properties libffi)))))
; llvm
(define (make-llvm-rocm version llvm)
(package
(inherit llvm)
(name (string-append (package-name llvm) "-rocm"))
(version version)
(source
(rocm-origin "llvm-project" version))
(inputs (modify-inputs (package-inputs llvm)
(replace "libffi" libffi-shared)))
(properties `((hidden? . #t) ,@(package-properties llvm)))))
;; Latest version of ROCm depends on llvm-18
(define-public llvm-rocm
(make-llvm-rocm rocm-version-latest llvm-18))
; clang runtime
(define-public (make-clang-runtime-rocm llvm-rocm clang-runtime)
(package
(inherit clang-runtime)
(name (string-append (package-name clang-runtime) "-rocm"))
(version (package-version llvm-rocm))
(source
(rocm-origin "llvm-project" version))
(inputs (modify-inputs (package-inputs clang-runtime)
(replace "llvm" llvm-rocm)
(replace "libffi" libffi-shared)
(append libxcrypt)))
(properties `((hidden? . #t) ,@(package-properties clang-runtime)))))
;; Latest version of ROCm depends on llvm-18
(define-public clang-runtime-rocm
(make-clang-runtime-rocm llvm-rocm clang-runtime-18))
; clang
(define (make-clang-rocm llvm-rocm clang-runtime-rocm clang)
(package
(inherit clang)
(name (string-append (package-name clang) "-rocm"))
(version (package-version llvm-rocm))
(source
(package-source clang-runtime-rocm))
(inputs (modify-inputs (package-inputs clang)
(delete "clang-tools-extra")))
(propagated-inputs (modify-inputs (package-propagated-inputs clang)
(replace "llvm" llvm-rocm)
(replace "clang-runtime" clang-runtime-rocm)))
(arguments
(substitute-keyword-arguments (package-arguments clang)
((#:phases phases
'(@ () %standard-phases))
#~(modify-phases #$phases
(replace 'add-tools-extra
(lambda _
(copy-recursively "../clang-tools-extra" "tools/extra")))))))
(properties `((hidden? . #t) ,@(package-properties clang)))))
;; Latest version of ROCm depends on llvm-18
(define-public clang-rocm
(make-clang-rocm llvm-rocm clang-runtime-rocm clang-18))
; lld
(define (make-lld-rocm llvm-rocm lld)
(package
(inherit lld)
(name (string-append (package-name lld) "-rocm"))
(version (package-version llvm-rocm))
(source
(rocm-origin "llvm-project" version))
(inputs (list llvm-rocm))
(properties `((hidden? . #t) ,@(package-properties lld)))))
;; Latest version of ROCm depends on llvm-18
(define-public lld-rocm
(make-lld-rocm llvm-rocm lld-18))
; rocm-device-libs
(define (make-rocm-device-libs clang-rocm)
(package
(name "rocm-device-libs")
(version (package-version clang-rocm))
(source
(rocm-origin (if (version>=? version "6.1.1") "llvm-project" name)
version))
(build-system cmake-build-system)
(arguments
(list
#:build-type "Release"
#:tests? #f
#:phases #~(modify-phases %standard-phases
(add-after 'unpack 'ockl_ocml_irif_inc
(lambda* (#:key outputs #:allow-other-keys)
(chdir #$(if (version>=? version "6.1.1")
"amd/device-libs" "."))
(copy-recursively "irif/inc"
(string-append (assoc-ref outputs
"out")
"/irif/inc"))
(copy-recursively "oclc/inc"
(string-append (assoc-ref outputs
"out")
"/oclc/inc"))
(copy-recursively "ockl/inc"
(string-append (assoc-ref outputs
"out")
"/ockl/inc")))))))
(native-inputs (list clang-rocm))
(synopsis "ROCm Device libraries")
(description
"This repository contains the sources and CMake build system for
a set of AMD specific device-side language runtime libraries.")
(home-page "https://github.com/RadeonOpenCompute/ROCm-Device-Libs.git")
(license license:ncsa)))
(define-public llvm-device-libs
(make-rocm-device-libs clang-rocm))
; roct-thunk-interface
(define (make-roct-thunk version)
(package
(name "roct-thunk-interface")
(version version)
(source
(rocm-origin name version))
(build-system cmake-build-system)
(arguments
(list
#:build-type "Release"
#:tests? #f))
(inputs (list libdrm numactl))
(native-inputs (list `(,gcc "lib") pkg-config))
(synopsis "ROCT Thunk interface")
(description "This repository includes the user-mode API interfaces used
to interact with the ROCk driver.")
(home-page "https://github.com/RadeonOpenCompute/ROCT-Thunk-Interface.git")
(license license:expat)))
(define-public roct-thunk
(make-roct-thunk rocm-version-latest))
; rocprof-register
(define (make-rocprof-register version)
(package
(name "rocprof-register")
(version version)
(source
(rocm-origin "rocprofiler-register" version))
(build-system cmake-build-system)
(arguments
(list
#:configure-flags
;; Don't let CMake download and build these dependencies
#~(list "-DROCPROFILER_REGISTER_BUILD_GLOG=OFF"
"-DROCPROFILER_REGISTER_BUILD_FMT=OFF")))
(inputs (list fmt glog-0.7))
(synopsis "The rocprofiler-register helper library.")
(description
"The rocprofiler-register library is a helper library that coordinates
the modification of the intercept API table(s) of the HSA/HIP/ROCTx runtime libraries by the
ROCprofiler (v2) library. The purpose of this library is to provide a consistent and automated
mechanism of enabling performance analysis in the ROCm runtimes which does not rely on environment
variables or unique methods for each runtime library.")
(home-page "https://github.com/rocm/rocprofiler-register")
(license license:expat)))
;; Only valid for ROCm 6.2.0 and above
(define-public rocprof-register
(make-rocprof-register rocm-version-latest))
; rocr-runtime
(define (make-rocr-runtime roct-thunk rocm-device-libs lld-rocm clang-rocm
rocprof-register)
(package
(name "rocr-runtime")
(version (package-version rocm-device-libs))
(source
(rocm-origin name version))
(build-system cmake-build-system)
(arguments
(list
#:build-type "Release"
#:tests? #f ;No tests.
#:configure-flags #~(list (string-append "-DBITCODE_DIR="
#$(this-package-input
"rocm-device-libs")
"/amdgcn/bitcode/"))
#:phases #~(modify-phases %standard-phases
(add-after 'unpack 'chdir
(lambda _
(chdir "src"))))))
(inputs (append (list numactl libdrm libffi roct-thunk rocm-device-libs)
(if (version>=? version "6.2.0")
(list rocprof-register)
'())))
(native-inputs (list xxd libelf lld-rocm clang-rocm pkg-config))
(synopsis "HSA Runtime API and runtime for ROCm")
(description
"This repository includes the user-mode API interfaces and
libraries necessary for host applications to launch compute kernels to
available HSA ROCm kernel agents. Reference source code for the
core runtime is also available.")
(home-page "https://github.com/RadeonOpenCompute/ROCR-Runtime.git")
(license license:ncsa)))
;; rocprof-register only required for ROCm 6.2.0 and above
(define-public rocr-runtime
(make-rocr-runtime roct-thunk llvm-device-libs lld-rocm clang-rocm
rocprof-register))
; lld-wrapper
(define-public lld-wrapper-rocm
(make-lld-wrapper lld-rocm))
; libomp
(define (make-libomp-rocm llvm-rocm
clang-rocm
lld-rocm
rocm-device-libs
rocr-runtime
roct-thunk
libomp)
(package
(inherit libomp)
(name (string-append (package-name libomp) "-rocm"))
(version (package-version llvm-rocm))
(source
(rocm-origin "llvm-project" version))
(native-inputs (append (list `("gcc:lib" ,gcc "lib"))
(modify-inputs (package-native-inputs libomp)
(replace "clang" clang-rocm)
(replace "llvm" llvm-rocm)
(replace "python" python-wrapper)
(append lld-rocm)
(append elfutils))))
(inputs (modify-inputs (package-inputs libomp)
(append libdrm) ;required for rocm-5.7 onwards
(append numactl) ;required for rocm-5.7 onwards
(append roct-thunk) ;required for rocm-5.7 onwards
(append libffi-shared)
(append rocm-device-libs)
(append rocr-runtime)))
(arguments
(substitute-keyword-arguments (package-arguments libomp)
((#:configure-flags flags)
#~(append (list "-DOPENMP_ENABLE_LIBOMPTARGET=1"
"-DCMAKE_C_COMPILER=clang"
"-DCMAKE_CXX_COMPILER=clang++"
"-DCMAKE_BUILD_TYPE=Release" ;strictly speaking unnecesary as debug will be stripped
"-DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld" ;can be removed if we use lld-as-ld-wrapper
"-DCMAKE_SHARED_LINKER_FLAGS=-fuse-ld=lld" ;can be removed if we use lld-as-ld-wrapper
"-DLIBOMPTARGET_AMDGCN_GFXLIST=gfx906;gfx908;gfx90a;gfx940;gfx1030;gfx1100"
(string-append "-DDEVICELIBS_ROOT="
#$(this-package-input "rocm-device-libs"))
(string-append "-DLLVM_DIR="
#$(this-package-native-input "llvm")))
#$flags))
((#:phases phases
'(@ () %standard-phases))
#~(modify-phases #$phases
(add-after 'set-paths 'adjust-LD_LIBRARY_PATH
(lambda* (#:key inputs #:allow-other-keys)
(setenv "LD_LIBRARY_PATH"
(string-append (assoc-ref inputs "llvm") "/lib" ":"
(assoc-ref inputs "gcc:lib") "/lib"))))
(add-after 'unpack 'patch-clang-tools
(lambda _
;; FIXME: Create a patch exposing a configuration option (e.g. -DCLANG_DIR=<...>)
;; to use instead of this substitution
(substitute* (append '("openmp/libomptarget/CMakeLists.txt"
"openmp/libomptarget/DeviceRTL/CMakeLists.txt")
(if #$(version>=? "6.1.2" version)
'("openmp/libomptarget/deviceRTLs/amdgcn/CMakeLists.txt")
'()))
(("find_program\\(CLANG_TOOL clang PATHS \\$\\{LLVM_TOOLS_BINARY_DIR\\}")
(string-append "find_program(CLANG_TOOL clang PATHS "
#$clang-rocm "/bin"))
(("find_program\\(CLANG_OFFLOAD_BUNDLER_TOOL clang-offload-bundler PATHS \\$\\{LLVM_TOOLS_BINARY_DIR\\}")
(string-append
"find_program(CLANG_OFFLOAD_BUNDLER_TOOL clang-offload-bundler PATHS "
#$clang-rocm "/bin"))
(("find_program\\(PACKAGER_TOOL clang-offload-packager PATHS \\$\\{LLVM_TOOLS_BINARY_DIR\\}")
(string-append
"find_program(PACKAGER_TOOL clang-offload-packager PATHS "
#$clang-rocm "/bin")))))))))
(properties `((hidden? . #t) ,@(package-properties libomp)))))
;; Latest version of ROCm depends on llvm-18
(define-public libomp-rocm
(make-libomp-rocm llvm-rocm
clang-rocm
lld-wrapper-rocm
llvm-device-libs
rocr-runtime
roct-thunk
libomp-18))
; rocm-toolchain
(define (make-rocm-toolchain clang-rocm
libomp-rocm
lld-wrapper-rocm
rocr-runtime
rocm-device-libs
roct-thunk)
(let ((rocm-clang-toolchain (make-clang-toolchain clang-rocm libomp-rocm)))
(package
(inherit rocm-clang-toolchain)
(name "rocm-toolchain")
(version (package-version rocm-clang-toolchain))
(inputs (modify-inputs (package-inputs rocm-clang-toolchain)
(append lld-wrapper-rocm rocr-runtime rocm-device-libs
roct-thunk)))
(properties (alist-delete 'hidden?
(package-properties rocm-clang-toolchain)))
(synopsis
"Complete ROCm toolchain, based on the Clang toolchain, for C/C++ development")
(description
"This package provides a complete ROCm toolchain for C/C++
development to be installed in user profiles. This includes Clang, as well as
libc (headers and binaries, plus debugging symbols in the @code{debug}
output), Binutils, the ROCm device libraries, and the ROCr runtime."))))
(define-public rocm-toolchain
(make-rocm-toolchain clang-rocm
libomp-rocm
lld-wrapper-rocm
rocr-runtime
llvm-device-libs
roct-thunk))
; hipify
(define (make-hipify clang-rocm)
(package
(name "hipify")
(version (package-version clang-rocm))
(source
(rocm-origin name version))
(build-system cmake-build-system)
(arguments
(list
#:build-type "Release"
#:tests? #f ;No tests.
#:configure-flags #~(list "-DCMAKE_C_COMPILER=clang"
"-DCMAKE_CXX_COMPILER=clang++"
(if (string=? #$(package-version this-package)
"5.5.1") "-DSWDEV_375013=ON" ""))
#:phases #~(modify-phases %standard-phases
(add-before 'configure 'prepare-cmake
(lambda _
(substitute* "CMakeLists.txt"
(("set.CMAKE_CXX_COMPILER.*")
"")
(("set.CMAKE_C_COMPILER.*")
"")
(("--disable-new-dtags")
;; Required for 5.6.1 but does not seem to
;; affect other versions.
"--enable-new-dtags")))))))
(inputs (list clang-rocm perl))
(synopsis "HIPIFY: Convert CUDA to HIP code.")
(description
"HIPIFY is a set of tools that you can use to automatically translate
CUDA source code into portable HIP C++.")
(home-page "https://github.com/ROCm/HIPIFY")
(license license:ncsa)))
(define-public hipify
(make-hipify clang-rocm))
|