Closed Quuxplusone closed 7 years ago
Attached streamcluster.tar.gz
(21541 bytes, application/x-gzip): Streamcluster application with makefile to reproduce the error + log of the compilation with error
If you want to do it this way, you'll need to explicitly tell clang to compile your top-level .cpp file as CUDA by passing '-x cuda' option.
(In reply to Artem Belevich from comment #1)
> #include of a CUDA file from inside a CPP file is not going to work as clang
> has no idea that the source will have CUDA in it.
>
> If you want to do it this way, you'll need to explicitly tell clang to
> compile your top-level .cpp file as CUDA by passing '-x cuda' option.
Should we add a better error message for this? Maybe something like:
#ifndef __CUDACC__
#error Say something useful.
#endif
I can't think of a good place for such a check. During C++ compilation we do not pre-include any CUDA headers, so we can't put the check there. We could always pre-include a special header with this check during C++ compilation, but I'm not sure whether it's worth it (all C++ compilations will have to carry the overhead, however small, just to catch a rare user error in non-C++ compilation).
We could add device and other key CUDA keywords in C++ mode and issue a warning or error if they are seen. Given that they all start with double-underscore, this should be OK to do. I think.
(In reply to Artem Belevich from comment #3)
> I can't think of a good place for such a check. During C++ compilation we do
> not pre-include any CUDA headers, so we can't put the check there. We could
> always pre-include a special header with this check during C++ compilation,
> but I'm not sure whether it's worth it (all C++ compilations will have to
> carry the overhead, however small, just to catch a rare user error in
> non-C++ compilation).
From the log attached to this bug report, it looks like the errors are
triggered when including: lib/clang/5.0.0/include/cuda_wrappers/new - I was
trying to suggest putting the ifdef checks in those headers.
I'm not sure how the cuda_wrapper/new got included in this case. My attempt to
reproduce the issue fails due to missing <cuda.h>. This is what I'd expect as
C++ compilation does not set up include paths to CUDA headers.
clang++ --cuda-path=/usr/local/cuda-8.0 streamcluster_cuda_cpu.cpp -c
tra@art2:~/tmp/Streamcluster
In file included from streamcluster_cuda_cpu.cpp:16:
./streamcluster_header.cu:29:10: fatal error: 'cuda.h' file not found
#include <cuda.h>
^~~~~~~~
1 error generated.
In any case CUDA sources often rely on the headers nvcc always pre-includes, so
they don't always #include <cuda.h>. E.g. your complete CUDA source may be just
this single line which I would expect to be compilable:
__device__ void foo() {}
That said, I'll add some sanity checks in cuda_wrappers so we at least catch
inclusion of CUDA wrappers during C++ compilation mode.
streamcluster.tar.gz
(21541 bytes, application/x-gzip)