Making JUCE CUDA Compatible? Does JUCE need to change?

I would like to add CUDA to my JUCE projects. The main steps of adding CUDA to an existing project as I understand are:

  • The .cu files are supposed to contain the CUDA kernel code.
  • We are supposed to right click these files in Visual Studio > Properties > General > Item Type > Select Cuda C/C++ from the list.
  • We are supposed to also add the CUDA build steps by right clicking the project (_SharedCode I presume) > Build Dependencies > Build Customizations > Select CUDA from the list.

That is all that is suggested is supposed to be needed to build.

This is based on the explanation here:

https://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html#build-customizations-for-existing-projects

What I understand is then supposed to happen is nvcc (Nvidia compiler) is supposed to compile the .cu CUDA files as a first step, and then the rest of the program builds after that.

Old instructions to add CUDA to existing projects, as best I could research them before I found this more recent guide are here. However, that all seems obsolete though perhaps helpful for understanding what is happening.

I believe all of this centers around needing to have some custom build steps or rules to make nvcc process the .cu files first before the rest of the build proceeds.

I have tried adding some basic CUDA test scripts to a JUCE project. I marked the .cu files as binary in Projucer (correct?). I added the CUDA header folder to the Header Search Paths (C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.6\include).

Then I opened in Visual Studio and made the two fixes above.

However, when I try to build I get:

|Severity|Code|Description|Project|File|Line|Suppression State|Details|
|—|—|—|—|—|—|—|—|
|Error|MSB3721|The command C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.6\bin\nvcc.exe -gencode=arch=compute_52,code=\sm_52,compute_52\ –use-local-env -ccbin C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\bin\HostX64\x64 -x cu -I…..\JuceLibraryCode -ID:\JUCE\app\modules -IC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.6\include -ID:/JUCE/ASIO/common -IC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.6\include -IC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.6\include -G --keep-dir Synth.C18B78B3\x64\Debug -maxrregcount=0 --machine 64 --compile -cudart static -g -D_CRT_SECURE_NO_WARNINGS -DWIN32 -D_WINDOWS -DDEBUG -D_DEBUG -DJUCER_VS2022_78A503E=1 -DJUCE_APP_VERSION=1.0.0 -DJUCE_APP_VERSION_HEX=0x10000 -DJucePlugin_Build_VST=0 -DJucePlugin_Build_VST3=0 -DJucePlugin_Build_AU=0 -DJucePlugin_Build_AUv3=0 -DJucePlugin_Build_AAX=0 -DJucePlugin_Build_Standalone=1 -DJucePlugin_Build_Unity=0 -DJucePlugin_Build_LV2=0 -DJUCE_SHARED_CODE=1 -D_LIB -Xcompiler /EHsc /W4 /nologo /Od /FS /Zi /MDd /GR -Xcompiler /Fd\x64\Debug\Shared Code\Synth.pdb\ -o D:\JUCE\PROJECTS\Synth-Private\Builds\VisualStudio2022\Synth.C18B78B3\x64\Debug\CudaKernel.cu.obj D:\JUCE\PROJECTS\Synth-Private\Source\CUDA\CudaKernel.cu exited with code 2.|Synth_SharedCode|C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\BuildCustomizations\CUDA 12.6.targets|799|||
|Error|C1189|#error: JUCE requires C++17 or later|Synth_SharedCode|D:\JUCE\app\modules\juce_core\system\juce_CompilerSupport.h|124|||

Any ideas? Thanks

I don’t have any experience with CUDA but if you find you can’t make it work with the Projucer it might be worth considering building your JUCE project using CMake, it looks like there is support for it.
https://cliutils.gitlab.io/modern-cmake/chapters/packages/CUDA.html

1 Like

NVCC should pass on all C++ compilation commands on to the compiler, but you should double check all flags/definitions are correctly passed on too (CMAKE is notorious for messing with this).

I would recommend splitting your .cu and .cpp source files as JUCE is not CUDA kernel compatible.

The other option is to use the CUDA api from C++.