Skip to content

[libclc] Move sign to the CLC builtins library #115699

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 1 commit into from
Feb 11, 2025

Conversation

frasercrmck
Copy link
Contributor

@frasercrmck frasercrmck commented Nov 11, 2024

This commit moves the sign builtin's implementation to the CLC library.
It simultaneously optimizes it (for vector types) by removing
control-flow from the implementation.

The __CLC_INTERNAL preprocessor definition has been repurposed (without
the leading underscores) to be passed when building the internal CLC
library. It was only used in one other place to guard an extra maths
preprocessor definition, which we can do unconditionally.

@frasercrmck frasercrmck added the libclc libclc OpenCL library label Nov 11, 2024
@frasercrmck frasercrmck requested a review from arsenm November 11, 2024 09:33
@frasercrmck
Copy link
Contributor Author

CC @tstellar @fooishbar who might be able to account for the Mesa/SPIR-V target?

Copy link
Collaborator

@tstellar tstellar left a comment

Choose a reason for hiding this comment

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

So is the sign function currently implemented in the OpenCL headers?

@frasercrmck
Copy link
Contributor Author

So is the sign function currently implemented in the OpenCL headers?

The sign function for SPIR-V/Mesa is currently implemented by libclc here. With this change, sign now calls __clc_sign which has the same implementation. We just need to do a bit of extra inlining of CLC functions into OpenCL functions to maintain more or less the same SPIR-V.

@frasercrmck

This comment was marked as outdated.

@fooishbar
Copy link
Contributor

cc @karolherbst @airlied who are better contacts for CL in Mesa these days

@frasercrmck
Copy link
Contributor Author

@arsenm I've just updated this PR. It still moves the sign implementation to the CLC library but now also optimizes it for vector types. There's no control flow nor scalarizing for vectors. I trust this will be a good enough default for the scalar form (on GPUs) though I suppose CPUs may prefer the old control flow form. I doubt any would prefer the old vector form, though.

alive2 seems to be happy with the transformation (for half2): https://alive2.llvm.org/ce/z/RZ8Dc4

Let me know what you think.

@frasercrmck
Copy link
Contributor Author

I'll look into undoing the CMake changes and building the dependent CLC functions for SPIR-V targets later on.

@frasercrmck
Copy link
Contributor Author

ping, thanks

This patch necessitates some changes to how CLSPV and SPIR-V targets are
built. This is the first patch in this series in which an OpenCL
function declaration has been called from the CLC library for these
targets. Since libclc's OpenCL headers aren't being included at this
stage, the OpenCL sign function isn't available. To fix this, these two
libclc targets now have clang declare OpenCL builtins when building the
internal CLC library.

The __CLC_INTERNAL preprocessor definition has been repurposed (without
the leading underscores) to be passed when building the internal CLC
library. It was only used in one other place to guard an extra maths
preprocessor definition, which we can do unconditionally.

There are no changes (with llvm-diff) to any libclc target other than
SPIR-V, which now has OpenCL sign call __clc_sign.
@frasercrmck frasercrmck merged commit 64735ad into llvm:main Feb 11, 2025
8 checks passed
@frasercrmck frasercrmck deleted the libclc-clc-sign branch February 11, 2025 11:14
Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
This commit moves the sign builtin's implementation to the CLC library.
It simultaneously optimizes it (for vector types) by removing
control-flow from the implementation.

The __CLC_INTERNAL preprocessor definition has been repurposed (without
the leading underscores) to be passed when building the internal CLC
library. It was only used in one other place to guard an extra maths
preprocessor definition, which we can do unconditionally.
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
This commit moves the sign builtin's implementation to the CLC library.
It simultaneously optimizes it (for vector types) by removing
control-flow from the implementation.

The __CLC_INTERNAL preprocessor definition has been repurposed (without
the leading underscores) to be passed when building the internal CLC
library. It was only used in one other place to guard an extra maths
preprocessor definition, which we can do unconditionally.
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
This commit moves the sign builtin's implementation to the CLC library.
It simultaneously optimizes it (for vector types) by removing
control-flow from the implementation.

The __CLC_INTERNAL preprocessor definition has been repurposed (without
the leading underscores) to be passed when building the internal CLC
library. It was only used in one other place to guard an extra maths
preprocessor definition, which we can do unconditionally.
qiaojbao pushed a commit to GPUOpen-Drivers/llvm-project that referenced this pull request Feb 28, 2025
Local branch amd-gfx 0ea0575 Manual merge main:2cd8207b26ea into amd-gfx:6f68ba52734c
Remote branch main 64735ad [libclc] Move sign to the CLC builtins library (llvm#115699)
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.

5 participants