Skip to content

Commit 3caa78e

Browse files
authored
[SYCL][COMPAT] Fixes SYCLCOMPAT_PROFILING_ENABLED codepath (#14574)
The codepath which enabled profiling in syclcompat queues was neither working nor properly tested. - Fixes `sycl::property::queue::enable_profiling` being added to queue properties if SYCLCOMPAT_PROFILING_ENABLED is defined - Tests added for both SYCLCOMPAT_PROFILING_ENABLED defined and undefined. - Refactors `create_queue_impl` to accept a list of properties instead of a series of bools to enable properties. - Refactor does not affect public API. --------- Signed-off-by: Alberto Cabrera <[email protected]>
1 parent 8e40bb5 commit 3caa78e

File tree

2 files changed

+80
-8
lines changed

2 files changed

+80
-8
lines changed

sycl/include/syclcompat/device.hpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,11 @@ Use 64 bits as memory_bus_width default value."
545545
_queues.clear();
546546
// create new default queue
547547
// calls create_queue_impl since we already have a locked m_mutex
548+
548549
_saved_queue = _default_queue =
549-
create_queue_impl(print_on_async_exceptions, in_order);
550+
in_order ? create_queue_impl(print_on_async_exceptions,
551+
sycl::property::queue::in_order())
552+
: create_queue_impl(print_on_async_exceptions);
550553
}
551554
552555
void set_default_queue(const sycl::queue &q) {
@@ -573,7 +576,9 @@ Use 64 bits as memory_bus_width default value."
573576
queue_ptr create_queue(bool print_on_async_exceptions = false,
574577
bool in_order = true) {
575578
std::lock_guard<std::mutex> lock(m_mutex);
576-
return create_queue_impl(print_on_async_exceptions, in_order);
579+
return in_order ? create_queue_impl(print_on_async_exceptions,
580+
sycl::property::queue::in_order())
581+
: create_queue_impl(print_on_async_exceptions);
577582
}
578583
void destroy_queue(queue_ptr &queue) {
579584
std::lock_guard<std::mutex> lock(m_mutex);
@@ -645,15 +650,14 @@ Use 64 bits as memory_bus_width default value."
645650
private:
646651
/// Caller should only be done from functions where the resource \p m_mutex
647652
/// has been acquired.
653+
template <typename... PropertiesT>
648654
queue_ptr create_queue_impl(bool print_on_async_exceptions = false,
649-
bool in_order = true) {
650-
sycl::property_list prop = {};
651-
if (in_order) {
652-
prop = {sycl::property::queue::in_order()};
653-
}
655+
PropertiesT... properties) {
656+
sycl::property_list prop = sycl::property_list(
654657
#ifdef SYCLCOMPAT_PROFILING_ENABLED
655-
prop.push_back(sycl::property::queue::enable_profiling());
658+
sycl::property::queue::enable_profiling(),
656659
#endif
660+
properties...);
657661
if (print_on_async_exceptions) {
658662
_queues.push_back(std::make_shared<sycl::queue>(
659663
_ctx, *this, detail::exception_handler, prop));
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/***************************************************************************
2+
*
3+
* Copyright (C) Codeplay Software Ltd.
4+
*
5+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM
6+
* Exceptions. See https://llvm.org/LICENSE.txt for license information.
7+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*
15+
* SYCLcompat API
16+
*
17+
* device_profiling.cpp
18+
*
19+
* Description:
20+
* Tests for the enable_profiling property paths
21+
**************************************************************************/
22+
23+
// RUN: %clangxx -DSYCLCOMPAT_PROFILING_ENABLED=1 -fsycl -fsycl-targets=%{sycl_triple} %s -o %t-profiling.out
24+
// RUN: %{run} %t-profiling.out
25+
// RUN: %clangxx -fsycl -fsycl-targets=%{sycl_triple} %s -o %t-no-profiling.out
26+
// RUN: %{run} %t-no-profiling.out
27+
28+
#include <syclcompat/device.hpp>
29+
30+
#ifdef SYCLCOMPAT_PROFILING_ENABLED
31+
void test_event_profiling() {
32+
sycl::queue q = syclcompat::get_default_queue();
33+
34+
if (!q.get_device().has(sycl::aspect::queue_profiling)) {
35+
std::cout << "Device does not have aspect::queue_profiling, skipping."
36+
<< std::endl;
37+
return;
38+
}
39+
40+
assert(q.has_property<sycl::property::queue::enable_profiling>());
41+
42+
q = sycl::queue{q.get_device(), sycl::property::queue::enable_profiling()};
43+
auto event = q.submit([&](sycl::handler &cgh) { cgh.single_task([=]() {}); });
44+
event.get_profiling_info<sycl::info::event_profiling::command_end>();
45+
}
46+
#else
47+
void test_no_event_profiling() {
48+
sycl::queue q = syclcompat::get_default_queue();
49+
50+
if (!q.get_device().has(sycl::aspect::queue_profiling)) {
51+
std::cout << "Device does not have aspect::queue_profiling, skipping."
52+
<< std::endl;
53+
return;
54+
}
55+
56+
assert(!q.has_property<sycl::property::queue::enable_profiling>());
57+
}
58+
#endif
59+
60+
int main() {
61+
#ifdef SYCLCOMPAT_PROFILING_ENABLED
62+
test_event_profiling();
63+
#else
64+
test_no_event_profiling();
65+
#endif
66+
67+
return 0;
68+
}

0 commit comments

Comments
 (0)