Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(More) Invalid SPIR-V generated from Darktable / Geekbench 5 kernels #1104

Open
kpet opened this issue May 12, 2023 · 2 comments
Open

(More) Invalid SPIR-V generated from Darktable / Geekbench 5 kernels #1104

kpet opened this issue May 12, 2023 · 2 comments

Comments

@kpet
Copy link
Contributor

kpet commented May 12, 2023

#1102 made it possible for many more Darktable kernel source files to be compiled but not all of them yet.

The attached source, compiled with the following options:

clspv source.cl  -w -cl-fast-relaxed-math  -DNVIDIA=1 -I"/usr/share/darktable/kernels" -cl-single-precision-constant  -cl-kernel-arg-info   -fp16=0  -rewrite-packed-structs  -std430-ubo-layout  -decorate-nonuniform    -arch=spir  --use-native-builtins=acos,acosh,acospi,asin,asinh,asinpi,atan,atan2,atan2pi,atanh,atanpi,ceil,copysign,fabs,fdim,floor,fma,fmax,fmin,frexp,half_rsqrt,half_sqrt,isequal,isfinite,isgreater,isgreaterequal,isinf,isless,islessequal,islessgreater,isnan,isnormal,isnotequal,isordered,isunordered,ldexp,mad,rint,round,rsqrt,signbit,sqrt,tanh,trunc,  -spv-version=1.6  -max-pushconstant-size=256  -max-ubo-size=65536  -global-offset  -long-vector  -module-constants-in-storage-buffer  -cl-arm-non-uniform-work-group-size     -o compiled.spv

produces a SPIR-V module that fails validation with the following message:

error: 736: AtomicOr: expected Pointer to point to a value of type Result Type
  %520 = OpAtomicOr %uint %516 %uint_1 %uint_80 %uint_0

source.txt

@alan-baker
Copy link
Collaborator

This is tricky. Our fake pointer casting doesn't work with atomics. So we'd have to prefer the uint type for inference. That's a reasonably large change. This isn't the only time being greedy is detrimental though so it might be worth investigating.

Another alternative would be for darktable to use cl_khr_float_atomics and implement support for the various SPIR-V extensions like SPV_KHR_shader_atomic_float_add, but that requires changing darktable. Another problem with that route (beyond extension support) is that LLVM apppears to have "optimized" to atomic or which isn't supported with float. Maybe that wouldn't happen if it was all done in floats, but SPIR-V only supports add, min, and max.

@kpet
Copy link
Contributor Author

kpet commented May 16, 2023

I'm seeing a similar validation error with a kernel from Geekbench 5 too (attached):

error: 823: AtomicIAdd: expected Pointer to point to a value of type Result Type
  %622 = OpAtomicIAdd %uint %621 %uint_1 %uint_80 %619

Build options:

clspv source.cl  -cl-single-precision-constant  -cl-kernel-arg-info   -fp16=0  -rewrite-packed-structs  -std430-ubo-layout  -decorate-nonuniform    -arch=spir  --use-native-builtins=acos,acosh,acospi,asin,asinh,asinpi,atan,atan2,atan2pi,atanh,atanpi,ceil,copysign,fabs,fdim,floor,fma,fmax,fmin,frexp,half_rsqrt,half_sqrt,isequal,isfinite,isgreater,isgreaterequal,isinf,isless,islessequal,islessgreater,isnan,isnormal,isnotequal,isordered,isunordered,ldexp,mad,rint,round,rsqrt,signbit,sqrt,tanh,trunc,  -spv-version=1.6  -max-pushconstant-size=256  -max-ubo-size=65536  -global-offset  -long-vector  -module-constants-in-storage-buffer  -cl-arm-non-uniform-work-group-size     -o compiled.spv

source.txt

@kpet kpet changed the title (More) Invalid SPIR-V generated from Darktables kernels (More) Invalid SPIR-V generated from Darktable / Geekbench 5 kernels May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants