I need compile OpenCL kernels in SPIR-V to use with Vulkan, I tried with Google CLSPV https://github.com/google/clspv, but the problem occur with vectorization, functions like vload8 doesn't work. So I need compile OpenCL kernels in SPIR-V using clang.
I'm the project lead for Clspv. Jesse is right overall.
The lack of support for vectors of length 8 and 16 is deliberately out of scope for now.
That's because Vulkan itself does not support that.
We haven't added the support to mimic such support, and don't have plans to do so even in the medium term.
There is more info on an old closed issue:
https://github.com/google/clspv/issues/8
Clspv is the only toolchain I'm aware of that compiles OpenCL C to Vulkan-compatible SPIR-V. You'll need to file an issue against Clspv; attaching a kernel that fails to compile properly would help a lot.
https://github.com/KhronosGroup/SPIR/tree/spirv-1.1
You can follow this Khronos project.
clang -cc1 -emit-spirv -triple=spir-unknown-unknown -cl-std=c++ -I include kernel.cl -o kernel.spv #For OpenCL C++
clang -cc1 -emit-spirv -triple=spir-unknown-unknown -cl-std=CL2.0 -include opencl.h kernel.cl -o kernel.spv #For OpenCL C
-emit-spirv
option. –
Invite Given
__kernel void add(__global float *a, __global float *result) {
float8 f = vload8(0, a);
vstore8(f, 0, result);
}
Run
$ clang -cc1 -emit-llvm-bc -triple spir64-unknown-unknown -cl-std=CL3.0 vadd.cl -finclude-default-header -o vadd.bc
$ llvm-spirv vadd.bc -o vadd.spv
$ spirv-dis vadd.spv
Clang can also generate SPIR-V directly:
$ clang -target spirv64 vadd.cl -Xclang -finclude-default-header -o vadd.spv
© 2022 - 2025 — McMap. All rights reserved.