-
Notifications
You must be signed in to change notification settings - Fork 769
[SYCL] Refactor stream class handing implementation #3646
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
Signed-off-by: Zahira Ammarguellat <zahira.ammarguellat@intel.com>
Signed-off-by: Zahira Ammarguellat <zahira.ammarguellat@intel.com>
Signed-off-by: Zahira Ammarguellat <zahira.ammarguellat@intel.com>
Signed-off-by: Zahira Ammarguellat <zahira.ammarguellat@intel.com>
FWIW, I don't feel particularly qualified to review this, so I'd recommend adding @elizabethandrews and @premanandrao as reviewers as well. |
@erichkeane, @Fznamznon, FYI. |
This is not quite working yet (draft)! I am still in the process of understanding the code. |
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.
From a quick look, FE changes look like it is heading in right direction. I haven't looked at the new stream implementation in headers. I suspect you also need to change AST tests with streams in them, since the InitListExpr generated now will be different. If these tests don't exist please add one to ensure AST generated for OpenCL kernel with streams is correct.
@AaronBallman the gist of this change is - stream was defined as a class holding accessors (@zahiraam please correct me if my memory serves me wrong). In SemaSYCL, we used to 'process' the stream class as a whole, and then step into this class to process each accessor individually. This change is introducing a __init( ) method in stream definition which makes it unnecessary to step into stream class and process its individual fields. We can now just call the __init( ) method to handle stream arguments like we do with other special types. |
Signed-off-by: Zahira Ammarguellat <zahira.ammarguellat@intel.com>
Signed-off-by: Zahira Ammarguellat <zahira.ammarguellat@intel.com>
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.
Always nice to simplify the code.
Perhaps the PR title should summarize more what is done in the PR?
Just curious: is it possible to have a stream to be hidden in some class, say a std::tuple
in some application using meta-programming and the stream work if the object is capture by the kernel lambda?
Signed-off-by: Zahira Ammarguellat <zahira.ammarguellat@intel.com>
@Fznamznon, @elizabethandrews This is not quite complete. But before going further (stream class LIT test needs editing) I want to make sure that this is moving in the right direction. Previously, the __init and __finalize of the fields were generated together, now each field has an __init and __finalize back to back. Is that correct? Did I put the createSpecialMethodCall with the finalize argument in the right place? |
Also should I add documentation only of a description of the init/finalize function creation in the AST or should it be a complete description as it is in #2091 ? Not sure if the work in this PR is already up-streamed? |
@keryell Thanks for the feedback. Let me know if the description is up to your expectations. |
Signed-off-by: Zahira Ammarguellat <zahira.ammarguellat@intel.com>
Sure! int main() {
std::tuple<sycl::stream> in_lambda { {0, 0, H} };
myQueue.submit([&](sycl::handler &h) {
h.single_task([=] {
std::get<0>(in_lambda).use();
});
});
return 0;
} just work? |
Signed-off-by: Zahira Ammarguellat <zahira.ammarguellat@intel.com>
Signed-off-by: Zahira Ammarguellat <zahira.ammarguellat@intel.com>
Signed-off-by: Zahira Ammarguellat <zahira.ammarguellat@intel.com>
@premanandrao, @againull Review please. Thanks. |
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.
In handleSyclStreamType
for SyclOptReportCreator
, there is a comment which can be removed with this change. Can you do that in this PR?
clang/test/CodeGenSYCL/stream.cpp
Outdated
// CHECK-SAME: %[[ID_TYPE]]* byval(%[[ID_TYPE]]) align 4 [[ACC_ID:%[a-zA-Z0-9_]+]], | ||
// CHECK-SAME: i32 [[ACC_INT:%[a-zA-Z0-9_]+]]) | ||
|
||
// CHECK: call spir_func void @{{.*}}__init{{.*}}(%{{.*}}cl::sycl::stream{{.*}} addrspace(4)* align 4 dereferenceable_or_null(16) %4, i8 addrspace(1)* %5, %[[RANGE_TYPE]]* byval(%[[RANGE_TYPE]]) {{.*}}%{{.*}} |
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.
%5
here is ACC_DATA
right? Since the parameters to __init
is important here, I think it will be useful to check it in this test (as opposed to just checking the call to __init
).
Signed-off-by: Zahira Ammarguellat <zahira.ammarguellat@intel.com>
/summary:run |
Signed-off-by: Zahira Ammarguellat <zahira.ammarguellat@intel.com>
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.
LGTM! Thanks!
@againull, @intel/llvm-reviewers-runtime, 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.
Thank you! LGTM
* sycl: (320 commits) [SYCL] Silence a "local variable is initialized but not referenced" warning; NFC (intel#3870) [SYCL] Improve SYCL_DEVICE_ALLOWLIST (intel#3826) [SPIR-V] Change return value of mapType function (intel#3871) [SYCL] Fix post-commit failure in handler.hpp from unused-parameters. (intel#3874) [Driver][SYCL] Do not imply defaultlib msvcrt for Linux based driver on Windows (intel#3827) [SYCL] Unique stable name rebase (intel#3835) [SYCL] Align behavior of empty command groups with SYCL2020 (intel#3822) [SYCL][ESIMD] Make typenames and constants consistent with SYCL API style. (intel#3850) [SYCL] Allow __failed_assertion to support libstdc++-11 (intel#3774) [SYCL] Refactor stream class handing implementation (intel#3646) [SYCL] Fix syntax error introduced in intel#3401 (intel#3861) [SYCL] SYCL 2020 sub_group algorithms (intel#3786) [Buildbot][NFC] Add option to use LLD as linker (intel#3866) Revert "Emit correct location lists with basic block sections." [SPIRITTAnnotations] Fix debug info for ITT calls. (intel#3829) [SYCL][Doc] Fix build of Sphinx docs (intel#3863) [SYCL][FPGA][NFC] Tidy up intel_fpga_reg codegen test (intel#3810) [CODEOWNERS] Fix SPIRITTAnnnotations tests ownership (intel#3859) [SYCL][ESIMD] Host-compile simd.cpp test, fix errors & warnings. (intel#3846) [SYCL] Store pointers to memory allocations instead of iterators (intel#3860) ...
Currently the stream class when passed from host to device requires additional handling.
It is handled as a wrapper struct for several accessors. In order to create the AST, the stream class is processed as a whole and each accessor is processed individually.
This patch is to simplify the process. An __init and __finalize methods are introduced that eliminate the need to process the field individually. The steps are as follows:
For this simple stream class:
sycl::handler H;
struct HasStreams {
// stream(totalBufferSize, workItemBufferSize, handler)
sycl::stream s1{0, 0, H};
};
int main() {
sycl::stream in_lambda{0, 0, H};
myQueue.submit([&](sycl::handler &h) {
h.single_task(= {
in_lambda.use();
});
});
return 0;
}
This is the resulting AST:
// Function Declaration
// CHECK: FunctionDecl {{.}}stream_test{{.}}
// CHECK: InitListExpr {{.}} '(lambda at
// CHECK-NEXT: CXXConstructExpr {{.}} 'sycl::stream':'sycl::stream' 'void () noexcept'
// CHECK: CXXMemberCallExpr {{.}} 'void'
// CHECK-NEXT: MemberExpr {{.}} 'void (__global char , range<1>, range<1>, id<1>, int)' lvalue .__init
// CHECK-NEXT: MemberExpr {{.}} 'sycl::stream':'sycl::stream' lvalue .
// CHECK-NEXT: DeclRefExpr {{.}} '(lambda at
// CHECK-NEXT: ImplicitCastExpr {{.}} '__global char '
// CHECK-NEXT: DeclRefExpr {{.}} '__global char *' lvalue ParmVar
// CHECK: CXXMemberCallExpr {{.}} 'void'
// CHECK-NEXT: MemberExpr {{.}} 'void ()' lvalue .__finalize
// CHECK-NEXT: MemberExpr {{.}} 'sycl::stream':'sycl::stream' lvalue .
// CHECK-NEXT: DeclRefExpr {{.}} '(lambda at