Skip to content

[SYCL][RTC] Clarify and test handling of include paths #17307

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 22 commits into from
Mar 11, 2025

Conversation

jopperm
Copy link
Contributor

@jopperm jopperm commented Mar 5, 2025

Multiple changes related to the handling of #include's in RTC:

  • Fix a bug in how the in-memory pipeline rendered joined arguments
  • Add "current working directory" and "directories specified via -I in build_options" to the locations that extension will look for header files, and clarifiy search order, in the specification. This change is meant to establish clang's usual include behavior.
  • Add an extensive E2E test for include handling
  • Check if filename is not present in include_files::add to match specification
  • Add missing constructors and add method to include_files and build_properties to match specification

@jopperm jopperm self-assigned this Mar 5, 2025
@jopperm jopperm temporarily deployed to WindowsCILock March 5, 2025 00:24 — with GitHub Actions Inactive
Signed-off-by: Julian Oppermann <[email protected]>
Signed-off-by: Julian Oppermann <[email protected]>
@jopperm jopperm temporarily deployed to WindowsCILock March 5, 2025 04:12 — with GitHub Actions Inactive
Signed-off-by: Julian Oppermann <[email protected]>
Signed-off-by: Julian Oppermann <[email protected]>
@jopperm jopperm temporarily deployed to WindowsCILock March 5, 2025 04:54 — with GitHub Actions Inactive
@jopperm jopperm temporarily deployed to WindowsCILock March 5, 2025 05:24 — with GitHub Actions Inactive
@jopperm jopperm marked this pull request as ready for review March 5, 2025 07:56
@jopperm jopperm requested review from a team as code owners March 5, 2025 07:56
Comment on lines 665 to 677
is useful, for example, to compile kernels using external libraries. The
following spellings are supported (note that the path is a separate element in
the `build_options` list for the second and fourth form):

[source,c++]
----
build_options{{
{"-Ipath"},
{"-I"}, {"path"},
{"--include-directory=path"},
{"--include-directory"}, {"path"}
}}
----
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I'd prefer it if we actually documented each of these flags separately, but I'm not sure we have precedent for how to do that. I don't want this comment to block this PR, but I'm leaving a note for @gmlueck to review upon his return.

Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, these are standard compiler flags for Clang and GCC, not specific to RTC, so users are potentially already familiar with them.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a good point. I agree that most people reading the specification will be able to figure this out, and that's another reason not to let my comment completely block this PR.

But, the specification for build_options currently says:

The source_language::sycl language does not define any standard build options, but an implementation may support implementation-defined options.

Because the current description of these include options is so vague, it's not clear to me whether there are intended to be supported by all implementations of this extension (in which case, the description of build_options is wrong), or whether they are intended to be specific to DPC++.

The only situation I'd feel comfortable leaving things with a vague description would be if the specification said something like "In DPC++, any additional build_options behave as if passed to DPC++", in which case we'd inherit the definitions of -I etc from there. But I don't know if that's the current behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, the documentation of the build_options still needs some attention in this document.

"In DPC++, any additional build_options behave as if passed to DPC++"

This is true for many options, but there are definitely some we cannot support right now (e.g. everything related to AoT compilation).

I plan to add a list of supported options before the release, in form of a DPC++-specific, non-normative section* towards the end of the document. This would of course include the -I option, so we could move the examples for using it to that section, and/or reference the DPC++ docs. Makes sense to me that the specification part would then only state that implementation-specific options can be added to build_options to include additional paths, and point the reader to the non-normative section.

*) Greg suggested (or at least approved of) having such a section.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, thanks for explaining that. I think if the intent is that -I is not guaranteed to be supported by all compilers, we should create the DPC++-specific non-normative section now, and just put the -I flags in it.

It's much easier to take something that's DPC++-specific and make it available to all implementations than to do the opposite. And you can still add the documentation for the other flags later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

[...] we should create the DPC++-specific non-normative section now, and just put the -I flags in it.

Makes sense, done! @Pennycook can you have another look, please?

