30 releases (19 breaking)

0.19.7 Mar 27, 2024
0.19.6 Nov 9, 2023
0.19.5 Oct 9, 2023
0.19.4 Aug 23, 2022
0.2.0 Nov 19, 2015

#94 in Concurrency

Download history 1747/week @ 2024-02-24 1217/week @ 2024-03-02 1919/week @ 2024-03-09 1397/week @ 2024-03-16 1646/week @ 2024-03-23 1237/week @ 2024-03-30 1188/week @ 2024-04-06 1378/week @ 2024-04-13 1343/week @ 2024-04-20 825/week @ 2024-04-27 1224/week @ 2024-05-04 1044/week @ 2024-05-11 1164/week @ 2024-05-18 981/week @ 2024-05-25 1016/week @ 2024-06-01 1047/week @ 2024-06-08

4,325 downloads per month
Used in 43 crates (35 directly)


22K SLoC


Supported platforms Linux Build Status

Pure OpenCL™ bindings and interfaces for Rust.


To provide:

  • A simple and intuitive interface to OpenCL devices
  • The full functionality and power of the OpenCL API
  • An absolute minimum of boilerplate
  • Zero or virtually zero performance overhead
  • Thread-safe and automatic management of API pointers and resources


Ensure that an OpenCL library is installed for your platform and that clinfo or some other diagnostic command will run. Add the following to your project's Cargo.toml:

ocl = "0.19"

And add the following to your crate root (lib.rs or main.rs):

extern crate ocl;


From examples/trivial.rs:

extern crate ocl;
use ocl::ProQue;

fn trivial() -> ocl::Result<()> {
    let src = r#"
        __kernel void add(__global float* buffer, float scalar) {
            buffer[get_global_id(0)] += scalar;

    let pro_que = ProQue::builder()
        .dims(1 << 20)

    let buffer = pro_que.create_buffer::<f32>()?;

    let kernel = pro_que.kernel_builder("add")

    unsafe { kernel.enq()?; }

    let mut vec = vec![0.0f32; buffer.len()];
    buffer.read(&mut vec).enq()?;

    println!("The value at index [{}] is now '{}'!", 200007, vec[200007]);

See the the remainder of examples/trivial.rs for more information about how this library leverages Rust's zero-cost abstractions to provide the full power and performance of the C API in a simple package.

Introduction to OpenCL

For a quick but thorough primer on the basics of OpenCL, please see Matthew Scarpino's excellent article, 'A Gentle Introduction to OpenCL' at drdobbs.com (his book is great too).

Diving Deeper

Already familiar with the standard OpenCL core API? See the ocl-core crate for access to the complete feature set in the conventional API style with Rust's safety and convenience.

Version Support

OpenCL versions 1.1 and above are supported. OpenCL version 1.0 is not supported due to its inherent thread unsafety.

Vulkan™ and the Future

The OpenCL API already posesses all of the new attributes of the Vulkan API such as low-overhead, high performance, and unfettered hardware access. For all practical purposes, Vulkan is simply a graphics-focused superset of OpenCL's features (sorta kinda). OpenCL 2.1+ and Vulkan kernels/shaders now both compile into SPIR-V making the device side of things the same. I wouldn't be suprised if most driver vendors implement the two host APIs identically.

In the future it's possible the two may completely merge (or that Vulkan will absorb OpenCL). Whatever happens, nothing will change as far as the front end of this library is concerned. This library will maintain its focus on the compute side of things.


Licensed under either of:

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

*“OpenCL and the OpenCL logo are trademarks of Apple Inc. used by permission by Khronos.”*
*“Vulkan and the Vulkan logo are trademarks of the Khronos Group Inc.”*


~32K SLoC