Skip to content

Commit 8ae97b7

Browse files
committed
Removing .a from hash check
1 parent 1422ab3 commit 8ae97b7

File tree

5 files changed

+17
-20
lines changed

5 files changed

+17
-20
lines changed

lib/kvbm-kernels/build.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -108,36 +108,34 @@ fn build_with_prebuilt_kernels() {
108108
);
109109
}
110110

111-
// Read and validate hashes (.cu, .fatbin, and .a)
111+
// Read and validate hashes (.cu and .fatbin only)
112+
// Note: We don't validate .a hashes because static libraries are not reproducible
113+
// across different build environments (timestamps, compiler metadata, etc.).
114+
// If .cu and .fatbin match, the .a was built from the same source and is valid.
112115
let stored_hashes_content = fs::read_to_string(&md5_path)
113116
.unwrap_or_else(|_| panic!("Failed to read {}", md5_path.display()));
114117
let stored_hashes: Vec<&str> = stored_hashes_content.lines().collect();
115118

116-
if stored_hashes.len() != 3 {
119+
if stored_hashes.len() < 2 {
117120
panic!(
118-
"Invalid .md5 format for {} (expected 3 lines: .cu hash, .fatbin hash, .a hash)",
121+
"Invalid .md5 format for {} (expected at least 2 lines: .cu hash, .fatbin hash)",
119122
kernel_name
120123
);
121124
}
122125

123126
let current_cu_hash = compute_file_hash(cu_path);
124127
let current_fatbin_hash = compute_file_hash(&fatbin_path);
125-
let current_lib_hash = compute_file_hash(&lib_path);
126128

127-
// Validate hashes
128-
if current_cu_hash != stored_hashes[0]
129-
|| current_fatbin_hash != stored_hashes[1]
130-
|| current_lib_hash != stored_hashes[2]
131-
{
129+
// Validate that .cu source and .fatbin GPU code match exactly.
130+
// This ensures the source code and compiled GPU kernels are in sync.
131+
if current_cu_hash != stored_hashes[0] || current_fatbin_hash != stored_hashes[1] {
132132
panic!(
133-
"Hash mismatch for {}! Rebuild with nvcc.\n .cu: current={}, stored={}\n .fatbin: current={}, stored={}\n .a: current={}, stored={}",
133+
"Hash mismatch for {}! Rebuild with nvcc.\n .cu: current={}, stored={}\n .fatbin: current={}, stored={}",
134134
kernel_name,
135135
current_cu_hash,
136136
stored_hashes[0],
137137
current_fatbin_hash,
138-
stored_hashes[1],
139-
current_lib_hash,
140-
stored_hashes[2]
138+
stored_hashes[1]
141139
);
142140
}
143141

@@ -326,13 +324,15 @@ fn generate_prebuilt_artifacts(cu_path: &Path, arch_flags: &[String], out_dir: &
326324
// Copy .a to prebuilt directory
327325
fs::copy(&temp_lib, &lib_path).expect("Failed to copy .a to cuda/prebuilt/");
328326

329-
// Generate MD5 hashes for consistency validation (.cu, .fatbin, and .a)
327+
// Generate MD5 hashes for consistency validation (.cu and .fatbin only)
328+
// Note: We don't hash .a files because they're not reproducible across different
329+
// build environments (timestamps, compiler versions, etc.). If source and .fatbin
330+
// match, the .a was built from the same source and is valid.
330331
let cu_hash = compute_file_hash(cu_path);
331332
let fatbin_hash = compute_file_hash(&fatbin_path);
332-
let lib_hash = compute_file_hash(&lib_path);
333333

334-
// Write hashes (one per line: .cu hash, .fatbin hash, .a hash)
335-
let hashes = format!("{}\n{}\n{}\n", cu_hash, fatbin_hash, lib_hash);
334+
// Write hashes (one per line: .cu hash, .fatbin hash)
335+
let hashes = format!("{}\n{}\n", cu_hash, fatbin_hash);
336336
fs::write(&md5_path, hashes).expect("Failed to write .md5 file");
337337

338338
println!(
@@ -343,7 +343,6 @@ fn generate_prebuilt_artifacts(cu_path: &Path, arch_flags: &[String], out_dir: &
343343
);
344344
println!("cargo:warning=.cu source hash: {}", cu_hash);
345345
println!("cargo:warning=.fatbin hash: {}", fatbin_hash);
346-
println!("cargo:warning=.a library hash: {}", lib_hash);
347346
}
348347

349348
fn compute_file_hash(path: &Path) -> String {
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
08fd40353d9ded18ad94cf80947702f0
22
9ebb27c2cfd6a2dc2dd983d34e5aa9c4
3-
25526fb169d43b4f2daab50efe0387ea
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
e018bb428d2df347daffbb934a6436da
22
92c5bd9f7474d55daed7654ee08ae8f4
3-
e1c805e76b235948acb7a3f9b0d7008c

0 commit comments

Comments
 (0)