Refactor Sip Kernel usage

Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
Mateusz Hoppe
2020-12-02 10:22:27 +00:00
committed by Compute-Runtime-Automation
parent da779d067f
commit 8198a739c8
30 changed files with 190 additions and 251 deletions

View File

@@ -7,13 +7,17 @@
#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h"
#include "opencl/source/helpers/built_ins_helper.h"
#include "shared/source/built_ins/sip.h"
namespace L0 {
namespace ult {
const NEO::SipKernel &MockBuiltins::getSipKernel(NEO::SipKernelType type, NEO::Device &device) {
return NEO::initSipKernel(type, device);
if (!(sipKernel && sipKernel->getType() == type)) {
sipKernel.reset(new NEO::SipKernel(type, allocation.get()));
}
return *sipKernel;
}
} // namespace ult

View File

@@ -7,13 +7,19 @@
#pragma once
#include "shared/source/built_ins/built_ins.h"
#include "shared/test/unit_test/mocks/mock_graphics_allocation.h"
namespace L0 {
namespace ult {
class MockBuiltins : public NEO::BuiltIns {
public:
MockBuiltins() : BuiltIns() {
allocation.reset(new NEO::MockGraphicsAllocation());
}
const NEO::SipKernel &getSipKernel(NEO::SipKernelType type, NEO::Device &device) override;
std::unique_ptr<NEO::SipKernel> sipKernel;
std::unique_ptr<NEO::MockGraphicsAllocation> allocation;
};
} // namespace ult
} // namespace L0

View File

@@ -8,6 +8,7 @@ target_sources(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/test_cmdlist_1.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_cmdlist_2.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_cmdlist_3.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_cmdlist_api.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_cmdlist_append_barrier.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_cmdlist_append_event_reset.cpp

View File

@@ -1114,72 +1114,5 @@ HWTEST2_F(CommandListCreate, givenHostAllocInMapWhenPtrLowerThanAnyInMapThenNull
commandList->hostPtrMap.clear();
}
struct MemoryManagerCommandListCreateNegativeTest : public NEO::MockMemoryManager {
MemoryManagerCommandListCreateNegativeTest(NEO::ExecutionEnvironment &executionEnvironment) : NEO::MockMemoryManager(const_cast<NEO::ExecutionEnvironment &>(executionEnvironment)) {}
NEO::GraphicsAllocation *allocateGraphicsMemoryWithProperties(const NEO::AllocationProperties &properties) override {
if (forceFailureInPrimaryAllocation) {
return nullptr;
}
return NEO::MemoryManager::allocateGraphicsMemoryWithProperties(properties);
}
bool forceFailureInPrimaryAllocation = false;
};
struct CommandListCreateNegativeTest : public ::testing::Test {
void SetUp() override {
executionEnvironment = new NEO::ExecutionEnvironment();
executionEnvironment->prepareRootDeviceEnvironments(numRootDevices);
for (uint32_t i = 0; i < numRootDevices; i++) {
executionEnvironment->rootDeviceEnvironments[i]->setHwInfo(NEO::defaultHwInfo.get());
}
memoryManager = new MemoryManagerCommandListCreateNegativeTest(*executionEnvironment);
executionEnvironment->memoryManager.reset(memoryManager);
std::vector<std::unique_ptr<NEO::Device>> devices;
for (uint32_t i = 0; i < numRootDevices; i++) {
neoDevice = NEO::MockDevice::create<NEO::MockDevice>(executionEnvironment, i);
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
}
driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
driverHandle->initialize(std::move(devices));
device = driverHandle->devices[0];
}
void TearDown() override {
}
NEO::ExecutionEnvironment *executionEnvironment = nullptr;
std::unique_ptr<Mock<L0::DriverHandleImp>> driverHandle;
NEO::MockDevice *neoDevice = nullptr;
L0::Device *device = nullptr;
MemoryManagerCommandListCreateNegativeTest *memoryManager = nullptr;
const uint32_t numRootDevices = 1u;
};
TEST_F(CommandListCreateNegativeTest, whenDeviceAllocationFailsDuringCommandListCreateThenAppropriateValueIsReturned) {
ze_result_t returnValue;
memoryManager->forceFailureInPrimaryAllocation = true;
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, returnValue));
EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, returnValue);
ASSERT_EQ(nullptr, commandList);
}
TEST_F(CommandListCreateNegativeTest, whenDeviceAllocationFailsDuringCommandListImmediateCreateThenAppropriateValueIsReturned) {
ze_result_t returnValue;
const ze_command_queue_desc_t desc = {};
bool internalEngine = true;
memoryManager->forceFailureInPrimaryAllocation = true;
std::unique_ptr<L0::CommandList> commandList(CommandList::createImmediate(productFamily,
device,
&desc,
internalEngine,
NEO::EngineGroupType::RenderCompute,
returnValue));
EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, returnValue);
ASSERT_EQ(nullptr, commandList);
}
} // namespace ult
} // namespace L0

