Skip to content

[libclc] only check filename part of the source for avoiding duplication #135710

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

Conversation

wenju-he
Copy link
Contributor

llvm-diff shows this PR has no changes to amdgcn--amdhsa.bc.

Motivation is that in our downstream the same category of target built-ins, e.g. math, are organized in several different folders. For example, in target SOURCES we have math-common/cos.cl, while in generic SOURCES it is math/cos.cl. Based on current check rule that compares both folder name and base filename, target math-common/cos.cl won't override math/cos.cl when collecting source files from SOURCES files in cmake function libclc_configure_lib_source.

With this PR, we allow folder name to be different in the process.

A notable change of this PR is that two entries in SOURCES with the same base filename must not implements the same built-in.

llvm-diff shows this PR has no changes to amdgcn--amdhsa.bc.

Motivation is that in our downstream the same category of target
built-ins, e.g. math, are organized in several different folders.
For example, in target SOURCES we have math-common/cos.cl, while in
generic SOURCES it is math/cos.cl. Based on current check rule that
compares both folder name and base filename, target math-common/cos.cl
won't override math/cos.cl when collecting source files from SOURCES
files in cmake function libclc_configure_lib_source.

With this PR, we allow folder name to be different in the process.

A notable change of this PR is that two entries in SOURCES with the same
base filename must not implements the same built-in.
@wenju-he
Copy link
Contributor Author

@frasercrmck please help to review? thanks.

@frasercrmck frasercrmck added the libclc libclc OpenCL library label Apr 16, 2025
@frasercrmck frasercrmck changed the title [liblc] only check filename part of the source for avoiding duplication [libclc] only check filename part of the source for avoiding duplication Apr 16, 2025
@frasercrmck
Copy link
Contributor

I don't mind this.

Given the current naming scheme, files are named after specific builtins so you're unlikely to want to include two cos.cl, for instance. I don't think the directory name is or should be significant in deciding what to override. I suppose you could currently have fp32/cos.cl and fp16/cos.cl whereas this change would prevent that. You could just have cos_fp32.cl and cos_fp16.cl, of course.

I would like to further investigate weak linkage as another means of overriding specific builtins down to a finer granularity. That approach might warrant another method of file discovery.

@wenju-he
Copy link
Contributor Author

You could just have cos_fp32.cl and cos_fp16.cl, of course.

Yes. To enable overriding generic implementation of cos.cl, the names in target folder could be cos.cl and cos_fp16.cl

I would like to further investigate weak linkage as another means of overriding specific builtins down to a finer granularity. That approach might warrant another method of file discovery.

It would bring unnecessary builds and may increase build time. Filename overriding should be better.

@frasercrmck
Copy link
Contributor

I would like to further investigate weak linkage as another means of overriding specific builtins down to a finer granularity. That approach might warrant another method of file discovery.

It would bring unnecessary builds and may increase build time. Filename overriding should be better.

Yes, however when a target only wants to override one type such as fp16, with the current approach the target has to override the whole of cos.cl and re-implement fp32 and fp64, for example. This isn't terrible for OpenCL where you can simply repeat the wrappers to the CLC functions, but when wanting to override the CLC functions for specific types it's awkward and can result in a lot of duplicated code.

The idea using weak linkage wouldn't remove file overriding (as you say, it's a good approach for coarse-grained overriding), but would have to compliment it. We actually do it already for a couple of builtins (such as ldexp), but it's a bit hacky.

@frasercrmck frasercrmck merged commit 77fe6aa into llvm:main Apr 24, 2025
11 checks passed
@wenju-he wenju-he deleted the libclc-libclc_configure_lib_source-name branch April 24, 2025 04:55
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…ion (llvm#135710)

llvm-diff shows this PR has no changes to amdgcn--amdhsa.bc.

Motivation is that in our downstream the same category of target
built-ins, e.g. math, are organized in several different folders. For
example, in target SOURCES we have math-common/cos.cl, while in generic
SOURCES it is math/cos.cl. Based on current check rule that compares
both folder name and base filename, target math-common/cos.cl won't
override math/cos.cl when collecting source files from SOURCES files in
cmake function libclc_configure_lib_source.

With this PR, we allow folder name to be different in the process.

A notable change of this PR is that two entries in SOURCES with the same
base filename must not implements the same built-in.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…ion (llvm#135710)

llvm-diff shows this PR has no changes to amdgcn--amdhsa.bc.

Motivation is that in our downstream the same category of target
built-ins, e.g. math, are organized in several different folders. For
example, in target SOURCES we have math-common/cos.cl, while in generic
SOURCES it is math/cos.cl. Based on current check rule that compares
both folder name and base filename, target math-common/cos.cl won't
override math/cos.cl when collecting source files from SOURCES files in
cmake function libclc_configure_lib_source.

With this PR, we allow folder name to be different in the process.

A notable change of this PR is that two entries in SOURCES with the same
base filename must not implements the same built-in.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…ion (llvm#135710)

llvm-diff shows this PR has no changes to amdgcn--amdhsa.bc.

Motivation is that in our downstream the same category of target
built-ins, e.g. math, are organized in several different folders. For
example, in target SOURCES we have math-common/cos.cl, while in generic
SOURCES it is math/cos.cl. Based on current check rule that compares
both folder name and base filename, target math-common/cos.cl won't
override math/cos.cl when collecting source files from SOURCES files in
cmake function libclc_configure_lib_source.

With this PR, we allow folder name to be different in the process.

A notable change of this PR is that two entries in SOURCES with the same
base filename must not implements the same built-in.
Ankur-0429 pushed a commit to Ankur-0429/llvm-project that referenced this pull request May 9, 2025
…ion (llvm#135710)

llvm-diff shows this PR has no changes to amdgcn--amdhsa.bc.

Motivation is that in our downstream the same category of target
built-ins, e.g. math, are organized in several different folders. For
example, in target SOURCES we have math-common/cos.cl, while in generic
SOURCES it is math/cos.cl. Based on current check rule that compares
both folder name and base filename, target math-common/cos.cl won't
override math/cos.cl when collecting source files from SOURCES files in
cmake function libclc_configure_lib_source.

With this PR, we allow folder name to be different in the process.

A notable change of this PR is that two entries in SOURCES with the same
base filename must not implements the same built-in.
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.

2 participants