开发者

Disassemble an OpenCL kernel?

I'm not sure if it's possible. I want to study OpenCL in-depth, so I was wondering if there is a tool to disas开发者_如何转开发semble an compiled OpenCL kernel.

For normal x86 executable, I can use objdump to get a disassembly view. Is there a similar tool for OpenCL kernel, yet?


If you're using NVIDIA's OpenCL implementation for their GPUs, you can do the followings to disassemble an OpenCL kernel:

  1. Use clGetEventProfilingInfo() to dump the ptx code to a file, say ptxfile.ptx. Please refer to the OpenCL specification to have more details on this function.

  2. Use nvcc to compile ptx to cubin file, for example: nvcc -cubin -arch=sm_20 ptxfile.ptx will compile ptxfile.ptx onto a compute capability 2.0 device.

  3. Use cuobjdump to disassemble the cubin file into GPU instructions. For example: cuobjdump -sass ptxfile.cubin

Hope this helps.


I know that this is an old question, but in case someone comes looking here for disassembling a AMD GPU kernel, you can do the following in linux:

export GPU_DUMP_DEVICE_KERNEL=3

This make any kernel that is compiled on your machine dump the assembled code to a file in the same directory.

Source: http://dis.unal.edu.co/~gjhernandezp/TOS/GPU/ATI_Stream_SDK_OpenCL_Programming_Guide.pdf

Sections 4.2.1 and 4.2.2


The simplest solution, in my experience, is to use clangs OpenCL C compiler and emit SPIR. It even works on Godbolt's compiler explorer: https://godbolt.org/z/_JbXPb

Clang can also emit ptx (https://godbolt.org/z/4ARMqM) and amdhsa (https://godbolt.org/z/TduTZQ), but it may not correspond to the ptx and amdhsa assembly generated by the respective driver at runtime.


If you work with an AMD GPU, you can use the Analyzer tool. It is free, cross-platform, and comes in two forms:

  1. Command line tool (ships as part of the CodeXL package, search for the CodeXLAnalyzer executable after installing).
  2. CodeXL GUI application (just switch to the Analyzer mode in CodeXL).

Here is a short summary of what you can do with the Analyzer:

  1. Compile OpenCL kernels, OpenGL shaders and D3D shaders for any GPU that is supported by the installed driver (even without having the GPU physically installed on your system), and get the ISA. Using CodeXL Analyzer (option #2 above), you can get additional information such as an estimation for the number of clock cycles that are required to execute the instruction.
  2. View the compiler-generated statistics (SGPRs usage, VGPRs usage, etc.)
  3. Generate the AMD IL code for the OpenCL kernel.
  4. Export the compiled binaries (ELF, in binary format).

You can download the CodeXL tool suite from here: https://gpuopen.com/compute-product/codexl/


As AMD CodeXLAnalyzer not not supported anymore use Radeon GPU Analyzer

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