Skip to main content

cufile_copy/
cufile-copy.rs

1#[cfg(all(feature = "std", feature = "cufile"))]
2fn main() -> Result<(), Box<dyn std::error::Error>> {
3    use std::fs;
4
5    use cudarc::{cufile::safe::Cufile, driver::CudaContext};
6
7    const N: usize = 100000;
8    let data: Vec<u8> = (0..N).flat_map(|x| (x as f32).to_le_bytes()).collect();
9    let data_sz = data.len();
10    let src_file = "/tmp/cufile_test.bin";
11    fs::write(src_file, &data)?;
12
13    let cufile = Cufile::new()?;
14    println!("{:?}", cufile.get_properties()?);
15
16    let file = fs::File::open(src_file)?;
17    let handle = cufile.register(file)?;
18
19    let ctx = CudaContext::new(0)?;
20    let stream = ctx.default_stream();
21    let mut buf = stream.alloc_zeros::<u8>(data_sz)?;
22
23    handle.sync_read(0, &mut buf)?;
24
25    let verify_dst = stream.clone_dtoh(&buf)?;
26    assert_eq!(verify_dst, data);
27
28    Ok(())
29}
30
31#[cfg(not(all(feature = "std", feature = "cufile")))]
32fn main() {
33    println!("This example requires `std` and `cufile` features")
34}