Skip to content

Commit 171aa09

Browse files
authored
[libspirv] Refine atomic built-ins headers, add some group built-ins headers (#18613)
1 parent d55e6f3 commit 171aa09

23 files changed

+325
-85
lines changed

libclc/libspirv/include/libspirv/atomic/atomic_dec.h

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
_CLC_OVERLOAD _CLC_DECL int __spirv_AtomicIDecrement(local int *, int Scope,
10-
enum MemorySemanticsMask);
11-
_CLC_OVERLOAD _CLC_DECL int __spirv_AtomicIDecrement(global int *, int Scope,
12-
enum MemorySemanticsMask);
13-
_CLC_OVERLOAD _CLC_DECL uint __spirv_AtomicIDecrement(local uint *, int Scope,
14-
enum MemorySemanticsMask);
15-
_CLC_OVERLOAD _CLC_DECL uint __spirv_AtomicIDecrement(global uint *, int Scope,
16-
enum MemorySemanticsMask);
17-
18-
#ifdef cl_khr_int64_base_atomics
19-
_CLC_OVERLOAD _CLC_DECL long __spirv_AtomicIDecrement(local long *, int Scope,
20-
enum MemorySemanticsMask);
21-
_CLC_OVERLOAD _CLC_DECL long __spirv_AtomicIDecrement(global long *, int Scope,
22-
enum MemorySemanticsMask);
23-
_CLC_OVERLOAD _CLC_DECL unsigned long
24-
__spirv_AtomicIDecrement(local unsigned long *, int Scope,
25-
enum MemorySemanticsMask);
26-
_CLC_OVERLOAD _CLC_DECL unsigned long
27-
__spirv_AtomicIDecrement(global unsigned long *, int Scope,
28-
enum MemorySemanticsMask);
29-
#endif
9+
#define __SPIRV_FUNCTION_S __spirv_AtomicIDecrement
10+
#define __SPIRV_FUNCTION_U __spirv_AtomicIDecrement
11+
#define __SPIRV_INT64_BASE
12+
#define __SPIRV_NO_VALUE_ARG
13+
#include <libspirv/atomic/atomic_decl.inc>

libclc/libspirv/include/libspirv/atomic/atomic_decl.inc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,19 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#ifdef __SPIRV_NO_VALUE_ARG
10+
#define __CLC_DECLARE_ATOMIC(ADDRSPACE, TYPE, NAME) \
11+
_CLC_OVERLOAD _CLC_DECL TYPE NAME(ADDRSPACE TYPE *, int Scope, \
12+
int MemorySemanticsMask);
13+
#elif defined(__SPIRV_RETURN_VOID)
14+
#define __CLC_DECLARE_ATOMIC(ADDRSPACE, TYPE, NAME) \
15+
_CLC_OVERLOAD _CLC_DECL void NAME(ADDRSPACE TYPE *, int Scope, \
16+
int MemorySemanticsMask, TYPE);
17+
#else
918
#define __CLC_DECLARE_ATOMIC(ADDRSPACE, TYPE, NAME) \
1019
_CLC_OVERLOAD _CLC_DECL TYPE NAME(ADDRSPACE TYPE *, int Scope, \
1120
int MemorySemanticsMask, TYPE);
21+
#endif
1222

1323
#define __CLC_DECLARE_ATOMIC_ADDRSPACE(TYPE, NAME) \
1424
__CLC_DECLARE_ATOMIC(global, TYPE, NAME) \
@@ -32,12 +42,27 @@ __CLC_DECLARE_ATOMIC_ADDRSPACE(ulong, __SPIRV_FUNCTION_U)
3242
#endif
3343
#endif
3444

45+
#ifdef __SPIRV_FLOATING_POINT
46+
#ifdef cl_khr_fp16
47+
__CLC_DECLARE_ATOMIC_ADDRSPACE(half, __SPIRV_FUNCTION)
48+
#endif // cl_khr_fp16
49+
__CLC_DECLARE_ATOMIC_ADDRSPACE(float, __SPIRV_FUNCTION)
50+
#if defined(cl_khr_fp64) && defined(cl_khr_int64_base_atomics) && \
51+
defined(cl_khr_int64_extended_atomics)
52+
__CLC_DECLARE_ATOMIC_ADDRSPACE(double, __SPIRV_FUNCTION)
53+
#endif
54+
#endif
55+
3556
#undef __CLC_DECLARE_ATOMIC_ADDRSPACE
3657
#undef __CLC_DECLARE_ATOMIC
3758

59+
#undef __SPIRV_FUNCTION
3860
#undef __SPIRV_FUNCTION_S
3961
#undef __SPIRV_FUNCTION_S_LEN
4062
#undef __SPIRV_FUNCTION_U
4163
#undef __SPIRV_FUNCTION_U_LEN
4264
#undef __SPIRV_INT64_BASE
4365
#undef __SPIRV_INT64_EXTENDED
66+
#undef __SPIRV_NO_VALUE_ARG
67+
#undef __SPIRV_RETURN_VOID
68+
#undef __SPIRV_FLOATING_POINT

libclc/libspirv/include/libspirv/atomic/atomic_inc.h

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
_CLC_OVERLOAD _CLC_DECL int __spirv_AtomicIIncrement(local int *, int Scope,
10-
enum MemorySemanticsMask);
11-
_CLC_OVERLOAD _CLC_DECL int __spirv_AtomicIIncrement(global int *, int Scope,
12-
enum MemorySemanticsMask);
13-
_CLC_OVERLOAD _CLC_DECL uint __spirv_AtomicIIncrement(local uint *, int Scope,
14-
enum MemorySemanticsMask);
15-
_CLC_OVERLOAD _CLC_DECL uint __spirv_AtomicIIncrement(global uint *, int Scope,
16-
enum MemorySemanticsMask);
17-
18-
#ifdef cl_khr_int64_base_atomics
19-
_CLC_OVERLOAD _CLC_DECL long __spirv_AtomicIIncrement(local long *, int Scope,
20-
enum MemorySemanticsMask);
21-
_CLC_OVERLOAD _CLC_DECL long __spirv_AtomicIIncrement(global long *, int Scope,
22-
enum MemorySemanticsMask);
23-
_CLC_OVERLOAD _CLC_DECL unsigned long
24-
__spirv_AtomicIIncrement(local unsigned long *, int Scope,
25-
enum MemorySemanticsMask);
26-
_CLC_OVERLOAD _CLC_DECL unsigned long
27-
__spirv_AtomicIIncrement(global unsigned long *, int Scope,
28-
enum MemorySemanticsMask);
29-
#endif
9+
#define __SPIRV_FUNCTION_S __spirv_AtomicIIncrement
10+
#define __SPIRV_FUNCTION_U __spirv_AtomicIIncrement
11+
#define __SPIRV_INT64_BASE
12+
#define __SPIRV_NO_VALUE_ARG
13+
#include <libspirv/atomic/atomic_decl.inc>

libclc/libspirv/include/libspirv/atomic/atomic_load.h

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,11 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#define DECL(TYPE, AS) \
10-
_CLC_OVERLOAD _CLC_DECL TYPE __spirv_AtomicLoad(AS TYPE *, int, int);
11-
12-
#define DECL_AS(TYPE) \
13-
DECL(TYPE, global) \
14-
DECL(TYPE, local) \
15-
DECL(TYPE, )
16-
17-
DECL_AS(int)
18-
DECL_AS(unsigned int)
19-
20-
#ifdef cl_khr_int64_base_atomics
21-
DECL_AS(long)
22-
DECL_AS(unsigned long)
23-
#endif
24-
25-
#undef DECL_AS
26-
#undef DECL
9+
#define __SPIRV_FUNCTION __spirv_AtomicLoad
10+
#define __SPIRV_FUNCTION_S __spirv_AtomicLoad
11+
#define __SPIRV_FUNCTION_U __spirv_AtomicLoad
12+
#define __SPIRV_INT64_BASE
13+
#define __SPIRV_INT64_EXTENDED
14+
#define __SPIRV_NO_VALUE_ARG
15+
#define __SPIRV_FLOATING_POINT
16+
#include <libspirv/atomic/atomic_decl.inc>

libclc/libspirv/include/libspirv/atomic/atomic_store.h

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,11 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#define DECL(TYPE, AS) \
10-
_CLC_OVERLOAD _CLC_DECL void __spirv_AtomicStore( \
11-
AS TYPE *, int Scope, int MemorySemanticsMask, TYPE);
12-
13-
#define DECL_AS(TYPE) \
14-
DECL(TYPE, global) \
15-
DECL(TYPE, local)
16-
17-
DECL_AS(int)
18-
DECL_AS(unsigned int)
19-
20-
#ifdef cl_khr_int64_base_atomics
21-
DECL_AS(long)
22-
DECL_AS(unsigned long)
23-
#endif
24-
25-
#undef DECL_AS
26-
#undef DECL
9+
#define __SPIRV_FUNCTION __spirv_AtomicStore
10+
#define __SPIRV_FUNCTION_S __spirv_AtomicStore
11+
#define __SPIRV_FUNCTION_U __spirv_AtomicStore
12+
#define __SPIRV_INT64_BASE
13+
#define __SPIRV_INT64_EXTENDED
14+
#define __SPIRV_RETURN_VOID
15+
#define __SPIRV_FLOATING_POINT
16+
#include <libspirv/atomic/atomic_decl.inc>

libclc/libspirv/include/libspirv/atomic/atomic_xchg.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99
#define __SPIRV_FUNCTION_S __spirv_AtomicExchange
1010
#define __SPIRV_FUNCTION_U __spirv_AtomicExchange
1111
#define __SPIRV_INT64_BASE
12-
13-
_CLC_OVERLOAD _CLC_DECL float __spirv_AtomicExchange(local float *, int Scope,
14-
int MemorySemanticsMask,
15-
float);
16-
_CLC_OVERLOAD _CLC_DECL float __spirv_AtomicExchange(global float *, int Scope,
17-
int MemorySemanticsMask,
18-
float);
12+
#define __SPIRV_INT64_EXTENDED
13+
#define __SPIRV_FLOATING_POINT
1914
#include <libspirv/atomic/atomic_decl.inc>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#define __CLC_FUNCTION __spirv_GroupIAdd
10+
#define __CLC_NON_UNIFORM_FUNCTION __spirv_GroupNonUniformIAdd
11+
#define __CLC_BODY <libspirv/group/group_decl.inc>
12+
13+
#include <clc/integer/gentype.inc>
14+
15+
#undef __CLC_FUNCTION
16+
#undef __CLC_NON_UNIFORM_FUNCTION
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#define __CLC_FUNCTION __spirv_GroupBitwiseAndKHR
10+
#define __CLC_NON_UNIFORM_FUNCTION __spirv_GroupNonUniformBitwiseAnd
11+
#define __CLC_BODY <libspirv/group/group_decl.inc>
12+
13+
#include <clc/integer/gentype.inc>
14+
15+
#undef __CLC_FUNCTION
16+
#undef __CLC_NON_UNIFORM_FUNCTION
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#define __CLC_FUNCTION __spirv_GroupBitwiseOrKHR
10+
#define __CLC_NON_UNIFORM_FUNCTION __spirv_GroupNonUniformBitwiseOr
11+
#define __CLC_BODY <libspirv/group/group_decl.inc>
12+
13+
#include <clc/integer/gentype.inc>
14+
15+
#undef __CLC_FUNCTION
16+
#undef __CLC_NON_UNIFORM_FUNCTION
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#define __CLC_FUNCTION __spirv_GroupBitwiseXorKHR
10+
#define __CLC_NON_UNIFORM_FUNCTION __spirv_GroupNonUniformBitwiseXor
11+
#define __CLC_BODY <libspirv/group/group_decl.inc>
12+
13+
#include <clc/integer/gentype.inc>
14+
15+
#undef __CLC_FUNCTION
16+
#undef __CLC_NON_UNIFORM_FUNCTION
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#define __CLC_BODY <libspirv/group/group_broadcast.inc>
10+
#include <clc/integer/gentype.inc>
11+
12+
#define __CLC_BODY <libspirv/group/group_broadcast.inc>
13+
#include <clc/math/gentype.inc>
14+
15+
#define __CLC_BODY <libspirv/group/group_non_uniform_broadcast.inc>
16+
#include <clc/integer/gentype.inc>
17+
18+
#define __CLC_BODY <libspirv/group/group_non_uniform_broadcast.inc>
19+
#include <clc/math/gentype.inc>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#define __GROUP_BROADCAST(LocalIdType) \
10+
_CLC_OVERLOAD _CLC_DEF _CLC_CONVERGENT __CLC_GENTYPE __spirv_GroupBroadcast( \
11+
int Execution, __CLC_GENTYPE Value, LocalIdType LocalId);
12+
13+
__GROUP_BROADCAST(ulong)
14+
__GROUP_BROADCAST(ulong2)
15+
__GROUP_BROADCAST(ulong3)
16+
__GROUP_BROADCAST(uint)
17+
__GROUP_BROADCAST(uint2)
18+
__GROUP_BROADCAST(uint3)
19+
#undef __GROUP_BROADCAST
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
_CLC_OVERLOAD _CLC_DEF _CLC_CONVERGENT __CLC_GENTYPE
10+
__CLC_FUNCTION(int Execution, int Operation, __CLC_GENTYPE X);
11+
12+
_CLC_OVERLOAD _CLC_DEF _CLC_CONVERGENT __CLC_GENTYPE __CLC_NON_UNIFORM_FUNCTION(
13+
int Execution, int Operation, __CLC_GENTYPE Value, uint ClusterSize);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#define __CLC_FUNCTION __spirv_GroupIMulKHR
10+
#define __CLC_NON_UNIFORM_FUNCTION __spirv_GroupNonUniformIMul
11+
#define __CLC_BODY <libspirv/group/group_decl.inc>
12+
13+
#include <clc/integer/gentype.inc>
14+
15+
#undef __CLC_FUNCTION
16+
#undef __CLC_NON_UNIFORM_FUNCTION
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#define __GROUP_NONUNIFORM_BROADCAST(IdType) \
10+
_CLC_OVERLOAD _CLC_DEF _CLC_CONVERGENT __CLC_GENTYPE \
11+
__spirv_GroupNonUniformBroadcast(int Execution, __CLC_GENTYPE Value, \
12+
IdType Id);
13+
14+
__GROUP_NONUNIFORM_BROADCAST(uint)
15+
__GROUP_NONUNIFORM_BROADCAST(ulong)
16+
#undef __GROUP_NONUNIFORM_BROADCAST
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#define __CLC_FUNCTION __spirv_GroupNonUniformShuffle
10+
11+
#define __CLC_BODY <libspirv/group/group_shuffle.inc>
12+
#include <clc/integer/gentype.inc>
13+
14+
#define __CLC_BODY <libspirv/group/group_shuffle.inc>
15+
#include <clc/math/gentype.inc>
16+
17+
#undef __CLC_FUNCTION
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
_CLC_OVERLOAD _CLC_DEF _CLC_CONVERGENT __CLC_GENTYPE
10+
__CLC_FUNCTION(int Execution, __CLC_GENTYPE Value, uint IdMaskDelta);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#define __CLC_FUNCTION __spirv_GroupNonUniformShuffleDown
10+
11+
#define __CLC_BODY <libspirv/group/group_shuffle.inc>
12+
#include <clc/integer/gentype.inc>
13+
14+
#define __CLC_BODY <libspirv/group/group_shuffle.inc>
15+
#include <clc/math/gentype.inc>
16+
17+
#undef __CLC_FUNCTION

0 commit comments

Comments
 (0)