From f291ce316003b25b23bd016bc7c0c7afe291f99e Mon Sep 17 00:00:00 2001 From: liuqi Date: Thu, 21 Dec 2017 10:46:39 +0800 Subject: [PATCH] Add version api. --- mace/codegen/BUILD | 11 +++++++++++ mace/core/BUILD | 2 +- mace/core/allocator.h | 2 +- mace/core/arg_helper.h | 2 +- mace/core/mace.cc | 5 ++--- mace/core/net.h | 2 +- mace/core/operator.h | 2 +- mace/core/{ => public}/mace.h | 0 mace/core/public/version.h | 26 ++++++++++++++++++++++++++ mace/core/serializer.h | 2 +- mace/core/tensor.h | 2 +- mace/core/types.h | 2 +- mace/core/workspace.h | 2 +- mace/examples/mace_run.cc | 8 ++++++-- mace/kernels/batch_norm.h | 2 +- mace/kernels/bias_add.h | 2 +- mace/kernels/concat.h | 2 +- mace/kernels/depthwise_conv2d.h | 2 +- mace/kernels/space_to_batch.h | 2 +- mace/ops/concat.h | 1 - mace/python/tools/model.template | 6 +++--- mace/tools/git/gen_version_source.sh | 21 +++++++++++++++++++++ tools/validate_gcn.sh | 6 ++++++ 23 files changed, 89 insertions(+), 23 deletions(-) rename mace/core/{ => public}/mace.h (100%) create mode 100644 mace/core/public/version.h create mode 100644 mace/tools/git/gen_version_source.sh diff --git a/mace/codegen/BUILD b/mace/codegen/BUILD index 04b0f8d6..29504c9b 100644 --- a/mace/codegen/BUILD +++ b/mace/codegen/BUILD @@ -15,6 +15,7 @@ cc_library( deps = [ "//mace/core", "//mace/ops", + '//mace/codegen:version_lib', ] + if_embed_binary_program([ '//mace/codegen:generated_opencl_lib', '//mace/codegen:generated_tuning_lib', @@ -34,3 +35,13 @@ cc_library( copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1"], linkstatic = 1, ) + +cc_library( + name = "version_lib", + srcs = glob(["version/*.cc"]), + copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1"], + linkstatic = 1, + deps = [ + "//mace/core", + ] +) diff --git a/mace/core/BUILD b/mace/core/BUILD index a3f35682..e1334527 100644 --- a/mace/core/BUILD +++ b/mace/core/BUILD @@ -35,7 +35,7 @@ cc_library( cc_library( name = "core", srcs = glob(["*.cc"]), - hdrs = glob(["*.h"]), + hdrs = glob(["*.h", "public/*.h"]), copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1"], linkopts = if_android(["-pie"]), deps = [ diff --git a/mace/core/allocator.h b/mace/core/allocator.h index 0f30d4ad..d20c5cef 100644 --- a/mace/core/allocator.h +++ b/mace/core/allocator.h @@ -9,7 +9,7 @@ #include #include "mace/core/common.h" #include "mace/core/registry.h" -#include "mace/core/mace.h" +#include "mace/core/public/mace.h" #include "mace/core/types.h" namespace mace { diff --git a/mace/core/arg_helper.h b/mace/core/arg_helper.h index a7c66173..b9bbf319 100644 --- a/mace/core/arg_helper.h +++ b/mace/core/arg_helper.h @@ -8,7 +8,7 @@ #include #include "mace/core/common.h" -#include "mace/core/mace.h" +#include "mace/core/public/mace.h" namespace mace { diff --git a/mace/core/mace.cc b/mace/core/mace.cc index f693d6b5..98478d36 100644 --- a/mace/core/mace.cc +++ b/mace/core/mace.cc @@ -2,7 +2,7 @@ // Copyright (c) 2017 XiaoMi All rights reserved. // -#include "mace/core/mace.h" +#include "mace/core/public/mace.h" #include "mace/core/types.h" #include "mace/core/net.h" #include "mace/core/workspace.h" @@ -495,8 +495,7 @@ MaceEngine::MaceEngine(const NetDef *net_def, DeviceType device_type): ws_->CreateTensor("mace_input_node:0", GetDeviceAllocator(device_type_), DT_FLOAT); net_ = std::move(CreateNet(*net_def, ws_.get(), device_type)); } -MaceEngine::~MaceEngine() { -} +MaceEngine::~MaceEngine(){} const float *MaceEngine::Run(const float *input, const std::vector &input_shape, std::vector &output_shape) { diff --git a/mace/core/net.h b/mace/core/net.h index 89744712..8619bcb8 100644 --- a/mace/core/net.h +++ b/mace/core/net.h @@ -6,7 +6,7 @@ #define MACE_CORE_NET_H_ #include "mace/core/common.h" -#include "mace/core/mace.h" +#include "mace/core/public/mace.h" namespace mace { diff --git a/mace/core/operator.h b/mace/core/operator.h index 9a1c6e94..66e4701e 100644 --- a/mace/core/operator.h +++ b/mace/core/operator.h @@ -11,7 +11,7 @@ #include "mace/core/registry.h" #include "mace/core/tensor.h" #include "mace/core/workspace.h" -#include "mace/core/mace.h" +#include "mace/core/public/mace.h" namespace mace { diff --git a/mace/core/mace.h b/mace/core/public/mace.h similarity index 100% rename from mace/core/mace.h rename to mace/core/public/mace.h diff --git a/mace/core/public/version.h b/mace/core/public/version.h new file mode 100644 index 00000000..ee824280 --- /dev/null +++ b/mace/core/public/version.h @@ -0,0 +1,26 @@ +// +// Copyright (c) 2017 XiaoMi All rights reserved. +// + +#ifndef MACE_CORE_PUBLIC_VERSION_H_ +#define MACE_CORE_PUBLIC_VERSION_H_ + +#define MACE_MAJOR_VERSION 0 +#define MACE_MINOR_VERSION 1 +#define MACE_PATCH_VERSION 0 + +// MACE_VERSION_SUFFIX is non-empty for pre-releases (e.g. "-alpha", "-alpha.1", +// "-beta", "-rc", "-rc.1") +#define MACE_VERSION_SUFFIX "" + +#define MACE_STR_HELPER(x) #x +#define MACE_STR(x) MACE_STR_HELPER(x) + +// e.g. "0.5.0" or "0.6.0-alpha". +#define MACE_VERSION_STRING \ + (MACE_STR(MACE_MAJOR_VERSION) "." MACE_STR(MACE_MINOR_VERSION) "." MACE_STR( \ + MACE_PATCH_VERSION) MACE_VERSION_SUFFIX) + +extern const char *MaceVersion(); +extern const char *MaceGitVersion(); +#endif // MACE_CORE_PUBLIC_VERSION_H_ diff --git a/mace/core/serializer.h b/mace/core/serializer.h index 9bfeea08..64c33b6d 100644 --- a/mace/core/serializer.h +++ b/mace/core/serializer.h @@ -7,7 +7,7 @@ #include "mace/core/common.h" #include "mace/core/tensor.h" -#include "mace/core/mace.h" +#include "mace/core/public/mace.h" namespace mace { diff --git a/mace/core/tensor.h b/mace/core/tensor.h index 2d97d833..2d00699e 100644 --- a/mace/core/tensor.h +++ b/mace/core/tensor.h @@ -9,7 +9,7 @@ #include "mace/core/common.h" #include "mace/utils/logging.h" #include "mace/core/types.h" -#include "mace/core/mace.h" +#include "mace/core/public/mace.h" namespace mace { diff --git a/mace/core/types.h b/mace/core/types.h index 2d1e94cb..bf0c8230 100644 --- a/mace/core/types.h +++ b/mace/core/types.h @@ -6,7 +6,7 @@ #define MACE_CORE_TYPES_H_ #include "mace/core/common.h" -#include "mace/core/mace.h" +#include "mace/core/public/mace.h" #include "mace/core/half.h" diff --git a/mace/core/workspace.h b/mace/core/workspace.h index 6aea528a..de06486b 100644 --- a/mace/core/workspace.h +++ b/mace/core/workspace.h @@ -7,7 +7,7 @@ #include "mace/core/common.h" #include "mace/core/tensor.h" -#include "mace/core/mace.h" +#include "mace/core/public/mace.h" namespace mace { diff --git a/mace/examples/mace_run.cc b/mace/examples/mace_run.cc index 09146737..2f97c12f 100644 --- a/mace/examples/mace_run.cc +++ b/mace/examples/mace_run.cc @@ -17,10 +17,12 @@ #include #include #include "mace/utils/command_line_flags.h" -#include "mace/core/mace.h" #include "mace/utils/logging.h" #include "mace/utils/env_time.h" +#include "mace/core/public/mace.h" +#include "mace/core/public/version.h" + using namespace std; using namespace mace; @@ -82,7 +84,9 @@ int main(int argc, char **argv) { return -1; } - VLOG(0) << "model: " << model_file << std::endl + VLOG(0) << "mace version: " << MaceVersion() << std::endl + << "mace git version: " << MaceGitVersion() << std::endl + << "model: " << model_file << std::endl << "input: " << input_node << std::endl << "output: " << output_node << std::endl << "input_shape: " << input_shape << std::endl diff --git a/mace/kernels/batch_norm.h b/mace/kernels/batch_norm.h index 46469b07..a8cbe58a 100644 --- a/mace/kernels/batch_norm.h +++ b/mace/kernels/batch_norm.h @@ -7,7 +7,7 @@ #include "mace/core/future.h" #include "mace/core/tensor.h" -#include "mace/core/mace.h" +#include "mace/core/public/mace.h" namespace mace { namespace kernels { diff --git a/mace/kernels/bias_add.h b/mace/kernels/bias_add.h index 7ba199d2..53b3a8d9 100644 --- a/mace/kernels/bias_add.h +++ b/mace/kernels/bias_add.h @@ -7,7 +7,7 @@ #include "mace/core/future.h" #include "mace/core/tensor.h" -#include "mace/core/mace.h" +#include "mace/core/public/mace.h" namespace mace { namespace kernels { diff --git a/mace/kernels/concat.h b/mace/kernels/concat.h index 3988dbab..4844f6df 100644 --- a/mace/kernels/concat.h +++ b/mace/kernels/concat.h @@ -8,7 +8,7 @@ #include "mace/core/common.h" #include "mace/core/future.h" #include "mace/core/types.h" -#include "mace/core/mace.h" +#include "mace/core/public/mace.h" #include "mace/core/tensor.h" namespace mace { diff --git a/mace/kernels/depthwise_conv2d.h b/mace/kernels/depthwise_conv2d.h index 9d762fb5..09d87b94 100644 --- a/mace/kernels/depthwise_conv2d.h +++ b/mace/kernels/depthwise_conv2d.h @@ -8,7 +8,7 @@ #include "mace/core/future.h" #include "mace/core/common.h" #include "mace/kernels/conv_pool_2d_util.h" -#include "mace/core/mace.h" +#include "mace/core/public/mace.h" namespace mace { namespace kernels { diff --git a/mace/kernels/space_to_batch.h b/mace/kernels/space_to_batch.h index e29c565b..d8683292 100644 --- a/mace/kernels/space_to_batch.h +++ b/mace/kernels/space_to_batch.h @@ -7,7 +7,7 @@ #include "mace/core/future.h" #include "mace/core/tensor.h" -#include "mace/core/mace.h" +#include "mace/core/public/mace.h" namespace mace { namespace kernels { diff --git a/mace/ops/concat.h b/mace/ops/concat.h index 27bc9012..4105722d 100644 --- a/mace/ops/concat.h +++ b/mace/ops/concat.h @@ -7,7 +7,6 @@ #include "mace/core/operator.h" #include "mace/kernels/concat.h" -#include "mace/core/mace.h" namespace mace { template diff --git a/mace/python/tools/model.template b/mace/python/tools/model.template index 3eaac6b9..810b2518 100644 --- a/mace/python/tools/model.template +++ b/mace/python/tools/model.template @@ -5,7 +5,7 @@ {% if mode == 0 %} #include -#include "mace/core/mace.h" +#include "mace/core/public/mace.h" namespace {{tag}}{ @@ -24,7 +24,7 @@ void Create{{tensor.name}}(std::vector &tensors) { {% elif mode == 1 %} #include #include -#include "mace/core/mace.h" +#include "mace/core/public/mace.h" namespace { static void UpdateOp(mace::OperatorDef &op, @@ -95,7 +95,7 @@ void CreateOperator{{i}}(mace::OperatorDef &op) { {% else %} #include #include -#include "mace/core/mace.h" +#include "mace/core/public/mace.h" namespace {{tag}} { diff --git a/mace/tools/git/gen_version_source.sh b/mace/tools/git/gen_version_source.sh new file mode 100644 index 00000000..8b7b4a18 --- /dev/null +++ b/mace/tools/git/gen_version_source.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# +# Copyright (c) 2017 XiaoMi All rights reserved. +# + +OUTPUT_FILENAME=$1 +if [[ -z "${OUTPUT_FILENAME}}" ]]; then + echo "Usage: $0 " + exit 1 +fi + +GIT_VERSION=$(git describe --long --tags) +if [[ $? != 0 ]]; then + GIT_VERSION=unknown +fi + +cat < ${OUTPUT_FILENAME} +#include "mace/core/public/version.h" +const char *MaceVersion() { return MACE_VERSION_STRING; } +const char *MaceGitVersion() { return "${GIT_VERSION}"; } +EOF diff --git a/tools/validate_gcn.sh b/tools/validate_gcn.sh index d97f7056..84e95f7f 100644 --- a/tools/validate_gcn.sh +++ b/tools/validate_gcn.sh @@ -27,6 +27,7 @@ CL_CODEGEN_DIR=${CODEGEN_DIR}/opencl CL_BIN_DIR=${CODEGEN_DIR}/opencl_bin TUNING_CODEGEN_DIR=${CODEGEN_DIR}/tuning TUNING_OR_NOT=${3:-0} +VERSION_SOURCE_PATH=${CODEGEN_DIR}/version build_and_run() { @@ -95,6 +96,11 @@ bazel-bin/mace/python/tools/tf_converter --input=${TF_MODEL_FILE_PATH} \ --model_tag=${MODEL_TAG} \ --confuse=True +echo "Step 3: Generate version source" +rm -rf ${VERSION_SOURCE_PATH} +mkdir -p ${VERSION_SOURCE_PATH} +bash mace/tools/git/gen_version_source.sh ${VERSION_SOURCE_PATH}/version.cc + echo "Step 3: Run model on the phone with files" build_and_run false -- GitLab