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
21 changes: 17 additions & 4 deletions src/backend/Level0/CHIPBackendLevel0.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* Copyright (c) 2021-22 chipStar developers
*
Expand Down Expand Up @@ -1350,7 +1350,7 @@
}

std::shared_ptr<chipstar::Event>
CHIPQueueLevel0::launchImpl(chipstar::ExecItem *ExecItem) {

Check warning on line 1353 in src/backend/Level0/CHIPBackendLevel0.cc

View workflow job for this annotation

GitHub Actions / cpp-linter

src/backend/Level0/CHIPBackendLevel0.cc:1353:18 [readability-function-cognitive-complexity]

function 'launchImpl' has cognitive complexity of 55 (threshold 25)
IsEmptyQueue_.store(false);
CHIPContextLevel0 *ChipCtxZe = (CHIPContextLevel0 *)ChipContext_;
CHIPKernelLevel0 *ChipKernel = (CHIPKernelLevel0 *)ExecItem->getKernel();
Expand Down Expand Up @@ -1392,10 +1392,23 @@
if (!ModInfo.HasNoIGBAs) {
// skpiing this check because PVC has a hardcoded value for this flag even though it's not supported:
// if (!LzDev->hasOnDemandPaging())
zeStatus = zeKernelSetIndirectAccess(
KernelZe, ZE_KERNEL_INDIRECT_ACCESS_FLAG_DEVICE |
ZE_KERNEL_INDIRECT_ACCESS_FLAG_HOST);
CHIPERR_CHECK_LOG_AND_THROW_TABLE(zeKernelSetIndirectAccess);
// The L0 driver appears to serialize zeKernelSetIndirectAccess across
// threads (it can deadlock or extreme-slow under back-to-back launches).
// The flag is a property of the kernel handle and only needs to be set
// once per kernel, not per launch. Cache the result and skip the call
// if it has already been performed for this kernel.
bool Expected = false;
if (ChipKernel->IndirectAccessSet_.compare_exchange_strong(
Expected, true, std::memory_order_acq_rel)) {
zeStatus = zeKernelSetIndirectAccess(
KernelZe, ZE_KERNEL_INDIRECT_ACCESS_FLAG_DEVICE |
ZE_KERNEL_INDIRECT_ACCESS_FLAG_HOST);
if (zeStatus != ZE_RESULT_SUCCESS) {
// Reset the flag so a future launch can retry.
ChipKernel->IndirectAccessSet_.store(false, std::memory_order_release);
}
CHIPERR_CHECK_LOG_AND_THROW_TABLE(zeKernelSetIndirectAccess);
}
}

// if there's a spill buffer, we must use an event so we can track when
Expand Down
7 changes: 7 additions & 0 deletions src/backend/Level0/CHIPBackendLevel0.hh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "../src/common.hh"
#include "zeHipErrorConversion.hh"
#include <algorithm>
#include <atomic>

static thread_local ze_result_t
zeStatus; // instantiated in CHIPBackendLevel0.cc
Expand Down Expand Up @@ -629,6 +630,12 @@
CHIPDeviceLevel0 *Device;

public:
// Tracks whether zeKernelSetIndirectAccess has already been called on
// this kernel handle. The L0 driver appears to serialize this call
// globally; calling it once per kernel instead of once per launch
// avoids contention/deadlocks with high launch rates.
std::atomic<bool> IndirectAccessSet_{false};

Check warning on line 637 in src/backend/Level0/CHIPBackendLevel0.hh

View workflow job for this annotation

GitHub Actions / cpp-linter

src/backend/Level0/CHIPBackendLevel0.hh:637:21 [readability-identifier-naming]

invalid case style for member 'IndirectAccessSet_'

CHIPKernelLevel0();

virtual ~CHIPKernelLevel0() {
Expand Down
Loading