Categories
GPU Computing
  • Github CLI
  • SSH
  • HTTPS
Clone Repo

Zig Build for the OpenCL ICD Loader

This project builds the OpenCL ICD with the Zig Build System. The OpenCL ICD takes care of finding appropriate drivers across different hardware and operating systems.

Traditionally, you install the ICD on your system with sudo apt install ocl-icd-opencl-dev and use $(CC) ... -lOpenCL to build your program.

This is not desirable becuase the linking is dynamic against libOpenCL.so.

Static linking with zig provides better portability and reliability.

Usage

Add the right release to your build.zig.zon

zig fetch --save https://github.com/e253/zig-ocl/archive/refs/tags/v3.0.16.tar.gz

and add the following to your build.zig

pub fn build(b: *std.Build) void {
    const ocl_icd = b.dependency("zig-ocl", .{
        .target = target,
        .optimize = optimize
    });
    your_compilation.linkLibrary(ocl_icd.artifact("opencl")); 
}

Also, see how test.c is built in the build.zig of this repository.

Supported Platforms

Tested on

  • Windows
  • Linux (Ubuntu 22.04 WSL)
  • MacOS
About
Zig package for the OpenCL ICD Loader
Owner
e253 (User)
Last Commit
2024-06-15
Latest Release
Latest Release Date
2024-06-15
Created
2024-06-15