Skip to content

[SYCL] the first kernel function declaration should be added with attribute #18405

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

Open
wants to merge 6 commits into
base: sycl
Choose a base branch
from

Conversation

dklochkov-emb
Copy link
Contributor

Docs Defining a free function kernel contains:
The property must appear on the first declaration of the function in the translation unit. Redeclarations of the function may optionally be decorated with the same property if the property argument is the same. The effect is the same regardless of whether redeclarations are so decorated.

This PR changes isFreeFunction to define if the first occurrence of kernel free function has attribute or not. New clang diagnostics was added to highlight that first occurrence does not have attribute but the next has.

@dklochkov-emb dklochkov-emb requested review from a team as code owners May 12, 2025 08:17
@dklochkov-emb dklochkov-emb marked this pull request as draft May 12, 2025 08:17
@dklochkov-emb dklochkov-emb self-assigned this May 12, 2025
@dklochkov-emb dklochkov-emb marked this pull request as ready for review May 12, 2025 11:34
}
bool FirstDecl = true;
clang::SourceLocation Loc = FD->getLocation();
while (!Redecls.empty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

AFAIK a FunctionDecl should have a member isFirstDecl. Can we just loop over FD->redecls(), and issue an error in case an attribute is applied to a decl returning false from isFirstDecl?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reworked

@@ -12676,7 +12676,8 @@ def err_free_function_variadic_args : Error<
"free function kernel cannot be a variadic function">;
def err_free_function_return_type : Error<
"SYCL free function kernel should have return type 'void'">;

def err_free_function_first_occurrence_missing_attr: Error<
"the first occurrence of kernel free function should be declared with attribute add_ir_attributes_function with 'sycl-nd-range-kernel' or 'sycl-single-task-kernel'">;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"the first occurrence of kernel free function should be declared with attribute add_ir_attributes_function with 'sycl-nd-range-kernel' or 'sycl-single-task-kernel'">;
"the first occurrence of SYCL kernel free function should be declared with 'sycl-nd-range-kernel' or 'sycl-single-task-kernel' compile time properties">;

for (const auto &NameValuePair : NameValuePairs) {
if (NameValuePair.first == "sycl-nd-range-kernel" ||
NameValuePair.first == "sycl-single-task-kernel") {
clang::SourceLocation Loc = FD->getLocation();
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm pretty sure clang nns is not required here.

Suggested change
clang::SourceLocation Loc = FD->getLocation();
SourceLocation Loc = FD->getLocation();

@@ -10,6 +10,22 @@ foo(int start, ...) { // expected-error {{free function kernel cannot be a varia
foo1(int start, ...) { // expected-error {{free function kernel cannot be a variadic function}}
}

// expected-note@+1 {{conflicting attribute is here}}
[[__sycl_detail__::add_ir_attributes_function("sycl-single-task-kernel", 1)]] void
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please extend the testing with the following cases:

  • There are more than 2 redeclarations and the attribute is not on the first one
  • Templated free function
  • Overloads with the same name, different set of arguments and attributes applied to each should not trigger the diag

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.

2 participants