Skip to content

Commit b5cc46a

Browse files
rebleCompute-Runtime-Automation
authored andcommitted
Rework Graph API tests
Signed-off-by: Pablo Reble <[email protected]>
1 parent dfdbf2f commit b5cc46a

File tree

6 files changed

+185
-198
lines changed

6 files changed

+185
-198
lines changed

source/benchmarks/graph_api_benchmark/definitions/submit_exec_graph.h

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (C) 2024-2025 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#pragma once
9+
10+
#include "framework/argument/basic_argument.h"
11+
#include "framework/test_case/test_case.h"
12+
13+
struct SubmitGraphArguments : TestCaseArgumentContainer {
14+
BooleanArgument useProfiling;
15+
BooleanArgument inOrderQueue;
16+
PositiveIntegerArgument numKernels;
17+
PositiveIntegerArgument kernelExecutionTime;
18+
BooleanArgument measureCompletionTime;
19+
20+
SubmitGraphArguments()
21+
: useProfiling(*this, "Profiling", "Create the queue with the enable_profiling property"),
22+
inOrderQueue(*this, "InOrderQueue", "Create the queue with the in_order property"),
23+
numKernels(*this, "NumKernels", "Number of kernels to submit to the queue"),
24+
kernelExecutionTime(*this, "KernelExecutionTime", "Approximately how long a single kernel executes, in us"),
25+
measureCompletionTime(*this, "MeasureCompletionTime", "Measures time taken to complete the submission (default is to measure only submit calls)") {}
26+
};
27+
28+
struct SubmitGraph : TestCase<SubmitGraphArguments> {
29+
using TestCase<SubmitGraphArguments>::TestCase;
30+
31+
std::string getTestCaseName() const override {
32+
return "SubmitGraph";
33+
}
34+
35+
std::string getHelp() const override {
36+
return "measures time spent in submitting a graph to a SYCL (or SYCL-like) queue on CPU.";
37+
}
38+
};

source/benchmarks/graph_api_benchmark/gtest/submit_exec_graph.cpp

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (C) 2024-2025 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "definitions/submit_graph.h"
9+
10+
#include "framework/test_case/register_test_case.h"
11+
#include "framework/utility/common_gtest_args.h"
12+
13+
#include <gtest/gtest.h>
14+
15+
[[maybe_unused]] static const inline RegisterTestCase<SubmitGraph> registerTestCase{};
16+
17+
class SubmitGraphTest : public ::testing::TestWithParam<std::tuple<Api, bool, bool, size_t, size_t, bool>> {
18+
};
19+
20+
TEST_P(SubmitGraphTest, Test) {
21+
SubmitGraphArguments args{};
22+
args.api = std::get<0>(GetParam());
23+
args.useProfiling = std::get<1>(GetParam());
24+
args.inOrderQueue = std::get<2>(GetParam());
25+
args.numKernels = std::get<3>(GetParam());
26+
args.kernelExecutionTime = std::get<4>(GetParam());
27+
args.measureCompletionTime = std::get<5>(GetParam());
28+
SubmitGraph test;
29+
test.run(args);
30+
}
31+
32+
INSTANTIATE_TEST_SUITE_P(
33+
SubmitGraphTest,
34+
SubmitGraphTest,
35+
::testing::Combine(
36+
::CommonGtestArgs::allApis(),
37+
::testing::Values(false, true), // useProfiling
38+
::testing::Values(false, true), // inOrderQueue
39+
::testing::Values(4u, 8u, 16u, 32u), // numKernels
40+
::testing::Values(1u), // kernelExecutionTime
41+
::testing::Values(false, true))); // measureCompletionTime

source/benchmarks/graph_api_benchmark/implementations/sycl/submit_exec_graph_sycl.cpp

Lines changed: 0 additions & 127 deletions
This file was deleted.
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Copyright (C) 2024-2025 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "framework/test_case/register_test_case.h"
9+
#include "framework/utility/timer.h"
10+
11+
#include "definitions/submit_graph.h"
12+
13+
#include <gtest/gtest.h>
14+
#include <sycl/sycl.hpp>
15+
#if __has_include(<sycl/ext/oneapi/experimental/graph.hpp>)
16+
#include <sycl/ext/oneapi/experimental/graph.hpp>
17+
#define HAS_SYCL_GRAPH
18+
#endif
19+
20+
static auto enableProfiling = sycl::property::queue::enable_profiling();
21+
static auto inOrder = sycl::property::queue::in_order();
22+
23+
[[maybe_unused]] static const sycl::property_list queueProps[] = {
24+
sycl::property_list{},
25+
sycl::property_list{enableProfiling},
26+
sycl::property_list{inOrder},
27+
sycl::property_list{inOrder, enableProfiling},
28+
};
29+
30+
static TestResult run([[maybe_unused]] const SubmitGraphArguments &arguments, Statistics &statistics) {
31+
try {
32+
MeasurementFields typeSelector(MeasurementUnit::Microseconds, MeasurementType::Cpu);
33+
34+
if (isNoopRun()) {
35+
statistics.pushUnitAndType(typeSelector.getUnit(), typeSelector.getType());
36+
return TestResult::Nooped;
37+
}
38+
39+
#if defined(HAS_SYCL_GRAPH)
40+
// Setup
41+
auto queuePropsIndex = 0;
42+
queuePropsIndex |= arguments.useProfiling ? 0x1 : 0;
43+
queuePropsIndex |= arguments.inOrderQueue ? 0x2 : 0;
44+
sycl::queue queue{queueProps[queuePropsIndex]};
45+
46+
Timer timer;
47+
const size_t gws = 1u;
48+
const size_t lws = 1u;
49+
sycl::nd_range<1> range(gws, lws);
50+
51+
// Create kernel
52+
int kernelOperationsCount = static_cast<int>(arguments.kernelExecutionTime);
53+
[[maybe_unused]] const auto eat_time = [=]([[maybe_unused]] auto u) {
54+
volatile int value = 1u;
55+
for (int i = 0; i < kernelOperationsCount; i++) {
56+
value /= 2;
57+
value *= 2;
58+
}
59+
};
60+
61+
// Building the graph without explicit dependencies
62+
sycl::ext::oneapi::experimental::command_graph graph(queue.get_context(), queue.get_device());
63+
graph.begin_recording(queue);
64+
for (auto iteration = 0u; iteration < arguments.numKernels; iteration++) {
65+
queue.parallel_for(range, eat_time);
66+
}
67+
graph.end_recording();
68+
69+
// Finalize the graph
70+
auto executable_graph = graph.finalize();
71+
72+
// Warmup
73+
queue.submit([&](sycl::handler &cgh) {
74+
cgh.ext_oneapi_graph(executable_graph);
75+
});
76+
queue.wait();
77+
78+
// Benchmark
79+
for (auto i = 0u; i < arguments.iterations; i++) {
80+
timer.measureStart();
81+
queue.submit([&](sycl::handler &cgh) {
82+
cgh.ext_oneapi_graph(executable_graph);
83+
});
84+
85+
if (!arguments.measureCompletionTime) {
86+
timer.measureEnd();
87+
}
88+
89+
queue.wait();
90+
91+
if (arguments.measureCompletionTime) {
92+
timer.measureEnd();
93+
}
94+
statistics.pushValue(timer.get(), typeSelector.getUnit(), typeSelector.getType());
95+
}
96+
97+
#endif
98+
} catch (sycl::exception &e) {
99+
std::cerr << "Caught SYCL exception: " << e.what() << "\n";
100+
return TestResult::Error;
101+
}
102+
103+
return TestResult::Success;
104+
}
105+
106+
[[maybe_unused]] static RegisterTestCaseImplementation<SubmitGraph> registerTestCase(run, Api::SYCL);

0 commit comments

Comments
 (0)