Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug in cgoflags.go #50

Open
MarkKremer opened this issue Mar 25, 2020 · 2 comments
Open

bug in cgoflags.go #50

MarkKremer opened this issue Mar 25, 2020 · 2 comments

Comments

@MarkKremer
Copy link

Hi people,

I had some difficulty trying to install this library. For one part that was because I didn't see that there is a guide until after I got it working. For the other part is was because cgoflags.go isn't entirely correct.

I got this error:

$ go install -v gorgonia.org/cu/cmd/cudatest
# gorgonia.org/cu
/home/markkremer/go/pkg/mod/gorgonia.org/[email protected]/addressing.go:3:11: fatal error: cuda.h: No such file or directory
 // #include <cuda.h>
           ^~~~~~~~
compilation terminated.

I did have cuda version 10.2 installed and symlinked to /usr/local/cuda/.

The start of cgoflags.go reads:

package cu

// This file provides CGO flags to find CUDA libraries and headers.

//#cgo LDFLAGS:-lcuda
//
////default location:
//#cgo linux,windows LDFLAGS:-L/usr/local/cuda/lib64 -L/usr/local/cuda/lib
//#cgo linux,windows CFLAGS: -I/usr/local/cuda/include/
//
////default location if not properly symlinked:
//#cgo linux LDFLAGS:-L/usr/local/cuda-10.1/lib64 -L/usr/local/cuda-10.1/lib
//#cgo linux LDFLAGS:-L/usr/local/cuda-6.0/lib64 -L/usr/local/cuda-6.0/lib
//#cgo linux LDFLAGS:-L/usr/local/cuda-5.5/lib64 -L/usr/local/cuda-5.5/lib
//#cgo linux LDFLAGS:-L/usr/local/cuda-5.0/lib64 -L/usr/local/cuda-5.0/lib
//#cgo linux CFLAGS: -I/usr/local/cuda-10.2/include/
//#cgo linux CFLAGS: -I/usr/local/cuda-6.0/include/
//#cgo linux CFLAGS: -I/usr/local/cuda-5.5/include/
//#cgo linux CFLAGS: -I/usr/local/cuda-5.0/include/

When running go install -v -n gorgonia.org/cu/cmd/cudatest (with -n) to view the commands go runs, it doesn't use the top two /usr/local/cuda/... at all:

#
# gorgonia.org/cu
#

mkdir -p $WORK/b033/
cd /home/markkremer/go/pkg/mod/gorgonia.org/[email protected]
CGO_LDFLAGS='"-g" "-O2" "-lcuda" "-L/usr/local/cuda-10.1/lib64" "-L/usr/local/cuda-10.1/lib" "-L/usr/local/cuda-6.0/lib64" "-L/usr/local/cuda-6.0/lib" "-L/usr/local/cuda-5.5/lib64" "-L/usr/local/cuda-5.5/lib" "-L/usr/local/cuda-5.0/lib64" "-L/usr/local/cuda-5.0/lib" "-L/usr/lib/x86_64-linux-gnu/" "-L/opt/cuda/lib64" "-L/opt/cuda/lib"' /usr/local/go/pkg/tool/linux_amd64/cgo -objdir $WORK/b033/ -importpath gorgonia.org/cu -- -I $WORK/b033/ -g -O2 -g -O3 -std=c99 -I/usr/local/cuda-10.1/include/ -I/usr/local/cuda-6.0/include/ -I/usr/local/cuda-5.5/include/ -I/usr/local/cuda-5.0/include/ -I/usr/include -I/opt/cuda/include ./addressing.go ./api.go ./array.go ./attributes.go ./batch.go ./batchedPatterns.go ./cgoflags.go ./context.go ./convenience.go ./ctx.go ./ctx_api.go ./cu.go ./cucontext.go ./device.go ./event.go ./execution.go ./flags.go ./jit.go ./memory.go ./module.go ./occupancy.go ./result.go ./stream.go ./surfref.go ./texref.go
cd $WORK

It does use all the other cuda directories. Unfortunately for me, 10.2 isn't in there.

I think the build constraint tags should be separated by spaces instead of commas:

- //#cgo linux,windows LDFLAGS:-L/usr/local/cuda/lib64 -L/usr/local/cuda/lib
+ //#cgo linux windows LDFLAGS:-L/usr/local/cuda/lib64 -L/usr/local/cuda/lib
- //#cgo linux,windows CFLAGS: -I/usr/local/cuda/include/
+ //#cgo linux windows CFLAGS: -I/usr/local/cuda/include/

Now it does show up:

#
# gorgonia.org/cu
#

mkdir -p $WORK/b033/
cd /home/markkremer/go/pkg/mod/gorgonia.org/[email protected]
CGO_LDFLAGS='"-g" "-O2" "-lcuda" "-L/usr/local/cuda/lib64" "-L/usr/local/cuda/lib" "-L/usr/local/cuda-10.2/lib64" "-L/usr/local/cuda-10.2/lib" "-L/usr/local/cuda-6.0/lib64" "-L/usr/local/cuda-6.0/lib" "-L/usr/local/cuda-5.5/lib64" "-L/usr/local/cuda-5.5/lib" "-L/usr/local/cuda-5.0/lib64" "-L/usr/local/cuda-5.0/lib" "-L/usr/lib/x86_64-linux-gnu/" "-L/opt/cuda/lib64" "-L/opt/cuda/lib"' /usr/local/go/pkg/tool/linux_amd64/cgo -objdir $WORK/b033/ -importpath gorgonia.org/cu -- -I $WORK/b033/ -g -O2 -g -O3 -std=c99 -I/usr/local/cuda/include/ -I/usr/local/cuda-10.1/include/ -I/usr/local/cuda-6.0/include/ -I/usr/local/cuda-5.5/include/ -I/usr/local/cuda-5.0/include/ -I/usr/include -I/opt/cuda/include ./addressing.go ./api.go ./array.go ./attributes.go ./batch.go ./batchedPatterns.go ./cgoflags.go ./context.go ./convenience.go ./ctx.go ./ctx_api.go ./cu.go ./cucontext.go ./device.go ./event.go ./execution.go ./flags.go ./jit.go ./memory.go ./module.go ./occupancy.go ./result.go ./stream.go ./surfref.go ./texref.go
cd $WORK

Although that isn't a Windows path so it's best to entirely remove the Windows part for that build constraint:

- //#cgo linux,windows LDFLAGS:-L/usr/local/cuda/lib64 -L/usr/local/cuda/lib
+ //#cgo linux LDFLAGS:-L/usr/local/cuda/lib64 -L/usr/local/cuda/lib
- //#cgo linux,windows CFLAGS: -I/usr/local/cuda/include/
+ //#cgo linux CFLAGS: -I/usr/local/cuda/include/

I still don't have everything working locally but at least it builds now.

@chewxy
Copy link
Member

chewxy commented Mar 25, 2020

Can you try with v0.9.2?

@MarkKremer
Copy link
Author

#
# gorgonia.org/cu
#

gorgonia.org/cu
mkdir -p $WORK/b033/
cd /home/markkremer/go/pkg/mod/gorgonia.org/[email protected]
CGO_LDFLAGS='"-g" "-O2" "-lcuda" "-L/usr/local/cuda-10.1/lib64" "-L/usr/local/cuda-10.1/lib" "-L/usr/local/cuda-6.0/lib64" "-L/usr/local/cuda-6.0/lib" "-L/usr/local/cuda-5.5/lib64" "-L/usr/local/cuda-5.5/lib" "-L/usr/local/cuda-5.0/lib64" "-L/usr/local/cuda-5.0/lib" "-L/usr/lib/x86_64-linux-gnu/" "-L/opt/cuda/lib64" "-L/opt/cuda/lib"' /usr/local/go/pkg/tool/linux_amd64/cgo -objdir $WORK/b033/ -importpath gorgonia.org/cu -- -I $WORK/b033/ -g -O2 -g -O3 -std=c99 -I/usr/local/cuda-10.2/include/ -I/usr/local/cuda-10.1/include/ -I/usr/local/cuda-6.0/include/ -I/usr/local/cuda-5.5/include/ -I/usr/local/cuda-5.0/include/ -I/usr/include -I/opt/cuda/include ./addressing.go ./api.go ./array.go ./attributes.go ./batch.go ./batchedPatterns.go ./cgoflags.go ./context.go ./convenience.go ./ctx.go ./ctx_api.go ./cu.go ./cucontext.go ./device.go ./event.go ./execution.go ./flags.go ./jit.go ./memory.go ./module.go ./occupancy.go ./result.go ./stream.go ./surfref.go ./texref.go
cd $WORK

My version (10.2) is in there now. The default is still not in there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants