You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to link a CUDA library to my project, but I encounter errors due to the presence of CUDA device functions (e.g., __umul64hi) in some of the library's header files. When using GCC for compilation, these functions are not recognized, leading to errors.
As I am not very familiar with Bazel and rules_cuda, I couldn't find a way to instruct Bazel to use nvcc for compiling these headers. I am unsure if I have misunderstood the cause of the errors.
Here is a minimal example that reproduces the issue:
INFO: Analyzed target //src:main (0 packages loaded, 0 targets configured).
ERROR: /home/user/project/bazel-cuda-test/src/BUILD.bazel:1:10: Compiling src/main.cc failed: (Exit 1):
gcc failed: error executing CppCompile command (from target //src:main) /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++14' -MD -MF ... (remaining 32 arguments skipped)
Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
In file included from src/main.cc:2:
third_party/cuda_example/include/cuda_example.cuh: In function'uint64_t multiply_high_uint64(uint64_t, uint64_t)':third_party/cuda_example/include/cuda_example.cuh:10:12: error: '__umul64hi' was not declared in this scope; did you mean 'test_umul64hi'? 10 | return __umul64hi(operand1, operand2); | ^~~~~~~~~~ | test_umul64hithird_party/cuda_example/include/cuda_example.cuh: In function 'void test_umul64hi_kernel(uint64_t*, uint64_t*, uint64_t*, int)':third_party/cuda_example/include/cuda_example.cuh:14:15: error: 'blockIdx' was not declared in this scope 14 | int idx = blockIdx.x * blockDim.x + threadIdx.x; | ^~~~~~~~third_party/cuda_example/include/cuda_example.cuh:14:28: error: 'blockDim' was not declared in this scope 14 | int idx = blockIdx.x * blockDim.x + threadIdx.x; | ^~~~~~~~third_party/cuda_example/include/cuda_example.cuh:14:41: error: 'threadIdx' was not declared in this scope 14 | int idx = blockIdx.x * blockDim.x + threadIdx.x; | ^~~~~~~~~Target //src:main failed to buildUse --verbose_failures to see the command lines of failed build steps.INFO: Elapsed time: 0.661s, Critical Path: 0.48sINFO: 3 processes: 3 internal.ERROR: Build did NOT complete successfully
I have found that the header files are not being compiled with nvcc, which seems to be the root cause of the errors. One direct but inefficient solution would be to add #ifdef __CUDACC__ to each header file, but my library contains a large number of such headers, making manual modifications impractical.
Could you please provide guidance on how to resolve this issue? Is there a way to ensure that .cuh files are processed by nvcc when using Bazel? Or is it possible that this error is not caused by this issue?
Thank you for your help!
The text was updated successfully, but these errors were encountered:
Hello, @cloudhan .
Thank you for your contributions to
rules_cuda
.I am trying to link a CUDA library to my project, but I encounter errors due to the presence of CUDA device functions (e.g.,
__umul64hi
) in some of the library's header files. When using GCC for compilation, these functions are not recognized, leading to errors.As I am not very familiar with Bazel and
rules_cuda
, I couldn't find a way to instruct Bazel to use nvcc for compiling these headers. I am unsure if I have misunderstood the cause of the errors.Here is a minimal example that reproduces the issue:
main.cc:
BUILD file for main:
cuda_example.cuh:
BUILD file for cuda_example:
When I run the build command:
I encounter the following errors:
I have found that the header files are not being compiled with nvcc, which seems to be the root cause of the errors. One direct but inefficient solution would be to add
#ifdef __CUDACC__
to each header file, but my library contains a large number of such headers, making manual modifications impractical.Could you please provide guidance on how to resolve this issue? Is there a way to ensure that
.cuh
files are processed by nvcc when using Bazel? Or is it possible that this error is not caused by this issue?Thank you for your help!
The text was updated successfully, but these errors were encountered: