does opencl support inline assembly?

hi i am a OpenCL beginner, and have two general questions:

  1. Can i include C inline assembly code in my openCL code?

  2. Does OpenCL support addtion and subtraction with carry?

thanks!

  1. No. (what assembly would you use? PTX, x86? )
  2. Not explicitly. If you want to detect a carry/overflow you need to check the output with respect to the input or use a larger data type as far as I know.

i see, thanks!

yes X86. then if i want to implement part of the code assembly, how can i call them from the main opencl program?

then how can opencl code access assembler instructions, such as if the GPU has assembly instruction addc?

There’s no supported way to do that. Some OpenCL implementations will return PTX if you ask for a program binary, and you could probably modify it and send it back, but that’s not really supported.

This is very old, but it comes up when people search for this question, so it merits correction.

TLDR : “Yes it can be done”, see
github sschaetz/nvidia-opencl-examples/tree/master/OpenCL/src/oclInlinePTX

Explanation:
Calling assembly code inline in C code is a feature of the compiler.
OpenCL kernels are C code compiled with the compiler flags to produce a binary for the target processor (GPU, FPGA, CPU) depending on the OpenCL “platform” and “device” selected in the OpenCL “context”.

Use the “asm(…)” function in C to wrap the assembly code.
cppreference w/cpp/language/asm