Skip to content

Commit e739786

Browse files
committed
[libclc] Fix memory fence scope mapping for OpenCL
The function `__opencl_get_memory_scope` incorrectly assumed that the Clang built-in `__MEMORY_SCOPE_*` macros defined as bitmasks, while they are actually defined as distinct integer values. This led to incorrect mapping of OpenCL memory fence flags to LLVM memory scopes, causing issues in generated code. The fix involves updating the `__opencl_get_memory_scope` function to return the correct `__MEMORY_SCOPE_*` values based on the provided `cl_mem_fence_flags`. Additionally, the `__opencl_get_memory_semantics` and the `__opencl_get_memory_scope` functions are marked as `static` to avoid potential multiple definition issues during linking.
1 parent c5fa1f8 commit e739786

File tree

1 file changed

+5
-6
lines changed
  • libclc/opencl/include/clc/opencl/synchronization

1 file changed

+5
-6
lines changed

libclc/opencl/include/clc/opencl/synchronization/utils.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@
1313
#include <clc/mem_fence/clc_mem_semantic.h>
1414
#include <clc/opencl/synchronization/cl_mem_fence_flags.h>
1515

16-
_CLC_INLINE int __opencl_get_memory_scope(cl_mem_fence_flags flag) {
17-
int memory_scope = 0;
16+
static _CLC_INLINE int __opencl_get_memory_scope(cl_mem_fence_flags flag) {
1817
if (flag & CLK_GLOBAL_MEM_FENCE)
19-
memory_scope |= __MEMORY_SCOPE_DEVICE;
18+
return __MEMORY_SCOPE_DEVICE;
2019
if (flag & CLK_LOCAL_MEM_FENCE)
21-
memory_scope |= __MEMORY_SCOPE_WRKGRP;
22-
return memory_scope;
20+
return __MEMORY_SCOPE_WRKGRP;
21+
return __MEMORY_SCOPE_SINGLE;
2322
}
2423

25-
_CLC_INLINE __CLC_MemorySemantics
24+
static _CLC_INLINE __CLC_MemorySemantics
2625
__opencl_get_memory_semantics(cl_mem_fence_flags flag) {
2726
if ((flag & CLK_LOCAL_MEM_FENCE) && (flag & CLK_GLOBAL_MEM_FENCE))
2827
return __CLC_MEMORY_LOCAL | __CLC_MEMORY_GLOBAL;

0 commit comments

Comments
 (0)