Skip to content

[SYCL] remove free function definition from host object file - #22890

Open
dklochkov-emb wants to merge 5 commits into
intel:syclfrom
dklochkov-emb:sycl-fat-free-function-output
Open

[SYCL] remove free function definition from host object file#22890
dklochkov-emb wants to merge 5 commits into
intel:syclfrom
dklochkov-emb:sycl-fat-free-function-output

Conversation

@dklochkov-emb

Copy link
Copy Markdown
Contributor

It was found that host object file contains free function definition which is no needed there. This PR fixes that.

@dklochkov-emb
dklochkov-emb requested review from a team as code owners August 6, 2026 16:03
@dm-vodopyanov

Copy link
Copy Markdown
Contributor

@intel/dpcpp-cfe-reviewers can you please review today? This is in MFL.

if (SemaSYCLRef.SemaRef.getLangOpts().SYCLIsDevice) {
CompoundStmt *KernelBody = createFreeFunctionKernelBody();
DeclCreator.setBody(KernelBody);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this change affect the ability to call the kernel function on the host as a regular host function? For example, does this work:

SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::nd_range_kernel<1>))
void func() {/*...*/}

int main() {
  func();  // Called as regular host function
}

I ask only because the spec says that this is allowed:

A function decorated with one of these properties can still be called as a normal function in either host or device code. The property has no effect in such cases.

If necessary, I think we could change the spec. However, we should update the spec if this no longer works.

~FreeFunctionKernelBodyCreator() {
CompoundStmt *KernelBody = createFreeFunctionKernelBody();
DeclCreator.setBody(KernelBody);
// For host compilation, skip creating the wrapper body to reduce object

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am confused by this. The processing of free functions is already gated for SYCLIsDevice. The code in this PR seems redundant. Am I missing something? See SemaDecl.cpp

// Handle free functions.
  if (LangOpts.SYCLIsDevice && Body && !FD->isDependentContext())
    SYCL().ProcessFreeFunction(FD);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see constructFreeFunctionKernel is also called in handleSYCLRegisteredKernels but there is gating for SYCLIsDevice here as well.

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