question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use CuPy's headers in a CUDA file?

See original GitHub issue

I must have missed something trivial. I want to use CuPy’s Thrust headers to do some tests, but I am unable to compile even a simple file like this:

//file: do_nothing.cu
#include <cupy/complex.cuh>

__device__ float xxx (const float x) {
    return x+1;
}

Compile it with nvcc -Icupy/core/include -c do_nothing.cu in the root of CuPy source to generate an object file, I got the following errors:

cupy/core/include/cupy/complex/arithmetic.h:258:78: error: ‘float thrust::abs(const thrust::complex<float>&)’ is not declared in ‘thrust’
 __device__ inline float abs(const complex<float>& z) {
                                                                              ^
cupy/core/include/cupy/complex/arithmetic.h:262:80: error: ‘double thrust::abs(const thrust::complex<double>&)’ is not declared in ‘thrust’
 __device__ inline double abs(const complex<double>& z) {
                                                                                ^
cupy/core/include/cupy/complex/cexp.h:169:91: error: ‘thrust::complex<double> thrust::exp(const thrust::complex<double>&)’ is not declared in ‘thrust’
 __device__ inline complex<double> exp(const complex<double>& z) {
                                                                                           ^
cupy/core/include/cupy/complex/cexpf.h:149:89: error: ‘thrust::complex<float> thrust::exp(const thrust::complex<float>&)’ is not declared in ‘thrust’
 __device__ inline complex<float> exp(const complex<float>& z) {
                                                                                         ^
cupy/core/include/cupy/complex/clog.h:192:91: error: ‘thrust::complex<double> thrust::log(const thrust::complex<double>&)’ is not declared in ‘thrust’
 __device__ inline complex<double> log(const complex<double>& z) {
                                                                                           ^
cupy/core/include/cupy/complex/clogf.h:188:89: error: ‘thrust::complex<float> thrust::log(const thrust::complex<float>&)’ is not declared in ‘thrust’
 __device__ inline complex<float> log(const complex<float>& z) {
                                                                                         ^
cupy/core/include/cupy/complex/ccosh.h:195:2: error: ‘thrust::complex<double> thrust::cos(const thrust::complex<double>&)’ is not declared in ‘thrust’
     const thrust::complex<double>& z) {
  ^
cupy/core/include/cupy/complex/ccosh.h:201:2: error: ‘thrust::complex<double> thrust::cosh(const thrust::complex<double>&)’ is not declared in ‘thrust’
     const thrust::complex<double>& z) {
  ^
cupy/core/include/cupy/complex/ccoshf.h:126:89: error: ‘thrust::complex<float> thrust::cos(const thrust::complex<float>&)’ is not declared in ‘thrust’
 __device__ inline complex<float> cos(const complex<float>& z) {
                                                                                         ^
cupy/core/include/cupy/complex/ccoshf.h:131:90: error: ‘thrust::complex<float> thrust::cosh(const thrust::complex<float>&)’ is not declared in ‘thrust’
 __device__ inline complex<float> cosh(const complex<float>& z) {
                                                                                          ^
cupy/core/include/cupy/complex/csinh.h:183:91: error: ‘thrust::complex<double> thrust::sin(const thrust::complex<double>&)’ is not declared in ‘thrust’
 __device__ inline complex<double> sin(const complex<double>& z) {
                                                                                           ^
cupy/core/include/cupy/complex/csinh.h:188:92: error: ‘thrust::complex<double> thrust::sinh(const thrust::complex<double>&)’ is not declared in ‘thrust’
 __device__ inline complex<double> sinh(const complex<double>& z) {
                                                                                            ^
cupy/core/include/cupy/complex/csinhf.h:124:89: error: ‘thrust::complex<float> thrust::sin(const thrust::complex<float>&)’ is not declared in ‘thrust’
 __device__ inline complex<float> sin(const complex<float>& z) {
                                                                                         ^
cupy/core/include/cupy/complex/csinhf.h:129:90: error: ‘thrust::complex<float> thrust::sinh(const thrust::complex<float>&)’ is not declared in ‘thrust’
 __device__ inline complex<float> sinh(const complex<float>& z) {
                                                                                          ^
cupy/core/include/cupy/complex/ctanh.h:182:91: error: ‘thrust::complex<double> thrust::tan(const thrust::complex<double>&)’ is not declared in ‘thrust’
 __device__ inline complex<double> tan(const complex<double>& z) {
                                                                                           ^
cupy/core/include/cupy/complex/ctanhf.h:107:89: error: ‘thrust::complex<float> thrust::tan(const thrust::complex<float>&)’ is not declared in ‘thrust’
 __device__ inline complex<float> tan(const complex<float>& z) {
                                                                                         ^
cupy/core/include/cupy/complex/csqrt.h:140:92: error: ‘thrust::complex<double> thrust::sqrt(const thrust::complex<double>&)’ is not declared in ‘thrust’
 __device__ inline complex<double> sqrt(const complex<double>& z) {
                                                                                            ^
cupy/core/include/cupy/complex/csqrtf.h:137:90: error: ‘thrust::complex<float> thrust::sqrt(const thrust::complex<float>&)’ is not declared in ‘thrust’
 __device__ inline complex<float> sqrt(const complex<float>& z) {
                                                                                          ^
cupy/core/include/cupy/complex/catrig.h:697:92: error: ‘thrust::complex<double> thrust::acos(const thrust::complex<double>&)’ is not declared in ‘thrust’
 __device__ inline complex<double> acos(const complex<double>& z) {
                                                                                            ^
cupy/core/include/cupy/complex/catrig.h:702:92: error: ‘thrust::complex<double> thrust::asin(const thrust::complex<double>&)’ is not declared in ‘thrust’
 __device__ inline complex<double> asin(const complex<double>& z) {
                                                                                            ^
cupy/core/include/cupy/complex/catrig.h:708:92: error: ‘thrust::complex<double> thrust::atan(const thrust::complex<double>&)’ is not declared in ‘thrust’
 __device__ inline complex<double> atan(const complex<double>& z) {
                                                                                            ^
cupy/core/include/cupy/complex/catrig.h:725:93: error: ‘thrust::complex<double> thrust::atanh(const thrust::complex<double>&)’ is not declared in ‘thrust’
 __device__ inline complex<double> atanh(const complex<double>& z) {
                                                                                             ^
cupy/core/include/cupy/complex/catrigf.h:411:90: error: ‘thrust::complex<float> thrust::acos(const thrust::complex<float>&)’ is not declared in ‘thrust’
 __device__ inline complex<float> acos(const complex<float>& z) {
                                                                                          ^
cupy/core/include/cupy/complex/catrigf.h:416:90: error: ‘thrust::complex<float> thrust::asin(const thrust::complex<float>&)’ is not declared in ‘thrust’
 __device__ inline complex<float> asin(const complex<float>& z) {
                                                                                          ^
cupy/core/include/cupy/complex/catrigf.h:422:90: error: ‘thrust::complex<float> thrust::atan(const thrust::complex<float>&)’ is not declared in ‘thrust’
 __device__ inline complex<float> atan(const complex<float>& z) {
                                                                                          ^
cupy/core/include/cupy/complex/catrigf.h:439:91: error: ‘thrust::complex<float> thrust::atanh(const thrust::complex<float>&)’ is not declared in ‘thrust’
 __device__ inline complex<float> atanh(const complex<float>& z) {
                                                                                           ^

Any hint or comment is appreciated.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
rkevkcommented, Jul 11, 2020

I had this same compiler issue yesterday while trying to compile the latest CuPy master branch on a RHEL 7 machine. RHEL 7’s EOL is 2024, i.e. there’s probably still a good number of people using it, but its default gcc version is 4.8.5, which won’t compile CuPy successfully.

I think it’d be good if you mentioned this on the installation doc page, so people are aware of the issue? If it helps, here’s what I used to point pip and nvcc to the latest dev version gcc binaries on that particular machine:

PATH=/opt/rh/devtoolset-8/root/usr/bin:$PATH NVCC="nvcc --compiler-bindir /opt/rh/devtoolset-8/root/usr/bin/" python3 -m pip --no-cache-dir install . --user -vvvv
1reaction
leofangcommented, Jul 11, 2020

@MrArsGravis Yes, I think this is planned: #3530. In this sense, CUDA’s installation guide for Linux is inaccurate. It mentioned gcc 4.8.5 is supported on several distros until CUDA 11.0, which now has a footnote to address this issue:

(2) Note that starting with CUDA 11.0, the minimum recommended GCC compiler is at least GCC 5 due to C++11 requirements in CUDA libraries e.g. cuFFT and CUB. On distributions such as RHEL 7 or CentOS 7 that may use an older GCC toolchain by default, it is recommended to use a newer GCC toolchain with CUDA 11.0. Newer GCC toolchains are available with the Red Hat Developer Toolset.

But this C++11 incompatibility already happened long before CUDA 11…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Headers in CUDA C - NVIDIA Developer Forums
Hello, Suppose I want to write somewhat larger kernels in CUDA C… do I still need to use header files to split up...
Read more >
Compiling a CUDA file, C file, and Cuda header file
Use nvcc -c to compile all CUDA-files and gcc -c to compile C-files. After that simply link them by gcc. I recommend you...
Read more >
Building CUDA Code - CERN Indico
By convention CUDA code is put into the following types of files. • *.cuh: Header files that require CUDA in “some way”.
Read more >
D94337 Add cuda header type for cuh files - LLVM
This adds a cuda header type with file extension "cuh". The output type file extension is "cuhi" - not sure if this is...
Read more >
CUDA Crash Course (v2): Visual Studio 2019 Setup - YouTube
In this video we look at the basic setup for CUDA development with VIsual Studio 2019!
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found