opencl_dynamic_sys/
lib.rs

1//! [![](https://img.shields.io/crates/v/opencl-dynamic-sys.svg)](https://crates.io/crates/opencl-dynamic-sys)
2//! [![](https://docs.rs/opencl-dynamic-sys/badge.svg)](https://docs.rs/opencl-dynamic-sys/)
3//! [![OpenCL 3.0](https://img.shields.io/badge/OpenCL-3.0-blue.svg)](https://www.khronos.org/registry/OpenCL/)
4//! [![](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://github.com/passware/opencl-dynamic-sys-rs/blob/main/LICENSE)
5//! [![Rust](https://github.com/passware/opencl-dynamic-sys-rs/actions/workflows/rust.yml/badge.svg)](https://github.com/passware/opencl-dynamic-sys-rs/actions)
6//!
7//! Rust library to handle the dynamic load of the OpenCL shared library.
8//!
9//! ## Description
10//!
11//! This library in general is a rewritten version of the [opencl-sys-rs](https://github.com/kenba/opencl-sys-rs) library.
12//! The main difference is a way in which the OpenCL library will be linked to the program:
13//! it will be loaded dynamically in the runtime during the first call to the OpenCL API with the help of the
14//! [dlopen2](https://github.com/OpenByteDev/dlopen2) library.
15//!
16//! If the OpenCL library not found, the error code `CL_RUNTIME_LOAD_FAILED = -2000` will be returned.
17//!
18//! If the OpenCL library doesn't have some API functions
19//! (such as [clCreateBufferWithProperties](https://registry.khronos.org/OpenCL/sdk/3.0/docs/man/html/clCreateBuffer.html),
20//! it is v3.0 API function), the error code `CL_FUNCTION_NOT_AVAILABLE = -2001` will be returned.
21//!
22//! ## Usage
23//!
24//! You do *not* need to install any OpenCL hardware driver(s) to run your code which depends on `opencl-dynamic-sys` library.
25//!
26//! Just include the library in the `dependencies` section in your `Cargo.toml` file:
27//! ```custom
28//! [dependencies]
29//! opencl-dynamic-sys = "0.1"
30//! ```
31//!
32//! ## Search path
33//!
34//! By default, the OpenCL shared library is searched as follows:
35//!
36//! - on Windows: `OpenCL.dll`
37//! - on macOS: `/System/Library/Frameworks/OpenCL.framework/OpenCL`
38//! - otherwise: `libOpenCL.so`
39//!
40//! If you have the OpenCL shared library in non-standard place, you can use an environment variable `OPENCL_DYLIB_PATH`
41//! to define where to look for the library (the value of the variable is a comma-separated string):
42//! ```custom
43//! OPENCL_DYLIB_PATH=/usr/lib/libOpenCL.so;/var/lib/OpenCL;%DESKTOP%/OpenCL.dll
44//! ```
45//!
46//! If the OpenCL shared library is found, then the call of `opencl-dynamic-sys::is_opencl_runtime_available()` will return `true`.
47//!
48//! ## License
49//! This library is distributed under the terms of the MIT license, see [LICENSE](https://github.com/passware/opencl-dynamic-sys-rs/blob/main/LICENSE) for details.
50
51mod errors;
52pub use errors::{Error, Result};
53
54/// Constants used by the OpenCL API.
55pub mod constants;
56
57/// Types used by the OpenCL API.
58pub mod types;
59
60mod container;
61pub use container::{is_opencl_runtime_available, load_library, OpenCl, OpenClRuntime};