[all-commits] [llvm/llvm-project] 4e80bc: [Clang] Introduce scoped variants of GNU atomic fu...

Joseph Huber via All-commits all-commits at lists.llvm.org
Thu Dec 7 11:40:39 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 4e80bc7d716b1f2344ffd7ad109413bfe5390879
      https://github.com/llvm/llvm-project/commit/4e80bc7d716b1f2344ffd7ad109413bfe5390879
  Author: Joseph Huber <huberjn at outlook.com>
  Date:   2023-12-07 (Thu, 07 Dec 2023)

  Changed paths:
    M clang/docs/LanguageExtensions.rst
    M clang/include/clang/AST/Expr.h
    M clang/include/clang/Basic/Builtins.def
    M clang/include/clang/Basic/SyncScope.h
    M clang/lib/AST/Expr.cpp
    M clang/lib/AST/StmtPrinter.cpp
    M clang/lib/CodeGen/CGAtomic.cpp
    M clang/lib/CodeGen/Targets/AMDGPU.cpp
    M clang/lib/Frontend/InitPreprocessor.cpp
    M clang/lib/Sema/SemaChecking.cpp
    A clang/test/CodeGen/scoped-atomic-ops.c
    M clang/test/Preprocessor/init-aarch64.c
    M clang/test/Preprocessor/init-loongarch.c
    M clang/test/Preprocessor/init.c
    A clang/test/Sema/scoped-atomic-ops.c

  Log Message:
  -----------
  [Clang] Introduce scoped variants of GNU atomic functions (#72280)

Summary:
The standard GNU atomic operations are a very common way to target
hardware atomics on the device. With more heterogenous devices being
introduced, the concept of memory scopes has been in the LLVM language
for awhile via the `syncscope` modifier. For targets, such as the GPU,
this can change code generation depending on whether or not we only need
to be consistent with the memory ordering with the entire system, the
single GPU device, or lower.

Previously these scopes were only exported via the `opencl` and `hip`
variants of these functions. However, this made it difficult to use
outside of those languages and the semantics were different from the
standard GNU versions. This patch introduces a `__scoped_atomic` variant
for the common functions. There was some discussion over whether or not
these should be overloads of the existing ones, or simply new variants.
I leant towards new variants to be less disruptive.

The scope here can be one of the following

```
__MEMORY_SCOPE_SYSTEM // All devices and systems
__MEMORY_SCOPE_DEVICE // Just this device
__MEMORY_SCOPE_WRKGRP // A 'work-group' AKA CUDA block
__MEMORY_SCOPE_WVFRNT // A 'wavefront' AKA CUDA warp
__MEMORY_SCOPE_SINGLE // A single thread.
```
Naming consistency was attempted, but it is difficult to capture to full
spectrum with no many names. Suggestions appreciated.




More information about the All-commits mailing list