Skip to content

Instantly share code, notes, and snippets.

@gmarkall
Created October 21, 2022 11:37
Show Gist options
  • Save gmarkall/e69344b4994877006a55dfea4ee9d2aa to your computer and use it in GitHub Desktop.
Save gmarkall/e69344b4994877006a55dfea4ee9d2aa to your computer and use it in GitHub Desktop.
Example defining an intrinsic in the Numba CUDA target
from numba.cuda.extending import intrinsic
from llvmlite import ir
@intrinsic
def cuda_clock64(typingctx):
sig = types.uint64()
def codegen(context, builder, sig, args):
function_type = ir.FunctionType(ir.IntType(64), [])
instruction = "mov.u64 $0, %clock64;"
clock64 = ir.InlineAsm(function_type, instruction, "=l",
side_effect=True)
return builder.call(clock64, [])
return sig, codegen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment