-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add double buffering for data printing
Showing
9 changed files
with
234 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#ifndef MARCO_RUNTIME_PRINTERS_DOUBLEBUFFER_H | ||
#define MARCO_RUNTIME_PRINTERS_DOUBLEBUFFER_H | ||
|
||
#include "marco/Runtime/Printers/Printer.h" | ||
#include <functional> | ||
|
||
namespace marco::runtime::printing | ||
{ | ||
class DoubleBuffer | ||
{ | ||
public: | ||
DoubleBuffer(uint64_t lineElementsCount, size_t bufferSizeBytes, std::function<void(const double*, uint64_t)> callback); | ||
|
||
DoubleBuffer(const DoubleBuffer& other) = delete; | ||
|
||
DoubleBuffer(DoubleBuffer&& other) = default; | ||
|
||
DoubleBuffer& operator=(const DoubleBuffer& other) = delete; | ||
|
||
DoubleBuffer& operator=(DoubleBuffer&& other) = default; | ||
|
||
double* getActiveBuffer(); | ||
|
||
void endLine(); | ||
|
||
void flush(); | ||
|
||
private: | ||
uint64_t lineElementsCount{1}; | ||
uint64_t lines{1}; | ||
std::function<void(const double*, uint64_t)> callback; | ||
|
||
std::vector<double> inputBuffer; | ||
std::vector<double> outputBuffer; | ||
|
||
uint64_t currentLine{0}; | ||
}; | ||
} | ||
|
||
#endif // MARCO_RUNTIME_PRINTERS_DOUBLEBUFFER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
marco_add_runtime_static_library(PrinterCSV | ||
STATIC | ||
../DoubleBuffer.cpp | ||
../Printer.cpp | ||
CLI.cpp | ||
Options.cpp | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "marco/Runtime/Printers/DoubleBuffer.h" | ||
|
||
using namespace ::marco::runtime::printing; | ||
|
||
namespace marco::runtime::printing { | ||
DoubleBuffer::DoubleBuffer( | ||
uint64_t lineElementsCount, size_t bufferSizeBytes, | ||
std::function<void(const double *, uint64_t)> callback) | ||
: lineElementsCount(lineElementsCount), callback(callback) { | ||
uint64_t requestedLines = | ||
bufferSizeBytes / (sizeof(double) * lineElementsCount); | ||
|
||
lines = std::max(static_cast<uint64_t>(1), requestedLines); | ||
inputBuffer.resize(lines * lineElementsCount, 0xDEADBEEF); | ||
outputBuffer.resize(lines * lineElementsCount, 0xDEADBEEF); | ||
} | ||
|
||
double *DoubleBuffer::getActiveBuffer() { | ||
return inputBuffer.data() + currentLine * lineElementsCount; | ||
} | ||
|
||
void DoubleBuffer::endLine() { | ||
if (++currentLine >= lines) { | ||
flush(); | ||
} | ||
} | ||
|
||
void DoubleBuffer::flush() { | ||
if (currentLine > 0) { | ||
std::swap(inputBuffer, outputBuffer); | ||
|
||
for (uint64_t line = 0; line < lines; ++line) { | ||
callback(outputBuffer.data() + line * lineElementsCount, | ||
lineElementsCount); | ||
} | ||
|
||
currentLine = 0; | ||
} | ||
} | ||
} // namespace marco::runtime::printing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters