diff --git a/experimental/xformer/BUILD b/experimental/xformer/BUILD index f3a36a4a3..8ee2e2965 100644 --- a/experimental/xformer/BUILD +++ b/experimental/xformer/BUILD @@ -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", diff --git a/experimental/xformer/Version.h b/experimental/xformer/Version.h new file mode 100644 index 000000000..c7215b8df --- /dev/null +++ b/experimental/xformer/Version.h @@ -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_ \ No newline at end of file diff --git a/experimental/xformer/WORKSPACE b/experimental/xformer/WORKSPACE index bbb96c630..cf908b9bc 100644 --- a/experimental/xformer/WORKSPACE +++ b/experimental/xformer/WORKSPACE @@ -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", diff --git a/experimental/xformer/XCoreOptMain.cpp b/experimental/xformer/XCoreOptMain.cpp index 96642e312..599132c0f 100644 --- a/experimental/xformer/XCoreOptMain.cpp +++ b/experimental/xformer/XCoreOptMain.cpp @@ -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" @@ -181,7 +184,19 @@ int main(int argc, char **argv) { int requiredThreadCount = module->getAttr(xcRequiredThreadCountAttrName) .cast() .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)); diff --git a/experimental/xformer/lib_tflite_micro.BUILD b/experimental/xformer/lib_tflite_micro.BUILD index c9c946c3e..9fc338fe3 100644 --- a/experimental/xformer/lib_tflite_micro.BUILD +++ b/experimental/xformer/lib_tflite_micro.BUILD @@ -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", ], ) diff --git a/experimental/xformer/patches/flatbuffer_export.patch b/experimental/xformer/patches/flatbuffer_export.patch new file mode 100644 index 000000000..f8254e97e --- /dev/null +++ b/experimental/xformer/patches/flatbuffer_export.patch @@ -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); diff --git a/third_party/lib_nn b/third_party/lib_nn index 970c278cb..7549c354e 160000 --- a/third_party/lib_nn +++ b/third_party/lib_nn @@ -1 +1 @@ -Subproject commit 970c278cbc3fa7d61bfb38011289a43e70a61251 +Subproject commit 7549c354e884e8e38c10637b8d129213fdd31686 diff --git a/third_party/lib_tflite_micro b/third_party/lib_tflite_micro index 89ee342c2..4ae6db264 160000 --- a/third_party/lib_tflite_micro +++ b/third_party/lib_tflite_micro @@ -1 +1 @@ -Subproject commit 89ee342c2f6f9ff65d4f9199021701ec2f9387ae +Subproject commit 4ae6db26482faf092fa2f2732b9b40ec95bd1d40