Skip to content

[SYCL][ESIMD] Implement "private globals" (file scope private vars) in FE #1756

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 4 commits into from
Jun 9, 2020

Conversation

kbobrovs
Copy link
Contributor

REVIEW ONLY THE LAST COMMIT

"private globals" are essentially private variables in a global scope.
Marked with attribute((opencl_private)). Additionally can be
marked with attribute((register_num(n))) to bind to a specific register.

Signed-off-by: Konstantin S Bobrovsky konstantin.s.bobrovsky@intel.com

@@ -3872,6 +3872,13 @@ LangAS CodeGenModule::GetGlobalVarAddressSpace(const VarDecl *D) {
if (!D || D->getType().getAddressSpace() == LangAS::Default) {
return LangAS::opencl_global;
}
if (D)
Copy link
Contributor

Choose a reason for hiding this comment

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

What cases exist where the VarDecl is null?

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 don't know. Following the above if (!D ||...) style

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this one is removed entirely

@@ -12562,6 +12562,14 @@ void Sema::ActOnUninitializedDecl(Decl *RealDecl) {
if (getLangOpts().OpenCL &&
Var->getType().getAddressSpace() == LangAS::opencl_local)
return;
// In SYCL ESIMD device code non-constant file scope variables can't be
// initialized.
// TODO add proper diagnostics for both SYCL and OpenCL paths
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like a good opportunity to just diagnose these.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you suggesting to implement the check with this PR?
It will take time that I don't have at this point, hence TODO. This is a big feature with a number of gaps which will be addressed incrementally over time.

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 this would have to happen to unblock this PR. The feature is not complete/ready for merge until you've done your proper semantic analysis.

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 will try.
Looks like OpenCL right above is not complete/ready too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update: this code is engaged only for implicit initialization, which shouldn't happen for private globals neither, so I just return skipping implicit initialization code creation (as OpenCL does). The check for explicit initialization is added elsewhere in SemaDecl.cpp, plus a test.

<< AL << 0;
return;
}
assert(AL.getNumArgs() == 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you have a test to make sure that this assert isn't hit when providing more args? A number of functions here check to make sure they have the right number of args.

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 don't have a test. Is there a policy that each assert should have a test?

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, you're doing something significantly different from what every other diagnostic happens. I presumed you thought the assert was safe (rather than checking that you have the correct number of args like everyone else here), so I wanted you to confirm it with a 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.

OK, I see your point now. I will change the assert to compiler check with diagnostics and add a negative test.

// Marks functions which must not be vectorized via horizontal SIMT widening,
// e.g. because the function is already vectorized. Used to mark SYCL
// explicit SIMD kernels and functions.
def SYCLSimd : InheritableAttr {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wow, I have seen this attribute in the previous patch.
Should It really be here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right, it should not.

def SYCLSimd : InheritableAttr {
let Spellings = [GNU<"sycl_explicit_simd">];
let Subjects = SubjectList<[Function]>;
let LangOpts = [SYCLIsDevice];
Copy link
Contributor

@Fznamznon Fznamznon May 26, 2020

Choose a reason for hiding this comment

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

But I just realized, should LangOpts value be SYCLExplicitSIMD instead of SYCLIsDevice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right

Comment on lines 3877 to 3881
if (AddrSpace == LangAS::opencl_private ||
AddrSpace == LangAS::opencl_local)
// SYCL explicit SIMD path: recognize globals in private or local address
// space.
return AddrSpace;
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't have a check in codegen test that these address spaces are actually preserved and not replaced with something else by return getTargetCodeGenInfo().getGlobalVarAddressSpace(*this, D);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why would I need that test?

Copy link
Contributor

Choose a reason for hiding this comment

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

Apparently, you need this particular change here which changes an address space of some variables. However, I don't see any tests that check for particular address space

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DenisBakhvalov agreed to help here with the test

Copy link
Contributor

Choose a reason for hiding this comment

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

Apparently, we found that this check is not needed anymore. Removed.

@kbobrovs
Copy link
Contributor Author

@erichkeane, @Fznamznon, @AlexeySachkov - ping

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.

I don't have objections, but I'd like @AlexeySachkov to approve first.

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.

Did my run-through, but @AlexeySachkov and @Fznamznon should both look at this and be familiar with it as well.

// expected-error@+1{{'register_num' attribute takes one argument}}
__attribute__((opencl_private)) __attribute__((register_num(10, 11))) int privGlob2;

// expected-error@+1{{(SYCL explicit SIMD) private global variable cannot have an initializer}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is SYCL explicit SIMD in parens in this message? It likely should be just SYCL Explicit SIMD private global....

Copy link
Contributor Author

@kbobrovs kbobrovs May 29, 2020

Choose a reason for hiding this comment

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

This designates the special mode. I expect there will be other messages tagged similarly, where absence of braces won't make sense.

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 don't get it? We don't have anything like that elsewhere in the compiler, so this would be a completely new designation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My point is that we'll likely have more of these. This is not adjective to "private global" but the "explicit SIMD" mode tag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SYCL explicit SIMD does not permit private global variable to have an initializer

Copy link
Contributor

Choose a reason for hiding this comment

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

We discussed a reword of this error message on the call, it seems it hasn't happened yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, overlooked this one

@kbobrovs kbobrovs requested a review from erichkeane May 29, 2020 21:17
kbobrovs added 2 commits June 5, 2020 19:32
…n Front End.

"private globals" are essentially private variables in a global scope.
Marked with __attribute__((opencl_private)). Additionally can be
marked with __attribute__((register_num(n))) to bind to a specific register.

Signed-off-by: Konstantin S Bobrovsky <konstantin.s.bobrovsky@intel.com>
- Better checking and diagnostics
- More tests

Signed-off-by: Konstantin S Bobrovsky <konstantin.s.bobrovsky@intel.com>
Signed-off-by: Konstantin S Bobrovsky <konstantin.s.bobrovsky@intel.com>
@kbobrovs
Copy link
Contributor Author

kbobrovs commented Jun 8, 2020

@AlexeySachkov, please take a look/approve.

Signed-off-by: Konstantin S Bobrovsky <konstantin.s.bobrovsky@intel.com>
@intel intel deleted a comment from kbobrovs Jun 9, 2020
@pvchupin pvchupin merged commit bba5911 into intel:sycl Jun 9, 2020
alexbatashev pushed a commit to alexbatashev/llvm that referenced this pull request Jun 10, 2020
* upstream/sycl:
  [SYCL] Fix broken build after introduction USM to ocl headers (intel#1852)
  [SYCL][ESIMD] Implement "private globals" (file scope private vars)  in FE (intel#1756)
  [SYCL] Introduce interop handle for host task (intel#1747)
@kbobrovs kbobrovs deleted the esimd-glob branch July 30, 2020 12:30
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.

6 participants