summaryrefslogtreecommitdiff
path: root/tests/tools/nnpackage_run/src/tensor_dumper.cc
diff options
context:
space:
mode:
Diffstat (limited to 'tests/tools/nnpackage_run/src/tensor_dumper.cc')
-rw-r--r--tests/tools/nnpackage_run/src/tensor_dumper.cc54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/tools/nnpackage_run/src/tensor_dumper.cc b/tests/tools/nnpackage_run/src/tensor_dumper.cc
new file mode 100644
index 000000000..ae4ed9518
--- /dev/null
+++ b/tests/tools/nnpackage_run/src/tensor_dumper.cc
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "tensor_dumper.h"
+
+#include <fstream>
+#include <iostream>
+#include <cstring>
+
+namespace NNPackageRun
+{
+TensorDumper::TensorDumper(const std::string &filename)
+{
+ // TODO Handle file open/write error
+ file_.open(filename, std::ios::out | std::ios::binary);
+ dumpInt32(version);
+}
+
+TensorDumper::~TensorDumper() { file_.close(); }
+
+void TensorDumper::dumpInt32(int32_t i)
+{
+ file_.write(reinterpret_cast<const char *>(&i), sizeof(i));
+}
+
+void TensorDumper::dumpSizeT(size_t i)
+{
+ file_.write(reinterpret_cast<const char *>(&i), sizeof(i));
+}
+
+void TensorDumper::dumpTensor(const nnfw_tensorinfo ti, void *buffer, size_t bytes)
+{
+ dumpInt32(ti.dtype);
+ dumpInt32(ti.rank);
+ for (uint i = 0; i < ti.rank; ++i)
+ dumpInt32(ti.dims[i]);
+ dumpSizeT(bytes);
+ file_.write(static_cast<char *>(buffer), bytes);
+}
+
+} // end of namespace NNPackageRun \ No newline at end of file