-
Notifications
You must be signed in to change notification settings - Fork 7
/
cuda.scm
290 lines (266 loc) · 11.9 KB
/
cuda.scm
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
;;; Copyright © 2018, 2019, 2020 Inria
;;; Copyright © 2021, 2022 Ricardo Wurmus <ricardo.wurmus@mdc-berlin.de>
;;;
;;; This program 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.
;;;
;;; This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
(define-module (guix-science-nonfree packages cuda)
#:use-module (guix)
#:use-module (guix gexp)
#:use-module (guix build-system gnu)
#:use-module (guix build-system trivial)
#:use-module ((guix licenses) #:prefix license:)
#:use-module ((guix-science-nonfree licenses) #:prefix nonfree:)
#:use-module (gnu packages base)
#:use-module (gnu packages bootstrap)
#:use-module (gnu packages elf)
#:use-module (gnu packages gcc)
#:use-module (gnu packages perl)
#:use-module (gnu packages python))
(define (make-cuda version origin)
(package
(name "cuda-toolkit")
(version version)
(source origin)
(supported-systems '("x86_64-linux"))
(build-system gnu-build-system)
(outputs '("out"
"doc")) ;196 MiB
(arguments
(list
#:modules '((guix build utils)
(guix build gnu-build-system)
(ice-9 match))
;; Let's not publish or obtain substitutes for that.
#:substitutable? #f
#:strip-binaries? #f ;no need
;; XXX: This would check DT_RUNPATH, but patchelf populate DT_RPATH,
;; not DT_RUNPATH.
#:validate-runpath? #f
#:phases
#~(modify-phases %standard-phases
(replace 'unpack
(lambda* (#:key inputs #:allow-other-keys)
(let ((source (assoc-ref inputs "source")))
(invoke "sh" source "--keep" "--noexec")
(chdir "pkg/run_files")
(match (find-files "." "^cuda-linux64-rel.*\\.run$")
((run)
(invoke "sh" run "--keep" "--noexec")))
(chdir "pkg"))))
(delete 'configure)
(delete 'check)
(replace 'build
(lambda* (#:key inputs #:allow-other-keys)
(define libc
(assoc-ref inputs "libc"))
(define gcc-lib
(assoc-ref inputs "gcc:lib"))
(define ld.so
(search-input-file inputs #$(glibc-dynamic-linker)))
(define rpath
(string-join (list "$ORIGIN"
(string-append #$output "/lib")
(string-append #$output "/nvvm/lib64")
(string-append libc "/lib")
(string-append gcc-lib "/lib"))
":"))
(define (patch-elf file)
(make-file-writable file)
(unless (string-contains file ".so")
(format #t "Setting interpreter on '~a'...~%" file)
(invoke "patchelf" "--set-interpreter" ld.so
file))
(format #t "Setting RPATH on '~a'...~%" file)
(invoke "patchelf" "--set-rpath" rpath
"--force-rpath" file))
(for-each (lambda (file)
(when (elf-file? file)
(patch-elf file)))
(find-files "."
(lambda (file stat)
(eq? 'regular
(stat:type stat)))))))
(replace 'install
(lambda _
(let ((lib (string-append #$output "/lib"))
(lib64 (string-append #$output "/lib64")))
(mkdir-p #$output)
(setenv "PERL5LIB" (getcwd)) ;for InstallUtils.pm
(invoke "perl" "install-linux.pl"
(string-append "--prefix=" #$output))
(rename-file lib64 lib))))
(add-after 'install 'move-documentation
(lambda* (#:key outputs #:allow-other-keys)
(let* ((out (assoc-ref outputs "out"))
(doc (assoc-ref outputs "doc"))
(docdir (string-append doc "/share/doc/cuda")))
(mkdir-p (dirname docdir))
(rename-file (string-append out "/doc") docdir)))))))
(native-inputs
(list patchelf perl python-2))
(inputs
`(("gcc:lib" ,gcc-8 "lib")))
(home-page "https://developer.nvidia.com/cuda-toolkit")
(synopsis
"Compiler for the CUDA language and associated run-time support")
(description
"This package provides the CUDA compiler and the CUDA run-time support
libraries for NVIDIA GPUs, all of which are proprietary.")
(license (nonfree:nonfree "https://developer.nvidia.com/nvidia-cuda-license"))))
(define-syntax-rule (cuda-source url hash)
;; Visit
;; <https://developer.nvidia.com/cuda-10.2-download-archive?target_os=Linux&target_arch=x86_64&target_distro=Fedora&target_version=29&target_type=runfilelocal> or similar to get the actual URL.
(origin
(uri url)
(sha256 (base32 hash))
(method url-fetch)))
(define-public cuda-8.0
(make-cuda "8.0.61"
(cuda-source
"https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda_8.0.61_375.26_linux-run"
"1i4xrsqbad283qffvysn88w2pmxzxbbby41lw0j1113z771akv4w")))
(define-public cuda-11.0
(package
(inherit cuda-8.0)
(version "11.0.3")
(source
(cuda-source
"https://developer.download.nvidia.com/compute/cuda/11.0.3/local_installers/cuda_11.0.3_450.51.06_linux.run"
"1h4c69nfrgm09jzv8xjnjcvpq8n4gnlii17v3wzqry5d13jc8ydh"))
(outputs '("out")) ;XXX: no documentation for now
(arguments
(substitute-keyword-arguments (package-arguments cuda-8.0)
((#:modules modules)
'((guix build utils)
(guix build gnu-build-system)
(ice-9 match)
(ice-9 ftw))) ;for 'scandir'
((#:phases phases)
#~(modify-phases #$phases
(replace 'unpack
(lambda* (#:key inputs #:allow-other-keys)
(define ld.so
(search-input-file inputs #$(glibc-dynamic-linker)))
(let ((source (assoc-ref inputs "source")))
(invoke "sh" source "--keep" "--noexec")
(chdir "pkg"))))
(add-after 'unpack 'remove-superfluous-stuff
(lambda _
;; Remove things we have no use for.
(with-directory-excursion "builds"
(for-each delete-file-recursively
'("nsight_compute" "nsight_systems" "cuda_gdb")))))
(replace 'install
(lambda _
(define (copy-from-directory directory)
(for-each (lambda (entry)
(define sub-directory
(string-append directory "/" entry))
(define target
(string-append #$output "/" (basename entry)))
(when (file-exists? sub-directory)
(copy-recursively sub-directory target)))
'("bin" "targets/x86_64-linux/lib"
"targets/x86_64-linux/include"
"nvvm/bin" "nvvm/include"
"nvvm/lib64")))
(setenv "COLUMNS" "200") ;wide backtraces!
(with-directory-excursion "builds"
(for-each copy-from-directory
(scandir "." (match-lambda
((or "." "..") #f)
(_ #t))))
;; 'cicc' needs that directory.
(copy-recursively "cuda_nvcc/nvvm/libdevice"
(string-append #$output "/nvvm/libdevice")))))
;; XXX: No documentation for now.
(delete 'move-documentation)))))
(native-inputs
(modify-inputs (package-native-inputs cuda-8.0)
(prepend which)))))
(define-public cuda-11.7
(package
(inherit cuda-11.0)
(version "11.7.0")
(source
(cuda-source
"https://developer.download.nvidia.com/compute/cuda/11.7.1/local_installers/cuda_11.7.1_515.65.01_linux.run"
"1nq47szb31fk1a4glsba8dy2h58vr8z7w3pbzv8bfjb5f0lnla2j"))
(inputs
`(("gcc:lib" ,gcc-10 "lib")))))
(define-public cuda-10.2
(package
(inherit cuda-11.0)
(version "10.2.89")
(source
(cuda-source
"https://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda_10.2.89_440.33.01_linux.run"
"04fasl9sjkb1jvchvqgaqxprnprcz7a8r52249zp2ijarzyhf3an"))
(arguments
(substitute-keyword-arguments (package-arguments cuda-11.0)
((#:phases phases)
#~(modify-phases #$phases
;; This phase doesn't work as is for 10.2.
(delete 'remove-superfluous-stuff)
(add-after 'install 'really-install-libdevice
(lambda _
;; XXX: The 'install' phase of CUDA 11.0 looks for libdevice
;; in a location that's different from that of libdevice in
;; CUDA 10. Copy it from the right place here.
;; 'cicc' needs that directory.
(copy-recursively "builds/cuda-toolkit/nvvm/libdevice/"
(string-append #$output "/nvvm/libdevice"))))))))))
(define-public cuda
;; Default version.
;;
;; Note: Pick a version that matches the actual "driver"--i.e.,
;; /usr/lib64/libcuda.so available on the target machine.
cuda-11.7)
(define-public no-float128
;; FIXME: We cannot simply add it to 'propagated-inputs' of cuda-toolkit
;; because then it would come after glibc in CPLUS_INCLUDE_PATH.
(package
(name "no-float128")
(version "0")
(source #f)
(build-system trivial-build-system)
(arguments
(list
#:modules '((guix build utils))
#:builder
#~(begin
(use-modules (guix build utils))
(let* ((header "/include/bits/floatn.h")
(target (string-append #$output (dirname header)))
(libc #$(this-package-input "libc")))
(mkdir-p target)
(install-file (string-append libc header) target)
(substitute* (string-append target "/" (basename header))
(("#([[:blank:]]*)define __HAVE_FLOAT128[[:blank:]]+1"
_ space)
(string-append "#" space
"define __HAVE_FLOAT128 0")))))))
(inputs `(("libc" ,glibc)))
(home-page "https://hpc.guix.info")
(synopsis "@file{<bits/floatn.h>} header that disables float128 support")
(description
"This package provides a @file{<bits/floatn.h>} header to override that
of glibc and disable float128 support. This is required allow the use of
@command{nvcc} with CUDA 8.0 and glibc 2.26+. Otherwise, @command{nvcc} fails like this:
@example
/gnu/store/…-glibc-2.26.105-g0890d5379c/include/bits/floatn.h(61): error: invalid argument to attribute \"__mode__\"
/gnu/store/…-glibc-2.26.105-g0890d5379c/include/bits/floatn.h(73): error: identifier \"__float128\" is undefined
@end example
See also
@url{https://devtalk.nvidia.com/default/topic/1023776/cuda-programming-and-performance/-request-add-nvcc-compatibility-with-glibc-2-26/1}.")
(license license:gpl3+)))