[OpenCL][AMDGPU] Using AMDGPU generated kernel code for OpenCL

Hello everyone

I was wondering, what the correct way of using an AMDGPU generated kernel code for OpenCL was. I am trying to provide Polly’s GPGPU Code generation with the ability to run on different GPU devices, such as AMD GPUs.

For NVIDIA, I simply retrieve a pre-compiled PTX string from the NVPTX backend and pass that to OpenCL’s ‘clCreateProgramWithBinary’ function. However, when doing the same with the AMDGPU backend and its returned kernel string, OpenCL complains about an invalid binary.
This has been tried with a number of different target triples (eg. ‘amdgcn–’, ‘amdgcn-amd-amdhsa’ etc), and my assumption so far is, that I am not trying the correct Triple.
Or am I missing something entirely, and there have to be additional steps, to get the correct ELF binary?

Thank you in advance for any help and pointers!

Best,
Philipp

The binary format expected by AMD OpenCL drivers are elf-linked binaries. See

http://openwall.info/wiki/john/development/AMD-IL
https://community.amd.com/thread/166955

Michael

Hi Michael

Thank you for those two links.
So if I understand that correctly, this means that the ISA generated by the AMDGPU backend is only a part of the expected elf-linked binary file, and would have to be correctly wrapped/packed up in order for OpenCL to accept it?

Best,
Philipp

I cannot tell you anything more than the two links already say.

I remember an article where somebody reverse-engineered the format and
found an elf inside and elf file, which they called "elfception".
Unfortunately I cannot find the article anymore.

If possible, I suggest to go using SPIR or SPIR-V instead. The
proprietary format might change in any version of the driver. There is
currently a discussion about including SPIR-V into LLVM.

Michael