Skip to content

Commit

Permalink
[SYCL][CUDA][libclc] Added atomics with scopes and memory orders (#4820)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
t4c1 authored Nov 18, 2021
1 parent 53c3268 commit 2ebde5f
Show file tree
Hide file tree
Showing 23 changed files with 9,278 additions and 334 deletions.
1,385 changes: 1,385 additions & 0 deletions clang/include/clang/Basic/BuiltinsNVPTX.def

Large diffs are not rendered by default.

1,747 changes: 1,719 additions & 28 deletions clang/lib/CodeGen/CGBuiltin.cpp

Large diffs are not rendered by default.

2,849 changes: 2,832 additions & 17 deletions clang/test/CodeGen/builtins-nvptx.c

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions libclc/ptx-nvidiacl/libspirv/SOURCES
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,13 @@ images/image_helpers.ll
images/image.cl
group/collectives_helpers.ll
group/collectives.cl
SPV_EXT_shader_atomic_float_add/atomicfaddext.cl
SPV_EXT_shader_atomic_float_add/faddext_helpers.ll
atomic/atomic_add.cl
atomic/atomic_and.cl
atomic/atomic_cmpxchg.cl
atomic/atomic_dec.cl
atomic/atomic_inc.cl
atomic/atomic_max.cl
atomic/atomic_min.cl
atomic/atomic_xchg.cl
atomic/atomic_or.cl
atomic/atomic_xor.cl

This file was deleted.

This file was deleted.

25 changes: 25 additions & 0 deletions libclc/ptx-nvidiacl/libspirv/atomic/atomic_add.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

#include <atomic_helpers.h>
#include <spirv/spirv.h>
#include <spirv/spirv_types.h>

__CLC_NVVM_ATOMIC(int, i, int, i, add, _Z18__spirv_AtomicIAdd)
__CLC_NVVM_ATOMIC(uint, j, int, i, add, _Z18__spirv_AtomicIAdd)
__CLC_NVVM_ATOMIC(long, l, long, l, add, _Z18__spirv_AtomicIAdd)
__CLC_NVVM_ATOMIC(ulong, m, long, l, add, _Z18__spirv_AtomicIAdd)

__CLC_NVVM_ATOMIC(float, f, float, f, add, _Z21__spirv_AtomicFAddEXT)
#ifdef cl_khr_int64_base_atomics
__CLC_NVVM_ATOMIC(double, d, double, d, add, _Z21__spirv_AtomicFAddEXT)
#endif

#undef __CLC_NVVM_ATOMIC_TYPES
#undef __CLC_NVVM_ATOMIC
#undef __CLC_NVVM_ATOMIC_IMPL
20 changes: 20 additions & 0 deletions libclc/ptx-nvidiacl/libspirv/atomic/atomic_and.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

#include <atomic_helpers.h>
#include <spirv/spirv.h>
#include <spirv/spirv_types.h>

__CLC_NVVM_ATOMIC(int, i, int, i, and, _Z17__spirv_AtomicAnd)
__CLC_NVVM_ATOMIC(long, l, long, l, and, _Z17__spirv_AtomicAnd)
__CLC_NVVM_ATOMIC(unsigned int, j, int, i, and, _Z17__spirv_AtomicAnd)
__CLC_NVVM_ATOMIC(unsigned long, m, long, l, and, _Z17__spirv_AtomicAnd)

#undef __CLC_NVVM_ATOMIC_TYPES
#undef __CLC_NVVM_ATOMIC
#undef __CLC_NVVM_ATOMIC_IMPL
Loading

0 comments on commit 2ebde5f

Please sign in to comment.