Debian Codegraph @

libclc/opencl/lib/amdgcn/mem_fence/fence.cl

raw
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 <clc/opencl/explicit_fence/explicit_memory_fence.h>
10
11 void __clc_amdgcn_s_waitcnt(unsigned flags);
12
13 // s_waitcnt takes 16bit argument with a combined number of maximum allowed
14 // pending operations:
15 // [12:8] LGKM -- LDS, GDS, Konstant (SMRD), Messages
16 // [7] -- undefined
17 // [6:4] -- exports, GDS, and mem write
18 // [3:0] -- vector memory operations
19
20 // Newer clang supports __builtin_amdgcn_s_waitcnt
21 #if __clang_major__ >= 5
22 #define __waitcnt(x) __builtin_amdgcn_s_waitcnt(x)
23 #else
24 #define __waitcnt(x) __clc_amdgcn_s_waitcnt(x)
25 _CLC_DEF void __clc_amdgcn_s_waitcnt(unsigned) __asm("llvm.amdgcn.s.waitcnt");
26 #endif
27
28 _CLC_DEF _CLC_OVERLOAD void mem_fence(cl_mem_fence_flags flags) {
29 if (flags & CLK_GLOBAL_MEM_FENCE) {
30 // scalar loads are counted with LGKM but we don't know whether
31 // the compiler turned any loads to scalar
32 __waitcnt(0);
33 } else if (flags & CLK_LOCAL_MEM_FENCE)
34 __waitcnt(0xff); // LGKM is [12:8]
35 }
36 #undef __waitcnt
37
38 // We don't have separate mechanism for read and write fences
39 _CLC_DEF _CLC_OVERLOAD void read_mem_fence(cl_mem_fence_flags flags) {
40 mem_fence(flags);
41 }
42
43 _CLC_DEF _CLC_OVERLOAD void write_mem_fence(cl_mem_fence_flags flags) {
44 mem_fence(flags);
45 }