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

Hard time wrapping this with Go. #103

Closed
dereklstinson opened this issue May 20, 2019 · 8 comments
Closed

Hard time wrapping this with Go. #103

dereklstinson opened this issue May 20, 2019 · 8 comments

Comments

@dereklstinson
Copy link

I am trying to bind miopen with golang. I made binding for cudnn relatively easily. I set the CGO flags to:

//#cgo LDFLAGS:-L/usr/local/cuda/lib64 -lcudnn -lcuda
//#cgo CFLAGS: -I/usr/local/cuda/include/

and it just works.

I'm having a hard time doing this with miopen. I installed rocm and miopen-hip using the prebuilt packages. I can't seem to find documentation to set up miopen and hip to play nice with C and Cgo. Would anyone be able to help me?

@pfultz2
Copy link
Contributor

pfultz2 commented May 20, 2019

I believe CFLAGS='-I/opt/rocm/include' and LDFLAGS='-L/opt/rocm/lib -lMIOpen -lhip_hcc' would be the equivalent flags.

@dereklstinson
Copy link
Author

I changed my cgo flags to that:

#cgo CFLAGS: -I/opt/rocm/include
#cgo LDFLAGS: -L/opt/rocm/lib -lMIOpen -lhip_hcc

Then I get this error:

"resource": "/opt/rocm/hip/include/hip/hip_runtime_api.h",
"owner": "go",
"severity": 8,
"message": "error: #error (\"Must define exactly one of __HIP_PLATFORM_HCC__ or _HIP_PLATFORM_NVCC__\");",
"source": "go",
"startLineNumber": 312,
"startColumn": 1,
"endLineNumber": 312,
"endColumn": 2

I tried adding -D__HIP_PLATFORM_HCC__ to the CFLAGS.

#cgo CFLAGS: -I/opt/rocm/include -D__HIP_PLATFORM_HCC__
#cgo LDFLAGS: -L/opt/rocm/lib -lMIOpen -lhip_hcc

Then, I get two more errors.

"resource": "/opt/rocm/hip/include/hip/hcc_detail/code_object_bundle.hpp",
"owner": "_generated_diagnostic_collection_name_#0",
"severity": 8,
"message": "cannot open source file "hsa/hsa.h"",
"startLineNumber": 25,
"startColumn": 1,
"endLineNumber": 25,
"endColumn": 21
"resource": "/opt/rocm/include/hip/hcc_detail/code_object_bundle.hpp",
"owner": "go",
"severity": 8,
"message": "fatal error: algorithm: No such file or directory",
"source": "go",
"startLineNumber": 27,
"startColumn": 1,
"endLineNumber": 27,
"endColumn": 2

I don't think adding -D__HIP_PLATFORM_HCC__ was the correct thing to do because hsa/hsa.h is in the /opt/rocm/include directory.

@pfultz2
Copy link
Contributor

pfultz2 commented May 20, 2019

I think you need to install the hsa-rocr-dev package to get the hsa headers.

@dereklstinson
Copy link
Author

It seems I am running into an issue with gcc. I tried making a small c program and built it using both gcc and hipcc. Hipcc worked fine, and gcc didn't (I get the same errors as my previous post). hip_runtime_api.h is supposed to be gcc and c compatable. Is there something I am missing, or is this a bug with hip. I am running ubuntu 18.04 with gcc version 7.4.

@pfultz2
Copy link
Contributor

pfultz2 commented May 21, 2019

Is there something I am missing, or is this a bug with hip.

I think this is possibly bug with HIP as its headers are supposed to work with g++.

@dereklstinson
Copy link
Author

Go has to use gcc not g++. But the good news is that I was able to get something to compile. I created a handle then exited. Changes had to be made to hip_runtime_api.h (which I will not go over here. It also looks like there is a pull request that might fix the stuff I had to change). For miopen, I had to add #include<stdbool.h> to miopen.h.

@daniellowell
Copy link
Contributor

@pfultz2 Do we want to just permanently add in #include<stdbool.h> to miopen.h?

@dereklstinson
Copy link
Author

I made a pull request. for this issue.

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

3 participants