This example shows how the target platform and compiler can be identified, as well as how properties from the device may be queried.
- Using compiler-defined macros, the target platform and compiler are identified.
- The number of devices in the system is queried, and for each device:
- The device is set as the active device.
- The device properties are queried and a selected set is printed.
- For each device in the system, it is queried and printed whether this device can access its memory.
- If NVIDIA is the target platform, some NVIDIA-specific device properties are printed.
- The amount of total and free memory of the device is queried and printed.
- HIP code can target the AMD and the NVIDIA platform, and it can be compiled with different compilers. Compiler-defined macros can be used in HIP code to write code that is specific to a target or a compiler. See HIP Programming Guide - Distinguishing Compiler Modes for more details.
hipGetDeviceCount
returns the number of devices in the system. Some device management API functions take an identifier for each device, which is a monotonically incrementing number starting from zero. Others require the active device to be set, withhipSetDevice
. A full overview of the device management API can be found at HIP API - Device Management.
__HIP_PLATFORM_AMD__
__HIP_PLATFORM_NVIDIA__
__CUDACC__
hipGetDeviceCount
hipSetDevice
hipGetDeviceProperties
hipDeviceCanAccessPeer
hipMemGetInfo
cudaDeviceGetLimit
cudaLimit::cudaLimitStackSize
cudaLimit::cudaLimitMallocHeapSize