OpenCL™ interfaces for Rust. Makes easy to use the most common features of OpenCL. All interfaces are virtually zero-cost and perform on a par with any C++ libraries.
Interfaces are still mildly unstable. Changes are now being documented in RELEASES.md.
To provide a simple and intuitive way to interact with OpenCL devices with: - The full functionality of the OpenCL C ABI - An absolute minimum of boilerplate - As close as possible to zero performance overhead
Tested so far only on Linux. Please provide feedback about failures and successes on other platforms. Note: Probably working in OS X, need confirmation.
Ensure that an OpenCL library is installed for your preferred platform and
that clinfo
or some other diagnostic command will run.
Add:
[dependencies] ocl = "0.5"
to your project's Cargo.toml
.
From 'examples/trivial.rs': ``` extern crate ocl; use ocl::{ProQue, SimpleDims, Buffer};
fn main() { // Define a kernel: let src = r#" kernel void multiply(global float* buffer, float coeff) { buffer[getglobalid(0)] *= coeff; } "#;
// Create an all-in-one context, program, and command queue:
let ocl_pq = ProQue::builder().src(src).build().unwrap();
// Set our work dimensions / data set size to something arbitrary:
let dims = SimpleDims::One(500000);
// Create a 'Buffer' with a built-in vector and initialize it with random
// floats between 0.0 and 20.0:
let mut buffer: Buffer<f32> = Buffer::with_vec_scrambled(
(0.0, 20.0), &dims, &ocl_pq.queue());
// Create a kernel with arguments matching those in the kernel:
let kern = ocl_pq.create_kernel("multiply", dims.work_dims()).unwrap()
.arg_buf(&buffer)
.arg_scl(10.0f32);
// // Enqueue kernel:
kern.enqueue(None, None);
// // Read results from the device into buffer's local vector:
buffer.fill_vec().ok();
// // Print a result:
println!("The value at index [{}] is '{}'!", 200007, buffer[200007]);
}
```
If troubleshooting your OpenCL drivers: check that /usr/lib/libOpenCL.so.1
exists. Go ahead and link /usr/lib/libOpenCL.so -> libOpenCL.so.1
just in
case it's not already (AMD drivers sometimes don't create this link). Intel
and AMD also have OpenCL libraries for your CPU if you're having trouble
getting your GPU to work (intel: windows, linux).
Please ask questions and provide feedback by opening an issue.
See RELEASES.md.
Image
type for dealing with images.Want to bring your OpenCL-ness to Rust but can't find the functionality you
need? File an issue and
prefix the title with Feature Request:
.
“OpenCL and the OpenCL logo are trademarks of Apple Inc. used by permission by Khronos.”