Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions crates/khal/src/backend/cuda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,16 @@ impl Backend for Cuda {
}
}

// Expect PTX text bytes.
let ptx_str = std::str::from_utf8(bytes).map_err(|_| CudaBackendError::InvalidPtx)?;
let ptx = cudarc::nvrtc::Ptx::from_src(ptx_str.to_string());
// Accept either PTX text or a pre-linked CUBIN (detected by ELF magic).
// A cubin is required when the module references symbols the driver JIT
// cannot resolve on its own (e.g. libdevice `__nv_*` math), which a
// toolchain links into a self-contained binary ahead of time.
let ptx = if bytes.starts_with(&[0x7f, b'E', b'L', b'F']) {
cudarc::nvrtc::Ptx::from_binary(bytes.to_vec())
} else {
let ptx_str = std::str::from_utf8(bytes).map_err(|_| CudaBackendError::InvalidPtx)?;
cudarc::nvrtc::Ptx::from_src(ptx_str.to_string())
};
let module = self.ctx.load_module(ptx)?;

// Cache the loaded module.
Expand Down
Loading