Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCL online compilation: get assembly from cl::program or cl::kernel

I'm running kernel benchmarks with OpenCL. I know that I can compile kernels offline with various tools from OpenCL vendors (i.e. ioc64 or poclcc). The problem is that I get performance results that I cannot explain with the assembly from these tools, the OpenCL runtime overhead or similar.

I would like to see the assembly of online compiled kernels that are compiled and executed by my benchmark program. Any ways to do that?

My approach is to get this assembly somewhere from the cl::program or cl::kernel objects but I haven't found any way to do that. I appreciate your advice or solutions.

like image 761
new2f7 Avatar asked Jul 25 '18 13:07

new2f7


Video Answer


2 Answers

For Intel Graphics you can use clGetKernelInfo(...,CL_KERNEL_BINARY_PROGRAM_INTEL,...) to directly get the kernel ISA bits. To disassemble those bits, you can get the latest GEN ISA disassembler and build it as described here. Specifically, see the section on Building an Intel GPU ISA Disassembler. I haven't used it in a while, but The Intel OpenCL SDK used to do a better job (not a GUI person). And this is a good article on how to use that tool to scrutinize the assembly.

For NVidia, the "binary" returned by clGetProgramInfo(...CL_PROGRAM_BINARIES...) actually returns ptx. This might be enough, but if you want the exact shader assembly executed, then you can actually feed the ptx into ptxas and then disassemble cuobjdump with the --dump-sass option to get the lowest level assembly. Note, we're reduced to guessing that the NVidia driver is using the same algorithm as ptxas, but it seems logical.

AMD likely has similar tools, but I am less versed on them.

like image 97
Tim Avatar answered Sep 18 '22 22:09

Tim


in clBuildProgram call you can pass compiler options.

  1. Include path with -I
  2. Flags with -D
  3. Force compiler to drop assembly files with -save-temps
like image 38
Boris Ivanov Avatar answered Sep 17 '22 22:09

Boris Ivanov