Repository navigation
Translate the remaining atomic instructions - #17
Merged
Merged
Conversation
SPIR-V gives the weak compare-exchange the semantics of the strong one, so lower it the same way, as the Khronos translator does: atomic_cmpxchg below OpenCL C 2.0, atomic_compare_exchange_strong_explicit from 2.0.
OpAtomicFMinEXT and OpAtomicFMaxEXT (SPV_EXT_shader_atomic_float_min_max) lower like the floating-point atomic add, to atomic_fetch_min_explicit and atomic_fetch_max_explicit on atomic_float or atomic_double under cl_ext_float_atomics, and are refused below OpenCL C 2.0. Their NaN and signed-zero behaviour is the same in both extensions. Half-precision min/max stays unsupported, because atomic_c11_pointer has no atomic_half.
OpAtomicFlagTestAndSet and OpAtomicFlagClear lower to atomic_flag_test_and_set_explicit and atomic_flag_clear_explicit on the flag's 32-bit integer storage reinterpreted as atomic_flag, keeping their memory order and scope. OpenCL C 1.x has no flags. As in the Khronos translator, relaxed flag operations there exchange 1 or 0 into the storage, which works because only flag instructions may access it. Ordered ones are refused, like the other 1.x atomics.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #14. These atomic instructions failed translation, and are now lowered the way the Khronos SPIRV-LLVM-Translator lowers them:
OpAtomicCompareExchangeWeaktakes theOpAtomicCompareExchangepath, since SPIR-V gives it the same semantics:atomic_cmpxchgbelow OpenCL C 2.0,atomic_compare_exchange_strong_explicitfrom 2.0.OpAtomicFMinEXT/OpAtomicFMaxEXTlower toatomic_fetch_min_explicit/atomic_fetch_max_explicitonatomic_float/atomic_doubleundercl_ext_float_atomics. They are refused below 2.0, like the float add: there, Khronos emits a floatatomic_min/atomic_max, which OpenCL C 1.x doesn't have. Half-precision min/max stays unsupported.OpAtomicFlagTestAndSet/OpAtomicFlagClearlower toatomic_flag_test_and_set_explicit/atomic_flag_clear_explicitfrom 2.0. Below 2.0, relaxed flag operations exchange 1 or 0 into the flag's storage, as Khronos does there. Ordered ones are refused, like the other 1.x atomics.The new tests compile their output with clang, which accepts the float min/max and flag builtins since llvm#168016 (clang 22).
Once this is in a spirv2clc_jll release, OpenCL.jl can stop masking the float min/max features on the spirv2clc path (
src/compiler/compilation.jl).