llvm-project
43 строки · 2.4 Кб
1// RUN: %clang_cc1 %s -cl-std=CL2.0 -O0 -triple=amdgcn-amd-amdhsa -target-cpu gfx90a \
2// RUN: -Rpass=atomic-expand -S -o - 2>&1 | \
3// RUN: FileCheck %s --check-prefix=REMARK
4
5// RUN: %clang_cc1 %s -cl-std=CL2.0 -O0 -triple=amdgcn-amd-amdhsa -target-cpu gfx90a \
6// RUN: -Rpass=atomic-expand -emit-llvm -o - 2>&1 | \
7// RUN: FileCheck %s --check-prefix=GFX90A-CAS
8
9// REQUIRES: amdgpu-registered-target
10
11typedef enum memory_order {
12memory_order_relaxed = __ATOMIC_RELAXED,
13memory_order_acquire = __ATOMIC_ACQUIRE,
14memory_order_release = __ATOMIC_RELEASE,
15memory_order_acq_rel = __ATOMIC_ACQ_REL,
16memory_order_seq_cst = __ATOMIC_SEQ_CST
17} memory_order;
18
19typedef enum memory_scope {
20memory_scope_work_item = __OPENCL_MEMORY_SCOPE_WORK_ITEM,
21memory_scope_work_group = __OPENCL_MEMORY_SCOPE_WORK_GROUP,
22memory_scope_device = __OPENCL_MEMORY_SCOPE_DEVICE,
23memory_scope_all_svm_devices = __OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES,
24#if defined(cl_intel_subgroups) || defined(cl_khr_subgroups)
25memory_scope_sub_group = __OPENCL_MEMORY_SCOPE_SUB_GROUP
26#endif
27} memory_scope;
28
29// REMARK: remark: A compare and swap loop was generated for an atomic fadd operation at workgroup-one-as memory scope [-Rpass=atomic-expand]
30// REMARK: remark: A compare and swap loop was generated for an atomic fadd operation at agent-one-as memory scope [-Rpass=atomic-expand]
31// REMARK: remark: A compare and swap loop was generated for an atomic fadd operation at one-as memory scope [-Rpass=atomic-expand]
32// REMARK: remark: A compare and swap loop was generated for an atomic fadd operation at wavefront-one-as memory scope [-Rpass=atomic-expand]
33// GFX90A-CAS-LABEL: @atomic_cas
34// GFX90A-CAS: atomicrmw fadd ptr addrspace(1) {{.*}} syncscope("workgroup-one-as") monotonic
35// GFX90A-CAS: atomicrmw fadd ptr addrspace(1) {{.*}} syncscope("agent-one-as") monotonic
36// GFX90A-CAS: atomicrmw fadd ptr addrspace(1) {{.*}} syncscope("one-as") monotonic
37// GFX90A-CAS: atomicrmw fadd ptr addrspace(1) {{.*}} syncscope("wavefront-one-as") monotonic
38float atomic_cas(__global atomic_float *d, float a) {
39float ret1 = __opencl_atomic_fetch_add(d, a, memory_order_relaxed, memory_scope_work_group);
40float ret2 = __opencl_atomic_fetch_add(d, a, memory_order_relaxed, memory_scope_device);
41float ret3 = __opencl_atomic_fetch_add(d, a, memory_order_relaxed, memory_scope_all_svm_devices);
42float ret4 = __opencl_atomic_fetch_add(d, a, memory_order_relaxed, memory_scope_sub_group);
43}
44