This example showcases a simple HIP program that is compiled on the CUDA platform using CMake.
- A kernel is launched: the function
hello_world_kernel
is executed on the device. The kernel is executed on a single thread, and prints "Hello, World!" to the console. - A launch error check is performed using
hipGetLastError
. - Synchronization is performed: the host program execution halts until the kernel on the device has finished executing.
- For introduction to the programming concepts in this example, refer to the general hello world example.
- This example showcases setting up a HIP program to be compiled to the CUDA platform using CMake.
- Since CMake (as of version 3.21) does not support compiling to CUDA in HIP language mode, CUDA language mode has to be used. Thereby the project language is specified as
CUDA
. - Additionally, we must "teach" CMake to compile the source file
main.hip
in CUDA language mode, because it cannot guess that from the file extension. This is done byset_source_files_properties(main.hip PROPERTIES LANGUAGE CUDA)
. - The HIP "runtime" on the CUDA platform is header only. Thereby there is no need to link to a library, but the HIP include directory have to be added to the search paths. This is performed by
target_include_directories(${example_name} PRIVATE "${ROCM_ROOT}/include"
.
- Since CMake (as of version 3.21) does not support compiling to CUDA in HIP language mode, CUDA language mode has to be used. Thereby the project language is specified as
hipGetLastError
hipDeviceSynchronize
__global__
This example is only supported on the CUDA platform.