-
Notifications
You must be signed in to change notification settings - Fork 796
[SYCL][COMPAT] Add max_active_work_groups_per_cu #15802
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ea94c64
This include was missing from kernel.hpp
joeatodd fbc2d33
First draft impl & test
joeatodd 78b1e8c
Define dim3 version & implement range version using it
joeatodd ac17463
Templatize test case & other improvements
joeatodd aa55e00
Move range & buffer instantiation inside if(false)
joeatodd 408fa70
Move to util.hpp header
joeatodd 2d8a8f5
Move & rename test
joeatodd d6ae1aa
Move to syclcompat:: namespace (woops)
joeatodd 7989cd7
Add docs
joeatodd d3af6af
Improve testing
joeatodd a79a9dd
Compare dim3 impl in test
joeatodd 0a44c80
Adopt templatized approach to avoid having to grab kernel_bundle
joeatodd a12ea30
Update docs slightly
joeatodd 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
133 changes: 133 additions & 0 deletions
133
sycl/test-e2e/syclcompat/util/max_active_work_groups_per_cu.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,133 @@ | ||
| /*************************************************************************** | ||
| * | ||
| * Copyright (C) Codeplay Software Ltd. | ||
| * | ||
| * 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 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| * SYCLcompat | ||
| * | ||
| * max_active_work_groups_per_cu.cpp | ||
| * | ||
| * Description: | ||
| * Test the syclcompat::max_active_work_groups_per_cu API | ||
| **************************************************************************/ | ||
| // RUN: %{build} -o %t.out | ||
| // RUN: %{run} %t.out | ||
|
|
||
| #include "sycl/accessor.hpp" | ||
| #include <sycl/detail/core.hpp> | ||
| #include <syclcompat/util.hpp> | ||
|
|
||
| template <class T, size_t Dim> | ||
| using sycl_global_accessor = | ||
| sycl::accessor<T, Dim, sycl::access::mode::read_write, | ||
| sycl::access::target::global_buffer>; | ||
|
|
||
| using value_type = int; | ||
|
|
||
| template <int RangeDim> struct MyKernel { | ||
| MyKernel(sycl_global_accessor<value_type, RangeDim> acc) : acc_{acc} {} | ||
| void operator()(sycl::nd_item<RangeDim> item) const { | ||
| auto gid = item.get_global_id(); | ||
| acc_[gid] = item.get_global_linear_id(); | ||
| } | ||
| sycl_global_accessor<value_type, RangeDim> acc_; | ||
| static constexpr bool has_local_mem = false; | ||
| }; | ||
|
|
||
| template <int RangeDim> struct MyLocalMemKernel { | ||
| MyLocalMemKernel(sycl_global_accessor<value_type, RangeDim> acc, | ||
| sycl::local_accessor<value_type, RangeDim> lacc) | ||
| : acc_{acc}, lacc_{lacc} {} | ||
| void operator()(sycl::nd_item<RangeDim> item) const { | ||
| auto gid = item.get_global_id(); | ||
| acc_[gid] = item.get_global_linear_id(); | ||
| auto lid = item.get_local_id(); | ||
| lacc_[lid] = item.get_global_linear_id(); | ||
| } | ||
| sycl_global_accessor<value_type, RangeDim> acc_; | ||
| sycl::local_accessor<value_type, RangeDim> lacc_; | ||
| static constexpr bool has_local_mem = true; | ||
| }; | ||
|
|
||
| template <template <int> class KernelName, int RangeDim> | ||
| void test_max_active_work_groups_per_cu(sycl::queue q, | ||
| sycl::range<RangeDim> wg_range, | ||
| size_t local_mem_size = 0) { | ||
| if constexpr (!KernelName<RangeDim>::has_local_mem) | ||
| assert(local_mem_size == 0 && "Bad test setup"); | ||
|
|
||
| size_t max_per_cu = syclcompat::max_active_work_groups_per_cu<KernelName<RangeDim>>( | ||
| wg_range, local_mem_size, q); | ||
|
|
||
| // Check we get the same result passing equivalent dim3 | ||
| syclcompat::dim3 wg_dim3{wg_range}; | ||
| size_t max_per_cu_dim3 = syclcompat::max_active_work_groups_per_cu<KernelName<RangeDim>>( | ||
| wg_dim3, local_mem_size, q); | ||
| assert(max_per_cu == max_per_cu_dim3); | ||
|
|
||
| // Compare w/ reference impl | ||
| size_t max_compute_units = | ||
| q.get_device().get_info<sycl::info::device::max_compute_units>(); | ||
| namespace syclex = sycl::ext::oneapi::experimental; | ||
| auto ctx = q.get_context(); | ||
| auto bundle = sycl::get_kernel_bundle<sycl::bundle_state::executable>(ctx); | ||
| auto kernel = bundle.template get_kernel<KernelName<RangeDim>>(); | ||
| size_t max_wgs = kernel.template ext_oneapi_get_info< | ||
| syclex::info::kernel_queue_specific::max_num_work_groups>( | ||
| q, sycl::range<3>{syclcompat::dim3{wg_range}}, local_mem_size); | ||
| assert(max_per_cu == max_wgs / max_compute_units); | ||
|
|
||
| // We aren't interested in the launch, it's here to define the kernel | ||
| if (false) { | ||
| sycl::range<RangeDim> global_range = wg_range; | ||
| if(max_per_cu > 0) | ||
| global_range[0] = global_range[0] * max_per_cu * max_compute_units; | ||
| sycl::nd_range<RangeDim> my_range{global_range, wg_range}; | ||
| sycl::buffer<value_type, RangeDim> buf{global_range}; | ||
|
|
||
| q.submit([&](sycl::handler &cgh) { | ||
| auto acc = buf.template get_access<sycl::access::mode::read_write>(cgh); | ||
| if constexpr (KernelName<RangeDim>::has_local_mem) { | ||
| sycl::local_accessor<value_type, RangeDim> lacc( | ||
| my_range.get_local_range(), cgh); | ||
| cgh.parallel_for(my_range, KernelName<RangeDim>{acc, lacc}); | ||
| } else { | ||
| cgh.parallel_for(my_range, KernelName<RangeDim>{acc}); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| int main() { | ||
| sycl::queue q{}; | ||
| sycl::range<1> range_1d{32}; | ||
| sycl::range<2> range_2d{1, 32}; | ||
| sycl::range<3> range_3d{1, 1, 32}; | ||
| syclcompat::dim3 wg_dim3{32, 1, 1}; | ||
|
|
||
| size_t lmem_size_small = sizeof(value_type) * 32; | ||
| size_t lmem_size_medium = lmem_size_small * 32; | ||
| size_t lmem_size_large = lmem_size_medium * 32; | ||
|
|
||
| test_max_active_work_groups_per_cu<MyKernel, 3>(q, range_3d); | ||
| test_max_active_work_groups_per_cu<MyKernel, 2>(q, range_2d); | ||
| test_max_active_work_groups_per_cu<MyKernel, 1>(q, range_1d); | ||
| test_max_active_work_groups_per_cu<MyLocalMemKernel, 3>(q, range_3d, | ||
| lmem_size_small); | ||
| test_max_active_work_groups_per_cu<MyLocalMemKernel, 3>(q, range_3d, | ||
| lmem_size_medium); | ||
| test_max_active_work_groups_per_cu<MyLocalMemKernel, 3>(q, range_3d, | ||
| lmem_size_large); | ||
| test_max_active_work_groups_per_cu<MyLocalMemKernel, 1>(q, range_1d, | ||
| lmem_size_large); | ||
| return 0; | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
do we expect NDEBUG to not to defined during testing ?
Does the CI build and test DPCPP with a specific configuration or is the build type string left empty ?
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,
asserts work as expected during testing.llvm-litwill test on as many backends as are available, AFAIK.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.
thanks