1use ocl;
2
3
4#[derive(Clone)]
6pub struct Context {
7 platform: ocl::Platform,
8 device: ocl::Device,
9 context: ocl::Context,
10 queue: ocl::Queue,
11}
12
13impl PartialEq for Context {
14 fn eq(&self, rhs: &Self) -> bool {
15 self.queue.as_core().as_ptr() == rhs.queue.as_core().as_ptr()
16 }
17}
18
19impl Context {
20 pub fn new(platform: ocl::Platform, device: ocl::Device) -> crate::Result<Self> {
21 let context = ocl::Context::builder()
22 .platform(platform)
23 .devices(device.clone())
24 .build()?;
25
26 let queue = ocl::Queue::new(&context, device, None)?;
27
28 Ok(Self { platform, device, context, queue })
29 }
30
31 pub fn platform(&self) -> &ocl::Platform {
32 &self.platform
33 }
34 pub fn device(&self) -> &ocl::Device {
35 &self.device
36 }
37 pub fn context(&self) -> &ocl::Context {
38 &self.context
39 }
40 pub fn queue(&self) -> &ocl::Queue {
41 &self.queue
42 }
43}