@@ -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
349348fn compute_file_hash ( path : & Path ) -> String {
0 commit comments