Skip to content

[SYCL] Kernel free function num args functionality #19517

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 26 commits into from
Jul 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
15555b7
[SYCL] add possibility to get number of argumnet of kernell free func…
dklochkov-emb Jul 18, 2025
e954028
[SYCL] update formatting
dklochkov-emb Jul 18, 2025
ecfea21
[SYCL] do no capture unused parameters in lambda
dklochkov-emb Jul 18, 2025
c0f2b29
[SYCL][E2E] update win abi test
dklochkov-emb Jul 18, 2025
6eb351e
Merge remote-tracking branch 'upstream/sycl' into sycl-free-functions…
dklochkov-emb Jul 21, 2025
cdc214c
[SYCL] return free function kernel data only if kernel is free function
dklochkov-emb Jul 21, 2025
a3e9450
[SYCL] fix formatting
dklochkov-emb Jul 21, 2025
2373446
[SYCL][TEST] update ABI tests
dklochkov-emb Jul 21, 2025
aab52c6
[SYCL] do not use public interface to get num_args
dklochkov-emb Jul 22, 2025
e415843
[SYCL] remove win symbols from abi test
dklochkov-emb Jul 22, 2025
9e1f16d
[SYCL] fix syntax
dklochkov-emb Jul 22, 2025
c0fdbc4
[SYCL] store kernel global data in a separate map in program manager
dklochkov-emb Jul 23, 2025
bf4786e
[SYCL] do not create a separate function to add global kernel descs …
dklochkov-emb Jul 23, 2025
811c4b6
[SYCL] do not use string pattern to detect if kernel is a free function
dklochkov-emb Jul 23, 2025
618f51e
[SYCL][TEST] update win abi test
dklochkov-emb Jul 23, 2025
ef30cde
[SYCL][TEST] add new headers to test input directory
dklochkov-emb Jul 23, 2025
ed5acdf
[SYCL] update args to match map
dklochkov-emb Jul 23, 2025
b052359
[SYCL] do not lock if add or get kernel global info
dklochkov-emb Jul 23, 2025
0a35b30
[SYCL][TEST] update win abi test
dklochkov-emb Jul 23, 2025
f4efc2f
[SYCL] do not cast unsigned to void pointer
dklochkov-emb Jul 24, 2025
11c6270
[SYCL] rework register global kernel info function
dklochkov-emb Jul 24, 2025
0b67f11
[SYCL][TEST] update win abi test
dklochkov-emb Jul 24, 2025
532aff0
[SYCL] more informative names and comments
dklochkov-emb Jul 24, 2025
b52a1b3
Merge remote-tracking branch 'upstream/sycl' into sycl-free-functions…
dklochkov-emb Jul 24, 2025
be6f64c
[SYCL] update formatting
dklochkov-emb Jul 29, 2025
80271f0
Merge remote-tracking branch 'upstream/sycl' into sycl-free-functions…
dklochkov-emb Jul 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 48 additions & 15 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6666,6 +6666,34 @@ class FreeFunctionPrinter {
FD->getTemplateSpecializationArgs());
}

/// Emits free function kernel info specialization for shimN.
/// \param ShimCounter The counter for the shim function.
/// \param KParamsSize The number of kernel free function arguments.
/// \param KName The name of the kernel free function.
void printFreeFunctionKernelInfo(const unsigned ShimCounter,
const size_t KParamsSize,
std::string_view KName) {
O << "\n";
O << "namespace sycl {\n";
O << "inline namespace _V1 {\n";
O << "namespace detail {\n";
O << "//Free Function Kernel info specialization for shim" << ShimCounter
<< "\n";
O << "template <> struct FreeFunctionInfoData<__sycl_shim" << ShimCounter
<< "()> {\n";
O << " __SYCL_DLL_LOCAL\n";
O << " static constexpr unsigned getNumParams() { return " << KParamsSize
<< "; }\n";
O << " __SYCL_DLL_LOCAL\n";
O << " static constexpr const char *getFunctionName() { return ";
O << "\"" << KName << "\"; }\n";
O << "};\n";
O << "} // namespace detail\n"
<< "} // namespace _V1\n"
<< "} // namespace sycl\n";
O << "\n";
}

private:
/// Helper method to get string with template types
/// \param TAL The template argument list.
Expand Down Expand Up @@ -6915,6 +6943,11 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {
O << " \"\",\n";
O << "};\n\n";

O << "static constexpr unsigned kernel_args_sizes[] = {";
for (unsigned I = 0; I < KernelDescs.size(); I++) {
O << KernelDescs[I].Params.size() << ", ";
}
O << "};\n\n";
O << "// array representing signatures of all kernels defined in the\n";
O << "// corresponding source\n";
O << "static constexpr\n";
Expand Down Expand Up @@ -7127,6 +7160,7 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {
FFPrinter.printFreeFunctionShim(K.SyclKernel, ShimCounter, ParmList);
O << ";\n";
O << "}\n";
FFPrinter.printFreeFunctionKernelInfo(ShimCounter, K.Params.size(), K.Name);
Policy.SuppressDefaultTemplateArgs = true;
Policy.EnforceDefaultTemplateArgs = false;

Expand Down Expand Up @@ -7156,22 +7190,21 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {

if (FreeFunctionCount > 0) {
O << "\n#include <sycl/kernel_bundle.hpp>\n";
}
ShimCounter = 1;
for (const KernelDesc &K : KernelDescs) {
if (!S.isFreeFunction(K.SyclKernel))
continue;

O << "\n// Definition of kernel_id of " << K.Name << "\n";
O << "#include <sycl/detail/kernel_global_info.hpp>\n";
O << "namespace sycl {\n";
O << "template <>\n";
O << "inline kernel_id ext::oneapi::experimental::get_kernel_id<__sycl_shim"
<< ShimCounter << "()>() {\n";
O << " return sycl::detail::get_kernel_id_impl(std::string_view{\""
<< K.Name << "\"});\n";
O << "}\n";
O << "}\n";
++ShimCounter;
O << "inline namespace _V1 {\n";
O << "namespace detail {\n";
O << "struct GlobalMapUpdater {\n";
O << " GlobalMapUpdater() {\n";
O << " sycl::detail::free_function_info_map::add("
<< "sycl::detail::kernel_names, sycl::detail::kernel_args_sizes, "
<< KernelDescs.size() << ");\n";
O << " }\n";
O << "};\n";
O << "static GlobalMapUpdater updater;\n";
O << "} // namespace detail\n";
O << "} // namespace _V1\n";
O << "} // namespace sycl\n";
}
}

Expand Down
Loading