I currently have cuda setup with a portion of the code in visual studio c++ files, another portion in *.cu files on host side and some *.cu files on the device side (containing global functions). Now all the *.cu files obviously compile using nvcc, while the cpp files are compiled by visual studio. All is running great but I am curious whetther it would be possible to rename all my *.cu files on host side to cpp and have them compiled by VS; with only the device functions compiled by nvcc.
How would I then call the kernel functions since I cant include a *.cu file in the VS compiler. Is it even possible?
Yes, it is possible to rename and compile the host side code as .cpp files, but you will lose a few things like. For example, the syntactic sugar nvcc deals with, which looks like:
Will have to be replaced with the underlying function calls:
cudaConfigureCall()
cudaSetupArgument()
cudaLaunch()
outlined in the NVIDIA CUDA programming guide (version 0.8.2) as ‘B.4 Execution Control’, or as 4.5.2.4 in version 0.8 of the guide.
I found it helpful to give the -keep option to nvcc, then search through the C intermediate files generated by nvcc for those three functions to see what the nvcc code looks like.
There is also a driver API described in section C.5, and outlined in Section 4.5.3.5, but I haven’t touched this yet.
HTH
PS: I am using Linux, not VC on Windows. I have every reason to believe the VC C++ compiler is used to generate the host-side code, so it should work the same way.
I did a quick grep, and found several examples of ‘include.*cutil.h’ in the .cpp files in the SDK sample projects, and they compile and run okay. Also I took a scan across cutil.h, and I don’t see any nvcc specific extensions like shared, device, etc. in the header. Finally (doh! should have been first), the source in NVIDIA_CUDA_SDK/common/src is all .cpp, so I would expect the functions to be fine.
Edit: There is an SDK example using the driver API, e.g. cuLaunch, in simpleTextureDrv.cpp
This also uses th API to set up a texture, which may be helpful.