CUDA Development with CLion

CLion from JetBrains provides very good support on CUDA development. This post will mainly talk about how to create a CUDA project in CLion in Windows and how to solve problem when using CUDA 11.2.

Prerequisites

Before creating CUDA project in CLion, please install the following softwares.

  • CUDA Toolkit 11.2 for Windows. Check this link.
  • Visual Studio 2019 Community. Check this link.

After installation, in CLion, make sure your Toolchain’s architecture is amd64.

Create CUDA Project In CLion

When creating new project in CLion, simply select “CUDA Executable” as the template.

Let’s modify the default main.cu and test if CUDA is working.

After build and run, you should see the following output.

Now CUDA is working in CLion project!

Trouble shooting

When having the issue related to vcvars64.bat…

At the beginning, I got the following issue

“Could not set up the environment for Microsoft Visual Studio using ‘C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/HostX64/x64/../../../../../../../VC/Auxiliary/Build/vcvars64.bat’

After some searching, the problem is due to %PATH% is too long. You need to remove the unnecessary paths from %PATH%. Actually, if you see any double quote in %PATH%, please also remove them.

When having the issue “Use of undeclared identifier cudaConfigureCall

I also saw the following issue,

You probably are using CUDA 11. In this version, the version.txt file was removed. Instead, version.json was introduced. To solve this issue, you can simply create a version.txt with following context and copy it to where the CUDA is installed.

After opening the CLion, the problem will be gone.

References