Skip to content

Commit 4f14837

Browse files
committed
tests: benchdnn: add experimental support for sycl graph
1 parent f6f9669 commit 4f14837

File tree

8 files changed

+79
-4
lines changed

8 files changed

+79
-4
lines changed

cmake/testing.cmake

+7-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ set(DNNL_TEST_SET_COVERAGE "0")
3232
set(DNNL_TEST_SET_COVERAGE_STR "")
3333
set(DNNL_TEST_SET_HAS_NO_CORR "0")
3434
set(DNNL_TEST_SET_HAS_ADD_BITWISE "0")
35+
set(DNNL_TEST_SET_HAS_SYCL_GRAPH "0")
3536

3637
function(check_consistency entry)
3738
if(NOT DNNL_TEST_SET_COVERAGE EQUAL 0)
@@ -57,6 +58,8 @@ foreach(entry ${DNNL_TEST_SET})
5758
set(DNNL_TEST_SET_HAS_NO_CORR "1")
5859
elseif(entry STREQUAL "ADD_BITWISE")
5960
set(DNNL_TEST_SET_HAS_ADD_BITWISE "1")
61+
elseif(entry STREQUAL "SYCL_GRAPH")
62+
set(DNNL_TEST_SET_HAS_SYCL_GRAPH "1")
6063
elseif(entry STREQUAL "CI_NO_CORR") # Left here for compatibility till v4.0
6164
set(DNNL_TEST_SET_COVERAGE ${DNNL_TEST_SET_CI})
6265
set(DNNL_TEST_SET_COVERAGE_STR "CI")
@@ -68,7 +71,7 @@ foreach(entry ${DNNL_TEST_SET})
6871
message(FATAL_ERROR
6972
"The DNNL_TEST_SET entry ${entry} is not recognized. "
7073
"Supported values are:"
71-
"NIGHTLY, CI, SMOKE, NO_CORR, ADD_BITWISE.")
74+
"NIGHTLY, CI, SMOKE, NO_CORR, ADD_BITWISE, SYCL_GRAPH.")
7275
endif()
7376
endforeach()
7477

@@ -79,3 +82,6 @@ endif()
7982
if(DNNL_TEST_SET_HAS_ADD_BITWISE EQUAL 1)
8083
message(STATUS "Enabled testing modifier: Add bitwise validation")
8184
endif()
85+
if(DNNL_TEST_SET_HAS_SYCL_GRAPH EQUAL 1)
86+
message(STATUS "Enabled testing modifier: Use experimental SYCL graph execution")
87+
endif()

tests/benchdnn/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ function(register_benchdnn_test engine driver test_file)
8585
set(cmd "--mode=${tm} ${mode_modifier} -v1 --engine=${engine} --${driver} --batch=${test_file}")
8686
set(benchdnn_target ${target_name}_${engine})
8787

88+
if(DNNL_TEST_SET_HAS_SYCL_GRAPH EQUAL 1)
89+
string(PREPEND cmd "--use-sycl-graph=true")
90+
endif()
91+
8892
if(NOT WIN32 OR DNNL_BUILD_FOR_CI)
8993
string(REPLACE " " ";" cmd "benchdnn ${cmd}")
9094
add_dnnl_test(${benchdnn_target} ${cmd})

tests/benchdnn/benchdnn.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
int verbose {0};
5757
bool canonical {false};
5858
bool mem_check {true};
59+
bool use_sycl_graph {false};
5960
std::string skip_impl;
6061
stat_t benchdnn_stat {0};
6162
std::string driver_name;

tests/benchdnn/common.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ enum { CRIT = 1, WARN = 2 };
9393
extern int verbose;
9494
extern bool canonical;
9595
extern bool mem_check;
96+
extern bool use_sycl_graph;
9697
extern bool attr_same_pd_check;
9798
extern bool check_ref_impl;
9899
extern std::string skip_impl; /* empty or "" means skip nothing */

tests/benchdnn/dnn_types.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,10 @@ std::ostream &dump_global_params(std::ostream &s) {
919919
#endif
920920
if (canonical || cold_cache_mode != default_cold_cache_mode)
921921
s << "--cold-cache=" << cold_cache_mode << " ";
922+
#if defined(DNNL_WITH_SYCL)
923+
if (canonical || use_sycl_graph != false)
924+
s << "--use-sycl-graph=" << bool2str(use_sycl_graph) << " ";
925+
#endif
922926

923927
return s;
924928
}

tests/benchdnn/dnnl_common.cpp

