Skip to content

Commit 2ebde5f

Browse files
authored
[SYCL][CUDA][libclc] Added atomics with scopes and memory orders (#4820)
Added libclc implementations for CUDA atomics, including for various scopes and memory orders. They are implemented using LLVM intrinsics and exposed as clang builtins, which are than used to implement functions in libclc.
1 parent 53c3268 commit 2ebde5f

File tree

23 files changed

+9278
-334
lines changed

23 files changed

+9278
-334
lines changed

clang/include/clang/Basic/BuiltinsNVPTX.def

Lines changed: 1385 additions & 0 deletions
Large diffs are not rendered by default.

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 1719 additions & 28 deletions
Large diffs are not rendered by default.

clang/test/CodeGen/builtins-nvptx.c

Lines changed: 2832 additions & 17 deletions
Large diffs are not rendered by default.

libclc/ptx-nvidiacl/libspirv/SOURCES

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,13 @@ images/image_helpers.ll
8585
images/image.cl
8686
group/collectives_helpers.ll
8787
group/collectives.cl
88-
SPV_EXT_shader_atomic_float_add/atomicfaddext.cl
89-
SPV_EXT_shader_atomic_float_add/faddext_helpers.ll
88+
atomic/atomic_add.cl
89+
atomic/atomic_and.cl
90+
atomic/atomic_cmpxchg.cl
91+
atomic/atomic_dec.cl
92+
atomic/atomic_inc.cl
93+
atomic/atomic_max.cl
94+
atomic/atomic_min.cl
95+
atomic/atomic_xchg.cl
96+
atomic/atomic_or.cl
97+
atomic/atomic_xor.cl

libclc/ptx-nvidiacl/libspirv/SPV_EXT_shader_atomic_float_add/atomicfaddext.cl

Lines changed: 0 additions & 136 deletions
This file was deleted.

libclc/ptx-nvidiacl/libspirv/SPV_EXT_shader_atomic_float_add/faddext_helpers.ll

Lines changed: 0 additions & 125 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
#include <atomic_helpers.h>
10+
#include <spirv/spirv.h>
11+
#include <spirv/spirv_types.h>
12+
13+
__CLC_NVVM_ATOMIC(int, i, int, i, add, _Z18__spirv_AtomicIAdd)
14+
__CLC_NVVM_ATOMIC(uint, j, int, i, add, _Z18__spirv_AtomicIAdd)
15+
__CLC_NVVM_ATOMIC(long, l, long, l, add, _Z18__spirv_AtomicIAdd)
16+
__CLC_NVVM_ATOMIC(ulong, m, long, l, add, _Z18__spirv_AtomicIAdd)
17+
18+
__CLC_NVVM_ATOMIC(float, f, float, f, add, _Z21__spirv_AtomicFAddEXT)
19+
#ifdef cl_khr_int64_base_atomics
20+
__CLC_NVVM_ATOMIC(double, d, double, d, add, _Z21__spirv_AtomicFAddEXT)
21+
#endif
22+
23+
#undef __CLC_NVVM_ATOMIC_TYPES
24+
#undef __CLC_NVVM_ATOMIC
25+
#undef __CLC_NVVM_ATOMIC_IMPL
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
#include <atomic_helpers.h>
10+
#include <spirv/spirv.h>
11+
#include <spirv/spirv_types.h>
12+
13+
__CLC_NVVM_ATOMIC(int, i, int, i, and, _Z17__spirv_AtomicAnd)
14+
__CLC_NVVM_ATOMIC(long, l, long, l, and, _Z17__spirv_AtomicAnd)
15+
__CLC_NVVM_ATOMIC(unsigned int, j, int, i, and, _Z17__spirv_AtomicAnd)
16+
__CLC_NVVM_ATOMIC(unsigned long, m, long, l, and, _Z17__spirv_AtomicAnd)
17+
18+
#undef __CLC_NVVM_ATOMIC_TYPES
19+
#undef __CLC_NVVM_ATOMIC
20+
#undef __CLC_NVVM_ATOMIC_IMPL

0 commit comments

Comments
 (0)