Skip to content

[SYCL][ESIMD] Setup compilation pipeline for ESIMD #2134

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 17 commits into from
Jul 29, 2020

Conversation

kbobrovs
Copy link
Contributor

  • Add passes in BackendUtil to enable ESIMD back-end code generation.
  • Add more tests some of which are dependent on the new compilation pipeline for ESIMD
  • on-device tests are to be added later once CI infrastructure is ready

Please review commits starting from
7f525d5 [SYCL][ESIMD] Enable LLVM passes for ESIMD.
Earlier commits are parts of other PRs.

@kbobrovs kbobrovs requested a review from DenisBakhvalov July 17, 2020 11:01
@kbobrovs kbobrovs requested a review from alexbatashev July 17, 2020 11:01
@kbobrovs kbobrovs added the esimd Explicit SIMD feature label Jul 17, 2020
bader
bader previously approved these changes Jul 17, 2020
Copy link
Contributor

@bader bader left a comment

Choose a reason for hiding this comment

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

LLVM changes looks good to me, but I would expect LLVM LIT test updates covering them.

Comment on lines 823 to 824
Value *TranslatedV =
TranslateFunc(*CI, SpirvIntrName.substr(1, 1));
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 add a regression test for this change, please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is added - sycl/test/esimd/spirv_intrins_trans.cpp

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean LLVM LIT test, not SYCL LIT test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I guess you mean IR->IR test. OK, will add. Even though functionality is covered by sycl/test/esimd/spirv_intrins_trans.cpp.

alexbatashev
alexbatashev previously approved these changes Jul 17, 2020
Copy link
Contributor

@alexbatashev alexbatashev left a comment

Choose a reason for hiding this comment

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

Contents of sycl/ LGTM.

@kbobrovs kbobrovs dismissed stale reviews from alexbatashev and bader via 6f58901 July 20, 2020 05:49
@kbobrovs
Copy link
Contributor Author

@bader, added a new test case into llvm/test/SYCLLowerIR/esimd_lower_intrins.ll - see
declare dso_local spir_func i64 @_Z27__spirv_LocalInvocationId_xv()

@kbobrovs
Copy link
Contributor Author

had to rebase to fix 2 failing tests and force-push.

alexbatashev
alexbatashev previously approved these changes Jul 20, 2020
Copy link
Contributor

@alexbatashev alexbatashev left a comment

Choose a reason for hiding this comment

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

SYCL part still LGTM

Comment on lines +175 to +178
%call = call spir_func i64 @_Z27__spirv_LocalInvocationId_xv()
; CHECK-NEXT: %call.esimd = call <3 x i32> @llvm.genx.local.id.v3i32()
; CHECK-NEXT: %local_id.x = extractelement <3 x i32> %call.esimd, i32 0
; CHECK-NEXT: %local_id.x.cast.ty = zext i32 %local_id.x to i64
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, consider following existing design for lowering functions like SPIR-V built-ins to device specific intrinsics by linking corresponding device library with SPIR-V functions implementation (see NVPTX implementation for details).
This will allow you to remove most of LowerESIMD pass (including the buggy part).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem with NVPTX approach as well as with using existing clang built-in infra is that it is hard to support the "C++" intrinsics mechanism with those. Once C++ intrinsics is supported in clang built-in infra - yes, this pass will simplify.

What buggy part do you refer to?

Copy link
Contributor

Choose a reason for hiding this comment

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

The problem with NVPTX approach as well as with using existing clang built-in infra is that it is hard to support the "C++" intrinsics mechanism with those.

I'm not sure why this mechanism is needed. translateSpirvIntrinsic doesn't require it.

BTW, why do we need this in the first place? According to my understanding these SPIR-V built-ins are lowered to valid SPIR-V, which should be supported by the back-end.

Once C++ intrinsics is supported in clang built-in infra - yes, this pass will simplify.

What buggy part do you refer to?

The one fixed by this patch.

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 see. You refer to SPIRV translation part. Agree - this could be done similar to NVPTX.

According to my understanding these SPIR-V built-ins are lowered to valid SPIR-V, which should be supported by the back-end.

Not quite. The vector BE does not support SPIRV intrinsics, as it is not a SIMT BE. But with subgroup size = 1 restriction it is doable really. I thought about this as a future step.

Copy link
Contributor

Choose a reason for hiding this comment

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

According to my understanding these SPIR-V built-ins are lowered to valid SPIR-V, which should be supported by the back-end.

Not quite. The vector BE does not support SPIRV intrinsics, as it is not a SIMT BE. But with subgroup size = 1 restriction it is doable really. I thought about this as a future step.

To be precise, this functions are represented in SPIR-V as a variable with decoration and I think it must be supported by any back-end. AFAIK, there are a lot of ESIMD specific patches landed to SPIR-V translator and it seems to the right place to lower this functionality.
SPIR-V consumer by design is supposed to lower standard SPIR-V instructions to HW specific intructions/intrinsics.
If I understand it correctly ESIMD extension implementation includes these two parts:

  • LLVM pass replaces SPIR-V built-in functions to GEN specific intrinsics in FE/ME.
  • SPIR-V translator is enhanced to preserve undefined GEN specific intrinsics in SPIR-V format.

According to my understanding these are not required if we move lowering of SPIR-V standard instructions to SPIR-V consumer.

NOTE: I'm talking about standard SPIR-V functionality only.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SPIR-V consumer by design is supposed to lower standard SPIR-V instructions to HW specific intructions/intrinsics.

That is true. But ESIMD back-end by design wasn't a "SPIRV consumer" and glue passes are still required to feed it LLVM IR resulting from SPIRV translation. Also ESIMD BE can't consume arbitrary SPIRV with Kernel capability - there are a number of restrictions. E.g. ESIMD BE does not have a concept of workitem, a central one in SIMT world. My point is that there are still design options which need to be discussed with the ESIMD BE devs.

Copy link
Contributor

Choose a reason for hiding this comment

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

But ESIMD back-end by design wasn't a "SPIRV consumer" and glue passes are still required to feed it LLVM IR resulting from SPIRV translation. Also ESIMD BE can't consume arbitrary SPIRV with Kernel capability - there are a number of restrictions. E.g. ESIMD BE does not have a concept of workitem, a central one in SIMT world. My point is that there are still design options which need to be discussed with the ESIMD BE devs.

If SPIR-V consumption is not designed, what is the point in using SPIR-V then?
It looks like using LLVM IR as exchange format in ESIMD mode would be much easier and doesn't require so much hacks.

Copy link
Contributor Author

@kbobrovs kbobrovs Jul 22, 2020

Choose a reason for hiding this comment

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

If SPIR-V consumption is not designed, what is the point in using SPIR-V then?

IR stability.

doesn't require so much hacks.

There can be parts which can be improved, but I don't see how this justifies calling it hacks.

bader
bader previously approved these changes Jul 20, 2020
Copy link
Contributor

@bader bader left a comment

Choose a reason for hiding this comment

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

de14866 - looks good me, assuming that other changes to llvm/* sources will be reviewed and merged separately (i.e. before this PR).

Copy link
Contributor

@elizabethandrews elizabethandrews left a comment

Choose a reason for hiding this comment

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

The only commit I see here with FE change not covered by other PRs is 2689ac1. This commit LGTM. Prior commits with FE changes have been reviewed, with changes requested, in their corresponding PRs.

@kbobrovs
Copy link
Contributor Author

Just for the record: this patch can be merged only after those:
#2133, #2097, #2096
some conflict resolution might be required

@kbobrovs kbobrovs dismissed stale reviews from elizabethandrews, bader, and alexbatashev via 2e70056 July 22, 2020 12:52
@kbobrovs kbobrovs force-pushed the esimd1-be-util branch 2 times, most recently from 2e70056 to 14dce98 Compare July 22, 2020 19:51
@kbobrovs
Copy link
Contributor Author

Had to resolve conflicts, rebase, fix test and force-push. The only changes are
[SQUASH] Fixed esimd_metadata2.cpp to prevent inlining. b28d14e264128b7800b215fde74f64ccea0b8718
[SQUASH] Applied clang format to ESIMD tests. 14dce981f37943719dea406a5f8ca6e5ea9c6732

@bader, please take a look at the two new above changes and re-approve.

Also new base commit covered by separate PR #2161 added.

@kbobrovs
Copy link
Contributor Author

Updated list of active PRs this one depends on:
#2161 #2097

Comment on lines 882 to 889
if (LangOpts.SYCLIsDevice && LangOpts.SYCLExplicitSIMD) {
PerModulePasses.add(createSYCLLowerESIMDPass());
}

CreatePasses(PerModulePasses, PerFunctionPasses);

if (LangOpts.SYCLIsDevice && LangOpts.SYCLExplicitSIMD &&
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't find review for this part, so I'll ask here.

Origianal code uses CreatePasses to populate PerModulePasses pass manager. It seems reasonable to move new code adding ESIMD passes to this function. Right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, will do.

@kbobrovs kbobrovs force-pushed the esimd1-be-util branch 2 times, most recently from ece45f5 to 2b0ee47 Compare July 23, 2020 12:07
kbobrovs and others added 15 commits July 28, 2020 21:45
Authors:
  Konstantin S Bobrovsky <[email protected]>
  Denis Bakhvalov <[email protected]>
  Gang Chen <[email protected]>

Signed-off-by: Konstantin S Bobrovsky <[email protected]>
Authors: Wei Pan, Konstantin S Bobrovsky, Denis Bakhvalov, Shahab Layeghi.

Signed-off-by: Konstantin S Bobrovsky <[email protected]>
Signed-off-by: Konstantin S Bobrovsky <[email protected]>
Co-authored-by: Alexander Batashev <[email protected]>
Signed-off-by: Konstantin S Bobrovsky <[email protected]>
Co-authored-by: Mariya Podchishchaeva <[email protected]>
@kbobrovs
Copy link
Contributor Author

Had to force-push after resolving conflicts, rebasing.

@kbobrovs kbobrovs requested a review from Fznamznon July 29, 2020 09:50
@kbobrovs
Copy link
Contributor Author

@bader, please take another look (essential change - fixed test for the vecarg pass)

@bader
Copy link
Contributor

bader commented Jul 29, 2020

@romanovvlad, could you take a look at clang-format-check. It looks like this sort of formatting suggestions should be suppressed. Right?
NOTE: users are free to set the comment prefixes for FileCheck, so I'm sure if there is a reliable regex to filter these comments. IIRC, you proposed to ignore all the comments. Can we apply this proposal?

@bader bader changed the title [SYCL][ESIMD] Setup compilation pipeline for ESIMD, add tests. [SYCL][ESIMD] Setup compilation pipeline for ESIMD Jul 29, 2020
@bader bader requested a review from alexbatashev July 29, 2020 14:08
@bader bader merged commit 44136bd into intel:sycl 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)
  ...
@kbobrovs kbobrovs deleted the esimd1-be-util branch July 30, 2020 12:28
jsji pushed a commit that referenced this pull request Aug 31, 2023
This completes the initial bulk conversion of tests using the
migration script.

There are more tests to be converted; however they will need manual
fixups, so leave them out of this bulk conversion.

Original commit:
KhronosGroup/SPIRV-LLVM-Translator@2c9f60f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
esimd Explicit SIMD feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants