2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2021-05-17 02:51:16 +08:00
|
|
|
* Copyright (C) 2018-2021 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/execution_environment/execution_environment.h"
|
2020-11-02 22:54:01 +08:00
|
|
|
#include "shared/source/memory_manager/os_agnostic_memory_manager.h"
|
2021-09-30 03:10:53 +08:00
|
|
|
#include "shared/source/program/kernel_info.h"
|
2021-07-06 21:44:16 +08:00
|
|
|
#include "shared/test/common/mocks/mock_execution_environment.h"
|
2021-01-21 20:10:13 +08:00
|
|
|
#include "shared/test/common/mocks/mock_graphics_allocation.h"
|
|
|
|
#include "shared/test/common/mocks/ult_device_factory.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-02-23 22:20:22 +08:00
|
|
|
#include "opencl/test/unit_test/fixtures/multi_root_device_fixture.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "gtest/gtest.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2018-03-27 20:30:05 +08:00
|
|
|
#include <memory>
|
2019-02-27 18:39:32 +08:00
|
|
|
#include <type_traits>
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-07-15 21:37:36 +08:00
|
|
|
TEST(KernelInfo, WhenKernelInfoIsCreatedThenItIsNotMoveableAndNotCopyable) {
|
2020-01-12 01:25:26 +08:00
|
|
|
static_assert(false == std::is_move_constructible<KernelInfo>::value, "");
|
|
|
|
static_assert(false == std::is_copy_constructible<KernelInfo>::value, "");
|
|
|
|
static_assert(false == std::is_move_assignable<KernelInfo>::value, "");
|
|
|
|
static_assert(false == std::is_copy_assignable<KernelInfo>::value, "");
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-04-05 01:02:07 +08:00
|
|
|
TEST(KernelInfoTest, givenKernelInfoWhenCreateKernelAllocationThenCopyWholeKernelHeapToKernelAllocation) {
|
|
|
|
KernelInfo kernelInfo;
|
2020-07-03 23:09:37 +08:00
|
|
|
auto factory = UltDeviceFactory{1, 0};
|
|
|
|
auto device = factory.rootDevices[0];
|
2018-04-05 01:02:07 +08:00
|
|
|
const size_t heapSize = 0x40;
|
|
|
|
char heap[heapSize];
|
2020-05-26 15:36:04 +08:00
|
|
|
kernelInfo.heapInfo.KernelHeapSize = heapSize;
|
2018-04-05 01:02:07 +08:00
|
|
|
kernelInfo.heapInfo.pKernelHeap = &heap;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < heapSize; i++) {
|
|
|
|
heap[i] = static_cast<char>(i);
|
|
|
|
}
|
|
|
|
|
2020-11-13 02:53:30 +08:00
|
|
|
auto retVal = kernelInfo.createKernelAllocation(*device, false);
|
2018-04-05 01:02:07 +08:00
|
|
|
EXPECT_TRUE(retVal);
|
|
|
|
auto allocation = kernelInfo.kernelAllocation;
|
|
|
|
EXPECT_EQ(0, memcmp(allocation->getUnderlyingBuffer(), heap, heapSize));
|
2021-04-23 22:09:03 +08:00
|
|
|
size_t isaPadding = HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getPaddingForISAAllocation();
|
|
|
|
EXPECT_EQ(allocation->getUnderlyingBufferSize(), heapSize + isaPadding);
|
2020-07-03 23:09:37 +08:00
|
|
|
device->getMemoryManager()->checkGpuUsageAndDestroyGraphicsAllocations(allocation);
|
2018-04-05 01:02:07 +08:00
|
|
|
}
|
|
|
|
|
2020-11-13 02:53:30 +08:00
|
|
|
TEST(KernelInfoTest, givenKernelInfoWhenCreatingKernelAllocationWithInternalIsaFalseTypeThenCorrectAllocationTypeIsUsed) {
|
|
|
|
KernelInfo kernelInfo;
|
|
|
|
auto factory = UltDeviceFactory{1, 0};
|
|
|
|
auto device = factory.rootDevices[0];
|
|
|
|
const size_t heapSize = 0x40;
|
|
|
|
char heap[heapSize];
|
|
|
|
kernelInfo.heapInfo.KernelHeapSize = heapSize;
|
|
|
|
kernelInfo.heapInfo.pKernelHeap = &heap;
|
|
|
|
|
|
|
|
auto retVal = kernelInfo.createKernelAllocation(*device, false);
|
|
|
|
EXPECT_TRUE(retVal);
|
|
|
|
auto allocation = kernelInfo.kernelAllocation;
|
|
|
|
EXPECT_EQ(GraphicsAllocation::AllocationType::KERNEL_ISA, allocation->getAllocationType());
|
|
|
|
device->getMemoryManager()->checkGpuUsageAndDestroyGraphicsAllocations(allocation);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(KernelInfoTest, givenKernelInfoWhenCreatingKernelAllocationWithInternalIsaTrueTypeThenCorrectAllocationTypeIsUsed) {
|
|
|
|
KernelInfo kernelInfo;
|
|
|
|
auto factory = UltDeviceFactory{1, 0};
|
|
|
|
auto device = factory.rootDevices[0];
|
|
|
|
const size_t heapSize = 0x40;
|
|
|
|
char heap[heapSize];
|
|
|
|
kernelInfo.heapInfo.KernelHeapSize = heapSize;
|
|
|
|
kernelInfo.heapInfo.pKernelHeap = &heap;
|
|
|
|
|
|
|
|
auto retVal = kernelInfo.createKernelAllocation(*device, true);
|
|
|
|
EXPECT_TRUE(retVal);
|
|
|
|
auto allocation = kernelInfo.kernelAllocation;
|
|
|
|
EXPECT_EQ(GraphicsAllocation::AllocationType::KERNEL_ISA_INTERNAL, allocation->getAllocationType());
|
|
|
|
device->getMemoryManager()->checkGpuUsageAndDestroyGraphicsAllocations(allocation);
|
|
|
|
}
|
|
|
|
|
2018-04-05 01:02:07 +08:00
|
|
|
class MyMemoryManager : public OsAgnosticMemoryManager {
|
|
|
|
public:
|
2018-10-01 22:10:54 +08:00
|
|
|
using OsAgnosticMemoryManager::OsAgnosticMemoryManager;
|
2020-07-01 20:03:46 +08:00
|
|
|
GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData, bool useLocalMemory) override { return nullptr; }
|
2018-04-05 01:02:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST(KernelInfoTest, givenKernelInfoWhenCreateKernelAllocationAndCannotAllocateMemoryThenReturnsFalse) {
|
|
|
|
KernelInfo kernelInfo;
|
2020-07-03 23:09:37 +08:00
|
|
|
auto executionEnvironment = new MockExecutionEnvironment(defaultHwInfo.get());
|
|
|
|
executionEnvironment->memoryManager.reset(new MyMemoryManager(*executionEnvironment));
|
2021-05-06 22:15:19 +08:00
|
|
|
if (executionEnvironment->memoryManager->isLimitedGPU(0)) {
|
|
|
|
GTEST_SKIP();
|
|
|
|
}
|
2020-07-03 23:09:37 +08:00
|
|
|
auto device = std::unique_ptr<Device>(Device::create<RootDevice>(executionEnvironment, mockRootDeviceIndex));
|
2020-11-13 02:53:30 +08:00
|
|
|
auto retVal = kernelInfo.createKernelAllocation(*device, false);
|
2018-04-05 01:02:07 +08:00
|
|
|
EXPECT_FALSE(retVal);
|
|
|
|
}
|
|
|
|
|
2019-12-04 20:45:32 +08:00
|
|
|
using KernelInfoMultiRootDeviceTests = MultiRootDeviceFixture;
|
|
|
|
|
2020-12-27 17:12:54 +08:00
|
|
|
TEST_F(KernelInfoMultiRootDeviceTests, WhenCreatingKernelAllocationThenItHasCorrectRootDeviceIndex) {
|
2019-12-04 20:45:32 +08:00
|
|
|
KernelInfo kernelInfo;
|
|
|
|
const size_t heapSize = 0x40;
|
|
|
|
char heap[heapSize];
|
2020-05-26 15:36:04 +08:00
|
|
|
kernelInfo.heapInfo.KernelHeapSize = heapSize;
|
2019-12-04 20:45:32 +08:00
|
|
|
kernelInfo.heapInfo.pKernelHeap = &heap;
|
|
|
|
|
2020-11-20 19:04:46 +08:00
|
|
|
auto retVal = kernelInfo.createKernelAllocation(device1->getDevice(), false);
|
2019-12-04 20:45:32 +08:00
|
|
|
EXPECT_TRUE(retVal);
|
|
|
|
auto allocation = kernelInfo.kernelAllocation;
|
|
|
|
ASSERT_NE(nullptr, allocation);
|
|
|
|
EXPECT_EQ(expectedRootDeviceIndex, allocation->getRootDeviceIndex());
|
|
|
|
mockMemoryManager->checkGpuUsageAndDestroyGraphicsAllocations(allocation);
|
|
|
|
}
|
2020-01-12 01:25:26 +08:00
|
|
|
|
|
|
|
TEST(KernelInfo, whenGetKernelNamesStringIsCalledThenNamesAreProperlyConcatenated) {
|
|
|
|
ExecutionEnvironment execEnv;
|
|
|
|
KernelInfo kernel1 = {};
|
2020-10-20 02:36:05 +08:00
|
|
|
kernel1.kernelDescriptor.kernelMetadata.kernelName = "kern1";
|
2020-01-12 01:25:26 +08:00
|
|
|
KernelInfo kernel2 = {};
|
2020-10-20 02:36:05 +08:00
|
|
|
kernel2.kernelDescriptor.kernelMetadata.kernelName = "kern2";
|
2020-01-12 01:25:26 +08:00
|
|
|
std::vector<KernelInfo *> kernelInfoArray;
|
|
|
|
kernelInfoArray.push_back(&kernel1);
|
|
|
|
kernelInfoArray.push_back(&kernel2);
|
|
|
|
EXPECT_STREQ("kern1;kern2", concatenateKernelNames(kernelInfoArray).c_str());
|
|
|
|
}
|