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 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
|
/*
* Copyright (C) 2024-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
* @file zel_events_checker.cpp
*
*/
#include "zel_events_checker.h"
#include <iostream>
#include <sstream>
namespace validation_layer {
class eventsChecker events_checker;
eventsChecker::eventsChecker() {
enableEvents = getenv_tobool("ZEL_ENABLE_EVENTS_CHECKER");
if (enableEvents) {
eventsChecker::ZEeventsChecker *zeChecker = new eventsChecker::ZEeventsChecker;
eventsChecker::ZESeventsChecker *zesChecker = new eventsChecker::ZESeventsChecker;
eventsChecker::ZETeventsChecker *zetChecker = new eventsChecker::ZETeventsChecker;
eventsChecker::ZEReventsChecker *zerChecker = new eventsChecker::ZEReventsChecker;
events_checker.zeValidation = zeChecker;
events_checker.zesValidation = zesChecker;
events_checker.zetValidation = zetChecker;
events_checker.zerValidation = zerChecker;
validation_layer::context.getInstance().validationHandlers.push_back(&events_checker);
}
}
eventsChecker::~eventsChecker() {
if (enableEvents) {
delete events_checker.zeValidation;
delete events_checker.zesValidation;
delete events_checker.zetValidation;
delete events_checker.zerValidation;
}
}
ze_result_t eventsChecker::ZEeventsChecker::zeEventCreateEpilogue(
ze_event_pool_handle_t hEventPool, ///< [in] handle of the event pool
const ze_event_desc_t *desc, ///< [in] pointer to event descriptor
ze_event_handle_t *phEvent, ///< [out] pointer to handle of event object created
ze_result_t result
) {
if(result != ZE_RESULT_SUCCESS) {
return ZE_RESULT_SUCCESS;
}
eventToDagID[*phEvent] = invalidDagID;
return ZE_RESULT_SUCCESS;
}
ze_result_t
eventsChecker::ZEeventsChecker::zeEventDestroyEpilogue(
ze_event_handle_t hEvent, ///< [in][release] handle of event object to destroy
ze_result_t result
) {
if(result != ZE_RESULT_SUCCESS) {
return ZE_RESULT_SUCCESS;
}
if (eventToDagID.find(hEvent) != eventToDagID.end()) {
// Delete event from eventToDagID but not from the dagIDToAction map as it may be needed for printing the discription of the action when printing path in the DAG.
eventToDagID.erase(hEvent);
}
return ZE_RESULT_SUCCESS;
}
ze_result_t
eventsChecker::ZEeventsChecker::zeCommandListAppendMemoryCopyPrologue(
ze_command_list_handle_t hCommandList, ///< [in] handle of command list
void *dstptr, ///< [in] pointer to destination memory to copy to
const void *srcptr, ///< [in] pointer to source memory to copy from
size_t size, ///< [in] size in bytes to copy
ze_event_handle_t hSignalEvent, ///< [in][optional] handle of the event to signal on completion
uint32_t numWaitEvents, ///< [in][optional] number of events to wait on before launching; must be 0
///< if `nullptr == phWaitEvents`
ze_event_handle_t *phWaitEvents ///< [in][optional][range(0, numWaitEvents)] handle of the events to wait
///< on before launching
) {
checkForDeadlock("zeCommandListAppendMemoryCopy", hSignalEvent, numWaitEvents, phWaitEvents);
return ZE_RESULT_SUCCESS;
}
ze_result_t
eventsChecker::ZEeventsChecker::zeCommandListAppendWriteGlobalTimestampPrologue(
ze_command_list_handle_t hCommandList, ///< [in] handle of the command list
uint64_t *dstptr, ///< [in,out] pointer to memory where timestamp value will be written; must
///< be 8byte-aligned.
ze_event_handle_t hSignalEvent, ///< [in][optional] handle of the event to signal on completion
uint32_t numWaitEvents, ///< [in][optional] number of events to wait on before executing query;
///< must be 0 if `nullptr == phWaitEvents`
ze_event_handle_t *phWaitEvents ///< [in][optional][range(0, numWaitEvents)] handle of the events to wait
///< on before executing query
) {
checkForDeadlock("zeCommandListAppendWriteGlobalTimestamp", hSignalEvent, numWaitEvents, phWaitEvents);
return ZE_RESULT_SUCCESS;
}
ze_result_t
eventsChecker::ZEeventsChecker::zeCommandListAppendBarrierPrologue(
ze_command_list_handle_t hCommandList, ///< [in] handle of the command list
ze_event_handle_t hSignalEvent, ///< [in][optional] handle of the event to signal on completion
uint32_t numWaitEvents, ///< [in][optional] number of events to wait on before executing barrier;
///< must be 0 if `nullptr == phWaitEvents`
ze_event_handle_t *phWaitEvents ///< [in][optional][range(0, numWaitEvents)] handle of the events to wait
///< on before executing barrier
) {
checkForDeadlock("zeCommandListAppendBarrier", hSignalEvent, numWaitEvents, phWaitEvents);
return ZE_RESULT_SUCCESS;
}
ze_result_t
eventsChecker::ZEeventsChecker::zeCommandListAppendMemoryRangesBarrierPrologue(
ze_command_list_handle_t hCommandList, ///< [in] handle of the command list
uint32_t numRanges, ///< [in] number of memory ranges
const size_t *pRangeSizes, ///< [in][range(0, numRanges)] array of sizes of memory range
const void **pRanges, ///< [in][range(0, numRanges)] array of memory ranges
ze_event_handle_t hSignalEvent, ///< [in][optional] handle of the event to signal on completion
uint32_t numWaitEvents, ///< [in][optional] number of events to wait on before executing barrier;
///< must be 0 if `nullptr == phWaitEvents`
ze_event_handle_t *phWaitEvents ///< [in][optional][range(0, numWaitEvents)] handle of the events to wait
///< on before executing barrier
) {
checkForDeadlock("zeCommandListAppendMemoryRangesBarrier", hSignalEvent, numWaitEvents, phWaitEvents);
return ZE_RESULT_SUCCESS;
}
ze_result_t
eventsChecker::ZEeventsChecker::zeCommandListAppendMemoryFillPrologue(
ze_command_list_handle_t hCommandList, ///< [in] handle of command list
void *ptr, ///< [in] pointer to memory to initialize
const void *pattern, ///< [in] pointer to value to initialize memory to
size_t pattern_size, ///< [in] size in bytes of the value to initialize memory to
size_t size, ///< [in] size in bytes to initialize
ze_event_handle_t hSignalEvent, ///< [in][optional] handle of the event to signal on completion
uint32_t numWaitEvents, ///< [in][optional] number of events to wait on before launching; must be 0
///< if `nullptr == phWaitEvents`
ze_event_handle_t *phWaitEvents ///< [in][optional][range(0, numWaitEvents)] handle of the events to wait
///< on before launching
) {
checkForDeadlock("zeCommandListAppendMemoryFill", hSignalEvent, numWaitEvents, phWaitEvents);
return ZE_RESULT_SUCCESS;
}
ze_result_t
eventsChecker::ZEeventsChecker::zeCommandListAppendMemoryCopyRegionPrologue(
ze_command_list_handle_t hCommandList, ///< [in] handle of command list
void *dstptr, ///< [in] pointer to destination memory to copy to
const ze_copy_region_t *dstRegion, ///< [in] pointer to destination region to copy to
uint32_t dstPitch, ///< [in] destination pitch in bytes
uint32_t dstSlicePitch, ///< [in] destination slice pitch in bytes. This is required for 3D region
///< copies where the `depth` member of ::ze_copy_region_t is not 0,
///< otherwise it's ignored.
const void *srcptr, ///< [in] pointer to source memory to copy from
const ze_copy_region_t *srcRegion, ///< [in] pointer to source region to copy from
uint32_t srcPitch, ///< [in] source pitch in bytes
uint32_t srcSlicePitch, ///< [in] source slice pitch in bytes. This is required for 3D region
///< copies where the `depth` member of ::ze_copy_region_t is not 0,
///< otherwise it's ignored.
ze_event_handle_t hSignalEvent, ///< [in][optional] handle of the event to signal on completion
uint32_t numWaitEvents, ///< [in][optional] number of events to wait on before launching; must be 0
///< if `nullptr == phWaitEvents`
ze_event_handle_t *phWaitEvents ///< [in][optional][range(0, numWaitEvents)] handle of the events to wait
///< on before launching
) {
checkForDeadlock("zeCommandListAppendMemoryCopyRegion", hSignalEvent, numWaitEvents, phWaitEvents);
return ZE_RESULT_SUCCESS;
}
ze_result_t
eventsChecker::ZEeventsChecker::zeCommandListAppendMemoryCopyFromContextPrologue(
ze_command_list_handle_t hCommandList, ///< [in] handle of command list
void *dstptr, ///< [in] pointer to destination memory to copy to
ze_context_handle_t hContextSrc, ///< [in] handle of source context object
const void *srcptr, ///< [in] pointer to source memory to copy from
size_t size, ///< [in] size in bytes to copy
ze_event_handle_t hSignalEvent, ///< [in][optional] handle of the event to signal on completion
uint32_t numWaitEvents, ///< [in][optional] number of events to wait on before launching; must be 0
///< if `nullptr == phWaitEvents`
ze_event_handle_t *phWaitEvents ///< [in][optional][range(0, numWaitEvents)] handle of the events to wait
///< on before launching
) {
checkForDeadlock("zeCommandListAppendMemoryCopyFromContext", hSignalEvent, numWaitEvents, phWaitEvents);
return ZE_RESULT_SUCCESS;
}
ze_result_t
eventsChecker::ZEeventsChecker::zeCommandListAppendImageCopyPrologue(
ze_command_list_handle_t hCommandList, ///< [in] handle of command list
ze_image_handle_t hDstImage, ///< [in] handle of destination image to copy to
ze_image_handle_t hSrcImage, ///< [in] handle of source image to copy from
ze_event_handle_t hSignalEvent, ///< [in][optional] handle of the event to signal on completion
uint32_t numWaitEvents, ///< [in][optional] number of events to wait on before launching; must be 0
///< if `nullptr == phWaitEvents`
ze_event_handle_t *phWaitEvents ///< [in][optional][range(0, numWaitEvents)] handle of the events to wait
///< on before launching
) {
checkForDeadlock("zeCommandListAppendImageCopy", hSignalEvent, numWaitEvents, phWaitEvents);
return ZE_RESULT_SUCCESS;
}
ze_result_t
eventsChecker::ZEeventsChecker::zeCommandListAppendImageCopyRegionPrologue(
ze_command_list_handle_t hCommandList, ///< [in] handle of command list
ze_image_handle_t hDstImage, ///< [in] handle of destination image to copy to
ze_image_handle_t hSrcImage, ///< [in] handle of source image to copy from
const ze_image_region_t *pDstRegion, ///< [in][optional] destination region descriptor
const ze_image_region_t *pSrcRegion, ///< [in][optional] source region descriptor
ze_event_handle_t hSignalEvent, ///< [in][optional] handle of the event to signal on completion
uint32_t numWaitEvents, ///< [in][optional] number of events to wait on before launching; must be 0
///< if `nullptr == phWaitEvents`
ze_event_handle_t *phWaitEvents ///< [in][optional][range(0, numWaitEvents)] handle of the events to wait
///< on before launching
) {
checkForDeadlock("zeCommandListAppendImageCopyRegion", hSignalEvent, numWaitEvents, phWaitEvents);
return ZE_RESULT_SUCCESS;
}
ze_result_t
eventsChecker::ZEeventsChecker::zeCommandListAppendImageCopyToMemoryPrologue(
ze_command_list_handle_t hCommandList, ///< [in] handle of command list
void *dstptr, ///< [in] pointer to destination memory to copy to
ze_image_handle_t hSrcImage, ///< [in] handle of source image to copy from
const ze_image_region_t *pSrcRegion, ///< [in][optional] source region descriptor
ze_event_handle_t hSignalEvent, ///< [in][optional] handle of the event to signal on completion
uint32_t numWaitEvents, ///< [in][optional] number of events to wait on before launching; must be 0
///< if `nullptr == phWaitEvents`
ze_event_handle_t *phWaitEvents ///< [in][optional][range(0, numWaitEvents)] handle of the events to wait
///< on before launching
) {
checkForDeadlock("zeCommandListAppendImageCopyToMemory", hSignalEvent, numWaitEvents, phWaitEvents);
return ZE_RESULT_SUCCESS;
}
ze_result_t
eventsChecker::ZEeventsChecker::zeCommandListAppendImageCopyFromMemoryPrologue(
ze_command_list_handle_t hCommandList, ///< [in] handle of command list
ze_image_handle_t hDstImage, ///< [in] handle of destination image to copy to
const void *srcptr, ///< [in] pointer to source memory to copy from
const ze_image_region_t *pDstRegion, ///< [in][optional] destination region descriptor
ze_event_handle_t hSignalEvent, ///< [in][optional] handle of the event to signal on completion
uint32_t numWaitEvents, ///< [in][optional] number of events to wait on before launching; must be 0
///< if `nullptr == phWaitEvents`
ze_event_handle_t *phWaitEvents ///< [in][optional][range(0, numWaitEvents)] handle of the events to wait
///< on before launching
) {
checkForDeadlock("zeCommandListAppendImageCopyFromMemory", hSignalEvent, numWaitEvents, phWaitEvents);
return ZE_RESULT_SUCCESS;
}
ze_result_t
eventsChecker::ZEeventsChecker::zeCommandListAppendSignalEventPrologue(
ze_command_list_handle_t hCommandList, ///< [in] handle of the command list
ze_event_handle_t hEvent ///< [in] handle of the event
) {
checkForDeadlock("zeCommandListAppendSignalEvent", hEvent, 0, nullptr);
return ZE_RESULT_SUCCESS;
}
ze_result_t
eventsChecker::ZEeventsChecker::zeCommandListAppendWaitOnEventsPrologue(
ze_command_list_handle_t hCommandList, ///< [in] handle of the command list
uint32_t numEvents, ///< [in] number of events to wait on before continuing
ze_event_handle_t *phEvents ///< [in][range(0, numEvents)] handles of the events to wait on before
///< continuing
) {
checkForDeadlock("zeCommandListAppendWaitOnEvents", nullptr, numEvents, phEvents);
return ZE_RESULT_SUCCESS;
}
ze_result_t
eventsChecker::ZEeventsChecker::zeEventHostSignalPrologue(
ze_event_handle_t hEvent ///< [in] handle of the event
) {
checkForDeadlock("zeEventHostSignal", hEvent, 0, nullptr);
return ZE_RESULT_SUCCESS;
}
void eventsChecker::ZEeventsChecker::resetEventInEventToDagID(
const std::string &zeCallDisc, /// action discription
const ze_event_handle_t hEvent ///< [in] handle of the event
) {
auto it = eventToDagID.find(hEvent);
// Check if user is using invalid events, hint if it doesn't exist in eventToDagID.
if (it == eventToDagID.end()) {
std::cerr << "Warning: hSignalEvent {" << hEvent << "} might be an invalid event in call to " << zeCallDisc << std::endl;
return;
}
if (it->second != invalidDagID) {
auto action = dagIDToAction.find(it->second);
if (action != dagIDToAction.end()) {
action->second.second = invalidEventAddress; // Reset
}
it->second = invalidDagID; // Reset
}
}
ze_result_t
eventsChecker::ZEeventsChecker::zeCommandListAppendEventResetPrologue(
ze_command_list_handle_t hCommandList, ///< [in] handle of the command list
ze_event_handle_t hEvent ///< [in] handle of the event
) {
resetEventInEventToDagID("zeCommandListAppendEventReset", hEvent);
return ZE_RESULT_SUCCESS;
}
ze_result_t
eventsChecker::ZEeventsChecker::zeEventHostResetPrologue(
ze_event_handle_t hEvent ///< [in] handle of the event
) {
resetEventInEventToDagID("zeEventHostReset", hEvent);
return ZE_RESULT_SUCCESS;
}
ze_result_t
eventsChecker::ZEeventsChecker::zeCommandListAppendQueryKernelTimestampsPrologue(
ze_command_list_handle_t hCommandList, ///< [in] handle of the command list
uint32_t numEvents, ///< [in] the number of timestamp events to query
ze_event_handle_t *phEvents, ///< [in][range(0, numEvents)] handles of timestamp events to query
void *dstptr, ///< [in,out] pointer to memory where ::ze_kernel_timestamp_result_t will
///< be written; must be size-aligned.
const size_t *pOffsets, ///< [in][optional][range(0, numEvents)] offset, in bytes, to write
///< results; address must be 4byte-aligned and offsets must be
///< size-aligned.
ze_event_handle_t hSignalEvent, ///< [in][optional] handle of the event to signal on completion
uint32_t numWaitEvents, ///< [in][optional] number of events to wait on before executing query;
///< must be 0 if `nullptr == phWaitEvents`
ze_event_handle_t *phWaitEvents ///< [in][optional][range(0, numWaitEvents)] handle of the events to wait
///< on before executing query
) {
checkForDeadlock("zeCommandListAppendQueryKernelTimestamps", hSignalEvent, numWaitEvents, phWaitEvents);
return ZE_RESULT_SUCCESS;
}
ze_result_t
eventsChecker::ZEeventsChecker::zeCommandListAppendLaunchKernelPrologue(
ze_command_list_handle_t hCommandList, ///< [in] handle of the command list
ze_kernel_handle_t hKernel, ///< [in] handle of the kernel object
const ze_group_count_t *pLaunchFuncArgs, ///< [in] thread group launch arguments
ze_event_handle_t hSignalEvent, ///< [in][optional] handle of the event to signal on completion
uint32_t numWaitEvents, ///< [in][optional] number of events to wait on before launching; must be 0
///< if `nullptr == phWaitEvents`
ze_event_handle_t *phWaitEvents ///< [in][optional][range(0, numWaitEvents)] handle of the events to wait
///< on before launching
) {
checkForDeadlock("zeCommandListAppendLaunchKernel", hSignalEvent, numWaitEvents, phWaitEvents);
return ZE_RESULT_SUCCESS;
}
ze_result_t
eventsChecker::ZEeventsChecker::zeCommandListAppendLaunchCooperativeKernelPrologue(
ze_command_list_handle_t hCommandList, ///< [in] handle of the command list
ze_kernel_handle_t hKernel, ///< [in] handle of the kernel object
const ze_group_count_t *pLaunchFuncArgs, ///< [in] thread group launch arguments
ze_event_handle_t hSignalEvent, ///< [in][optional] handle of the event to signal on completion
uint32_t numWaitEvents, ///< [in][optional] number of events to wait on before launching; must be 0
///< if `nullptr == phWaitEvents`
ze_event_handle_t *phWaitEvents ///< [in][optional][range(0, numWaitEvents)] handle of the events to wait
///< on before launching
) {
checkForDeadlock("zeCommandListAppendLaunchCooperativeKernel", hSignalEvent, numWaitEvents, phWaitEvents);
return ZE_RESULT_SUCCESS;
}
ze_result_t
eventsChecker::ZEeventsChecker::zeCommandListAppendLaunchKernelIndirectPrologue(
ze_command_list_handle_t hCommandList, ///< [in] handle of the command list
ze_kernel_handle_t hKernel, ///< [in] handle of the kernel object
const ze_group_count_t *pLaunchArgumentsBuffer, ///< [in] pointer to device buffer that will contain thread group launch
///< arguments
ze_event_handle_t hSignalEvent, ///< [in][optional] handle of the event to signal on completion
uint32_t numWaitEvents, ///< [in][optional] number of events to wait on before launching; must be 0
///< if `nullptr == phWaitEvents`
ze_event_handle_t *phWaitEvents ///< [in][optional][range(0, numWaitEvents)] handle of the events to wait
///< on before launching
) {
checkForDeadlock("zeCommandListAppendLaunchKernelIndirect", hSignalEvent, numWaitEvents, phWaitEvents);
return ZE_RESULT_SUCCESS;
}
ze_result_t
eventsChecker::ZEeventsChecker::zeCommandListAppendLaunchMultipleKernelsIndirectPrologue(
ze_command_list_handle_t hCommandList, ///< [in] handle of the command list
uint32_t numKernels, ///< [in] maximum number of kernels to launch
ze_kernel_handle_t *phKernels, ///< [in][range(0, numKernels)] handles of the kernel objects
const uint32_t *pCountBuffer, ///< [in] pointer to device memory location that will contain the actual
///< number of kernels to launch; value must be less than or equal to
///< numKernels
const ze_group_count_t *pLaunchArgumentsBuffer, ///< [in][range(0, numKernels)] pointer to device buffer that will contain
///< a contiguous array of thread group launch arguments
ze_event_handle_t hSignalEvent, ///< [in][optional] handle of the event to signal on completion
uint32_t numWaitEvents, ///< [in][optional] number of events to wait on before launching; must be 0
///< if `nullptr == phWaitEvents`
ze_event_handle_t *phWaitEvents ///< [in][optional][range(0, numWaitEvents)] handle of the events to wait
///< on before launching
) {
checkForDeadlock("zeCommandListAppendLaunchMultipleKernelsIndirect", hSignalEvent, numWaitEvents, phWaitEvents);
return ZE_RESULT_SUCCESS;
}
ze_result_t
eventsChecker::ZEeventsChecker::zeCommandListUpdateMutableCommandSignalEventExpPrologue(
ze_command_list_handle_t hCommandList, ///< [in] handle of the command list
uint64_t commandId, ///< [in] command identifier
ze_event_handle_t hSignalEvent ///< [in][optional] handle of the event to signal on completion
) {
checkForDeadlock("zeCommandListUpdateMutableCommandSignalEventExp", hSignalEvent, 0, nullptr);
return ZE_RESULT_SUCCESS;
}
ze_result_t
eventsChecker::ZEeventsChecker::zeCommandListUpdateMutableCommandWaitEventsExpPrologue(
ze_command_list_handle_t hCommandList, ///< [in] handle of the command list
uint64_t commandId, ///< [in] command identifier
uint32_t numWaitEvents, ///< [in][optional] the number of wait events
ze_event_handle_t *phWaitEvents ///< [in][optional][range(0, numWaitEvents)] handle of the events to wait
///< on before launching
) {
checkForDeadlock("zeCommandListUpdateMutableCommandWaitEventsExp", nullptr, numWaitEvents, phWaitEvents);
return ZE_RESULT_SUCCESS;
}
ze_result_t
eventsChecker::ZEeventsChecker::zeCommandListAppendImageCopyToMemoryExtPrologue(
ze_command_list_handle_t hCommandList, ///< [in] handle of command list
void *dstptr, ///< [in] pointer to destination memory to copy to
ze_image_handle_t hSrcImage, ///< [in] handle of source image to copy from
const ze_image_region_t *pSrcRegion, ///< [in][optional] source region descriptor
uint32_t destRowPitch, ///< [in] size in bytes of the 1D slice of the 2D region of a 2D or 3D
///< image or each image of a 1D or 2D image array being written
uint32_t destSlicePitch, ///< [in] size in bytes of the 2D slice of the 3D region of a 3D image or
///< each image of a 1D or 2D image array being written
ze_event_handle_t hSignalEvent, ///< [in][optional] handle of the event to signal on completion
uint32_t numWaitEvents, ///< [in][optional] number of events to wait on before launching; must be 0
///< if `nullptr == phWaitEvents`
ze_event_handle_t *phWaitEvents ///< [in][optional][range(0, numWaitEvents)] handle of the events to wait
///< on before launching
) {
checkForDeadlock("zeCommandListAppendImageCopyToMemoryExt", hSignalEvent, numWaitEvents, phWaitEvents);
return ZE_RESULT_SUCCESS;
}
ze_result_t
eventsChecker::ZEeventsChecker::zeCommandListAppendImageCopyFromMemoryExtPrologue(
ze_command_list_handle_t hCommandList, ///< [in] handle of command list
ze_image_handle_t hDstImage, ///< [in] handle of destination image to copy to
const void *srcptr, ///< [in] pointer to source memory to copy from
const ze_image_region_t *pDstRegion, ///< [in][optional] destination region descriptor
uint32_t srcRowPitch, ///< [in] size in bytes of the 1D slice of the 2D region of a 2D or 3D
///< image or each image of a 1D or 2D image array being read
uint32_t srcSlicePitch, ///< [in] size in bytes of the 2D slice of the 3D region of a 3D image or
///< each image of a 1D or 2D image array being read
ze_event_handle_t hSignalEvent, ///< [in][optional] handle of the event to signal on completion
uint32_t numWaitEvents, ///< [in][optional] number of events to wait on before launching; must be 0
///< if `nullptr == phWaitEvents`
ze_event_handle_t *phWaitEvents ///< [in][optional][range(0, numWaitEvents)] handle of the events to wait
///< on before launching
) {
checkForDeadlock("zeCommandListAppendImageCopyFromMemoryExt", hSignalEvent, numWaitEvents, phWaitEvents);
return ZE_RESULT_SUCCESS;
}
ze_result_t
eventsChecker::ZEeventsChecker::zeCommandListImmediateAppendCommandListsExpPrologue(
ze_command_list_handle_t hCommandListImmediate, ///< [in] handle of the immediate command list
uint32_t numCommandLists, ///< [in] number of command lists
ze_command_list_handle_t *phCommandLists, ///< [in][range(0, numCommandLists)] handles of command lists
ze_event_handle_t hSignalEvent, ///< [in][optional] handle of the event to signal on completion
///< - if not null, this event is signaled after the completion of all
///< appended command lists
uint32_t numWaitEvents, ///< [in][optional] number of events to wait on before executing appended
///< command lists; must be 0 if nullptr == phWaitEvents
ze_event_handle_t *phWaitEvents ///< [in][optional][range(0, numWaitEvents)] handle of the events to wait
///< on before executing appended command lists.
///< - if not null, all wait events must be satisfied prior to the start
///< of any appended command list(s)
) {
checkForDeadlock("zeCommandListImmediateAppendCommandListsExp", hSignalEvent, numWaitEvents, phWaitEvents);
return ZE_RESULT_SUCCESS;
}
void eventsChecker::ZEeventsChecker::validateSignalEventOwnership(const std::string &zeCallDisc,
const ze_event_handle_t hSignalEvent) {
const auto it = eventToDagID.find(hSignalEvent);
if (it != eventToDagID.end() && it->second != invalidDagID) {
const auto actionIt = dagIDToAction.find(it->second);
if (actionIt != dagIDToAction.end()) {
const std::string previousActionOwner = actionIt->second.first;
std::cerr << "Warning: " << zeCallDisc << " is using the same ze_event_handle_t for signal {" << hSignalEvent << "} which has been previously used by: " << previousActionOwner << std::endl;
}
}
}
void eventsChecker::ZEeventsChecker::checkForDeadlock(
const std::string &zeCallDisc, /// action discription
const ze_event_handle_t hSignalEvent, ///< [in][optional] handle of the event to forming the outgoing edge in the DAG
const uint32_t numWaitEvents, ///< [in][optional] number of events that point to this action.
const ze_event_handle_t *phWaitEvents ///< [in][optional][range(0, numWaitEvents)] handle of the events that point to this action.
) {
uint32_t this_action_new_node_id = invalidDagID;
if (hSignalEvent != nullptr) {
auto it = eventToDagID.find(hSignalEvent);
// Check if user is using invalid events, hint if it doesn't exist in eventToDagID.
if (it == eventToDagID.end()) {
std::cerr << "Warning: hSignalEvent {" << hSignalEvent << "} might be an invalid event in call to " << zeCallDisc << std::endl;
return;
}
// A passive check to see if the user is using the same event for multiple actions.
// It only print warnings and does not stop the event deadlock checker.
validateSignalEventOwnership(zeCallDisc, hSignalEvent);
if (it->second != invalidDagID) {
// This event already exists in the DAG. Get the DAG node ID.
// For example when there is indeed a deadlock it would have already been created.
this_action_new_node_id = it->second;
}
}
for (uint32_t i = 0; i < numWaitEvents; i++) {
if (eventToDagID.find(phWaitEvents[i]) == eventToDagID.end()) {
std::cerr << "Warning: phWaitEvents {" << hSignalEvent << "} might be an invalid event in call to " << zeCallDisc << std::endl;
return;
}
}
if (this_action_new_node_id == invalidDagID) {
// Create node in DAG
this_action_new_node_id = addNodeInDag();
// Now we know where the hSignalEvent points from/out in the DAG. Update the eventToDagID map.
eventToDagID[hSignalEvent] = this_action_new_node_id;
}
// Add this action to the actionToDagID map.
std::ostringstream oss;
oss << zeCallDisc << ": (hSignalEvent{" << hSignalEvent << "}, phWaitEvents{";
for (uint32_t i = 0; i < numWaitEvents; i++) {
oss << phWaitEvents[i];
if (i < numWaitEvents - 1) {
oss << ", ";
}
}
oss << "})";
std::string action = oss.str(); // Convert the stream to a string.
dagIDToAction[this_action_new_node_id] = actionAndSignalEvent(action, hSignalEvent);
// Form the dependency in the DAG
for (uint32_t i = 0; i < numWaitEvents; i++) {
auto it = eventToDagID.find(phWaitEvents[i]);
if (it == eventToDagID.end()) {
std::cerr << "Warning: phWaitEvents {" << phWaitEvents[i] << "} might be an invalid event in call to " << zeCallDisc << std::endl;
return;
}
uint32_t dagID = it->second;
if (dagID == invalidDagID) {
// Create a new node in the DAG for this wait event. That action will be created some time in the future.
dagID = addNodeInDag();
it->second = dagID;
}
auto getActionDetails = [&](int dagID) -> std::string {
auto actionIt = dagIDToAction.find(dagID);
return (actionIt != dagIDToAction.end()) ? actionIt->second.first : "PLACEHOLDER";
};
if (!addEdgeInDag(dagID, this_action_new_node_id)) {
std::string fromAction = getActionDetails(dagID);
std::string toAction = getActionDetails(this_action_new_node_id);
std::cerr << "Warning: There may be a potential event deadlock!\n";
std::cerr << "Adding the following dependency would create a cycle in the DAG:\n\tFrom: " << fromAction << "\n\tTo: " << toAction << "\n";
std::cerr << "There is already a path:\n";
constexpr uint32_t maxPathLength = 15;
auto path = dag.PathDagIDs(this_action_new_node_id, dagID, maxPathLength);
auto dagIDsInPath = path.first;
std::cerr << getActionDetails(dagIDsInPath[0]) << "\n";
std::string spacePrefix = "";
for (uint32_t j = 1; j < dagIDsInPath.size(); j++) {
std::cerr << spacePrefix << "|\n"
<< spacePrefix << "-> " << getActionDetails(dagIDsInPath[j]) << "\n";
spacePrefix += " ";
}
if (path.second) {
std::cerr << spacePrefix << "|\n"
<< spacePrefix << "-> ...\n";
}
}
}
}
} // namespace validation_layer
|