2018-07-05 17:23:28 +08:00
|
|
|
/*
|
2020-01-21 18:00:03 +08:00
|
|
|
* Copyright (C) 2018-2020 Intel Corporation
|
2018-07-05 17:23:28 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2018-07-05 17:23:28 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/command_stream/experimental_command_buffer.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/command_stream/command_stream_receiver.h"
|
|
|
|
#include "shared/source/command_stream/linear_stream.h"
|
2020-04-02 17:28:38 +08:00
|
|
|
#include "shared/source/helpers/constants.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/memory_manager/internal_allocation_storage.h"
|
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
2020-07-08 18:09:05 +08:00
|
|
|
#include "shared/source/os_interface/os_context.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2018-07-05 17:23:28 +08:00
|
|
|
#include <cstring>
|
|
|
|
#include <type_traits>
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2018-07-05 17:23:28 +08:00
|
|
|
|
2018-07-19 20:05:53 +08:00
|
|
|
ExperimentalCommandBuffer::ExperimentalCommandBuffer(CommandStreamReceiver *csr, double profilingTimerResolution) : commandStreamReceiver(csr),
|
|
|
|
currentStream(nullptr),
|
|
|
|
timestampsOffset(0),
|
|
|
|
experimentalAllocationOffset(0),
|
|
|
|
defaultPrint(true),
|
|
|
|
timerResolution(profilingTimerResolution) {
|
2019-11-07 21:15:04 +08:00
|
|
|
auto rootDeviceIndex = csr->getRootDeviceIndex();
|
2020-07-08 18:09:05 +08:00
|
|
|
timestamps = csr->getMemoryManager()->allocateGraphicsMemoryWithProperties({rootDeviceIndex, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, csr->getOsContext().getDeviceBitfield()});
|
2018-07-05 17:23:28 +08:00
|
|
|
memset(timestamps->getUnderlyingBuffer(), 0, timestamps->getUnderlyingBufferSize());
|
2020-07-08 18:09:05 +08:00
|
|
|
experimentalAllocation = csr->getMemoryManager()->allocateGraphicsMemoryWithProperties({rootDeviceIndex, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, csr->getOsContext().getDeviceBitfield()});
|
2018-07-05 17:23:28 +08:00
|
|
|
memset(experimentalAllocation->getUnderlyingBuffer(), 0, experimentalAllocation->getUnderlyingBufferSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
ExperimentalCommandBuffer::~ExperimentalCommandBuffer() {
|
|
|
|
auto timestamp = static_cast<uint64_t *>(timestamps->getUnderlyingBuffer());
|
|
|
|
for (uint32_t i = 0; i < timestampsOffset / (2 * sizeof(uint64_t)); i++) {
|
|
|
|
auto stop = static_cast<uint64_t>(*(timestamp + 1) * timerResolution);
|
|
|
|
auto start = static_cast<uint64_t>(*timestamp * timerResolution);
|
|
|
|
auto delta = stop - start;
|
2020-09-25 17:24:15 +08:00
|
|
|
PRINT_DEBUG_STRING(defaultPrint, stdout, "#%u: delta %llu start %llu stop %llu\n", i, delta, start, stop);
|
2018-07-05 17:23:28 +08:00
|
|
|
timestamp += 2;
|
|
|
|
}
|
2018-10-09 17:50:58 +08:00
|
|
|
MemoryManager *memoryManager = commandStreamReceiver->getMemoryManager();
|
2018-10-11 17:19:49 +08:00
|
|
|
memoryManager->freeGraphicsMemory(timestamps);
|
|
|
|
memoryManager->freeGraphicsMemory(experimentalAllocation);
|
|
|
|
|
|
|
|
if (currentStream.get()) {
|
|
|
|
memoryManager->freeGraphicsMemory(currentStream->getGraphicsAllocation());
|
|
|
|
currentStream->replaceGraphicsAllocation(nullptr);
|
2018-07-05 17:23:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExperimentalCommandBuffer::getCS(size_t minRequiredSize) {
|
|
|
|
if (!currentStream) {
|
|
|
|
currentStream.reset(new LinearStream(nullptr));
|
|
|
|
}
|
|
|
|
minRequiredSize += CSRequirements::minCommandQueueCommandStreamSize;
|
2019-02-20 17:31:32 +08:00
|
|
|
constexpr static auto additionalAllocationSize = CSRequirements::minCommandQueueCommandStreamSize + CSRequirements::csOverfetchSize;
|
|
|
|
commandStreamReceiver->ensureCommandBufferAllocation(*currentStream, minRequiredSize, additionalAllocationSize);
|
2018-07-05 17:23:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExperimentalCommandBuffer::makeResidentAllocations() {
|
|
|
|
commandStreamReceiver->makeResident(*currentStream->getGraphicsAllocation());
|
|
|
|
commandStreamReceiver->makeResident(*timestamps);
|
|
|
|
commandStreamReceiver->makeResident(*experimentalAllocation);
|
|
|
|
}
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|