#opencl #gpu #gpgpu #ffi #api

cl3

A Rust implementation of the Khronos OpenCL 3.0 API and extensions

27 releases (5 breaking)

0.6.3 Nov 20, 2021
0.6.1 Oct 17, 2021
0.4.0 May 30, 2021
0.2.0 Mar 28, 2021
0.1.3 Dec 31, 2020

#31 in Asynchronous

Download history 437/week @ 2021-08-14 207/week @ 2021-08-21 141/week @ 2021-08-28 377/week @ 2021-09-04 527/week @ 2021-09-11 609/week @ 2021-09-18 722/week @ 2021-09-25 953/week @ 2021-10-02 1056/week @ 2021-10-09 2288/week @ 2021-10-16 1561/week @ 2021-10-23 708/week @ 2021-10-30 578/week @ 2021-11-06 654/week @ 2021-11-13 803/week @ 2021-11-20 706/week @ 2021-11-27

2,850 downloads per month
Used in 20 crates (via opencl3)

Apache-2.0

460KB
10K SLoC

cl3

crates.io docs.io OpenCL 3.0 License Rust

A Rust adapter for the Khronos OpenCL API.

Description

A functional, safe Rust interface to the Khronos OpenCL 3.0 C API based upon the cl-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.

Design

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.

Use

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:

[dependencies]
cl3 = "0.6"

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

[dependencies.cl3]
version = "0.6"
features = ["CL_VERSION_2_1", "CL_VERSION_2_2"]

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

[dependencies.cl3]
version = "0.6"
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;

Tests

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

Examples

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

Contribution

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.

License

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.

Dependencies

~450KB

a