Skip to content

Conversation

wenju-he
Copy link
Contributor

@wenju-he wenju-he commented Aug 6, 2025

It is necessary to add MemorySemantic argument for AMDGPU which means the memory or address space to which the memory ordering is applied.

The MemorySemantic is also necessary for implementing the SPIR-V MemoryBarrier instruction. Additionally, the implementation of __clc_mem_fence on Intel GPUs requires the MemorySemantic argument.

Using __builtin_amdgcn_fence for AMDGPU is follow-up of #151446 (comment)

llvm-diff shows no change to nvptx64--nvidiacl.bc.

…ltin_amdgcn_fence for AMDGPU

It is necessary to add MemorySemantic argument which means the memory or
address space to which the memory ordering is applied.

The MemorySemantic is also necessary for implementing the SPIR-V
MemoryBarrier instruction. Additionally, the implementation of
__clc_mem_fence on Intel GPUs requires the MemorySemantic argument.

Using __builtin_amdgcn_fence for AMDGPU is follow-up of
llvm#151446 (comment)

llvm-diff shows no change to nvptx64--nvidiacl.bc.
@llvmbot llvmbot added the libclc libclc OpenCL library label Aug 6, 2025
@wenju-he wenju-he requested a review from arsenm August 6, 2025 09:08
@wenju-he wenju-he requested a review from frasercrmck August 6, 2025 09:09
Comment on lines 14 to 18
MEMORY_PRIVATE = 0x1,
MEMORY_LOCAL = 0x2,
MEMORY_GLOBAL = 0x4,
MEMORY_CONSTANT = 0x8,
MEMORY_GENERIC = 0x10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit mask, so write out as 1 << N for the values?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit mask, so write out as 1 << N for the values?

done in f25de34

@wenju-he wenju-he requested a review from arsenm August 7, 2025 01:31
MEMORY_CONSTANT = 1 << 2,
MEMORY_LOCAL = 1 << 3,
MEMORY_GENERIC = 1 << 4,
} MemorySemantic;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this MemorySemantic name copied from somewhere else? I don't think the name is quite right. It's a mask of fenced address spaces?

Copy link
Contributor Author

@wenju-he wenju-he Aug 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this MemorySemantic name copied from somewhere else? I don't think the name is quite right.

Yes, it is copied from our closed source code where the enum macros are defined as memory semantic.

It is also copied from https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Memory_Semantics_-id-
But the enum values here only models SubgroupMemory, WorkgroupMemory and CrossWorkgroupMemory part of SPIR-V Memory_Semantics. So the name is likely not quite right.

It's a mask of fenced address spaces?

Yes, IIUC it should be a mask of fenced address space for AMDGPU.

In term of the usage in Intel GPU and modeling of SPIR-V spec, it is the memory that the fence operation affects and the memory ordering applies.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer MemorySemantics - plural - as you can combine multiple in the same operation. This is also what the SPIR-V spec calls them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer MemorySemantics - plural - as you can combine multiple in the same operation. This is also what the SPIR-V spec calls them.

done in 001cec4

@wenju-he wenju-he requested a review from arsenm August 11, 2025 00:54
@@ -21,4 +22,14 @@ _CLC_INLINE int getCLCMemoryScope(cl_mem_fence_flags flag) {
return memory_scope;
}

_CLC_INLINE MemorySemantics getCLCMemorySemantics(cl_mem_fence_flags flag) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't follow clc naming conventions (enum name too), but that already appears to be an issue in this file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't follow clc naming conventions (enum name too), but that already appears to be an issue in this file

Done in 02e3047

  • Added __CLC_ prefix to MemorySemantics and its enum values
  • Added __opencl_ prefix to functions in libclc/opencl/include/clc/opencl/synchronization/utils.h

…l_ prefix to functions in opencl/synchronization/utils.h
@wenju-he wenju-he requested a review from arsenm August 12, 2025 02:25
@wenju-he
Copy link
Contributor Author

wenju-he commented Sep 1, 2025

kindly ping @arsenm @frasercrmck to review the last commit. It is a renaming commit.

@wenju-he wenju-he merged commit a247da4 into llvm:main Sep 1, 2025
9 checks passed
@wenju-he wenju-he deleted the libclc-__builtin_amdgcn_fence branch September 1, 2025 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libclc libclc OpenCL library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants