Are there anything equal to SYCL of C++?

https://www.khronos.org/sycl/
SYCL is an open, royalty-free, cross-platform abstraction layer that enables code for heterogeneous and offload processors to be written using modern ISO C++

Zig has SPIR-V backend. You can write code that can be compiled to GPU. See demos here GitHub - Snektron/zig-opencl-spirv-demos: Demo OpenCL kernels written in Zig

You can write something like this, so it can be compiled both to CPU and GPU:

inline fn saxpyImpl(y: anytype, x: anytype, a: f32) void {
    y.* += x.* * a;
}

/// Performs y = y + x * a.
pub fn saxpy(y: *f32, x: *const f32, a: f32) void {
    return saxpyImpl(y, x, a);
}

fn saxpyKernel(
    y: [*]addrspace(.global) f32,
    x: [*]addrspace(.global) const f32,
    a: f32,
) callconv(.kernel) void {
    const gid = @workGroupId(0) * @workGroupSize(0) + @workItemId(0);
    saxpyImpl(&y[gid], &x[gid], a);
}

comptime {
    if (builtin.zig_backend == .stage2_spirv) {
        @export(&saxpyKernel, .{ .name = "saxpy" });
    }
}

I suggest using 0.14.1, or 0.15-dev before pre-writergate or wait for spirv: refactor and remove deduplication ISel by alichraghi · Pull Request #24661 · ziglang/zig · GitHub merge.

I cannot help but pointing out SYCL = https://softwareyoucan.love from @kristoff :slight_smile:

1 Like