Skip to content
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

[SYCL] disallow mutable lambdas #1785

Merged
merged 19 commits into from
Jul 29, 2020

Conversation

cperkinsintel
Copy link
Contributor

@cperkinsintel cperkinsintel commented May 29, 2020

With the latest changes in the SYCL spec kernel lambdas (and functors) must be const references. Have updated the SYCL headers and tests with this change. Also had to make a minor adjustment to the kernel generation code in Clang and update many of the SemaSYCL tests, because their mock kernel defs needed to be updated as well.

Signed-off-by: Chris Perkins [email protected]

@cperkinsintel cperkinsintel requested a review from a team as a code owner May 29, 2020 21:44
@cperkinsintel cperkinsintel changed the title disallow mutable lambdas [SYCL] disallow mutable lambdas May 30, 2020
@AlexeySachkov
Copy link
Contributor

I did not update the definitions of the various reductions. Should I do so?

@vzakhari, @Pennycook: could you please answer here?

@vzakhari
Copy link
Contributor

vzakhari commented Jun 1, 2020

I did not update the definitions of the various reductions. Should I do so?

@vzakhari, @Pennycook: could you please answer here?

@AlexeySachkov, did you want to contact @v-klochkov instead of me?

@Pennycook
Copy link
Contributor

I did not update the definitions of the various reductions. Should I do so?

@vzakhari, @Pennycook: could you please answer here?

I think the interfaces should be consistent. If parallel_for shouldn't accept mutable lambdas, the form of parallel_for with support for reductions shouldn't accept mutable lambdas either.

@romanovvlad romanovvlad marked this pull request as draft July 8, 2020 12:17
@romanovvlad
Copy link
Contributor

@cperkinsintel Please, click on "ready for review" button once it's ready for review.

@cperkinsintel cperkinsintel force-pushed the cperkins-no-mutable-kernel-func branch from 1eada98 to 15c522e Compare July 14, 2020 21:05
sycl/include/CL/sycl/handler.hpp Outdated Show resolved Hide resolved
@cperkinsintel cperkinsintel requested a review from v-klochkov July 15, 2020 16:03
@cperkinsintel cperkinsintel force-pushed the cperkins-no-mutable-kernel-func branch from 7887e98 to 52a534d Compare July 18, 2020 06:07
@v-klochkov v-klochkov marked this pull request as ready for review July 20, 2020 22:00
@v-klochkov
Copy link
Contributor

@v-klochkov v-klochkov requested review from elizabethandrews, Fznamznon and premanandrao as code owners now

It the result of mis-click (accidentally clicked 'Ready for review' button, which did not ask for any confirmations after the click).
It still may be useful for code-owners to start reviewing this patch.

@cperkinsintel cperkinsintel requested a review from erichkeane July 20, 2020 22:13
Copy link
Contributor

@erichkeane erichkeane left a comment

Choose a reason for hiding this comment

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

I don't think changing all the tests in the CFE is the right idea. While I am fine fixing a bunch of them, we should still ensure the old behavior still works. This many file changes is likely unnecessary and just distracting review-wise.

Additionally, I think we should warn in both cases based on the SYCL version. So in 1.2.1, we should warn like we do with other language compatibility items (such as allowing C++11 features in 03, etc). In the newer one, we should warn to change it.

@@ -730,7 +730,13 @@ getKernelInvocationKind(FunctionDecl *KernelCallerFunc) {
}

static CXXRecordDecl *getKernelObjectType(FunctionDecl *Caller) {
return (*Caller->param_begin())->getType()->getAsCXXRecordDecl();
auto KernelParam = (*Caller->param_begin());
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
auto KernelParam = (*Caller->param_begin());
auto KernelParamTy = (*Caller->param_begin())->getType();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for catching that. Done.

clang/lib/Sema/SemaSYCL.cpp Outdated Show resolved Hide resolved
clang/lib/Sema/SemaSYCL.cpp Outdated Show resolved Hide resolved
clang/lib/Sema/SemaSYCL.cpp Outdated Show resolved Hide resolved
clang/lib/Sema/SemaSYCL.cpp Outdated Show resolved Hide resolved
@cperkinsintel
Copy link
Contributor Author

@erichkeane - There is a test that ensures that the SYCL 1.2 and SYCL 2020 versions are both supported: clang/test/CodeGenSYCL/kernel-by-reference.cpp

Also I agree about emitting a warning. But that seems out-of-scope for this change. How does the clang front end want to handle different versions of the SYCL runtime headers? Is this the only place we'll encounter differences? I think opening a ticket for it might be better.

@erichkeane
Copy link
Contributor

@erichkeane - There is a test that ensures that the SYCL 1.2 and SYCL 2020 versions are both supported: clang/test/CodeGenSYCL/kernel-by-reference.cpp

Also I agree about emitting a warning. But that seems out-of-scope for this change. How does the clang front end want to handle different versions of the SYCL runtime headers? Is this the only place we'll encounter differences? I think opening a ticket for it might be better.

I would think it is exactly in scope of this change, but I'll leave that to the code owners to make that decision.

Since we have a test that makes sure both works, I don't really see much value in changing the other 100+ tests, but I'll again leave that to the code owners to decide.

erichkeane pushed a commit to erichkeane/llvm that referenced this pull request Jul 21, 2020
This adds const-correctness to a bit of the visitor, as brought up in
review on intel#1785.
bader pushed a commit that referenced this pull request Jul 21, 2020
This adds const-correctness to a bit of the visitor, as brought up in
review on #1785.
@cperkinsintel cperkinsintel force-pushed the cperkins-no-mutable-kernel-func branch from 02d8f7c to 29ffe63 Compare July 21, 2020 21:42
romanovvlad
romanovvlad previously approved these changes Jul 22, 2020
Copy link
Contributor

@romanovvlad romanovvlad left a comment

Choose a reason for hiding this comment

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

I'm OK with the runtime part.

@cperkinsintel
Copy link
Contributor Author

@Fznamznon @elizabethandrews @premanandrao as code owners of the front-end, could one of you review that side of it? I had to update all those ersatz test kernels to bring them up to date with the new const-ref requirement on their lambdas. That touches a lot files, but the change is trivial, just avoids deferred maintenance. Other than that, the FE changes are very small.

@premanandrao
Copy link
Contributor

@Fznamznon @elizabethandrews @premanandrao as code owners of the front-end, could one of you review that side of it? I had to update all those ersatz test kernels to bring them up to date with the new const-ref requirement on their lambdas. That touches a lot files, but the change is trivial, just avoids deferred maintenance. Other than that, the FE changes are very small.

I am fine with the source code changes; it is just the volume of test changes that I was uncomfortable with.
What is the long-term plan for SYCL 1.2.1 way of passing lambdas? Will we continue to support it for a long time? If so, I am a bitconcerned about the lack of test coverage for that style. On the other hand, if the old style will be disallowed in the near future, then changing all the tests and having one test for completeness seems okay.

Signed-off-by: Chris Perkins <[email protected]>
Signed-off-by: Chris Perkins <[email protected]>
Signed-off-by: Chris Perkins <[email protected]>
@cperkinsintel
Copy link
Contributor Author

I've rebased, updated the conflicted test, and incorporated in @erichkeane latest request. Should be good to go.

@cperkinsintel
Copy link
Contributor Author

@erichkeane - Ok, I've added the second diagnostic, moved the emitting of it to its own function called from ConstructOpenCLKernel, put the warnings in their own groups, -Wno suppressed that same warning in a bunch of the tests that are now using the 2020 kernel definitions. Let me know if there are other changes.

clang/include/clang/Basic/DiagnosticSemaKinds.td Outdated Show resolved Hide resolved
@@ -1127,7 +1127,9 @@ def OpenMP : DiagGroup<"openmp", [
]>;

// SYCL warnings
def SyclStrict : DiagGroup<"sycl-strict">;
def Sycl2017Conform : DiagGroup<"sycl-2017-conform">;
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps sycl-2017-compat to be more consistent with c++98-compat, et al?

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, good call. Done.

clang/include/clang/Basic/DiagnosticSemaKinds.td Outdated Show resolved Hide resolved
clang/lib/Sema/SemaSYCL.cpp Outdated Show resolved Hide resolved
@@ -1948,6 +1971,7 @@ void Sema::ConstructOpenCLKernel(FunctionDecl *KernelCallerFunc,
if (LC.capturesThis() && LC.isImplicit())
Diag(LC.getLocation(), diag::err_implicit_this_capture);
}
diagKernelCallerSpecConformance(*this, KernelCallerFunc);
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment I had made in the past was to move the checks from 1969 into their own function as soon as we had a 2nd thing to check. So please make 1 function that checks both:

checkKernel? Anyone wanna bikeshed for me? @elizabethandrews @premanandrao ?

Copy link
Contributor

Choose a reason for hiding this comment

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

checkKernelParameters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

checkKernelAndCaller ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

checkKernelCompat ?

Copy link
Contributor

Choose a reason for hiding this comment

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

checkKernelParameters?

Its not really the Parameters, to the kernel, its the kernel object itself (plus the caller).

checkKernelAndCaller ?
Probably good enough for now. Presumably someone will come up with a better idea in the future and we can rename it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

Signed-off-by: Chris Perkins <[email protected]>
Copy link
Contributor

@erichkeane erichkeane left a comment

Choose a reason for hiding this comment

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

2 nits, otherwise LGTM.

clang/include/clang/Basic/DiagnosticSemaKinds.td Outdated Show resolved Hide resolved
}

// check that calling kernel conforms to spec
QualType KernelParamTy = (*Caller->param_begin())->getType();
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably want an assert here that Caller->param_size() >=1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Signed-off-by: Chris Perkins <[email protected]>
@romanovvlad romanovvlad merged commit a43dcc2 into intel:sycl Jul 29, 2020
romanovvlad added a commit that referenced this pull request Jul 29, 2020
alexbatashev pushed a commit to alexbatashev/llvm that referenced this pull request Jul 30, 2020
…rogram

* upstream/sycl: (609 commits)
  [SYCL] Fix fail in the post commit testing (intel#2210)
  [SYCL] Materialize shadow local variables for byval arguments before use (intel#2200)
  [SYCL] Support lambda functions passed to reduction (intel#2190)
  [SYCL][USM] Improve USM Allocator. (intel#2026)
  [SYCL] Disallow mutable lambdas (intel#1785)
  [SYCL][ESIMD] Setup compilation pipeline for ESIMD (intel#2134)
  [SYCL] Fix not found kernel due to empty kernel name when using set_arg(s) (intel#2181)
  [SYCL] Fixed check for set_arg (intel#2203)
  Refactor indirect access calls to minimize invocations. (intel#2185)
  [SYCL][NFC] Fix potential null-pointer access (intel#2197)
  [SYCL] Propagate attributes from transitive calls to kernel (intel#1878)
  [SYCL] Fix warnings from static analysis tool (intel#2193)
  [SYCL][NFC] Fix ac_float test for compilation with FE optimizations (intel#2184)
  [GitHub Actions] Uplift clang-format version to 10 (intel#2194)
  [SYCL][ESIMD] Pass to replace simd* parameters with native llvm vectors. (intel#2097)
  [SYCL][NFC] Fixed SYCL_PI_TRACE output while selecting a device. (intel#2192)
  [SYCL][FPGA] New spec for controlling load-store units in FPGAs (intel#2158)
  [SYCL][Doc] Clarify reqd_sub_group_size (intel#2103)
  [SYCL] Remove noreturn function attribute (intel#2165)
  [SYCL] Aligned set_arg behaviour with SYCL specification (intel#2159)
  ...
vladimirlaz pushed a commit that referenced this pull request Jul 30, 2020
alexbatashev pushed a commit to alexbatashev/llvm that referenced this pull request Jul 31, 2020
…rogram

* upstream/sycl:
  [SYCL] Add barrier before leader guard in LowerWGSCope pass (intel#2208)
  [SYCL] Add prototype of atomic_ref<T*> (intel#2177)
  Revert "[SYCL] Disallow mutable lambdas (intel#1785)" (intel#2213)
@erichkeane
Copy link
Contributor

@cperkinsintel : This got reverted, so you need to update this to figure out why it caused a bunch of test failures.

@Fznamznon
Copy link
Contributor

@cperkinsintel : This got reverted, so you need to update this to figure out why it caused a bunch of test failures.

I guess he already did, see #2259

@erichkeane
Copy link
Contributor

Ah, i see! He didn't mention this PR# so I guess it didn't get picked up.

@cperkinsintel cperkinsintel deleted the cperkins-no-mutable-kernel-func branch September 13, 2023 17:08
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.

10 participants