Skip to content

Commit 0ecf73c

Browse files
committed
Init certification checker
Signed-off-by: Kozlowski, Marek <marek.kozlowski@intel.com>
1 parent ec7b3f2 commit 0ecf73c

11 files changed

Lines changed: 2783 additions & 1 deletion

File tree

scripts/generate_code.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ def _mako_loader_cpp(path, namespace, tags, version, specs, meta):
163163
'param.cpp.mako' : ('checkers/parameter_validation', 'parameter_validation.cpp'),
164164
'param.h.mako' : ('checkers/parameter_validation', 'parameter_validation.h'),
165165
'handle_lifetime.h.mako' : ('handle_lifetime_tracking', 'handle_lifetime.h'),
166-
'handle_lifetime.cpp.mako' : ('handle_lifetime_tracking', 'handle_lifetime.cpp')
166+
'handle_lifetime.cpp.mako' : ('handle_lifetime_tracking', 'handle_lifetime.cpp'),
167+
'certification.h.mako' : ('checkers/certification/generated', 'certification.h'),
167168
}
168169

169170
def _mako_validation_layer_cpp(path, namespace, tags, version, specs, meta):
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<%!
2+
from templates import helper as th
3+
%><%
4+
n=namespace
5+
N=n.upper()
6+
%>/*
7+
* ***THIS FILE IS GENERATED. ***
8+
*
9+
* Copyright (C) 2025 Intel Corporation
10+
*
11+
* SPDX-License-Identifier: MIT
12+
*
13+
* @file ${name}
14+
*
15+
*/
16+
#pragma once
17+
#include "../zel_global_certification_state.h"
18+
#include "${n}_entry_points.h"
19+
20+
namespace validation_layer {
21+
class ${N}certificationCheckerGenerated : public ${N}ValidationEntryPoints {
22+
public:
23+
%for obj in th.extract_objs(specs, r"function"):
24+
virtual ze_result_t ${th.make_func_name(n, tags, obj)}Prologue( \
25+
%for line in th.make_param_lines(n, tags, obj, format=["type", "name", "delim"]):
26+
${line} \
27+
%endfor
28+
) override {
29+
if (GlobalCertificationState::getInstance().certification_version < ${th.get_version(obj)}) {
30+
return ZE_RESULT_ERROR_UNSUPPORTED_VERSION;
31+
}
32+
return ZE_RESULT_SUCCESS;
33+
}
34+
%endfor
35+
};
36+
} // namespace validation_layer

source/layers/validation/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ By default, no validation modes will be enabled. The individual validation modes
2121
- `ZEL_ENABLE_EVENTS_CHECKER`
2222
- `ZEL_ENABLE_BASIC_LEAK_CHECKER`
2323
- `ZE_ENABLE_THREADING_VALIDATION` (Not yet Implemented)
24+
- `ZEL_ENABLE_CERTIFICATION_CHECKER`
2425

2526
## Validation Modes
2627

@@ -83,6 +84,10 @@ Basic leak checker in the validation layer which tracks the Create and Destroy c
8384
Validates:
8485
- Objects are not concurrently reused in free-threaded API calls
8586

87+
### `ZEL_ENABLE_CERTIFICATION_CHECKER`
88+
89+
When this mode is enabled, the certification checker validates API usage against the version supported by the driver or an explicitly specified version.
90+
If an API is used that was introduced in a version higher than the supported version, the checker will return `ZE_RESULT_ERROR_UNSUPPORTED_VERSION`.
8691

8792

8893
## Testing
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright (C) 2025 Intel Corporation
2+
# SPDX-License-Identifier: MIT
3+
4+
target_sources(${TARGET_NAME}
5+
PRIVATE
6+
${CMAKE_CURRENT_LIST_DIR}/zel_certification_checker.h
7+
${CMAKE_CURRENT_LIST_DIR}/zel_certification_checker.cpp
8+
${CMAKE_CURRENT_LIST_DIR}/zel_global_certification_state.h
9+
${CMAKE_CURRENT_LIST_DIR}/generated/ze_certification.h
10+
${CMAKE_CURRENT_LIST_DIR}/generated/zes_certification.h
11+
${CMAKE_CURRENT_LIST_DIR}/generated/zet_certification.h
12+
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Certification Checker
2+
3+
## Description
4+
The Certification Checker is a validation layer component designed to ensure that API usage conforms to a specific version supported by the driver.
5+
Its primary function is to restrict the use of APIs to those that are available in the version reported by the driver or a version explicitly specified by the user.
6+
If an attempt is made to use an API introduced in a later version, the checker shall return `ZE_RESULT_ERROR_UNSUPPORTED_VERSION`.
7+
8+
When enabled, the checker intercepts API calls and compares the version of each API used against the version supported by the driver.
9+
There are two modes:
10+
- **Default:**
11+
The supported version is, by default, set to the loader's defined `ZE_API_VERSION_CURRENT`.
12+
It is updated to the driver’s reported version once `zeDriverGetApiVersion` is first called.
13+
- **Explicit:**
14+
The version can be overridden by setting the `ZEL_CERTIFICATION_CHECKER_VERSION` environment variable to a value of `<major>.<minor>`. Once set, the version returned by `zeDriverGetApiVersion` is ignored.
15+
For example, to restrict API usage to version 1.6:
16+
`export ZEL_CERTIFICATION_CHECKER_VERSION=1.6`

source/layers/validation/checkers/certification/generated/ze_certification.h

Lines changed: 1237 additions & 0 deletions
Large diffs are not rendered by default.

source/layers/validation/checkers/certification/generated/zes_certification.h

Lines changed: 913 additions & 0 deletions
Large diffs are not rendered by default.

source/layers/validation/checkers/certification/generated/zet_certification.h

Lines changed: 433 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (C) 2025 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
* @file zel_certification_checker.cpp
7+
*
8+
*/
9+
#include "zel_certification_checker.h"
10+
#include "ze_api.h"
11+
12+
namespace validation_layer {
13+
class certificationChecker certification_checker;
14+
using ze_checker = certificationChecker::ZEcertificationChecker;
15+
16+
certificationChecker::certificationChecker() {
17+
enablecertification = getenv_tobool("ZEL_ENABLE_CERTIFICATION_CHECKER");
18+
if (enablecertification) {
19+
certificationChecker::ZEcertificationChecker *zeChecker =
20+
new certificationChecker::ZEcertificationChecker;
21+
certificationChecker::ZEScertificationChecker *zesChecker =
22+
new certificationChecker::ZEScertificationChecker;
23+
certificationChecker::ZETcertificationChecker *zetChecker =
24+
new certificationChecker::ZETcertificationChecker;
25+
ze_api_version_t certification_version = ZE_API_VERSION_CURRENT;
26+
const auto certification_version_string =
27+
getenv_string("ZEL_CERTIFICATION_CHECKER_VERSION");
28+
if (!certification_version_string.empty()) {
29+
const auto major = certification_version_string.substr(
30+
0, certification_version_string.find('.'));
31+
const auto minor = certification_version_string.substr(
32+
certification_version_string.find('.') + 1);
33+
certification_version = static_cast<ze_api_version_t>(
34+
ZE_MAKE_VERSION(std::stoi(major), std::stoi(minor)));
35+
globalCertificationState.default_mode = false;
36+
}
37+
globalCertificationState.certification_version = certification_version;
38+
certification_checker.zeValidation = zeChecker;
39+
certification_checker.zetValidation = zetChecker;
40+
certification_checker.zesValidation = zesChecker;
41+
validation_layer::context.validationHandlers.push_back(
42+
&certification_checker);
43+
}
44+
}
45+
46+
certificationChecker::~certificationChecker() {
47+
if (enablecertification) {
48+
delete certification_checker.zeValidation;
49+
delete certification_checker.zetValidation;
50+
delete certification_checker.zesValidation;
51+
}
52+
}
53+
54+
ze_result_t ze_checker::zeDriverGetApiVersionEpilogue(
55+
ze_driver_handle_t hDriver, ze_api_version_t *version, ze_result_t result) {
56+
auto &globalCertificationState = GlobalCertificationState::getInstance();
57+
if (result == ZE_RESULT_SUCCESS && version != nullptr &&
58+
globalCertificationState.default_mode) {
59+
globalCertificationState.certification_version = *version;
60+
}
61+
return ZE_RESULT_SUCCESS;
62+
}
63+
64+
} // namespace validation_layer
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
*
3+
* Copyright (C) 2025 Intel Corporation
4+
*
5+
* SPDX-License-Identifier: MIT
6+
*
7+
* @file zel_certification_checker.h
8+
*
9+
*/
10+
11+
#pragma once
12+
13+
#include "generated/ze_certification.h"
14+
#include "generated/zes_certification.h"
15+
#include "generated/zet_certification.h"
16+
#include "ze_api.h"
17+
#include "ze_validation_layer.h"
18+
#include "zel_global_certification_state.h"
19+
20+
namespace validation_layer {
21+
22+
class __zedlllocal certificationChecker : public validationChecker {
23+
public:
24+
certificationChecker();
25+
~certificationChecker();
26+
class ZEcertificationChecker : public ZEcertificationCheckerGenerated {
27+
ze_result_t zeDriverGetApiVersionEpilogue(ze_driver_handle_t hDriver,
28+
ze_api_version_t *version,
29+
ze_result_t result) override;
30+
};
31+
class ZEScertificationChecker : public ZEScertificationCheckerGenerated {};
32+
class ZETcertificationChecker : public ZETcertificationCheckerGenerated {};
33+
34+
bool enablecertification = false;
35+
36+
GlobalCertificationState &globalCertificationState =
37+
GlobalCertificationState::getInstance();
38+
};
39+
extern class certificationChecker certification_checker;
40+
} // namespace validation_layer

0 commit comments

Comments
 (0)