ocl_core/
lib.rs

1// ocl::core::
2
3//! Thin wrappers for the `OpenCL` FFI functions and types.
4//!
5//! Allows access to `OpenCL` FFI functions with a minimal layer of zero-cost
6//! abstraction, providing, safety, performance, and convenience. The [`ocl`]
7//! crate contains higher level and easier to use interfaces to the
8//! functionality contained within.
9//!
10//!
11//! ## Even Lower Level: [`cl-sys`]
12//!
13//! If there's still something missing or for some reason you need direct FFI
14//! access, use the functions in the [`cl-sys`] module. The pointers used by
15//! [`cl-sys`] functions can be wrapped in [`ocl-core`] wrappers
16//! (`ocl_core::PlatformId`, `ocl_core::Context`, etc.) and passed to
17//! [`ocl-core`] module functions. Likewise the other way around (using, for
18//! example: [`EventRaw::as_ptr`]).
19//!
20//!
21//! ## Performance
22//!
23//! Performance between all three interface layers, [`cl-sys`], [`ocl-core`],
24//! and the 'standard' ([`ocl`]) types, is identical or virtually identical
25//! (if not, please file an issue).
26//!
27//!
28//! ## Safety
29//!
30//! Running any kernel at all is inherently unsafe. The guarantee we aim to
31//! make in this library is that if there is a segfault or invalid memory
32//! access, the fault lies within the kernel. No effort is or will be made to
33//! verify or sanitize kernels. Consider all kernels within user-supplied
34//! programs just as if you would an `unsafe fn`.
35//!
36//!
37//! ## Length vs Size
38//!
39//! No, not that...
40//!
41//! Quantifiers passed to functions in the `OpenCL` API are generally
42//! expressed in bytes. Units passed to functions in *this* library are
43//! expected to be `bytes / sizeof(T)` (corresponding with units returned by
44//! the ubiquitous `.len()` method). The suffix '_size' or '_bytes' is
45//! generally used when a parameter deviates from this convention.
46//!
47//!
48//! ## Version Control
49//!
50//! The version control system is in place to ensure that you don't call
51//! functions that your hardware/driver does not support.
52//!
53//! Functions in this crate with the `[Version Controlled: OpenCL {...}+]` tag
54//! in the description require an additional parameter, `device_version` or
55//! `device_versions`: a parsed result (or slice of results) of
56//! `DeviceInfo::Version`. This is a runtime check to ensure that the device
57//! supports the function being called. Calling a function which a particular
58//! device does not support will likely cause a segmentation fault and
59//! possibly data corruption.
60//!
61//! Saving the `OpenclVersion` returned from `device_version()` for your
62//! device(s) at the start of your program and passing it each time you call
63//! a version controlled function is the fastest and safest method (see the
64//! `ocl` library for an example). The cost of this check is little more than
65//! a single `if` statement.
66//!
67//! Passing `None` for `device_version` will cause an automated version check
68//! which has a small cost (calling info function, parsing the version number
69//! etc.) but is a safe option if you are not sure what to do.
70//!
71//! Passing the result of a call to `OpenclVersion::max()` or passing a fake
72//! version will bypass any safety checks and has all of the risks described
73//! above. Only do this if you're absolutely sure you know what you're doing
74//! and are not concerned about segfaults and data integrity.
75//!
76
77//!
78//!
79//! ## More Documentation
80//!
81//! As most of the functions here are minimally documented, please refer to
82//! the official `OpenCL` documentation linked below. Although there isn't a
83//! precise 1:1 parameter mapping between the `core` and original functions,
84//! it's close enough (modulo the size/len difference discussed above) to help
85//! sort out any questions you may have until a more thorough documentation
86//! pass can be made. View the source code in [`src/types/functions.rs`] for
87//! more mapping details.
88//!
89//! ['OpenCL' 1.2 SDK Reference: https://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/]
90//!
91//!
92//!
93//!
94//!
95//!
96//! [`ocl`]: https://github.com/cogciprocate/ocl
97//! [`ocl-core`]: https://github.com/cogciprocate/ocl-core
98//! [`cl-sys`]: https://github.com/cogciprocate/cl-sys
99//! [issue]: https://github.com/cogciprocate/ocl-core/issues
100//! ['OpenCL' 1.2 SDK Reference: https://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/]: https://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/
101//! [`src/types/functions.rs`]: /ocl-core/src/ocl-core/src/types/functions.rs.html
102
103// #![doc(html_root_url="https://docs.rs/ocl-core/0.3/")]
104
105#[macro_use]
106extern crate bitflags;
107#[macro_use]
108extern crate enum_primitive;
109pub extern crate cl_sys as ffi;
110extern crate num_complex;
111extern crate num_traits;
112#[cfg(feature = "ocl-core-vector")]
113extern crate ocl_core_vector as vector;
114
115mod extension_functions;
116mod functions;
117#[cfg(test)]
118mod tests;
119pub use extension_functions::ExtensionFunctions;
120pub mod error;
121pub mod types;
122pub mod util;
123
124pub use self::error::{Error, Result};
125
126pub use self::types::abs::{
127    AsMem, ClContextPtr, ClDeviceIdPtr, ClEventPtrRef, ClNullEventPtr, ClPlatformIdPtr, ClVersions,
128    ClWaitListPtr, CommandQueue, Context, DeviceId, Event, EventRefWrapper, Kernel, Mem, MemCmdAll,
129    MemCmdRw, MemMap, PlatformId, Program, Sampler,
130};
131
132pub use self::types::structs::{
133    self, ArgVal, BufferRegion, ContextProperties, ContextPropertyValue, ImageDescriptor,
134    ImageFormat, ImageFormatParseError, ImageFormatParseResult, OpenclVersion,
135};
136
137pub use self::types::enums::{
138    CommandQueueInfoResult, ContextInfoResult, DeviceInfoResult, EmptyInfoResultError,
139    EventInfoResult, GlContextInfoResult, ImageInfoResult, KernelArgInfoResult, KernelInfoResult,
140    KernelWorkGroupInfoResult, MemInfoResult, PlatformInfoResult, ProfilingInfoResult,
141    ProgramBuildInfoResult, ProgramInfoResult, SamplerInfoResult,
142};
143
144pub use self::functions::{
145    _complete_user_event, _dummy_event_callback, build_program, compile_program, create_buffer,
146    create_build_program, create_command_queue, create_context, create_context_from_type,
147    create_image, create_kernel, create_kernels_in_program, create_program_with_binary,
148    create_program_with_built_in_kernels, create_program_with_source, create_sampler,
149    create_sub_buffer, create_sub_devices, create_user_event, default_device_type,
150    default_platform, default_platform_idx, device_versions, enqueue_barrier_with_wait_list,
151    enqueue_copy_buffer, enqueue_copy_buffer_rect, enqueue_copy_buffer_to_image,
152    enqueue_copy_image, enqueue_copy_image_to_buffer, enqueue_fill_image, enqueue_kernel,
153    enqueue_map_buffer, enqueue_map_image, enqueue_marker_with_wait_list,
154    enqueue_migrate_mem_objects, enqueue_native_kernel, enqueue_read_buffer,
155    enqueue_read_buffer_rect, enqueue_read_image, enqueue_task, enqueue_unmap_mem_object,
156    enqueue_write_buffer, enqueue_write_buffer_rect, enqueue_write_image, event_is_complete,
157    event_status, finish, flush, get_command_queue_info, get_context_info, get_context_platform,
158    get_device_ids, get_device_info, get_device_info_raw, get_event_info, get_event_profiling_info,
159    get_extension_function_address_for_platform, get_image_info, get_kernel_arg_info,
160    get_kernel_info, get_kernel_work_group_info, get_mem_object_info, get_platform_ids,
161    get_platform_info, get_program_build_info, get_program_info, get_sampler_info,
162    get_supported_image_formats, link_program, program_build_err, release_command_queue,
163    release_context, release_device, release_event, release_kernel, release_mem_object,
164    release_program, release_sampler, retain_command_queue, retain_context, retain_device,
165    retain_event, retain_kernel, retain_mem_object, retain_program, retain_sampler,
166    set_event_callback, set_kernel_arg, set_mem_object_destructor_callback, set_user_event_status,
167    verify_context, wait_for_event, wait_for_events,
168};
169
170#[cfg(not(feature = "opencl_vendor_mesa"))]
171pub use self::functions::{
172    create_from_gl_buffer, create_from_gl_renderbuffer, create_from_gl_texture,
173    create_from_gl_texture_2d, create_from_gl_texture_3d, enqueue_acquire_gl_objects,
174    enqueue_fill_buffer, enqueue_release_gl_objects, get_gl_context_info_khr,
175};
176
177pub use self::functions::{
178    create_from_d3d11_buffer, create_from_d3d11_texture2d, create_from_d3d11_texture3d,
179    enqueue_acquire_d3d11_objects, enqueue_release_d3d11_objects,
180};
181
182pub use crate::traits::{OclNum, OclPrm, OclScl};
183
184#[cfg(feature = "ocl-core-vector")]
185pub use self::vector::{
186    // pub use self::types::vector::{
187    Char,
188    Char16,
189    Char2,
190    Char3,
191    Char4,
192    Char8,
193    Double,
194    Double16,
195    Double2,
196    Double3,
197    Double4,
198    Double8,
199    Float,
200    Float16,
201    Float2,
202    Float3,
203    Float4,
204    Float8,
205    Int,
206    Int16,
207    Int2,
208    Int3,
209    Int4,
210    Int8,
211    Long,
212    Long16,
213    Long2,
214    Long3,
215    Long4,
216    Long8,
217    Short,
218    Short16,
219    Short2,
220    Short3,
221    Short4,
222    Short8,
223    Uchar,
224    Uchar16,
225    Uchar2,
226    Uchar3,
227    Uchar4,
228    Uchar8,
229    Uint,
230    Uint16,
231    Uint2,
232    Uint3,
233    Uint4,
234    Uint8,
235    Ulong,
236    Ulong16,
237    Ulong2,
238    Ulong3,
239    Ulong4,
240    Ulong8,
241    Ushort,
242    Ushort16,
243    Ushort2,
244    Ushort3,
245    Ushort4,
246    Ushort8,
247};
248
249#[cfg(feature = "ocl-core-vector")]
250pub use crate::traits::OclVec;
251
252#[cfg(feature = "opencl_version_2_1")]
253pub use self::functions::create_program_with_il;
254
255//=============================================================================
256//================================ CONSTANTS ==================================
257//=============================================================================
258
259pub const DEVICES_MAX: u32 = 64;
260
261//=============================================================================
262//================================= TYPEDEFS ==================================
263//=============================================================================
264
265pub type EventCallbackFn = extern "C" fn(ffi::cl_event, i32, *mut ffi::c_void);
266pub type CreateContextCallbackFn =
267    extern "C" fn(*const ffi::c_char, *const ffi::c_void, ffi::size_t, *mut ffi::c_void);
268pub type BuildProgramCallbackFn = extern "C" fn(*mut ffi::c_void, *mut ffi::c_void);
269pub type UserDataPtr = *mut ffi::c_void;
270
271//=============================================================================
272//================================== TRAITS ===================================
273//=============================================================================
274
275mod traits {
276    use num_complex::{Complex32, Complex64};
277    use num_traits::{FromPrimitive, NumCast, One, ToPrimitive, Zero};
278    use std::fmt::{Debug, Display};
279    use std::iter::{Product, Sum};
280    use std::ops::*;
281
282    // Implements an unsafe trait for a list of types.
283    macro_rules! impl_unsafe {
284        ($trt:ident: $( $ty:ident ),+) => {
285            $( unsafe impl $trt for $ty {} )+
286        }
287    }
288
289    #[cfg(feature = "ocl-core-vector")]
290    pub use self::ocl_vec::OclVec;
291
292    /// A primitive type usable within `OpenCL` kernels.
293    ///
294    /// Includes all of the signed, unsigned, and floating point 8 bit - 64 bit
295    /// scalar primitives (ex.: cl_char, cl_uint, cl_double) (exception: cl_half)
296    /// and their vector counterparts (ex.: cl_int4, cl_float3, cl_short16);
297    ///
298    /// Can also be implemented for custom types as long as layout and
299    /// alignment are conserved between Rust and OpenCL (repr "C").
300    pub unsafe trait OclPrm:
301        Debug + Clone + Copy + Default + PartialEq + Send + Sync + 'static
302    {
303    }
304
305    impl_unsafe!(
306        OclPrm: u8,
307        i8,
308        u16,
309        i16,
310        u32,
311        i32,
312        u64,
313        i64,
314        usize,
315        isize,
316        f32,
317        f64,
318        Complex32,
319        Complex64
320    );
321
322    /// A set of traits common to numeric built-in OpenCL scalar and vector
323    /// primitives.
324    ///
325    /// To describe the contents of buffers, etc., prefer using the more general
326    /// `OclPrm` trait unless numeric operations are required.
327    pub unsafe trait OclNum:
328        Debug
329        + Display
330        + Clone
331        + Copy
332        + Default
333        + PartialOrd
334        + Zero<Output = Self>
335        + One<Output = Self>
336        + Add<Self, Output = Self>
337        + Sub<Self, Output = Self>
338        + Mul<Self, Output = Self>
339        + Div<Self, Output = Self>
340        + Rem<Self, Output = Self>
341        + PartialEq<Self>
342        + AddAssign<Self>
343        + SubAssign<Self>
344        + MulAssign<Self>
345        + DivAssign<Self>
346        + RemAssign<Self>
347        + Sum<Self>
348        + Product<Self>
349        + Send
350        + Sync
351        + 'static
352    {
353    }
354
355    impl_unsafe!(
356        OclNum: u8,
357        i8,
358        u16,
359        i16,
360        u32,
361        i32,
362        u64,
363        i64,
364        usize,
365        isize,
366        f32,
367        f64
368    );
369
370    /// A scalar type usable within OpenCL kernels.
371    ///
372    /// To describe the contents of buffers, etc., prefer using the more general
373    /// `OclPrm` trait unless numeric operations are required.
374    pub unsafe trait OclScl:
375        OclPrm + OclNum + NumCast + FromPrimitive + ToPrimitive
376    {
377    }
378
379    impl_unsafe!(
380        OclScl: u8,
381        i8,
382        u16,
383        i16,
384        u32,
385        i32,
386        u64,
387        i64,
388        usize,
389        isize,
390        f32,
391        f64
392    );
393
394    #[cfg(feature = "ocl-core-vector")]
395    mod ocl_vec {
396        use crate::traits::{OclNum, OclPrm};
397
398        /// A vector type usable within `OpenCL` kernels.
399        ///
400        /// To describe the contents of buffers, etc., prefer using the more general
401        /// `OclPrm` trait unless numeric operations are required.
402        pub unsafe trait OclVec: OclPrm + OclNum {}
403
404        use crate::vector::{
405            Char, Char16, Char2, Char3, Char4, Char8, Double, Double16, Double2, Double3, Double4,
406            Double8, Float, Float16, Float2, Float3, Float4, Float8, Int, Int16, Int2, Int3, Int4,
407            Int8, Long, Long16, Long2, Long3, Long4, Long8, Short, Short16, Short2, Short3, Short4,
408            Short8, Uchar, Uchar16, Uchar2, Uchar3, Uchar4, Uchar8, Uint, Uint16, Uint2, Uint3,
409            Uint4, Uint8, Ulong, Ulong16, Ulong2, Ulong3, Ulong4, Ulong8, Ushort, Ushort16,
410            Ushort2, Ushort3, Ushort4, Ushort8,
411        };
412
413        impl_unsafe!(
414            OclNum: Char,
415            Char2,
416            Char3,
417            Char4,
418            Char8,
419            Char16,
420            Uchar,
421            Uchar2,
422            Uchar3,
423            Uchar4,
424            Uchar8,
425            Uchar16,
426            Short,
427            Short2,
428            Short3,
429            Short4,
430            Short8,
431            Short16,
432            Ushort,
433            Ushort2,
434            Ushort3,
435            Ushort4,
436            Ushort8,
437            Ushort16,
438            Int,
439            Int2,
440            Int3,
441            Int4,
442            Int8,
443            Int16,
444            Uint,
445            Uint2,
446            Uint3,
447            Uint4,
448            Uint8,
449            Uint16,
450            Long,
451            Long2,
452            Long3,
453            Long4,
454            Long8,
455            Long16,
456            Ulong,
457            Ulong2,
458            Ulong3,
459            Ulong4,
460            Ulong8,
461            Ulong16,
462            Float,
463            Float2,
464            Float3,
465            Float4,
466            Float8,
467            Float16,
468            Double,
469            Double2,
470            Double3,
471            Double4,
472            Double8,
473            Double16
474        );
475
476        impl_unsafe!(
477            OclPrm: Char,
478            Char2,
479            Char3,
480            Char4,
481            Char8,
482            Char16,
483            Uchar,
484            Uchar2,
485            Uchar3,
486            Uchar4,
487            Uchar8,
488            Uchar16,
489            Short,
490            Short2,
491            Short3,
492            Short4,
493            Short8,
494            Short16,
495            Ushort,
496            Ushort2,
497            Ushort3,
498            Ushort4,
499            Ushort8,
500            Ushort16,
501            Int,
502            Int2,
503            Int3,
504            Int4,
505            Int8,
506            Int16,
507            Uint,
508            Uint2,
509            Uint3,
510            Uint4,
511            Uint8,
512            Uint16,
513            Long,
514            Long2,
515            Long3,
516            Long4,
517            Long8,
518            Long16,
519            Ulong,
520            Ulong2,
521            Ulong3,
522            Ulong4,
523            Ulong8,
524            Ulong16,
525            Float,
526            Float2,
527            Float3,
528            Float4,
529            Float8,
530            Float16,
531            Double,
532            Double2,
533            Double3,
534            Double4,
535            Double8,
536            Double16
537        );
538
539        impl_unsafe!(
540            OclVec: Char,
541            Char2,
542            Char3,
543            Char4,
544            Char8,
545            Char16,
546            Uchar,
547            Uchar2,
548            Uchar3,
549            Uchar4,
550            Uchar8,
551            Uchar16,
552            Short,
553            Short2,
554            Short3,
555            Short4,
556            Short8,
557            Short16,
558            Ushort,
559            Ushort2,
560            Ushort3,
561            Ushort4,
562            Ushort8,
563            Ushort16,
564            Int,
565            Int2,
566            Int3,
567            Int4,
568            Int8,
569            Int16,
570            Uint,
571            Uint2,
572            Uint3,
573            Uint4,
574            Uint8,
575            Uint16,
576            Long,
577            Long2,
578            Long3,
579            Long4,
580            Long8,
581            Long16,
582            Ulong,
583            Ulong2,
584            Ulong3,
585            Ulong4,
586            Ulong8,
587            Ulong16,
588            Float,
589            Float2,
590            Float3,
591            Float4,
592            Float8,
593            Float16,
594            Double,
595            Double2,
596            Double3,
597            Double4,
598            Double8,
599            Double16
600        );
601    }
602}
603
604//=============================================================================
605//================================ BITFIELDS ==================================
606//=============================================================================
607
608bitflags! {
609    /// cl_device_type - bitfield
610    ///
611    /// * `CL_DEVICE_TYPE_DEFAULT`: The default `OpenCL` device in the system.
612    /// * `CL_DEVICE_TYPE_CPU`: An `OpenCL` device that is the host processor.
613    ///   The host processor runs the `OpenCL` implementations and is a single
614    ///   or multi-core CPU.
615    /// * `CL_DEVICE_TYPE_GPU`: An `OpenCL` device that is a GPU. By this we
616    ///   mean that the device can also be used to accelerate a 3D API such as
617    ///   OpenGL or DirectX.
618    /// * `CL_DEVICE_TYPE_ACCELERATOR`: Dedicated `OpenCL` accelerators (for
619    ///   example the IBM CELL Blade). These devices communicate with the host
620    ///   processor using a peripheral interconnect such as PCIe.
621    /// * `CL_DEVICE_TYPE_ALL`: A union of all flags.
622    ///
623    pub struct DeviceType: u64 {
624        const DEFAULT = 1;
625        const CPU = 1 << 1;
626        const GPU = 1 << 2;
627        const ACCELERATOR = 1 << 3;
628        const CUSTOM = 1 << 4;
629        const ALL = 0xFFFF_FFFF;
630    }
631}
632
633impl DeviceType {
634    #[inline]
635    pub fn new() -> DeviceType {
636        DeviceType::empty()
637    }
638    #[inline]
639    pub fn system_default(self) -> DeviceType {
640        self | DeviceType::DEFAULT
641    }
642    #[inline]
643    pub fn cpu(self) -> DeviceType {
644        self | DeviceType::CPU
645    }
646    #[inline]
647    pub fn gpu(self) -> DeviceType {
648        self | DeviceType::GPU
649    }
650    #[inline]
651    pub fn accelerator(self) -> DeviceType {
652        self | DeviceType::ACCELERATOR
653    }
654    #[inline]
655    pub fn custom(self) -> DeviceType {
656        self | DeviceType::CUSTOM
657    }
658    // #[inline] pub fn all() -> DeviceType { DeviceType::ALL }
659}
660
661impl Default for DeviceType {
662    #[inline]
663    fn default() -> DeviceType {
664        DeviceType::ALL
665    }
666}
667
668pub const DEVICE_TYPE_DEFAULT: DeviceType = DeviceType::DEFAULT;
669pub const DEVICE_TYPE_CPU: DeviceType = DeviceType::CPU;
670pub const DEVICE_TYPE_GPU: DeviceType = DeviceType::GPU;
671pub const DEVICE_TYPE_ACCELERATOR: DeviceType = DeviceType::ACCELERATOR;
672pub const DEVICE_TYPE_CUSTOM: DeviceType = DeviceType::CUSTOM;
673pub const DEVICE_TYPE_ALL: DeviceType = DeviceType::ALL;
674
675bitflags! {
676    /// cl_device_fp_config - bitfield
677    pub struct DeviceFpConfig: u64 {
678        const DENORM = 1;
679        const INF_NAN = 1 << 1;
680        const ROUND_TO_NEAREST = 1 << 2;
681        const ROUND_TO_ZERO = 1 << 3;
682        const ROUND_TO_INF = 1 << 4;
683        const FMA = 1 << 5;
684        const SOFT_FLOAT = 1 << 6;
685        const CORRECTLY_ROUNDED_DIVIDE_SQRT = 1 << 7;
686    }
687}
688
689pub const FP_DENORM: DeviceFpConfig = DeviceFpConfig::DENORM;
690pub const FP_INF_NAN: DeviceFpConfig = DeviceFpConfig::INF_NAN;
691pub const FP_ROUND_TO_NEAREST: DeviceFpConfig = DeviceFpConfig::ROUND_TO_NEAREST;
692pub const FP_ROUND_TO_ZERO: DeviceFpConfig = DeviceFpConfig::ROUND_TO_ZERO;
693pub const FP_ROUND_TO_INF: DeviceFpConfig = DeviceFpConfig::ROUND_TO_INF;
694pub const FP_FMA: DeviceFpConfig = DeviceFpConfig::FMA;
695pub const FP_SOFT_FLOAT: DeviceFpConfig = DeviceFpConfig::SOFT_FLOAT;
696pub const FP_CORRECTLY_ROUNDED_DIVIDE_SQRT: DeviceFpConfig =
697    DeviceFpConfig::CORRECTLY_ROUNDED_DIVIDE_SQRT;
698
699bitflags! {
700    /// cl_device_exec_capabilities - bitfield
701    pub struct DeviceExecCapabilities: u64 {
702        const KERNEL = 1;
703        const NATIVE_KERNEL = 1 << 1;
704    }
705}
706
707pub const EXEC_KERNEL: DeviceExecCapabilities = DeviceExecCapabilities::KERNEL;
708pub const EXEC_NATIVE_KERNEL: DeviceExecCapabilities = DeviceExecCapabilities::NATIVE_KERNEL;
709
710bitflags! {
711    /// cl_command_queue_properties - bitfield
712    pub struct CommandQueueProperties: u64 {
713        const OUT_OF_ORDER_EXEC_MODE_ENABLE = 1;
714        const PROFILING_ENABLE = 1 << 1;
715        const ON_DEVICE = 1 << 2;
716        const ON_DEVICE_DEFAULT = 1 << 3;
717    }
718}
719
720impl CommandQueueProperties {
721    #[inline]
722    pub fn new() -> CommandQueueProperties {
723        CommandQueueProperties::empty()
724    }
725    #[inline]
726    pub fn out_of_order(self) -> CommandQueueProperties {
727        self | CommandQueueProperties::OUT_OF_ORDER_EXEC_MODE_ENABLE
728    }
729    #[inline]
730    pub fn profiling(self) -> CommandQueueProperties {
731        self | CommandQueueProperties::PROFILING_ENABLE
732    }
733}
734
735impl Default for CommandQueueProperties {
736    #[inline]
737    fn default() -> CommandQueueProperties {
738        CommandQueueProperties::empty()
739    }
740}
741
742pub const QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE: CommandQueueProperties =
743    CommandQueueProperties::OUT_OF_ORDER_EXEC_MODE_ENABLE;
744pub const QUEUE_PROFILING_ENABLE: CommandQueueProperties = CommandQueueProperties::PROFILING_ENABLE;
745pub const QUEUE_ON_DEVICE: CommandQueueProperties = CommandQueueProperties::ON_DEVICE;
746pub const QUEUE_ON_DEVICE_DEFAULT: CommandQueueProperties =
747    CommandQueueProperties::ON_DEVICE_DEFAULT;
748
749bitflags! {
750    /// cl_device_affinity_domain
751    pub struct DeviceAffinityDomain: u64 {
752        const NUMA = 1;
753        const L4_CACHE = 1 << 1;
754        const L3_CACHE = 1 << 2;
755        const L2_CACHE = 1 << 3;
756        const L1_CACHE = 1 << 4;
757        const NEXT_PARTITIONABLE = 1 << 5;
758    }
759}
760
761pub const DEVICE_AFFINITY_DOMAIN_NUMA: DeviceAffinityDomain = DeviceAffinityDomain::NUMA;
762pub const DEVICE_AFFINITY_DOMAIN_L4_CACHE: DeviceAffinityDomain = DeviceAffinityDomain::L4_CACHE;
763pub const DEVICE_AFFINITY_DOMAIN_L3_CACHE: DeviceAffinityDomain = DeviceAffinityDomain::L3_CACHE;
764pub const DEVICE_AFFINITY_DOMAIN_L2_CACHE: DeviceAffinityDomain = DeviceAffinityDomain::L2_CACHE;
765pub const DEVICE_AFFINITY_DOMAIN_L1_CACHE: DeviceAffinityDomain = DeviceAffinityDomain::L1_CACHE;
766pub const DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE: DeviceAffinityDomain =
767    DeviceAffinityDomain::NEXT_PARTITIONABLE;
768
769bitflags! {
770    /// cl_mem_flags - bitfield
771    pub struct MemFlags: u64 {
772        const READ_WRITE = 1;
773        const WRITE_ONLY = 1 << 1;
774        const READ_ONLY = 1 << 2;
775        const USE_HOST_PTR = 1 << 3;
776        const ALLOC_HOST_PTR = 1 << 4;
777        const COPY_HOST_PTR = 1 << 5;
778        // RESERVED            1<< 6;
779        const HOST_WRITE_ONLY = 1 << 7;
780        const HOST_READ_ONLY = 1 << 8;
781        const HOST_NO_ACCESS = 1 << 9;
782    }
783}
784
785impl MemFlags {
786    #[inline]
787    pub fn new() -> MemFlags {
788        MemFlags::empty()
789    }
790    #[inline]
791    pub fn read_write(self) -> MemFlags {
792        self | MemFlags::READ_WRITE
793    }
794    #[inline]
795    pub fn write_only(self) -> MemFlags {
796        self | MemFlags::WRITE_ONLY
797    }
798    #[inline]
799    pub fn read_only(self) -> MemFlags {
800        self | MemFlags::READ_ONLY
801    }
802    #[inline]
803    pub fn use_host_ptr(self) -> MemFlags {
804        self | MemFlags::USE_HOST_PTR
805    }
806    #[inline]
807    pub fn alloc_host_ptr(self) -> MemFlags {
808        self | MemFlags::ALLOC_HOST_PTR
809    }
810    #[inline]
811    pub fn copy_host_ptr(self) -> MemFlags {
812        self | MemFlags::COPY_HOST_PTR
813    }
814    #[inline]
815    pub fn host_write_only(self) -> MemFlags {
816        self | MemFlags::HOST_WRITE_ONLY
817    }
818    #[inline]
819    pub fn host_read_only(self) -> MemFlags {
820        self | MemFlags::HOST_READ_ONLY
821    }
822    #[inline]
823    pub fn host_no_access(self) -> MemFlags {
824        self | MemFlags::HOST_NO_ACCESS
825    }
826}
827
828impl Default for MemFlags {
829    #[inline]
830    fn default() -> MemFlags {
831        MemFlags::READ_WRITE
832    }
833}
834
835pub const MEM_READ_WRITE: MemFlags = MemFlags::READ_WRITE;
836pub const MEM_WRITE_ONLY: MemFlags = MemFlags::WRITE_ONLY;
837pub const MEM_READ_ONLY: MemFlags = MemFlags::READ_ONLY;
838pub const MEM_USE_HOST_PTR: MemFlags = MemFlags::USE_HOST_PTR;
839pub const MEM_ALLOC_HOST_PTR: MemFlags = MemFlags::ALLOC_HOST_PTR;
840pub const MEM_COPY_HOST_PTR: MemFlags = MemFlags::COPY_HOST_PTR;
841// RESERVED            1<< 6;
842pub const MEM_HOST_WRITE_ONLY: MemFlags = MemFlags::HOST_WRITE_ONLY;
843pub const MEM_HOST_READ_ONLY: MemFlags = MemFlags::HOST_READ_ONLY;
844pub const MEM_HOST_NO_ACCESS: MemFlags = MemFlags::HOST_NO_ACCESS;
845
846bitflags! {
847    /// cl_mem_migration_flags - bitfield
848    pub struct MemMigrationFlags: u64 {
849        const OBJECT_HOST = 1;
850        const OBJECT_CONTENT_UNDEFINED = 1 << 1;
851    }
852}
853
854pub const MIGRATE_MEM_OBJECT_HOST: MemMigrationFlags = MemMigrationFlags::OBJECT_HOST;
855pub const MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED: MemMigrationFlags =
856    MemMigrationFlags::OBJECT_CONTENT_UNDEFINED;
857
858bitflags! {
859    /// cl_map_flags - bitfield
860    pub struct MapFlags: u64 {
861        const READ = 1;
862        const WRITE = 1 << 1;
863        const WRITE_INVALIDATE_REGION = 1 << 2;
864    }
865}
866
867impl MapFlags {
868    #[inline]
869    pub fn new() -> MapFlags {
870        MapFlags::empty()
871    }
872    #[inline]
873    pub fn read(self) -> MapFlags {
874        self | MapFlags::READ
875    }
876    #[inline]
877    pub fn write(self) -> MapFlags {
878        self | MapFlags::WRITE
879    }
880    #[inline]
881    pub fn write_invalidate_region(self) -> MapFlags {
882        self | MapFlags::WRITE_INVALIDATE_REGION
883    }
884}
885
886impl Default for MapFlags {
887    #[inline]
888    fn default() -> MapFlags {
889        MapFlags::empty()
890    }
891}
892
893pub const MAP_READ: MapFlags = MapFlags::READ;
894pub const MAP_WRITE: MapFlags = MapFlags::WRITE;
895pub const MAP_WRITE_INVALIDATE_REGION: MapFlags = MapFlags::WRITE_INVALIDATE_REGION;
896
897bitflags! {
898    /// cl_program_binary_type
899    pub struct ProgramBinaryType: u32 {
900        const NONE = 0x0;
901        const COMPILED_OBJECT = 0x1;
902        const LIBRARY = 0x2;
903        const EXECUTABLE = 0x4;
904    }
905}
906
907pub const PROGRAM_BINARY_TYPE_NONE: ProgramBinaryType = ProgramBinaryType::NONE;
908pub const PROGRAM_BINARY_TYPE_COMPILED_OBJECT: ProgramBinaryType =
909    ProgramBinaryType::COMPILED_OBJECT;
910pub const PROGRAM_BINARY_TYPE_LIBRARY: ProgramBinaryType = ProgramBinaryType::LIBRARY;
911pub const PROGRAM_BINARY_TYPE_EXECUTABLE: ProgramBinaryType = ProgramBinaryType::EXECUTABLE;
912
913bitflags! {
914    /// cl_kernel_arg_type_qualifer
915    pub struct KernelArgTypeQualifier: u64 {
916        const NONE = 0;
917        const CONST = 1;
918        const RESTRICT = 1 << 1;
919        const VOLATILE = 1 << 2;
920    }
921}
922
923pub const KERNEL_ARG_TYPE_NONE: KernelArgTypeQualifier = KernelArgTypeQualifier::NONE;
924pub const KERNEL_ARG_TYPE_CONST: KernelArgTypeQualifier = KernelArgTypeQualifier::CONST;
925pub const KERNEL_ARG_TYPE_RESTRICT: KernelArgTypeQualifier = KernelArgTypeQualifier::RESTRICT;
926pub const KERNEL_ARG_TYPE_VOLATILE: KernelArgTypeQualifier = KernelArgTypeQualifier::VOLATILE;
927
928//=============================================================================
929//=============================== ENUMERATORS =================================
930//=============================================================================
931
932// #[derive(PartialEq, Debug, FromPrimitive)]
933enum_from_primitive! {
934    /// The status of an OpenCL API call. Used for returning success/error codes.
935    #[allow(non_camel_case_types)]
936    #[repr(C)]
937    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
938    pub enum Status {
939        CL_SUCCESS                                      = 0,
940        CL_DEVICE_NOT_FOUND                             = -1,
941        CL_DEVICE_NOT_AVAILABLE                         = -2,
942        CL_COMPILER_NOT_AVAILABLE                       = -3,
943        CL_MEM_OBJECT_ALLOCATION_FAILURE                = -4,
944        CL_OUT_OF_RESOURCES                             = -5,
945        CL_OUT_OF_HOST_MEMORY                           = -6,
946        CL_PROFILING_INFO_NOT_AVAILABLE                 = -7,
947        CL_MEM_COPY_OVERLAP                             = -8,
948        CL_IMAGE_FORMAT_MISMATCH                        = -9,
949        CL_IMAGE_FORMAT_NOT_SUPPORTED                   = -10,
950        CL_BUILD_PROGRAM_FAILURE                        = -11,
951        CL_MAP_FAILURE                                  = -12,
952        CL_MISALIGNED_SUB_BUFFER_OFFSET                 = -13,
953        CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST    = -14,
954        CL_COMPILE_PROGRAM_FAILURE                      = -15,
955        CL_LINKER_NOT_AVAILABLE                         = -16,
956        CL_LINK_PROGRAM_FAILURE                         = -17,
957        CL_DEVICE_PARTITION_FAILED                      = -18,
958        CL_KERNEL_ARG_INFO_NOT_AVAILABLE                = -19,
959        CL_INVALID_VALUE                                = -30,
960        CL_INVALID_DEVICE_TYPE                          = -31,
961        CL_INVALID_PLATFORM                             = -32,
962        CL_INVALID_DEVICE                               = -33,
963        CL_INVALID_CONTEXT                              = -34,
964        CL_INVALID_QUEUE_PROPERTIES                     = -35,
965        CL_INVALID_COMMAND_QUEUE                        = -36,
966        CL_INVALID_HOST_PTR                             = -37,
967        CL_INVALID_MEM_OBJECT                           = -38,
968        CL_INVALID_IMAGE_FORMAT_DESCRIPTOR              = -39,
969        CL_INVALID_IMAGE_SIZE                           = -40,
970        CL_INVALID_SAMPLER                              = -41,
971        CL_INVALID_BINARY                               = -42,
972        CL_INVALID_BUILD_OPTIONS                        = -43,
973        CL_INVALID_PROGRAM                              = -44,
974        CL_INVALID_PROGRAM_EXECUTABLE                   = -45,
975        CL_INVALID_KERNEL_NAME                          = -46,
976        CL_INVALID_KERNEL_DEFINITION                    = -47,
977        CL_INVALID_KERNEL                               = -48,
978        CL_INVALID_ARG_INDEX                            = -49,
979        CL_INVALID_ARG_VALUE                            = -50,
980        CL_INVALID_ARG_SIZE                             = -51,
981        CL_INVALID_KERNEL_ARGS                          = -52,
982        CL_INVALID_WORK_DIMENSION                       = -53,
983        CL_INVALID_WORK_GROUP_SIZE                      = -54,
984        CL_INVALID_WORK_ITEM_SIZE                       = -55,
985        CL_INVALID_GLOBAL_OFFSET                        = -56,
986        CL_INVALID_EVENT_WAIT_LIST                      = -57,
987        CL_INVALID_EVENT                                = -58,
988        CL_INVALID_OPERATION                            = -59,
989        CL_INVALID_GL_OBJECT                            = -60,
990        CL_INVALID_BUFFER_SIZE                          = -61,
991        CL_INVALID_MIP_LEVEL                            = -62,
992        CL_INVALID_GLOBAL_WORK_SIZE                     = -63,
993        CL_INVALID_PROPERTY                             = -64,
994        CL_INVALID_IMAGE_DESCRIPTOR                     = -65,
995        CL_INVALID_COMPILER_OPTIONS                     = -66,
996        CL_INVALID_LINKER_OPTIONS                       = -67,
997        CL_INVALID_DEVICE_PARTITION_COUNT               = -68,
998        CL_INVALID_PIPE_SIZE                            = -69,
999        CL_INVALID_DEVICE_QUEUE                         = -70,
1000        CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR          = -1000,
1001        CL_PLATFORM_NOT_FOUND_KHR                       = -1001,
1002        CL_NV_INVALID_MEM_ACCESS                        = -9999,
1003    }
1004}
1005
1006impl std::fmt::Display for Status {
1007    fn fmt(&self, fmtr: &mut std::fmt::Formatter) -> std::fmt::Result {
1008        write!(fmtr, "{:?}", self)
1009    }
1010}
1011
1012enum_from_primitive! {
1013    /// specify the texture target type
1014    #[repr(C)]
1015    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1016    pub enum GlTextureTarget {
1017        GlTexture1d = ffi::GL_TEXTURE_1D as isize,
1018        GlTexture1dArray = ffi::GL_TEXTURE_1D_ARRAY as isize,
1019        GlTextureBuffer = ffi::GL_TEXTURE_BUFFER as isize,
1020        GlTexture2d = ffi::GL_TEXTURE_2D as isize,
1021        GlTexture2dArray = ffi::GL_TEXTURE_2D_ARRAY as isize,
1022        GlTexture3d = ffi::GL_TEXTURE_3D as isize,
1023        GlTextureCubeMapPositiveX = ffi::GL_TEXTURE_CUBE_MAP_POSITIVE_X as isize,
1024        GlTextureCubeMapPositiveY = ffi::GL_TEXTURE_CUBE_MAP_POSITIVE_Y as isize,
1025        GlTextureCubeMapPositiveZ = ffi::GL_TEXTURE_CUBE_MAP_POSITIVE_Z as isize,
1026        GlTextureCubeMapNegativeX = ffi::GL_TEXTURE_CUBE_MAP_NEGATIVE_X as isize,
1027        GlTextureCubeMapNegativeY = ffi::GL_TEXTURE_CUBE_MAP_NEGATIVE_Y as isize,
1028        GlTextureCubeMapNegativeZ = ffi::GL_TEXTURE_CUBE_MAP_NEGATIVE_Z as isize,
1029        GlTextureRectangle = ffi::GL_TEXTURE_RECTANGLE as isize,
1030    }
1031}
1032
1033enum_from_primitive! {
1034    // cl_gl_object_type = 0x2000 - 0x200F enum values are currently taken
1035    #[repr(C)]
1036    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1037    pub enum ClGlObjectType {
1038        ClGlObjectBuffer = ffi::CL_GL_OBJECT_BUFFER as isize,
1039        ClGlObjectTexture2D = ffi::CL_GL_OBJECT_TEXTURE2D as isize,
1040        ClGlObjectTexture3D = ffi::CL_GL_OBJECT_TEXTURE3D as isize,
1041        ClGlObjectRenderbuffer = ffi::CL_GL_OBJECT_RENDERBUFFER as isize,
1042        ClGlObjectTexture2DArray = ffi::CL_GL_OBJECT_TEXTURE2D_ARRAY as isize,
1043        ClGlObjectTexture1D = ffi::CL_GL_OBJECT_TEXTURE1D as isize,
1044        ClGlObjectTexture1DArray = ffi::CL_GL_OBJECT_TEXTURE1D_ARRAY as isize,
1045        ClGlObjectTextureBuffer = ffi::CL_GL_OBJECT_TEXTURE_BUFFER as isize,
1046    }
1047}
1048
1049enum_from_primitive! {
1050    /// Specifies the number of channels and the channel layout i.e. the memory layout in which channels are stored in the image. Valid values are described in the table below. (from SDK)
1051    #[repr(C)]
1052    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1053    pub enum ImageChannelOrder {
1054        R = ffi::CL_R as isize,
1055        A = ffi::CL_A as isize,
1056        Rg = ffi::CL_RG as isize,
1057        Ra = ffi::CL_RA as isize,
1058        // This format can only be used if channel data type = CL_UNORM_SHORT_565, CL_UNORM_SHORT_555 or CL_UNORM_INT101010:
1059        Rgb = ffi::CL_RGB as isize,
1060        Rgba = ffi::CL_RGBA as isize,
1061        // This format can only be used if channel data type = CL_UNORM_INT8, CL_SNORM_INT8, CL_SIGNED_INT8 or CL_UNSIGNED_INT8:
1062        Bgra = ffi::CL_BGRA as isize,
1063        // This format can only be used if channel data type = CL_UNORM_INT8, CL_SNORM_INT8, CL_SIGNED_INT8 or CL_UNSIGNED_INT8:
1064        Argb = ffi::CL_ARGB as isize,
1065        // This format can only be used if channel data type = CL_UNORM_INT8, CL_UNORM_INT16, CL_SNORM_INT8, CL_SNORM_INT16, CL_HALF_FLOAT, or CL_FLOAT:
1066        Intensity = ffi::CL_INTENSITY as isize,
1067        // This format can only be used if channel data type = CL_UNORM_INT8, CL_UNORM_INT16, CL_SNORM_INT8, CL_SNORM_INT16, CL_HALF_FLOAT, or CL_FLOAT:
1068        Luminance = ffi::CL_LUMINANCE as isize,
1069        Rx = ffi::CL_Rx as isize,
1070        Rgx = ffi::CL_RGx as isize,
1071        // This format can only be used if channel data type = CL_UNORM_SHORT_565, CL_UNORM_SHORT_555 or CL_UNORM_INT101010:
1072        Rgbx = ffi::CL_RGBx as isize,
1073        Depth = ffi::CL_DEPTH as isize,
1074        DepthStencil = ffi::CL_DEPTH_STENCIL as isize,
1075    }
1076}
1077
1078enum_from_primitive! {
1079    /// Describes the size of the channel data type. The number of bits per element determined by the image_channel_data_type and image_channel_order must be a power of two. The list of supported values is described in the table below. (from SDK)
1080    #[repr(C)]
1081    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1082    pub enum ImageChannelDataType {
1083        // Each channel component is a normalized signed 8-bit integer value:
1084        SnormInt8 = ffi::CL_SNORM_INT8 as isize,
1085        // Each channel component is a normalized signed 16-bit integer value:
1086        SnormInt16 = ffi::CL_SNORM_INT16 as isize,
1087        // Each channel component is a normalized unsigned 8-bit integer value:
1088        UnormInt8 = ffi::CL_UNORM_INT8 as isize,
1089        // Each channel component is a normalized unsigned 16-bit integer value:
1090        UnormInt16 = ffi::CL_UNORM_INT16 as isize,
1091        // Represents a normalized 5-6-5 3-channel RGB image. The channel order must be CL_RGB or CL_RGBx:
1092        UnormShort565 = ffi::CL_UNORM_SHORT_565 as isize,
1093        // Represents a normalized x-5-5-5 4-channel xRGB image. The channel order must be CL_RGB or CL_RGBx:
1094        UnormShort555 = ffi::CL_UNORM_SHORT_555 as isize,
1095        // Represents a normalized x-10-10-10 4-channel xRGB image. The channel order must be CL_RGB or CL_RGBx:
1096        UnormInt101010 = ffi::CL_UNORM_INT_101010 as isize,
1097        // Each channel component is an unnormalized signed 8-bit integer value:
1098        SignedInt8 = ffi::CL_SIGNED_INT8 as isize,
1099        // Each channel component is an unnormalized signed 16-bit integer value:
1100        SignedInt16 = ffi::CL_SIGNED_INT16 as isize,
1101        // Each channel component is an unnormalized signed 32-bit integer value:
1102        SignedInt32 = ffi::CL_SIGNED_INT32 as isize,
1103        // Each channel component is an unnormalized unsigned 8-bit integer value:
1104        UnsignedInt8 = ffi::CL_UNSIGNED_INT8 as isize,
1105        // Each channel component is an unnormalized unsigned 16-bit integer value:
1106        UnsignedInt16 = ffi::CL_UNSIGNED_INT16 as isize,
1107        // Each channel component is an unnormalized unsigned 32-bit integer value:
1108        UnsignedInt32 = ffi::CL_UNSIGNED_INT32 as isize,
1109        // Each channel component is a 16-bit half-float value:
1110        HalfFloat = ffi::CL_HALF_FLOAT as isize,
1111        // Each channel component is a single precision floating-point value:
1112        Float = ffi::CL_FLOAT as isize,
1113        // Each channel component is a normalized unsigned 24-bit integer value:
1114        UnormInt24 = ffi::CL_UNORM_INT24 as isize,
1115    }
1116}
1117
1118enum_from_primitive! {
1119    /// cl_bool
1120    #[repr(C)]
1121    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1122    pub enum Cbool {
1123        False = ffi::CL_FALSE as isize,
1124        True = ffi::CL_TRUE as isize,
1125    }
1126}
1127
1128enum_from_primitive! {
1129    /// cl_bool: Polling
1130    #[repr(C)]
1131    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1132    pub enum Polling {
1133        Blocking = ffi::CL_BLOCKING as isize,
1134        NonBlocking = ffi::CL_NON_BLOCKING as isize,
1135    }
1136}
1137
1138enum_from_primitive! {
1139    /// cl_platform_info
1140    #[repr(C)]
1141    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1142    pub enum PlatformInfo {
1143        Profile = ffi::CL_PLATFORM_PROFILE as isize,
1144        Version = ffi::CL_PLATFORM_VERSION as isize,
1145        Name = ffi::CL_PLATFORM_NAME as isize,
1146        Vendor = ffi::CL_PLATFORM_VENDOR as isize,
1147        Extensions = ffi::CL_PLATFORM_EXTENSIONS as isize,
1148    }
1149}
1150
1151enum_from_primitive! {
1152    /// cl_device_info
1153    #[repr(C)]
1154    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1155    pub enum DeviceInfo {
1156        Type = ffi::CL_DEVICE_TYPE as isize,
1157        VendorId = ffi::CL_DEVICE_VENDOR_ID as isize,
1158        MaxComputeUnits = ffi::CL_DEVICE_MAX_COMPUTE_UNITS as isize,
1159        MaxWorkItemDimensions = ffi::CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS as isize,
1160        MaxWorkGroupSize = ffi::CL_DEVICE_MAX_WORK_GROUP_SIZE as isize,
1161        MaxWorkItemSizes = ffi::CL_DEVICE_MAX_WORK_ITEM_SIZES as isize,
1162        PreferredVectorWidthChar = ffi::CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR as isize,
1163        PreferredVectorWidthShort = ffi::CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT as isize,
1164        PreferredVectorWidthInt = ffi::CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT as isize,
1165        PreferredVectorWidthLong = ffi::CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG as isize,
1166        PreferredVectorWidthFloat = ffi::CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT as isize,
1167        PreferredVectorWidthDouble = ffi::CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE as isize,
1168        MaxClockFrequency = ffi::CL_DEVICE_MAX_CLOCK_FREQUENCY as isize,
1169        AddressBits = ffi::CL_DEVICE_ADDRESS_BITS as isize,
1170        MaxReadImageArgs = ffi::CL_DEVICE_MAX_READ_IMAGE_ARGS as isize,
1171        MaxWriteImageArgs = ffi::CL_DEVICE_MAX_WRITE_IMAGE_ARGS as isize,
1172        MaxMemAllocSize = ffi::CL_DEVICE_MAX_MEM_ALLOC_SIZE as isize,
1173        Image2dMaxWidth = ffi::CL_DEVICE_IMAGE2D_MAX_WIDTH as isize,
1174        Image2dMaxHeight = ffi::CL_DEVICE_IMAGE2D_MAX_HEIGHT as isize,
1175        Image3dMaxWidth = ffi::CL_DEVICE_IMAGE3D_MAX_WIDTH as isize,
1176        Image3dMaxHeight = ffi::CL_DEVICE_IMAGE3D_MAX_HEIGHT as isize,
1177        Image3dMaxDepth = ffi::CL_DEVICE_IMAGE3D_MAX_DEPTH as isize,
1178        ImageSupport = ffi::CL_DEVICE_IMAGE_SUPPORT as isize,
1179        MaxParameterSize = ffi::CL_DEVICE_MAX_PARAMETER_SIZE as isize,
1180        MaxSamplers = ffi::CL_DEVICE_MAX_SAMPLERS as isize,
1181        MemBaseAddrAlign = ffi::CL_DEVICE_MEM_BASE_ADDR_ALIGN as isize,
1182        MinDataTypeAlignSize = ffi::CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE as isize,
1183        SingleFpConfig = ffi::CL_DEVICE_SINGLE_FP_CONFIG as isize,
1184        GlobalMemCacheType = ffi::CL_DEVICE_GLOBAL_MEM_CACHE_TYPE as isize,
1185        GlobalMemCachelineSize = ffi::CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE as isize,
1186        GlobalMemCacheSize = ffi::CL_DEVICE_GLOBAL_MEM_CACHE_SIZE as isize,
1187        GlobalMemSize = ffi::CL_DEVICE_GLOBAL_MEM_SIZE as isize,
1188        MaxConstantBufferSize = ffi::CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE as isize,
1189        MaxConstantArgs = ffi::CL_DEVICE_MAX_CONSTANT_ARGS as isize,
1190        LocalMemType = ffi::CL_DEVICE_LOCAL_MEM_TYPE as isize,
1191        LocalMemSize = ffi::CL_DEVICE_LOCAL_MEM_SIZE as isize,
1192        ErrorCorrectionSupport = ffi::CL_DEVICE_ERROR_CORRECTION_SUPPORT as isize,
1193        ProfilingTimerResolution = ffi::CL_DEVICE_PROFILING_TIMER_RESOLUTION as isize,
1194        EndianLittle = ffi::CL_DEVICE_ENDIAN_LITTLE as isize,
1195        Available = ffi::CL_DEVICE_AVAILABLE as isize,
1196        CompilerAvailable = ffi::CL_DEVICE_COMPILER_AVAILABLE as isize,
1197        ExecutionCapabilities = ffi::CL_DEVICE_EXECUTION_CAPABILITIES as isize,
1198        QueueProperties = ffi::CL_DEVICE_QUEUE_PROPERTIES as isize,
1199        Name = ffi::CL_DEVICE_NAME as isize,
1200        Vendor = ffi::CL_DEVICE_VENDOR as isize,
1201        DriverVersion = ffi::CL_DRIVER_VERSION as isize,
1202        Profile = ffi::CL_DEVICE_PROFILE as isize,
1203        Version = ffi::CL_DEVICE_VERSION as isize,
1204        Extensions = ffi::CL_DEVICE_EXTENSIONS as isize,
1205        Platform = ffi::CL_DEVICE_PLATFORM as isize,
1206        DoubleFpConfig = ffi::CL_DEVICE_DOUBLE_FP_CONFIG as isize,
1207        HalfFpConfig = ffi::CL_DEVICE_HALF_FP_CONFIG as isize,
1208        PreferredVectorWidthHalf = ffi::CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF as isize,
1209        HostUnifiedMemory = ffi::CL_DEVICE_HOST_UNIFIED_MEMORY as isize,
1210        NativeVectorWidthChar = ffi::CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR as isize,
1211        NativeVectorWidthShort = ffi::CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT as isize,
1212        NativeVectorWidthInt = ffi::CL_DEVICE_NATIVE_VECTOR_WIDTH_INT as isize,
1213        NativeVectorWidthLong = ffi::CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG as isize,
1214        NativeVectorWidthFloat = ffi::CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT as isize,
1215        NativeVectorWidthDouble = ffi::CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE as isize,
1216        NativeVectorWidthHalf = ffi::CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF as isize,
1217        OpenclCVersion = ffi::CL_DEVICE_OPENCL_C_VERSION as isize,
1218        LinkerAvailable = ffi::CL_DEVICE_LINKER_AVAILABLE as isize,
1219        BuiltInKernels = ffi::CL_DEVICE_BUILT_IN_KERNELS as isize,
1220        ImageMaxBufferSize = ffi::CL_DEVICE_IMAGE_MAX_BUFFER_SIZE as isize,
1221        ImageMaxArraySize = ffi::CL_DEVICE_IMAGE_MAX_ARRAY_SIZE as isize,
1222        ParentDevice = ffi::CL_DEVICE_PARENT_DEVICE as isize,
1223        PartitionMaxSubDevices = ffi::CL_DEVICE_PARTITION_MAX_SUB_DEVICES as isize,
1224        PartitionProperties = ffi::CL_DEVICE_PARTITION_PROPERTIES as isize,
1225        PartitionAffinityDomain = ffi::CL_DEVICE_PARTITION_AFFINITY_DOMAIN as isize,
1226        PartitionType = ffi::CL_DEVICE_PARTITION_TYPE as isize,
1227        ReferenceCount = ffi::CL_DEVICE_REFERENCE_COUNT as isize,
1228        PreferredInteropUserSync = ffi::CL_DEVICE_PREFERRED_INTEROP_USER_SYNC as isize,
1229        PrintfBufferSize = ffi::CL_DEVICE_PRINTF_BUFFER_SIZE as isize,
1230        ImagePitchAlignment = ffi::CL_DEVICE_IMAGE_PITCH_ALIGNMENT as isize,
1231        ImageBaseAddressAlignment = ffi::CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT as isize,
1232    }
1233}
1234
1235enum_from_primitive! {
1236    /// cl_mem_cache_type
1237    #[repr(C)]
1238    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1239    pub enum DeviceMemCacheType {
1240        None = ffi::CL_NONE as isize,
1241        ReadOnlyCache = ffi::CL_READ_ONLY_CACHE as isize,
1242        ReadWriteCache = ffi::CL_READ_WRITE_CACHE as isize,
1243    }
1244}
1245
1246enum_from_primitive! {
1247    /// cl_device_local_mem_type
1248    #[repr(C)]
1249    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1250    pub enum DeviceLocalMemType {
1251        None = ffi::CL_NONE as isize,
1252        Local = ffi::CL_LOCAL as isize,
1253        Global = ffi::CL_GLOBAL as isize,
1254    }
1255}
1256
1257enum_from_primitive! {
1258    /// cl_context_info
1259    #[repr(C)]
1260    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1261    pub enum ContextInfo {
1262        ReferenceCount = ffi::CL_CONTEXT_REFERENCE_COUNT as isize,
1263        Devices = ffi::CL_CONTEXT_DEVICES as isize,
1264        Properties = ffi::CL_CONTEXT_PROPERTIES as isize,
1265        NumDevices = ffi::CL_CONTEXT_NUM_DEVICES as isize,
1266    }
1267}
1268
1269enum_from_primitive! {
1270    /// cl_gl_context_info
1271    #[repr(C)]
1272    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1273    pub enum GlContextInfo {
1274        // Return the CL device currently associated with the specified OpenGL context.
1275        CurrentDevice = ffi::CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR as isize,
1276        // List of all CL devices which may be associated with the specified OpenGL context.
1277        Devices = ffi::CL_DEVICES_FOR_GL_CONTEXT_KHR as isize,
1278    }
1279}
1280
1281// [TODO]: Do proper auto-detection of available OpenGL context type.
1282#[cfg(target_os = "macos")]
1283pub const CL_CGL_SHAREGROUP_KHR_OS_SPECIFIC: isize =
1284    ffi::CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE;
1285#[cfg(not(target_os = "macos"))]
1286pub const CL_CGL_SHAREGROUP_KHR_OS_SPECIFIC: isize = ffi::CL_CGL_SHAREGROUP_KHR;
1287
1288enum_from_primitive! {
1289    /// cl_context_info + cl_context_properties
1290    #[repr(C)]
1291    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1292    pub enum ContextProperty {
1293        Platform = ffi::CL_CONTEXT_PLATFORM as isize,
1294        InteropUserSync = ffi::CL_CONTEXT_INTEROP_USER_SYNC as isize,
1295        D3d10DeviceKhr = ffi::CL_CONTEXT_D3D10_DEVICE_KHR as isize,
1296        GlContextKhr = ffi::CL_GL_CONTEXT_KHR as isize,
1297        EglDisplayKhr = ffi::CL_EGL_DISPLAY_KHR as isize,
1298        GlxDisplayKhr = ffi::CL_GLX_DISPLAY_KHR as isize,
1299        CglSharegroupKhr = CL_CGL_SHAREGROUP_KHR_OS_SPECIFIC,
1300        WglHdcKhr = ffi::CL_WGL_HDC_KHR as isize,
1301        AdapterD3d9Khr = ffi::CL_CONTEXT_ADAPTER_D3D9_KHR as isize,
1302        AdapterD3d9exKhr = ffi::CL_CONTEXT_ADAPTER_D3D9EX_KHR as isize,
1303        AdapterDxvaKhr = ffi::CL_CONTEXT_ADAPTER_DXVA_KHR as isize,
1304        D3d11DeviceKhr = ffi::CL_CONTEXT_D3D11_DEVICE_KHR as isize,
1305    }
1306}
1307
1308enum_from_primitive! {
1309    /// cl_context_info + cl_context_properties
1310    #[repr(C)]
1311    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1312    pub enum ContextInfoOrPropertiesPointerType {
1313        Platform = ffi::CL_CONTEXT_PLATFORM as isize,
1314        InteropUserSync = ffi::CL_CONTEXT_INTEROP_USER_SYNC as isize,
1315    }
1316}
1317
1318enum_from_primitive! {
1319    /// [INCOMPLETE] cl_device_partition_property
1320    ///
1321    /// [FIXME]: This types variants should also contain data described in:
1322    /// [https://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCreateSubDevices.html]
1323    /// (https://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCreateSubDevices.html)
1324    ///
1325    #[repr(C)]
1326    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1327    pub enum DevicePartitionProperty {
1328        Equally = ffi::CL_DEVICE_PARTITION_EQUALLY as isize,
1329        ByCounts = ffi::CL_DEVICE_PARTITION_BY_COUNTS as isize,
1330        ByCountsListEnd = ffi::CL_DEVICE_PARTITION_BY_COUNTS_LIST_END as isize,
1331        ByAffinityDomain = ffi::CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN as isize,
1332    }
1333}
1334
1335enum_from_primitive! {
1336    /// cl_command_queue_info
1337    #[repr(C)]
1338    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1339    pub enum CommandQueueInfo {
1340        Context = ffi::CL_QUEUE_CONTEXT as isize,
1341        Device = ffi::CL_QUEUE_DEVICE as isize,
1342        ReferenceCount = ffi::CL_QUEUE_REFERENCE_COUNT as isize,
1343        Properties = ffi::CL_QUEUE_PROPERTIES as isize,
1344    }
1345}
1346
1347enum_from_primitive! {
1348    /// cl_channel_type
1349    #[repr(C)]
1350    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1351    pub enum ChannelType {
1352        SnormInt8 = ffi::CL_SNORM_INT8 as isize,
1353        SnormInt16 = ffi::CL_SNORM_INT16 as isize,
1354        UnormInt8 = ffi::CL_UNORM_INT8 as isize,
1355        UnormInt16 = ffi::CL_UNORM_INT16 as isize,
1356        UnormShort565 = ffi::CL_UNORM_SHORT_565 as isize,
1357        UnormShort555 = ffi::CL_UNORM_SHORT_555 as isize,
1358        UnormInt101010 = ffi::CL_UNORM_INT_101010 as isize,
1359        SignedInt8 = ffi::CL_SIGNED_INT8 as isize,
1360        SignedInt16 = ffi::CL_SIGNED_INT16 as isize,
1361        SignedInt32 = ffi::CL_SIGNED_INT32 as isize,
1362        UnsignedInt8 = ffi::CL_UNSIGNED_INT8 as isize,
1363        UnsignedInt16 = ffi::CL_UNSIGNED_INT16 as isize,
1364        UnsignedInt32 = ffi::CL_UNSIGNED_INT32 as isize,
1365        HalfFloat = ffi::CL_HALF_FLOAT as isize,
1366        Float = ffi::CL_FLOAT as isize,
1367        UnormInt24 = ffi::CL_UNORM_INT24 as isize,
1368    }
1369}
1370
1371enum_from_primitive! {
1372    /// cl_mem_object_type
1373    #[repr(C)]
1374    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1375    pub enum MemObjectType {
1376        Buffer = ffi::CL_MEM_OBJECT_BUFFER as isize,
1377        Image2d = ffi::CL_MEM_OBJECT_IMAGE2D as isize,
1378        Image3d = ffi::CL_MEM_OBJECT_IMAGE3D as isize,
1379        Image2dArray = ffi::CL_MEM_OBJECT_IMAGE2D_ARRAY as isize,
1380        Image1d = ffi::CL_MEM_OBJECT_IMAGE1D as isize,
1381        Image1dArray = ffi::CL_MEM_OBJECT_IMAGE1D_ARRAY as isize,
1382        Image1dBuffer = ffi::CL_MEM_OBJECT_IMAGE1D_BUFFER as isize,
1383    }
1384}
1385
1386enum_from_primitive! {
1387    /// cl_mem_info
1388    #[repr(C)]
1389    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1390    pub enum MemInfo {
1391        Type = ffi::CL_MEM_TYPE as isize,
1392        Flags = ffi::CL_MEM_FLAGS as isize,
1393        Size = ffi::CL_MEM_SIZE as isize,
1394        HostPtr = ffi::CL_MEM_HOST_PTR as isize,
1395        MapCount = ffi::CL_MEM_MAP_COUNT as isize,
1396        ReferenceCount = ffi::CL_MEM_REFERENCE_COUNT as isize,
1397        Context = ffi::CL_MEM_CONTEXT as isize,
1398        AssociatedMemobject = ffi::CL_MEM_ASSOCIATED_MEMOBJECT as isize,
1399        Offset = ffi::CL_MEM_OFFSET as isize,
1400    }
1401}
1402
1403enum_from_primitive! {
1404    /// cl_image_info
1405    #[repr(C)]
1406    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1407    pub enum ImageInfo {
1408        Format = ffi::CL_IMAGE_FORMAT as isize,
1409        ElementSize = ffi::CL_IMAGE_ELEMENT_SIZE as isize,
1410        RowPitch = ffi::CL_IMAGE_ROW_PITCH as isize,
1411        SlicePitch = ffi::CL_IMAGE_SLICE_PITCH as isize,
1412        Width = ffi::CL_IMAGE_WIDTH as isize,
1413        Height = ffi::CL_IMAGE_HEIGHT as isize,
1414        Depth = ffi::CL_IMAGE_DEPTH as isize,
1415        ArraySize = ffi::CL_IMAGE_ARRAY_SIZE as isize,
1416        Buffer = ffi::CL_IMAGE_BUFFER as isize,
1417        NumMipLevels = ffi::CL_IMAGE_NUM_MIP_LEVELS as isize,
1418        NumSamples = ffi::CL_IMAGE_NUM_SAMPLES as isize,
1419    }
1420}
1421
1422enum_from_primitive! {
1423    /// cl_addressing_mode
1424    #[repr(C)]
1425    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1426    pub enum AddressingMode {
1427        None = ffi::CL_ADDRESS_NONE as isize,
1428        ClampToEdge = ffi::CL_ADDRESS_CLAMP_TO_EDGE as isize,
1429        Clamp = ffi::CL_ADDRESS_CLAMP as isize,
1430        Repeat = ffi::CL_ADDRESS_REPEAT as isize,
1431        MirroredRepeat = ffi::CL_ADDRESS_MIRRORED_REPEAT as isize,
1432    }
1433}
1434
1435enum_from_primitive! {
1436    /// cl_filter_mode
1437    #[repr(C)]
1438    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1439    pub enum FilterMode {
1440        Nearest = ffi::CL_FILTER_NEAREST as isize,
1441        Linear = ffi::CL_FILTER_LINEAR as isize,
1442    }
1443}
1444
1445enum_from_primitive! {
1446    /// cl_sampler_info
1447    #[repr(C)]
1448    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1449    pub enum SamplerInfo {
1450        ReferenceCount = ffi::CL_SAMPLER_REFERENCE_COUNT as isize,
1451        Context = ffi::CL_SAMPLER_CONTEXT as isize,
1452        NormalizedCoords = ffi::CL_SAMPLER_NORMALIZED_COORDS as isize,
1453        AddressingMode = ffi::CL_SAMPLER_ADDRESSING_MODE as isize,
1454        FilterMode = ffi::CL_SAMPLER_FILTER_MODE as isize,
1455    }
1456}
1457
1458enum_from_primitive! {
1459    /// cl_program_info
1460    #[repr(C)]
1461    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1462    pub enum ProgramInfo {
1463        ReferenceCount = ffi::CL_PROGRAM_REFERENCE_COUNT as isize,
1464        Context = ffi::CL_PROGRAM_CONTEXT as isize,
1465        NumDevices = ffi::CL_PROGRAM_NUM_DEVICES as isize,
1466        Devices = ffi::CL_PROGRAM_DEVICES as isize,
1467        Source = ffi::CL_PROGRAM_SOURCE as isize,
1468        BinarySizes = ffi::CL_PROGRAM_BINARY_SIZES as isize,
1469        Binaries = ffi::CL_PROGRAM_BINARIES as isize,
1470        NumKernels = ffi::CL_PROGRAM_NUM_KERNELS as isize,
1471        KernelNames = ffi::CL_PROGRAM_KERNEL_NAMES as isize,
1472    }
1473}
1474
1475enum_from_primitive! {
1476    /// cl_program_build_info
1477    #[repr(C)]
1478    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1479    pub enum ProgramBuildInfo {
1480        BuildStatus = ffi::CL_PROGRAM_BUILD_STATUS as isize,
1481        BuildOptions = ffi::CL_PROGRAM_BUILD_OPTIONS as isize,
1482        BuildLog = ffi::CL_PROGRAM_BUILD_LOG as isize,
1483        BinaryType = ffi::CL_PROGRAM_BINARY_TYPE as isize,
1484    }
1485}
1486
1487enum_from_primitive! {
1488    /// cl_build_status
1489    #[repr(C)]
1490    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1491    pub enum ProgramBuildStatus {
1492        Success = ffi::CL_BUILD_SUCCESS as isize,
1493        None = ffi::CL_BUILD_NONE as isize,
1494        Error = ffi::CL_BUILD_ERROR as isize,
1495        InProgress = ffi::CL_BUILD_IN_PROGRESS as isize,
1496    }
1497}
1498
1499enum_from_primitive! {
1500    /// cl_kernel_info
1501    #[repr(C)]
1502    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1503    pub enum KernelInfo {
1504        FunctionName = ffi::CL_KERNEL_FUNCTION_NAME as isize,
1505        NumArgs = ffi::CL_KERNEL_NUM_ARGS as isize,
1506        ReferenceCount = ffi::CL_KERNEL_REFERENCE_COUNT as isize,
1507        Context = ffi::CL_KERNEL_CONTEXT as isize,
1508        Program = ffi::CL_KERNEL_PROGRAM as isize,
1509        Attributes = ffi::CL_KERNEL_ATTRIBUTES as isize,
1510    }
1511}
1512
1513enum_from_primitive! {
1514    /// cl_kernel_arg_info
1515    #[repr(C)]
1516    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1517    pub enum KernelArgInfo {
1518        AddressQualifier = ffi::CL_KERNEL_ARG_ADDRESS_QUALIFIER as isize,
1519        AccessQualifier = ffi::CL_KERNEL_ARG_ACCESS_QUALIFIER as isize,
1520        TypeName = ffi::CL_KERNEL_ARG_TYPE_NAME as isize,
1521        TypeQualifier = ffi::CL_KERNEL_ARG_TYPE_QUALIFIER as isize,
1522        Name = ffi::CL_KERNEL_ARG_NAME as isize,
1523    }
1524}
1525
1526enum_from_primitive! {
1527    /// cl_kernel_arg_address_qualifier
1528    #[repr(C)]
1529    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1530    pub enum KernelArgAddressQualifier {
1531        Global = ffi::CL_KERNEL_ARG_ADDRESS_GLOBAL as isize,
1532        Local = ffi::CL_KERNEL_ARG_ADDRESS_LOCAL as isize,
1533        Constant = ffi::CL_KERNEL_ARG_ADDRESS_CONSTANT as isize,
1534        Private = ffi::CL_KERNEL_ARG_ADDRESS_PRIVATE as isize,
1535    }
1536}
1537
1538enum_from_primitive! {
1539    /// cl_kernel_arg_access_qualifier
1540    #[repr(C)]
1541    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1542    pub enum KernelArgAccessQualifier {
1543        ReadOnly = ffi::CL_KERNEL_ARG_ACCESS_READ_ONLY as isize,
1544        WriteOnly = ffi::CL_KERNEL_ARG_ACCESS_WRITE_ONLY as isize,
1545        ReadWrite = ffi::CL_KERNEL_ARG_ACCESS_READ_WRITE as isize,
1546        None = ffi::CL_KERNEL_ARG_ACCESS_NONE as isize,
1547     }
1548}
1549
1550enum_from_primitive! {
1551    /// cl_kernel_work_group_info
1552    ///
1553    /// [NOTE] PrivateMemSize: If device is not a custom device or kernel is not a built-in
1554    /// kernel, clGetKernelArgInfo returns the error CL_INVALID_VALUE:
1555    #[repr(C)]
1556    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1557    pub enum KernelWorkGroupInfo {
1558        WorkGroupSize = ffi::CL_KERNEL_WORK_GROUP_SIZE as isize,
1559        CompileWorkGroupSize = ffi::CL_KERNEL_COMPILE_WORK_GROUP_SIZE as isize,
1560        LocalMemSize = ffi::CL_KERNEL_LOCAL_MEM_SIZE as isize,
1561        PreferredWorkGroupSizeMultiple = ffi::CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE as isize,
1562        PrivateMemSize = ffi::CL_KERNEL_PRIVATE_MEM_SIZE as isize,
1563        GlobalWorkSize = ffi::CL_KERNEL_GLOBAL_WORK_SIZE as isize,
1564    }
1565}
1566
1567enum_from_primitive! {
1568    /// cl_event_info
1569    #[repr(C)]
1570    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1571    pub enum EventInfo {
1572        CommandQueue = ffi::CL_EVENT_COMMAND_QUEUE as isize,
1573        CommandType = ffi::CL_EVENT_COMMAND_TYPE as isize,
1574        ReferenceCount = ffi::CL_EVENT_REFERENCE_COUNT as isize,
1575        CommandExecutionStatus = ffi::CL_EVENT_COMMAND_EXECUTION_STATUS as isize,
1576        Context = ffi::CL_EVENT_CONTEXT as isize,
1577    }
1578}
1579
1580enum_from_primitive! {
1581    /// cl_command_type
1582    #[repr(C)]
1583    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1584    pub enum CommandType {
1585        NdrangeKernel = ffi::CL_COMMAND_NDRANGE_KERNEL as isize,
1586        Task = ffi::CL_COMMAND_TASK as isize,
1587        NativeKernel = ffi::CL_COMMAND_NATIVE_KERNEL as isize,
1588        ReadBuffer = ffi::CL_COMMAND_READ_BUFFER as isize,
1589        WriteBuffer = ffi::CL_COMMAND_WRITE_BUFFER as isize,
1590        CopyBuffer = ffi::CL_COMMAND_COPY_BUFFER as isize,
1591        ReadImage = ffi::CL_COMMAND_READ_IMAGE as isize,
1592        WriteImage = ffi::CL_COMMAND_WRITE_IMAGE as isize,
1593        CopyImage = ffi::CL_COMMAND_COPY_IMAGE as isize,
1594        CopyImageToBuffer = ffi::CL_COMMAND_COPY_IMAGE_TO_BUFFER as isize,
1595        CopyBufferToImage = ffi::CL_COMMAND_COPY_BUFFER_TO_IMAGE as isize,
1596        MapBuffer = ffi::CL_COMMAND_MAP_BUFFER as isize,
1597        MapImage = ffi::CL_COMMAND_MAP_IMAGE as isize,
1598        UnmapMemObject = ffi::CL_COMMAND_UNMAP_MEM_OBJECT as isize,
1599        Marker = ffi::CL_COMMAND_MARKER as isize,
1600        AcquireGlObjects = ffi::CL_COMMAND_ACQUIRE_GL_OBJECTS as isize,
1601        ReleaseGlObjects = ffi::CL_COMMAND_RELEASE_GL_OBJECTS as isize,
1602        ReadBufferRect = ffi::CL_COMMAND_READ_BUFFER_RECT as isize,
1603        WriteBufferRect = ffi::CL_COMMAND_WRITE_BUFFER_RECT as isize,
1604        CopyBufferRect = ffi::CL_COMMAND_COPY_BUFFER_RECT as isize,
1605        User = ffi::CL_COMMAND_USER as isize,
1606        Barrier = ffi::CL_COMMAND_BARRIER as isize,
1607        MigrateMemObjects = ffi::CL_COMMAND_MIGRATE_MEM_OBJECTS as isize,
1608        FillBuffer = ffi::CL_COMMAND_FILL_BUFFER as isize,
1609        FillImage = ffi::CL_COMMAND_FILL_IMAGE as isize,
1610    }
1611}
1612
1613enum_from_primitive! {
1614    /// command execution status
1615    #[repr(C)]
1616    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1617    pub enum CommandExecutionStatus {
1618        Complete = ffi::CL_COMPLETE as isize,
1619        Running = ffi::CL_RUNNING as isize,
1620        Submitted = ffi::CL_SUBMITTED as isize,
1621        Queued = ffi::CL_QUEUED as isize,
1622    }
1623}
1624
1625enum_from_primitive! {
1626    /// cl_buffer_create_type
1627    #[repr(C)]
1628    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1629    pub enum BufferCreateType {
1630        Region = ffi::CL_BUFFER_CREATE_TYPE_REGION as isize,
1631        __DUMMY,
1632    }
1633}
1634
1635enum_from_primitive! {
1636    /// cl_profiling_info
1637    #[repr(C)]
1638    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1639    pub enum ProfilingInfo {
1640        Queued = ffi::CL_PROFILING_COMMAND_QUEUED as isize,
1641        Submit = ffi::CL_PROFILING_COMMAND_SUBMIT as isize,
1642        Start = ffi::CL_PROFILING_COMMAND_START as isize,
1643        End = ffi::CL_PROFILING_COMMAND_END as isize,
1644    }
1645}