Revert "fix: serialize printf kernel accesses using device-wise locks"

This reverts commit 3d33366ff6.

Signed-off-by: Compute-Runtime-Validation <compute-runtime-validation@intel.com>
This commit is contained in:
Compute-Runtime-Validation
2023-08-24 17:11:33 +02:00
committed by Compute-Runtime-Automation
parent d16debf5dc
commit 21a506b045
23 changed files with 131 additions and 652 deletions

View File

@@ -22,7 +22,6 @@
#include "level_zero/core/source/driver/driver_handle_imp.h" #include "level_zero/core/source/driver/driver_handle_imp.h"
#include "level_zero/core/source/event/event.h" #include "level_zero/core/source/event/event.h"
#include "level_zero/core/source/kernel/kernel.h" #include "level_zero/core/source/kernel/kernel.h"
#include "level_zero/core/source/kernel/kernel_imp.h"
namespace L0 { namespace L0 {
@@ -39,12 +38,11 @@ CommandList::~CommandList() {
} }
void CommandList::storePrintfKernel(Kernel *kernel) { void CommandList::storePrintfKernel(Kernel *kernel) {
auto it = std::find_if(this->printfKernelContainer.begin(), this->printfKernelContainer.end(), auto it = std::find(this->printfKernelContainer.begin(), this->printfKernelContainer.end(),
[&kernel](const auto &printfKernel) { return printfKernel.lock().get() == kernel; }); kernel);
if (it == this->printfKernelContainer.end()) { if (it == this->printfKernelContainer.end()) {
auto module = static_cast<const ModuleImp *>(&static_cast<KernelImp *>(kernel)->getParentModule()); this->printfKernelContainer.push_back(kernel);
this->printfKernelContainer.push_back(module->getPrintfKernelWeakPtr(kernel->toHandle()));
} }
} }

View File

@@ -226,7 +226,7 @@ struct CommandList : _ze_command_list_handle_t {
return indirectAllocationsAllowed; return indirectAllocationsAllowed;
} }
std::vector<std::weak_ptr<Kernel>> &getPrintfKernelContainer() { std::vector<Kernel *> &getPrintfKernelContainer() {
return this->printfKernelContainer; return this->printfKernelContainer;
} }
@@ -357,7 +357,7 @@ struct CommandList : _ze_command_list_handle_t {
std::map<const void *, NEO::GraphicsAllocation *> hostPtrMap; std::map<const void *, NEO::GraphicsAllocation *> hostPtrMap;
std::vector<NEO::GraphicsAllocation *> ownedPrivateAllocations; std::vector<NEO::GraphicsAllocation *> ownedPrivateAllocations;
std::vector<NEO::GraphicsAllocation *> patternAllocations; std::vector<NEO::GraphicsAllocation *> patternAllocations;
std::vector<std::weak_ptr<Kernel>> printfKernelContainer; std::vector<Kernel *> printfKernelContainer;
NEO::CommandContainer commandContainer; NEO::CommandContainer commandContainer;

View File

@@ -388,10 +388,7 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendLaunchKernelIndirect(ze_
if (hEvent) { if (hEvent) {
event = Event::fromHandle(hEvent); event = Event::fromHandle(hEvent);
if (Kernel::fromHandle(kernelHandle)->getPrintfBufferAllocation() != nullptr) { if (Kernel::fromHandle(kernelHandle)->getPrintfBufferAllocation() != nullptr) {
Kernel *kernel = Kernel::fromHandle(kernelHandle); event->setKernelForPrintf(Kernel::fromHandle(kernelHandle));
auto module = static_cast<const ModuleImp *>(&static_cast<KernelImp *>(kernel)->getParentModule());
event->setKernelForPrintf(module->getPrintfKernelWeakPtr(kernelHandle));
event->setKernelWithPrintfDeviceMutex(kernel->getDevicePrintfKernelMutex());
} }
launchParams.isHostSignalScopeEvent = event->isSignalScope(ZE_EVENT_SCOPE_FLAG_HOST); launchParams.isHostSignalScopeEvent = event->isSignalScope(ZE_EVENT_SCOPE_FLAG_HOST);
} }

View File

@@ -385,7 +385,7 @@ inline ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::executeCommand
this->cmdQImmediate->setTaskCount(completionStamp.taskCount); this->cmdQImmediate->setTaskCount(completionStamp.taskCount);
if (this->isSyncModeQueue) { if (this->isSyncModeQueue || this->printfKernelContainer.size() > 0u) {
status = hostSynchronize(std::numeric_limits<uint64_t>::max(), completionStamp.taskCount, true); status = hostSynchronize(std::numeric_limits<uint64_t>::max(), completionStamp.taskCount, true);
} }
@@ -1242,10 +1242,7 @@ template <GFXCORE_FAMILY gfxCoreFamily>
void CommandListCoreFamilyImmediate<gfxCoreFamily>::printKernelsPrintfOutput(bool hangDetected) { void CommandListCoreFamilyImmediate<gfxCoreFamily>::printKernelsPrintfOutput(bool hangDetected) {
size_t size = this->printfKernelContainer.size(); size_t size = this->printfKernelContainer.size();
for (size_t i = 0; i < size; i++) { for (size_t i = 0; i < size; i++) {
std::lock_guard<std::mutex> lock(static_cast<DeviceImp *>(this->device)->printfKernelMutex); this->printfKernelContainer[i]->printPrintfOutput(hangDetected);
if (!this->printfKernelContainer[i].expired()) {
this->printfKernelContainer[i].lock()->printPrintfOutput(hangDetected);
}
} }
this->printfKernelContainer.clear(); this->printfKernelContainer.clear();
} }

View File

@@ -240,9 +240,7 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendLaunchKernelWithParams(K
} }
if (event != nullptr && kernel->getPrintfBufferAllocation() != nullptr) { if (event != nullptr && kernel->getPrintfBufferAllocation() != nullptr) {
auto module = static_cast<const ModuleImp *>(&static_cast<KernelImp *>(kernel)->getParentModule()); event->setKernelForPrintf(kernel);
event->setKernelForPrintf(module->getPrintfKernelWeakPtr(kernel->toHandle()));
event->setKernelWithPrintfDeviceMutex(kernel->getDevicePrintfKernelMutex());
} }
if (this->inOrderExecutionEnabled && !launchParams.isKernelSplitOperation) { if (this->inOrderExecutionEnabled && !launchParams.isKernelSplitOperation) {

View File

@@ -24,9 +24,7 @@
#include "shared/source/xe_hp_core/hw_info.h" #include "shared/source/xe_hp_core/hw_info.h"
#include "level_zero/core/source/cmdlist/cmdlist_hw.h" #include "level_zero/core/source/cmdlist/cmdlist_hw.h"
#include "level_zero/core/source/device/device.h"
#include "level_zero/core/source/driver/driver_handle_imp.h" #include "level_zero/core/source/driver/driver_handle_imp.h"
#include "level_zero/core/source/event/event.h"
#include "level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper.h" #include "level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper.h"
#include "level_zero/core/source/kernel/kernel_imp.h" #include "level_zero/core/source/kernel/kernel_imp.h"
#include "level_zero/core/source/module/module.h" #include "level_zero/core/source/module/module.h"
@@ -173,9 +171,7 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendLaunchKernelWithParams(K
Event *compactEvent = nullptr; Event *compactEvent = nullptr;
if (event) { if (event) {
if (kernel->getPrintfBufferAllocation() != nullptr) { if (kernel->getPrintfBufferAllocation() != nullptr) {
auto module = static_cast<const ModuleImp *>(&static_cast<KernelImp *>(kernel)->getParentModule()); event->setKernelForPrintf(kernel);
event->setKernelForPrintf(module->getPrintfKernelWeakPtr(kernel->toHandle()));
event->setKernelWithPrintfDeviceMutex(kernel->getDevicePrintfKernelMutex());
} }
isHostSignalScopeEvent = event->isSignalScope(ZE_EVENT_SCOPE_FLAG_HOST); isHostSignalScopeEvent = event->isSignalScope(ZE_EVENT_SCOPE_FLAG_HOST);
if (compactL3FlushEvent(getDcFlushRequired(event->isSignalScope()))) { if (compactL3FlushEvent(getDcFlushRequired(event->isSignalScope()))) {

View File

@@ -189,10 +189,7 @@ ze_result_t CommandQueueImp::synchronizeByPollingForTaskCount(uint64_t timeout)
void CommandQueueImp::printKernelsPrintfOutput(bool hangDetected) { void CommandQueueImp::printKernelsPrintfOutput(bool hangDetected) {
size_t size = this->printfKernelContainer.size(); size_t size = this->printfKernelContainer.size();
for (size_t i = 0; i < size; i++) { for (size_t i = 0; i < size; i++) {
std::lock_guard<std::mutex> lock(static_cast<DeviceImp *>(this->getDevice())->printfKernelMutex); this->printfKernelContainer[i]->printPrintfOutput(hangDetected);
if (!this->printfKernelContainer[i].expired()) {
this->printfKernelContainer[i].lock()->printPrintfOutput(hangDetected);
}
} }
this->printfKernelContainer.clear(); this->printfKernelContainer.clear();
} }

View File

@@ -137,7 +137,7 @@ struct CommandQueueImp : public CommandQueue {
NEO::LinearStream firstCmdListStream{}; NEO::LinearStream firstCmdListStream{};
NEO::HeapContainer heapContainer; NEO::HeapContainer heapContainer;
ze_command_queue_desc_t desc; ze_command_queue_desc_t desc;
std::vector<std::weak_ptr<Kernel>> printfKernelContainer; std::vector<Kernel *> printfKernelContainer;
Device *device = nullptr; Device *device = nullptr;
NEO::CommandStreamReceiver *csr = nullptr; NEO::CommandStreamReceiver *csr = nullptr;

View File

@@ -131,8 +131,6 @@ struct DeviceImp : public Device {
ze_pci_speed_ext_t pciMaxSpeed = {-1, -1, -1}; ze_pci_speed_ext_t pciMaxSpeed = {-1, -1, -1};
Device *rootDevice = nullptr; Device *rootDevice = nullptr;
std::mutex printfKernelMutex;
BcsSplit bcsSplit; BcsSplit bcsSplit;
bool resourcesReleased = false; bool resourcesReleased = false;

View File

@@ -18,7 +18,6 @@
#include <chrono> #include <chrono>
#include <limits> #include <limits>
#include <memory> #include <memory>
#include <mutex>
#include <vector> #include <vector>
struct _ze_event_handle_t {}; struct _ze_event_handle_t {};
@@ -197,24 +196,12 @@ struct Event : _ze_event_handle_t {
uint32_t getMaxKernelCount() const { uint32_t getMaxKernelCount() const {
return maxKernelCount; return maxKernelCount;
} }
void setKernelForPrintf(std::weak_ptr<Kernel> inputKernelWeakPtr) { void setKernelForPrintf(Kernel *inputKernelPtr) {
kernelWithPrintf = inputKernelWeakPtr; kernelWithPrintf = inputKernelPtr;
} }
std::weak_ptr<Kernel> getKernelForPrintf() { Kernel *getKernelForPrintf() {
return kernelWithPrintf; return kernelWithPrintf;
} }
void resetKernelForPrintf() {
kernelWithPrintf.reset();
}
void setKernelWithPrintfDeviceMutex(std::mutex *mutexPtr) {
kernelWithPrintfDeviceMutex = mutexPtr;
}
std::mutex *getKernelWithPrintfDeviceMutex() {
return kernelWithPrintfDeviceMutex;
}
void resetKernelWithPrintfDeviceMutex() {
kernelWithPrintfDeviceMutex = nullptr;
}
bool isSignalScope() const { bool isSignalScope() const {
return !!signalScope; return !!signalScope;
@@ -275,8 +262,7 @@ struct Event : _ze_event_handle_t {
void *hostAddress = nullptr; void *hostAddress = nullptr;
Device *device = nullptr; Device *device = nullptr;
EventPool *eventPool = nullptr; EventPool *eventPool = nullptr;
std::weak_ptr<Kernel> kernelWithPrintf = std::weak_ptr<Kernel>(); Kernel *kernelWithPrintf = nullptr;
std::mutex *kernelWithPrintfDeviceMutex = nullptr;
NEO::GraphicsAllocation *inOrderExecDataAllocation = nullptr; NEO::GraphicsAllocation *inOrderExecDataAllocation = nullptr;
CommandQueue *latestUsedCmdQueue = nullptr; CommandQueue *latestUsedCmdQueue = nullptr;

View File

@@ -14,7 +14,6 @@
#include "shared/source/memory_manager/memory_operations_handler.h" #include "shared/source/memory_manager/memory_operations_handler.h"
#include "shared/source/os_interface/os_time.h" #include "shared/source/os_interface/os_time.h"
#include "level_zero/core/source/device/device.h"
#include "level_zero/core/source/event/event_imp.h" #include "level_zero/core/source/event/event_imp.h"
#include "level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper.h" #include "level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper.h"
#include "level_zero/core/source/kernel/kernel.h" #include "level_zero/core/source/kernel/kernel.h"
@@ -407,13 +406,9 @@ ze_result_t EventImp<TagSizeT>::hostSynchronize(uint64_t timeout) {
ret = queryStatus(); ret = queryStatus();
} }
if (ret == ZE_RESULT_SUCCESS) { if (ret == ZE_RESULT_SUCCESS) {
if (this->getKernelWithPrintfDeviceMutex() != nullptr) { if (this->getKernelForPrintf() != nullptr) {
std::lock_guard<std::mutex> lock(*this->getKernelWithPrintfDeviceMutex()); static_cast<Kernel *>(this->getKernelForPrintf())->printPrintfOutput(true);
if (!this->getKernelForPrintf().expired()) { this->setKernelForPrintf(nullptr);
this->getKernelForPrintf().lock()->printPrintfOutput(true);
}
this->resetKernelForPrintf();
this->resetKernelWithPrintfDeviceMutex();
} }
if (device->getNEODevice()->getRootDeviceEnvironment().assertHandler.get()) { if (device->getNEODevice()->getRootDeviceEnvironment().assertHandler.get()) {
device->getNEODevice()->getRootDeviceEnvironment().assertHandler->printAssertAndAbort(); device->getNEODevice()->getRootDeviceEnvironment().assertHandler->printAssertAndAbort();

View File

@@ -141,7 +141,6 @@ struct Kernel : _ze_kernel_handle_t, virtual NEO::DispatchKernelEncoderI {
virtual UnifiedMemoryControls getUnifiedMemoryControls() const = 0; virtual UnifiedMemoryControls getUnifiedMemoryControls() const = 0;
virtual bool hasIndirectAllocationsAllowed() const = 0; virtual bool hasIndirectAllocationsAllowed() const = 0;
virtual std::mutex *getDevicePrintfKernelMutex() = 0;
virtual NEO::GraphicsAllocation *getPrintfBufferAllocation() = 0; virtual NEO::GraphicsAllocation *getPrintfBufferAllocation() = 0;
virtual void printPrintfOutput(bool hangDetected) = 0; virtual void printPrintfOutput(bool hangDetected) = 0;

View File

@@ -1086,11 +1086,11 @@ void KernelImp::createPrintfBuffer() {
if (pImplicitArgs) { if (pImplicitArgs) {
pImplicitArgs->printfBufferPtr = printfBuffer->getGpuAddress(); pImplicitArgs->printfBufferPtr = printfBuffer->getGpuAddress();
} }
this->devicePrintfKernelMutex = &(static_cast<DeviceImp *>(this->module->getDevice())->printfKernelMutex);
} }
} }
void KernelImp::printPrintfOutput(bool hangDetected) { void KernelImp::printPrintfOutput(bool hangDetected) {
std::lock_guard<std::mutex> lock(this->printfLock);
PrintfHandler::printOutput(kernelImmData, this->printfBuffer, module->getDevice(), hangDetected); PrintfHandler::printOutput(kernelImmData, this->printfBuffer, module->getDevice(), hangDetected);
} }

View File

@@ -14,8 +14,6 @@
#include "shared/source/unified_memory/unified_memory.h" #include "shared/source/unified_memory/unified_memory.h"
#include "level_zero/core/source/kernel/kernel.h" #include "level_zero/core/source/kernel/kernel.h"
#include "level_zero/core/source/module/module.h"
#include "level_zero/core/source/module/module_imp.h"
#include <memory> #include <memory>
#include <mutex> #include <mutex>
@@ -40,12 +38,8 @@ struct KernelImp : Kernel {
~KernelImp() override; ~KernelImp() override;
ze_result_t destroy() override { ze_result_t destroy() override {
if (this->devicePrintfKernelMutex == nullptr) { delete this;
delete this; return ZE_RESULT_SUCCESS;
return ZE_RESULT_SUCCESS;
} else {
return static_cast<ModuleImp *>(this->module)->destroyPrintfKernel(this);
}
} }
ze_result_t getBaseAddress(uint64_t *baseAddress) override; ze_result_t getBaseAddress(uint64_t *baseAddress) override;
@@ -105,7 +99,6 @@ struct KernelImp : Kernel {
uint32_t getNumThreadsPerThreadGroup() const override { return numThreadsPerThreadGroup; } uint32_t getNumThreadsPerThreadGroup() const override { return numThreadsPerThreadGroup; }
uint32_t getThreadExecutionMask() const override { return threadExecutionMask; } uint32_t getThreadExecutionMask() const override { return threadExecutionMask; }
std::mutex *getDevicePrintfKernelMutex() override { return this->devicePrintfKernelMutex; }
NEO::GraphicsAllocation *getPrintfBufferAllocation() override { return this->printfBuffer; } NEO::GraphicsAllocation *getPrintfBufferAllocation() override { return this->printfBuffer; }
void printPrintfOutput(bool hangDetected) override; void printPrintfOutput(bool hangDetected) override;
@@ -206,7 +199,6 @@ struct KernelImp : Kernel {
std::vector<KernelImp::KernelArgHandler> kernelArgHandlers; std::vector<KernelImp::KernelArgHandler> kernelArgHandlers;
std::vector<NEO::GraphicsAllocation *> residencyContainer; std::vector<NEO::GraphicsAllocation *> residencyContainer;
std::mutex *devicePrintfKernelMutex = nullptr;
NEO::GraphicsAllocation *printfBuffer = nullptr; NEO::GraphicsAllocation *printfBuffer = nullptr;
uint32_t groupSize[3] = {0u, 0u, 0u}; uint32_t groupSize[3] = {0u, 0u, 0u};
@@ -246,6 +238,7 @@ struct KernelImp : Kernel {
std::unique_ptr<NEO::ImplicitArgs> pImplicitArgs; std::unique_ptr<NEO::ImplicitArgs> pImplicitArgs;
std::unique_ptr<KernelExt> pExtension; std::unique_ptr<KernelExt> pExtension;
std::mutex printfLock;
struct SuggestGroupSizeCacheEntry { struct SuggestGroupSizeCacheEntry {
Vec3<size_t> groupSize; Vec3<size_t> groupSize;

View File

@@ -39,7 +39,6 @@
#include "shared/source/program/program_initialization.h" #include "shared/source/program/program_initialization.h"
#include "level_zero/core/source/device/device.h" #include "level_zero/core/source/device/device.h"
#include "level_zero/core/source/device/device_imp.h"
#include "level_zero/core/source/driver/driver_handle.h" #include "level_zero/core/source/driver/driver_handle.h"
#include "level_zero/core/source/driver/driver_handle_imp.h" #include "level_zero/core/source/driver/driver_handle_imp.h"
#include "level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper.h" #include "level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper.h"
@@ -500,12 +499,6 @@ ModuleImp::ModuleImp(Device *device, ModuleBuildLog *moduleBuildLog, ModuleType
} }
ModuleImp::~ModuleImp() { ModuleImp::~ModuleImp() {
for (auto &kernel : printfKernelContainer) {
if (kernel.get() != nullptr) {
destroyPrintfKernel(kernel->toHandle());
}
}
printfKernelContainer.clear();
kernelImmDatas.clear(); kernelImmDatas.clear();
} }
@@ -824,9 +817,6 @@ ze_result_t ModuleImp::createKernel(const ze_kernel_desc_t *desc,
if (res == ZE_RESULT_SUCCESS) { if (res == ZE_RESULT_SUCCESS) {
*kernelHandle = kernel->toHandle(); *kernelHandle = kernel->toHandle();
if (kernel->getPrintfBufferAllocation() != nullptr) {
this->printfKernelContainer.push_back(std::shared_ptr<Kernel>(kernel));
}
} else { } else {
driverHandle->clearErrorDescription(); driverHandle->clearErrorDescription();
} }
@@ -845,29 +835,6 @@ ze_result_t ModuleImp::createKernel(const ze_kernel_desc_t *desc,
return res; return res;
} }
std::weak_ptr<Kernel> ModuleImp::getPrintfKernelWeakPtr(ze_kernel_handle_t kernelHandle) const {
std::lock_guard<std::mutex> lock(static_cast<DeviceImp *>(device)->printfKernelMutex);
Kernel *kernel = Kernel::fromHandle(kernelHandle);
auto it = std::find_if(this->printfKernelContainer.begin(), this->printfKernelContainer.end(), [&kernel](const auto &kernelSharedPtr) { return kernelSharedPtr.get() == kernel; });
if (it == this->printfKernelContainer.end()) {
return std::weak_ptr<Kernel>{};
} else {
return std::weak_ptr<Kernel>{*it};
}
}
ze_result_t ModuleImp::destroyPrintfKernel(ze_kernel_handle_t kernelHandle) {
std::lock_guard<std::mutex> lock(static_cast<DeviceImp *>(device)->printfKernelMutex);
Kernel *kernel = Kernel::fromHandle(kernelHandle);
auto it = std::find_if(this->printfKernelContainer.begin(), this->printfKernelContainer.end(),
[&kernel](const auto &kernelPtr) { return kernelPtr.get() == kernel; });
if (it == this->printfKernelContainer.end()) {
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
}
it->reset();
return ZE_RESULT_SUCCESS;
}
ze_result_t ModuleImp::getNativeBinary(size_t *pSize, uint8_t *pModuleNativeBinary) { ze_result_t ModuleImp::getNativeBinary(size_t *pSize, uint8_t *pModuleNativeBinary) {
auto genBinary = this->translationUnit->packedDeviceBinary.get(); auto genBinary = this->translationUnit->packedDeviceBinary.get();

View File

@@ -11,7 +11,6 @@
#include "shared/source/compiler_interface/linker.h" #include "shared/source/compiler_interface/linker.h"
#include "shared/source/program/program_info.h" #include "shared/source/program/program_info.h"
#include "level_zero/core/source/kernel/kernel.h"
#include "level_zero/core/source/module/module.h" #include "level_zero/core/source/module/module.h"
#include "igfxfmid.h" #include "igfxfmid.h"
@@ -155,10 +154,6 @@ struct ModuleImp : public Module {
return this->translationUnit.get(); return this->translationUnit.get();
} }
std::vector<std::shared_ptr<Kernel>> &getPrintfKernelContainer() { return this->printfKernelContainer; }
std::weak_ptr<Kernel> getPrintfKernelWeakPtr(ze_kernel_handle_t kernelHandle) const;
ze_result_t destroyPrintfKernel(ze_kernel_handle_t kernelHandle);
protected: protected:
ze_result_t initializeTranslationUnit(const ze_module_desc_t *desc, NEO::Device *neoDevice); ze_result_t initializeTranslationUnit(const ze_module_desc_t *desc, NEO::Device *neoDevice);
ze_result_t checkIfBuildShouldBeFailed(NEO::Device *neoDevice); ze_result_t checkIfBuildShouldBeFailed(NEO::Device *neoDevice);
@@ -179,7 +174,6 @@ struct ModuleImp : public Module {
std::unique_ptr<ModuleTranslationUnit> translationUnit; std::unique_ptr<ModuleTranslationUnit> translationUnit;
ModuleBuildLog *moduleBuildLog = nullptr; ModuleBuildLog *moduleBuildLog = nullptr;
NEO::GraphicsAllocation *exportedFunctionsSurface = nullptr; NEO::GraphicsAllocation *exportedFunctionsSurface = nullptr;
std::vector<std::shared_ptr<Kernel>> printfKernelContainer;
std::vector<std::unique_ptr<KernelImmutableData>> kernelImmDatas; std::vector<std::unique_ptr<KernelImmutableData>> kernelImmDatas;
NEO::Linker::RelocatedSymbolsMap symbols; NEO::Linker::RelocatedSymbolsMap symbols;

View File

@@ -178,7 +178,7 @@ std::unique_ptr<WhiteBox<::L0::KernelImp>> ModuleFixture::createKernelWithName(s
} }
void ModuleFixture::tearDown() { void ModuleFixture::tearDown() {
kernel.reset(); kernel.reset(nullptr);
module.reset(nullptr); module.reset(nullptr);
DeviceFixture::tearDown(); DeviceFixture::tearDown();
} }
@@ -219,7 +219,7 @@ void MultiDeviceModuleFixture::createKernel(uint32_t rootDeviceIndex) {
} }
void MultiDeviceModuleFixture::tearDown() { void MultiDeviceModuleFixture::tearDown() {
kernel.reset(); kernel.reset(nullptr);
for (auto &module : modules) { for (auto &module : modules) {
module.reset(nullptr); module.reset(nullptr);
} }

View File

@@ -219,43 +219,36 @@ HWTEST2_F(CommandListAppendLaunchKernel, givenNotEnoughSpaceInCommandStreamWhenA
} }
HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithPrintfUsedWhenAppendedToCommandListThenKernelIsStored) { HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithPrintfUsedWhenAppendedToCommandListThenKernelIsStored) {
createKernel();
ze_result_t returnValue; ze_result_t returnValue;
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, returnValue)); std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, returnValue));
ze_group_count_t groupCount{1, 1, 1}; ze_group_count_t groupCount{1, 1, 1};
auto kernel = new Mock<KernelImp>(); EXPECT_TRUE(kernel->kernelImmData->getDescriptor().kernelAttributes.flags.usesPrintf);
kernel->module = module.get();
kernel->descriptor.kernelAttributes.flags.usesPrintf = true;
kernel->createPrintfBuffer();
static_cast<ModuleImp *>(module.get())->getPrintfKernelContainer().push_back(std::shared_ptr<Kernel>{kernel});
CmdListKernelLaunchParams launchParams = {}; CmdListKernelLaunchParams launchParams = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, commandList->appendLaunchKernel(kernel->toHandle(), &groupCount, nullptr, 0, nullptr, launchParams, false)); auto result = commandList->appendLaunchKernel(kernel->toHandle(), &groupCount, nullptr, 0, nullptr, launchParams, false);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(1u, commandList->getPrintfKernelContainer().size()); EXPECT_EQ(1u, commandList->getPrintfKernelContainer().size());
std::shared_ptr<Kernel> kernelSharedPtr = commandList->getPrintfKernelContainer()[0].lock(); EXPECT_EQ(kernel.get(), commandList->getPrintfKernelContainer()[0]);
EXPECT_EQ(kernel, kernelSharedPtr.get());
} }
HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithPrintfUsedWhenAppendedToCommandListMultipleTimesThenKernelIsStoredOnce) { HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithPrintfUsedWhenAppendedToCommandListMultipleTimesThenKernelIsStoredOnce) {
createKernel();
ze_result_t returnValue; ze_result_t returnValue;
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, returnValue)); std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, returnValue));
ze_group_count_t groupCount{1, 1, 1}; ze_group_count_t groupCount{1, 1, 1};
auto kernel = new Mock<KernelImp>(); EXPECT_TRUE(kernel->kernelImmData->getDescriptor().kernelAttributes.flags.usesPrintf);
kernel->module = module.get();
kernel->descriptor.kernelAttributes.flags.usesPrintf = true;
kernel->createPrintfBuffer();
static_cast<ModuleImp *>(module.get())->getPrintfKernelContainer().push_back(std::shared_ptr<Kernel>{kernel});
CmdListKernelLaunchParams launchParams = {}; CmdListKernelLaunchParams launchParams = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, commandList->appendLaunchKernel(kernel->toHandle(), &groupCount, nullptr, 0, nullptr, launchParams, false)); auto result = commandList->appendLaunchKernel(kernel->toHandle(), &groupCount, nullptr, 0, nullptr, launchParams, false);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(1u, commandList->getPrintfKernelContainer().size()); EXPECT_EQ(1u, commandList->getPrintfKernelContainer().size());
std::shared_ptr<Kernel> kernelSharedPtr = commandList->getPrintfKernelContainer()[0].lock(); EXPECT_EQ(kernel.get(), commandList->getPrintfKernelContainer()[0]);
EXPECT_EQ(kernel, kernelSharedPtr.get());
EXPECT_EQ(ZE_RESULT_SUCCESS, commandList->appendLaunchKernel(kernel->toHandle(), &groupCount, nullptr, 0, nullptr, launchParams, false)); result = commandList->appendLaunchKernel(kernel->toHandle(), &groupCount, nullptr, 0, nullptr, launchParams, false);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(1u, commandList->getPrintfKernelContainer().size()); EXPECT_EQ(1u, commandList->getPrintfKernelContainer().size());
} }
@@ -269,27 +262,25 @@ HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithPrintfWhenAppendedToSynch
std::unique_ptr<L0::CommandList> commandList(CommandList::createImmediate(productFamily, device, &queueDesc, false, NEO::EngineGroupType::RenderCompute, returnValue)); std::unique_ptr<L0::CommandList> commandList(CommandList::createImmediate(productFamily, device, &queueDesc, false, NEO::EngineGroupType::RenderCompute, returnValue));
auto kernel = new Mock<KernelImp>(); Mock<KernelImp> kernel;
kernel->module = module.get(); kernel.descriptor.kernelAttributes.flags.usesPrintf = true;
kernel->descriptor.kernelAttributes.flags.usesPrintf = true;
kernel->createPrintfBuffer();
static_cast<ModuleImp *>(module.get())->getPrintfKernelContainer().push_back(std::shared_ptr<Kernel>{kernel});
EXPECT_EQ(0u, kernel->printPrintfOutputCalledTimes);
ze_group_count_t groupCount{1, 1, 1}; ze_group_count_t groupCount{1, 1, 1};
CmdListKernelLaunchParams launchParams = {}; CmdListKernelLaunchParams launchParams = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, commandList->appendLaunchKernel(kernel->toHandle(), &groupCount, nullptr, 0, nullptr, launchParams, false)); auto result = commandList->appendLaunchKernel(kernel.toHandle(), &groupCount, nullptr, 0, nullptr, launchParams, false);
EXPECT_EQ(1u, kernel->printPrintfOutputCalledTimes); EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_FALSE(kernel->hangDetectedPassedToPrintfOutput); EXPECT_EQ(1u, kernel.printPrintfOutputCalledTimes);
EXPECT_FALSE(kernel.hangDetectedPassedToPrintfOutput);
EXPECT_EQ(0u, commandList->getPrintfKernelContainer().size()); EXPECT_EQ(0u, commandList->getPrintfKernelContainer().size());
EXPECT_EQ(ZE_RESULT_SUCCESS, commandList->appendLaunchKernel(kernel->toHandle(), &groupCount, nullptr, 0, nullptr, launchParams, false)); result = commandList->appendLaunchKernel(kernel.toHandle(), &groupCount, nullptr, 0, nullptr, launchParams, false);
EXPECT_EQ(2u, kernel->printPrintfOutputCalledTimes); EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_FALSE(kernel->hangDetectedPassedToPrintfOutput); EXPECT_EQ(2u, kernel.printPrintfOutputCalledTimes);
EXPECT_FALSE(kernel.hangDetectedPassedToPrintfOutput);
EXPECT_EQ(0u, commandList->getPrintfKernelContainer().size()); EXPECT_EQ(0u, commandList->getPrintfKernelContainer().size());
} }
HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithPrintfWhenAppendedToAsynchronousImmCommandListThenPrintfBufferIsNotPrintedUntilHostSync) { HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithPrintfWhenAppendedToAsynchronousImmCommandListThenPrintfBufferIsPrinted) {
DebugManagerStateRestore dbgRestorer; DebugManagerStateRestore dbgRestorer;
DebugManager.flags.EnableFlushTaskSubmission.set(1); DebugManager.flags.EnableFlushTaskSubmission.set(1);
@@ -299,26 +290,21 @@ HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithPrintfWhenAppendedToAsync
std::unique_ptr<L0::CommandList> commandList(CommandList::createImmediate(productFamily, device, &queueDesc, false, NEO::EngineGroupType::RenderCompute, returnValue)); std::unique_ptr<L0::CommandList> commandList(CommandList::createImmediate(productFamily, device, &queueDesc, false, NEO::EngineGroupType::RenderCompute, returnValue));
auto kernel = new Mock<KernelImp>(); Mock<KernelImp> kernel;
kernel->module = module.get(); kernel.descriptor.kernelAttributes.flags.usesPrintf = true;
kernel->descriptor.kernelAttributes.flags.usesPrintf = true;
kernel->createPrintfBuffer();
static_cast<ModuleImp *>(module.get())->getPrintfKernelContainer().push_back(std::shared_ptr<Kernel>{kernel});
ze_group_count_t groupCount{1, 1, 1}; ze_group_count_t groupCount{1, 1, 1};
CmdListKernelLaunchParams launchParams = {}; CmdListKernelLaunchParams launchParams = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, commandList->appendLaunchKernel(kernel->toHandle(), &groupCount, nullptr, 0, nullptr, launchParams, false)); auto result = commandList->appendLaunchKernel(kernel.toHandle(), &groupCount, nullptr, 0, nullptr, launchParams, false);
EXPECT_EQ(0u, kernel->printPrintfOutputCalledTimes); EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(ZE_RESULT_SUCCESS, commandList->hostSynchronize(std::numeric_limits<uint64_t>::max())); EXPECT_EQ(1u, kernel.printPrintfOutputCalledTimes);
EXPECT_EQ(1u, kernel->printPrintfOutputCalledTimes); EXPECT_FALSE(kernel.hangDetectedPassedToPrintfOutput);
EXPECT_FALSE(kernel->hangDetectedPassedToPrintfOutput);
EXPECT_EQ(0u, commandList->getPrintfKernelContainer().size()); EXPECT_EQ(0u, commandList->getPrintfKernelContainer().size());
EXPECT_EQ(ZE_RESULT_SUCCESS, commandList->appendLaunchKernel(kernel->toHandle(), &groupCount, nullptr, 0, nullptr, launchParams, false)); result = commandList->appendLaunchKernel(kernel.toHandle(), &groupCount, nullptr, 0, nullptr, launchParams, false);
EXPECT_EQ(1u, kernel->printPrintfOutputCalledTimes); EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(ZE_RESULT_SUCCESS, commandList->hostSynchronize(std::numeric_limits<uint64_t>::max())); EXPECT_EQ(2u, kernel.printPrintfOutputCalledTimes);
EXPECT_EQ(2u, kernel->printPrintfOutputCalledTimes); EXPECT_FALSE(kernel.hangDetectedPassedToPrintfOutput);
EXPECT_FALSE(kernel->hangDetectedPassedToPrintfOutput);
EXPECT_EQ(0u, commandList->getPrintfKernelContainer().size()); EXPECT_EQ(0u, commandList->getPrintfKernelContainer().size());
} }
@@ -337,404 +323,24 @@ HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithPrintfWhenAppendToSynchro
std::unique_ptr<L0::CommandList> commandList(CommandList::createImmediate(productFamily, device, &queueDesc, false, NEO::EngineGroupType::RenderCompute, returnValue)); std::unique_ptr<L0::CommandList> commandList(CommandList::createImmediate(productFamily, device, &queueDesc, false, NEO::EngineGroupType::RenderCompute, returnValue));
auto kernel = new Mock<KernelImp>(); Mock<KernelImp> kernel;
kernel->module = module.get(); kernel.descriptor.kernelAttributes.flags.usesPrintf = true;
kernel->descriptor.kernelAttributes.flags.usesPrintf = true;
kernel->createPrintfBuffer();
static_cast<ModuleImp *>(module.get())->getPrintfKernelContainer().push_back(std::shared_ptr<Kernel>{kernel});
EXPECT_EQ(0u, kernel->printPrintfOutputCalledTimes);
ze_group_count_t groupCount{1, 1, 1}; ze_group_count_t groupCount{1, 1, 1};
CmdListKernelLaunchParams launchParams = {}; CmdListKernelLaunchParams launchParams = {};
EXPECT_EQ(ZE_RESULT_ERROR_DEVICE_LOST, commandList->appendLaunchKernel(kernel->toHandle(), &groupCount, nullptr, 0, nullptr, launchParams, false)); auto result = commandList->appendLaunchKernel(kernel.toHandle(), &groupCount, nullptr, 0, nullptr, launchParams, false);
EXPECT_EQ(1u, kernel->printPrintfOutputCalledTimes); EXPECT_EQ(ZE_RESULT_ERROR_DEVICE_LOST, result);
EXPECT_TRUE(kernel->hangDetectedPassedToPrintfOutput); EXPECT_EQ(1u, kernel.printPrintfOutputCalledTimes);
EXPECT_TRUE(kernel.hangDetectedPassedToPrintfOutput);
EXPECT_EQ(0u, commandList->getPrintfKernelContainer().size()); EXPECT_EQ(0u, commandList->getPrintfKernelContainer().size());
EXPECT_EQ(ZE_RESULT_ERROR_DEVICE_LOST, commandList->appendLaunchKernel(kernel->toHandle(), &groupCount, nullptr, 0, nullptr, launchParams, false)); result = commandList->appendLaunchKernel(kernel.toHandle(), &groupCount, nullptr, 0, nullptr, launchParams, false);
EXPECT_EQ(2u, kernel->printPrintfOutputCalledTimes); EXPECT_EQ(ZE_RESULT_ERROR_DEVICE_LOST, result);
EXPECT_TRUE(kernel->hangDetectedPassedToPrintfOutput); EXPECT_EQ(2u, kernel.printPrintfOutputCalledTimes);
EXPECT_TRUE(kernel.hangDetectedPassedToPrintfOutput);
EXPECT_EQ(0u, commandList->getPrintfKernelContainer().size()); EXPECT_EQ(0u, commandList->getPrintfKernelContainer().size());
} }
HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithPrintfAppendedToCommandListAndDestroyKernelAfterSynchronizationThenSuccessIsReturned) {
ze_result_t result;
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, result));
auto kernel = new Mock<KernelImp>();
kernel->module = module.get();
kernel->descriptor.kernelAttributes.flags.usesPrintf = true;
kernel->createPrintfBuffer();
static_cast<ModuleImp *>(module.get())->getPrintfKernelContainer().push_back(std::shared_ptr<Kernel>{kernel});
ze_group_count_t groupCount{1, 1, 1};
CmdListKernelLaunchParams launchParams = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, commandList->appendLaunchKernel(kernel->toHandle(), &groupCount, nullptr, 0, nullptr, launchParams, false));
EXPECT_EQ(ZE_RESULT_SUCCESS, commandList->close());
ze_command_queue_handle_t commandQueueHandle;
ze_command_queue_desc_t desc{};
desc.stype = ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC;
desc.pNext = nullptr;
desc.mode = ZE_COMMAND_QUEUE_MODE_ASYNCHRONOUS;
desc.ordinal = 0u;
desc.index = 0u;
EXPECT_EQ(ZE_RESULT_SUCCESS, device->createCommandQueue(&desc, &commandQueueHandle));
auto commandQueue = static_cast<L0::ult::CommandQueue *>(L0::CommandQueue::fromHandle(commandQueueHandle));
ASSERT_NE(commandQueue, nullptr);
auto commandListHandle = commandList->toHandle();
EXPECT_EQ(0u, kernel->printPrintfOutputCalledTimes);
EXPECT_EQ(ZE_RESULT_SUCCESS, commandQueue->executeCommandLists(1, &commandListHandle, nullptr, false));
EXPECT_EQ(ZE_RESULT_SUCCESS, commandQueue->synchronize(std::numeric_limits<uint64_t>::max()));
EXPECT_EQ(1u, kernel->printPrintfOutputCalledTimes);
EXPECT_EQ(ZE_RESULT_SUCCESS, kernel->destroy());
EXPECT_EQ(nullptr, static_cast<ModuleImp *>(module.get())->getPrintfKernelContainer()[0].get());
commandQueue->destroy();
}
HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithPrintfAndEventAppendedToCommandListAndDestroyKernelAfterQueueSyncThenSuccessIsReturnedAndEventSyncDoesNotAccessKernel) {
ze_result_t result;
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, result));
auto kernel = new Mock<KernelImp>();
kernel->module = module.get();
kernel->descriptor.kernelAttributes.flags.usesPrintf = true;
kernel->createPrintfBuffer();
static_cast<ModuleImp *>(module.get())->getPrintfKernelContainer().push_back(std::shared_ptr<Kernel>{kernel});
ze_event_pool_desc_t eventPoolDesc = {};
eventPoolDesc.stype = ZE_STRUCTURE_TYPE_EVENT_POOL_DESC;
eventPoolDesc.pNext = nullptr;
eventPoolDesc.count = 1;
eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE;
auto eventPool = std::unique_ptr<::L0::EventPool>(::L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, result));
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
ze_event_desc_t eventDesc = {};
eventDesc.stype = ZE_STRUCTURE_TYPE_EVENT_DESC;
eventDesc.pNext = nullptr;
eventDesc.index = 0;
eventDesc.signal = ZE_EVENT_SCOPE_FLAG_HOST;
eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
auto event = std::unique_ptr<::L0::Event>(::L0::Event::create<typename FamilyType::TimestampPacketType>(eventPool.get(), &eventDesc, device));
auto hEventHandle = event->toHandle();
ze_group_count_t groupCount{1, 1, 1};
CmdListKernelLaunchParams launchParams = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, commandList->appendLaunchKernel(kernel->toHandle(), &groupCount, hEventHandle, 0, nullptr, launchParams, false));
EXPECT_NE(nullptr, event->getKernelForPrintf().lock().get());
EXPECT_NE(nullptr, event->getKernelWithPrintfDeviceMutex());
EXPECT_EQ(ZE_RESULT_SUCCESS, commandList->close());
ze_command_queue_handle_t commandQueueHandle;
ze_command_queue_desc_t desc{};
desc.stype = ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC;
desc.pNext = nullptr;
desc.mode = ZE_COMMAND_QUEUE_MODE_ASYNCHRONOUS;
desc.ordinal = 0u;
desc.index = 0u;
EXPECT_EQ(ZE_RESULT_SUCCESS, device->createCommandQueue(&desc, &commandQueueHandle));
auto commandQueue = static_cast<L0::ult::CommandQueue *>(L0::CommandQueue::fromHandle(commandQueueHandle));
ASSERT_NE(commandQueue, nullptr);
auto commandListHandle = commandList->toHandle();
EXPECT_EQ(0u, kernel->printPrintfOutputCalledTimes);
EXPECT_EQ(ZE_RESULT_SUCCESS, commandQueue->executeCommandLists(1, &commandListHandle, nullptr, false));
EXPECT_EQ(ZE_RESULT_SUCCESS, commandQueue->synchronize(std::numeric_limits<uint64_t>::max()));
*reinterpret_cast<uint32_t *>(event->getHostAddress()) = Event::STATE_SIGNALED;
EXPECT_EQ(1u, kernel->printPrintfOutputCalledTimes);
EXPECT_EQ(ZE_RESULT_SUCCESS, kernel->destroy());
EXPECT_EQ(nullptr, static_cast<ModuleImp *>(module.get())->getPrintfKernelContainer()[0].get());
EXPECT_EQ(1u, commandList->getPrintfKernelContainer().size());
EXPECT_EQ(nullptr, commandList->getPrintfKernelContainer()[0].lock());
EXPECT_EQ(nullptr, event->getKernelForPrintf().lock().get());
EXPECT_EQ(ZE_RESULT_SUCCESS, event->queryStatus());
EXPECT_EQ(ZE_RESULT_SUCCESS, event->hostSynchronize(std::numeric_limits<uint64_t>::max()));
EXPECT_EQ(nullptr, event->getKernelWithPrintfDeviceMutex());
commandQueue->destroy();
}
HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithPrintfAndEventAppendedToCommandListAndDestroyKernelAfterEventSyncThenSuccessIsReturnedAndQueueSyncDoesNotAccessKernel) {
ze_result_t result;
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, result));
auto kernel = new Mock<KernelImp>();
kernel->module = module.get();
kernel->descriptor.kernelAttributes.flags.usesPrintf = true;
kernel->createPrintfBuffer();
static_cast<ModuleImp *>(module.get())->getPrintfKernelContainer().push_back(std::shared_ptr<Kernel>{kernel});
ze_event_pool_desc_t eventPoolDesc = {};
eventPoolDesc.stype = ZE_STRUCTURE_TYPE_EVENT_POOL_DESC;
eventPoolDesc.pNext = nullptr;
eventPoolDesc.count = 1;
eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE;
auto eventPool = std::unique_ptr<::L0::EventPool>(::L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, result));
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
ze_event_desc_t eventDesc = {};
eventDesc.stype = ZE_STRUCTURE_TYPE_EVENT_DESC;
eventDesc.pNext = nullptr;
eventDesc.index = 0;
eventDesc.signal = ZE_EVENT_SCOPE_FLAG_HOST;
eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
auto event = std::unique_ptr<::L0::Event>(::L0::Event::create<typename FamilyType::TimestampPacketType>(eventPool.get(), &eventDesc, device));
auto hEventHandle = event->toHandle();
ze_group_count_t groupCount{1, 1, 1};
CmdListKernelLaunchParams launchParams = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, commandList->appendLaunchKernel(kernel->toHandle(), &groupCount, hEventHandle, 0, nullptr, launchParams, false));
EXPECT_NE(nullptr, event->getKernelForPrintf().lock().get());
EXPECT_NE(nullptr, event->getKernelWithPrintfDeviceMutex());
EXPECT_EQ(ZE_RESULT_SUCCESS, commandList->close());
ze_command_queue_handle_t commandQueueHandle;
ze_command_queue_desc_t desc{};
desc.stype = ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC;
desc.pNext = nullptr;
desc.mode = ZE_COMMAND_QUEUE_MODE_ASYNCHRONOUS;
desc.ordinal = 0u;
desc.index = 0u;
EXPECT_EQ(ZE_RESULT_SUCCESS, device->createCommandQueue(&desc, &commandQueueHandle));
auto commandQueue = static_cast<L0::ult::CommandQueue *>(L0::CommandQueue::fromHandle(commandQueueHandle));
ASSERT_NE(commandQueue, nullptr);
auto commandListHandle = commandList->toHandle();
EXPECT_EQ(0u, kernel->printPrintfOutputCalledTimes);
EXPECT_EQ(ZE_RESULT_SUCCESS, commandQueue->executeCommandLists(1, &commandListHandle, nullptr, false));
*reinterpret_cast<uint32_t *>(event->getHostAddress()) = Event::STATE_SIGNALED;
EXPECT_EQ(ZE_RESULT_SUCCESS, event->hostSynchronize(std::numeric_limits<uint64_t>::max()));
EXPECT_EQ(1u, kernel->printPrintfOutputCalledTimes);
EXPECT_EQ(ZE_RESULT_SUCCESS, kernel->destroy());
EXPECT_EQ(nullptr, static_cast<ModuleImp *>(module.get())->getPrintfKernelContainer()[0].get());
EXPECT_EQ(nullptr, event->getKernelForPrintf().lock().get());
EXPECT_EQ(nullptr, event->getKernelWithPrintfDeviceMutex());
EXPECT_EQ(ZE_RESULT_SUCCESS, commandQueue->synchronize(std::numeric_limits<uint64_t>::max()));
EXPECT_EQ(1u, commandList->getPrintfKernelContainer().size());
EXPECT_EQ(nullptr, commandList->getPrintfKernelContainer()[0].lock());
commandQueue->destroy();
}
HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithPrintfAppendedToImmCommandListWithFlushTaskSubmissionAndDestroyKernelAfterSynchronizationThenSuccessIsReturned) {
DebugManagerStateRestore restorer;
NEO::DebugManager.flags.EnableFlushTaskSubmission.set(1);
ze_result_t result;
ze_command_queue_desc_t queueDesc = {};
queueDesc.stype = ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC;
queueDesc.pNext = nullptr;
queueDesc.mode = ZE_COMMAND_QUEUE_MODE_ASYNCHRONOUS;
queueDesc.ordinal = 0;
queueDesc.index = 0;
std::unique_ptr<L0::CommandList> commandList(CommandList::createImmediate(productFamily, device, &queueDesc, false, NEO::EngineGroupType::RenderCompute, result));
auto kernel = new Mock<KernelImp>();
kernel->module = module.get();
kernel->descriptor.kernelAttributes.flags.usesPrintf = true;
kernel->createPrintfBuffer();
static_cast<ModuleImp *>(module.get())->getPrintfKernelContainer().push_back(std::shared_ptr<Kernel>{kernel});
EXPECT_EQ(0u, kernel->printPrintfOutputCalledTimes);
ze_group_count_t groupCount{1, 1, 1};
CmdListKernelLaunchParams launchParams = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, commandList->appendLaunchKernel(kernel->toHandle(), &groupCount, nullptr, 0, nullptr, launchParams, false));
EXPECT_EQ(ZE_RESULT_SUCCESS, commandList->hostSynchronize(std::numeric_limits<uint64_t>::max()));
EXPECT_EQ(1u, kernel->printPrintfOutputCalledTimes);
EXPECT_EQ(ZE_RESULT_SUCCESS, kernel->destroy());
EXPECT_EQ(nullptr, static_cast<ModuleImp *>(module.get())->getPrintfKernelContainer()[0].get());
}
HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithPrintfAndEventAppendedToImmCommandListWithFlushTaskSubmissionAndDestroyKernelAfterListSyncThenSuccessIsReturnedAndEventSyncDoesNotAccessKernel) {
DebugManagerStateRestore restorer;
NEO::DebugManager.flags.EnableFlushTaskSubmission.set(1);
ze_result_t result;
ze_command_queue_desc_t queueDesc = {};
queueDesc.stype = ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC;
queueDesc.pNext = nullptr;
queueDesc.mode = ZE_COMMAND_QUEUE_MODE_ASYNCHRONOUS;
queueDesc.ordinal = 0;
queueDesc.index = 0;
std::unique_ptr<L0::CommandList> commandList(CommandList::createImmediate(productFamily, device, &queueDesc, false, NEO::EngineGroupType::RenderCompute, result));
auto kernel = new Mock<KernelImp>();
kernel->module = module.get();
kernel->descriptor.kernelAttributes.flags.usesPrintf = true;
kernel->createPrintfBuffer();
static_cast<ModuleImp *>(module.get())->getPrintfKernelContainer().push_back(std::shared_ptr<Kernel>{kernel});
ze_event_pool_desc_t eventPoolDesc = {};
eventPoolDesc.stype = ZE_STRUCTURE_TYPE_EVENT_POOL_DESC;
eventPoolDesc.pNext = nullptr;
eventPoolDesc.count = 1;
eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE;
auto eventPool = std::unique_ptr<::L0::EventPool>(::L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, result));
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
ze_event_desc_t eventDesc = {};
eventDesc.stype = ZE_STRUCTURE_TYPE_EVENT_DESC;
eventDesc.pNext = nullptr;
eventDesc.index = 0;
eventDesc.signal = ZE_EVENT_SCOPE_FLAG_HOST;
eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
auto event = std::unique_ptr<::L0::Event>(::L0::Event::create<typename FamilyType::TimestampPacketType>(eventPool.get(), &eventDesc, device));
auto hEventHandle = event->toHandle();
EXPECT_EQ(0u, kernel->printPrintfOutputCalledTimes);
ze_group_count_t groupCount{1, 1, 1};
CmdListKernelLaunchParams launchParams = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, commandList->appendLaunchKernel(kernel->toHandle(), &groupCount, hEventHandle, 0, nullptr, launchParams, false));
EXPECT_NE(nullptr, event->getKernelForPrintf().lock().get());
EXPECT_NE(nullptr, event->getKernelWithPrintfDeviceMutex());
EXPECT_EQ(ZE_RESULT_SUCCESS, commandList->hostSynchronize(std::numeric_limits<uint64_t>::max()));
*reinterpret_cast<uint32_t *>(event->getHostAddress()) = Event::STATE_SIGNALED;
EXPECT_EQ(1u, kernel->printPrintfOutputCalledTimes);
EXPECT_EQ(ZE_RESULT_SUCCESS, kernel->destroy());
EXPECT_EQ(nullptr, static_cast<ModuleImp *>(module.get())->getPrintfKernelContainer()[0].get());
EXPECT_EQ(nullptr, event->getKernelForPrintf().lock().get());
EXPECT_EQ(ZE_RESULT_SUCCESS, event->queryStatus());
EXPECT_EQ(ZE_RESULT_SUCCESS, event->hostSynchronize(std::numeric_limits<uint64_t>::max()));
EXPECT_EQ(nullptr, event->getKernelWithPrintfDeviceMutex());
}
HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithPrintfAndEventAppendedToImmCommandListWithFlushTaskSubmissionAndDestroyKernelAfterEventSyncThenSuccessIsReturnedAndListSyncDoesNotAccessKernel) {
DebugManagerStateRestore restorer;
NEO::DebugManager.flags.EnableFlushTaskSubmission.set(1);
ze_result_t result;
ze_command_queue_desc_t queueDesc = {};
queueDesc.stype = ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC;
queueDesc.pNext = nullptr;
queueDesc.mode = ZE_COMMAND_QUEUE_MODE_ASYNCHRONOUS;
queueDesc.ordinal = 0;
queueDesc.index = 0;
std::unique_ptr<L0::CommandList> commandList(CommandList::createImmediate(productFamily, device, &queueDesc, false, NEO::EngineGroupType::RenderCompute, result));
auto kernel = new Mock<KernelImp>();
kernel->module = module.get();
kernel->descriptor.kernelAttributes.flags.usesPrintf = true;
kernel->createPrintfBuffer();
static_cast<ModuleImp *>(module.get())->getPrintfKernelContainer().push_back(std::shared_ptr<Kernel>{kernel});
ze_event_pool_desc_t eventPoolDesc = {};
eventPoolDesc.stype = ZE_STRUCTURE_TYPE_EVENT_POOL_DESC;
eventPoolDesc.pNext = nullptr;
eventPoolDesc.count = 1;
eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE;
auto eventPool = std::unique_ptr<::L0::EventPool>(::L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, result));
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
ze_event_desc_t eventDesc = {};
eventDesc.stype = ZE_STRUCTURE_TYPE_EVENT_DESC;
eventDesc.pNext = nullptr;
eventDesc.index = 0;
eventDesc.signal = ZE_EVENT_SCOPE_FLAG_HOST;
eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
auto event = std::unique_ptr<::L0::Event>(::L0::Event::create<typename FamilyType::TimestampPacketType>(eventPool.get(), &eventDesc, device));
auto hEventHandle = event->toHandle();
EXPECT_EQ(0u, kernel->printPrintfOutputCalledTimes);
ze_group_count_t groupCount{1, 1, 1};
CmdListKernelLaunchParams launchParams = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, commandList->appendLaunchKernel(kernel->toHandle(), &groupCount, hEventHandle, 0, nullptr, launchParams, false));
EXPECT_NE(nullptr, event->getKernelForPrintf().lock().get());
EXPECT_NE(nullptr, event->getKernelWithPrintfDeviceMutex());
*reinterpret_cast<uint32_t *>(event->getHostAddress()) = Event::STATE_SIGNALED;
EXPECT_EQ(ZE_RESULT_SUCCESS, event->hostSynchronize(std::numeric_limits<uint64_t>::max()));
EXPECT_EQ(1u, kernel->printPrintfOutputCalledTimes);
EXPECT_EQ(ZE_RESULT_SUCCESS, kernel->destroy());
EXPECT_EQ(nullptr, static_cast<ModuleImp *>(module.get())->getPrintfKernelContainer()[0].get());
EXPECT_EQ(nullptr, event->getKernelForPrintf().lock().get());
EXPECT_EQ(nullptr, event->getKernelWithPrintfDeviceMutex());
EXPECT_EQ(ZE_RESULT_SUCCESS, commandList->hostSynchronize(std::numeric_limits<uint64_t>::max()));
}
HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithPrintfAppendedToImmCommandListWithoutFlushTaskSubmissionAndDestroyKernelAfterSynchronizationThenSuccessIsReturned) {
DebugManagerStateRestore restorer;
NEO::DebugManager.flags.EnableFlushTaskSubmission.set(0);
ze_result_t result;
ze_command_queue_desc_t queueDesc = {};
queueDesc.stype = ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC;
queueDesc.pNext = nullptr;
queueDesc.mode = ZE_COMMAND_QUEUE_MODE_ASYNCHRONOUS;
queueDesc.ordinal = 0;
queueDesc.index = 0;
std::unique_ptr<L0::CommandList> commandList(CommandList::createImmediate(productFamily, device, &queueDesc, false, NEO::EngineGroupType::RenderCompute, result));
auto kernel = new Mock<KernelImp>();
kernel->module = module.get();
kernel->descriptor.kernelAttributes.flags.usesPrintf = true;
kernel->createPrintfBuffer();
static_cast<ModuleImp *>(module.get())->getPrintfKernelContainer().push_back(std::shared_ptr<Kernel>{kernel});
EXPECT_EQ(0u, kernel->printPrintfOutputCalledTimes);
ze_group_count_t groupCount{1, 1, 1};
CmdListKernelLaunchParams launchParams = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, commandList->appendLaunchKernel(kernel->toHandle(), &groupCount, nullptr, 0, nullptr, launchParams, false));
EXPECT_EQ(ZE_RESULT_SUCCESS, commandList->hostSynchronize(std::numeric_limits<uint64_t>::max()));
EXPECT_EQ(1u, kernel->printPrintfOutputCalledTimes);
EXPECT_EQ(ZE_RESULT_SUCCESS, kernel->destroy());
EXPECT_EQ(nullptr, static_cast<ModuleImp *>(module.get())->getPrintfKernelContainer()[0].get());
}
HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithPrintfAndEventAppendedToImmCommandListWithoutFlushTaskSubmissionAndDestroyKernelAfterListSyncThenSuccessIsReturnedAndEventSyncDoesNotAccessKernel) {
DebugManagerStateRestore restorer;
NEO::DebugManager.flags.EnableFlushTaskSubmission.set(0);
ze_result_t result;
ze_command_queue_desc_t queueDesc = {};
queueDesc.stype = ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC;
queueDesc.pNext = nullptr;
queueDesc.mode = ZE_COMMAND_QUEUE_MODE_ASYNCHRONOUS;
queueDesc.ordinal = 0;
queueDesc.index = 0;
std::unique_ptr<L0::CommandList> commandList(CommandList::createImmediate(productFamily, device, &queueDesc, false, NEO::EngineGroupType::RenderCompute, result));
auto kernel = new Mock<KernelImp>();
kernel->module = module.get();
kernel->descriptor.kernelAttributes.flags.usesPrintf = true;
kernel->createPrintfBuffer();
static_cast<ModuleImp *>(module.get())->getPrintfKernelContainer().push_back(std::shared_ptr<Kernel>{kernel});
ze_event_pool_desc_t eventPoolDesc = {};
eventPoolDesc.stype = ZE_STRUCTURE_TYPE_EVENT_POOL_DESC;
eventPoolDesc.pNext = nullptr;
eventPoolDesc.count = 1;
eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE;
auto eventPool = std::unique_ptr<::L0::EventPool>(::L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, result));
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
ze_event_desc_t eventDesc = {};
eventDesc.stype = ZE_STRUCTURE_TYPE_EVENT_DESC;
eventDesc.pNext = nullptr;
eventDesc.index = 0;
eventDesc.signal = ZE_EVENT_SCOPE_FLAG_HOST;
eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
auto event = std::unique_ptr<::L0::Event>(::L0::Event::create<typename FamilyType::TimestampPacketType>(eventPool.get(), &eventDesc, device));
auto hEventHandle = event->toHandle();
EXPECT_EQ(0u, kernel->printPrintfOutputCalledTimes);
ze_group_count_t groupCount{1, 1, 1};
CmdListKernelLaunchParams launchParams = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, commandList->appendLaunchKernel(kernel->toHandle(), &groupCount, hEventHandle, 0, nullptr, launchParams, false));
EXPECT_NE(nullptr, event->getKernelForPrintf().lock().get());
EXPECT_NE(nullptr, event->getKernelWithPrintfDeviceMutex());
EXPECT_EQ(ZE_RESULT_SUCCESS, commandList->hostSynchronize(std::numeric_limits<uint64_t>::max()));
*reinterpret_cast<uint32_t *>(event->getHostAddress()) = Event::STATE_SIGNALED;
EXPECT_EQ(1u, kernel->printPrintfOutputCalledTimes);
EXPECT_EQ(ZE_RESULT_SUCCESS, kernel->destroy());
EXPECT_EQ(nullptr, static_cast<ModuleImp *>(module.get())->getPrintfKernelContainer()[0].get());
EXPECT_EQ(nullptr, event->getKernelForPrintf().lock().get());
EXPECT_EQ(ZE_RESULT_SUCCESS, event->queryStatus());
EXPECT_EQ(ZE_RESULT_SUCCESS, event->hostSynchronize(std::numeric_limits<uint64_t>::max()));
EXPECT_EQ(nullptr, event->getKernelWithPrintfDeviceMutex());
}
HWTEST_F(CommandListAppendLaunchKernel, WhenAppendingMultipleTimesThenSshIsNotDepletedButReallocated) { HWTEST_F(CommandListAppendLaunchKernel, WhenAppendingMultipleTimesThenSshIsNotDepletedButReallocated) {
createKernel(); createKernel();
ze_result_t returnValue; ze_result_t returnValue;

View File

@@ -266,8 +266,7 @@ HWTEST2_F(CommandListAppendLaunchKernel, givenImmediateCommandListWhenAppendingL
HWTEST2_F(CommandListAppendLaunchKernel, givenNonemptyAllocPrintfBufferKernelWhenAppendingLaunchKernelIndirectThenKernelIsStoredOnEvent, IsAtLeastSkl) { HWTEST2_F(CommandListAppendLaunchKernel, givenNonemptyAllocPrintfBufferKernelWhenAppendingLaunchKernelIndirectThenKernelIsStoredOnEvent, IsAtLeastSkl) {
Mock<Module> module(this->device, nullptr); Mock<Module> module(this->device, nullptr);
std::shared_ptr<Mock<::L0::KernelImp>> kernel{new Mock<::L0::KernelImp>()}; Mock<::L0::KernelImp> kernel;
static_cast<ModuleImp *>(&module)->getPrintfKernelContainer().push_back(kernel);
ze_result_t returnValue; ze_result_t returnValue;
std::unique_ptr<L0::CommandList> commandList(L0::CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, returnValue)); std::unique_ptr<L0::CommandList> commandList(L0::CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, returnValue));
@@ -275,9 +274,9 @@ HWTEST2_F(CommandListAppendLaunchKernel, givenNonemptyAllocPrintfBufferKernelWhe
eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE; eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE;
eventPoolDesc.count = 1; eventPoolDesc.count = 1;
kernel->module = &module; kernel.module = &module;
kernel->descriptor.kernelAttributes.flags.usesPrintf = true; kernel.descriptor.kernelAttributes.flags.usesPrintf = true;
kernel->createPrintfBuffer(); kernel.createPrintfBuffer();
ze_event_desc_t eventDesc = {}; ze_event_desc_t eventDesc = {};
eventDesc.index = 0; eventDesc.index = 0;
@@ -287,15 +286,15 @@ HWTEST2_F(CommandListAppendLaunchKernel, givenNonemptyAllocPrintfBufferKernelWhe
auto event = std::unique_ptr<Event>(Event::create<typename FamilyType::TimestampPacketType>(eventPool.get(), &eventDesc, device)); auto event = std::unique_ptr<Event>(Event::create<typename FamilyType::TimestampPacketType>(eventPool.get(), &eventDesc, device));
ze_group_count_t groupCount{1, 1, 1}; ze_group_count_t groupCount{1, 1, 1};
auto result = commandList->appendLaunchKernelIndirect(kernel->toHandle(), &groupCount, event->toHandle(), 0, nullptr, false); auto result = commandList->appendLaunchKernelIndirect(kernel.toHandle(), &groupCount, event->toHandle(), 0, nullptr, false);
EXPECT_EQ(ZE_RESULT_SUCCESS, result); EXPECT_EQ(ZE_RESULT_SUCCESS, result);
ASSERT_FALSE(event->getKernelForPrintf().expired()); ASSERT_NE(nullptr, event->getKernelForPrintf());
} }
HWTEST2_F(CommandListAppendLaunchKernel, givenEmptyAllocPrintfBufferKernelWhenAppendingLaunchKernelIndirectThenKernelIsNotStoredOnEvent, IsAtLeastSkl) { HWTEST2_F(CommandListAppendLaunchKernel, givenEmptyAllocPrintfBufferKernelWhenAppendingLaunchKernelIndirectThenKernelIsNotStoredOnEvent, IsAtLeastSkl) {
Mock<Module> module(this->device, nullptr); Mock<Module> module(this->device, nullptr);
std::shared_ptr<Mock<::L0::KernelImp>> kernel{new Mock<::L0::KernelImp>()}; Mock<::L0::KernelImp> kernel;
ze_result_t returnValue; ze_result_t returnValue;
std::unique_ptr<L0::CommandList> commandList(L0::CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, returnValue)); std::unique_ptr<L0::CommandList> commandList(L0::CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, returnValue));
@@ -303,8 +302,8 @@ HWTEST2_F(CommandListAppendLaunchKernel, givenEmptyAllocPrintfBufferKernelWhenAp
eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE; eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE;
eventPoolDesc.count = 1; eventPoolDesc.count = 1;
kernel->module = &module; kernel.module = &module;
kernel->descriptor.kernelAttributes.flags.usesPrintf = false; kernel.descriptor.kernelAttributes.flags.usesPrintf = false;
ze_event_desc_t eventDesc = {}; ze_event_desc_t eventDesc = {};
eventDesc.index = 0; eventDesc.index = 0;
@@ -314,25 +313,24 @@ HWTEST2_F(CommandListAppendLaunchKernel, givenEmptyAllocPrintfBufferKernelWhenAp
auto event = std::unique_ptr<Event>(Event::create<typename FamilyType::TimestampPacketType>(eventPool.get(), &eventDesc, device)); auto event = std::unique_ptr<Event>(Event::create<typename FamilyType::TimestampPacketType>(eventPool.get(), &eventDesc, device));
ze_group_count_t groupCount{1, 1, 1}; ze_group_count_t groupCount{1, 1, 1};
auto result = commandList->appendLaunchKernelIndirect(kernel->toHandle(), &groupCount, event->toHandle(), 0, nullptr, false); auto result = commandList->appendLaunchKernelIndirect(kernel.toHandle(), &groupCount, event->toHandle(), 0, nullptr, false);
EXPECT_EQ(ZE_RESULT_SUCCESS, result); EXPECT_EQ(ZE_RESULT_SUCCESS, result);
ASSERT_TRUE(event->getKernelForPrintf().expired()); ASSERT_EQ(nullptr, event->getKernelForPrintf());
} }
HWTEST2_F(CommandListAppendLaunchKernel, givenNonemptyAllocPrintfBufferKernelWhenAppendingLaunchKernelWithParamThenKernelIsStoredOnEvent, IsAtLeastSkl) { HWTEST2_F(CommandListAppendLaunchKernel, givenNonemptyAllocPrintfBufferKernelWhenAppendingLaunchKernelWithParamThenKernelIsStoredOnEvent, IsAtLeastSkl) {
Mock<Module> module(this->device, nullptr); Mock<Module> module(this->device, nullptr);
std::shared_ptr<Mock<::L0::KernelImp>> kernel{new Mock<::L0::KernelImp>()}; Mock<::L0::KernelImp> kernel;
static_cast<ModuleImp *>(&module)->getPrintfKernelContainer().push_back(kernel);
ze_result_t returnValue; ze_result_t returnValue;
ze_event_pool_desc_t eventPoolDesc = {}; ze_event_pool_desc_t eventPoolDesc = {};
eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE; eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE;
eventPoolDesc.count = 1; eventPoolDesc.count = 1;
kernel->module = &module; kernel.module = &module;
kernel->descriptor.kernelAttributes.flags.usesPrintf = true; kernel.descriptor.kernelAttributes.flags.usesPrintf = true;
kernel->createPrintfBuffer(); kernel.createPrintfBuffer();
ze_event_desc_t eventDesc = {}; ze_event_desc_t eventDesc = {};
eventDesc.index = 0; eventDesc.index = 0;
@@ -348,23 +346,23 @@ HWTEST2_F(CommandListAppendLaunchKernel, givenNonemptyAllocPrintfBufferKernelWhe
auto pCommandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>(); auto pCommandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
pCommandList->initialize(device, NEO::EngineGroupType::Compute, 0u); pCommandList->initialize(device, NEO::EngineGroupType::Compute, 0u);
auto result = pCommandList->appendLaunchKernelWithParams(kernel.get(), &groupCount, event.get(), launchParams); auto result = pCommandList->appendLaunchKernelWithParams(&kernel, &groupCount, event.get(), launchParams);
EXPECT_EQ(ZE_RESULT_SUCCESS, result); EXPECT_EQ(ZE_RESULT_SUCCESS, result);
ASSERT_FALSE(event->getKernelForPrintf().expired()); ASSERT_NE(nullptr, event->getKernelForPrintf());
} }
HWTEST2_F(CommandListAppendLaunchKernel, givenEmptyAllocPrintfBufferKernelWhenAppendingLaunchKernelWithParamThenKernelIsNotStoredOnEvent, IsAtLeastSkl) { HWTEST2_F(CommandListAppendLaunchKernel, givenEmptyAllocPrintfBufferKernelWhenAppendingLaunchKernelWithParamThenKernelIsNotStoredOnEvent, IsAtLeastSkl) {
Mock<Module> module(this->device, nullptr); Mock<Module> module(this->device, nullptr);
std::shared_ptr<Mock<::L0::KernelImp>> kernel{new Mock<::L0::KernelImp>()}; Mock<::L0::KernelImp> kernel;
ze_result_t returnValue; ze_result_t returnValue;
ze_event_pool_desc_t eventPoolDesc = {}; ze_event_pool_desc_t eventPoolDesc = {};
eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE; eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE;
eventPoolDesc.count = 1; eventPoolDesc.count = 1;
kernel->module = &module; kernel.module = &module;
kernel->descriptor.kernelAttributes.flags.usesPrintf = false; kernel.descriptor.kernelAttributes.flags.usesPrintf = false;
ze_event_desc_t eventDesc = {}; ze_event_desc_t eventDesc = {};
eventDesc.index = 0; eventDesc.index = 0;
@@ -380,10 +378,10 @@ HWTEST2_F(CommandListAppendLaunchKernel, givenEmptyAllocPrintfBufferKernelWhenAp
auto pCommandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>(); auto pCommandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
pCommandList->initialize(device, NEO::EngineGroupType::Compute, 0u); pCommandList->initialize(device, NEO::EngineGroupType::Compute, 0u);
auto result = pCommandList->appendLaunchKernelWithParams(kernel.get(), &groupCount, event.get(), launchParams); auto result = pCommandList->appendLaunchKernelWithParams(&kernel, &groupCount, event.get(), launchParams);
EXPECT_EQ(ZE_RESULT_SUCCESS, result); EXPECT_EQ(ZE_RESULT_SUCCESS, result);
ASSERT_TRUE(event->getKernelForPrintf().expired()); ASSERT_EQ(nullptr, event->getKernelForPrintf());
} }
HWTEST2_F(CommandListAppendLaunchKernel, givenImmediateCommandListWhenAppendingLaunchKernelIndirectThenKernelIsExecutedOnImmediateCmdQ, IsAtLeastSkl) { HWTEST2_F(CommandListAppendLaunchKernel, givenImmediateCommandListWhenAppendingLaunchKernelIndirectThenKernelIsExecutedOnImmediateCmdQ, IsAtLeastSkl) {

View File

@@ -81,17 +81,16 @@ TEST_F(CommandQueueCreate, whenSynchronizeByPollingTaskCountThenCallsPrintOutput
false, false,
returnValue)); returnValue));
std::shared_ptr<Mock<KernelImp>> kernel1{new Mock<KernelImp>()}; Mock<KernelImp> kernel1, kernel2;
std::shared_ptr<Mock<KernelImp>> kernel2{new Mock<KernelImp>()};
commandQueue->printfKernelContainer.push_back(std::weak_ptr<Kernel>{kernel1}); commandQueue->printfKernelContainer.push_back(&kernel1);
commandQueue->printfKernelContainer.push_back(std::weak_ptr<Kernel>{kernel2}); commandQueue->printfKernelContainer.push_back(&kernel2);
commandQueue->synchronizeByPollingForTaskCount(0u); commandQueue->synchronizeByPollingForTaskCount(0u);
EXPECT_EQ(0u, commandQueue->printfKernelContainer.size()); EXPECT_EQ(0u, commandQueue->printfKernelContainer.size());
EXPECT_EQ(1u, kernel1->printPrintfOutputCalledTimes); EXPECT_EQ(1u, kernel1.printPrintfOutputCalledTimes);
EXPECT_EQ(1u, kernel2->printPrintfOutputCalledTimes); EXPECT_EQ(1u, kernel2.printPrintfOutputCalledTimes);
commandQueue->destroy(); commandQueue->destroy();
} }
@@ -108,20 +107,20 @@ HWTEST_F(CommandQueueCreate, givenPrintfKernelAndDetectedHangWhenSynchronizingBy
false, false,
returnValue)); returnValue));
std::shared_ptr<Mock<KernelImp>> kernel1{new Mock<KernelImp>()}; Mock<KernelImp> kernel1;
TaskCountType currentTaskCount = 33u; TaskCountType currentTaskCount = 33u;
auto &csr = neoDevice->getUltCommandStreamReceiver<FamilyType>(); auto &csr = neoDevice->getUltCommandStreamReceiver<FamilyType>();
csr.callBaseWaitForCompletionWithTimeout = false; csr.callBaseWaitForCompletionWithTimeout = false;
csr.latestWaitForCompletionWithTimeoutTaskCount = currentTaskCount; csr.latestWaitForCompletionWithTimeoutTaskCount = currentTaskCount;
csr.returnWaitForCompletionWithTimeout = WaitStatus::GpuHang; csr.returnWaitForCompletionWithTimeout = WaitStatus::GpuHang;
commandQueue->printfKernelContainer.push_back(std::weak_ptr<Kernel>{kernel1}); commandQueue->printfKernelContainer.push_back(&kernel1);
commandQueue->synchronizeByPollingForTaskCount(0u); commandQueue->synchronizeByPollingForTaskCount(0u);
EXPECT_EQ(0u, commandQueue->printfKernelContainer.size()); EXPECT_EQ(0u, commandQueue->printfKernelContainer.size());
EXPECT_EQ(1u, kernel1->printPrintfOutputCalledTimes); EXPECT_EQ(1u, kernel1.printPrintfOutputCalledTimes);
EXPECT_TRUE(kernel1->hangDetectedPassedToPrintfOutput); EXPECT_TRUE(kernel1.hangDetectedPassedToPrintfOutput);
commandQueue->destroy(); commandQueue->destroy();
} }
@@ -141,18 +140,18 @@ HWTEST_F(CommandQueueCreate, givenPrintfKernelAndDetectedHangWhenSynchronizingTh
false, false,
returnValue)); returnValue));
std::shared_ptr<Mock<KernelImp>> kernel1{new Mock<KernelImp>()}; Mock<KernelImp> kernel1;
TaskCountType currentTaskCount = 33u; TaskCountType currentTaskCount = 33u;
auto &csr = neoDevice->getUltCommandStreamReceiver<FamilyType>(); auto &csr = neoDevice->getUltCommandStreamReceiver<FamilyType>();
csr.latestWaitForCompletionWithTimeoutTaskCount = currentTaskCount; csr.latestWaitForCompletionWithTimeoutTaskCount = currentTaskCount;
csr.waitForTaskCountWithKmdNotifyFallbackReturnValue = WaitStatus::GpuHang; csr.waitForTaskCountWithKmdNotifyFallbackReturnValue = WaitStatus::GpuHang;
commandQueue->printfKernelContainer.push_back(std::weak_ptr<Kernel>{kernel1}); commandQueue->printfKernelContainer.push_back(&kernel1);
commandQueue->synchronize(std::numeric_limits<uint64_t>::max()); commandQueue->synchronize(std::numeric_limits<uint64_t>::max());
EXPECT_EQ(0u, commandQueue->printfKernelContainer.size()); EXPECT_EQ(0u, commandQueue->printfKernelContainer.size());
EXPECT_EQ(1u, kernel1->printPrintfOutputCalledTimes); EXPECT_EQ(1u, kernel1.printPrintfOutputCalledTimes);
EXPECT_TRUE(kernel1->hangDetectedPassedToPrintfOutput); EXPECT_TRUE(kernel1.hangDetectedPassedToPrintfOutput);
commandQueue->destroy(); commandQueue->destroy();
} }
@@ -326,7 +325,7 @@ HWTEST_F(CommandQueueCreate, given100CmdListsWhenExecutingThenCommandStreamIsNot
returnValue)); returnValue));
ASSERT_NE(nullptr, commandQueue); ASSERT_NE(nullptr, commandQueue);
Mock<::L0::KernelImp> kernel; Mock<KernelImp> kernel;
kernel.immutableData.device = device; kernel.immutableData.device = device;
auto commandList = std::unique_ptr<CommandList>(whiteboxCast(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, returnValue))); auto commandList = std::unique_ptr<CommandList>(whiteboxCast(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, returnValue)));
@@ -379,7 +378,7 @@ HWTEST2_F(CommandQueueCreate, givenLogicalStateHelperWhenExecutingThenMergeState
auto ultCsr = static_cast<UltCommandStreamReceiver<FamilyType> *>(commandQueue->getCsr()); auto ultCsr = static_cast<UltCommandStreamReceiver<FamilyType> *>(commandQueue->getCsr());
ultCsr->logicalStateHelper.reset(mockCsrLogicalStateHelper); ultCsr->logicalStateHelper.reset(mockCsrLogicalStateHelper);
Mock<::L0::KernelImp> kernel; Mock<KernelImp> kernel;
kernel.immutableData.device = device; kernel.immutableData.device = device;
auto commandList = std::unique_ptr<L0::ult::CommandList>(whiteboxCast(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, returnValue))); auto commandList = std::unique_ptr<L0::ult::CommandList>(whiteboxCast(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, returnValue)));
@@ -418,7 +417,7 @@ HWTEST2_F(CommandQueueCreate, givenLogicalStateHelperAndImmediateCmdListWhenExec
auto ultCsr = static_cast<UltCommandStreamReceiver<FamilyType> *>(commandQueue->getCsr()); auto ultCsr = static_cast<UltCommandStreamReceiver<FamilyType> *>(commandQueue->getCsr());
ultCsr->logicalStateHelper.reset(mockCsrLogicalStateHelper); ultCsr->logicalStateHelper.reset(mockCsrLogicalStateHelper);
Mock<::L0::KernelImp> kernel; Mock<KernelImp> kernel;
kernel.immutableData.device = device; kernel.immutableData.device = device;
auto commandList = std::unique_ptr<L0::ult::CommandList>(whiteboxCast(CommandList::createImmediate(productFamily, device, &desc, false, NEO::EngineGroupType::RenderCompute, returnValue))); auto commandList = std::unique_ptr<L0::ult::CommandList>(whiteboxCast(CommandList::createImmediate(productFamily, device, &desc, false, NEO::EngineGroupType::RenderCompute, returnValue)));
@@ -443,7 +442,7 @@ HWTEST2_F(CommandQueueCreate, givenOutOfHostMemoryErrorFromSubmitBatchBufferWhen
commandQueue->initialize(false, false, false); commandQueue->initialize(false, false, false);
commandQueue->submitBatchBufferReturnValue = NEO::SubmissionStatus::OUT_OF_HOST_MEMORY; commandQueue->submitBatchBufferReturnValue = NEO::SubmissionStatus::OUT_OF_HOST_MEMORY;
Mock<::L0::KernelImp> kernel; Mock<KernelImp> kernel;
kernel.immutableData.device = device; kernel.immutableData.device = device;
ze_result_t returnValue; ze_result_t returnValue;
@@ -467,7 +466,7 @@ HWTEST2_F(CommandQueueCreate, givenGpuHangInReservingLinearStreamWhenExecutingCo
MockCommandQueueHw<gfxCoreFamily> commandQueue(device, neoDevice->getDefaultEngine().commandStreamReceiver, &desc); MockCommandQueueHw<gfxCoreFamily> commandQueue(device, neoDevice->getDefaultEngine().commandStreamReceiver, &desc);
commandQueue.reserveLinearStreamSizeReturnValue = NEO::WaitStatus::GpuHang; commandQueue.reserveLinearStreamSizeReturnValue = NEO::WaitStatus::GpuHang;
Mock<::L0::KernelImp> kernel; Mock<KernelImp> kernel;
kernel.immutableData.device = device; kernel.immutableData.device = device;
ze_result_t returnValue; ze_result_t returnValue;

View File

@@ -3569,36 +3569,31 @@ TEST_F(EventTests, GivenResetAllPacketsFalseWhenResetPacketsThenKernelCountAndPa
TEST_F(EventTests, givenCallToEventQueryStatusWithKernelPointerReturnsCounter) { TEST_F(EventTests, givenCallToEventQueryStatusWithKernelPointerReturnsCounter) {
auto event = std::make_unique<MockEventCompletion<uint32_t>>(eventPool.get(), 1u, device); auto event = std::make_unique<MockEventCompletion<uint32_t>>(eventPool.get(), 1u, device);
Mock<Module> mockModule(this->device, nullptr); Mock<Module> mockModule(this->device, nullptr);
std::shared_ptr<Mock<KernelImp>> mockKernel{new Mock<KernelImp>()}; Mock<KernelImp> mockKernel;
mockKernel->descriptor.kernelAttributes.flags.usesPrintf = true; mockKernel.descriptor.kernelAttributes.flags.usesPrintf = true;
mockKernel->module = &mockModule; mockKernel.module = &mockModule;
std::mutex mockDevicePrintfKernelMutex; event->setKernelForPrintf(&mockKernel);
event->setKernelForPrintf(std::weak_ptr<Kernel>{mockKernel}); EXPECT_NE(nullptr, event->getKernelForPrintf());
event->setKernelWithPrintfDeviceMutex(&mockDevicePrintfKernelMutex);
EXPECT_FALSE(event->getKernelForPrintf().expired());
EXPECT_NE(nullptr, event->getKernelWithPrintfDeviceMutex());
constexpr uint64_t timeout = std::numeric_limits<std::uint64_t>::max(); constexpr uint64_t timeout = std::numeric_limits<std::uint64_t>::max();
event->hostSynchronize(timeout); event->hostSynchronize(timeout);
EXPECT_EQ(1u, mockKernel->printPrintfOutputCalledTimes); EXPECT_EQ(1u, mockKernel.printPrintfOutputCalledTimes);
} }
TEST_F(EventTests, givenCallToEventQueryStatusWithNullKernelPointerReturnsCounter) { TEST_F(EventTests, givenCallToEventQueryStatusWithNullKernelPointerReturnsCounter) {
auto event = std::make_unique<MockEventCompletion<uint32_t>>(eventPool.get(), 1u, device); auto event = std::make_unique<MockEventCompletion<uint32_t>>(eventPool.get(), 1u, device);
Mock<Module> mockModule(this->device, nullptr); Mock<Module> mockModule(this->device, nullptr);
std::shared_ptr<Mock<KernelImp>> mockKernel{new Mock<KernelImp>()}; Mock<KernelImp> mockKernel;
mockKernel->descriptor.kernelAttributes.flags.usesPrintf = true; mockKernel.descriptor.kernelAttributes.flags.usesPrintf = true;
mockKernel->module = &mockModule; mockKernel.module = &mockModule;
event->resetKernelForPrintf(); event->setKernelForPrintf(nullptr);
event->resetKernelWithPrintfDeviceMutex(); EXPECT_EQ(nullptr, event->getKernelForPrintf());
EXPECT_TRUE(event->getKernelForPrintf().expired());
EXPECT_EQ(nullptr, event->getKernelWithPrintfDeviceMutex());
constexpr uint64_t timeout = std::numeric_limits<std::uint64_t>::max(); constexpr uint64_t timeout = std::numeric_limits<std::uint64_t>::max();
event->hostSynchronize(timeout); event->hostSynchronize(timeout);
EXPECT_EQ(0u, mockKernel->printPrintfOutputCalledTimes); EXPECT_EQ(0u, mockKernel.printPrintfOutputCalledTimes);
} }
TEST_F(EventSynchronizeTest, whenEventSetCsrThenCorrectCsrSet) { TEST_F(EventSynchronizeTest, whenEventSetCsrThenCorrectCsrSet) {

View File

@@ -364,13 +364,13 @@ HWTEST_F(FenceTest, givenPrintfKernelWhenSynchronizingFenceThenPrintPrintfOutput
false, false,
false, false,
returnValue)); returnValue));
std::shared_ptr<Mock<KernelImp>> kernel{new Mock<KernelImp>()}; Mock<KernelImp> kernel;
TaskCountType currentTaskCount = 33u; TaskCountType currentTaskCount = 33u;
auto &csr = neoDevice->getUltCommandStreamReceiver<FamilyType>(); auto &csr = neoDevice->getUltCommandStreamReceiver<FamilyType>();
csr.returnWaitForCompletionWithTimeout = WaitStatus::Ready; csr.returnWaitForCompletionWithTimeout = WaitStatus::Ready;
csr.latestWaitForCompletionWithTimeoutTaskCount = currentTaskCount; csr.latestWaitForCompletionWithTimeoutTaskCount = currentTaskCount;
*csr.tagAddress = currentTaskCount; *csr.tagAddress = currentTaskCount;
commandQueue->printfKernelContainer.push_back(std::weak_ptr<Kernel>{kernel}); commandQueue->printfKernelContainer.push_back(&kernel);
ze_fence_desc_t fenceDesc = {ZE_STRUCTURE_TYPE_FENCE_DESC, ze_fence_desc_t fenceDesc = {ZE_STRUCTURE_TYPE_FENCE_DESC,
nullptr, nullptr,
@@ -382,8 +382,8 @@ HWTEST_F(FenceTest, givenPrintfKernelWhenSynchronizingFenceThenPrintPrintfOutput
EXPECT_EQ(ZE_RESULT_SUCCESS, result); EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(0u, commandQueue->printfKernelContainer.size()); EXPECT_EQ(0u, commandQueue->printfKernelContainer.size());
EXPECT_EQ(1u, kernel->printPrintfOutputCalledTimes); EXPECT_EQ(1u, kernel.printPrintfOutputCalledTimes);
EXPECT_FALSE(kernel->hangDetectedPassedToPrintfOutput); EXPECT_FALSE(kernel.hangDetectedPassedToPrintfOutput);
delete fence; delete fence;
@@ -407,14 +407,14 @@ HWTEST_F(FenceTest, givenPrintfKernelAndDetectedHangWhenSynchronizingFenceThenPr
false, false,
returnValue)); returnValue));
std::shared_ptr<Mock<KernelImp>> kernel{new Mock<KernelImp>()}; Mock<KernelImp> kernel;
TaskCountType currentTaskCount = 33u; TaskCountType currentTaskCount = 33u;
auto &csr = neoDevice->getUltCommandStreamReceiver<FamilyType>(); auto &csr = neoDevice->getUltCommandStreamReceiver<FamilyType>();
csr.latestWaitForCompletionWithTimeoutTaskCount = currentTaskCount; csr.latestWaitForCompletionWithTimeoutTaskCount = currentTaskCount;
csr.returnWaitForCompletionWithTimeout = WaitStatus::GpuHang; csr.returnWaitForCompletionWithTimeout = WaitStatus::GpuHang;
*csr.tagAddress = 0; *csr.tagAddress = 0;
csr.gpuHangCheckPeriod = 0us; csr.gpuHangCheckPeriod = 0us;
commandQueue->printfKernelContainer.push_back(std::weak_ptr<Kernel>{kernel}); commandQueue->printfKernelContainer.push_back(&kernel);
ze_fence_desc_t fenceDesc = {ZE_STRUCTURE_TYPE_FENCE_DESC, ze_fence_desc_t fenceDesc = {ZE_STRUCTURE_TYPE_FENCE_DESC,
nullptr, nullptr,
@@ -426,8 +426,8 @@ HWTEST_F(FenceTest, givenPrintfKernelAndDetectedHangWhenSynchronizingFenceThenPr
EXPECT_EQ(ZE_RESULT_ERROR_DEVICE_LOST, result); EXPECT_EQ(ZE_RESULT_ERROR_DEVICE_LOST, result);
EXPECT_EQ(0u, commandQueue->printfKernelContainer.size()); EXPECT_EQ(0u, commandQueue->printfKernelContainer.size());
EXPECT_EQ(1u, kernel->printPrintfOutputCalledTimes); EXPECT_EQ(1u, kernel.printPrintfOutputCalledTimes);
EXPECT_TRUE(kernel->hangDetectedPassedToPrintfOutput); EXPECT_TRUE(kernel.hangDetectedPassedToPrintfOutput);
delete fence; delete fence;
commandQueue->destroy(); commandQueue->destroy();
@@ -444,14 +444,14 @@ HWTEST_F(FenceTest, givenPrintfKernelNotCompletedWhenSynchronizingFenceWithZeroT
false, false,
false, false,
returnValue)); returnValue));
std::shared_ptr<Mock<KernelImp>> kernel{new Mock<KernelImp>()}; Mock<KernelImp> kernel;
TaskCountType currentTaskCount = 33u; TaskCountType currentTaskCount = 33u;
auto &csr = neoDevice->getUltCommandStreamReceiver<FamilyType>(); auto &csr = neoDevice->getUltCommandStreamReceiver<FamilyType>();
csr.returnWaitForCompletionWithTimeout = WaitStatus::Ready; csr.returnWaitForCompletionWithTimeout = WaitStatus::Ready;
csr.latestWaitForCompletionWithTimeoutTaskCount = currentTaskCount; csr.latestWaitForCompletionWithTimeoutTaskCount = currentTaskCount;
*csr.tagAddress = currentTaskCount - 1; *csr.tagAddress = currentTaskCount - 1;
commandQueue->printfKernelContainer.push_back(std::weak_ptr<Kernel>{kernel}); commandQueue->printfKernelContainer.push_back(&kernel);
ze_fence_desc_t fenceDesc = {ZE_STRUCTURE_TYPE_FENCE_DESC, ze_fence_desc_t fenceDesc = {ZE_STRUCTURE_TYPE_FENCE_DESC,
nullptr, nullptr,
@@ -463,7 +463,7 @@ HWTEST_F(FenceTest, givenPrintfKernelNotCompletedWhenSynchronizingFenceWithZeroT
EXPECT_EQ(ZE_RESULT_NOT_READY, result); EXPECT_EQ(ZE_RESULT_NOT_READY, result);
EXPECT_EQ(1u, commandQueue->printfKernelContainer.size()); EXPECT_EQ(1u, commandQueue->printfKernelContainer.size());
EXPECT_EQ(0u, kernel->printPrintfOutputCalledTimes); EXPECT_EQ(0u, kernel.printPrintfOutputCalledTimes);
delete fence; delete fence;
commandQueue->destroy(); commandQueue->destroy();

View File

@@ -2838,40 +2838,6 @@ TEST_F(KernelPrintHandlerTest, whenPrintPrintfOutputIsCalledThenPrintfBufferIsUs
EXPECT_EQ(buffer, MyPrintfHandler::getPrintfSurfaceInitialDataSize()); EXPECT_EQ(buffer, MyPrintfHandler::getPrintfSurfaceInitialDataSize());
} }
using PrintfKernelOwnershipTest = Test<ModuleFixture>;
TEST_F(PrintfKernelOwnershipTest, givenKernelWithPrintfThenTheModuleStoresItCorrectly) {
ze_kernel_handle_t kernelHandle;
ze_kernel_desc_t kernelDesc = {};
kernelDesc.pKernelName = kernelName.c_str();
EXPECT_EQ(ZE_RESULT_SUCCESS, module->createKernel(&kernelDesc, &kernelHandle));
auto kernel = static_cast<Mock<KernelImp> *>(L0::Kernel::fromHandle(kernelHandle));
EXPECT_NE(nullptr, kernel->getPrintfBufferAllocation());
EXPECT_NE(nullptr, kernel->getDevicePrintfKernelMutex());
EXPECT_EQ(1u, static_cast<ModuleImp *>(module.get())->getPrintfKernelContainer().size());
EXPECT_EQ(kernel, static_cast<ModuleImp *>(module.get())->getPrintfKernelContainer()[0].get());
}
TEST_F(PrintfKernelOwnershipTest, givenKernelWithPrintfDestroyedFirstThenModuleDestructionReturnsTheCorrectStatus) {
ze_kernel_handle_t kernelHandle;
ze_kernel_desc_t kernelDesc = {};
kernelDesc.pKernelName = kernelName.c_str();
EXPECT_EQ(ZE_RESULT_SUCCESS, module->createKernel(&kernelDesc, &kernelHandle));
auto kernel = static_cast<Mock<KernelImp> *>(L0::Kernel::fromHandle(kernelHandle));
EXPECT_NE(nullptr, kernel->getPrintfBufferAllocation());
EXPECT_NE(nullptr, kernel->getDevicePrintfKernelMutex());
EXPECT_EQ(1u, static_cast<ModuleImp *>(module.get())->getPrintfKernelContainer().size());
EXPECT_EQ(kernel, static_cast<ModuleImp *>(module.get())->getPrintfKernelContainer()[0].get());
EXPECT_EQ(ZE_RESULT_SUCCESS, kernel->destroy());
EXPECT_EQ(1u, static_cast<ModuleImp *>(module.get())->getPrintfKernelContainer().size());
EXPECT_EQ(nullptr, static_cast<ModuleImp *>(module.get())->getPrintfKernelContainer()[0].get());
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, static_cast<ModuleImp *>(module.get())->destroyPrintfKernel(kernelHandle));
}
using PrintfTest = Test<DeviceFixture>; using PrintfTest = Test<DeviceFixture>;
TEST_F(PrintfTest, givenKernelWithPrintfThenPrintfBufferIsCreated) { TEST_F(PrintfTest, givenKernelWithPrintfThenPrintfBufferIsCreated) {