diff --git a/mace/codegen/BUILD b/mace/codegen/BUILD index 04b0f8d6f5c5f71091a7605c04d4d288f4e0e499..29504c9b48255bc3ff543358662136ca1f38b801 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 a3f35682fd2f287f7f6b0a55aa88395803ac716d..e1334527adad0d2109b7a98e471eda987fd6ed9a 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 0f30d4adcea0b000ae912a923c6c3d3b9ea1c507..d20c5cef7eb1ad76f24a98d71106277db8ed4324 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 a7c66173a98032a5decc8cdf7983b4cd91e0fa4a..b9bbf3192eb9f5a7ae669c6df6f711b9f7a79ef3 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 f693d6b55fa9576bb77afddbb10adbf526f91407..98478d369b72b10759ce4aed37e584a0f77a3aa4 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 89744712eba97520d38e55a97d6e11645e3ca325..8619bcb81e8215108271b91175a75830761782aa 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 9a1c6e94ba7f8221d7320228db739e36afa63a8b..66e4701e8024c00e6b103734b01127ec9c8cd2e3 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 0000000000000000000000000000000000000000..ee82428094f1bb3a08704718c5f649762c669041 --- /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 9bfeea08192b780bee6d43b72f4c7b18a5d4cdd3..64c33b6d12d4a482c600a56028db50c4787296bc 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 2d97d833b7f62a57cfcc6d5a14073f65a8e15e2d..2d00699ed863acac513e39e23b71b048b6d577b2 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 2d1e94cb5e5d21797fe83676d1953f0bb2d7f015..bf0c8230d9623e908fd6c3a0579eff86be9094d2 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 6aea528a33a51f6bca3af7e1f0c182b79ea68936..de06486b5e2b36ce5e0b59655d4da7a5d5b9b1b7 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 09146737c42067d1800afdb147bab8ac98c6d4c5..2f97c12fba174f5940418743b193d307fb047ca7 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 46469b07049519a6bc69b255b31bd846de11012a..a8cbe58ac569a0aedbacd48413bd7735a7185bca 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 7ba199d2d36a1f67ee91b7f73e0fbc64bd4e3108..53b3a8d901dffa982e0854ddc8e1777be1037f9f 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 3988dbab2b3a59a483554b6e085bf2d9cc0db73f..4844f6dffcca6084c3146ba37bd23d65e471c007 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 9d762fb5fb3e194aad9636b23ff20434fb854ce1..09d87b9435da11859519d9f397c810545a87e989 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 e29c565b1e4ecf7615da02b1153604f2659eafa6..d868329223cd798c001710b5ff94a917acc91f2e 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 27bc9012e8a00cdf5bdb7d76aa422b361a660d41..4105722d8890e13f0c670939df6e474f5ecba645 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 3eaac6b9be7e21235b96c19f7e25f1eefe75c344..810b2518e1d2e6246c02ce01a3fb5c5b4a805086 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 0000000000000000000000000000000000000000..8b7b4a18455a38595f7c8a6ff5ac2168a49272d1 --- /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 d97f70566f1039a372adc7dda9e33d7f5fd46180..84e95f7fbe81266caec401b752ae63cb4a8eb913 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