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 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571
|
// Copyright 2020-2024 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
#include "ze_mock.h"
#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
namespace ispcrt {
namespace testing {
namespace mock {
namespace driver {
#define MOCK_RET return Config::getRetValue(__FUNCTION__)
#define MOCK_SHOULD_SUCCEED (Config::getRetValue(__FUNCTION__) == ZE_RESULT_SUCCESS)
#define MOCK_CNT_CALL CallCounters::inc(__FUNCTION__)
static unsigned MockHandleHandle = 1;
template <typename HT> struct MockHandle {
HT get() { return handle; }
MockHandle() { handle = reinterpret_cast<HT>(MockHandleHandle++); }
private:
HT handle;
};
MockHandle<ze_device_handle_t> DeviceHandle;
MockHandle<ze_context_handle_t> ContextHandle;
MockHandle<ze_module_handle_t> ModuleHandle;
MockHandle<ze_kernel_handle_t> KernelHandle;
MockHandle<ze_command_list_handle_t> CmdListHandle;
MockHandle<ze_command_queue_handle_t> CmdQueueHandle;
MockHandle<ze_event_pool_handle_t> EventPoolHandle;
MockHandle<ze_event_handle_t> LaunchEventHandle;
MockHandle<ze_fence_handle_t> FenceHandle;
bool ExpectedDevice(ze_device_handle_t hDevice) {
auto dp = reinterpret_cast<DeviceProperties *>(hDevice);
return dp == Config::getDevicePtr(Config::getExpectedDevice());
}
bool ValidDevice(ze_device_handle_t hDevice) {
auto dp = reinterpret_cast<DeviceProperties *>(hDevice);
for (int i = 0; i < Config::getDeviceCount(); i++)
if (dp == Config::getDevicePtr(i))
return true;
return false;
}
ze_result_t zeInit(ze_init_flags_t flags) { MOCK_RET; }
ze_result_t zeDriverGet(uint32_t *pCount, ze_driver_handle_t *phDrivers) {
MOCK_CNT_CALL;
if (*pCount == 0) {
*pCount = 1;
}
// Should always succeed - error handling is done by Level Zero loader
return ZE_RESULT_SUCCESS;
}
ze_result_t zeDeviceGet(ze_driver_handle_t hDriver, uint32_t *pCount, ze_device_handle_t *phDevices) {
MOCK_CNT_CALL;
*pCount = Config::getDeviceCount();
if (phDevices) {
for (int i = 0; i < *pCount; i++) {
phDevices[i] = reinterpret_cast<ze_device_handle_t>(Config::getDevicePtr(i));
}
}
MOCK_RET;
}
ze_result_t zeDeviceGetProperties(ze_device_handle_t hDevice, ze_device_properties_t *pDeviceProperties) {
MOCK_CNT_CALL;
if (!ValidDevice(hDevice) || pDeviceProperties == nullptr)
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
auto dp = reinterpret_cast<DeviceProperties *>(hDevice);
pDeviceProperties->stype = ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES;
pDeviceProperties->type = ZE_DEVICE_TYPE_GPU;
pDeviceProperties->deviceId = dp->deviceId;
pDeviceProperties->vendorId = dp->vendorId;
const std::string MOCK_NAME{"ISPCRT Mock Device"};
std::copy(MOCK_NAME.cbegin(), MOCK_NAME.cend(), pDeviceProperties->name);
MOCK_RET;
}
ze_result_t zeContextCreate(ze_driver_handle_t hDriver, const ze_context_desc_t *desc, ze_context_handle_t *phContext) {
MOCK_CNT_CALL;
*phContext = ContextHandle.get();
MOCK_RET;
}
ze_result_t zeContextDestroy(ze_context_handle_t hContext) {
MOCK_CNT_CALL;
if (hContext != ContextHandle.get())
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
MOCK_RET;
}
ze_result_t zeCommandQueueCreate(ze_context_handle_t hContext, ze_device_handle_t hDevice,
const ze_command_queue_desc_t *desc, ze_command_queue_handle_t *phCommandQueue) {
MOCK_CNT_CALL;
if (!ExpectedDevice(hDevice) || hContext != ContextHandle.get() || desc == nullptr || phCommandQueue == nullptr)
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
*phCommandQueue = CmdQueueHandle.get();
MOCK_RET;
}
ze_result_t zeCommandQueueDestroy(ze_command_queue_handle_t hCommandQueue) {
MOCK_CNT_CALL;
if (hCommandQueue != CmdQueueHandle.get())
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
MOCK_RET;
}
ze_result_t zeCommandQueueExecuteCommandLists(ze_command_queue_handle_t hCommandQueue, uint32_t numCommandLists,
ze_command_list_handle_t *phCommandLists, ze_fence_handle_t hFence) {
MOCK_CNT_CALL;
if (hCommandQueue != CmdQueueHandle.get() || !Config::isCmdListClosed())
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
MOCK_RET;
}
ze_result_t zeCommandQueueSynchronize(ze_command_queue_handle_t hCommandQueue, uint64_t timeout) {
MOCK_CNT_CALL;
if (hCommandQueue != CmdQueueHandle.get() || !Config::isCmdListClosed())
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
MOCK_RET;
}
ze_result_t zeCommandListCreate(ze_context_handle_t hContext, ze_device_handle_t hDevice,
const ze_command_list_desc_t *desc, ze_command_list_handle_t *phCommandList) {
MOCK_CNT_CALL;
if (!ExpectedDevice(hDevice) || hContext != ContextHandle.get() || desc == nullptr || phCommandList == nullptr)
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
*phCommandList = CmdListHandle.get();
MOCK_RET;
}
ze_result_t zeCommandListDestroy(ze_command_list_handle_t hCommandList) {
MOCK_CNT_CALL;
if (hCommandList != CmdListHandle.get())
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
MOCK_RET;
}
ze_result_t zeCommandListClose(ze_command_list_handle_t hCommandList) {
MOCK_CNT_CALL;
if (hCommandList != CmdListHandle.get())
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
Config::closeCmdList();
MOCK_RET;
}
ze_result_t zeCommandListReset(ze_command_list_handle_t hCommandList) {
MOCK_CNT_CALL;
if (hCommandList != CmdListHandle.get())
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
Config::resetCmdList();
MOCK_RET;
}
ze_result_t zeCommandListAppendBarrier(ze_command_list_handle_t hCommandList, ze_event_handle_t hSignalEvent,
uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents) {
MOCK_CNT_CALL;
if (hCommandList != CmdListHandle.get() || Config::isCmdListClosed())
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
if (MOCK_SHOULD_SUCCEED)
Config::addToCmdList(CmdListElem::Barrier);
MOCK_RET;
}
ze_result_t zeCommandListAppendMemoryCopy(ze_command_list_handle_t hCommandList, void *dstptr, const void *srcptr,
size_t size, ze_event_handle_t hSignalEvent, uint32_t numWaitEvents,
ze_event_handle_t *phWaitEvents) {
MOCK_CNT_CALL;
if (hCommandList != CmdListHandle.get() || Config::isCmdListClosed())
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
if (MOCK_SHOULD_SUCCEED)
Config::addToCmdList(CmdListElem::MemoryCopy);
MOCK_RET;
}
ze_result_t zeEventPoolCreate(ze_context_handle_t hContext, const ze_event_pool_desc_t *desc, uint32_t numDevices,
ze_device_handle_t *phDevices, ze_event_pool_handle_t *phEventPool) {
MOCK_CNT_CALL;
if (hContext != ContextHandle.get() || numDevices == 0 || !phDevices || !phEventPool)
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
*phEventPool = EventPoolHandle.get();
MOCK_RET;
}
ze_result_t zeEventPoolDestroy(ze_event_pool_handle_t hEventPool) {
MOCK_CNT_CALL;
if (hEventPool != EventPoolHandle.get())
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
MOCK_RET;
}
ze_result_t zeEventCreate(ze_event_pool_handle_t hEventPool, const ze_event_desc_t *desc, ze_event_handle_t *phEvent) {
MOCK_CNT_CALL;
if (hEventPool != EventPoolHandle.get() || !desc || !phEvent)
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
*phEvent = LaunchEventHandle.get();
MOCK_RET;
}
ze_result_t zeEventDestroy(ze_event_handle_t hEvent) {
MOCK_CNT_CALL;
MOCK_RET;
}
ze_result_t zeEventQueryStatus(ze_event_handle_t hEvent) {
MOCK_CNT_CALL;
MOCK_RET;
}
ze_result_t zeEventQueryKernelTimestamp(ze_event_handle_t hEvent, ze_kernel_timestamp_result_t *dstptr) {
MOCK_CNT_CALL;
MOCK_RET;
}
ze_result_t zeEventHostReset(ze_event_handle_t hEvent) {
MOCK_CNT_CALL;
MOCK_RET;
}
static int fenceSignalTimerCounter = 0;
ze_result_t zeFenceCreate(ze_command_queue_handle_t hCommandQueue, const ze_fence_desc_t *desc,
ze_fence_handle_t *phFence) {
MOCK_CNT_CALL;
if (hCommandQueue != CmdQueueHandle.get() || !desc || !phFence)
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
*phFence = FenceHandle.get();
fenceSignalTimerCounter = 0;
MOCK_RET;
}
ze_result_t zeFenceReset(ze_fence_handle_t hFence) {
MOCK_CNT_CALL;
if (hFence != FenceHandle.get())
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
fenceSignalTimerCounter = 0;
MOCK_RET;
}
ze_result_t zeFenceQueryStatus(ze_fence_handle_t hFence) {
MOCK_CNT_CALL;
if (hFence != FenceHandle.get())
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
return (fenceSignalTimerCounter++ >= 5) ? ZE_RESULT_SUCCESS : ZE_RESULT_NOT_READY;
}
ze_result_t zeFenceHostSynchronize(ze_fence_handle_t hFence, uint64_t timeout) {
MOCK_CNT_CALL;
if (hFence != FenceHandle.get())
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
fenceSignalTimerCounter = 5;
MOCK_RET;
}
ze_result_t zeFenceDestroy(ze_fence_handle_t hFence) {
MOCK_CNT_CALL;
if (hFence != FenceHandle.get())
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
fenceSignalTimerCounter = 0;
MOCK_RET;
}
ze_result_t zeMemAllocDevice(ze_context_handle_t hContext, const ze_device_mem_alloc_desc_t *device_desc, size_t size,
size_t alignment, ze_device_handle_t hDevice, void **pptr) {
MOCK_CNT_CALL;
if (hContext != ContextHandle.get())
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
if (MOCK_SHOULD_SUCCEED)
*pptr = new uint8_t[size];
MOCK_RET;
}
ze_result_t zeMemAllocShared(ze_context_handle_t hContext, const ze_device_mem_alloc_desc_t *device_desc,
const ze_host_mem_alloc_desc_t *host_desc, size_t size, size_t alignment,
ze_device_handle_t hDevice, void **pptr) {
MOCK_CNT_CALL;
if (hContext != ContextHandle.get())
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
if (MOCK_SHOULD_SUCCEED)
*pptr = new uint8_t[size];
MOCK_RET;
}
ze_result_t zeMemFree(ze_context_handle_t hContext, void *ptr) {
MOCK_CNT_CALL;
if (hContext != ContextHandle.get() || !ptr)
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
delete[] (uint8_t *)ptr;
MOCK_RET;
}
ze_result_t zeModuleCreate(ze_context_handle_t hContext, ze_device_handle_t hDevice, const ze_module_desc_t *desc,
ze_module_handle_t *phModule, ze_module_build_log_handle_t *phBuildLog) {
MOCK_CNT_CALL;
if (hContext != ContextHandle.get() || !ExpectedDevice(hDevice))
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
*phModule = ModuleHandle.get();
MOCK_RET;
}
ze_result_t zeModuleDestroy(ze_module_handle_t hModule) {
MOCK_CNT_CALL;
if (hModule != ModuleHandle.get())
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
MOCK_RET;
}
ze_result_t zeModuleDynamicLink(uint32_t numModules, ze_module_handle_t *phModules,
ze_module_build_log_handle_t *phLinkLog) {
MOCK_CNT_CALL;
if (phModules == nullptr)
return ZE_RESULT_ERROR_INVALID_NULL_POINTER;
MOCK_RET;
}
ze_result_t zeModuleBuildLogGetString(ze_module_build_log_handle_t hModuleBuildLog, size_t *pSize, char *pBuildLog) {
MOCK_CNT_CALL;
*pSize = 0;
MOCK_RET;
}
ze_result_t zeModuleBuildLogDestroy(ze_module_build_log_handle_t hModuleBuildLog) {
MOCK_CNT_CALL;
if (hModuleBuildLog == nullptr)
return ZE_RESULT_ERROR_UNINITIALIZED;
MOCK_RET;
}
static void *pfnFunctionMem = nullptr;
ze_result_t zeModuleGetFunctionPointer(ze_module_handle_t hModule, const char *pFunctionName, void **pfnFunction) {
MOCK_CNT_CALL;
if (hModule != ModuleHandle.get())
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
if (pFunctionName == nullptr)
return ZE_RESULT_ERROR_INVALID_NULL_POINTER;
*pfnFunction = &pfnFunctionMem;
MOCK_RET;
}
ze_result_t zeKernelCreate(ze_module_handle_t hModule, const ze_kernel_desc_t *desc, ze_kernel_handle_t *phKernel) {
MOCK_CNT_CALL;
if (hModule != ModuleHandle.get())
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
*phKernel = KernelHandle.get();
MOCK_RET;
}
ze_result_t zeKernelDestroy(ze_kernel_handle_t hKernel) {
MOCK_CNT_CALL;
if (hKernel != KernelHandle.get())
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
MOCK_RET;
}
ze_result_t zeKernelSetArgumentValue(ze_kernel_handle_t hKernel, uint32_t argIndex, size_t argSize,
const void *pArgValue) {
MOCK_CNT_CALL;
MOCK_RET;
}
ze_result_t zeKernelSetIndirectAccess(ze_kernel_handle_t hKernel, ze_kernel_indirect_access_flags_t) {
MOCK_CNT_CALL;
MOCK_RET;
}
ze_result_t zeKernelSuggestGroupSize(ze_kernel_handle_t hKernel, uint32_t globalSizeX, uint32_t globalSizeY,
uint32_t globalSizeZ, uint32_t *groupSizeX, uint32_t *groupSizeY,
uint32_t *groupSizeZ) {
MOCK_CNT_CALL;
if (hKernel != KernelHandle.get()) {
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
}
if (groupSizeX == nullptr || groupSizeY == nullptr || groupSizeZ == nullptr) {
return ZE_RESULT_ERROR_INVALID_NULL_POINTER;
}
*groupSizeX = 1;
*groupSizeY = 1;
*groupSizeZ = 1;
MOCK_RET;
}
ze_result_t zeKernelSetGroupSize(ze_kernel_handle_t hKernel, uint32_t groupSizeX, uint32_t groupSizeY,
uint32_t groupSizeZ) {
MOCK_CNT_CALL;
if (hKernel != KernelHandle.get()) {
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
}
MOCK_RET;
}
ze_result_t zeCommandListAppendLaunchKernel(ze_command_list_handle_t hCommandList, ze_kernel_handle_t hKernel,
const ze_group_count_t *pLaunchFuncArgs, ze_event_handle_t hSignalEvent,
uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents) {
MOCK_CNT_CALL;
if (hCommandList != CmdListHandle.get() || hKernel != KernelHandle.get() || !pLaunchFuncArgs)
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
if (MOCK_SHOULD_SUCCEED)
Config::addToCmdList(CmdListElem::KernelLaunch);
MOCK_RET;
}
} // namespace driver
} // namespace mock
} // namespace testing
} // namespace ispcrt
#if defined(__cplusplus)
extern "C" {
#endif
ze_result_t zeGetGlobalProcAddrTable(ze_api_version_t version, ze_global_dditable_t *pDdiTable) {
pDdiTable->pfnInit = ispcrt::testing::mock::driver::zeInit;
return ZE_RESULT_SUCCESS;
}
ze_result_t zeGetDriverProcAddrTable(ze_api_version_t version, ze_driver_dditable_t *pDdiTable) {
pDdiTable->pfnGet = ispcrt::testing::mock::driver::zeDriverGet;
return ZE_RESULT_SUCCESS;
}
ze_result_t zeGetDeviceProcAddrTable(ze_api_version_t version, ze_device_dditable_t *pDdiTable) {
pDdiTable->pfnGet = ispcrt::testing::mock::driver::zeDeviceGet;
pDdiTable->pfnGetProperties = ispcrt::testing::mock::driver::zeDeviceGetProperties;
return ZE_RESULT_SUCCESS;
}
ze_result_t zeGetContextProcAddrTable(ze_api_version_t version, ze_context_dditable_t *pDdiTable) {
pDdiTable->pfnCreate = ispcrt::testing::mock::driver::zeContextCreate;
pDdiTable->pfnDestroy = ispcrt::testing::mock::driver::zeContextDestroy;
return ZE_RESULT_SUCCESS;
}
ze_result_t zeGetCommandQueueProcAddrTable(ze_api_version_t version, ze_command_queue_dditable_t *pDdiTable) {
pDdiTable->pfnCreate = ispcrt::testing::mock::driver::zeCommandQueueCreate;
pDdiTable->pfnDestroy = ispcrt::testing::mock::driver::zeCommandQueueDestroy;
pDdiTable->pfnExecuteCommandLists = ispcrt::testing::mock::driver::zeCommandQueueExecuteCommandLists;
pDdiTable->pfnSynchronize = ispcrt::testing::mock::driver::zeCommandQueueSynchronize;
return ZE_RESULT_SUCCESS;
}
ze_result_t zeGetCommandListProcAddrTable(ze_api_version_t version, ze_command_list_dditable_t *pDdiTable) {
pDdiTable->pfnCreate = ispcrt::testing::mock::driver::zeCommandListCreate;
pDdiTable->pfnDestroy = ispcrt::testing::mock::driver::zeCommandListDestroy;
pDdiTable->pfnClose = ispcrt::testing::mock::driver::zeCommandListClose;
pDdiTable->pfnReset = ispcrt::testing::mock::driver::zeCommandListReset;
pDdiTable->pfnAppendBarrier = ispcrt::testing::mock::driver::zeCommandListAppendBarrier;
pDdiTable->pfnAppendMemoryCopy = ispcrt::testing::mock::driver::zeCommandListAppendMemoryCopy;
pDdiTable->pfnAppendLaunchKernel = ispcrt::testing::mock::driver::zeCommandListAppendLaunchKernel;
return ZE_RESULT_SUCCESS;
}
ze_result_t zeGetEventProcAddrTable(ze_api_version_t version, ze_event_dditable_t *pDdiTable) {
pDdiTable->pfnCreate = ispcrt::testing::mock::driver::zeEventCreate;
pDdiTable->pfnDestroy = ispcrt::testing::mock::driver::zeEventDestroy;
pDdiTable->pfnQueryKernelTimestamp = ispcrt::testing::mock::driver::zeEventQueryKernelTimestamp;
pDdiTable->pfnQueryStatus = ispcrt::testing::mock::driver::zeEventQueryStatus;
pDdiTable->pfnHostReset = ispcrt::testing::mock::driver::zeEventHostReset;
return ZE_RESULT_SUCCESS;
}
ze_result_t zeGetEventPoolProcAddrTable(ze_api_version_t version, ze_event_pool_dditable_t *pDdiTable) {
pDdiTable->pfnCreate = ispcrt::testing::mock::driver::zeEventPoolCreate;
pDdiTable->pfnDestroy = ispcrt::testing::mock::driver::zeEventPoolDestroy;
return ZE_RESULT_SUCCESS;
}
ze_result_t zeGetKernelProcAddrTable(ze_api_version_t version, ze_kernel_dditable_t *pDdiTable) {
pDdiTable->pfnCreate = ispcrt::testing::mock::driver::zeKernelCreate;
pDdiTable->pfnDestroy = ispcrt::testing::mock::driver::zeKernelDestroy;
pDdiTable->pfnSetArgumentValue = ispcrt::testing::mock::driver::zeKernelSetArgumentValue;
pDdiTable->pfnSetIndirectAccess = ispcrt::testing::mock::driver::zeKernelSetIndirectAccess;
pDdiTable->pfnSetGroupSize = ispcrt::testing::mock::driver::zeKernelSetGroupSize;
pDdiTable->pfnSuggestGroupSize = ispcrt::testing::mock::driver::zeKernelSuggestGroupSize;
return ZE_RESULT_SUCCESS;
}
ze_result_t zeGetMemProcAddrTable(ze_api_version_t version, ze_mem_dditable_t *pDdiTable) {
pDdiTable->pfnAllocDevice = ispcrt::testing::mock::driver::zeMemAllocDevice;
pDdiTable->pfnAllocShared = ispcrt::testing::mock::driver::zeMemAllocShared;
pDdiTable->pfnFree = ispcrt::testing::mock::driver::zeMemFree;
return ZE_RESULT_SUCCESS;
}
ze_result_t zeGetModuleProcAddrTable(ze_api_version_t version, ze_module_dditable_t *pDdiTable) {
pDdiTable->pfnCreate = ispcrt::testing::mock::driver::zeModuleCreate;
pDdiTable->pfnDestroy = ispcrt::testing::mock::driver::zeModuleDestroy;
pDdiTable->pfnDynamicLink = ispcrt::testing::mock::driver::zeModuleDynamicLink;
pDdiTable->pfnGetFunctionPointer = ispcrt::testing::mock::driver::zeModuleGetFunctionPointer;
return ZE_RESULT_SUCCESS;
}
ze_result_t zeGetModuleBuildLogProcAddrTable(ze_api_version_t version, ze_module_build_log_dditable_t *pDdiTable) {
pDdiTable->pfnGetString = ispcrt::testing::mock::driver::zeModuleBuildLogGetString;
pDdiTable->pfnDestroy = ispcrt::testing::mock::driver::zeModuleBuildLogDestroy;
return ZE_RESULT_SUCCESS;
}
ze_result_t zeGetFenceProcAddrTable(ze_api_version_t version, ze_fence_dditable_t *pDdiTable) {
pDdiTable->pfnCreate = ispcrt::testing::mock::driver::zeFenceCreate;
pDdiTable->pfnQueryStatus = ispcrt::testing::mock::driver::zeFenceQueryStatus;
pDdiTable->pfnReset = ispcrt::testing::mock::driver::zeFenceReset;
pDdiTable->pfnHostSynchronize = ispcrt::testing::mock::driver::zeFenceHostSynchronize;
pDdiTable->pfnDestroy = ispcrt::testing::mock::driver::zeFenceDestroy;
return ZE_RESULT_SUCCESS;
}
#define MOCK_DDI_FUN(Fn, TT) \
ze_result_t Fn(ze_api_version_t version, TT *pDdiTable) { return ZE_RESULT_SUCCESS; }
MOCK_DDI_FUN(zeGetImageProcAddrTable, ze_image_dditable_t)
MOCK_DDI_FUN(zeGetPhysicalMemProcAddrTable, ze_physical_mem_dditable_t)
MOCK_DDI_FUN(zeGetSamplerProcAddrTable, ze_sampler_dditable_t)
MOCK_DDI_FUN(zeGetVirtualMemProcAddrTable, ze_virtual_mem_dditable_t)
// ZES
MOCK_DDI_FUN(zesGetDeviceProcAddrTable, zes_device_dditable_t)
MOCK_DDI_FUN(zesGetDriverProcAddrTable, zes_driver_dditable_t)
MOCK_DDI_FUN(zesGetDiagnosticsProcAddrTable, zes_diagnostics_dditable_t)
MOCK_DDI_FUN(zesGetEngineProcAddrTable, zes_engine_dditable_t)
MOCK_DDI_FUN(zesGetFabricPortProcAddrTable, zes_fabric_port_dditable_t)
MOCK_DDI_FUN(zesGetFanProcAddrTable, zes_fan_dditable_t)
MOCK_DDI_FUN(zesGetFirmwareProcAddrTable, zes_firmware_dditable_t)
MOCK_DDI_FUN(zesGetFrequencyProcAddrTable, zes_frequency_dditable_t)
MOCK_DDI_FUN(zesGetLedProcAddrTable, zes_led_dditable_t)
MOCK_DDI_FUN(zesGetMemoryProcAddrTable, zes_memory_dditable_t)
MOCK_DDI_FUN(zesGetPerformanceFactorProcAddrTable, zes_performance_factor_dditable_t)
MOCK_DDI_FUN(zesGetPowerProcAddrTable, zes_power_dditable_t)
MOCK_DDI_FUN(zesGetPsuProcAddrTable, zes_psu_dditable_t)
MOCK_DDI_FUN(zesGetRasProcAddrTable, zes_ras_dditable_t)
MOCK_DDI_FUN(zesGetSchedulerProcAddrTable, zes_scheduler_dditable_t)
MOCK_DDI_FUN(zesGetStandbyProcAddrTable, zes_standby_dditable_t)
MOCK_DDI_FUN(zesGetTemperatureProcAddrTable, zes_temperature_dditable_t)
// ZET
MOCK_DDI_FUN(zetGetDeviceProcAddrTable, zet_device_dditable_t)
MOCK_DDI_FUN(zetGetContextProcAddrTable, zet_context_dditable_t)
MOCK_DDI_FUN(zetGetCommandListProcAddrTable, zet_command_list_dditable_t)
MOCK_DDI_FUN(zetGetKernelProcAddrTable, zet_kernel_dditable_t)
MOCK_DDI_FUN(zetGetModuleProcAddrTable, zet_module_dditable_t)
MOCK_DDI_FUN(zetGetDebugProcAddrTable, zet_debug_dditable_t)
MOCK_DDI_FUN(zetGetMetricProcAddrTable, zet_metric_dditable_t)
MOCK_DDI_FUN(zetGetMetricGroupProcAddrTable, zet_metric_group_dditable_t)
MOCK_DDI_FUN(zetGetMetricQueryProcAddrTable, zet_metric_query_dditable_t)
MOCK_DDI_FUN(zetGetMetricQueryPoolProcAddrTable, zet_metric_query_pool_dditable_t)
MOCK_DDI_FUN(zetGetMetricStreamerProcAddrTable, zet_metric_streamer_dditable_t)
MOCK_DDI_FUN(zetGetTracerExpProcAddrTable, zet_tracer_exp_dditable_t)
#undef MOCK_DDI_FUN
#if defined(__cplusplus)
}
#endif
|