2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2019-01-11 09:00:11 +01:00
|
|
|
* Copyright (C) 2017-2019 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-18 09:11:08 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2019-01-11 09:00:11 +01:00
|
|
|
#include "runtime/event/user_event.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
#include "runtime/helpers/task_information.h"
|
2019-01-11 09:00:11 +01:00
|
|
|
#include "runtime/memory_manager/internal_allocation_storage.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
#include "test.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
#include "unit_tests/fixtures/device_fixture.h"
|
|
|
|
|
#include "unit_tests/mocks/mock_buffer.h"
|
|
|
|
|
#include "unit_tests/mocks/mock_command_queue.h"
|
|
|
|
|
#include "unit_tests/mocks/mock_csr.h"
|
2019-01-11 09:00:11 +01:00
|
|
|
#include "unit_tests/mocks/mock_kernel.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
using namespace NEO;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
TEST(CommandTest, mapUnmapSubmitWithoutTerminateFlagFlushesCsr) {
|
2018-07-25 17:12:44 +02:00
|
|
|
std::unique_ptr<Device> device(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
|
2017-12-21 00:45:38 +01:00
|
|
|
std::unique_ptr<MockCommandQueue> cmdQ(new MockCommandQueue(nullptr, device.get(), nullptr));
|
2018-10-11 11:19:49 +02:00
|
|
|
MockCommandStreamReceiver csr(*device->getExecutionEnvironment());
|
2017-12-21 00:45:38 +01:00
|
|
|
MockBuffer buffer;
|
|
|
|
|
|
|
|
|
|
auto initialTaskCount = csr.peekTaskCount();
|
2018-02-17 22:26:28 +01:00
|
|
|
|
|
|
|
|
MemObjSizeArray size = {{1, 1, 1}};
|
|
|
|
|
MemObjOffsetArray offset = {{0, 0, 0}};
|
2019-07-22 20:55:09 +02:00
|
|
|
std::unique_ptr<Command> command(new CommandMapUnmap(MapOperationType::MAP, buffer, size, offset, false, *cmdQ));
|
2017-12-21 00:45:38 +01:00
|
|
|
CompletionStamp completionStamp = command->submit(20, false);
|
|
|
|
|
|
|
|
|
|
auto expectedTaskCount = initialTaskCount + 1;
|
|
|
|
|
EXPECT_EQ(expectedTaskCount, completionStamp.taskCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(CommandTest, mapUnmapSubmitWithTerminateFlagAbortsFlush) {
|
2018-07-25 17:12:44 +02:00
|
|
|
std::unique_ptr<Device> device(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
|
2017-12-21 00:45:38 +01:00
|
|
|
std::unique_ptr<MockCommandQueue> cmdQ(new MockCommandQueue(nullptr, device.get(), nullptr));
|
2018-10-11 11:19:49 +02:00
|
|
|
MockCommandStreamReceiver csr(*device->getExecutionEnvironment());
|
2017-12-21 00:45:38 +01:00
|
|
|
MockBuffer buffer;
|
|
|
|
|
|
|
|
|
|
auto initialTaskCount = csr.peekTaskCount();
|
2018-02-17 22:26:28 +01:00
|
|
|
|
|
|
|
|
MemObjSizeArray size = {{1, 1, 1}};
|
|
|
|
|
MemObjOffsetArray offset = {{0, 0, 0}};
|
2019-07-22 20:55:09 +02:00
|
|
|
std::unique_ptr<Command> command(new CommandMapUnmap(MapOperationType::MAP, buffer, size, offset, false, *cmdQ));
|
2017-12-21 00:45:38 +01:00
|
|
|
CompletionStamp completionStamp = command->submit(20, true);
|
|
|
|
|
|
|
|
|
|
auto submitTaskCount = csr.peekTaskCount();
|
|
|
|
|
EXPECT_EQ(initialTaskCount, submitTaskCount);
|
|
|
|
|
|
|
|
|
|
auto expectedTaskCount = 0u;
|
|
|
|
|
EXPECT_EQ(expectedTaskCount, completionStamp.taskCount);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-10 07:57:54 +02:00
|
|
|
TEST(CommandTest, markerSubmitWithoutTerminateFlagDosntFlushCsr) {
|
2018-07-25 17:12:44 +02:00
|
|
|
std::unique_ptr<Device> device(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
|
2017-12-21 00:45:38 +01:00
|
|
|
std::unique_ptr<MockCommandQueue> cmdQ(new MockCommandQueue(nullptr, device.get(), nullptr));
|
2018-10-11 11:19:49 +02:00
|
|
|
MockCommandStreamReceiver csr(*device->getExecutionEnvironment());
|
2017-12-21 00:45:38 +01:00
|
|
|
MockBuffer buffer;
|
|
|
|
|
|
|
|
|
|
auto initialTaskCount = csr.peekTaskCount();
|
2019-07-22 21:28:59 +02:00
|
|
|
std::unique_ptr<Command> command(new CommandMarker(*cmdQ));
|
2017-12-21 00:45:38 +01:00
|
|
|
CompletionStamp completionStamp = command->submit(20, false);
|
|
|
|
|
|
2019-07-10 07:57:54 +02:00
|
|
|
EXPECT_EQ(initialTaskCount, completionStamp.taskCount);
|
|
|
|
|
EXPECT_EQ(initialTaskCount, csr.peekTaskCount());
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(CommandTest, markerSubmitWithTerminateFlagAbortsFlush) {
|
2018-07-25 17:12:44 +02:00
|
|
|
std::unique_ptr<Device> device(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
|
2017-12-21 00:45:38 +01:00
|
|
|
std::unique_ptr<MockCommandQueue> cmdQ(new MockCommandQueue(nullptr, device.get(), nullptr));
|
2018-10-11 11:19:49 +02:00
|
|
|
MockCommandStreamReceiver csr(*device->getExecutionEnvironment());
|
2017-12-21 00:45:38 +01:00
|
|
|
MockBuffer buffer;
|
|
|
|
|
|
|
|
|
|
auto initialTaskCount = csr.peekTaskCount();
|
2019-07-22 21:28:59 +02:00
|
|
|
std::unique_ptr<Command> command(new CommandMarker(*cmdQ));
|
2017-12-21 00:45:38 +01:00
|
|
|
CompletionStamp completionStamp = command->submit(20, true);
|
|
|
|
|
|
|
|
|
|
auto submitTaskCount = csr.peekTaskCount();
|
|
|
|
|
EXPECT_EQ(initialTaskCount, submitTaskCount);
|
|
|
|
|
|
|
|
|
|
auto expectedTaskCount = 0u;
|
|
|
|
|
EXPECT_EQ(expectedTaskCount, completionStamp.taskCount);
|
|
|
|
|
}
|
2019-01-11 09:00:11 +01:00
|
|
|
|
|
|
|
|
TEST(CommandTest, givenWaitlistRequestWhenCommandComputeKernelIsCreatedThenMakeLocalCopyOfWaitlist) {
|
|
|
|
|
class MockCommandComputeKernel : public CommandComputeKernel {
|
|
|
|
|
public:
|
|
|
|
|
using CommandComputeKernel::eventsWaitlist;
|
2019-07-22 20:55:09 +02:00
|
|
|
MockCommandComputeKernel(CommandQueue &commandQueue, std::unique_ptr<KernelOperation> &kernelOperation, std::vector<Surface *> &surfaces, Kernel *kernel)
|
|
|
|
|
: CommandComputeKernel(commandQueue, kernelOperation, surfaces, false, false, false, nullptr, PreemptionMode::Disabled, kernel, 0) {}
|
2019-01-11 09:00:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(platformDevices[0]));
|
|
|
|
|
CommandQueue cmdQ(nullptr, device.get(), nullptr);
|
|
|
|
|
MockKernelWithInternals kernel(*device);
|
|
|
|
|
|
|
|
|
|
IndirectHeap *ih1 = nullptr, *ih2 = nullptr, *ih3 = nullptr;
|
|
|
|
|
cmdQ.allocateHeapMemory(IndirectHeap::DYNAMIC_STATE, 1, ih1);
|
|
|
|
|
cmdQ.allocateHeapMemory(IndirectHeap::INDIRECT_OBJECT, 1, ih2);
|
|
|
|
|
cmdQ.allocateHeapMemory(IndirectHeap::SURFACE_STATE, 1, ih3);
|
2019-02-18 15:23:15 +01:00
|
|
|
auto cmdStream = new LinearStream(device->getMemoryManager()->allocateGraphicsMemoryWithProperties({1, GraphicsAllocation::AllocationType::COMMAND_BUFFER}));
|
2019-01-11 09:00:11 +01:00
|
|
|
|
|
|
|
|
std::vector<Surface *> surfaces;
|
2019-07-22 20:55:09 +02:00
|
|
|
auto kernelOperation = std::make_unique<KernelOperation>(cmdStream, *device->getDefaultEngine().commandStreamReceiver->getInternalAllocationStorage());
|
2019-07-18 21:15:50 +02:00
|
|
|
kernelOperation->setHeaps(ih1, ih2, ih3);
|
2019-01-11 09:00:11 +01:00
|
|
|
|
|
|
|
|
UserEvent event1, event2, event3;
|
|
|
|
|
cl_event waitlist[] = {&event1, &event2};
|
|
|
|
|
EventsRequest eventsRequest(2, waitlist, nullptr);
|
2018-12-04 14:18:17 +01:00
|
|
|
|
|
|
|
|
MockCommandComputeKernel command(cmdQ, kernelOperation, surfaces, kernel);
|
|
|
|
|
|
|
|
|
|
event1.incRefInternal();
|
|
|
|
|
event2.incRefInternal();
|
|
|
|
|
|
2019-01-11 09:00:11 +01:00
|
|
|
command.setEventsRequest(eventsRequest);
|
|
|
|
|
|
|
|
|
|
waitlist[1] = &event3;
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(static_cast<cl_event>(&event1), command.eventsWaitlist[0]);
|
|
|
|
|
EXPECT_EQ(static_cast<cl_event>(&event2), command.eventsWaitlist[1]);
|
|
|
|
|
}
|
2019-02-18 15:23:15 +01:00
|
|
|
|
|
|
|
|
TEST(KernelOperationDestruction, givenKernelOperationWhenItIsDestructedThenAllAllocationsAreStoredInInternalStorageForReuse) {
|
|
|
|
|
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(platformDevices[0]));
|
|
|
|
|
CommandQueue cmdQ(nullptr, device.get(), nullptr);
|
|
|
|
|
InternalAllocationStorage &allocationStorage = *device->getDefaultEngine().commandStreamReceiver->getInternalAllocationStorage();
|
|
|
|
|
auto &allocationsForReuse = allocationStorage.getAllocationsForReuse();
|
|
|
|
|
|
|
|
|
|
IndirectHeap *ih1 = nullptr, *ih2 = nullptr, *ih3 = nullptr;
|
|
|
|
|
cmdQ.allocateHeapMemory(IndirectHeap::DYNAMIC_STATE, 1, ih1);
|
|
|
|
|
cmdQ.allocateHeapMemory(IndirectHeap::INDIRECT_OBJECT, 1, ih2);
|
|
|
|
|
cmdQ.allocateHeapMemory(IndirectHeap::SURFACE_STATE, 1, ih3);
|
2019-07-18 21:15:50 +02:00
|
|
|
auto cmdStream = new LinearStream(device->getMemoryManager()->allocateGraphicsMemoryWithProperties({1, GraphicsAllocation::AllocationType::COMMAND_BUFFER}));
|
2019-02-18 15:23:15 +01:00
|
|
|
|
|
|
|
|
auto &heapAllocation1 = *ih1->getGraphicsAllocation();
|
|
|
|
|
auto &heapAllocation2 = *ih2->getGraphicsAllocation();
|
|
|
|
|
auto &heapAllocation3 = *ih3->getGraphicsAllocation();
|
|
|
|
|
auto &cmdStreamAllocation = *cmdStream->getGraphicsAllocation();
|
|
|
|
|
|
2019-07-18 21:15:50 +02:00
|
|
|
auto kernelOperation = std::make_unique<KernelOperation>(cmdStream, allocationStorage);
|
|
|
|
|
kernelOperation->setHeaps(ih1, ih2, ih3);
|
2019-02-18 15:23:15 +01:00
|
|
|
EXPECT_TRUE(allocationsForReuse.peekIsEmpty());
|
|
|
|
|
|
|
|
|
|
kernelOperation.reset();
|
|
|
|
|
EXPECT_TRUE(allocationsForReuse.peekContains(cmdStreamAllocation));
|
|
|
|
|
EXPECT_TRUE(allocationsForReuse.peekContains(heapAllocation1));
|
|
|
|
|
EXPECT_TRUE(allocationsForReuse.peekContains(heapAllocation2));
|
|
|
|
|
EXPECT_TRUE(allocationsForReuse.peekContains(heapAllocation3));
|
|
|
|
|
}
|