-
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
5
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
5 commits
Select commit
Hold shift + click to select a range
a96112b
Implement `sycl_khr_work_item_queries` extension
0x12CC bfb2d89
Add license to extension header
0x12CC 532327a
Merge branch 'sycl' into sycl_khr_work_item_queries
0x12CC 23c0efb
Move feature test macro to correct header
0x12CC 3528f1b
Improve test case error reporting
0x12CC 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,34 @@ | ||
//===-- 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> | ||
|
||
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
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
120 changes: 120 additions & 0 deletions
120
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,120 @@ | ||
// 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 <iostream> | ||
#include <sycl/detail/core.hpp> | ||
#include <sycl/khr/work_item_queries.hpp> | ||
|
||
template <size_t... Dims> static int 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) { | ||
if (!result) { | ||
std::cerr << "check_this_nd_item_api failed for dimensionality " | ||
<< Dimensions << ".\n"; | ||
return 1; | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
template <size_t... Dims> static int 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) { | ||
if (!result) { | ||
std::cerr << "check_this_group_api failed for dimensionality " | ||
<< Dimensions << ".\n"; | ||
return 1; | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
template <size_t... Dims> static int 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) { | ||
if (!result) { | ||
std::cerr << "check_this_sub_group_api failed for dimensionality " | ||
<< Dimensions << ".\n"; | ||
return 1; | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
int main() { | ||
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; | ||
} |
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.
Similar comment as in #18521 (comment). We should let KHR extensions be the leaves as much as possible.