gorgonia / cu

package cu provides an idiomatic interface to the CUDA Driver API.
Apache License 2.0
475 stars 64 forks source link

Build failure with cuda toolkit 12.0 #66

Closed Infinoid closed 5 months ago

Infinoid commented 1 year ago

I am trying to build the cudatest program on Debian Trixie (testing) as the documentation suggests. It fails to build the cgo part due to missing symbols.

versions

logs

% go version
go version go1.21.0 linux/amd64

% go install gorgonia.org/cu/cmd/cudatest
go: 'go install' requires a version when current directory is not in a module
    Try 'go install gorgonia.org/cu/cmd/cudatest@latest' to install the latest version

% go install gorgonia.org/cu/cmd/cudatest@latest
# gorgonia.org/cu
go/pkg/mod/gorgonia.org/cu@v0.9.4/jit.go:138:32: could not determine kind of name for C.CU_TARGET_COMPUTE_20
go/pkg/mod/gorgonia.org/cu@v0.9.4/jit.go:139:32: could not determine kind of name for C.CU_TARGET_COMPUTE_21

% dpkg -l nvidia-driver-bin nvidia-cuda-toolkit golang-go
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                Version           Architecture Description
+++-===================-=================-============-=======================================>
ii  golang-go:amd64     2:1.21~2          amd64        Go programming language compiler, linke>
ii  nvidia-cuda-toolkit 12.0.140~12.0.1-2 amd64        NVIDIA CUDA development toolkit
ii  nvidia-driver-bin   525.125.06-2      amd64        NVIDIA driver support binaries

% nvidia-smi                                    
Mon Sep 11 19:24:49 2023       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 525.125.06   Driver Version: 525.125.06   CUDA Version: 12.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  On   | 00000000:43:00.0  On |                  N/A |
| 47%   48C    P0    97W / 350W |   1441MiB / 12288MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

to reproduce without breaking everything

Note: alias docker=podman if that's what you have; either one should work. And you don't need an actual GPU to build it.

Also note: nvidia libs are kinda big. Make sure you have ~10GB of disk space available for this.

% docker run -it --rm debian:trixie bash
# perl -pi -e 's/main/main contrib non-free/' /etc/apt/sources.list.d/debian.sources
# apt update
# apt install nvidia-cuda-toolkit golang-go
# go install gorgonia.org/cu/cmd/cudatest@latest
Infinoid commented 1 year ago

I checked out the repo, commented out the relevant lines of jit.go, and tried to build it. I got a lot of warnings, and a new build error:

The build failure was:

# gorgonia.org/cu
./params.go:41:2: too few values in struct literal of type _Ctype_struct_CUDA_KERNEL_NODE_PARAMS_v2_st

The warnings can be summarized as follows:

neurlang commented 6 months ago

works with these changes:

diff --git a/jit.go b/jit.go
index 72df1b8..fa85ec2 100644
--- a/jit.go
diff --git a/jit.go b/jit.go
index 72df1b8..fa85ec2 100644
--- a/jit.go
+++ b/jit.go
@@ -135,8 +135,8 @@ const (
        // JITTarget11 JITTargetOption = C.CU_TARGET_COMPUTE_11
        // JITTarget12 JITTargetOption = C.CU_TARGET_COMPUTE_12
        // JITTarget13 JITTargetOption = C.CU_TARGET_COMPUTE_13
-       JITTarget20 JITTargetOption = C.CU_TARGET_COMPUTE_20
-       JITTarget21 JITTargetOption = C.CU_TARGET_COMPUTE_21
+       // JITTarget20 JITTargetOption = C.CU_TARGET_COMPUTE_20
+       // JITTarget21 JITTargetOption = C.CU_TARGET_COMPUTE_21
        JITTarget30 JITTargetOption = C.CU_TARGET_COMPUTE_30
        JITTarget32 JITTargetOption = C.CU_TARGET_COMPUTE_32
        JITTarget35 JITTargetOption = C.CU_TARGET_COMPUTE_35
diff --git a/params.go b/params.go
index 0938730..f91b5cc 100644
--- a/params.go
+++ b/params.go
@@ -38,6 +35,8 @@ func (p *KernelNodeParams) c() *C.CUDA_KERNEL_NODE_PARAMS {
                C.uint(p.SharedMemBytes),
                nil,
                nil,
+               nil,
+               nil,
        }
        return retVal
 }
neurlang commented 6 months ago

you can add:

require gorgonia.org/cu v0.9.5-0.20240520013750-498bd6b70d43

to your go.mod, cuda 12 should work

Infinoid commented 5 months ago

Thanks for the fix. I am now able to follow the documented instructions, and install cudatest on Debian Trixie (go 1.22.3, gcc 13.2.0, cuda 12.2).