ocl_macros/
lib.rs

1//! # [![](https://img.shields.io/crates/v/ocl-macros.svg)](https://crates.io/crates/ocl-macros) | [GitHub](https://github.com/pipinspace/ocl-macros)
2//!
3//! Macros for easier/faster working with the [`ocl`] crate. `ocl-macros` currently supports rust macros for easy ocl::Kernel and ocl::Buffer creation.
4//!
5//! This crate is still in early development. If you encounter any problems or have a suggestion, feel free to open an [issue].
6//!
7//! ## Simple Example
8//!
9//! This is an example use-case of ocl-macros:
10//! ```rust
11//! use ocl::{Context, Device, Platform, Program, Queue};
12//! use ocl_macros::*;
13//!
14//! let PROGRAM_SRC: &str = r#"
15//! kernel void add_one(global float* var) {
16//!     const uint n = get_global_id(0);
17//!     // This program adds 1.0f to each element in the buffer
18//!     var[n] += 1.0f;
19//! }
20//! "#;
21//! 
22//! // Initialize OpenCL context/queue
23//! let platform = Platform::default();
24//! // Get first device on default platform
25//! let device = default_device!();
26//! let context = Context::builder()
27//!     .platform(platform)
28//!     .devices(device)
29//!     .build()
30//!     .unwrap();
31//! let queue = Queue::new(&context, device, None).unwrap();
32//! let program = Program::builder()
33//!     .devices(device)
34//!     .src(PROGRAM_SRC)
35//!     .build(&context)
36//!     .unwrap();
37//! 
38//! // Create new float buffer with 100 elements of starting value 0.0f32
39//! let buffer = buffer!(&queue, 100, 0.0f32);
40//! // Create the "add_one" kernel with work size 100 and buffer as first unnamed argument
41//! let kernel = kernel!(program, queue, "add_one", 100, &buffer);
42//! 
43//! // Run kernel (This is unsafe)
44//! unsafe { kernel.enq().unwrap(); }
45//! // Get buffer content as new vector
46//! let vec = bget!(buffer);
47//! // The elements are now 1.0f32!
48//! assert!(vec[0] == 1.0f32);
49//! ```
50//! This code uses various macros to create a new buffer and kernel with the created buffer as an unnamed argument.
51//! The kernel is then executed. The buffer content is read into a new vector and verified. It has changed from 0.0 to 1.0!
52//!
53//!
54//! [issue]: https://github.com/pipinspace/ocl-macros/issues
55//! [`ocl`]: https://github.com/cogciprocate/ocl
56
57extern crate ocl;
58
59#[cfg(test)]
60mod tests;
61
62pub mod buffer;
63pub mod device;
64pub mod kernel;
65pub mod proque;