forked from oneapi-src/level-zero
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzer_nullddi.cpp
More file actions
170 lines (142 loc) · 5.82 KB
/
zer_nullddi.cpp
File metadata and controls
170 lines (142 loc) · 5.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
*
* Copyright (C) 2019-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
* @file zer_nullddi.cpp
*
*/
#include "ze_null.h"
#include <cstring>
namespace driver
{
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zerGetLastErrorDescription
__zedlllocal ze_result_t ZE_APICALL
zerGetLastErrorDescription(
const char** ppString ///< [in,out] pointer to a null-terminated array of characters describing
///< cause of error.
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
// if the driver has created a custom function, then call it instead of using the generic path
auto pfnGetLastErrorDescription = context.zerDdiTable.Global.pfnGetLastErrorDescription;
if( nullptr != pfnGetLastErrorDescription )
{
result = pfnGetLastErrorDescription( ppString );
}
else
{
// generic implementation
}
char *env_str = context.setenv_var_with_driver_id("zerGetLastErrorDescription", ZEL_NULL_DRIVER_ID);
context.env_vars.push_back(env_str);
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zerTranslateDeviceHandleToIdentifier
__zedlllocal uint32_t ZE_APICALL
zerTranslateDeviceHandleToIdentifier(
ze_device_handle_t hDevice ///< [in] handle of the device
)
{
uint32_t result {};
// if the driver has created a custom function, then call it instead of using the generic path
auto pfnTranslateDeviceHandleToIdentifier = context.zerDdiTable.Global.pfnTranslateDeviceHandleToIdentifier;
if( nullptr != pfnTranslateDeviceHandleToIdentifier )
{
result = pfnTranslateDeviceHandleToIdentifier( hDevice );
}
else
{
// generic implementation
}
char *env_str = context.setenv_var_with_driver_id("zerTranslateDeviceHandleToIdentifier", ZEL_NULL_DRIVER_ID);
context.env_vars.push_back(env_str);
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zerTranslateIdentifierToDeviceHandle
__zedlllocal ze_device_handle_t ZE_APICALL
zerTranslateIdentifierToDeviceHandle(
uint32_t identifier ///< [in] integer identifier of the device
)
{
ze_device_handle_t result {};
// if the driver has created a custom function, then call it instead of using the generic path
auto pfnTranslateIdentifierToDeviceHandle = context.zerDdiTable.Global.pfnTranslateIdentifierToDeviceHandle;
if( nullptr != pfnTranslateIdentifierToDeviceHandle )
{
result = pfnTranslateIdentifierToDeviceHandle( identifier );
}
else
{
// generic implementation
}
char *env_str = context.setenv_var_with_driver_id("zerTranslateIdentifierToDeviceHandle", ZEL_NULL_DRIVER_ID);
context.env_vars.push_back(env_str);
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zerGetDefaultContext
__zedlllocal ze_context_handle_t ZE_APICALL
zerGetDefaultContext(
void
)
{
ze_context_handle_t result {};
// if the driver has created a custom function, then call it instead of using the generic path
auto pfnGetDefaultContext = context.zerDdiTable.Global.pfnGetDefaultContext;
if( nullptr != pfnGetDefaultContext )
{
result = pfnGetDefaultContext( );
}
else
{
// generic implementation
}
char *env_str = context.setenv_var_with_driver_id("zerGetDefaultContext", ZEL_NULL_DRIVER_ID);
context.env_vars.push_back(env_str);
return result;
}
} // namespace driver
#if defined(__cplusplus)
extern "C" {
#endif
///////////////////////////////////////////////////////////////////////////////
/// @brief Exported function for filling application's Global table
/// with current process' addresses
///
/// @returns
/// - ::ZE_RESULT_SUCCESS
/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER
/// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION
ZE_DLLEXPORT ze_result_t ZE_APICALL
zerGetGlobalProcAddrTable(
ze_api_version_t version, ///< [in] API version requested
zer_global_dditable_t* pDdiTable ///< [in,out] pointer to table of DDI function pointers
)
{
auto zer_api_disable = getenv_string( "ZEL_TEST_NULL_DRIVER_DISABLE_ZER_API" );
#ifndef ZEL_NULL_DRIVER_ID
#define ZEL_NULL_DRIVER_ID 1
#endif
std::string null_driver_id_str = std::to_string(ZEL_NULL_DRIVER_ID);
auto zer_api_unsupported = (zer_api_disable == null_driver_id_str);
if(zer_api_unsupported)
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
if( nullptr == pDdiTable )
return ZE_RESULT_ERROR_INVALID_NULL_POINTER;
if (ZE_MAJOR_VERSION(driver::context.version) != ZE_MAJOR_VERSION(version))
return ZE_RESULT_ERROR_UNSUPPORTED_VERSION;
ze_result_t result = ZE_RESULT_SUCCESS;
pDdiTable->pfnGetLastErrorDescription = driver::zerGetLastErrorDescription;
pDdiTable->pfnTranslateDeviceHandleToIdentifier = driver::zerTranslateDeviceHandleToIdentifier;
pDdiTable->pfnTranslateIdentifierToDeviceHandle = driver::zerTranslateIdentifierToDeviceHandle;
pDdiTable->pfnGetDefaultContext = driver::zerGetDefaultContext;
return result;
}
#if defined(__cplusplus)
};
#endif