Skip to content

[NVPTX][AMDGPU] Move annotation creation out of clang #14634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Aug 5, 2024

Conversation

frasercrmck
Copy link
Contributor

@frasercrmck frasercrmck commented Jul 18, 2024

This patch refactors the way we lower SYCL attributes and properties to NVVM annotations, through function attributes and metadata. It unifies the flow better with the SPIR-V paths at the same time.

Previously we had:

  1. Clang handling function attributes in two places:
    1. CodeGenFunction did generic lowering of attributes to function metadata
    2. NVPTXTargetCodeGenInfo did its own additional lowering of attributes to NVVM annotations
  2. Kernel properties being handled in clang. NVPTXTargetCodeGenInfo lowered kernel properties, which had already been converted to function attributes, to NVVM annotations.
  3. Kernel properties for HIP/CUDA not being turned into function metadata. Because function metadata is how the ComputeModuleRuntimeInfo library creates runtime info, this meant that target backends couldn't act on properties, as they were lost during lowering.

Fundamentally, clang is not the correct place for handling SYCL kernel properties as it unnecessarily touches the front-end for what is really library code.

With this patch, we now have:

  1. Clang handles function attributes in one place, lowering to function metadata
  2. SYCLLowerIR lowers kernel properties to the same function metadata: now working for HIP and CUDA kernels too. Because function metadata is consistently present for kernel properties, they behave as expected on HIP/CUDA targets now.
  3. A new pass converts function metadata to NVVM annotations, replacing the code we've taken out of clang.

This patch refactors the way we lower SYCL attributes and properties to
NVVM annotations, through function attributes and metadata. It unifies
the flow better with the SPIR-V paths at the same time.

Previously we had:

1. Clang handling function attributes in two places:
  a. CodeGenFunction did generic lowering of attributes to function metadata
  b. NVPTXTargetCodeGenInfo did its own additional lowering of
     attributes to NVVM annotations
2. Kernel properties being handled in clang. NVPTXTargetCodeGenInfo
   lowered kernel properties, which had already been converted to
   function attributes, to NVVM annotations.
3. Kernel properties for HIP/CUDA *not* being turned into function
   metadata. Because function metadata is how the
   ComputeModuleRuntimeInfo library creates runtime info, this meant
   that target backends couldn't act on properties, as they were lost
   during lowering.

Fundamentally, clang is not the correct place for handling SYCL kernel
properties as it unnecessarily touches the front-end for what is really
library code.

With this patch, we now have:

1. Clang handles function attributes in one place, lowering to function
   metadata
2. SYCLLowerIR lowers kernel properties to the same function metadata:
   now working for HIP and CUDA kernels too. Because function metadata
   is consistently present for kernel properties, they behave as
   expected on HIP/CUDA targets now.
3. A new pass converts function metadata to NVVM annotations, replacing
   the code we've taken out of clang.
Copy link
Contributor

@EwanC EwanC left a comment

Choose a reason for hiding this comment

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

Graph test changes LGTM

Copy link
Contributor

@dm-vodopyanov dm-vodopyanov left a comment

Choose a reason for hiding this comment

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

sycl/test-e2e/* LGTM

Copy link
Contributor

@sarnex sarnex left a comment

Choose a reason for hiding this comment

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

llvm/lib/SYCLLowerIR/CMakeLists.txt lgtm

@sarnex sarnex requested a review from a team July 22, 2024 15:13
@bader
Copy link
Contributor

bader commented Jul 22, 2024

@intel/dpcpp-cfe-reviewers, ping.

@bader
Copy link
Contributor

bader commented Jul 29, 2024

@frasercrmck, please, resolve merge conflicts.

@frasercrmck
Copy link
Contributor Author

@frasercrmck, please, resolve merge conflicts.

Done, thanks. I haven't waited for all CI but Linux looks happy at least.

@frasercrmck
Copy link
Contributor Author

@intel/llvm-gatekeepers this looks ready to merge, thank you.

@bader bader merged commit 3d73d9b into intel:sycl Aug 5, 2024
14 checks passed
@frasercrmck frasercrmck deleted the sycl-nvptx-hip-annotations-pass branch August 5, 2024 17:04
@sarnex
Copy link
Contributor

sarnex commented Aug 5, 2024

@frasercrmck We are seeing macos post commit failures, can you please take a look?

https://github.com/intel/llvm/actions/runs/10253109905/job/28365021433

FAILED: lib/SYCLLowerIR/CMakeFiles/LLVMSYCLLowerIR.dir/SYCLCreateNVVMAnnotations.cpp.o 
ccache /Applications/Xcode_14.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/Users/runner/work/llvm/llvm/build/lib/SYCLLowerIR -I/Users/runner/work/llvm/llvm/src/llvm/lib/SYCLLowerIR -I/Users/runner/work/llvm/llvm/build/include -I/Users/runner/work/llvm/llvm/src/llvm/include -I/Users/runner/work/llvm/llvm/src/llvm/projects/vc-intrinsics/GenXIntrinsics/include -I/Users/runner/work/llvm/llvm/build/projects/vc-intrinsics/GenXIntrinsics/include -I/Users/runner/work/llvm/llvm/build/_deps/vc-intrinsics-src/GenXIntrinsics/include -I/Users/runner/work/llvm/llvm/build/_deps/vc-intrinsics-build/GenXIntrinsics/lib/GenXIntrinsics/../../include -I/Users/runner/work/llvm/llvm/build/_deps/vc-intrinsics-build/GenXIntrinsics/include -isystem /usr/local/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -O3 -DNDEBUG -std=c++17 -isysroot /Applications/Xcode_14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -mmacosx-version-min=12.7  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT lib/SYCLLowerIR/CMakeFiles/LLVMSYCLLowerIR.dir/SYCLCreateNVVMAnnotations.cpp.o -MF lib/SYCLLowerIR/CMakeFiles/LLVMSYCLLowerIR.dir/SYCLCreateNVVMAnnotations.cpp.o.d -o lib/SYCLLowerIR/CMakeFiles/LLVMSYCLLowerIR.dir/SYCLCreateNVVMAnnotations.cpp.o -c /Users/runner/work/llvm/llvm/src/llvm/lib/SYCLLowerIR/SYCLCreateNVVMAnnotations.cpp
/Users/runner/work/llvm/llvm/src/llvm/lib/SYCLLowerIR/SYCLCreateNVVMAnnotations.cpp:62:10: error: no viable conversion from returned value of type 'array<optional<size_t>, [...]>' to function return type 'array<optional<uint64_t>, [...]>'
  return Ops;
         ^~~
/Applications/Xcode_14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/include/c++/v1/array:129:29: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'std::array<std::optional<size_t>, 3>' (aka 'array<optional<unsigned long>, 3>') to 'const std::array<std::optional<unsigned long long>, 3> &' for 1st argument
struct _LIBCPP_TEMPLATE_VIS array
                            ^
/Applications/Xcode_14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/include/c++/v1/array:129:29: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'std::array<std::optional<size_t>, 3>' (aka 'array<optional<unsigned long>, 3>') to 'std::array<std::optional<unsigned long long>, 3> &&' for 1st argument
1 error generated.

@frasercrmck
Copy link
Contributor Author

@frasercrmck We are seeing macos post commit failures, can you please take a look?

https://github.com/intel/llvm/actions/runs/10253109905/job/28365021433

FAILED: lib/SYCLLowerIR/CMakeFiles/LLVMSYCLLowerIR.dir/SYCLCreateNVVMAnnotations.cpp.o 
ccache /Applications/Xcode_14.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/Users/runner/work/llvm/llvm/build/lib/SYCLLowerIR -I/Users/runner/work/llvm/llvm/src/llvm/lib/SYCLLowerIR -I/Users/runner/work/llvm/llvm/build/include -I/Users/runner/work/llvm/llvm/src/llvm/include -I/Users/runner/work/llvm/llvm/src/llvm/projects/vc-intrinsics/GenXIntrinsics/include -I/Users/runner/work/llvm/llvm/build/projects/vc-intrinsics/GenXIntrinsics/include -I/Users/runner/work/llvm/llvm/build/_deps/vc-intrinsics-src/GenXIntrinsics/include -I/Users/runner/work/llvm/llvm/build/_deps/vc-intrinsics-build/GenXIntrinsics/lib/GenXIntrinsics/../../include -I/Users/runner/work/llvm/llvm/build/_deps/vc-intrinsics-build/GenXIntrinsics/include -isystem /usr/local/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -O3 -DNDEBUG -std=c++17 -isysroot /Applications/Xcode_14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -mmacosx-version-min=12.7  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT lib/SYCLLowerIR/CMakeFiles/LLVMSYCLLowerIR.dir/SYCLCreateNVVMAnnotations.cpp.o -MF lib/SYCLLowerIR/CMakeFiles/LLVMSYCLLowerIR.dir/SYCLCreateNVVMAnnotations.cpp.o.d -o lib/SYCLLowerIR/CMakeFiles/LLVMSYCLLowerIR.dir/SYCLCreateNVVMAnnotations.cpp.o -c /Users/runner/work/llvm/llvm/src/llvm/lib/SYCLLowerIR/SYCLCreateNVVMAnnotations.cpp
/Users/runner/work/llvm/llvm/src/llvm/lib/SYCLLowerIR/SYCLCreateNVVMAnnotations.cpp:62:10: error: no viable conversion from returned value of type 'array<optional<size_t>, [...]>' to function return type 'array<optional<uint64_t>, [...]>'
  return Ops;
         ^~~
/Applications/Xcode_14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/include/c++/v1/array:129:29: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'std::array<std::optional<size_t>, 3>' (aka 'array<optional<unsigned long>, 3>') to 'const std::array<std::optional<unsigned long long>, 3> &' for 1st argument
struct _LIBCPP_TEMPLATE_VIS array
                            ^
/Applications/Xcode_14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/include/c++/v1/array:129:29: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'std::array<std::optional<size_t>, 3>' (aka 'array<optional<unsigned long>, 3>') to 'std::array<std::optional<unsigned long long>, 3> &&' for 1st argument
1 error generated.

Whoops, sorry. See #14964

@sarnex
Copy link
Contributor

sarnex commented Aug 6, 2024

Thanks!

AlexeySachkov pushed a commit to AlexeySachkov/llvm that referenced this pull request Nov 26, 2024
This patch refactors the way we lower SYCL attributes and properties to
NVVM annotations, through function attributes and metadata. It unifies
the flow better with the SPIR-V paths at the same time.

Previously we had:

1. Clang handling function attributes in two places:
1. CodeGenFunction did generic lowering of attributes to function
metadata
2. NVPTXTargetCodeGenInfo did its own additional lowering of attributes
to NVVM annotations
2. Kernel properties being handled in clang. NVPTXTargetCodeGenInfo
lowered kernel properties, which had already been converted to function
attributes, to NVVM annotations.
3. Kernel properties for HIP/CUDA *not* being turned into function
metadata. Because function metadata is how the ComputeModuleRuntimeInfo
library creates runtime info, this meant that target backends couldn't
act on properties, as they were lost during lowering.

Fundamentally, clang is not the correct place for handling SYCL kernel
properties as it unnecessarily touches the front-end for what is really
library code.

With this patch, we now have:

1. Clang handles function attributes in one place, lowering to function
metadata
2. SYCLLowerIR lowers kernel properties to the same function metadata:
now working for HIP and CUDA kernels too. Because function metadata is
consistently present for kernel properties, they behave as expected on
HIP/CUDA targets now.
3. A new pass converts function metadata to NVVM annotations, replacing
the code we've taken out of clang.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants