#[macro_export]
macro_rules! program {
($device:ident) => {{
use $crate::rust_gpu_tools::{Framework, GPUError, Program};
(|device: &Device| -> Result<Program, $crate::EcError> {
let default_framework = device.framework();
let framework = match ::std::env::var("EC_GPU_FRAMEWORK") {
Ok(env) => match env.as_ref() {
"cuda" => {
#[cfg(feature = "cuda")]
{
Framework::Cuda
}
#[cfg(not(feature = "cuda"))]
return Err($crate::EcError::Simple("CUDA framework is not supported, please compile with the `cuda` feature enabled."))
}
"opencl" => {
#[cfg(feature = "opencl")]
{
Framework::Opencl
}
#[cfg(not(feature = "opencl"))]
return Err($crate::EcError::Simple("OpenCL framework is not supported, please compile with the `opencl` feature enabled."))
}
_ => default_framework,
},
Err(_) => default_framework,
};
match framework {
#[cfg(feature = "cuda")]
Framework::Cuda => {
let kernel = include_bytes!(env!("_EC_GPU_CUDA_KERNEL_FATBIN"));
let cuda_device = device.cuda_device().ok_or(GPUError::DeviceNotFound)?;
let program = $crate::rust_gpu_tools::cuda::Program::from_bytes(cuda_device, kernel)?;
Ok(Program::Cuda(program))
}
#[cfg(feature = "opencl")]
Framework::Opencl => {
let source = include_str!(env!("_EC_GPU_OPENCL_KERNEL_SOURCE"));
let opencl_device = device.opencl_device().ok_or(GPUError::DeviceNotFound)?;
let program = $crate::rust_gpu_tools::opencl::Program::from_opencl(opencl_device, source)?;
Ok(Program::Opencl(program))
}
}
})($device)
}};
}