Skip to content

Commit

Permalink
gtests: add a test case for profiling API
Browse files Browse the repository at this point in the history
  • Loading branch information
densamoilov authored and vpirogov committed Jul 10, 2023
1 parent 2ca2938 commit 51a8f7a
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
47 changes: 47 additions & 0 deletions tests/gtests/ocl/api/test_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,51 @@ TEST_F(ocl_stream_test_cpp_t, TestProfilingAPICPU) {

#endif

#ifndef DNNL_EXPERIMENTAL_PROFILING
extern "C" dnnl_status_t dnnl_reset_profiling(dnnl_stream_t stream);
#endif

TEST_F(ocl_stream_test_cpp_t, TestProfilingAPIDisabledAndEnabled) {
SKIP_IF(!find_ocl_device(CL_DEVICE_TYPE_GPU),
"OpenCL GPU devices not found.");

memory::dims dims = {2, 3, 4, 5};
memory::desc md(dims, memory::data_type::f32, memory::format_tag::nchw);

auto eltwise_pd = eltwise_forward::primitive_desc(
eng, prop_kind::forward, algorithm::eltwise_relu, md, md, 0.0f);
auto eltwise = eltwise_forward(eltwise_pd);
auto mem = memory(md, eng);

cl_int err;
#ifdef CL_VERSION_2_0
cl_queue_properties properties[]
= {CL_QUEUE_PROPERTIES, CL_QUEUE_PROFILING_ENABLE, 0};
cl_command_queue ocl_queue = clCreateCommandQueueWithProperties(
ocl_ctx, ocl_dev, properties, &err);
#else
cl_command_queue_properties properties = CL_QUEUE_PROFILING_ENABLE;
cl_command_queue ocl_queue
= clCreateCommandQueue(ocl_ctx, ocl_dev, properties, &err);
#endif

TEST_OCL_CHECK(err);

auto stream = ocl_interop::make_stream(eng, ocl_queue);
TEST_OCL_CHECK(clReleaseCommandQueue(ocl_queue));

eltwise.execute(stream, {{DNNL_ARG_SRC, mem}, {DNNL_ARG_DST, mem}});
stream.wait();

auto st = dnnl_reset_profiling(stream.get());

// If the experimental profiling API is not enabled then the library should not
// enable profiling regardless of the queue's properties.
#ifdef DNNL_EXPERIMENTAL_PROFILING
EXPECT_EQ(st, dnnl_success);
#else
EXPECT_EQ(st, dnnl_invalid_arguments);
#endif
}

} // namespace dnnl
45 changes: 44 additions & 1 deletion tests/gtests/sycl/api/test_stream.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2019-2022 Intel Corporation
* Copyright 2019-2023 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -132,6 +132,49 @@ TEST_P(sycl_stream_test, InteropIncompatibleQueue) {
true, dnnl_invalid_arguments);
}

#ifndef DNNL_EXPERIMENTAL_PROFILING
extern "C" dnnl_status_t dnnl_reset_profiling(dnnl_stream_t stream);
#endif

TEST_P(sycl_stream_test, TestProfilingAPIDisabledAndEnabled) {
engine::kind kind = GetParam();
SKIP_IF(!has(kind), "Device not found.");
SKIP_IF(kind == engine::kind::cpu, "Test is GPU specific.");

auto sycl_queue = sycl::queue(get_context(kind), get_device(kind),
sycl::property_list {sycl::property::queue::in_order {},
sycl::property::queue::enable_profiling {}});
stream strm = sycl_interop::make_stream(get_engine(kind), sycl_queue);

memory::dims tz_dims = {2, 3, 4, 5};
const size_t N = std::accumulate(tz_dims.begin(), tz_dims.end(), (size_t)1,
std::multiplies<size_t>());
auto usm_buffer = (float *)malloc_shared(
N * sizeof(float), get_device(kind), get_context(kind));

memory::desc mem_d(
tz_dims, memory::data_type::f32, memory::format_tag::nchw);

memory mem = sycl_interop::make_memory(mem_d, get_engine(kind),
sycl_interop::memory_kind::usm, usm_buffer);

auto relu_pd = eltwise_forward::primitive_desc(get_engine(kind),
prop_kind::forward, algorithm::eltwise_relu, mem_d, mem_d, 0.0f);
auto relu = eltwise_forward(relu_pd);
relu.execute(strm, {{DNNL_ARG_SRC, mem}, {DNNL_ARG_DST, mem}});
strm.wait();

auto st = dnnl_reset_profiling(strm.get());

// If the experimental profiling API is not enabled then the library should not
// enable profiling regardless of the queue's properties.
#ifdef DNNL_EXPERIMENTAL_PROFILING
EXPECT_EQ(st, dnnl_success);
#else
EXPECT_EQ(st, dnnl_invalid_arguments);
#endif
}

// TODO: Enable the test below after sycl_stream_t is fixed to not reuse the
// service stream. Now it ignores the input stream flags and reuses the service
// stream which is constructed without any flags.
Expand Down

0 comments on commit 51a8f7a

Please sign in to comment.