File tree Expand file tree Collapse file tree 12 files changed +90
-23
lines changed
Expand file tree Collapse file tree 12 files changed +90
-23
lines changed Original file line number Diff line number Diff line change 1616
1717//! Amplitude encoding implementation.
1818
19+ // Allow unused_unsafe: qdp_kernels functions are unsafe in CUDA builds but safe stubs in no-CUDA builds.
20+ // The compiler can't statically determine which path is taken.
21+ #![ allow( unused_unsafe) ]
22+
1923use std:: ffi:: c_void;
2024
2125use cudarc:: driver:: { CudaSlice , DevicePtrMut } ;
Original file line number Diff line number Diff line change 1616
1717//! Angle encoding implementation.
1818
19+ // Allow unused_unsafe: qdp_kernels functions are unsafe in CUDA builds but safe stubs in no-CUDA builds.
20+ // The compiler can't statically determine which path is taken.
21+ #![ allow( unused_unsafe) ]
22+
1923use std:: ffi:: c_void;
2024
2125use qdp_kernels:: launch_angle_encode_batch;
@@ -103,22 +107,22 @@ impl ChunkEncoder for AngleEncoder {
103107 }
104108 }
105109
106- unsafe {
107- crate :: profile_scope! ( "GPU::BatchEncode" ) ;
108- let ret = launch_angle_encode_batch (
110+ crate :: profile_scope! ( "GPU::BatchEncode" ) ;
111+ let ret = unsafe {
112+ launch_angle_encode_batch (
109113 dev_ptr as * const f64 ,
110114 state_ptr_offset,
111115 samples_in_chunk,
112116 state_len,
113117 num_qubits as u32 ,
114118 ctx. stream_compute . stream as * mut c_void ,
115- ) ;
116- if ret != 0 {
117- return Err ( MahoutError :: KernelLaunch ( format ! (
118- "Angle encode kernel error: {}" ,
119- ret
120- ) ) ) ;
121- }
119+ )
120+ } ;
121+ if ret != 0 {
122+ return Err ( MahoutError :: KernelLaunch ( format ! (
123+ "Angle encode kernel error: {}" ,
124+ ret
125+ ) ) ) ;
122126 }
123127 Ok ( ( ) )
124128 }
Original file line number Diff line number Diff line change 1616
1717//! Basis encoding implementation.
1818
19+ // Allow unused_unsafe: qdp_kernels functions are unsafe in CUDA builds but safe stubs in no-CUDA builds.
20+ // The compiler can't statically determine which path is taken.
21+ #![ allow( unused_unsafe) ]
22+
1923use std:: ffi:: c_void;
2024
2125use cudarc:: driver:: { CudaSlice , DevicePtr } ;
Original file line number Diff line number Diff line change 1616
1717// Amplitude encoding: state injection with L2 normalization
1818
19+ // Allow unused_unsafe: qdp_kernels functions are unsafe in CUDA builds but safe stubs in no-CUDA builds.
20+ // The compiler can't statically determine which path is taken.
21+ #![ allow( unused_unsafe) ]
22+
1923use std:: sync:: Arc ;
2024
2125use super :: QuantumEncoder ;
Original file line number Diff line number Diff line change 1616
1717// Angle encoding: map per-qubit angles to product state amplitudes.
1818
19+ // Allow unused_unsafe: qdp_kernels functions are unsafe in CUDA builds but safe stubs in no-CUDA builds.
20+ // The compiler can't statically determine which path is taken.
21+ #![ allow( unused_unsafe) ]
22+
1923use super :: QuantumEncoder ;
2024#[ cfg( target_os = "linux" ) ]
2125use crate :: error:: cuda_error_to_string;
Original file line number Diff line number Diff line change 1616
1717// Basis encoding: map integers to computational basis states
1818
19+ // Allow unused_unsafe: qdp_kernels functions are unsafe in CUDA builds but safe stubs in no-CUDA builds.
20+ // The compiler can't statically determine which path is taken.
21+ #![ allow( unused_unsafe) ]
22+
1923use super :: QuantumEncoder ;
2024#[ cfg( target_os = "linux" ) ]
2125use crate :: error:: cuda_error_to_string;
Original file line number Diff line number Diff line change 1313// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414// See the License for the specific language governing permissions and
1515// limitations under the License.
16+
17+ // Allow unused_unsafe: qdp_kernels functions are unsafe in CUDA builds but safe stubs in no-CUDA builds.
18+ // The compiler can't statically determine which path is taken.
19+ #![ allow( unused_unsafe) ]
20+
1621use crate :: error:: { MahoutError , Result } ;
1722use cudarc:: driver:: { CudaDevice , CudaSlice , DevicePtr } ;
1823use qdp_kernels:: { CuComplex , CuDoubleComplex } ;
Original file line number Diff line number Diff line change 1919// Provides generic double-buffered execution for large data processing.
2020// Separates the "streaming mechanics" from the "kernel logic".
2121
22+ // Allow unused_unsafe: CUDA FFI functions are unsafe in CUDA builds but safe stubs in no-CUDA builds.
23+ // The compiler can't statically determine which path is taken.
24+ #![ allow( unused_unsafe) ]
25+
2226use crate :: error:: { MahoutError , Result } ;
2327#[ cfg( target_os = "linux" ) ]
2428use crate :: gpu:: buffer_pool:: { PinnedBufferHandle , PinnedBufferPool } ;
Original file line number Diff line number Diff line change 1414// See the License for the specific language governing permissions and
1515// limitations under the License.
1616
17+ // Allow unused_unsafe: CUDA FFI and kernel functions are unsafe in CUDA builds but safe stubs in no-CUDA builds.
18+ // The compiler can't statically determine which path is taken.
19+ #![ allow( unused_unsafe) ]
20+
1721pub mod dlpack;
1822#[ cfg( target_os = "linux" ) ]
1923mod encoding;
Original file line number Diff line number Diff line change @@ -27,16 +27,27 @@ use std::env;
2727use std:: process:: Command ;
2828
2929fn main ( ) {
30+ // Let rustc know about our build-script-defined cfg flags (avoids `unexpected_cfgs` warnings).
31+ println ! ( "cargo::rustc-check-cfg=cfg(qdp_no_cuda)" ) ;
32+
3033 // Tell Cargo to rerun this script if the kernel sources change
3134 println ! ( "cargo:rerun-if-changed=src/amplitude.cu" ) ;
3235 println ! ( "cargo:rerun-if-changed=src/basis.cu" ) ;
3336 println ! ( "cargo:rerun-if-changed=src/angle.cu" ) ;
37+ println ! ( "cargo:rerun-if-env-changed=QDP_NO_CUDA" ) ;
3438 println ! ( "cargo:rerun-if-changed=src/kernel_config.h" ) ;
3539
3640 // Check if CUDA is available by looking for nvcc
37- let has_cuda = Command :: new ( "nvcc" ) . arg ( "--version" ) . output ( ) . is_ok ( ) ;
41+ let force_no_cuda = env:: var ( "QDP_NO_CUDA" )
42+ . map ( |v| v == "1" || v. eq_ignore_ascii_case ( "true" ) || v. eq_ignore_ascii_case ( "yes" ) )
43+ . unwrap_or ( false ) ;
44+
45+ let has_cuda = !force_no_cuda && Command :: new ( "nvcc" ) . arg ( "--version" ) . output ( ) . is_ok ( ) ;
3846
3947 if !has_cuda {
48+ // Expose a cfg for conditional compilation of stub symbols on Linux.
49+ // This allows qdp-kernels (and dependents) to link on Linux machines without CUDA.
50+ println ! ( "cargo:rustc-cfg=qdp_no_cuda" ) ;
4051 println ! ( "cargo:warning=CUDA not found (nvcc not in PATH). Skipping kernel compilation." ) ;
4152 println ! ( "cargo:warning=This is expected on macOS or non-CUDA environments." ) ;
4253 println ! (
You can’t perform that action at this time.
0 commit comments