Skip to content
This repository was archived by the owner on Apr 6, 2026. It is now read-only.

Commit 2a98589

Browse files
authored
Add cuda-minver option for CUDA kernels (#176)
This allows for kernels that support all the upstream CUDA versions, but have some 'subkernels' that require a newer CUDA version (e.g. CUDA 12.9 for Blackwell).
1 parent bbc4e71 commit 2a98589

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

build2cmake/src/config/v2.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ pub enum Kernel {
9090
Cuda {
9191
cuda_capabilities: Option<Vec<String>>,
9292
cuda_flags: Option<Vec<String>>,
93+
cuda_minver: Option<Version>,
9394
cxx_flags: Option<Vec<String>>,
9495
depends: Vec<Dependencies>,
9596
include: Option<Vec<String>>,
@@ -256,6 +257,7 @@ fn convert_kernels(v1_kernels: HashMap<String, v1::Kernel>) -> Result<HashMap<St
256257
Kernel::Cuda {
257258
cuda_capabilities: kernel.cuda_capabilities,
258259
cuda_flags: None,
260+
cuda_minver: None,
259261
cxx_flags: None,
260262
depends: kernel.depends,
261263
include: kernel.include,

build2cmake/src/templates/cuda/kernel.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
{% if cuda_minver %}
2+
if (CUDA_VERSION VERSION_GREATER_EQUAL {{ cuda_minver }})
3+
{% endif %}
4+
15
set({{kernel_name}}_SRC
26
{{ sources }}
37
)
@@ -50,3 +54,6 @@ elseif(GPU_LANG STREQUAL "HIP")
5054
{% endif %}
5155
endif()
5256

57+
{% if cuda_minver %}
58+
endif()
59+
{% endif %}

build2cmake/src/torch/cuda.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,19 @@ pub fn render_kernel(
298298
.collect_vec()
299299
.join("\n");
300300

301-
let (cuda_capabilities, rocm_archs, cuda_flags) = match kernel {
301+
let (cuda_capabilities, rocm_archs, cuda_flags, cuda_minver) = match kernel {
302302
Kernel::Cuda {
303303
cuda_capabilities,
304304
cuda_flags,
305+
cuda_minver,
305306
..
306-
} => (cuda_capabilities.as_deref(), None, cuda_flags.as_deref()),
307-
Kernel::Rocm { rocm_archs, .. } => (None, rocm_archs.as_deref(), None),
307+
} => (
308+
cuda_capabilities.as_deref(),
309+
None,
310+
cuda_flags.as_deref(),
311+
cuda_minver.as_ref(),
312+
),
313+
Kernel::Rocm { rocm_archs, .. } => (None, rocm_archs.as_deref(), None, None),
308314
_ => unreachable!("Unsupported kernel type for CUDA rendering"),
309315
};
310316

@@ -314,6 +320,7 @@ pub fn render_kernel(
314320
context! {
315321
cuda_capabilities => cuda_capabilities,
316322
cuda_flags => cuda_flags.map(|flags| flags.join(";")),
323+
cuda_minver => cuda_minver.map(ToString::to_string),
317324
cxx_flags => kernel.cxx_flags().map(|flags| flags.join(";")),
318325
rocm_archs => rocm_archs,
319326
includes => kernel.include().map(prefix_and_join_includes),

0 commit comments

Comments
 (0)