stagingBuffer: rename nDgramsPerFrame=>nSlots
This commit is contained in:
@@ -83,8 +83,8 @@ void StagingBuffer::computeSlotStrideAndBufferSize()
|
|||||||
inputConstraints.framePadToNBytes,
|
inputConstraints.framePadToNBytes,
|
||||||
inputConstraints.slotPadToNBytes);
|
inputConstraints.slotPadToNBytes);
|
||||||
|
|
||||||
// Calculate total size needed for nDgramsPerFrame slots
|
// Calculate total size needed for nSlots slots
|
||||||
size_t slotAreaSize = nDgramsPerFrame * slotStrideNBytes;
|
size_t slotAreaSize = nSlots * slotStrideNBytes;
|
||||||
|
|
||||||
// Add padding space at buffer start for alignment offset (worst case: max alignment - 1)
|
// Add padding space at buffer start for alignment offset (worst case: max alignment - 1)
|
||||||
size_t alignmentPadding = maxAlignment - 1;
|
size_t alignmentPadding = maxAlignment - 1;
|
||||||
@@ -102,7 +102,7 @@ void StagingBuffer::computeSlotStrideAndBufferSize()
|
|||||||
size_t StagingBuffer::calculateFirstSlotOffsetAndValidate(
|
size_t StagingBuffer::calculateFirstSlotOffsetAndValidate(
|
||||||
uint8_t* buffer,
|
uint8_t* buffer,
|
||||||
size_t bufferNBytes,
|
size_t bufferNBytes,
|
||||||
size_t nDgramsPerFrame,
|
size_t nSlots,
|
||||||
size_t slotStrideNBytes,
|
size_t slotStrideNBytes,
|
||||||
const StagingBuffer::IOEngineConstraints& inputConstraints)
|
const StagingBuffer::IOEngineConstraints& inputConstraints)
|
||||||
{
|
{
|
||||||
@@ -150,12 +150,12 @@ size_t StagingBuffer::calculateFirstSlotOffsetAndValidate(
|
|||||||
+ ")");
|
+ ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstSlotOffsetNBytes + nDgramsPerFrame * slotStrideNBytes
|
if (firstSlotOffsetNBytes + nSlots * slotStrideNBytes
|
||||||
> bufferNBytes)
|
> bufferNBytes)
|
||||||
{
|
{
|
||||||
throw std::runtime_error(std::string(__func__)
|
throw std::runtime_error(std::string(__func__)
|
||||||
+ ": StagingBuffer: buffer size insufficient to hold "
|
+ ": StagingBuffer: buffer size insufficient to hold "
|
||||||
+ std::to_string(nDgramsPerFrame)
|
+ std::to_string(nSlots)
|
||||||
+ " slots with proper alignment and padding");
|
+ " slots with proper alignment and padding");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,17 +165,17 @@ size_t StagingBuffer::calculateFirstSlotOffsetAndValidate(
|
|||||||
StagingBuffer::StagingBuffer(
|
StagingBuffer::StagingBuffer(
|
||||||
const IOEngineConstraints& inputEngineConstraints_,
|
const IOEngineConstraints& inputEngineConstraints_,
|
||||||
const IOEngineConstraints& /*outputEngineConstraints*/,
|
const IOEngineConstraints& /*outputEngineConstraints*/,
|
||||||
size_t nDgramsPerFrame)
|
size_t nSlots)
|
||||||
: buffer(nullptr, MmapDeleter(0)), bufferNBytes(0),
|
: buffer(nullptr, MmapDeleter(0)), bufferNBytes(0),
|
||||||
nDgramsPerFrame(nDgramsPerFrame), slotStrideNBytes(0),
|
nSlots(nSlots), slotStrideNBytes(0),
|
||||||
firstSlotOffsetNBytes(0),
|
firstSlotOffsetNBytes(0),
|
||||||
inputConstraints(inputEngineConstraints_),
|
inputConstraints(inputEngineConstraints_),
|
||||||
assemblingFlag(false)
|
assemblingFlag(false)
|
||||||
{
|
{
|
||||||
if (nDgramsPerFrame == 0)
|
if (nSlots == 0)
|
||||||
{
|
{
|
||||||
throw std::invalid_argument(std::string(__func__)
|
throw std::invalid_argument(std::string(__func__)
|
||||||
+ ": StagingBuffer: nDgramsPerFrame must be > 0");
|
+ ": StagingBuffer: nSlots must be > 0");
|
||||||
}
|
}
|
||||||
|
|
||||||
computeSlotStrideAndBufferSize();
|
computeSlotStrideAndBufferSize();
|
||||||
@@ -208,14 +208,14 @@ assemblingFlag(false)
|
|||||||
|
|
||||||
// Calculate offset and validate invariants (helper function in .cpp)
|
// Calculate offset and validate invariants (helper function in .cpp)
|
||||||
firstSlotOffsetNBytes = StagingBuffer::calculateFirstSlotOffsetAndValidate(
|
firstSlotOffsetNBytes = StagingBuffer::calculateFirstSlotOffsetAndValidate(
|
||||||
buffer.get(), bufferNBytes, nDgramsPerFrame,
|
buffer.get(), bufferNBytes, nSlots,
|
||||||
slotStrideNBytes, inputConstraints);
|
slotStrideNBytes, inputConstraints);
|
||||||
|
|
||||||
// Build FrameAssemblyDesc once
|
// Build FrameAssemblyDesc once
|
||||||
std::vector<FrameAssemblyDesc::SlotDesc> slots;
|
std::vector<FrameAssemblyDesc::SlotDesc> slots;
|
||||||
slots.reserve(nDgramsPerFrame);
|
slots.reserve(nSlots);
|
||||||
uint8_t *frameBase = buffer.get() + firstSlotOffsetNBytes;
|
uint8_t *frameBase = buffer.get() + firstSlotOffsetNBytes;
|
||||||
for (size_t i = 0; i < nDgramsPerFrame; ++i)
|
for (size_t i = 0; i < nSlots; ++i)
|
||||||
{
|
{
|
||||||
size_t off = i * slotStrideNBytes;
|
size_t off = i * slotStrideNBytes;
|
||||||
FrameAssemblyDesc::SlotDesc s{
|
FrameAssemblyDesc::SlotDesc s{
|
||||||
@@ -225,7 +225,7 @@ assemblingFlag(false)
|
|||||||
}
|
}
|
||||||
|
|
||||||
frameDesc = std::make_shared<FrameAssemblyDesc>(
|
frameDesc = std::make_shared<FrameAssemblyDesc>(
|
||||||
nDgramsPerFrame, inputConstraints.slotPadToNBytes, bufferNBytes,
|
nSlots, inputConstraints.slotPadToNBytes, bufferNBytes,
|
||||||
std::move(slots));
|
std::move(slots));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public:
|
|||||||
explicit StagingBuffer(
|
explicit StagingBuffer(
|
||||||
const IOEngineConstraints& inputEngineConstraints,
|
const IOEngineConstraints& inputEngineConstraints,
|
||||||
const IOEngineConstraints& outputEngineConstraints,
|
const IOEngineConstraints& outputEngineConstraints,
|
||||||
size_t nDgramsPerFrame);
|
size_t nSlots);
|
||||||
~StagingBuffer() = default;
|
~StagingBuffer() = default;
|
||||||
|
|
||||||
// Non-copyable, movable
|
// Non-copyable, movable
|
||||||
@@ -123,7 +123,7 @@ public:
|
|||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << "StagingBuffer{"
|
oss << "StagingBuffer{"
|
||||||
<< "nDgramsPerFrame=" << nDgramsPerFrame
|
<< "nSlots=" << nSlots
|
||||||
<< ", bufferNBytes=" << bufferNBytes
|
<< ", bufferNBytes=" << bufferNBytes
|
||||||
<< ", slotStrideNBytes=" << slotStrideNBytes
|
<< ", slotStrideNBytes=" << slotStrideNBytes
|
||||||
<< ", constraints=" << inputConstraints.stringify()
|
<< ", constraints=" << inputConstraints.stringify()
|
||||||
@@ -136,7 +136,7 @@ private:
|
|||||||
static size_t calculateFirstSlotOffsetAndValidate(
|
static size_t calculateFirstSlotOffsetAndValidate(
|
||||||
uint8_t* buffer,
|
uint8_t* buffer,
|
||||||
size_t bufferNBytes,
|
size_t bufferNBytes,
|
||||||
size_t nDgramsPerFrame,
|
size_t nSlots,
|
||||||
size_t slotStrideNBytes,
|
size_t slotStrideNBytes,
|
||||||
const IOEngineConstraints& inputConstraints);
|
const IOEngineConstraints& inputConstraints);
|
||||||
|
|
||||||
@@ -163,7 +163,7 @@ private:
|
|||||||
size_t bufferNBytes;
|
size_t bufferNBytes;
|
||||||
|
|
||||||
// Layout/invariants
|
// Layout/invariants
|
||||||
size_t nDgramsPerFrame;
|
size_t nSlots;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
size_t slotStrideNBytes;
|
size_t slotStrideNBytes;
|
||||||
|
|||||||
Reference in New Issue
Block a user