Skip to content

[libspirv] Refine atomic built-ins headers, add some group built-ins headers #18613

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

Merged
merged 1 commit into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 5 additions & 21 deletions libclc/libspirv/include/libspirv/atomic/atomic_dec.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,8 @@
//
//===----------------------------------------------------------------------===//

_CLC_OVERLOAD _CLC_DECL int __spirv_AtomicIDecrement(local int *, int Scope,
enum MemorySemanticsMask);
_CLC_OVERLOAD _CLC_DECL int __spirv_AtomicIDecrement(global int *, int Scope,
enum MemorySemanticsMask);
_CLC_OVERLOAD _CLC_DECL uint __spirv_AtomicIDecrement(local uint *, int Scope,
enum MemorySemanticsMask);
_CLC_OVERLOAD _CLC_DECL uint __spirv_AtomicIDecrement(global uint *, int Scope,
enum MemorySemanticsMask);

#ifdef cl_khr_int64_base_atomics
_CLC_OVERLOAD _CLC_DECL long __spirv_AtomicIDecrement(local long *, int Scope,
enum MemorySemanticsMask);
_CLC_OVERLOAD _CLC_DECL long __spirv_AtomicIDecrement(global long *, int Scope,
enum MemorySemanticsMask);
_CLC_OVERLOAD _CLC_DECL unsigned long
__spirv_AtomicIDecrement(local unsigned long *, int Scope,
enum MemorySemanticsMask);
_CLC_OVERLOAD _CLC_DECL unsigned long
__spirv_AtomicIDecrement(global unsigned long *, int Scope,
enum MemorySemanticsMask);
#endif
#define __SPIRV_FUNCTION_S __spirv_AtomicIDecrement
#define __SPIRV_FUNCTION_U __spirv_AtomicIDecrement
#define __SPIRV_INT64_BASE
#define __SPIRV_NO_VALUE_ARG
#include <libspirv/atomic/atomic_decl.inc>
25 changes: 25 additions & 0 deletions libclc/libspirv/include/libspirv/atomic/atomic_decl.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@
//
//===----------------------------------------------------------------------===//

#ifdef __SPIRV_NO_VALUE_ARG
#define __CLC_DECLARE_ATOMIC(ADDRSPACE, TYPE, NAME) \
_CLC_OVERLOAD _CLC_DECL TYPE NAME(ADDRSPACE TYPE *, int Scope, \
int MemorySemanticsMask);
#elif defined(__SPIRV_RETURN_VOID)
#define __CLC_DECLARE_ATOMIC(ADDRSPACE, TYPE, NAME) \
_CLC_OVERLOAD _CLC_DECL void NAME(ADDRSPACE TYPE *, int Scope, \
int MemorySemanticsMask, TYPE);
#else
#define __CLC_DECLARE_ATOMIC(ADDRSPACE, TYPE, NAME) \
_CLC_OVERLOAD _CLC_DECL TYPE NAME(ADDRSPACE TYPE *, int Scope, \
int MemorySemanticsMask, TYPE);
#endif

#define __CLC_DECLARE_ATOMIC_ADDRSPACE(TYPE, NAME) \
__CLC_DECLARE_ATOMIC(global, TYPE, NAME) \
Expand All @@ -32,12 +42,27 @@ __CLC_DECLARE_ATOMIC_ADDRSPACE(ulong, __SPIRV_FUNCTION_U)
#endif
#endif

#ifdef __SPIRV_FLOATING_POINT
#ifdef cl_khr_fp16
__CLC_DECLARE_ATOMIC_ADDRSPACE(half, __SPIRV_FUNCTION)
#endif // cl_khr_fp16
__CLC_DECLARE_ATOMIC_ADDRSPACE(float, __SPIRV_FUNCTION)
#if defined(cl_khr_fp64) && defined(cl_khr_int64_base_atomics) && \
defined(cl_khr_int64_extended_atomics)
__CLC_DECLARE_ATOMIC_ADDRSPACE(double, __SPIRV_FUNCTION)
#endif
#endif

#undef __CLC_DECLARE_ATOMIC_ADDRSPACE
#undef __CLC_DECLARE_ATOMIC

#undef __SPIRV_FUNCTION
#undef __SPIRV_FUNCTION_S
#undef __SPIRV_FUNCTION_S_LEN
#undef __SPIRV_FUNCTION_U
#undef __SPIRV_FUNCTION_U_LEN
#undef __SPIRV_INT64_BASE
#undef __SPIRV_INT64_EXTENDED
#undef __SPIRV_NO_VALUE_ARG
#undef __SPIRV_RETURN_VOID
#undef __SPIRV_FLOATING_POINT
26 changes: 5 additions & 21 deletions libclc/libspirv/include/libspirv/atomic/atomic_inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,8 @@
//
//===----------------------------------------------------------------------===//

_CLC_OVERLOAD _CLC_DECL int __spirv_AtomicIIncrement(local int *, int Scope,
enum MemorySemanticsMask);
_CLC_OVERLOAD _CLC_DECL int __spirv_AtomicIIncrement(global int *, int Scope,
enum MemorySemanticsMask);
_CLC_OVERLOAD _CLC_DECL uint __spirv_AtomicIIncrement(local uint *, int Scope,
enum MemorySemanticsMask);
_CLC_OVERLOAD _CLC_DECL uint __spirv_AtomicIIncrement(global uint *, int Scope,
enum MemorySemanticsMask);

#ifdef cl_khr_int64_base_atomics
_CLC_OVERLOAD _CLC_DECL long __spirv_AtomicIIncrement(local long *, int Scope,
enum MemorySemanticsMask);
_CLC_OVERLOAD _CLC_DECL long __spirv_AtomicIIncrement(global long *, int Scope,
enum MemorySemanticsMask);
_CLC_OVERLOAD _CLC_DECL unsigned long
__spirv_AtomicIIncrement(local unsigned long *, int Scope,
enum MemorySemanticsMask);
_CLC_OVERLOAD _CLC_DECL unsigned long
__spirv_AtomicIIncrement(global unsigned long *, int Scope,
enum MemorySemanticsMask);
#endif
#define __SPIRV_FUNCTION_S __spirv_AtomicIIncrement
#define __SPIRV_FUNCTION_U __spirv_AtomicIIncrement
#define __SPIRV_INT64_BASE
#define __SPIRV_NO_VALUE_ARG
#include <libspirv/atomic/atomic_decl.inc>
26 changes: 8 additions & 18 deletions libclc/libspirv/include/libspirv/atomic/atomic_load.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,11 @@
//
//===----------------------------------------------------------------------===//

#define DECL(TYPE, AS) \
_CLC_OVERLOAD _CLC_DECL TYPE __spirv_AtomicLoad(AS TYPE *, int, int);

#define DECL_AS(TYPE) \
DECL(TYPE, global) \
DECL(TYPE, local) \
DECL(TYPE, )

DECL_AS(int)
DECL_AS(unsigned int)

#ifdef cl_khr_int64_base_atomics
DECL_AS(long)
DECL_AS(unsigned long)
#endif

#undef DECL_AS
#undef DECL
#define __SPIRV_FUNCTION __spirv_AtomicLoad
#define __SPIRV_FUNCTION_S __spirv_AtomicLoad
#define __SPIRV_FUNCTION_U __spirv_AtomicLoad
#define __SPIRV_INT64_BASE
#define __SPIRV_INT64_EXTENDED
#define __SPIRV_NO_VALUE_ARG
#define __SPIRV_FLOATING_POINT
#include <libspirv/atomic/atomic_decl.inc>
26 changes: 8 additions & 18 deletions libclc/libspirv/include/libspirv/atomic/atomic_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,11 @@
//
//===----------------------------------------------------------------------===//

#define DECL(TYPE, AS) \
_CLC_OVERLOAD _CLC_DECL void __spirv_AtomicStore( \
AS TYPE *, int Scope, int MemorySemanticsMask, TYPE);

#define DECL_AS(TYPE) \
DECL(TYPE, global) \
DECL(TYPE, local)

DECL_AS(int)
DECL_AS(unsigned int)

#ifdef cl_khr_int64_base_atomics
DECL_AS(long)
DECL_AS(unsigned long)
#endif

#undef DECL_AS
#undef DECL
#define __SPIRV_FUNCTION __spirv_AtomicStore
#define __SPIRV_FUNCTION_S __spirv_AtomicStore
#define __SPIRV_FUNCTION_U __spirv_AtomicStore
#define __SPIRV_INT64_BASE
#define __SPIRV_INT64_EXTENDED
#define __SPIRV_RETURN_VOID
#define __SPIRV_FLOATING_POINT
#include <libspirv/atomic/atomic_decl.inc>
9 changes: 2 additions & 7 deletions libclc/libspirv/include/libspirv/atomic/atomic_xchg.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
#define __SPIRV_FUNCTION_S __spirv_AtomicExchange
#define __SPIRV_FUNCTION_U __spirv_AtomicExchange
#define __SPIRV_INT64_BASE

_CLC_OVERLOAD _CLC_DECL float __spirv_AtomicExchange(local float *, int Scope,
int MemorySemanticsMask,
float);
_CLC_OVERLOAD _CLC_DECL float __spirv_AtomicExchange(global float *, int Scope,
int MemorySemanticsMask,
float);
#define __SPIRV_INT64_EXTENDED
#define __SPIRV_FLOATING_POINT
#include <libspirv/atomic/atomic_decl.inc>
16 changes: 16 additions & 0 deletions libclc/libspirv/include/libspirv/group/group_add.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#define __CLC_FUNCTION __spirv_GroupIAdd
#define __CLC_NON_UNIFORM_FUNCTION __spirv_GroupNonUniformIAdd
#define __CLC_BODY <libspirv/group/group_decl.inc>

#include <clc/integer/gentype.inc>

#undef __CLC_FUNCTION
#undef __CLC_NON_UNIFORM_FUNCTION
16 changes: 16 additions & 0 deletions libclc/libspirv/include/libspirv/group/group_bitwise_and.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#define __CLC_FUNCTION __spirv_GroupBitwiseAndKHR
#define __CLC_NON_UNIFORM_FUNCTION __spirv_GroupNonUniformBitwiseAnd
#define __CLC_BODY <libspirv/group/group_decl.inc>

#include <clc/integer/gentype.inc>

#undef __CLC_FUNCTION
#undef __CLC_NON_UNIFORM_FUNCTION
16 changes: 16 additions & 0 deletions libclc/libspirv/include/libspirv/group/group_bitwise_or.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#define __CLC_FUNCTION __spirv_GroupBitwiseOrKHR
#define __CLC_NON_UNIFORM_FUNCTION __spirv_GroupNonUniformBitwiseOr
#define __CLC_BODY <libspirv/group/group_decl.inc>

#include <clc/integer/gentype.inc>

#undef __CLC_FUNCTION
#undef __CLC_NON_UNIFORM_FUNCTION
16 changes: 16 additions & 0 deletions libclc/libspirv/include/libspirv/group/group_bitwise_xor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#define __CLC_FUNCTION __spirv_GroupBitwiseXorKHR
#define __CLC_NON_UNIFORM_FUNCTION __spirv_GroupNonUniformBitwiseXor
#define __CLC_BODY <libspirv/group/group_decl.inc>

#include <clc/integer/gentype.inc>

#undef __CLC_FUNCTION
#undef __CLC_NON_UNIFORM_FUNCTION
19 changes: 19 additions & 0 deletions libclc/libspirv/include/libspirv/group/group_broadcast.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#define __CLC_BODY <libspirv/group/group_broadcast.inc>
#include <clc/integer/gentype.inc>

