2018-07-05 17:23:28 +08:00
|
|
|
/*
|
2018-09-18 15:11:08 +08:00
|
|
|
* Copyright (C) 2018 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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "runtime/command_stream/command_stream_receiver.h"
|
|
|
|
#include "runtime/command_stream/experimental_command_buffer.h"
|
|
|
|
#include "runtime/command_stream/linear_stream.h"
|
2018-10-24 20:25:04 +08:00
|
|
|
#include "runtime/memory_manager/internal_allocation_storage.h"
|
2018-07-05 17:23:28 +08:00
|
|
|
#include "runtime/memory_manager/memory_constants.h"
|
|
|
|
#include "runtime/memory_manager/memory_manager.h"
|
|
|
|
#include <cstring>
|
|
|
|
#include <type_traits>
|
|
|
|
|
|
|
|
namespace OCLRT {
|
|
|
|
|
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) {
|
2018-12-12 01:56:37 +08:00
|
|
|
timestamps = csr->getMemoryManager()->allocateGraphicsMemoryWithProperties({MemoryConstants::pageSize, GraphicsAllocation::AllocationType::UNDECIDED});
|
2018-07-05 17:23:28 +08:00
|
|
|
memset(timestamps->getUnderlyingBuffer(), 0, timestamps->getUnderlyingBufferSize());
|
2018-12-12 01:56:37 +08:00
|
|
|
experimentalAllocation = csr->getMemoryManager()->allocateGraphicsMemoryWithProperties({MemoryConstants::pageSize, GraphicsAllocation::AllocationType::UNDECIDED});
|
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;
|
|
|
|
printDebugString(defaultPrint, stdout, "#%u: delta %llu start %llu stop %llu\n", i, delta, start, stop);
|
|
|
|
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;
|
|
|
|
if (currentStream->getAvailableSpace() < minRequiredSize) {
|
2018-10-09 17:50:58 +08:00
|
|
|
MemoryManager *memoryManager = commandStreamReceiver->getMemoryManager();
|
2018-07-05 17:23:28 +08:00
|
|
|
// If not, allocate a new block. allocate full pages
|
|
|
|
minRequiredSize = alignUp(minRequiredSize, MemoryConstants::pageSize);
|
|
|
|
|
|
|
|
auto requiredSize = minRequiredSize + CSRequirements::csOverfetchSize;
|
2018-10-26 16:58:00 +08:00
|
|
|
auto storageWithAllocations = commandStreamReceiver->getInternalAllocationStorage();
|
|
|
|
GraphicsAllocation *allocation = storageWithAllocations->obtainReusableAllocation(requiredSize, false).release();
|
2018-07-05 17:23:28 +08:00
|
|
|
if (!allocation) {
|
2018-12-12 01:56:37 +08:00
|
|
|
allocation = memoryManager->allocateGraphicsMemoryWithProperties({requiredSize, GraphicsAllocation::AllocationType::LINEAR_STREAM});
|
2018-07-05 17:23:28 +08:00
|
|
|
}
|
|
|
|
allocation->setAllocationType(GraphicsAllocation::AllocationType::LINEAR_STREAM);
|
|
|
|
// Deallocate the old block, if not null
|
|
|
|
auto oldAllocation = currentStream->getGraphicsAllocation();
|
|
|
|
if (oldAllocation) {
|
2018-10-26 16:58:00 +08:00
|
|
|
storageWithAllocations->storeAllocation(std::unique_ptr<GraphicsAllocation>(oldAllocation), REUSABLE_ALLOCATION);
|
2018-07-05 17:23:28 +08:00
|
|
|
}
|
|
|
|
currentStream->replaceBuffer(allocation->getUnderlyingBuffer(), minRequiredSize - CSRequirements::minCommandQueueCommandStreamSize);
|
|
|
|
currentStream->replaceGraphicsAllocation(allocation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExperimentalCommandBuffer::makeResidentAllocations() {
|
|
|
|
commandStreamReceiver->makeResident(*currentStream->getGraphicsAllocation());
|
|
|
|
commandStreamReceiver->makeResident(*timestamps);
|
|
|
|
commandStreamReceiver->makeResident(*experimentalAllocation);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace OCLRT
|