Skip to content

Commit 6e4061a

Browse files
committed
build: Skip regenerating kernels when source unchanged
Prevents CI from regenerating non-reproducible .a files unnecessarily. Only regenerates when .cu source changes or artifacts are missing. Delete .md5 files to force regeneration after changing CUDA_ARCHS.
1 parent 8ae97b7 commit 6e4061a

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

lib/kvbm-kernels/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,19 @@ cargo build --release
247247
# Commit the updated cuda/prebuilt/tensor_kernels.{fatbin,md5}
248248
```
249249

250+
**Important:** If you change `CUDA_ARCHS` or update your nvcc version, you need to
251+
force regeneration by deleting the checksums:
252+
253+
```bash
254+
# Force regeneration after changing CUDA_ARCHS or nvcc version
255+
rm cuda/prebuilt/*.md5
256+
cargo build --release
257+
# Commit the updated files
258+
```
259+
260+
The build system only checks if the `.cu` source has changed, not build configuration.
261+
This prevents CI from regenerating non-reproducible `.a` files unnecessarily.
262+
250263
---
251264

252265
### Python Bindings & Tests

lib/kvbm-kernels/build.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,30 @@ fn generate_prebuilt_artifacts(cu_path: &Path, arch_flags: &[String], out_dir: &
246246
let lib_path = prebuilt_dir.join(format!("lib{}.a", kernel_name));
247247
let md5_path = prebuilt_dir.join(format!("{}.md5", kernel_name));
248248

249+
// Skip regeneration if valid prebuilt artifacts already exist
250+
// (avoids modifying source tree with non-reproducible .a files in CI)
251+
//
252+
// LIMITATION: This only checks if the .cu source has changed, not build configuration
253+
// (CUDA_ARCHS, nvcc version, compiler flags). If you change CUDA_ARCHS or update nvcc,
254+
// manually delete the .md5 files to force regeneration:
255+
// rm lib/kvbm-kernels/cuda/prebuilt/*.md5
256+
if fatbin_path.exists() && lib_path.exists() && md5_path.exists() {
257+
// Validate that existing artifacts match current source
258+
if let Ok(stored_hashes) = fs::read_to_string(&md5_path) {
259+
let hashes: Vec<&str> = stored_hashes.lines().collect();
260+
if hashes.len() >= 2 {
261+
let current_cu_hash = compute_file_hash(cu_path);
262+
if current_cu_hash == hashes[0] {
263+
println!(
264+
"cargo:warning=Skipping regeneration of {} (valid prebuilt artifacts exist)",
265+
kernel_name
266+
);
267+
return;
268+
}
269+
}
270+
}
271+
}
272+
249273
// Generate .fatbin using nvcc
250274
let temp_fatbin = Path::new(out_dir).join(format!("{}.fatbin", kernel_name));
251275
// Generate .o (object file) for static library

0 commit comments

Comments
 (0)