MCPcopy Create free account
hub / github.com/apache/tvm / tvm_callback_cuda_compile

Function tvm_callback_cuda_compile

python/tvm/support/nvcc.py:852–892  ·  view source on GitHub ↗

Compile CUDA code using the configured backend (nvcc or nvrtc). This callback is invoked by TVM's C++ backend during CUDA module compilation. By default, uses nvrtc to generate cubin. The current target is fetched inside the callback (via ``tvm.target.Target.current(allow_none=Tru

(code)

Source from the content-addressed store, hash-verified

850
851@tvm_ffi.register_global_func
852def tvm_callback_cuda_compile(code):
853 """
854 Compile CUDA code using the configured backend (nvcc or nvrtc).
855
856 This callback is invoked by TVM's C++ backend during CUDA module compilation.
857 By default, uses nvrtc to generate cubin. The current target is fetched
858 inside the callback (via ``tvm.target.Target.current(allow_none=True)``)
859 so the caller does not need to push/pop a target scope around the
860 invocation.
861
862 Environment Variables
863 ---------------------
864 TVM_CUDA_COMPILE_MODE : str
865 Compiler backend: "nvrtc" (default) or "nvcc"
866 - "nvrtc": Use NVRTC via cuda-bindings for faster JIT, generates cubin
867 - "nvcc": Use nvcc subprocess, generates fatbin
868 TVM_KERNEL_DUMP : str
869 If set, dump generated CUDA/intermediate files and append "-lineinfo" so profilers can
870 correlate SASS back to the dumped source.
871
872 Parameters
873 ----------
874 code : str
875 CUDA source code to compile
876
877 Returns
878 -------
879 bytes
880 Compiled binary (fatbin for nvcc, cubin for nvrtc)
881 """
882 # The current Target is fetched inside compile_cuda via
883 # tvm.target.Target.current(allow_none=True) when arch is unset; the
884 # caller no longer needs to push/pop a target scope.
885 compiler = os.environ.get("TVM_CUDA_COMPILE_MODE", "nvrtc").lower()
886
887 if compiler == "nvrtc":
888 return compile_cuda(code, target_format="cubin", compiler="nvrtc")
889 if compiler == "nvcc":
890 return compile_cuda(code, target_format="fatbin", compiler="nvcc")
891
892 raise ValueError(f"Invalid TVM_CUDA_COMPILE_MODE: {compiler}. Expected 'nvcc' or 'nvrtc'.")
893
894
895@tvm_ffi.register_global_func("tvm_callback_libdevice_path")

Callers

nothing calls this directly

Calls 2

compile_cudaFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…