Skip to content

[SYCL][ESIMD] Refactor ESIMD kernel support in FE. #2747

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

Closed
wants to merge 8 commits into from

Conversation

kbobrovs
Copy link
Contributor

@kbobrovs kbobrovs commented Nov 9, 2020

This patch adds necessary support in FE to get rid of buffer object wrapping into image1d_buffer -
workaround for ESIMD BE gaps.

  • Add 'esimd_acc_ptr' parameter attribute to FE.
    This attribute is to be used by the FE to mark ESIMD kernel arguments
    originating from buffer accessors, which is then translated to BE-specific
    metadata needed for correct code generation.
  • Use 'esimd_acc_ptr' attribute to mark ESIMD kernel pointer
    arguments originating from accessors
  • Use '__init_esimd' initializer in FE for ESIMD kernel accessors.
  • Add 'isESIMD()' function to the integration header for the RT to
    be able to distinguish ESIMD kernels from normal ones for the
    purpose of proper accessor arg setting.

TODO add tests for the new attrs

The other two PRs needed for this one to work are:

This attribute is to be used by the FE to mark ESIMD kernel arguments
originating from buffer accessors, which is then translated to BE-specific
metadata needed for correct code generation.

Signed-off-by: Konstantin S Bobrovsky <[email protected]>
- Use 'esimd_acc_ptr' attribute to mark ESIMD kernel pointer
  arguments originating from accessors
- Use '__init_esimd' initializer in FE for ESIMD kernel accessors.
- Add 'isESIMD()' function to the integration header for the RT to
  be able to distinguish ESIMD kernels from normal ones for the
  purpose of proper accessor arg setting.

Signed-off-by: Konstantin S Bobrovsky <[email protected]>
SyclKernelArgsSizeChecker ArgsSizeChecker(*this, Args[0]->getExprLoc());

const CXXMethodDecl *OpParens = getOperatorParens(KernelObj);
bool IsSIMD = (OpParens != nullptr) && OpParens->hasAttr<SYCLSimdAttr>();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Those two lines are repeated multiple times. Maybe create a helper function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

// Not supposed to be used directly in the source - SYCL device compiler FE
// automatically adds it for ESIMD kernels.
def SYCLSimdAccessorPtr : InheritableAttr {
let Spellings = [GNU<"esimd_acc_ptr">, Declspec<"esimd_acc_ptr">];
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we don't need spelling if this attribute is not supposed to be used in the source.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

Comment on lines 1165 to 1169
// Used to mark kernel pointer parameters which correspond to the original
// lambda's captured accessor. FE turns it to some metadata required by the
// ESIMD Back-End.
// Not supposed to be used directly in the source - SYCL device compiler FE
// automatically adds it for ESIMD kernels.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can move this information to the doc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

@@ -375,6 +375,9 @@ class SYCLIntegrationHeader {

SourceLocation KernelLocation;

/// Whether this kernel is an ESIMD one.
bool IsESIMD;
Copy link
Contributor

Choose a reason for hiding this comment

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

How about

Suggested change
bool IsESIMD;
bool IsESIMDKernel;

To make it clear that this flag is about kernel and not language options, for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok


argESIMDAccPtrs.push_back(
llvm::ConstantAsMetadata::get(CGF->Builder.getInt1(
parm->getAttr<SYCLSimdAccessorPtrAttr>() != nullptr)));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it will be a bit more optimal.

Suggested change
parm->getAttr<SYCLSimdAccessorPtrAttr>() != nullptr)));
parm->hasAttr<SYCLSimdAccessorPtrAttr>())));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure. I want 0 or 1 is a clean input for getInt1. Non-null parm->getAttr() is neither

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I didn't get your statement. I thought that parm->getAttr<SYCLSimdAccessorPtrAttr>() != nullptr actually gives bool which is 0 or 1 as well as hasAttr function which also returns bool (https://clang.llvm.org/doxygen/classclang_1_1Decl.html#ae7a63b99398864d86f53afd8a03c359b).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, you are right. hasAttr is OK - will change

Comment on lines 8212 to 8214
case ParsedAttr::AT_SYCLSimdAccessorPtr:
handleSimpleAttribute<SYCLSimdAccessorPtrAttr>(S, D, AL);
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we won't need this part if we remove spelling.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

kbobrovs and others added 5 commits November 10, 2020 07:18
Signed-off-by: Konstantin S Bobrovsky <[email protected]>
Copy link
Contributor

@Fznamznon Fznamznon left a comment

Choose a reason for hiding this comment

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

Please add tests.
I would expect a codegen IR test and a test for integration header changes.

@kbobrovs
Copy link
Contributor Author

Yes, tests will be added.

@kbobrovs
Copy link
Contributor Author

@Fznamznon, I added 2 tests you to this PR: #2746
where I consolidated all the patches so that I can pass tests. All the patches should be committed at the same time anyway.

@kbobrovs
Copy link
Contributor Author

now part of #2746

@kbobrovs kbobrovs closed this Nov 17, 2020
@kbobrovs kbobrovs deleted the drop_image_wrap_fe branch January 19, 2022 22:51
jsji pushed a commit that referenced this pull request Oct 11, 2024
```
.../SPIRV-LLVM-Translator/lib/SPIRV/SPIRVWriter.cpp:1697:44: warning: private field 'IndexGroupArrayMap' is not used [-Wunused-private-field]
 1697 |   LLVMToSPIRVBase::LLVMToSPIRVMetadataMap &IndexGroupArrayMap;
      |
```
IndexGroupArrayMap is used but only during the constructor to
validate and build other things.

This change happened in 4a7804bc45ada92b8365c82b99387726382b5d7d
where code was moved from a separate method, into the constructor.

Original commit:
KhronosGroup/SPIRV-LLVM-Translator@9a23d54079204ae
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.

3 participants