Search code examples
cwindowsgocudacgo

trying to use cuda with go on windows


There are various Go libraries that rely on the cuda.h file and the cuda library (specifically ML libraries). Every time I try to install one of these libraries on Windows, I get an error saying

 fatal error: cuda.h: No such file or directory
 //#include <cuda.h>

I am aware of what I need to do (link the Cuda library/header files to the go library that I am trying to install), however, I am not sure how to go about doing this especially on windows. I am using GCC and not MSVC for various reasons, but even when I've tried using MSVC, I've had the same issues.

Is there some way that I can link the cuda compiler/header files directly to my Go env or do I need to manually point the go/cgo compiler to the directory holding the Cuda headers and how do I go about doing this?

I've tried asking a few of the developers who make these libraries for help but most of them are linux users so they don't really know. An exhaustive google search has really lead me nowhere so I'm asking here.


Solution

  • I was able to find the answer.

    The windows cuda installer installs things by default into a weird path:

    C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include
    

    This path caused a lot of pain for the compiler as a result of the spaces in the folder names. After reinstalling Cuda into C:\CUDA\v8.0 and then appending my CFLAGS and LDFLAGS appropriately in my CGO file I was able to get things to run correctly.

    For reference here are the CFLAGS and LDFLAGS that I used to get this to work:

    //#cgo windows LDFLAGS:-LC:/cuda/v8.0/lib/x64
    //#cgo windows CFLAGS: -IC:/cuda/v8.0/include
    import "C"
    

    This was with the github.com/chewxy/cu go library. I also appended the new flags into that library in the cgoflags.go file because the maintainer did not have version 8 or version 9 in there already. I mentioned this to him and he might update it later but for now that's what you have to do.