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

点点圈 提交于 2019-12-10 05:18:36

问题


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.


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/51519918/opencl-online-compilation-get-assembly-from-clprogram-or-clkernel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!