+34-2
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,40 @@ int execute_and_wait(perf_function_t &exec_func, const dnnl_engine_t &engine,
366366

367367
execute_unmap_args(args, dnnl_args);
368368

369-
auto status = exec_func(stream, dnnl_args);
370-
DNN_SAFE(dnnl_stream_wait(stream), CRIT);
369+
dnnl_status_t status = dnnl_runtime_error;
370+
bool run_regular_exec = true;
371+
#if DNNL_GPU_RUNTIME == DNNL_RUNTIME_DPCPP
372+
while (use_sycl_graph && is_gpu(engine)) {
373+
void *queue_ptr;
374+
DNN_SAFE(dnnl_sycl_interop_stream_get_queue(stream, &queue_ptr), CRIT);
375+
sycl::queue queue = *static_cast<sycl::queue *>(queue_ptr);
376+
const bool can_run_sycl_graph = queue.get_device().get_backend()
377+
== sycl::backend::ext_oneapi_level_zero;
378+
if (!can_run_sycl_graph) break;
379+
380+
BENCHDNN_PRINT(
381+
2, "%s\n", "[INFO] Using experimental SYCL graph execution.");
382+
sycl::ext::oneapi::experimental::command_graph graph {
383+
queue.get_context(), queue.get_device()};
384+
385+
graph.begin_recording(queue);
386+
status = exec_func(stream, dnnl_args);
387+
graph.end_recording(queue);
388+
DNN_SAFE(dnnl_stream_wait(stream), CRIT);
389+
390+
auto exec = graph.finalize();
391+
queue.ext_oneapi_graph(exec).wait();
392+
393+
// SYCL graph feature completed submission and execution, no need to
394+
// have a regular run.
395+
run_regular_exec = false;
396+
break;
397+
}
398+
#endif
399+
if (run_regular_exec) {
400+
status = exec_func(stream, dnnl_args);
401+
DNN_SAFE(dnnl_stream_wait(stream), CRIT);
402+
}
371403
if (res) res->state = EXECUTED;
372404

373405
execute_map_args(args);

tests/benchdnn/doc/knobs_common.md

+6
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ Additional information is printed to the stdout depending on a level `N`. `N` is
146146
a non-negative integer value. The default value is `0`. Refer to
147147
[verbose](knobs_verbose.md) for details.
148148

149+
### --use-sycl-graph
150+
`--use-sycl-graph=BOOL` instructs the driver to execute using the experimental
151+
SYCL Graph backend when `BOOL` is set to `true`. When `BOOL` is set to `false`
152+
(the default), the driver will execute normally. This feature is limited to
153+
DPC++ runtime with Level Zero backend.
154+
149155
## Correctness mode settings
150156

151157
### --attr-same-pd-check

tests/benchdnn/utils/parser.cpp

+22-1
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,26 @@ static bool parse_verbose(
13781378
return false;
13791379
}
13801380

1381+
static bool parse_use_sycl_graph(
1382+
const char *str, const std::string &option_name = "use-sycl-graph") {
1383+
static const std::string help
1384+
= "BOOL (Default: `false`)\n Instructs the driver to execute "
1385+
"using experimental SYCL Graph backend, when set to `true`.\n";
1386+
bool parsed = parse_single_value_option(
1387+
use_sycl_graph, false, str2bool, str, option_name, help);
1388+
1389+
#if !defined(DNNL_WITH_SYCL)
1390+
if (parsed) {
1391+
BENCHDNN_PRINT(0,
1392+
"Error: option `--%s` is supported with DPC++ "
1393+
"builds only, exiting...\n",
1394+
option_name.c_str());
1395+
SAFE_V(FAIL);
1396+
}
1397+
#endif
1398+
return parsed;
1399+
}
1400+
13811401
bool parse_bench_settings(const char *str) {
13821402
last_parsed_is_problem = false; // if start parsing, expect an option
13831403

@@ -1402,7 +1422,8 @@ bool parse_bench_settings(const char *str) {
14021422
|| parse_num_streams(str) || parse_repeats_per_prb(str)
14031423
|| parse_mem_check(str) || parse_memory_kind(str) || parse_mode(str)
14041424
|| parse_mode_modifier(str) || parse_start(str)
1405-
|| parse_stream_kind(str) || parse_verbose(str);
1425+
|| parse_stream_kind(str) || parse_verbose(str)
1426+
|| parse_use_sycl_graph(str);
14061427

14071428
// Last condition makes this help message to be triggered once driver_name
14081429
// is already known.

0 commit comments

Comments
 (0)