Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion scripts/generate_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ def _mako_loader_cpp(path, namespace, tags, version, specs, meta):
'param.cpp.mako' : ('checkers/parameter_validation', 'parameter_validation.cpp'),
'param.h.mako' : ('checkers/parameter_validation', 'parameter_validation.h'),
'handle_lifetime.h.mako' : ('handle_lifetime_tracking', 'handle_lifetime.h'),
'handle_lifetime.cpp.mako' : ('handle_lifetime_tracking', 'handle_lifetime.cpp')
'handle_lifetime.cpp.mako' : ('handle_lifetime_tracking', 'handle_lifetime.cpp'),
'certification.h.mako' : ('checkers/certification/generated', 'certification.h'),
}

def _mako_validation_layer_cpp(path, namespace, tags, version, specs, meta):
Expand Down
36 changes: 36 additions & 0 deletions scripts/templates/validation/certification.h.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<%!
from templates import helper as th
%><%
n=namespace
N=n.upper()
%>/*
* ***THIS FILE IS GENERATED. ***
*
* Copyright (C) 2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
* @file ${name}
*
*/
#pragma once
#include "../zel_global_certification_state.h"
#include "${n}_entry_points.h"

namespace validation_layer {
class ${N}certificationCheckerGenerated : public ${N}ValidationEntryPoints {
public:
%for obj in th.extract_objs(specs, r"function"):
virtual ze_result_t ${th.make_func_name(n, tags, obj)}Prologue( \
%for line in th.make_param_lines(n, tags, obj, format=["type", "name", "delim"]):
${line} \
%endfor
) override {
if (GlobalCertificationState::getInstance().certification_version < ${th.get_version(obj)}) {
return ZE_RESULT_ERROR_UNSUPPORTED_VERSION;
}
return ZE_RESULT_SUCCESS;
}
%endfor
};
} // namespace validation_layer
5 changes: 5 additions & 0 deletions source/layers/validation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ By default, no validation modes will be enabled. The individual validation modes
- `ZEL_ENABLE_EVENTS_CHECKER`
- `ZEL_ENABLE_BASIC_LEAK_CHECKER`
- `ZE_ENABLE_THREADING_VALIDATION` (Not yet Implemented)
- `ZEL_ENABLE_CERTIFICATION_CHECKER`

## Validation Modes

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

### `ZEL_ENABLE_CERTIFICATION_CHECKER`

When this mode is enabled, the certification checker validates API usage against the version supported by the driver or an explicitly specified version.
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`.


## Testing
Expand Down
12 changes: 12 additions & 0 deletions source/layers/validation/checkers/certification/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: MIT

target_sources(${TARGET_NAME}
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/zel_certification_checker.h
${CMAKE_CURRENT_LIST_DIR}/zel_certification_checker.cpp
${CMAKE_CURRENT_LIST_DIR}/zel_global_certification_state.h
${CMAKE_CURRENT_LIST_DIR}/generated/ze_certification.h
${CMAKE_CURRENT_LIST_DIR}/generated/zes_certification.h
${CMAKE_CURRENT_LIST_DIR}/generated/zet_certification.h
)
16 changes: 16 additions & 0 deletions source/layers/validation/checkers/certification/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Certification Checker

## Description
The Certification Checker is a validation layer component designed to ensure that API usage conforms to a specific version supported by the driver.
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.
If an attempt is made to use an API introduced in a later version, the checker shall return `ZE_RESULT_ERROR_UNSUPPORTED_VERSION`.

When enabled, the checker intercepts API calls and compares the version of each API used against the version supported by the driver.
There are two modes:
- **Default:**
The supported version is, by default, set to the loader's defined `ZE_API_VERSION_CURRENT`.
It is updated to the driver’s reported version once `zeDriverGetApiVersion` is first called.
- **Explicit:**
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.
For example, to restrict API usage to version 1.6:
`export ZEL_CERTIFICATION_CHECKER_VERSION=1.6`
1,237 changes: 1,237 additions & 0 deletions source/layers/validation/checkers/certification/generated/ze_certification.h

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (C) 2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
* @file zel_certification_checker.cpp
*
*/
#include "zel_certification_checker.h"
#include "ze_api.h"

namespace validation_layer {
class certificationChecker certification_checker;
using ze_checker = certificationChecker::ZEcertificationChecker;

certificationChecker::certificationChecker() {
enablecertification = getenv_tobool("ZEL_ENABLE_CERTIFICATION_CHECKER");
if (enablecertification) {
certificationChecker::ZEcertificationChecker *zeChecker =
new certificationChecker::ZEcertificationChecker;
certificationChecker::ZEScertificationChecker *zesChecker =
new certificationChecker::ZEScertificationChecker;
certificationChecker::ZETcertificationChecker *zetChecker =
new certificationChecker::ZETcertificationChecker;
ze_api_version_t certification_version = ZE_API_VERSION_CURRENT;
const auto certification_version_string =
getenv_string("ZEL_CERTIFICATION_CHECKER_VERSION");
if (!certification_version_string.empty()) {
const auto major = certification_version_string.substr(
0, certification_version_string.find('.'));
const auto minor = certification_version_string.substr(
certification_version_string.find('.') + 1);
certification_version = static_cast<ze_api_version_t>(
ZE_MAKE_VERSION(std::stoi(major), std::stoi(minor)));
globalCertificationState.default_mode = false;
}
globalCertificationState.certification_version = certification_version;
certification_checker.zeValidation = zeChecker;
certification_checker.zetValidation = zetChecker;
certification_checker.zesValidation = zesChecker;
validation_layer::context.validationHandlers.push_back(
&certification_checker);
}
}

certificationChecker::~certificationChecker() {
if (enablecertification) {
delete certification_checker.zeValidation;
delete certification_checker.zetValidation;
delete certification_checker.zesValidation;
}
}

ze_result_t ze_checker::zeDriverGetApiVersionEpilogue(
ze_driver_handle_t hDriver, ze_api_version_t *version, ze_result_t result) {
auto &globalCertificationState = GlobalCertificationState::getInstance();
if (result == ZE_RESULT_SUCCESS && version != nullptr &&
globalCertificationState.default_mode) {
globalCertificationState.certification_version = *version;
}
return ZE_RESULT_SUCCESS;
}

} // namespace validation_layer
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
*
* Copyright (C) 2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
* @file zel_certification_checker.h
*
*/

#pragma once

#include "generated/ze_certification.h"
#include "generated/zes_certification.h"
#include "generated/zet_certification.h"
#include "ze_api.h"
#include "ze_validation_layer.h"
#include "zel_global_certification_state.h"

namespace validation_layer {

class __zedlllocal certificationChecker : public validationChecker {
public:
certificationChecker();
~certificationChecker();
class ZEcertificationChecker : public ZEcertificationCheckerGenerated {
ze_result_t zeDriverGetApiVersionEpilogue(ze_driver_handle_t hDriver,
ze_api_version_t *version,
ze_result_t result) override;
};
class ZEScertificationChecker : public ZEScertificationCheckerGenerated {};
class ZETcertificationChecker : public ZETcertificationCheckerGenerated {};

bool enablecertification = false;

GlobalCertificationState &globalCertificationState =
GlobalCertificationState::getInstance();
};
extern class certificationChecker certification_checker;
} // namespace validation_layer
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
*
* Copyright (C) 2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
* @file zel_certification_checker.h
*
*/

#pragma once

#include "ze_api.h"

namespace validation_layer {
class GlobalCertificationState {
public:
static GlobalCertificationState &getInstance() {
static GlobalCertificationState instance;
return instance;
}
bool default_mode = true;
ze_api_version_t certification_version = ZE_API_VERSION_1_0;
};
} // namespace validation_layer
Loading