[BUG] CuTe DSL: export_to_c fails for a --gpu-arch other than the current GPU's
Which component has the problem?
CuTe DSL
Bug Report
Describe the bug
export_to_c fails on the plain C path (no --enable-tvm-ffi) when the function was compiled for a different arch than the current GPU. For example, --gpu-arch sm_90a on a B200:
JIT session error: Symbols not found: [ _cuKernelGetAttribute, _cudaDeviceGetAttribute, _cudaFuncSetAttribute, _cudaGetDevice, _cudaKernelSetAttributeForDevice, _cudaLaunchKernelEx, _cudaLibraryGetKernel, _cudaLibraryLoadData ]
error: Error dumping object file: Failed to dump object file with PIC relocationThe same export works for the native arch, and it also works if I load the runtime libraries RTLD_GLOBAL first. My guess is that no execution engine gets built for an arch the GPU can't run, so libcute_dsl_runtime.so never gets loaded before the object dump.
Steps/Code to reproduce bug
import ctypes, sys, tempfile
import cuda.bindings.driver as cuda
import cutlass
import cutlass.cute as cute
from cutlass.cute.runtime import make_fake_stream
@cute.kernel
def noop_kernel(x: cutlass.Int32):
pass
@cute.jit
def noop(x: cutlass.Int32, stream: cuda.CUstream):
noop_kernel(x).launch(grid=(1, 1, 1), block=(32, 1, 1), stream=stream)
if "--preload" in sys.argv:
for lib in cute.runtime.find_runtime_libraries(enable_tvm_ffi=False):
ctypes.CDLL(lib, mode=ctypes.RTLD_GLOBAL)
fn = cute.compile(noop, cutlass.Int32(0), make_fake_stream(), options="--gpu-arch sm_90a")
with tempfile.TemporaryDirectory() as tmp:
fn.export_to_c(tmp, "noop", function_prefix="noop")
print(f"cutlass-dsl {cutlass.__version__}: exported", flush=True)$ python repro.py
JIT session error: Symbols not found: [ _cuKernelGetAttribute, ... ]
$ python repro.py --preload
cutlass-dsl 4.8.0: exportedExpected behavior
export_to_c works for any --gpu-arch the compiler accepts, with no manual preloading.
Environment details (please complete the following information):
- Environment location: Bare-metal
- nvidia-cutlass-dsl 4.8.0 and 4.7.0 (cu13), cuda-python 13.4.1
- B200, driver 580.159.03, Ubuntu 22.04, Python 3.12
Additional context
#2859 had the same error on the TVM-FFI path and was fixed in 4.3.3; the TVM-FFI path does export cross-arch now. The plain C path still fails. Workaround: preload cute.runtime.find_runtime_libraries() with RTLD_GLOBAL.
Source: NVIDIA/cutlass