Skip to content

Commit 8e5a57f

Browse files
committed
gtests: add regression test for PVC WAR bug workaround
1 parent 806bc59 commit 8e5a57f

File tree

7 files changed

+140
-9
lines changed

7 files changed

+140
-9
lines changed

src/gpu/intel/compute/device_info.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct alignas(int) gpu_product_t {
4949
unsigned char data[12];
5050
};
5151

52-
static inline std::string to_string(gpu_arch_t arch) {
52+
static inline const char *to_string(gpu_arch_t arch) {
5353
#define CASE(_case) \
5454
if (arch == gpu_arch_t::_case) return STRINGIFY(_case)
5555
CASE(xe_lp);

src/gpu/intel/engine.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,19 @@ status_t engine_t::init(const std::vector<uint8_t> &cache_blob) {
8888
} // namespace impl
8989
} // namespace dnnl
9090

91-
bool dnnl_impl_gpu_mayiuse_ngen_kernels(dnnl::impl::engine_t *engine) {
91+
bool dnnl_impl_gpu_intel_mayiuse_ngen_kernels(dnnl::impl::engine_t *engine) {
9292
using namespace dnnl::impl;
9393
using namespace dnnl::impl::gpu;
9494

9595
auto *intel_engine = utils::downcast<intel::engine_t *>(engine);
9696
return intel_engine->mayiuse_ngen_kernels();
9797
}
98+
99+
const char *dnnl_impl_gpu_intel_get_isa_name(dnnl::impl::engine_t *engine) {
100+
using namespace dnnl::impl;
101+
using namespace dnnl::impl::gpu;
102+
103+
auto *intel_engine = utils::downcast<intel::engine_t *>(engine);
104+
auto *device_info = intel_engine->device_info();
105+
return intel::compute::to_string(device_info->gpu_arch());
106+
}

src/gpu/intel/engine.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,9 @@ class engine_t : public gpu::engine_t {
217217
} // namespace dnnl
218218

219219
// Exported for testing purposes only.
220-
extern "C" bool DNNL_API dnnl_impl_gpu_mayiuse_ngen_kernels(
220+
extern "C" bool DNNL_API dnnl_impl_gpu_intel_mayiuse_ngen_kernels(
221+
dnnl::impl::engine_t *engine);
222+
extern "C" DNNL_API const char *dnnl_impl_gpu_intel_get_isa_name(
221223
dnnl::impl::engine_t *engine);
222224

223225
#endif

tests/gtests/ocl/api/test_engine.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <string>
2424
#include <CL/cl.h>
2525

26-
extern "C" bool dnnl_impl_gpu_mayiuse_ngen_kernels(dnnl_engine_t engine);
26+
extern "C" bool dnnl_impl_gpu_intel_mayiuse_ngen_kernels(dnnl_engine_t engine);
2727

2828
namespace dnnl {
2929
namespace {
@@ -287,7 +287,7 @@ TEST_P(ocl_engine_test_t, BinaryKernels) {
287287
//DNNL_ENABLE_MEM_DEBUG forces allocation fail, causing mayiuse to fail
288288
#ifndef DNNL_ENABLE_MEM_DEBUG
289289
if (s == dnnl_success) {
290-
ASSERT_EQ(dnnl_impl_gpu_mayiuse_ngen_kernels(eng), true);
290+
ASSERT_EQ(dnnl_impl_gpu_intel_mayiuse_ngen_kernels(eng), true);
291291
}
292292
#endif
293293

tests/gtests/regression/CMakeLists.txt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,22 @@
1414
# limitations under the License.
1515
#===============================================================================
1616

17-
set(TEST_EXE test_regression)
17+
set(TEST_SOURCES
18+
test_regression_binary_stride.cpp
19+
)
1820

19-
file(GLOB TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/test_*.cpp)
20-
list(APPEND TEST_SOURCES ${MAIN_SRC_GTEST})
21+
if(UNIX AND NOT DNNL_GPU_RUNTIME STREQUAL "NONE" AND DNNL_GPU_VENDOR STREQUAL "INTEL")
22+
set(TEST_SOURCES "${TEST_SOURCES};test_regression_pvc_war_wa.cpp")
23+
endif()
2124

22-
register_exe(${TEST_EXE} "${TEST_SOURCES}" "test" "dnnl_gtest")
25+
foreach(TEST_FILE ${TEST_SOURCES})
26+
get_filename_component(exe ${TEST_FILE} NAME_WE)
27+
register_exe("${exe}" "${CMAKE_CURRENT_SOURCE_DIR}/${TEST_FILE};${MAIN_SRC_GTEST}" "test" "dnnl_gtest")
28+
endforeach()
29+
30+
if(TARGET test_regression_pvc_war_wa)
31+
# Regression test for PVC WAR bug workaround. The bug is triggered by setting
32+
# round-robin thread arbitration policy so override it here.
33+
set_tests_properties(test_regression_pvc_war_wa
34+
PROPERTIES ENVIRONMENT "NEOReadDebugKeys=1;OverrideThreadArbitrationPolicy=1")
35+
endif()
File renamed without changes.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*******************************************************************************
2+
* Copyright 2025 Intel Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*******************************************************************************/
16+
17+
#include "dnnl_test_common.hpp"
18+
#include "gtest/gtest.h"
19+
20+
#include "oneapi/dnnl/dnnl.hpp"
21+
22+
#include <cstdlib>
23+
#include <iostream>
24+
25+
extern "C" const char *dnnl_impl_gpu_intel_get_isa_name(dnnl_engine_t engine);
26+
27+
namespace dnnl {
28+
29+
struct conv_params_t {
30+
memory::dim MB, IC, OC, IH, OH, KH;
31+
};
32+
33+
// This is a regression test for PVC write-after-read hardware bug workaround.
34+
// The bug manifests as a page fault caused by WAR-related corruption of the
35+
// send header. The test doesn't include any validation, the expected failure
36+
// is a GPU page fault and test segfault.
37+
class test_regression_conv_pvc_war_t
38+
: public ::testing::TestWithParam<conv_params_t> {
39+
conv_params_t params;
40+
engine eng;
41+
42+
protected:
43+
void SetUp() override {
44+
SKIP_IF_CUDA(true, "Unsupported test for CUDA.");
45+
SKIP_IF_HIP(true, "Unsupported test for HIP.");
46+
SKIP_IF_GENERIC(true, "Unsupported test for generic GPU.");
47+
SKIP_IF(engine::get_count(engine::kind::gpu) == 0,
48+
"GPU engine not found.");
49+
50+
eng = engine(engine::kind::gpu, 0);
51+
SKIP_IF(dnnl_impl_gpu_intel_get_isa_name(eng.get())
52+
!= std::string("xe_hpc"),
53+
"Test is for PVC only");
54+
55+
params = ::testing::TestWithParam<decltype(params)>::GetParam();
56+
Test();
57+
}
58+
59+
void Test() {
60+
memory::dims src_dims = {params.MB, params.IC, params.IH, params.IH};
61+
memory::dims wei_dims = {params.OC, params.IC, params.KH, params.KH};
62+
memory::dims dst_dims = {params.MB, params.OC, params.OH, params.OH};
63+
memory::dims strides = {1, 1};
64+
memory::dims padding = {1, 1};
65+
66+
memory::desc src_md(
67+
src_dims, memory::data_type::f64, memory::format_tag::nchw);
68+
memory::desc wei_md(
69+
wei_dims, memory::data_type::f64, memory::format_tag::oihw);
70+
memory::desc dst_md(
71+
dst_dims, memory::data_type::f64, memory::format_tag::nchw);
72+
73+
convolution_forward::primitive_desc hint_fwd_pd(eng,
74+
prop_kind::forward_training, algorithm::convolution_direct,
75+
src_md, wei_md, dst_md, strides, padding, padding);
76+
convolution_backward_data::primitive_desc pd(eng,
77+
algorithm::convolution_direct, src_md, wei_md, dst_md, strides,
78+
padding, padding, hint_fwd_pd);
79+
convolution_backward_data prim(pd);
80+
81+
auto dst_mem_desc = pd.diff_dst_desc();
82+
auto wei_mem_desc = pd.weights_desc();
83+
auto src_mem_desc = pd.diff_src_desc();
84+
85+
memory dst_mem(dst_mem_desc, eng);
86+
memory wei_mem(wei_mem_desc, eng);
87+
memory src_mem(src_mem_desc, eng);
88+
89+
stream strm(eng);
90+
91+
const int REPEATS = 10;
92+
for (int i = 0; i < REPEATS; ++i) {
93+
prim.execute(strm,
94+
{{DNNL_ARG_DIFF_DST, dst_mem}, {DNNL_ARG_WEIGHTS, wei_mem},
95+
{DNNL_ARG_DIFF_SRC, src_mem}});
96+
}
97+
strm.wait();
98+
}
99+
};
100+
101+
TEST_P(test_regression_conv_pvc_war_t, Tests) {}
102+
103+
GPU_INSTANTIATE_TEST_SUITE_P(All, test_regression_conv_pvc_war_t,
104+
::testing::Values(conv_params_t {8, 32, 64, 128, 128, 3},
105+
conv_params_t {1, 64, 64, 256, 256, 3}));
106+
107+
} // namespace dnnl

0 commit comments

Comments
 (0)