use lazy_static::*; use ocl::ProQue; #[macro_use] lazy_static! { static ref BUFFER: ocl::Buffer = { let platform = ocl::Platform::default(); let device = ocl::Device::first(platform).unwrap(); let context = ocl::Context::builder() .platform(platform) .devices(device.clone()) .build() .unwrap(); let queue = ocl::Queue::new(&context, device, None).unwrap(); println!("created buffer!"); ocl::Buffer::builder() .queue(queue) .copy_host_slice(crate::solvers::PERMUTATIONS.1.as_ref()) .len(crate::solvers::PERMUTATIONS.1.len()) .build() .unwrap() }; static ref QUEUE: ocl::ProQue = { let src = std::fs::read_to_string("src/solvers/check.cl").expect("failed to open kernel file"); ProQue::builder() .src(src) .dims(crate::solvers::PERMUTATIONS.0.len()) .build() .unwrap() }; } pub fn get_buffer() -> &'static ocl::Buffer { &BUFFER } pub fn check(permutations: &[u64], w: u32, n: u32, mask: u64, offset: usize) -> ocl::Result<()> { //println!("read src!"); let src = std::fs::read_to_string("src/solvers/check.cl").expect("failed to open kernel file"); //println!("created queue!"); //println!("offset: {}", offset); //println!("length: {}", permutations.len() - offset); let pro_que = ProQue::builder() .src(src) .dims(permutations.len() - offset) .build()?; let results = pro_que.create_buffer::()?; let kernel = pro_que .kernel_builder("check") .arg(get_buffer()) .arg(&results) .arg(mask) .arg(n) .arg(w) .arg(offset as u64) //.global_work_offset(offset) .build()?; //println!("starting calculation"); unsafe { kernel.enq()?; } let mut vec = vec![0; results.len()]; results.read(&mut vec).enq()?; if vec.iter().any(|x| *x != 0) { println!("The resuts are now '{:?}'!", vec); } Ok(()) }