Skip to content

Conversation

frasercrmck
Copy link
Contributor

This removes the dependency on an external tool to build the SPIR-V files. It may be of interest to projects such as Mesa.

Note that the option is off by default as using the SPIR-V backend, at least on my machine, uses a lot of memory and the process is often killed in a parallelized build. It does complete, however.

Fixes #135327.

This removes the dependency on an external tool to build the SPIR-V
files. It may be of interest to projects such as Mesa.

Note that the option is off by default as using the SPIR-V backend, at
least on my machine, uses a *lot* of memory and the process is often
killed in a parallelized build. It does complete, however.

Fixes llvm#135327.
@frasercrmck frasercrmck requested review from nikic and wenju-he July 30, 2025 14:50
@frasercrmck frasercrmck added the libclc libclc OpenCL library label Jul 30, 2025
Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@nikic
Copy link
Contributor

nikic commented Jul 30, 2025

Note that the option is off by default as using the SPIR-V backend, at least on my machine, uses a lot of memory and the process is often killed in a parallelized build. It does complete, however.

I see the same behavior, goes up to something like 30GB. The input is not particularly large (just 300k lines of IR).

From a quick run through massif, it looks like MachineInstrs in SPIRVGlobalRegistry are the memory hog?

)
if ( LIBCLC_USE_SPIRV_BACKEND )
add_custom_command( OUTPUT ${libclc_builtins_lib}
COMMAND ${clang_exe} --target=${ARG_TRIPLE} -x ir -o ${libclc_builtins_lib} ${builtins_link_lib}
Copy link
Contributor

Choose a reason for hiding this comment

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

should -c be added to clang command line? It avoids spirv-link step.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question! I'm not sure, to be honest. I tried using -c and it generates a slightly larger file (6900 vs 6792). It seems to take a few fewer seconds to do so, which is an upside. I haven't looked into what exactly it's doing.

Copy link
Contributor

@wenju-he wenju-he Aug 1, 2025

Choose a reason for hiding this comment

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

perhaps spirv-link does optimization, but obviously there is only one file to link. LGTM as the final size is smaller, so this is not meant to be a blocker.

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry, not meant to be

Copy link
Contributor

@wenju-he wenju-he left a comment

Choose a reason for hiding this comment

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

LGTM

@frasercrmck frasercrmck merged commit b0313ad into llvm:main Aug 1, 2025
11 checks passed
@frasercrmck frasercrmck deleted the libclc-spirv-backend branch August 1, 2025 08:48
@FireBurn
Copy link

FireBurn commented Oct 1, 2025

Can this be backported to 21?

@nikic
Copy link
Contributor

nikic commented Oct 1, 2025

I don't think it makes sense to backport this. At least at the time it landed it only worked in the sense of "does not crash during compilation". I'm not sure if the big compile-time and memory usage issue has been resolved since, or anyone has checked whether the produced SPIRV actually works.

@FireBurn
Copy link

FireBurn commented Oct 1, 2025

Yeah, it looks like at least 638383c is needed on 21 to make it work

Just that infact

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.

Use spirv backend in libclc
4 participants