Comment on lines 665 to 677
is useful, for example, to compile kernels using external libraries. The
following spellings are supported (note that the path is a separate element in
the `build_options` list for the second and fourth form):

[source,c++]
----
build_options{{
{"-Ipath"},
{"-I"}, {"path"},
{"--include-directory=path"},
{"--include-directory"}, {"path"}
}}
----
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, these are standard compiler flags for Clang and GCC, not specific to RTC, so users are potentially already familiar with them.

Comment on lines 962 to 968
if (std::find_if(record.begin(), record.end(), [&name](auto &p) {
return p.first == name;
}) != record.end()) {
throw sycl::exception(make_error_code(errc::invalid),
"Include file '" + name +
"' is already registered");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the specification promise this exception to be thrown?

It seems like potential overhead to go through the existing list over and over again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes:

* An `exception` with the `errc::invalid` error code if there is already an
entry with `name` in this property.

Not sure if we are expecting apps to register many virtual header files. For registered_kernel_names, the semantics are more relaxed:

[_Note:_ It is not an error to have duplicate names in a `registered_names`
property, but the duplicates have no effect.

Maybe we should adopt that. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Could we potentially use a different data structure, e.g., map, to make the lookup more efficient and avoid the quadratic complexity?

Copy link
Contributor Author

@jopperm jopperm Mar 7, 2025

Choose a reason for hiding this comment

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

Yes, the order of the virtual include files should be insignificant. In 0ad484d I switched the container to an unordered_map. Unfortunately this causes the rather large change to the sycl_classes_abi_neutral_test.cpp test.

Signed-off-by: Julian Oppermann <[email protected]>
@jopperm
Copy link
Contributor Author

jopperm commented Mar 10, 2025

Changes themselves LGTM, but we need to check whether include_files has been in a release ABI and if we can make this potentially ABI-breaking change now.

AFAICT this is not an ABI break. The entrypoint into libsycl is:

__SYCL_EXPORT kernel_bundle<bundle_state::ext_oneapi_source>
make_kernel_bundle_from_source(
const context &SyclContext, source_language Language,
sycl::detail::string_view Source,
std::vector<std::pair<sycl::detail::string_view, sycl::detail::string_view>>
IncludePairsVec);

which is unaffected by the changes to include_files.

sycl/test/abi/sycl_classes_abi_neutral_test.cpp ensures that SYCL classes do not contain std::basic_string and std::list members. include_files was already listed as an exclusion in the test, however, a map's internal layout is more complicated than a vector, requiring more CHECK lines to match all occurences of std::basic_string.

Copy link
Contributor

@sommerlukas sommerlukas 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/abi/sycl_classes_abi_neutral_test.cpp ensures that SYCL classes do not contain std::basic_string and std::list members. include_files was already listed as an exclusion in the test, however, a map's internal layout is more complicated than a vector, requiring more CHECK lines to match all occurences of std::basic_string.

Thanks for explanation, that makes sense.

Implementation LGTM.

Copy link
Contributor

@Pennycook Pennycook left a comment

Choose a reason for hiding this comment

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

Latest extension specification LGTM.

Signed-off-by: Julian Oppermann <[email protected]>
@jopperm
Copy link
Contributor Author

jopperm commented Mar 11, 2025

@intel/llvm-gatekeepers Can you merge this, please?

I'd argue we don't need to wait for the AMD runner. The AMD workflow was successful for 5fbd5b0, and I just bumped the counter in a SYCL lit test for the pending commit.

@uditagarwal97 uditagarwal97 merged commit 81e9be7 into intel:sycl Mar 11, 2025
24 checks passed
sommerlukas pushed a commit that referenced this pull request Mar 18, 2025
Partially revert #17307: change the container in the `include_files`
property back to vector of pairs, as the more complex internal structure
of a map made it very fragile to test in
`sycl_classes_abi_neutral_test.cpp`.

---------

Signed-off-by: Julian Oppermann <[email protected]>
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.

5 participants