Skip to content

[SYCL][COMPAT] Fixes SYCLCOMPAT_PROFILING_ENABLED codepath #14574

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 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions sycl/include/syclcompat/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,11 @@ Use 64 bits as memory_bus_width default value."
_queues.clear();
// create new default queue
// calls create_queue_impl since we already have a locked m_mutex

_saved_queue = _default_queue =
create_queue_impl(print_on_async_exceptions, in_order);
in_order ? create_queue_impl(print_on_async_exceptions,
sycl::property::queue::in_order())
: create_queue_impl(print_on_async_exceptions);
}

void set_default_queue(const sycl::queue &q) {
Expand All @@ -573,7 +576,9 @@ Use 64 bits as memory_bus_width default value."
queue_ptr create_queue(bool print_on_async_exceptions = false,
bool in_order = true) {
std::lock_guard<std::mutex> lock(m_mutex);
return create_queue_impl(print_on_async_exceptions, in_order);
return in_order ? create_queue_impl(print_on_async_exceptions,
sycl::property::queue::in_order())
: create_queue_impl(print_on_async_exceptions);
}
void destroy_queue(queue_ptr &queue) {
std::lock_guard<std::mutex> lock(m_mutex);
Expand Down Expand Up @@ -645,15 +650,14 @@ Use 64 bits as memory_bus_width default value."
private:
/// Caller should only be done from functions where the resource \p m_mutex
/// has been acquired.
template <typename... PropertiesT>
queue_ptr create_queue_impl(bool print_on_async_exceptions = false,
bool in_order = true) {
sycl::property_list prop = {};
if (in_order) {
prop = {sycl::property::queue::in_order()};
}
PropertiesT... properties) {
sycl::property_list prop = sycl::property_list(
#ifdef SYCLCOMPAT_PROFILING_ENABLED
prop.push_back(sycl::property::queue::enable_profiling());
sycl::property::queue::enable_profiling(),
#endif
properties...);
if (print_on_async_exceptions) {
_queues.push_back(std::make_shared<sycl::queue>(
_ctx, *this, detail::exception_handler, prop));
Expand Down
68 changes: 68 additions & 0 deletions sycl/test-e2e/syclcompat/device/device_profiling.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/***************************************************************************
*
* 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 API
*
* device_profiling.cpp
*
* Description:
* Tests for the enable_profiling property paths
**************************************************************************/

// RUN: %clangxx -DSYCLCOMPAT_PROFILING_ENABLED=1 -fsycl -fsycl-targets=%{sycl_triple} %s -o %t-profiling.out
// RUN: %{run} %t-profiling.out
// RUN: %clangxx -fsycl -fsycl-targets=%{sycl_triple} %s -o %t-no-profiling.out
// RUN: %{run} %t-no-profiling.out

#include <syclcompat/device.hpp>

#ifdef SYCLCOMPAT_PROFILING_ENABLED
void test_event_profiling() {
sycl::queue q = syclcompat::get_default_queue();

if (!q.get_device().has(sycl::aspect::queue_profiling)) {
std::cout << "Device does not have aspect::queue_profiling, skipping."
<< std::endl;
return;
}

assert(q.has_property<sycl::property::queue::enable_profiling>());

q = sycl::queue{q.get_device(), sycl::property::queue::enable_profiling()};
auto event = q.submit([&](sycl::handler &cgh) { cgh.single_task([=]() {}); });
event.get_profiling_info<sycl::info::event_profiling::command_end>();
}
#else
void test_no_event_profiling() {
sycl::queue q = syclcompat::get_default_queue();

if (!q.get_device().has(sycl::aspect::queue_profiling)) {
std::cout << "Device does not have aspect::queue_profiling, skipping."
<< std::endl;
return;
}

assert(!q.has_property<sycl::property::queue::enable_profiling>());
}
#endif

int main() {
#ifdef SYCLCOMPAT_PROFILING_ENABLED
test_event_profiling();
#else
test_no_event_profiling();
#endif

return 0;
}
Loading