Skip to content

[SYCL] Reject zero length arrays #1153

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 19 commits into from
Mar 3, 2020
Merged

[SYCL] Reject zero length arrays #1153

merged 19 commits into from
Mar 3, 2020

Conversation

cperkinsintel
Copy link
Contributor

This moves this work so it originates from a private fork. Also incorporated in the feedback.

zero length arrays in SYCL kernels are not allowed. Adding code to issue a deferred diagnostic error.

Signed-off-by: Chris Perkins [email protected]

@bader bader changed the title [SYCL] reject zero length arrays [SYCL] Reject zero length arrays Feb 21, 2020
cperkinsintel and others added 4 commits February 21, 2020 12:00
Signed-off-by: Chris Perkins <[email protected]>
Co-Authored-By: Mariya Podchishchaeva <[email protected]>
Signed-off-by: Chris Perkins <[email protected]>
Co-Authored-By: Mariya Podchishchaeva <[email protected]>
Signed-off-by: Chris Perkins <[email protected]>

Co-Authored-By: Alexey Bader <[email protected]>
@bader
Copy link
Contributor

bader commented Feb 22, 2020

@cperkinsintel, please, fix LIT test failures.
@erichkeane, @Fznamznon, please, take a look at unresolved comments.


// --- lambda in specialized function testing ---

//array A is only used to feed the template
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this array A is needed at all?
The problem with diagnostics appears only if single_task function is called from a template 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.

Correct. The diagnostics do not emit if the lambda that contains the violations appears in a templated function. So I'm just using the array to specialize the template.

// expected-error@+1 {{__float128 is not supported on this target}}
__float128 malFloat = 40;

// not sure if 'no virtual function' is a _deferred_ diagnostic, testing anyway
Copy link
Contributor

Choose a reason for hiding this comment

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

What exactly do you mean here?
BTW, we diagnose only usages of virtual functions, as SYCL spec requires. Using of classes with virtual functions is not prohibited.

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 am not sure if this particular violation ( a virtual function in SYCL context ) results in a deferred diagnostic, as opposed to an immediate diagnostic. @erichkeane added it to one of the files when he was working on reducing the problem. So I kept it in 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.

AFAIK we diagnose virtual functions usage through SemaSYCL callgraph traversing. See

<< Sema::KernelCallVirtualFunction;
. But, I suppose, we will move this to Sema and deferred diagnostics.

But we already diagnose variadic function calls through deferred diagnostic, I remember patch from Erich doing this #998 .
So If here you are trying to check only deferred diagnostics, I suggest switch from virtual functions to variadic functions.

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 switched to variadic.


