Skip to content

[SYCL][FPGA] Update __builtin_intel_fpga_mem #5002

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 5 commits into from

Conversation

Fznamznon
Copy link
Contributor

According to #4980 this built-in
should take four more constant integer parameters with following default
values:

const int32_t AnchorID = -1
const int32_t TargetAnchor = 0
const int32_t Type = 0
const int32_t Cycle = 0

The old variant is still allowed for backward compatibility. In case
some parameters are not provided - default value will be emitted in
annotation string.

According to intel#4980 this built-in
should take four more constant integer parameters with following default
values:
```
const int32_t AnchorID = -1
const int32_t TargetAnchor = 0
const int32_t Type = 0
const int32_t Cycle = 0
```
The old variant is still allowed for backward compatibility. In case
some parameters are not provided - default value will be emitted in
annotation string.
@Fznamznon
Copy link
Contributor Author

@shuoniu-intel , please take a look to make sure we have the same understanding of how this is supposed to work. Please also let me know if strings emitted in LLVM IR i.e. anchor-id, target-anchor, type, cycle are ok.

@shuoniu-intel
Copy link
Contributor

@shuoniu-intel , please take a look to make sure we have the same understanding of how this is supposed to work. Please also let me know if strings emitted in LLVM IR i.e. anchor-id, target-anchor, type, cycle are ok.

LGTM!

@Fznamznon
Copy link
Contributor Author

Ping @elizabethandrews , @premanandrao , @smanna12 on review.

Copy link
Contributor

@premanandrao premanandrao left a comment

Choose a reason for hiding this comment

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

Changes look good to me. I just have minor nits.

smanna12
smanna12 previously approved these changes Nov 30, 2021
Copy link
Contributor

@smanna12 smanna12 left a comment

Choose a reason for hiding this comment

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

LGTM

premanandrao
premanandrao previously approved these changes Nov 30, 2021
Copy link
Contributor

@premanandrao premanandrao left a comment

Choose a reason for hiding this comment

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

LGTM

@Fznamznon Fznamznon dismissed stale reviews from premanandrao and smanna12 via 5916950 November 30, 2021 16:35
@Fznamznon
Copy link
Contributor Author

/summary:run

@Fznamznon
Copy link
Contributor Author

@shuoniu-intel , Is it safe to merge this one? Does FPGA compiler support new form of the annotations? Or maybe we should wait for the spec?

@bader
Copy link
Contributor

bader commented Dec 2, 2021

Is it safe to merge this one?

I think the spec must be approved and merged before the implementation.

Comment on lines +20474 to +20488
auto AddOptionalArgValue = [&E, &Ctx, &Out](int DefaultValue,
unsigned NumOfArg,
StringRef StringToAdd) {
Optional<llvm::APSInt> IntVal =
(E->getNumArgs() > NumOfArg)
? E->getArg(NumOfArg)->getIntegerConstantExpr(Ctx)
: APSInt::get(DefaultValue);
assert(IntVal.hasValue() && "Constant arg isn't actually constant?");
Out << "{" << StringToAdd << ":" << toString(*IntVal, 10) << "}";
};

AddOptionalArgValue(-1, 3, "anchor-id");
AddOptionalArgValue(0, 4, "target-anchor");
AddOptionalArgValue(0, 5, "type");
AddOptionalArgValue(0, 6, "cycle");
Copy link
Contributor

@mlychkov mlychkov Dec 2, 2021

Choose a reason for hiding this comment

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

May we use AddOptionalArgValue for first two parameters as well (maybe to rename lambda to AddArgValue)?

Suggested change
auto AddOptionalArgValue = [&E, &Ctx, &Out](int DefaultValue,
unsigned NumOfArg,
StringRef StringToAdd) {
Optional<llvm::APSInt> IntVal =
(E->getNumArgs() > NumOfArg)
? E->getArg(NumOfArg)->getIntegerConstantExpr(Ctx)
: APSInt::get(DefaultValue);
assert(IntVal.hasValue() && "Constant arg isn't actually constant?");
Out << "{" << StringToAdd << ":" << toString(*IntVal, 10) << "}";
};
AddOptionalArgValue(-1, 3, "anchor-id");
AddOptionalArgValue(0, 4, "target-anchor");
AddOptionalArgValue(0, 5, "type");
AddOptionalArgValue(0, 6, "cycle");
auto AddArgValue = [&E, &Ctx, &Out](unsigned NumOfArg,
StringRef StringToAdd,
int DefaultValue = MIN_INT) {
Optional<llvm::APSInt> IntVal =
(E->getNumArgs() > NumOfArg)
? E->getArg(NumOfArg)->getIntegerConstantExpr(Ctx)
: APSInt::get(DefaultValue);
assert(IntVal.hasValue() && "Constant arg isn't actually constant?");
Out << "{" << StringToAdd << ":" << toString(*IntVal, 10) << "}";
};
AddArgValue(1, "params");
AddArgValue(2, "cache-size");
AddArgValue(3, "anchor-id", -1);
AddArgValue(4, "target-anchor", 0);
AddArgValue(5, "type", 0);
AddArgValue(6, "cycle", 0);

@shuoniu-intel
Copy link
Contributor

@shuoniu-intel , Is it safe to merge this one? Does FPGA compiler support new form of the annotations? Or maybe we should wait for the spec?

It should be safe since your implementation is backwards-compatible.
I'm okay with it if reviewers think this PR should wait for the spec.

@Fznamznon
Copy link
Contributor Author

@shuoniu-intel , Is it safe to merge this one? Does FPGA compiler support new form of the annotations? Or maybe we should wait for the spec?

It should be safe since your implementation is backwards-compatible. I'm okay with it if reviewers think this PR should wait for the spec.

Please note that even though the new builtin is backward compatible for users in C++ code, this patch adds permanent generation of four new default values in the annotation string in LLVM IR, so after this patch the output is always a bit different. I was wondering if FPGA compiler will be ok with that.
I've ran extended pre commit in order to understand if some of the compiler's components are not ok with this change. Even though the tests have passed, it can be explained by lack of the tests. So I'm double checking with people.
BTW, @MrSidims , do you know if SPIR-V translator will be ok with the new LLVM IR emitted?

@shuoniu-intel
Copy link
Contributor

Let this PR wait for the spec then. Meanwhile I'll verify if the FPGA compiler is okay with the new annotation string.

Btw this will be the new look of the annotation string output from clang and SPIR-V right?
[[ANN1:@.str[\.]*[0-9]*]] = {{.*}}{params:384}{cache-size:0}{anchor-id:-1}{target-anchor:0}{type:0}{cycle:0}

@MrSidims
Copy link
Contributor

MrSidims commented Dec 2, 2021

do you know if SPIR-V translator will be ok with the new LLVM IR emitted?

I expect, that it will map LLVM IR construct on UserSemantic decoration and translate it backwards without any problems. If it's not happening - then it's a bug in the translator.

I've ran extended pre commit in order to understand if some of the compiler's components are not ok with this change

I don't think we have OK test coverage for FPGA h/w here :(

In general, if the compiler doesn't know what to do with annotation information - the annotation intrinsics should be ignored (if seen otherwise - it's a bug in the device's backend IMO).

@Fznamznon
Copy link
Contributor Author

Btw this will be the new look of the annotation string output from clang and SPIR-V right? [[ANN1:@.str[\.]*[0-9]*]] = {{.*}}{params:384}{cache-size:0}{anchor-id:-1}{target-anchor:0}{type:0}{cycle:0}

Yeah, It will look like the old variant but with default values {anchor-id:-1}{target-anchor:0}{type:0}{cycle:0} added at the end.
An example of normal emitted IR:

@.str = private unnamed_addr constant [75 x i8] c"{params:384}{cache-size:0}{anchor-id:-1}{target-anchor:0}{type:0}{cycle:0}\00", section "llvm.metadata"

@bader bader marked this pull request as draft December 2, 2021 17:08
@github-actions github-actions bot added the Stale label Jun 1, 2022
pvchupin pushed a commit that referenced this pull request Jun 28, 2022
This is a continuation of @Fznamznon's PR #5002. Most of the changes here are from there.

According to #4980 this built-in
should take four more constant integer parameters with following default
values:

const int32_t AnchorID = -1
const int32_t TargetAnchor = 0
const int32_t Type = 0
const int32_t Cycle = 0
The old variant is still allowed for backward compatibility. In case
some parameters are not provided - default value will be emitted in
annotation string.

In addition to the state of PR #5002, this PR makes minor changes. It incorporates @mlychkov's
code review comments there and modifies the CodeGenSYCL test to accept both opaque and
non-opaque pointers.
@github-actions github-actions bot closed this Jul 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants