|
| 1 | + |
| 2 | +# Using CUDA and CMakeLists |
| 3 | + |
| 4 | +This section contains information on a few things found to be necessary for the |
| 5 | +simulator CUDA code to build and run correctly when using CMakeLists. This is |
| 6 | +not a complete guide on using CMakeLists with CUDA. |
| 7 | + |
| 8 | +## Static Libraries |
| 9 | + |
| 10 | +Each library created in the CMakeLists.txt file that contains CUDA source code |
| 11 | +should be created with the STATIC keyword. More information on the difference |
| 12 | +between STATIC and SHARED type libraries can be found in the CMake documentation, |
| 13 | +and a short summary is available on the [add_library documentation page](https://cmake.org/cmake/help/latest/command/add_library.html). Libraries |
| 14 | +with no type specified will be assigned one automatically based on conditions |
| 15 | +listed in the documentation, but in the case of our simulator they can be observed |
| 16 | +as being SHARED if no type is specified. |
| 17 | + |
| 18 | +If a library containing CUDA source files is created as SHARED, the linking of |
| 19 | +the corresponding CUDA device code will be done individually just before the |
| 20 | +step of linking the SHARED library it is a part of. Explicitly declaring libraries |
| 21 | +containing CUDA code as STATIC instead allows the linking of CUDA device code to |
| 22 | +be put off and done all together just before the final executable is linked and |
| 23 | +built. This change allows the linker for CUDA code to function correctly and |
| 24 | +prevents many errors that arise if the libraries are left as SHARED. |
| 25 | + |
| 26 | +Example of creating a STATIC library: |
| 27 | + ```add_library(Edges STATIC ${Edges_Source})``` |
| 28 | + Where `${Edges_Source}` is a collection of source files |
| 29 | + |
| 30 | +## Separable Compilation |
| 31 | + |
| 32 | +CUDA separable compilation allows different pieces of CUDA code to be compiled |
| 33 | +into separate objects and then linked together later. More information can be |
| 34 | +found about Separate Compilation and Linking of CUDA code in this [NVIDIA developer |
| 35 | +blog post](https://developer.nvidia.com/blog/separate-compilation-linking-cuda-device-code/). This must be enabled in the CMakeLists.txt file individually for each |
| 36 | +library containing CUDA source code by setting the CUDA_SEPARABLE_COMPILATION |
| 37 | +property to ON. Information on this property can be found [here](https://cmake.org/cmake/help/latest/prop_tgt/CUDA_SEPARABLE_COMPILATION.html) in the CMake |
| 38 | +documentation. |
| 39 | + |
| 40 | +It is set using the set_property command, for example like this: |
| 41 | + ```set_property(TARGET Edges PROPERTY CUDA_SEPARABLE_COMPILATION ON)``` |
| 42 | + Where `Edges` is a library containing CUDA source code. |
0 commit comments