deviceQueue.submit([&](cl::sycl::handler &cgh) {

cgh.single_task<class AName>([=]() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Fznamznon
Can you help with with this test? I have one last "note" I need to suppress.

When running llvm-lit -v deferred-diagnostics-emit.cpp I get this:

error: 'note' diagnostics seen but not expected: 
  File /iusers/cperkins/sycl_workspace/llvm/clang/test/SemaSYCL/Inputs/sycl.hpp Line 182: called by 'kernel_single_task<AName, (lambda at /iusers/cperkins/sycl_workspace/llvm/clang/test/SemaSYCL/deferred-diagnostics-emit.cpp:61:34)>'
  File /iusers/cperkins/sycl_workspace/llvm/clang/test/SemaSYCL/Inputs/sycl.hpp Line 182: called by 'kernel_single_task<AName, (lambda at /iusers/cperkins/sycl_workspace/llvm/clang/test/SemaSYCL/deferred-diagnostics-emit.cpp:61:34)>'

So it looks like I should add this expectation:

// expected-note@+1 2{{called by 'kernel_single_task<AName, (lambda}}

But no matter where I put that expectation it never works. First it tells me it expected the note but didn't see it, then it says it saw the note without expecting it. Awesome.

error: 'note' diagnostics expected but not seen: 
  File /iusers/cperkins/sycl_workspace/llvm/clang/test/SemaSYCL/deferred-diagnostics-emit.cpp Line 61 (directive at /iusers/cperkins/sycl_workspace/llvm/clang/test/SemaSYCL/deferred-diagnostics-emit.cpp:60): called by 'kernel_single_task<AName, (lambda
  File /iusers/cperkins/sycl_workspace/llvm/clang/test/SemaSYCL/deferred-diagnostics-emit.cpp Line 61 (directive at /iusers/cperkins/sycl_workspace/llvm/clang/test/SemaSYCL/deferred-diagnostics-emit.cpp:60): called by 'kernel_single_task<AName, (lambda
error: 'note' diagnostics seen but not expected: 
  File /iusers/cperkins/sycl_workspace/llvm/clang/test/SemaSYCL/Inputs/sycl.hpp Line 182: called by 'kernel_single_task<AName, (lambda at /iusers/cperkins/sycl_workspace/llvm/clang/test/SemaSYCL/deferred-diagnostics-emit.cpp:61:34)>'
  File /iusers/cperkins/sycl_workspace/llvm/clang/test/SemaSYCL/Inputs/sycl.hpp Line 182: called by 'kernel_single_task<AName, (lambda at /iusers/cperkins/sycl_workspace/llvm/clang/test/SemaSYCL/deferred-diagnostics-emit.cpp:61:34)>'

Is the expectation correct? I haven't been able to find docs for them, so I'm just cribbing from other places.

I tried putting the expectation at line 58, line 60, in the argument list of cgh.single_task so at to precede the lambda, line 62, line 76, etc. But nothing works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a compiler flag to suppress the notes?

Copy link
Contributor

Choose a reason for hiding this comment

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

First, I don't think that we should suppress notes in tests.
Second, I see what happens. You are trying to add note expectation to wrong place.
See logs, the emitted note points to function named kernel_single_task and it's defined in file test/SemaSYCL/Inputs/sycl.hpp on line 182.
By the construction like // expected-note@+1 2{{called by 'kernel_single_task<AName, (lambda}} in test/SemaSYCL/deferred-diagnostics-emit.cpp file on line 60 means that you expect 2 same notes with this text in this file on line 61.
The trick here that you use single_task function from our fake sycl runtime, and kernel_single_task call happens inside it. I'm not sure that I know how to expect notes from other file (maybe @erichkeane knows). As a fix you can declare your own kernel_single_task function in your test file and note expectation will point to correct file.

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 re-introduced the bespoke SYCL namespace code into the test and put the expectation into it. Now the llvm-lit passes and the test correctly stresses the namespace aspect we require.

Signed-off-by: Chris Perkins <[email protected]>
Signed-off-by: Chris Perkins <[email protected]>
Signed-off-by: Chris Perkins <[email protected]>
Signed-off-by: Chris Perkins <[email protected]>
Comment on lines 8 to 18
class queue {
public:
template <typename T>
void submit(T CGF) {}
};

template <int I>
class id {};

template <int I>
class range {};
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not see the purpose of defining these classes, it is unnecessary and makes test fat. Can we just use one function with sycl_kernel attribute? Only this is needed to show the compiler where the device code starts from.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Fznamznon
We cannot just throw the sycl_kernel attribute on a function like we do in some of the other tests - what we are looking for, specifically, is that the deferred diagnostics are working with namespaces.
Remember, there is that overhaul of the deferred diagnostic system which was merged and then backed out - that overhaul passed all existing tests but yet caused all of our SYCL deferred diagnostics to suddenly not work. The purpose of this deferred-diagnostics-emit.cpp is to provide defensive testing that will fail if that overhaul makes the same mistake and is later re-introduced. This code you are identifying came from the case where we isolated the problem when used against that overhaul. It has been confirmed against that. Before I can change it, I'll have to reconfirm.

This PR has been open for over a week now, and is really quite small. This particular test file is defensive. I would prefer that we merge it because we all have other things demanding our attention. I can look into trimming this side test file, if you insist, but my preference is to merge this PR rather than having it languish another week. Let me know.

Copy link
Contributor

Choose a reason for hiding this comment

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

I understand that you want to capture some problems and we won't forget about them, I appreciate it. But all that I'm asking is reduce the test case to have minimal reproducer for our problems. You want capture that we have problems with namespaces - use namespaces, instead of adding not necessary stuff. All these classes will appear in AST dumps for module and will make debugging harder.
BTW. We have tons of ugly/bad/unnecessary changes in SYCL just because someone was running out of time. So the fact that it's "long conversation"/"we don't have time", "someone very needed to merge it yesterday" etc, won't force me to give approve for the patch if this patch doesn't fix crash which happens in the compiler on every second code sample.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

Signed-off-by: Chris Perkins <[email protected]>
Signed-off-by: Chris Perkins <[email protected]>
@cperkinsintel
Copy link
Contributor Author

ping @Fznamznon - I think I have addressed everything you brought up when reviewing this PR. It should be ready to be approved and merged. Let me know if not.

@romanovvlad
Copy link
Contributor

@bader @erichkeane Could you please finish review?

@erichkeane
Copy link
Contributor

I was OK with it a while ago, Up to @Fznamznon as far as I'm concerned.

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.

Spent a while looking at this based on @Fznamznon 's comments, and I think this covers it.

@cperkinsintel
Copy link
Contributor Author

@erichkeane - thanks! I think you'll have to merge it as well, as I don't have authorization for that.

@erichkeane
Copy link
Contributor

@bader is the only one I know of that can merge anything, I also lack permissions to do so.

@bader bader merged commit e6ce614 into intel:sycl Mar 3, 2020
alexbatashev pushed a commit to alexbatashev/llvm that referenced this pull request Mar 4, 2020
…ctor_tests

* origin/sycl: (32 commits)
  [SYCL] Fix circular reference between events and queues (intel#1226)
  [CI][Doc] Use SSH to deploy GitHub Pages (intel#1232)
  [SYCL][CUDA][Test] Testing for use of CUDA primary context (intel#1174)
  [SYCL] allow underscore symbol in temporary directory name
  [SYCL] Reject zero length arrays (intel#1153)
  [SYCL] Fix static code analyzis concerns (intel#1189)
  [SYCL] Add more details about the -fintelfpga option (intel#1218)
  [SYCL][CUDA] Select only NVPTX64 device binaries (intel#1223)
  [SYCL] Reverse max work-group size order (intel#1177)
  [SYCL][Doc] Add GroupAlgorithms extension (intel#1079)
  [SYCL] Fix SYCL internal enumerators conflict with user defined macro (intel#1188)
  [SYCL][CUDA] Fixes context release and unnamed context scope (intel#1207)
  [SYCL][CUDA] Fix context creation property parsing
  [CUDA][PI] clang-format pi.h
  [SYCL][CUDA] Handle the case of not having any CUDA device (intel#1212)
  [SYCL] Fix check-sycl-deploy target problems (intel#1165)
  [SYCL] Disable tests which take more than 5 minutes (intel#1220)
  [SYCL] Make context constructors explicit to avoid unintended conversions (intel#1219)
  [SYCL][NFC] Add clang-format configuration file for SYCL LIT tests (intel#1224)
  [SYCL] Fix command cleanup invoked from multiple threads (intel#1214)
  ...
alexbatashev pushed a commit to alexbatashev/llvm that referenced this pull request Mar 5, 2020
…_accessor_refactor

* origin/sycl: (38 commits)
  [SYCL] Fix device::get_devices() with a non-host device type (intel#1235)
  [SYCL][PI][CUDA] Implement kernel and kernel-group information queries (intel#1180)
  [SYCL] Remove default error code value in exception (intel#1150)
  [SYCL] Fix devicelib assert LIT test (intel#1245)
  [SYCL] Set aux-target-cpu for SYCL offload device compilation (intel#1225)
  [SYCL] Remove fabs and ceil from the list of unsupported math functions (intel#1217)
  [SYCL] Fix circular reference between events and queues (intel#1226)
  [CI][Doc] Use SSH to deploy GitHub Pages (intel#1232)
  [SYCL][CUDA][Test] Testing for use of CUDA primary context (intel#1174)
  [SYCL] allow underscore symbol in temporary directory name
  [SYCL] Reject zero length arrays (intel#1153)
  [SYCL] Fix static code analyzis concerns (intel#1189)
  [SYCL] Add more details about the -fintelfpga option (intel#1218)
  [SYCL][CUDA] Select only NVPTX64 device binaries (intel#1223)
  [SYCL] Reverse max work-group size order (intel#1177)
  [SYCL][Doc] Add GroupAlgorithms extension (intel#1079)
  [SYCL] Fix SYCL internal enumerators conflict with user defined macro (intel#1188)
  [SYCL][CUDA] Fixes context release and unnamed context scope (intel#1207)
  [SYCL][CUDA] Fix context creation property parsing
  [CUDA][PI] clang-format pi.h
  ...
vmaksimo pushed a commit to vmaksimo/llvm that referenced this pull request Aug 23, 2021
* Update SPIR-V friendly IR doc according to recent changes

KhronosGroup/SPIRV-LLVM-Translator#1133 added
full support for SPIR-V friendly IR with SPIR-V built-in variables
mapped to calls. This commit adds info to the doc about the new supported
representation.

* Apply suggestions from code review

Co-authored-by: Dmitry Sidorov <[email protected]>

Co-authored-by: Dmitry Sidorov <[email protected]>

Original commit:
KhronosGroup/SPIRV-LLVM-Translator@168cb23
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