HIP: Heterogenous-computing Interface for Portability
|
HIP allows you to compile kernels at runtime with its hiprtc*
APIs. Kernels can be store as a text string and can be passed on to hiprtc APIs alongside options to guide the compilation.
To use hiprtc functionality, hiprtc header needs to be included first.
Now to compile this kernel, it needs to be associated with hiprtcProgram type, which is done via declaring hiprtcProgram prog;
and associating the string of kernel with this program:
hiprtcCreateProgram API also allows you to add headers which can be included in your rtc program. For online compilation, the compiler pre-defines HIP device API functions, HIP specific types and macros for device compilation, but does not include standard C/C++ headers by default. Users can only include header files provided to hiprtcCreateProgram.
After associating the kernel string with hiprtcProgram, you can now compile this program using:
hiprtcCompileProgram returns a status value which can be converted to string via hiprtcGetErrorString
. If compilation is successful, hiprtcCompileProgram will return HIPRTC_SUCCESS
.
If the compilation fails, you can look up the logs via:
If the compilation is successful, you can load the compiled binary in a local variable.
After loading the binary, hiprtcProgram can be destroyed.
And now this kernel can be launched via hipModule APIs.
Please have a look at saxpy.cpp and hiprtcGetLoweredName.cpp files for a detailed example.
HIPRTC provides a few hiprtc specific flags
--gpu-architecture
: This flag can guide the code object generation for a specific gpu arch. Example: --gpu-architecture=gfx906:sramecc+:xnack-
, its equivalent to --offload-arch
.Users will be required to link to libhiprtc.so/libhiprtc.dll in future releases. Currently all symbols are present in libhipamd64.so/libhipamd64.dll and there is a plan in action to separate HIPRTC APIs from HIP APIs.