-
Notifications
You must be signed in to change notification settings - Fork 769
[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
Conversation
clang/lib/CodeGen/CodeGenModule.cpp
Outdated
@@ -3872,6 +3872,13 @@ LangAS CodeGenModule::GetGlobalVarAddressSpace(const VarDecl *D) { | |||
if (!D || D->getType().getAddressSpace() == LangAS::Default) { | |||
return LangAS::opencl_global; | |||
} | |||
if (D) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
clang/lib/Sema/SemaDecl.cpp
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
clang/lib/Sema/SemaDeclAttr.cpp
Outdated
<< AL << 0; | ||
return; | ||
} | ||
assert(AL.getNumArgs() == 1); |
There was a problem hiding this comment.
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.
There was a problem hiding this 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 a test. Is there a policy that each assert should have a test?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
clang/include/clang/Basic/Attr.td
Outdated
// 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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, it should not.
clang/include/clang/Basic/Attr.td
Outdated
def SYCLSimd : InheritableAttr { | ||
let Spellings = [GNU<"sycl_explicit_simd">]; | ||
let Subjects = SubjectList<[Function]>; | ||
let LangOpts = [SYCLIsDevice]; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right
clang/lib/CodeGen/CodeGenModule.cpp
Outdated
if (AddrSpace == LangAS::opencl_private || | ||
AddrSpace == LangAS::opencl_local) | ||
// SYCL explicit SIMD path: recognize globals in private or local address | ||
// space. | ||
return AddrSpace; |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
@erichkeane, @Fznamznon, @AlexeySachkov - ping |
There was a problem hiding this 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.
There was a problem hiding this 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}} |
There was a problem hiding this comment.
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....
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, overlooked this one
…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>
@AlexeySachkov, please take a look/approve. |
Signed-off-by: Konstantin S Bobrovsky <konstantin.s.bobrovsky@intel.com>
* 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)
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