Skip to content

Commit

Permalink
Merge pull request #571 from xmos/feature/versions
Browse files Browse the repository at this point in the history
Add version support
  • Loading branch information
panickal-xmos authored Mar 30, 2022
2 parents e7917bc + 134b110 commit 87575be
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 5 deletions.
4 changes: 2 additions & 2 deletions experimental/xformer/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ cc_library(

cc_binary(
name = "xcore-opt",
srcs = ["XCoreOptMain.cpp"],
srcs = ["XCoreOptMain.cpp", "Version.h"],
deps = [
":xcore_passes",
":utils",
"@lib_tflite_micro//:shared_header",
"@lib_tflite_micro//:shared_headers",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:StandardOps",
"@llvm-project//mlir:QuantOps",
Expand Down
15 changes: 15 additions & 0 deletions experimental/xformer/Version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2021 XMOS LIMITED. This Software is subject to the terms of the
// XMOS Public License: Version 1

#ifndef XFORMER_VERSION_H_
#define XFORMER_VERSION_H_

namespace xformer {

unsigned majorVersion = 0;
unsigned minorVersion = 1;
unsigned patchVersion = 6;

} // namespace xformer

#endif // XFORMER_VERSION_H_
1 change: 1 addition & 0 deletions experimental/xformer/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ http_archive(
patch_tool = "patch",
patches = [
"//patches:llvm_update.patch",
"//patches:flatbuffer_export.patch",
],
sha256 = "e68c1d346fc3d529653530ca346b2c62f5b31bd4fcca7ffc9c65bb39ab2f6ed3",
strip_prefix = "tensorflow-2.6.2",
Expand Down
15 changes: 15 additions & 0 deletions experimental/xformer/XCoreOptMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
#include "Transforms/Options.h"
#include "Transforms/Passes.h"
#include "Utils/FileIO.h"
#include "Version.h"

#include "lib_nn/api/version.h"
#include "lib_tflite_micro/api/version.h"
#include "lib_tflite_micro/api/xcore_shared_config.h"
#include "mlir/IR/AsmState.h"
#include "mlir/Parser.h"
Expand Down Expand Up @@ -181,7 +184,19 @@ int main(int argc, char **argv) {
int requiredThreadCount = module->getAttr(xcRequiredThreadCountAttrName)
.cast<mlir::IntegerAttr>()
.getInt();

struct shared_config::xcore_metadata cfg;
// Store version info
cfg.lib_nn_major_version = lib_nn::major_version;
cfg.lib_nn_minor_version = lib_nn::minor_version;
cfg.lib_nn_patch_version = lib_nn::patch_version;
cfg.lib_tflite_micro_major_version = lib_tflite_micro::major_version;
cfg.lib_tflite_micro_minor_version = lib_tflite_micro::minor_version;
cfg.lib_tflite_micro_patch_version = lib_tflite_micro::patch_version;
cfg.xformer_major_version = xformer::majorVersion;
cfg.xformer_minor_version = xformer::minorVersion;
cfg.xformer_patch_version = xformer::patchVersion;
// Store number of threads needed to execute the model
cfg.required_thread_count = requiredThreadCount;
auto bufferData =
std::string((char *)&cfg, sizeof(shared_config::xcore_metadata));
Expand Down
3 changes: 2 additions & 1 deletion experimental/xformer/lib_tflite_micro.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package(
)

cc_library(
name = "shared_header",
name = "shared_headers",
srcs = [
"lib_tflite_micro/api/version.h",
"lib_tflite_micro/api/xcore_shared_config.h",
],
)
20 changes: 20 additions & 0 deletions experimental/xformer/patches/flatbuffer_export.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--- tensorflow/compiler/mlir/lite/flatbuffer_export.cc 2022-03-28 16:22:27.000000000 +0100
+++ tensorflow/compiler/mlir/lite/flatbuffer_export.cc 2022-03-28 16:21:41.000000000 +0100
@@ -1553,10 +1553,13 @@
BuildMetadata("min_runtime_version", std::string(kByteStringSize, '\0')));
for (const auto& kv : metadata_) {
const std::string& val = kv.second;
- // Only take the first kByteStringSize values.
- const int count = std::min(kByteStringSize, val.length());
- std::string value = std::string(kByteStringSize, '\0')
- .assign(val.begin(), val.begin() + count);
+ if(val.length() % 16 != 0) {
+ module_.emitError(
+ "metadata string must be aligned to 16 bytes");
+ return llvm::None;
+ }
+ std::string value = std::string(val.length(), '\0')
+ .assign(val.begin(), val.begin() + val.length());
metadata.push_back(BuildMetadata(kv.first, value));
}
return builder_.CreateVector(metadata);
2 changes: 1 addition & 1 deletion third_party/lib_nn
Submodule lib_nn updated 49 files
+0 −19 lib_nn/api/nn_bin_utils.h
+0 −185 lib_nn/api/nn_binary_structs.h
+0 −90 lib_nn/api/nn_bso.h
+0 −492 lib_nn/api/nn_conv2d_bin.h
+0 −1,953 lib_nn/api/nn_conv2d_int8.h
+0 −280 lib_nn/api/nn_conv2d_int8_structs.h
+0 −269 lib_nn/api/nn_fully_connected.h
+1 −0 lib_nn/api/nn_layers.h
+0 −53 lib_nn/api/nn_op_utils.h
+0 −3 lib_nn/api/nn_operator.h
+5 −235 lib_nn/api/nn_pooling.h
+13 −0 lib_nn/api/version.h
+0 −298 lib_nn/src/asm/bconv2d_bin_DI_impl.S
+0 −344 lib_nn/src/asm/bconv2d_bin_impl.S
+0 −402 lib_nn/src/asm/bconv2d_int8_DIDO_impl.S
+0 −458 lib_nn/src/asm/bconv2d_int8_impl.S
+0 −303 lib_nn/src/c/avgpool2d.c
+0 −428 lib_nn/src/c/bnn_conv2d_bin_out.c
+0 −597 lib_nn/src/c/bnn_conv2d_int8_out.c
+0 −520 lib_nn/src/c/bnn_conv2d_ref.c
+0 −102 lib_nn/src/c/bnn_layer2.c
+0 −269 lib_nn/src/c/conv2d_1x1.c
+0 −312 lib_nn/src/c/conv2d_deep.c
+0 −278 lib_nn/src/c/conv2d_depthwise.c
+0 −342 lib_nn/src/c/conv2d_im2col.c
+0 −307 lib_nn/src/c/conv2d_shallowin.c
+0 −260 lib_nn/src/c/fully_connected.c
+0 −89 lib_nn/src/c/nn_op_utils.c
+0 −77 lib_nn/src/c/util/binary/bin_utils.c
+0 −1,022 lib_nn/src/c/util/deep/nn_conv2d_hstrip_deep.c
+0 −223 lib_nn/src/c/util/depthwise/nn_conv2d_hstrip_depthwise.c
+0 −712 lib_nn/src/c/util/shallow/nn_conv2d_hstrip_shallowin.c
+0 −439 test/unit_test/src/adv/deep/test_nn_conv2d_hstrip_deep.c
+0 −943 test/unit_test/src/adv/deep/test_nn_conv2d_hstrip_deep_padded.c
+0 −526 test/unit_test/src/adv/deep/test_nn_conv2d_hstrip_tail_deep.c
+0 −1,075 test/unit_test/src/adv/deep/test_nn_conv2d_hstrip_tail_deep_padded.c
+0 −551 test/unit_test/src/adv/shallow/test_nn_conv2d_hstrip_shallowin.c
+0 −948 test/unit_test/src/adv/shallow/test_nn_conv2d_hstrip_shallowin_padded.c
+0 −565 test/unit_test/src/adv/shallow/test_nn_conv2d_hstrip_tail_shallowin.c
+0 −982 test/unit_test/src/adv/shallow/test_nn_conv2d_hstrip_tail_shallowin_padded.c
+0 −21 test/unit_test/src/main.c
+0 −510 test/unit_test/src/test_avgpool2d.c
+0 −796 test/unit_test/src/test_conv2d_1x1.c
+0 −1,909 test/unit_test/src/test_conv2d_deep.c
+0 −1,394 test/unit_test/src/test_conv2d_depthwise.c
+0 −1,958 test/unit_test/src/test_conv2d_im2col.c
+0 −1,845 test/unit_test/src/test_conv2d_shallowin.c
+0 −1,538 test/unit_test/src/test_fully_connected_16.c
+0 −1,497 test/unit_test/src/test_fully_connected_8.c

0 comments on commit 87575be

Please sign in to comment.