6

I want to create an OpenCL kernel that works on AMD GPUs (Fury Nano). Basically I would like to write a draft kernel using OpenCL, and use an OpenCL API to output the assembly code using clGetProgramInfo. And then I will modify the assembly code and load it back to the program using clcreateprogramwithbinary.

Is there any possible ways to do this?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Zk1001
  • 2,033
  • 4
  • 19
  • 36

2 Answers2

3

If you add "–save-temps" to invocation of create program (or whatever it is called) you will see the generated assembly files. You can modify these and can then create an opencl program from this assembly.

Another way to get the assembly output it to build llvm with support for amd gpu and then compile this to assembly using the -S flag.

The command line I used for polaris10, with opencl standard 2.0 was:

clang -std=CL2.0 -target amdgcn-amd-amdpal-opencl -mcpu=polaris10 -S -c foo.cl -O3

You need to modify foo.cl to include opencl-c.h, by adding

#include <opencl-c.h>

to the first line of the opencl source file.

This will then generate the assembly file as foo.s in the current directory. To generate code for an R9 fury, change the mcpu to fiji. ie.

... -mcpu=fiji ...
  • 1
    What about generating an opencl program from assembly code? –  Mar 19 '18 at 23:05
  • Just include the assembly source in the opencl program as inline assembly in a c file. –  Mar 19 '18 at 23:17
3

I can suggest to use CLRadeonExtender, that is a real assembler for AMD GCN GPUs with support of all main OpenCL runtimes both on Windows and Linux. I have a very positive experience with it.

Ivan Siutsou
  • 121
  • 1
  • 5