Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This library is now an abstraction for OpenCL and CUDA. It can be compiled with support for either or both, via the feature flags `opencl` and `cuda`. There is now a `Device`, which can point to an OpenCL and/or CUDA device. You should be able to execute OpenCL and CUDA kernels with the same code without modifications. You would pass in two closures with the same function body into `Program::run()`. To create two closures with the correct signature but the same body, you can use the `program_closures()` helper macro. So your code would look like this: use rust_gpu_tools::{cuda, program_closures, Device, GPUError, Program}; pub fn main() { let closures = program_closures!(|program, data: &[u8]| -> Result<Vec<u8>, GPUError> { let input = program.create_buffer_from_slice(data)?; let output = unsafe { program.create_buffer::<u8>(128)? }; let kernel = program.create_kernel("foo", 24, 4)?; kernel.arg(&input).arg(&output).run()?; let mut out = vec![0u8; 128]; program.read_into_buffer(&output, 0, &mut out)?; Ok(out) }); let cuda_device = Device::all().first().unwrap().cuda_device().unwrap(); let cuda_kernel_path = std::ffi::CString::new("/some/path").unwrap(); let cuda_program = cuda::Program::from_binary(cuda_device, &cuda_kernel_path).unwrap(); let program = Program::Cuda(cuda_program); let data = vec![5u8; 128]; let results = program.run(closures, &data).unwrap(); println!("results: {:?}", results); }
- Loading branch information