Separating Cuda CU file to many other files and OPENGL compiling issue - c++

i have a huge CU file which contains my project , im trying to separate it into small CU files , but im getting many gl.h errors , i dont know what to do... it's driving me crazy..
1> Compiling CUDA source file core.cu...
1>
1> C:\Users\igal\Desktop\prj trying to devide files\graph>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\bin\nvcc.exe" -gencode=arch=compute_10,code=\"sm_10,compute_10\" --use-local-env --cl-version 2010 -ccbin "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\include" -G0 --keep-dir "Debug" -maxrregcount=0 --machine 32 --compile -D_NEXUS_DEBUG -g -Xcompiler "/EHsc /nologo /Od /Zi /MDd " -o "Debug\core.cu.obj" "C:\Users\igal\Desktop\prj trying to devide files\graph\core.cu"
1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1152): error : this declaration has no storage class or type specifier
1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1152): error : expected a ";"
1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1153): error : this declaration has no storage class or type specifier
1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1153): error : variable "WINGDIAPI" has already been defined
1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1153): error : expected a ";"
and the list goes on..

Since you're on Windows, make sure that you include windows.h before including gl.h, or any other file which may indirectly include gl.h.
As stated on MSDN, this is necessary for OpenGL to work.

Related

Why does VS2019 Pro have compile errors with xutility, xmemory, and atomic when creating a CUDA project via CMake?

I'm trying to create a simple CUDA project via CMake and getting strange compilation errors. I'm following this tutorial.
Originally, I was using Visual Studio 2019 Community, CMake 3.18.3, and CUDA 11.3 and everything worked fine. Then, I updated to Visual Studio 2019 Professional and CMake 3.20.3, and it failed to compile the same exact same source code.
Here's my entire CMakeLists file:
cmake_minimum_required(VERSION 3.18.3)
project(hello_world LANGUAGES CXX CUDA)
add_executable(hello_world_target main.cu)
target_compile_features(hello_world_target PUBLIC cxx_std_11)
set_target_properties(hello_world_target PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
set_target_properties(hello_world_target PROPERTIES CUDA_ARCHITECTURES "52")
Here's my only source file, main.cu:
#include <iostream>
int main(){
std::cout << "Hello, world!" << std::endl;
return 0;
}
When I try to compile, I get the following errors:
1>Compiling CUDA source file ..\main.cu...
1>
1>C:\Users\[username]\Documents\hello_cmake\build>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\bin\nvcc.exe" -gencode=arch=compute_52,code=\"compute_52,compute_52\" -gencode=arch=compute_52,code=\"sm_52,compute_52\" --use-local-env -ccbin "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\bin\HostX64\x64" -x cu -rdc=true -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\include" --keep-dir x64\Debug -maxrregcount=0 --machine 64 --compile -cudart static -std=c++14 -Xcompiler="/EHsc -Zi -Ob0" -g -D_WINDOWS -D"CMAKE_INTDIR=\"Debug\"" -D"CMAKE_INTDIR=\"Debug\"" -D_MBCS -Xcompiler "/EHsc /W1 /nologo /Od /Fdhello_world_target.dir\Debug\vc142.pdb /FS /Zi /RTC1 /MDd /GR" -o hello_world_target.dir\Debug\main.obj "C:\Users\[username]\Documents\hello_cmake\main.cu"
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\xutility(1309): error : expected a "("
1> detected during instantiation of "void std::_Adl_verify_range(const _Iter &, const _Sentinel &) [with _Iter=const char *, _Sentinel=const char *]"
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\xlocale(1990): here
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\xutility(1309): error : expected a "("
1> detected during instantiation of "void std::_Adl_verify_range(const _Iter &, const _Sentinel &) [with _Iter=__wchar_t *, _Sentinel=__wchar_t *]"
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\xlocale(1991): here
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\xutility(1309): error : expected a "("
1> detected during instantiation of "void std::_Adl_verify_range(const _Iter &, const _Sentinel &) [with _Iter=const __wchar_t *, _Sentinel=const __wchar_t *]"
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\xlocale(2026): here
.....etc., etc., etc.....
31 errors detected in the compilation of "C:/Users/[username]/Documents/hello_cmake/main.cu".
1>main.cu
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\BuildCustomizations\CUDA 11.3.targets(785,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\bin\nvcc.exe" -gencode=arch=compute_52,code=\"compute_52,compute_52\" -gencode=arch=compute_52,code=\"sm_52,compute_52\" --use-local-env -ccbin "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\bin\HostX64\x64" -x cu -rdc=true -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\include" --keep-dir x64\Debug -maxrregcount=0 --machine 64 --compile -cudart static -std=c++14 -Xcompiler="/EHsc -Zi -Ob0" -g -D_WINDOWS -D"CMAKE_INTDIR=\"Debug\"" -D"CMAKE_INTDIR=\"Debug\"" -D_MBCS -Xcompiler "/EHsc /W1 /nologo /Od /Fdhello_world_target.dir\Debug\vc142.pdb /FS /Zi /RTC1 /MDd /GR" -o hello_world_target.dir\Debug\main.obj "C:\Users\[username]\Documents\hello_cmake\main.cu"" exited with code 1.
1>Done building project "hello_world_target.vcxproj" -- FAILED.
What's perplexing is that this worked fine with the different versions of Visual Studio and CMake. Also, if I rewrite the CMakeLists.txt file to remove CUDA from the LANGUAGES list, and change main.cu to main.cpp, everything works fine.
It's also confusing that the compiler would complain about the xutility, xmemory, and atomic files. That sounds like a red herring, though.
What could be causing this issue?
UPDATE 10/20/2021: For me, VS2019 16.11.5 works fine with CUDA 11.4.120 and CMake 3.21.3, no modifications needed.
I ran into basically the same problem after upgrading from Visual Studio 2019 16.9.6 to 16.10.
The problem seems to be caused by changes in xutility, xmemory etc. in the version of the MSVC v142 build tools 14.29.30037 delivered with Visual Studio 2019 16.10.
I could not solve the problem for the new version of the build tools, but I found a workaround. It is possible to install the v142 build tools from VS2019 16.9 with VS2019 16.10:
In VS the installer, "Visual Studio 2019->Modify->Individual components" add
MSVC v142 - VS2019 C++ x64/x86 build tools (14.28-16.9)
C++ v14.28 (16.9) ATL for v142 build tools (x86 & x64)
optionally: MFC, commandline tools, etc.
To compile the CUDA CMake project the MSVC toolset version needs to be set explicitly. This can be done by entering
version=14.28.29910
in "Optional toolset to use (argument to -T) in the CMake GUI (CMake cache needs to be deleted).
Nothing wrong with the program and with the MSVC compiler and libs. You can use the latest release (now 16.10.1)
cmake generated this (chaotic) compiler command in the vs 2019 IDE:
"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\bin\nvcc.exe" -gencode=arch=compute_75,code="compute_75,compute_75" -gencode=arch=compute_75,code="sm_75,compute_75" --use-local-env -ccbin "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30037\bin\HostX64\x64" -x cu -rdc=true -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\include" --keep-dir x64\Release -maxrregcount=0 --machine 64 --compile -cudart static -std=c++14 -Xcompiler="/EHsc -Ob2" -D_WINDOWS -DNDEBUG -D"CMAKE_INTDIR="Release"" -D_MBCS -D"CMAKE_INTDIR="Release"" -Xcompiler "/EHsc /W1 /nologo /O2 /Fdhello_world_target.dir\Release\vc142.pdb /FS /MD /GR" -o hello_world_target.dir\Release\main.obj "D:\projects\test\main.cu"
remove additional option: -std=c++14 in this command and it works
Why:
With cuda 11.3 and MSVC 19.29.++ MSVC arranges itself the setting for the host compiler icw NVCC, so using this option gives problems.
It must be edited in the CMAKE release. Module compiler(NVIDIA-CUDA.cmake) I think. I'm not an expert on that, but you can see there a lot of hocus-pocus around this option.
Also Windows Visual Studio does not support specifying CUDAHOSTCXX or CMAKE_CUDA_HOST_COMPILER env settings and gives problems like this.
I used cmake version 3.20.3 and win-build 3.20.20210609-g5e26887 to test.

cl.exe installed but not found

I've looked at the other questions on this, all say install visual studio with c++, I have done this - 2017 version.
I'm trying to build pypoisson in python3 which requires the c++ complier, I get this error:
cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\garyn\PycharmProjects\pointcloudprocessor\venv\lib\site-packages\numpy\core\include -IC:\Users\garyn\PycharmProjects\pointcloudprocessor\venv\include "-IC:\Pr
ogram Files\Python\Python37\include" "-IC:\Program Files\Python\Python37\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\ATLMFC\include" "-IC:\Program Files (x8
6)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\ucrt"
"-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\winrt" "-IC
:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\cppwinrt" /EHsc /Tpsrc\pypoisson.cpp /Fobuild\temp.win-amd64-3.7\Release\src\pypoisson.obj -w -fopenmp
error: command 'cl.exe' failed: No such file or directory
I looked in my system variables and in path there is a route to cl.exe
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\bin\Hostx64\x64\cl.exe
and
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\bin
My system is 64-bit OS and x64-based processor
Searching windows for cl.exe returns 8 possibilities all under the directory: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\bin some in Hostx64 and Hostx86
Any ideas? I've been stuck on this for months.
# EDIT
On running:pip install git+https://github.com/mmolero/pypoisson.git
Collecting git+https://github.com/mmolero/pypoisson.git
Cloning https://github.com/mmolero/pypoisson.git to c:\users\garyn\appdata\local\temp\pip-req-build-mp9rv8zh
Installing collected packages: pypoisson
Running setup.py install for pypoisson ... error
Complete output from command C:\Users\garyn\PycharmProjects\pointcloudprocessor\venv\Scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\garyn\\AppData\\Local\\Temp\\pip-req-build-mp9rv
8zh\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\garyn\AppData\Local\Temp\pip-record-z9a0hu
hl\install-record.txt --single-version-externally-managed --compile --install-headers C:\Users\garyn\PycharmProjects\pointcloudprocessor\venv\include\site\python3.7\pypoisson:
running install
running build
running build_ext
cythoning src/pypoisson.pyx to src\pypoisson.cpp
C:\Users\garyn\PycharmProjects\pointcloudprocessor\venv\lib\site-packages\Cython\Compiler\Main.py:367: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a la
ter release! File: C:\Users\garyn\AppData\Local\Temp\pip-req-build-mp9rv8zh\src\pypoisson.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
warning: src\pypoisson.pyx:130:67: Index should be typed for more efficient access
building 'pypoisson' extension
creating build
creating build\temp.win-amd64-3.7
creating build\temp.win-amd64-3.7\Release
creating build\temp.win-amd64-3.7\Release\src
creating build\temp.win-amd64-3.7\Release\src\PoissonRecon_v6_13
creating build\temp.win-amd64-3.7\Release\src\PoissonRecon_v6_13\src
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\garyn\PycharmProjects\pointcloudprocessor\venv\lib
\site-packages\numpy\core\include -IC:\Users\garyn\PycharmProjects\pointcloudprocessor\venv\include "-IC:\Program Files\Python\Python37\include" "-IC:\Program Files\Python\Python37\include" "-IC:\Program Files (x
86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\include" "-IC:\Program Files (x86)\W
indows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared" "-IC:\Program Files (x86)\Windows
Kits\10\include\10.0.17134.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\cppwinrt" /EHsc /Tpsrc\pypoisson.cpp /Fobuild
\temp.win-amd64-3.7\Release\src\pypoisson.obj -w -fopenmp
cl : Command line warning D9025 : overriding '/W3' with '/w'
cl : Command line warning D9002 : ignoring unknown option '-fopenmp'
pypoisson.cpp
c:\users\garyn\pycharmprojects\pointcloudprocessor\venv\lib\site-packages\numpy\core\include\numpy\npy_1_7_deprecated_api.h(14) : Warning Msg: Using deprecated NumPy API, disable it with #define NPY_NO_DEPREC
ATED_API NPY_1_7_API_VERSION
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\garyn\PycharmProjects\pointcloudprocessor\venv\lib
\site-packages\numpy\core\include -IC:\Users\garyn\PycharmProjects\pointcloudprocessor\venv\include "-IC:\Program Files\Python\Python37\include" "-IC:\Program Files\Python\Python37\include" "-IC:\Program Files (x
86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\include" "-IC:\Program Files (x86)\W
indows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared" "-IC:\Program Files (x86)\Windows
Kits\10\include\10.0.17134.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\cppwinrt" /EHsc /Tpsrc/PoissonRecon_v6_13/src
/CmdLineParser.cpp /Fobuild\temp.win-amd64-3.7\Release\src/PoissonRecon_v6_13/src/CmdLineParser.obj -w -fopenmp
cl : Command line warning D9025 : overriding '/W3' with '/w'
cl : Command line warning D9002 : ignoring unknown option '-fopenmp'
CmdLineParser.cpp
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\garyn\PycharmProjects\pointcloudprocessor\venv\lib
\site-packages\numpy\core\include -IC:\Users\garyn\PycharmProjects\pointcloudprocessor\venv\include "-IC:\Program Files\Python\Python37\include" "-IC:\Program Files\Python\Python37\include" "-IC:\Program Files (x
86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\include" "-IC:\Program Files (x86)\W
indows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared" "-IC:\Program Files (x86)\Windows
Kits\10\include\10.0.17134.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\cppwinrt" /EHsc /Tpsrc/PoissonRecon_v6_13/src
/Factor.cpp /Fobuild\temp.win-amd64-3.7\Release\src/PoissonRecon_v6_13/src/Factor.obj -w -fopenmp
cl : Command line warning D9025 : overriding '/W3' with '/w'
cl : Command line warning D9002 : ignoring unknown option '-fopenmp'
Factor.cpp
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\garyn\PycharmProjects\pointcloudprocessor\venv\lib
\site-packages\numpy\core\include -IC:\Users\garyn\PycharmProjects\pointcloudprocessor\venv\include "-IC:\Program Files\Python\Python37\include" "-IC:\Program Files\Python\Python37\include" "-IC:\Program Files (x
86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\include" "-IC:\Program Files (x86)\W
indows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared" "-IC:\Program Files (x86)\Windows
Kits\10\include\10.0.17134.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\cppwinrt" /EHsc /Tpsrc/PoissonRecon_v6_13/src
/Geometry.cpp /Fobuild\temp.win-amd64-3.7\Release\src/PoissonRecon_v6_13/src/Geometry.obj -w -fopenmp
cl : Command line warning D9025 : overriding '/W3' with '/w'
cl : Command line warning D9002 : ignoring unknown option '-fopenmp'
Geometry.cpp
c:\users\garyn\appdata\local\temp\pip-req-build-mp9rv8zh\src\poissonrecon_v6_13\src\Geometry.h(33): fatal error C1189: #error: OpenMP is required
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.15.26726\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2

Facing problem in installing mysqlclient in python

I am a beginner in python. I am doing my college project in django-python. I want to use MySQL (phpMyAdmin). I am facing problem in installing mysqlclient.
The error is given below...
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.15.26726\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(1,3,12,'final',0) -D__version__=1.3.12 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include" -Ic:\users\bhuvan_02\appdata\local\programs\python\python37\include -Ic:\users\bhuvan_02\appdata\local\programs\python\python37\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.15.26726\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\cppwinrt" /Tc_mysql.c /Fobuild\temp.win-amd64-3.7\Release_mysql.obj /Zl
_mysql.c
_mysql.c(29): fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory
error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.15.26726\bin\HostX86\x64\cl.exe' failed with exit status 2
Any type of help is appreciated...
Install older version, latest version 1.3.13 is having problems.
pip install mysqlclient==1.3.12

Different errors when trying to link cuRAND on Windows

I have a DLL that contains my CUDA code and recent added a pair .cuh/.cu with cuRAND code to be part of the DLL.
Because there are a lot of linking problems regarding cuRAND, first I wrote a minimalist piece of code just to see if the thing links.
For the sake of completion, the .cuh and .cu are, respectively:
extern "C"
{
void simple_curand_test(void);
}
And
#include "GPU_Rand.cuh"
#include <curand.h>
#include <curand_kernel.h>
void simple_curand_test(void)
{
curandGenerator_t gen;
curandCreateGenerator(&gen, CURAND_RNG_PSEUDO_DEFAULT);
}
Then, my compiler command to generate the DLL is:
nvcc -o bin\GPU_Methods.dll --shared src\GPU_Utils.cu src\GPU_Rand.cu -L"c:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\lib\x64" -lcurand
It ends with this error:
Creating library bin/GPU_Methods.lib and object bin/GPU_Methods.exp
tmpxft_000015a0_00000000-44_GPU_Rand.obj : error LNK2019: unresolved external symbol curandCreateGenerator referenced in function simple_curand_test
bin/SCS_GPU.dll : fatal error LNK1120: 1 unresolved externals
If I change the command to make the linker use the variable LIBRARIES, it looks like:
set LIBRARIES="c:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\lib\x64"
nvcc -o bin\GPU_Methods.dll --shared src\GPU_Utils.cu src\GPU_Rand.cu -lcurand
Then the error turns to:
nvlink fatal : Could not open input file 'c:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\lib\x64'
After spending some days reading and trying multiple combinations of parameters and commands, it is time to ask if you guys can spot what I am missing.
UPDATE - 01/06/2018
These are the environment variables in a command prompt that runs nvcc (some of them were omitted because they are not relevant to the issue and to avoid bloating your screen even more):
ALLUSERSPROFILE=C:\ProgramData
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1
CUDA_PATH_V9_1=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
NVCUDASAMPLES9_1_ROOT=C:\ProgramData\NVIDIA Corporation\CUDA Samples\v9.1
NVCUDASAMPLES_ROOT=C:\ProgramData\NVIDIA Corporation\CUDA Samples\v9.1
NVTOOLSEXT_PATH=C:\Program Files\NVIDIA Corporation\NvToolsExt\
OS=Windows_NT
Path=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\libnvvp;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Windows Live\Shared;C:\MiKTeX 2.9\miktex\bin\x64\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Programming\MSYS2\mingw64\bin;C:\Programming\Java\jdk1.8.0_162\bin;C:\Programming\Python365;C:\Programming\Python365\Lib;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\bin\Hostx64\x64
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=AMD64
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 94 Stepping 3, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=5e03
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files
PROMPT=$P$G
PSModulePath=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
PUBLIC=C:\Users\Public
PYTHONPATH=C:\Programming\Python365;C:\Programming\Python365\Lib
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\Windows
VS120COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\
windir=C:\Windows
The way I managed to link cuRAND and generate the dll was using Visual Studio instead of the command line. Somehow it has the proper arguments for nvcc to link cuRAND that, I suspect, my environment variables are missing.
Thanks to Robert Crovella for also giving it a try and providing input.

How to make CUDA 8 work on Visual Studio 2015 update 3 with CMake?

I am having trouble even to compile the simplest code for CUDA 8 and Visual Studio 2015 update 3.
CUDASample.cuh
class CUDASample {
public:
CUDASample();
~CUDASample();
};
CUDASample.cu
#include "CUDASample.cuh"
CUDASample::CUDASample() {
}
CUDASample::~CUDASample(){
}
I am getting compilation errors like
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(63): error : unknown attribute "guard"
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(64): error : unknown attribute "guard"
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(76): error : unknown attribute "guard"
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(98): error : unknown attribute "guard"
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(118): error : unknown attribute "guard"
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(125): error : unknown attribute "guard"
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(126): error : unknown attribute "guard"
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(137): error : unknown attribute "guard"
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(144): error : unknown attribute "guard"
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(161): error : unknown attribute "guard"
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(170): error : unknown attribute "guard"
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(171): error : unknown attribute "guard"
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(180): error : unknown attribute "guard"
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(188): error : unknown attribute "guard"
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(189): error : unknown attribute "guard"
I am pretty sure it's a CUDA problem because if I change the source file extension to "cpp" and header extension to "h" everything works as usual. How can I solve this?
EDIT:
The commandline shown in properties -> Linker -> Command Line is
/OUT:"C:\Users\David\Desktop\sample\build\bin\Release\cudasample.dll" /MANIFEST /NXCOMPAT /PDB:"C:/Users/David/Desktop/sample/build/bin/Release/cudasample.pdb" /DYNAMICBASE "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "comdlg32.lib" "advapi32.lib" "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64\cudart_static.lib" /IMPLIB:"C:/Users/David/Desktop/sample/build/lib/Release/cudasample.lib" /DLL /MACHINE:X64 /INCREMENTAL:NO /PGD:"C:\Users\David\Desktop\sample\build\bin\Release\cudasample.pgd" /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"cudasample.dir\Release\cudasample.dll.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /TLBID:1
EDIT:
As Robert mentioned, since I am able to compile the cuda samples successfully, the problem might be related to cmake configuration. Below is the CMakeLists I used which work for me when compiling on Visual Studio 2013 + CUDA 7.5.
project(cudasample)
set(PROJECT_SRCS
${PROJECT_SOURCE_DIR}/src/CUDASample.cu
)
set(PROJECT_INCS
${PROJECT_SOURCE_DIR}/include/CUDASample.cuh
)
include_directories(${PROJECT_SOURCE_DIR}/include)
find_package( CUDA REQUIRED )
list(APPEND CUDA_NVCC_FLAGS "-gencode arch=compute_52,code=sm_52;")
list(APPEND CUDA_NVCC_FLAGS "-gencode arch=compute_50,code=sm_50;")
list(APPEND CUDA_NVCC_FLAGS "-gencode arch=compute_35,code=sm_35;")
list(APPEND CUDA_NVCC_FLAGS "-gencode arch=compute_30,code=sm_30;")
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
set(CUDA_PROPAGATE_HOST_FLAGS OFF)
list(APPEND CUDA_NVCC_FLAGS "-std=c++11;")
endif()
cuda_add_library(${PROJECT_NAME} SHARED ${PROJECT_SRCS} ${PROJECT_INCS})
What could be wrong?
I at least managed to get it to work. The root cause is the sdl compiler flag in my head CMakeLists.txt
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /sdl")
So if I add in this line in the project CMakeLists.txt
string(REGEX REPLACE "/sdl" "/sdl-" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
it will compile sucessfully.
However it is still unclear to me why the sdl compiler flag will cause NVCC to fail in the combination of CUDA 8 and Visual Studio 2015 Update 3. Hopefully someone can come up with a better answer.