7/7/2023 0 Comments Cmake cuda![]() So 7.0 would be a common choice for our 7.2 card. This needs to have the same major number as your target card, and be equal to or less than the target card. Then there's a target architecture, which must be equal or greater to the code architecture. You have two choices the first is the code level this will report to the code being compiled a version, like "5.0", and it will take advantage of all the features up to 5.0 but not past (assuming well written code / standard libraries). If you don't, you compile 'ptx', which provide the basic instructions but is compiled at runtime, making it potentially much slower to load.Īll cards have an architecture level, like "7.2". When you build CUDA code, you generally should be targeting an architecture. You can also directly make a PTX file with the CUDA_PTX_COMPILATION property. You can also use separable compilation: set_target_properties(mylib PROPERTIES cu for CUDA files, you can just add libraries exactly like you normally would. This is the easy part as long as you use. You are already used to from the cxx versions. If you are looking for CUDA's standard level, in CMake 3.17 a new collection ofĬompiler features were added, like cuda_std_11. Many variables with CXX in the name have a CUDA version with CUDA instead.įor example, to set the C++ standard required for CUDA, if(NOT DEFINED CMAKE_CUDA_STANDARD) You can check the version withĬMAKE_CUDA_COMPILER_VERSION. "NVIDIA", Clang was added in CMake 3.18). You can check variables like CMAKE_CUDA_COMPILER_ID (for nvcc, this is You can see if CUDA is present by checking CMAKE_CUDA_COMPILER (was missing To check to see if CUDA is available, use CheckLanuage: include(CheckLanguage) Want to put this in somewhere conditionally: enable_language(CUDA) You'll probably want CXX listed here also. If CUDA is not optional: project(MY_PROJECT LANGUAGES CUDA CXX) There are two ways to enable CUDA support. Unlike the older languages, CUDA support has been rapidly evolving, and building CUDA is hard, so I would recommend you require a very recent version of CMake! CMake 3.17 and 3.18 have a lot of improvements directly targeting CUDA.Ī good resource for CUDA and Modern CMake is this talk by CMake developer Robert Maynard at GTC 2017. The new method, introduced in CMake 3.8 (3.9 for Windows), should be strongly preferred over the old, hacky method - I only mention the old method due to the high chances of an old package somewhere having it. None the less, I hope you have a smoother transition from an old CMake version with my tips above.CUDA support is available in two flavors. There are more things this release introduced that you may need. The things I mentioned above are just what I have to change in my own CMake project to make CUDA work again. It could be a bit difficult to get started because CUDA-related changes are not documented in a single place. With CMake 3.8, we have a new way to use CUDA in our CMake projects. This variable contains the paths that nvcc implicitly uses to find libraries. We could find those libraries relying on the new CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES. Sometimes you may just want to link to certain CUDA libraries with pure C/C++ code. Since CMake 3.11, we can also directly set the CMAKE_CUDA_SEPARABLE_COMPILATION property which will internally be used to initialize the value of CUDA_SEPARABLE_COMPILATION on each target. set_property(TARGET PROPERTY CUDA_SEPARABLE_COMPILATION ON) Unlike with FindCUDA, we have to enable CUDA device code separable compilation on a per target basis now. add_executable(cuda_exe c_file.c cuda_file.cu) CMake will use different compiler depending on the file extension and link everything properly in the end. ![]() Simply use add_executable and add_library to build executables and libraries which contain CUDA code. The CUDA specific cuda_add_executable and cuda_add_library macros are no longer necessary. We can follow the same way we set compiler flags for C/C++ source. This can be easily done with project( LANGUAGES CUDA) The first thing you have to do is to set CUDA as a language in your CMake project. In this blog post, I will talk about how to use CUDA in CMake 3.8+. These all changed with CUDA becoming a language in CMake 3.8. Essentially, it has to duplicate a lot of features already in CMake specifically for CUDA support. ![]() To let CMake use nvcc to compile something, the FindCUDA module provides macros like cuda_add_executable (similar to add_executable). Unlike other libraries, CUDA provides not only some libraries but a compiler as well. Prior to CMake 3.8, it has been providing this module to support compiling CUDA code and linking with CUDA libraries. If you have ever created or built a CUDA CMake project in the past, you have probably heard about the FindCUDA CMake module.
0 Comments
Leave a Reply. |