-
Notifications
You must be signed in to change notification settings - Fork 798
[SYCL] Add structure to pass references to ranges #19805
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
Draft
Alexandr-Konovalov
wants to merge
11
commits into
intel:sycl
Choose a base branch
from
Alexandr-Konovalov:Alexandr-Konovalov/ref-ndrange
base: sycl
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9571fec
[SYCL] Add structure to pass references to ranges
Alexandr-Konovalov 2521805
Fix formatting.
Alexandr-Konovalov 1a90e48
Fix const.
Alexandr-Konovalov 38945f3
Rename RangesRefT to ranges_ref_view and move to sycl::detail namespace.
Alexandr-Konovalov d4c267e
Fix formatting.
Alexandr-Konovalov 0d76be9
Move assignment near ctors.
Alexandr-Konovalov 858bf21
Decrease dumpilcation is the test.
Alexandr-Konovalov 95beb6a
Fix formatting.
Alexandr-Konovalov f2e347d
Fix formatting.
Alexandr-Konovalov 71e2eee
Add export to sycl::detail::NDRDescT.
Alexandr-Konovalov 7a3f269
Fix formatting.
Alexandr-Konovalov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//==---- ranges_ref_view.hpp --- SYCL iteration with reference to ranges ---==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
|
||
#include <sycl/nd_range.hpp> | ||
|
||
namespace sycl { | ||
inline namespace _V1 { | ||
namespace detail { | ||
|
||
class NDRDescT; | ||
|
||
// The structure to keep dimension and references to ranges unified for | ||
// all dimensions. | ||
class ranges_ref_view { | ||
|
||
public: | ||
ranges_ref_view() = default; | ||
ranges_ref_view(const ranges_ref_view &Desc) = default; | ||
ranges_ref_view(ranges_ref_view &&Desc) = default; | ||
ranges_ref_view &operator=(const ranges_ref_view &Desc) = default; | ||
ranges_ref_view &operator=(ranges_ref_view &&Desc) = default; | ||
|
||
template <int Dims_> | ||
ranges_ref_view(sycl::range<Dims_> &GlobalSizes, | ||
sycl::range<Dims_> &LocalSizes) | ||
: GlobalSize(&(GlobalSizes[0])), LocalSize(&(LocalSizes[0])), | ||
Dims{size_t(Dims_)} {} | ||
|
||
// to support usage in sycl::ext::oneapi::experimental::submit_with_event() | ||
template <int Dims_> | ||
ranges_ref_view(sycl::nd_range<Dims_> &ExecutionRange) | ||
: GlobalSize(&ExecutionRange.globalSize[0]), | ||
LocalSize(&ExecutionRange.localSize[0]), | ||
GlobalOffset(&ExecutionRange.offset[0]), Dims{size_t(Dims_)} {} | ||
|
||
template <int Dims_> | ||
ranges_ref_view(sycl::range<Dims_> &Range) | ||
: GlobalSize(&(Range[0])), Dims{size_t(Dims_)} {} | ||
|
||
sycl::detail::NDRDescT toNDRDescT() const; | ||
|
||
const size_t *GlobalSize = nullptr; | ||
const size_t *LocalSize = nullptr; | ||
const size_t *GlobalOffset = nullptr; | ||
size_t Dims = 0; | ||
}; | ||
|
||
} // namespace detail | ||
} // namespace _V1 | ||
} // namespace sycl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
//==---- RangesRefViewUsage.cpp --- Check ranges_ref_view ------------------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#include <detail/cg.hpp> | ||
#include <sycl/detail/ranges_ref_view.hpp> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
template <int dims> | ||
void TestNDRangesRefView(sycl::range<dims> global, sycl::range<dims> local, | ||
sycl::id<dims> offset) { | ||
{ | ||
sycl::nd_range<dims> nd_range{global, local, offset}; | ||
sycl::detail::ranges_ref_view r{nd_range}; | ||
ASSERT_EQ(r.Dims, size_t{dims}); | ||
for (int d = 0; d < dims; d++) { | ||
ASSERT_EQ(r.GlobalSize[d], global[d]); | ||
ASSERT_EQ(r.LocalSize[d], local[d]); | ||
ASSERT_EQ(r.GlobalOffset[d], offset[d]); | ||
} | ||
|
||
sycl::detail::NDRDescT NDRDesc = r.toNDRDescT(); | ||
ASSERT_EQ(NDRDesc.Dims, size_t{dims}); | ||
for (int d = 0; d < dims; d++) { | ||
ASSERT_EQ(NDRDesc.GlobalSize[d], global[d]); | ||
ASSERT_EQ(NDRDesc.LocalSize[d], local[d]); | ||
ASSERT_EQ(NDRDesc.GlobalOffset[d], offset[d]); | ||
} | ||
} | ||
{ | ||
sycl::detail::ranges_ref_view r{global, local}; | ||
ASSERT_EQ(r.Dims, size_t{dims}); | ||
for (int d = 0; d < dims; d++) { | ||
ASSERT_EQ(r.GlobalSize[d], global[d]); | ||
ASSERT_EQ(r.LocalSize[d], local[d]); | ||
} | ||
ASSERT_EQ(r.GlobalOffset, nullptr); | ||
|
||
sycl::detail::NDRDescT NDRDesc = r.toNDRDescT(); | ||
ASSERT_EQ(NDRDesc.Dims, size_t{dims}); | ||
for (int d = 0; d < dims; d++) { | ||
ASSERT_EQ(NDRDesc.GlobalSize[d], global[d]); | ||
ASSERT_EQ(NDRDesc.LocalSize[d], local[d]); | ||
} | ||
for (int d = dims; d < 3; d++) { | ||
ASSERT_EQ(NDRDesc.GlobalSize[d], 0UL); | ||
ASSERT_EQ(NDRDesc.LocalSize[d], 0UL); | ||
} | ||
for (int d = 0; d < 3; d++) { | ||
ASSERT_EQ(NDRDesc.GlobalOffset[d], 0UL); | ||
} | ||
} | ||
{ | ||
sycl::detail::ranges_ref_view r{global}; | ||
ASSERT_EQ(r.Dims, size_t{dims}); | ||
for (int d = 0; d < dims; d++) { | ||
ASSERT_EQ(r.GlobalSize[d], global[d]); | ||
} | ||
ASSERT_EQ(r.LocalSize, nullptr); | ||
ASSERT_EQ(r.GlobalOffset, nullptr); | ||
|
||
sycl::detail::NDRDescT NDRDesc = r.toNDRDescT(); | ||
ASSERT_EQ(NDRDesc.Dims, size_t{dims}); | ||
for (int d = 0; d < dims; d++) { | ||
ASSERT_EQ(NDRDesc.GlobalSize[d], global[d]); | ||
} | ||
for (int d = dims; d < 3; d++) { | ||
ASSERT_EQ(NDRDesc.GlobalSize[d], 0UL); | ||
} | ||
for (int d = 0; d < 3; d++) { | ||
ASSERT_EQ(NDRDesc.LocalSize[d], 0UL); | ||
ASSERT_EQ(NDRDesc.GlobalOffset[d], 0UL); | ||
} | ||
} | ||
} | ||
|
||
TEST(RangesRefUsage, RangesRefUsage) { | ||
TestNDRangesRefView(sycl::range<1>{1024}, sycl::range<1>{64}, | ||
sycl::id<1>{10}); | ||
TestNDRangesRefView(sycl::range<2>{1024, 512}, sycl::range<2>{64, 32}, | ||
sycl::id<2>{10, 5}); | ||
TestNDRangesRefView(sycl::range<3>{1024, 512, 256}, | ||
sycl::range<3>{64, 32, 16}, sycl::id<3>{10, 5, 2}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 am not sure that it is the best name. We have
sycl::range
and someone might assume thatranges_ref_view
is a view to thesycl::range
. Also it is not lear what_ref_
means in the name. Why not justnd_range_view
?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.
View has strong connotation to views from C++20, that may be or may be not good.
Alternatively, it can be
nd_range_ref
. I don't know.That's for "reference", I hope.