View File

@@ -0,0 +1,84 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
#include "test.h"
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
#include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h"
namespace L0 {
namespace ult {
struct MemoryManagerCommandListCreateNegativeTest : public NEO::MockMemoryManager {
MemoryManagerCommandListCreateNegativeTest(NEO::ExecutionEnvironment &executionEnvironment) : NEO::MockMemoryManager(const_cast<NEO::ExecutionEnvironment &>(executionEnvironment)) {}
NEO::GraphicsAllocation *allocateGraphicsMemoryWithProperties(const NEO::AllocationProperties &properties) override {
if (forceFailureInPrimaryAllocation) {
return nullptr;
}
return NEO::MemoryManager::allocateGraphicsMemoryWithProperties(properties);
}
bool forceFailureInPrimaryAllocation = false;
};
struct CommandListCreateNegativeTest : public ::testing::Test {
void SetUp() override {
executionEnvironment = new NEO::ExecutionEnvironment();
executionEnvironment->prepareRootDeviceEnvironments(numRootDevices);
for (uint32_t i = 0; i < numRootDevices; i++) {
executionEnvironment->rootDeviceEnvironments[i]->setHwInfo(NEO::defaultHwInfo.get());
}
memoryManager = new MemoryManagerCommandListCreateNegativeTest(*executionEnvironment);
executionEnvironment->memoryManager.reset(memoryManager);
std::vector<std::unique_ptr<NEO::Device>> devices;
for (uint32_t i = 0; i < numRootDevices; i++) {
neoDevice = NEO::MockDevice::create<NEO::MockDevice>(executionEnvironment, i);
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
}
driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
driverHandle->initialize(std::move(devices));
device = driverHandle->devices[0];
}
void TearDown() override {
}
NEO::ExecutionEnvironment *executionEnvironment = nullptr;
std::unique_ptr<Mock<L0::DriverHandleImp>> driverHandle;
NEO::MockDevice *neoDevice = nullptr;
L0::Device *device = nullptr;
MemoryManagerCommandListCreateNegativeTest *memoryManager = nullptr;
const uint32_t numRootDevices = 1u;
};
TEST_F(CommandListCreateNegativeTest, whenDeviceAllocationFailsDuringCommandListCreateThenAppropriateValueIsReturned) {
ze_result_t returnValue;
memoryManager->forceFailureInPrimaryAllocation = true;
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, returnValue));
EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, returnValue);
ASSERT_EQ(nullptr, commandList);
}
TEST_F(CommandListCreateNegativeTest, whenDeviceAllocationFailsDuringCommandListImmediateCreateThenAppropriateValueIsReturned) {
ze_result_t returnValue;
const ze_command_queue_desc_t desc = {};
bool internalEngine = true;
memoryManager->forceFailureInPrimaryAllocation = true;
std::unique_ptr<L0::CommandList> commandList(CommandList::createImmediate(productFamily,
device,
&desc,
internalEngine,
NEO::EngineGroupType::RenderCompute,
returnValue));
EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, returnValue);
ASSERT_EQ(nullptr, commandList);
}
} // namespace ult
} // namespace L0