-
Notifications
You must be signed in to change notification settings - Fork 6
Implement SYCL_KHR_WORK_ITEM_QUERIES #47
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
PeterTh
wants to merge
4
commits into
master
Choose a base branch
from
khr_work_item_queries
base: master
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
4 commits
Select commit
Hold shift + click to select a range
9342b37
Implement SYCL_KHR_WORK_ITEM_QUERIES
PeterTh c0d3e83
Work item queries: use thread locals, some refactoring
PeterTh 3b5ae85
Add error reporting unit test for SYCL_KHR_WORK_ITEM_QUERIES
PeterTh 81e0323
Actually set the wi query feature test macro (and test that)
PeterTh 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
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
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,50 @@ | ||
#include "simsycl/sycl/group.hh" | ||
#include "simsycl/sycl/nd_item.hh" | ||
#include "simsycl/sycl/sub_group.hh" | ||
|
||
#if SIMSYCL_ENABLE_SYCL_KHR_WORK_ITEM_QUERIES | ||
#define SYCL_KHR_WORK_ITEM_QUERIES 1 | ||
#endif // SIMSYCL_ENABLE_SYCL_KHR_WORK_ITEM_QUERIES | ||
|
||
namespace simsycl::sycl::khr { | ||
|
||
#if SIMSYCL_ENABLE_SYCL_KHR_WORK_ITEM_QUERIES | ||
|
||
namespace detail { | ||
template<int Dimensions> | ||
thread_local std::optional<simsycl::sycl::nd_item<Dimensions>> g_khr_wi_query_this_nd_item; | ||
|
||
template<int Dimensions> | ||
thread_local std::optional<simsycl::sycl::group<Dimensions>> g_khr_wi_query_this_group; | ||
|
||
inline thread_local std::optional<simsycl::sycl::sub_group> g_khr_wi_query_this_sub_group; | ||
|
||
inline void khr_wi_query_check(bool val, [[maybe_unused]] const char *query_name) { | ||
SIMSYCL_CHECK_MSG(val, | ||
"Work item query state '%s' is not available.\n" | ||
"Make sure that the query originated from a kernel launched with a sycl::nd_range argument", | ||
query_name); | ||
} | ||
|
||
} // namespace detail | ||
|
||
template<int Dimensions> | ||
simsycl::sycl::nd_item<Dimensions> this_nd_item() { | ||
detail::khr_wi_query_check(detail::g_khr_wi_query_this_nd_item<Dimensions>.has_value(), "this_nd_item"); | ||
return detail::g_khr_wi_query_this_nd_item<Dimensions>.value(); | ||
} | ||
|
||
template<int Dimensions> | ||
simsycl::sycl::group<Dimensions> this_group() { | ||
detail::khr_wi_query_check(detail::g_khr_wi_query_this_group<Dimensions>.has_value(), "this_group"); | ||
return detail::g_khr_wi_query_this_group<Dimensions>.value(); | ||
} | ||
|
||
inline simsycl::sycl::sub_group this_sub_group() { | ||
detail::khr_wi_query_check(detail::g_khr_wi_query_this_sub_group.has_value(), "this_sub_group"); | ||
return detail::g_khr_wi_query_this_sub_group.value(); | ||
} | ||
|
||
#endif // SIMSYCL_ENABLE_SYCL_KHR_WORK_ITEM_QUERIES | ||
|
||
} // namespace simsycl::sycl::khr |
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,85 @@ | ||
#include <simsycl/sycl.hh> | ||
|
||
#include <catch2/catch_template_test_macros.hpp> | ||
#include <catch2/catch_test_macros.hpp> | ||
#include <catch2/generators/catch_generators.hpp> | ||
#include <catch2/matchers/catch_matchers_string.hpp> | ||
|
||
using Catch::Matchers::ContainsSubstring; | ||
|
||
using namespace simsycl; | ||
|
||
TEST_CASE("work item queries set feature test macro", "[khr][work_item_queries]") { | ||
#if SIMSYCL_ENABLE_SYCL_KHR_WORK_ITEM_QUERIES | ||
CHECK(SYCL_KHR_WORK_ITEM_QUERIES == 1); | ||
#endif // SIMSYCL_ENABLE_SYCL_KHR_WORK_ITEM_QUERIES | ||
} | ||
|
||
TEMPLATE_TEST_CASE_SIG( | ||
"work item queries are correct if supported", "[khr][work_item_queries]", ((int Dims), Dims), 1, 2, 3) { | ||
#if SIMSYCL_ENABLE_SYCL_KHR_WORK_ITEM_QUERIES | ||
|
||
sycl::range<Dims> global_range; | ||
sycl::range<Dims> local_range; | ||
for(int d = 0; d < Dims; ++d) { | ||
const int s = d + 1; | ||
global_range[d] = s * (2 + s); | ||
local_range[d] = 2 + s; | ||
} | ||
|
||
std::vector<bool> visited(global_range.size(), false); | ||
sycl::queue() | ||
.submit([&](sycl::handler &cgh) { | ||
cgh.parallel_for(sycl::nd_range(global_range, local_range), [=, &visited](sycl::nd_item<Dims> it) { | ||
const auto global_linear_id = it.get_global_linear_id(); | ||
CHECK(global_linear_id < global_range.size()); | ||
CHECK(!visited[global_linear_id]); | ||
visited[global_linear_id] = true; | ||
|
||
CHECK(sycl::khr::this_nd_item<Dims>() == it); | ||
CHECK(sycl::khr::this_group<Dims>() == it.get_group()); | ||
CHECK(sycl::khr::this_sub_group() == it.get_sub_group()); | ||
|
||
group_barrier(it.get_group()); | ||
|
||
// check again after scheduling through group_barrier | ||
CHECK(sycl::khr::this_nd_item<Dims>() == it); | ||
CHECK(sycl::khr::this_group<Dims>() == it.get_group()); | ||
CHECK(sycl::khr::this_sub_group() == it.get_sub_group()); | ||
}); | ||
}) | ||
.wait(); | ||
|
||
for(size_t i = 0; i < global_range.size(); ++i) { | ||
CAPTURE(i); | ||
CHECK(visited[i]); | ||
} | ||
|
||
#else // SIMSYCL_ENABLE_SYCL_KHR_WORK_ITEM_QUERIES | ||
SKIP("SYCL_KHR_WORK_ITEM_QUERIES not enabled"); | ||
#endif // SIMSYCL_ENABLE_SYCL_KHR_WORK_ITEM_QUERIES | ||
} | ||
|
||
TEST_CASE("work item queries provide useful errors", "[khr][work_item_queries]") { | ||
#if SIMSYCL_ENABLE_SYCL_KHR_WORK_ITEM_QUERIES | ||
|
||
// outside of everything | ||
REQUIRE_THROWS_WITH(sycl::khr::this_nd_item<1>(), ContainsSubstring("state 'this_nd_item' is not available")); | ||
REQUIRE_THROWS_WITH(sycl::khr::this_group<1>(), ContainsSubstring("state 'this_group' is not available")); | ||
REQUIRE_THROWS_WITH(sycl::khr::this_sub_group(), ContainsSubstring("state 'this_sub_group' is not available")); | ||
|
||
// in a non-nd parallel for | ||
sycl::queue{}.submit([&](sycl::handler &cgh) { | ||
cgh.parallel_for(sycl::range{1}, [=](sycl::item<1>) { | ||
const char *test_str | ||
= "Make sure that the query originated from a kernel launched with a sycl::nd_range argument"; | ||
CHECK_THROWS_WITH(sycl::khr::this_nd_item<1>(), ContainsSubstring(test_str)); | ||
CHECK_THROWS_WITH(sycl::khr::this_group<1>(), ContainsSubstring(test_str)); | ||
CHECK_THROWS_WITH(sycl::khr::this_sub_group(), ContainsSubstring(test_str)); | ||
}); | ||
}); | ||
|
||
#else // SIMSYCL_ENABLE_SYCL_KHR_WORK_ITEM_QUERIES | ||
SKIP("SYCL_KHR_WORK_ITEM_QUERIES not enabled"); | ||
#endif // SIMSYCL_ENABLE_SYCL_KHR_WORK_ITEM_QUERIES | ||
} |
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.
Is this a clang-format change?
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.
Yes, that's how it is formatted for me right now. (I wouldn't write that on purpose ;))