Skip to content

[SYCL] Fix bugs with recursion in SYCL kernel #3958

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 6 commits into from
Jun 23, 2021

Conversation

elizabethandrews
Copy link
Contributor

@elizabethandrews elizabethandrews commented Jun 18, 2021

This patch removes ConstexprDepthRAII which incorrectly maintained
constexpr context. Instead we don't traverse statements which are
forced constant expressions.

This patch fixes the following bugs -

  1. constexpr int j = test_constexpr_context(recfn(1));
  2. int k;
    if constexpr (false)
    k = recfn(1);

Here, recfn() is a recursive function. The usage 1. should not
diagnose in SYCL kernel since the function is called in constexpr
context. Similarly 2. should not diagnose in SYCL kernel since the
recursive function call is in a discarded branch.

Includes commits in PR - #3714

Signed-off-by: Elizabeth Andrews elizabeth.andrews@intel.com

Erich Keane and others added 5 commits May 7, 2021 10:34
For the checks we do in SemaSYCL via the callgraph, we don't want to
diagnose when it is in a discarded statement. This adds the
infrastructure for another bug, where we visit constexpr during this
too.
This patch removes ConstexprDepthRAII which incorrectly maintained
constexpr context. Instead we don't traverse statements which are
forced constant expressions.

This patch fixes the following bugs -

1. constexpr int j = test_constexpr_context(recfn(1));
2. int k;
   if constexpr (false)
     k = recfn(1);

Here, recfn() is a recursive function. The usage 1. and 2. should not
diagnose in SYCL kernel since the function is called in constexpr
context.

Signed-off-by: Elizabeth Andrews <elizabeth.andrews@intel.com>
@elizabethandrews elizabethandrews marked this pull request as ready for review June 18, 2021 19:34
@vladimirlaz
Copy link
Contributor

According to SYCL spec "5.4. Language restrictions for device functions":

• Recursion is not allowed in a device function

Do we really need this change? The case looks explicitly restricted by the SYCL specification.

@AaronBallman
Copy link
Contributor

According to SYCL spec "5.4. Language restrictions for device functions":

• Recursion is not allowed in a device function

Do we really need this change? The case looks explicitly restricted by the SYCL specification.

It does, and if we do need this change, the SYCL spec needs to be fixed to clarify what it means.

My understanding (from previous conversations) is that the spec is trying to disallow runtime recursion on the device, not trying to disallow compile-time recursion that happens in the implementation execution environment. Based on that, I think these changes are necessary for implementation consistency.

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.

Generally OK, but the visitor can have some of its member functions deleted, when all it is doing is calling the same function on the base.

erichkeane
erichkeane previously approved these changes Jun 21, 2021
AaronBallman
AaronBallman previously approved these changes Jun 21, 2021
Copy link
Contributor

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

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

LGTM aside from the minor naming nit.

Signed-off-by: Elizabeth Andrews <elizabeth.andrews@intel.com>
@elizabethandrews elizabethandrews dismissed stale reviews from AaronBallman and erichkeane via be2739c June 21, 2021 14:00
Copy link
Contributor

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

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

LGTM!

@elizabethandrews
Copy link
Contributor Author

Thanks for the review!

@elizabethandrews
Copy link
Contributor Author

elizabethandrews commented Jun 22, 2021

@vladimirlaz @bader I think this patch is good to merge. Tests passed prior to last commit (which was a NFC renaming a variable). I tried restarting the failing tests but I'm not able to.

@vladimirlaz
Copy link
Contributor

@vladimirlaz @bader I think this patch is good to merge. Tests passed prior to last commit (which was a NFC renaming a variable). I tried restarting the failing tests but I'm not able to.

I have restarted the tests. Will wait for completion...

@vladimirlaz vladimirlaz merged commit 9a9a018 into intel:sycl Jun 23, 2021
alexbatashev added a commit to alexbatashev/llvm that referenced this pull request Jun 24, 2021
* upstream/sycl: (489 commits)
  [SYCL][NFC] Lower overhead of making plugin calls (intel#3982)
  [SYCL][NFC] Use default macro initialization where applicable (intel#3979)
  [SYCL] Enable SPV_INTEL_fpga_invocation_pipelining_attributes extension (intel#3864)
  [SYCL] Disable reassociate pass to reduce register pressure (intel#3615)
  [Driver][SYCL][FPGA] Restrict -O0 for FPGA with hardware (intel#3966)
  [SYCL][NFC] Fix warnings coming out of SYCL headers. (intel#3978)
  [SYCL] Fix bugs with recursion in SYCL kernel (intel#3958)
  [SYCL][LevelZero] Add support to detect host->device and device->host transfers for USM (intel#3975)
  [SYCL] Enable native FP atomics by default (intel#3869)
  [sycl-post-link] Avoid copying from nullptr (intel#3963)
  [SYCL-PTX] Add warp-reduce path in sub-group reduce (intel#3949)
  [BuildBot] Uplift CPU/FPGAEMU RT version for CI Process (intel#3946)
  Fix handling of complex constant expressions
  Handle OpSpecConstantOp with CompositeExtract and CompositeInsert
  Handle OpSpecConstantOp with VectorShuffle
  [FuncSpec] Don't specialise functions with NoDuplicate instructions.
  [mlir][linalg] Support low padding in subtensor(pad_tensor) lowering
  [gn build] Port 208332d
  [AMDGPU] Add Optimize VGPR LiveRange Pass.
  [mlir][Linalg] NFC - Drop unused variable definition.
  ...
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants