#opencl #api #gpgpu #gpu #ffi


A Rust implementation of the Khronos OpenCL 3.0 API and extensions

39 releases

0.10.0 Mar 31, 2024
0.9.5 Dec 22, 2023
0.9.4 Nov 5, 2023
0.9.2 Jul 30, 2023
0.1.3 Dec 31, 2020

#54 in Graphics APIs

Download history 940/week @ 2024-03-31 598/week @ 2024-04-07 535/week @ 2024-04-14 753/week @ 2024-04-21 501/week @ 2024-04-28 708/week @ 2024-05-05 583/week @ 2024-05-12 551/week @ 2024-05-19 544/week @ 2024-05-26 548/week @ 2024-06-02 543/week @ 2024-06-09 432/week @ 2024-06-16 488/week @ 2024-06-23 226/week @ 2024-06-30 288/week @ 2024-07-07 336/week @ 2024-07-14

1,397 downloads per month
Used in 31 crates (via opencl3)




crates.io docs.io OpenCL 3.0 License Rust

A Rust adapter for the Khronos OpenCL API.


A functional, safe Rust interface to the Khronos OpenCL 3.0 C API based upon the opencl-sys OpenCL FFI bindings.
It is the foundation of the opencl3 crate which provides a simpler, object based model of the OpenCL 3.0 API.

OpenCL 3.0 is a unified specification that adds little new functionality to previous OpenCL versions.
It specifies that all OpenCL 1.2 features are mandatory, while all OpenCL 2.x and 3.0 features are now optional.

OpenCL also has extensions that enable other features such as OpenGL and Direct X interoperability, see OpenCL Extensions. This library includes FFI bindings to use OpenCL extensions.


This crate applies the adapter pattern to convert OpenCL C API functions into Rust functions that return a Result containing the desired result of the C function or the OpenCL error code. The only exception is svm_free, which just provides a safe wrapper for the clSVMFree C API function.

Most of the modules are named after their equivalent "API" sections in cl.h. They contain Rust adapter functions for the OpenCL API C functions defined in those sections with their associated types and constants.
For more information see the Rust documentation.

The API for OpenCL versions and extensions are controlled by Rust features such as "CL_VERSION_2_0" and "cl_khr_gl_sharing". To enable an OpenCL version, the feature for that version and all previous OpenCL versions must be enabled, e.g. for "CL_VERSION_2_0"; "CL_VERSION_1_1" and "CL_VERSION_1_2" must also be enabled.

The default features are "CL_VERSION_1_1" and "CL_VERSION_1_2".

Rust deprecation warnings are given for OpenCL API functions that are deprecated by an enabled OpenCL version e.g., clCreateCommandQueue is deprecated whenever "CL_VERSION_2_0" is enabled.


Ensure that an OpenCL Installable Client Driver (ICD) and the appropriate OpenCL hardware driver(s) are installed, see OpenCL Installation.

cl3 supports OpenCL 1.2 and 2.0 ICD loaders by default. If you have an OpenCL 2.0 ICD loader then add the following to your project's Cargo.toml:

cl3 = "0.9"

If your OpenCL ICD loader supports higher versions of OpenCL then add the appropriate features to cl3, e.g. for an OpenCL 2.1 ICD loader add the following to your project's Cargo.toml instead:

version = "0.9"
features = ["CL_VERSION_1_1", "CL_VERSION_1_2", "CL_VERSION_2_0", "CL_VERSION_2_1"]

OpenCL extensions can also be enabled by adding their features, e.g.:

version = "0.9"
features = ["cl_khr_gl_sharing", "cl_khr_dx9_media_sharing"]

Whichever version of OpenCL ICD loader you use, add the following to your crate root (lib.rs or main.rs):

extern crate cl3;


The crate contains unit, documentation and integration tests.
The tests run the platform and device info functions (among others) so they can provide useful information about OpenCL capabilities of the system.

It is recommended to run the tests in single-threaded mode, since some of them can interfere with each other when run multi-threaded, e.g.:

cargo test -- --test-threads=1 --show-output

The integration tests are marked ignore so use the following command to run them:

cargo test -- --test-threads=1 --show-output --ignored


The tests provide examples of how the crate may be used, e.g. see: platform, device, context and integration_test.


If you want to contribute through code or documentation, the Contributing guide is the best place to start. If you have any questions, please feel free to ask. Just please abide by our Code of Conduct.


Licensed under the Apache License, Version 2.0, as per Khronos Group OpenCL.
You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0

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 licensed as above, without any additional terms or conditions.

OpenCL and the OpenCL logo are trademarks of Apple Inc. used by permission by Khronos.


~26K SLoC