aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFredrik Svedberg <fredrik.svedberg@arm.com>2022-06-30 10:57:57 +0200
committerKristofer Jonsson <kristofer.jonsson@arm.com>2022-09-13 09:01:16 +0000
commit39a03248a3fc2168332e8bd9b663935f5282243d (patch)
treee624309dfe7c3ffe97b31262cd65e85a5b40052f
parent449c8d81f5b0c4d75c632b7849ddd9966cfd71cf (diff)
downloadethos-u-core-software-39a03248a3fc2168332e8bd9b663935f5282243d.tar.gz
Log ofm data base64 encoded
Added base64 encoded printing of ofm data to speed up logging of large ofms. Change-Id: Ibebd0a3557396eb68d69789f2c016161e085e64a
-rw-r--r--applications/inference_process/src/inference_process.cpp43
1 files changed, 29 insertions, 14 deletions
diff --git a/applications/inference_process/src/inference_process.cpp b/applications/inference_process/src/inference_process.cpp
index e96d601..0c47d1e 100644
--- a/applications/inference_process/src/inference_process.cpp
+++ b/applications/inference_process/src/inference_process.cpp
@@ -41,6 +41,33 @@
using namespace std;
+namespace {
+const char *BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+void printBase64(const uint8_t *data, size_t len) {
+ size_t count = len / 3;
+ size_t remainder = len % 3;
+ char buf[] = "====";
+ while (count--) {
+ buf[0] = BASE64[data[0] >> 2];
+ buf[1] = BASE64[(data[0] & 3) << 4 | data[1] >> 4];
+ buf[2] = BASE64[(data[1] & 0xf) << 2 | data[2] >> 6];
+ buf[3] = BASE64[data[2] & 0x3f];
+ LOG("%s", buf);
+ data += 3;
+ }
+ if (remainder) {
+ uint8_t b2 = remainder > 1 ? data[1] : 0;
+ buf[0] = BASE64[data[0] >> 2];
+ buf[1] = BASE64[(data[0] & 3) << 4 | b2 >> 4];
+ buf[2] = remainder > 1 ? BASE64[(b2 & 0xf) << 2] : '=';
+ buf[3] = '=';
+ LOG("%s", buf);
+ }
+}
+
+} // namespace
+
namespace InferenceProcess {
DataPtr::DataPtr(void *_data, size_t _size) : data(_data), size(_size) {}
@@ -338,20 +365,8 @@ void InferenceProcess::printOutputTensor(TfLiteTensor *output, size_t bytesToPri
if (numBytesToPrint) {
LOG("\"crc32\": \"%08" PRIx32 "\",\n", crc32);
LOG("\"data\":\"");
-
- for (int i = 0; i < numBytesToPrint - 1; ++i) {
- /*
- * Workaround an issue when compiling with GCC where by
- * printing only a '\n' the produced global output is wrong.
- */
- if (i % 15 == 0 && i != 0) {
- LOG("0x%02x,\n", output->data.uint8[i]);
- } else {
- LOG("0x%02x,", output->data.uint8[i]);
- }
- }
-
- LOG("0x%02x\"\n", output->data.uint8[numBytesToPrint - 1]);
+ printBase64(output->data.uint8, numBytesToPrint);
+ LOG("\"\n");
} else {
LOG("\"crc32\": \"%08" PRIx32 "\"\n", crc32);
}