CLion 2020.1 EAP: CUDA Support & Clang on Windows

CLion started the 2020.1 EAP program last week with many improvements to Clang-based tooling, the debugger, and the overall editor. This week a new build is available, bringing more sophisticated CUDA support!

You can download the build (201.4865.10) from our website, via the Toolbox App, or as a snap package (for Ubuntu) and install it side by side with the stable release build.

DOWNLOAD CLION 2020.1 EAP

CUDA support

Why CUDA?

Before jumping into a detailed overview of what’s actually supported for CUDA, let me first briefly elaborate on how we have come to this decision. If you are not really interested in this, feel free to skip directly to the next part.

CLion is a general-purpose cross-platform C and C++ IDE. There are plenty of interesting domains where C and C++ are used as the primary language. A number of global industries, like High-frequency trading (HFT), embedded development, and game development, use C and C++, along with other more specific fields like automated vehicle research, AI, telecommunications, and GPGPU. Because of the limited number of developers we have in the team, it’s hard to cover each and every one of these areas right now. (Believe us, we’d love too!) So we have had to make some difficult choices about what to prioritize.

That’s why we recently analyzed the current state of CLion’s support for various C++ development areas. The main criterion we considered was whether users were able to expect their code to be correctly handled by the IDE, at least from the general C++ perspective. And once that was determined, more specific requests would come into play.

With this framework to guide us, in November 2019 we took a look at various areas where CLion was still weak and realized that CUDA was one where we generally failed to meet our criterion. Taking Qt as a point of contrast, CLion can successfully parse and work with a Qt project. Some Qt specifics might not be taken into account in the refactorings, code generation, and other smart actions, but from a C++ language perspective, they are still correct. With CUDA the situation was different. CUDA C and C++ is essentially C/C++ with a few extensions, and the IDE was not handling these extensions correctly. This resulted in red code, false positives, and other unpleasant consequences that you could encounter as soon as you started using CUDA in CLion, making the IDE completely impossible to use.

That’s why we’ve decided to dedicate some time to fixing these issues with CUDA. Of course, more specific support for specific technologies, be they CUDA, Qt, or others, is also on our roadmap for the future. But for now, our goal is to eliminate the most irritating issues.

Start a new project with CUDA

If you are new to CUDA, we recommend starting by downloading the CUDA Toolkit from the official site and checking out the official documentation. To start a new project in CLion, call File | New Project and select CUDA library or CUDA executable:
New CUDA project

The sample CMake and main.cu files will be generated for you:
new CUDA project CMake

You may notice new file extensions for source and header CUDA files – .cu/.cuh. They are also available in the new C/C++ file creation dialog and have their own icons:
CUDA files

For CUDA projects, the list of CMake targets in this dialog includes general CMake and CUDA targets (created with cuda_add_executable/cuda_add_library).

How does CLion support CUDA?

Let’s clone the ClaraGenomicsAnalysis project from GitHub and check out what CLion is capable of in terms of CUDA support. Make sure CMake used in CLion knows where to find the CUDA toolchain. For example, you can set CMAKE_CUDA_COMPILER to the nvcc compiler path.

The first thing you’ll notice is that CUDA code, including all CUDA specific extensions, is now parsed and highlighted correctly:
CUDA prj sample

This means code navigation, code documentation, and other code assistance actions work:
Quick Documentation

Additionally, CLion can complete angle brackets for kernel calls:
CUDA completion

Known issues and limitations

First of all, there are some OS-specific details you’ll need to pay close attention to:

  • On Windows: CUDA only works with the Microsoft Visual C++ toolchain, and you are required to have x64 cl.exe in your PATH. For this toolchain, CLion bundles the LLDB-based debugger developed by JetBrains, which for the moment might have issues with the CUDA code.
  • On Linux: Because of the regression, cuda-gdb can’t be selected in the UI (CPP-18931).
  • On macOS: We didn’t test on this platform, as it’s officially no longer supported after v10.13.

Other notable issues for CUDA code include:

  • Code insight actions (like Go to Declaration, Rename, or Extract Variable) don’t work inside <<<...>>> (CPP-18722).
  • In the alpaka project, CLion fails to collect compiler info, and so red code is present (CPP-18901).
  • For CUDA projects, CLion incorrectly parses the compilation database generated by CMake (CPP-18926).
  • Coverage, cuda-memcheck, Valgrind Memcheck, and Profiling don’t work properly for CUDA projects, for now at least. This is definitely a feature we are considering to address in future updates.

Clang on Windows

While Clang has been available in CLion on Linux and macOS for quite a long time, certain issues and limitations made it too inconvenient to be practical on Windows. We have now made it possible to use clang-cl in CLion on Windows! All versions from 8.0 on are supported.

You can install it from the LLVM site or along with the Visual Studio tools. When done, select the Visual Studio toolchain in CLion and point to clang-cl.exe in the toolchain settings:
Clang-cl

You are now all set up!

Mind you, there is a known issue that causes -T clangcl options not to be picked up by CLion if the bundled CMake is in use while Visual Studio is enabled (CPP-18848).

If you want to find out more, the full release notes are available here.

DOWNLOAD CLION 2020.1 EAP

Your CLion team
JetBrains
The Drive to Develop

This entry was posted in Announcement, Early Access Preview and tagged , , , , . Bookmark the permalink.

21 Responses to CLion 2020.1 EAP: CUDA Support & Clang on Windows

  1. Ricardo Maltez says:

    Hi!
    First of all thank you for keeping improving the Clion!
    I would like to request to take the time to look into this issue:
    https://youtrack.jetbrains.com/issue/CPP-5102

    In the codebase that I work on all the functions are “noexcept” so when I try to override any function using the amazing auto override feature of Clion I have to correct the function declaration and implementation to include the “noexcept” keyword.

    This would really improve my daily work and probably the work of other developers :)

  2. Fernando Rodriguez says:

    Try using clag-cl.exe and when loading CMAKE you get the error: — broken

    • Fernando Rodriguez says:

      CMake Error at C:/Program Files/JetBrains/CLion 201.4515.29/bin/cmake/win/share/cmake-3.16/Modules/CMakeTestCXXCompiler.cmake:53 (message):
      The C++ compiler

      “C:/Program Files/LLVM/bin/clang-cl.exe”

      is not able to compile a simple test program.

      It fails with the following output:

      Change Dir: C:/git/AGENT/cmake-build-clang/CMakeFiles/CMakeTmp

      Run Build Command(s):C:/jom_1_1_2/jom.exe /nologo cmTC_59ce6\fast && jom: parallel job execution disabled for Makefile
      C:\jom_1_1_2\jom.exe -f CMakeFiles\cmTC_59ce6.dir\build.make /nologo -L CMakeFiles\cmTC_59ce6.dir\build
      Building CXX object CMakeFiles/cmTC_59ce6.dir/testCXXCompiler.cxx.obj
      C:\PROGRA~1\LLVM\bin\clang-cl.exe @C:\Users\DIEGO~1.ROD\AppData\Local\Temp\testCXXCompiler.cxx.obj.23876.0.jom
      Linking CXX executable cmTC_59ce6.exe
      “C:\Program Files\JetBrains\CLion 201.4515.29\bin\cmake\win\bin\cmake.exe” -E vs_link_exe –intdir=CMakeFiles\cmTC_59ce6.dir –rc=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x64\rc.exe –mt=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x64\mt.exe –manifests — C:\PROGRA~2\MICROS~4\2019\ENTERP~1\VC\Tools\Llvm\bin\lld-link.exe /nologo @CMakeFiles\cmTC_59ce6.dir\objects1.rsp @C:\Users\DIEGO~1.ROD\AppData\Local\Temp\cmTC_59ce6.exe.23876.125.jom
      LINK Pass 1: command “C:\PROGRA~2\MICROS~4\2019\ENTERP~1\VC\Tools\Llvm\bin\lld-link.exe /nologo @CMakeFiles\cmTC_59ce6.dir\objects1.rsp /out:cmTC_59ce6.exe /implib:cmTC_59ce6.lib /pdb:C:\git\AGENT\cmake-build-clang\CMakeFiles\CMakeTmp\cmTC_59ce6.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\cmTC_59ce6.dir/intermediate.manifest CMakeFiles\cmTC_59ce6.dir/manifest.res” failed (exit code 1) with the following output:
      lld-link: error: : undefined symbol: mainCRTStartup
      jom: C:\git\AGENT\cmake-build-clang\CMakeFiles\CMakeTmp\CMakeFiles\cmTC_59ce6.dir\build.make [cmTC_59ce6.exe] Error 2
      jom: C:\git\AGENT\cmake-build-clang\CMakeFiles\CMakeTmp\Makefile [cmTC_59ce6\fast] Error 2

      CMake will not be able to correctly generate this project.
      Call Stack (most recent call first):

      • Anastasia Kazakova says:

        We’ll check the error and will be back to you soon

      • Ivan says:

        Do you have the same bitness for your installed clang-cl and your Visual studio toolchain? If they match then please report a bug. You can also try to use another CMake generator like ninja for example.

  3. Helge Penne says:

    We just ran into an incredibly confusing and dangerous problem with the “amend commit” feature:
    https://youtrack.jetbrains.com/issue/CPP-18991

    This can cause a lot of pain and confusion, and can cause unintentional and hidden changes to the user’s code base. The good news is that it should probably be an easy fix. Is there any chance of getting this fixed in the next release?

    • Anastasia Kazakova says:

      Thanks for reporting, we’ll proceed in the ticket

      • Helge Penne says:

        I see that this has been filed under IDEA-65263, which is probably correct. This bug is quite old. Is there any hope that you can get this fixed? It is important because the damage this can do to the user’s code base is very significant It should also be an easy fix.

        • Anastasia Kazakova says:

          I see there is an ongoing discussion about the required fix. Let’s see where it goes in the ticket. And feel free to share your ideas and expectations there.

  4. Shawn Zhong says:

    Hi, I am wondering if there is an option to disable CUDA support on Mac?

    Before upgrading to EAP, I rely on the CUDA header files for code completion. CLion treated .cu files as normal C++ files, and everything works smoothly (except that CLion complains about “<<>>”, but that’s fine for me).

    I upgraded to EAP yesterday and CLion seems to treat *.cu files as CUDA files. It throws tons of errors, complaining that it cannot find the definition of some symbols. So I have to downgrade it to the stable version.

    Note: I am not expected to compile CUDA projects on my Mac. I add the following lines on my CMakeLists.txt just for code completion and documents.


    add_definitions(-include cstdlib)
    add_definitions(-include ${CUDA_INCLUDE_DIR}/cuda_runtime_api.h)
    add_definitions(-include ${CUDA_INCLUDE_DIR}/device_launch_parameters.h)
    include_directories(SYSTEM ${CUDA_INCLUDE_DIR})

  5. Helge Penne says:

    We ran into a bug with the Google Test integration when upgrading to the latest version of Google Test. It seems that CLion misinterprets the Google Test output of parameterized tests and terminates the test execution. The tests run just fine outside of CLion:
    https://youtrack.jetbrains.com/issue/CPP-18042

    Details have been added to the issue. Note that the title of the issue is perhaps a little misleading. This seems rather major to us, as it prevents us from using the latest Google Test version. We really hope you can fix this in the release you are working on.

  6. Nick says:

    Hope the remote cuda code running and debuging could be kept in the macOS version! Appreciate with your best effort. Thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *