HIP icon indicating copy to clipboard operation
HIP copied to clipboard

Getting Started for compiler developers

Open seanbaxter opened this issue 2 years ago • 1 comments

I wrote a C++ compiler that currently targets CUDA as well as SPIR-V and DXIL shaders. I'd like to add an AMD GPU target, but I'm having trouble understanding how to generate HIP modules with LLVM and how to instrument the runtime pipeline to actually go from the module to a launch. I've done all that for the PTX/CUDA side, but the AMD tools are subtly different.

I'm aware of this page, but it is exceedingly low-level, and unclear that it's even the right thing. No mention of HSACO format, for example.

Is there a guide or set of notes that can walk me through it? Eg, how do I configure the LLVM TargetMachine? There are so many AMDGPU targets, how do I decide what needs to be generated? How do I bind the hsaco files into the hip-fatbin, etc. I'm well positioned to move quickly on this, so just some nudges showing me the path would be real helpful.

edit Been poking at the amdclang compiler through the hipcc wrapper. I found the 47 .bc files in /opt/rocm/amdgcn/bitcode. I take it those get linked and internalized into the device module? Looking for assistance at this level.

seanbaxter avatar Feb 24 '22 03:02 seanbaxter

For a quick start, you may try download and run the docker rocm/dev-ubuntu-20.04:5.0.

Try compile a simple HIP program e.g. https://github.com/ROCm-Developer-Tools/HIP-Examples/blob/master/vectorAdd/vectoradd_hip.cpp

/opt/rocm/hip/bin/hipcc -save-temps -v -offload-arch=gfx906 vectoradd_hip.cpp

and check how host/device compilation is done and fat binary is embedded.

The following link has a brief description about how HIP kernel launching is implemented: https://github.com/ROCm-Developer-Tools/HIP/blob/develop/docs/markdown/hip_porting_driver_api.md

HIP-Clang sets up TargetMachine as usual in clang https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/BackendUtil.cpp#L935

Application developers usually choose amdgpu targets that cover their main users. usually gfx900, gfx906, gfx1010, gfx1030 and maybe more. You may find gfx names for amdgpus at this link https://llvm.org/docs/AMDGPUUsage.html#processors

yxsamliu avatar Feb 25 '22 16:02 yxsamliu

@seanbaxter Have you been able to resolve your issue? If so, please close ticket. Thanks!

ppanchad-amd avatar Apr 03 '24 17:04 ppanchad-amd