-
Notifications
You must be signed in to change notification settings - Fork 769
Implement sycl_khr_work_item_queries
extension
#18519
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
Open
0x12CC
wants to merge
2
commits into
intel:sycl
Choose a base branch
from
0x12CC:sycl_khr_work_item_queries
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.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,36 @@ | ||
//===-- work_item_queries.hpp --- KHR work item queries extension ---------===// | ||
// | ||
// 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 | ||
|
||
#ifdef __DPCPP_ENABLE_UNFINISHED_KHR_EXTENSIONS | ||
|
||
#include <sycl/ext/oneapi/free_function_queries.hpp> | ||
|
||
#define SYCL_KHR_WORK_ITEM_QUERIES 1 | ||
|
||
namespace sycl { | ||
inline namespace _V1 { | ||
namespace khr { | ||
|
||
template <int Dimensions> nd_item<Dimensions> this_nd_item() { | ||
return ext::oneapi::experimental::this_nd_item<Dimensions>(); | ||
} | ||
|
||
template <int Dimensions> group<Dimensions> this_group() { | ||
return ext::oneapi::this_work_item::get_work_group<Dimensions>(); | ||
} | ||
|
||
inline sub_group this_sub_group() { | ||
return ext::oneapi::this_work_item::get_sub_group(); | ||
} | ||
|
||
} // namespace khr | ||
} // namespace _V1 | ||
} // namespace sycl | ||
|
||
#endif |
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
99 changes: 99 additions & 0 deletions
99
sycl/test-e2e/Basic/work_item_queries/work_item_queries.cpp
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,99 @@ | ||||||||||||||||||||
// RUN: %{build} -o %t.out | ||||||||||||||||||||
// RUN: %{run} %t.out | ||||||||||||||||||||
|
||||||||||||||||||||
//===- work_item_queries.cpp - KHR work item queries test -----------------===// | ||||||||||||||||||||
// | ||||||||||||||||||||
// 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 | ||||||||||||||||||||
// | ||||||||||||||||||||
//===----------------------------------------------------------------------===// | ||||||||||||||||||||
|
||||||||||||||||||||
#define __DPCPP_ENABLE_UNFINISHED_KHR_EXTENSIONS | ||||||||||||||||||||
|
||||||||||||||||||||
#include <cassert> | ||||||||||||||||||||
#include <sycl/detail/core.hpp> | ||||||||||||||||||||
#include <sycl/khr/work_item_queries.hpp> | ||||||||||||||||||||
|
||||||||||||||||||||
template <size_t... Dims> static void check_this_nd_item_api() { | ||||||||||||||||||||
// Define the kernel ranges. | ||||||||||||||||||||
constexpr int Dimensions = sizeof...(Dims); | ||||||||||||||||||||
const sycl::range<Dimensions> local_range{Dims...}; | ||||||||||||||||||||
const sycl::range<Dimensions> global_range = local_range; | ||||||||||||||||||||
const sycl::nd_range<Dimensions> nd_range{global_range, local_range}; | ||||||||||||||||||||
// Launch an ND-range kernel. | ||||||||||||||||||||
sycl::queue q; | ||||||||||||||||||||
sycl::buffer<bool, Dimensions> results{global_range}; | ||||||||||||||||||||
q.submit([&](sycl::handler &cgh) { | ||||||||||||||||||||
sycl::accessor acc{results, cgh, sycl::write_only}; | ||||||||||||||||||||
cgh.parallel_for(nd_range, [=](sycl::nd_item<Dimensions> it) { | ||||||||||||||||||||
// Compare it to this_nd_item<Dimensions>(). | ||||||||||||||||||||
acc[it.get_global_id()] = (it == sycl::khr::this_nd_item<Dimensions>()); | ||||||||||||||||||||
}); | ||||||||||||||||||||
}); | ||||||||||||||||||||
// Check the test results. | ||||||||||||||||||||
sycl::host_accessor acc{results}; | ||||||||||||||||||||
for (const auto &result : acc) | ||||||||||||||||||||
assert(result); | ||||||||||||||||||||
Comment on lines
+36
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit; Asserts stop execution immediately, so personally I prefer to do something like:
Suggested change
and then in the main function you do: int Failed = 0;
// nd_item
Failed += check_this_nd_item_api<2>();
Failed += check_this_nd_item_api<2, 3>();
Failed += check_this_nd_item_api<2, 3, 4>();
// group
Failed += check_this_group_api<2>();
Failed += check_this_group_api<2, 3>();
Failed += check_this_group_api<2, 3, 4>();
// sub_group
Failed += check_this_sub_group_api<2>();
Failed += check_this_sub_group_api<2, 3>();
Failed += check_this_sub_group_api<2, 3, 4>();
return Failed; The more information, the better. |
||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
template <size_t... Dims> static void check_this_group_api() { | ||||||||||||||||||||
// Define the kernel ranges. | ||||||||||||||||||||
constexpr int Dimensions = sizeof...(Dims); | ||||||||||||||||||||
const sycl::range<Dimensions> local_range{Dims...}; | ||||||||||||||||||||
const sycl::range<Dimensions> global_range = local_range; | ||||||||||||||||||||
const sycl::nd_range<Dimensions> nd_range{global_range, local_range}; | ||||||||||||||||||||
// Launch an ND-range kernel. | ||||||||||||||||||||
sycl::queue q; | ||||||||||||||||||||
sycl::buffer<bool, Dimensions> results{global_range}; | ||||||||||||||||||||
q.submit([&](sycl::handler &cgh) { | ||||||||||||||||||||
sycl::accessor acc{results, cgh, sycl::write_only}; | ||||||||||||||||||||
cgh.parallel_for(nd_range, [=](sycl::nd_item<Dimensions> it) { | ||||||||||||||||||||
// Compare it.get_group() to this_group<Dimensions>(). | ||||||||||||||||||||
acc[it.get_global_id()] = | ||||||||||||||||||||
(it.get_group() == sycl::khr::this_group<Dimensions>()); | ||||||||||||||||||||
}); | ||||||||||||||||||||
}); | ||||||||||||||||||||
// Check the test results. | ||||||||||||||||||||
sycl::host_accessor acc{results}; | ||||||||||||||||||||
for (const auto &result : acc) | ||||||||||||||||||||
assert(result); | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
template <size_t... Dims> static void check_this_sub_group_api() { | ||||||||||||||||||||
// Define the kernel ranges. | ||||||||||||||||||||
constexpr int Dimensions = sizeof...(Dims); | ||||||||||||||||||||
const sycl::range<Dimensions> local_range{Dims...}; | ||||||||||||||||||||
const sycl::range<Dimensions> global_range = local_range; | ||||||||||||||||||||
const sycl::nd_range<Dimensions> nd_range{global_range, local_range}; | ||||||||||||||||||||
// Launch an ND-range kernel. | ||||||||||||||||||||
sycl::queue q; | ||||||||||||||||||||
sycl::buffer<bool, Dimensions> results{global_range}; | ||||||||||||||||||||
q.submit([&](sycl::handler &cgh) { | ||||||||||||||||||||
sycl::accessor acc{results, cgh, sycl::write_only}; | ||||||||||||||||||||
cgh.parallel_for(nd_range, [=](sycl::nd_item<Dimensions> it) { | ||||||||||||||||||||
// Compare it.get_sub_group() to this_sub_group(). | ||||||||||||||||||||
acc[it.get_global_id()] = | ||||||||||||||||||||
(it.get_sub_group() == sycl::khr::this_sub_group()); | ||||||||||||||||||||
}); | ||||||||||||||||||||
}); | ||||||||||||||||||||
// Check the test results. | ||||||||||||||||||||
sycl::host_accessor acc{results}; | ||||||||||||||||||||
for (const auto &result : acc) | ||||||||||||||||||||
assert(result); | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
int main() { | ||||||||||||||||||||
// nd_item | ||||||||||||||||||||
check_this_nd_item_api<2>(); | ||||||||||||||||||||
check_this_nd_item_api<2, 3>(); | ||||||||||||||||||||
check_this_nd_item_api<2, 3, 4>(); | ||||||||||||||||||||
// group | ||||||||||||||||||||
check_this_group_api<2>(); | ||||||||||||||||||||
check_this_group_api<2, 3>(); | ||||||||||||||||||||
check_this_group_api<2, 3, 4>(); | ||||||||||||||||||||
// sub_group | ||||||||||||||||||||
check_this_sub_group_api<2>(); | ||||||||||||||||||||
check_this_sub_group_api<2, 3>(); | ||||||||||||||||||||
check_this_sub_group_api<2, 3, 4>(); | ||||||||||||||||||||
} |
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 see this is how we do it in khr/group_interface.hpp too, but would it be more appropriate to guard the definition in sycl/source/feature_test.hpp.in together with all the other feature test macros?
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 agree on this because there are already two khr extension macros set within
sycl/source/feature_test.hpp.in