#define __CLC_BODY <libspirv/group/group_broadcast.inc>
#include <clc/math/gentype.inc>

#define __CLC_BODY <libspirv/group/group_non_uniform_broadcast.inc>
#include <clc/integer/gentype.inc>

#define __CLC_BODY <libspirv/group/group_non_uniform_broadcast.inc>
#include <clc/math/gentype.inc>
19 changes: 19 additions & 0 deletions libclc/libspirv/include/libspirv/group/group_broadcast.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#define __GROUP_BROADCAST(LocalIdType) \
_CLC_OVERLOAD _CLC_DEF _CLC_CONVERGENT __CLC_GENTYPE __spirv_GroupBroadcast( \
int Execution, __CLC_GENTYPE Value, LocalIdType LocalId);

__GROUP_BROADCAST(ulong)
__GROUP_BROADCAST(ulong2)
__GROUP_BROADCAST(ulong3)
__GROUP_BROADCAST(uint)
__GROUP_BROADCAST(uint2)
__GROUP_BROADCAST(uint3)
#undef __GROUP_BROADCAST
13 changes: 13 additions & 0 deletions libclc/libspirv/include/libspirv/group/group_decl.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

_CLC_OVERLOAD _CLC_DEF _CLC_CONVERGENT __CLC_GENTYPE
__CLC_FUNCTION(int Execution, int Operation, __CLC_GENTYPE X);

_CLC_OVERLOAD _CLC_DEF _CLC_CONVERGENT __CLC_GENTYPE __CLC_NON_UNIFORM_FUNCTION(
int Execution, int Operation, __CLC_GENTYPE Value, uint ClusterSize);
16 changes: 16 additions & 0 deletions libclc/libspirv/include/libspirv/group/group_mul.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#define __CLC_FUNCTION __spirv_GroupIMulKHR
#define __CLC_NON_UNIFORM_FUNCTION __spirv_GroupNonUniformIMul
#define __CLC_BODY <libspirv/group/group_decl.inc>

#include <clc/integer/gentype.inc>

#undef __CLC_FUNCTION
#undef __CLC_NON_UNIFORM_FUNCTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#define __GROUP_NONUNIFORM_BROADCAST(IdType) \
_CLC_OVERLOAD _CLC_DEF _CLC_CONVERGENT __CLC_GENTYPE \
__spirv_GroupNonUniformBroadcast(int Execution, __CLC_GENTYPE Value, \
IdType Id);

__GROUP_NONUNIFORM_BROADCAST(uint)
__GROUP_NONUNIFORM_BROADCAST(ulong)
#undef __GROUP_NONUNIFORM_BROADCAST
17 changes: 17 additions & 0 deletions libclc/libspirv/include/libspirv/group/group_shuffle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#define __CLC_FUNCTION __spirv_GroupNonUniformShuffle

#define __CLC_BODY <libspirv/group/group_shuffle.inc>
#include <clc/integer/gentype.inc>

#define __CLC_BODY <libspirv/group/group_shuffle.inc>
#include <clc/math/gentype.inc>

#undef __CLC_FUNCTION
10 changes: 10 additions & 0 deletions libclc/libspirv/include/libspirv/group/group_shuffle.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

_CLC_OVERLOAD _CLC_DEF _CLC_CONVERGENT __CLC_GENTYPE
__CLC_FUNCTION(int Execution, __CLC_GENTYPE Value, uint IdMaskDelta);
17 changes: 17 additions & 0 deletions libclc/libspirv/include/libspirv/group/group_shuffle_down.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#define __CLC_FUNCTION __spirv_GroupNonUniformShuffleDown

#define __CLC_BODY <libspirv/group/group_shuffle.inc>
#include <clc/integer/gentype.inc>

#define __CLC_BODY <libspirv/group/group_shuffle.inc>
#include <clc/math/gentype.inc>

#undef __CLC_FUNCTION
Loading