A modern OpenCL wrapper for Zig language, providing easy-to-use interfaces for OpenCL functionalities.
- Zig 0.13.0 or higher
- OpenCL 1.0 or higher
To include this wrapper in your Zig project as a submodule, follow these steps:
- Edit your
build.zig.zon
: Add thezig-opencl
dependency to yourbuild.zig.zon
file, similar to the following:
.{
// ......
.dependencies = .{
.@"zig-opencl" = .{
.url = "https://github.com/kython28/zig-opencl/archive/refs/tags/v0.3.0.tar.gz",
.hash = "1220f5e5f896607483e5177125f8b6bdf4343d37b4c0bccbe6733f545fafe9a60345",
},
},
// .....
}
- Edit your
build.zig
: Configure yourbuild.zig
file to include thezig-opencl
module:
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const package = b.dependency("zig-opencl", .{
.target = target,
.optimize = optimize
});
const module = package.module("opencl");
const app = b.addExecutable(.{
.name = "test-opencl",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize
});
app.root_module.addImport("opencl", module);
b.installArtifact(app);
}
- Build the project: Now you can build your project using Zig:
zig build
This setup will allow you to use the zig-opencl
wrapper in your project.
This OpenCL wrapper for Zig leverages several features of the Zig programming language, such as error handling and slices, to provide a safer and easier-to-use interface compared to the traditional C approach. For detailed documentation, please refer to the Documentation.
This wrapper does not include all existing OpenCL functions. It was specifically created for use in my projects, and therefore, only includes the functions I frequently use. If you need a function that is not included, please open an issue, and I will be happy to add it. Alternatively, if you would like to collaborate, feel free to create a pull request, and I will review and include it in the repository.