diff --git a/mace/BUILD b/mace/BUILD index 8ae6e6d6adbcfca7b87ed14a308e186fccfa3114..65eb1e8d6f8f5f8ff59891ecffd7ecdd36b4326e 100644 --- a/mace/BUILD +++ b/mace/BUILD @@ -32,6 +32,14 @@ config_setting( visibility = ["//visibility:public"], ) +config_setting( + name = "enable_neon", + define_values = { + "neon": "true", + }, + visibility = ["//visibility:public"], +) + config_setting( name = "embed_binary_program", define_values = { 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/BUILD b/mace/examples/BUILD index 7b6a268d56a78bce9879d9707d71f9f8eb4f29c6..ffdb4f7265da572368f6a61cffa81c43c96a1218 100644 --- a/mace/examples/BUILD +++ b/mace/examples/BUILD @@ -1,5 +1,5 @@ # Examples -load("//mace:mace.bzl", "if_android", "if_embed_binary_program") +load("//mace:mace.bzl", "if_android", "if_enable_neon", "if_embed_binary_program") cc_binary( name = "helloworld", @@ -7,7 +7,7 @@ cc_binary( "helloworld.cc", ], copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1"], - linkopts = ["-fopenmp"], + linkopts = if_enable_neon(["-fopenmp"]), deps = [ "//mace/core", "//mace/ops", @@ -20,7 +20,7 @@ cc_test( testonly = 1, srcs = ["benchmark_example.cc"], copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1"], - linkopts = ["-fopenmp"], + linkopts = if_enable_neon(["-fopenmp"]), linkstatic = 1, deps = [ "//mace/core", @@ -32,7 +32,7 @@ cc_binary( name = "mace_run", srcs = ["mace_run.cc"], copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1"], - linkopts = ["-fopenmp"], + linkopts = if_enable_neon(["-fopenmp"]), linkstatic = 1, deps = [ "//mace/codegen:generated_models_lib", diff --git a/mace/examples/mace_run.cc b/mace/examples/mace_run.cc index a8308d5078a1b4e7cca964900463fccee546eada..7a02b8efca692a67ef1167f1e2032500a8a83732 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/BUILD b/mace/kernels/BUILD index e03e63e2eabefb4d66ab498f77a3531fc112d522..da1ee8ec3e5314e79c5ef286626f39504f99ea42 100644 --- a/mace/kernels/BUILD +++ b/mace/kernels/BUILD @@ -7,22 +7,22 @@ package( licenses(["notice"]) # Apache 2.0 -load("//mace:mace.bzl", "if_android", "if_android_arm64", "if_embed_binary_program") +load("//mace:mace.bzl", "if_android", "if_enable_neon", "if_embed_binary_program") cc_library( name = "kernels", - srcs = glob(["*.cc", "opencl/*.cc"]) + if_android_arm64(glob([ + srcs = glob(["*.cc", "opencl/*.cc"]) + if_enable_neon(glob([ "neon/*.cc", ])), - hdrs = glob(["*.h", "opencl/*.h"]) + if_android_arm64(glob([ + hdrs = glob(["*.h", "opencl/*.h"]) + if_enable_neon(glob([ "neon/*.h", ])), copts = [ "-std=c++11", - "-fopenmp", "-D_GLIBCXX_USE_C99_MATH_TR1", ] + - if_embed_binary_program(["-DMACE_EMBED_BINARY_PROGRAM"]), + if_embed_binary_program(["-DMACE_EMBED_BINARY_PROGRAM"]) + + if_enable_neon(["-fopenmp"]), linkopts = if_android(["-lm"]), deps = [ "//mace/core", 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/mace.bzl b/mace/mace.bzl index d7d10109f75e2d7ba630528242ed53a0e79aecf6..2cf6e2aeab688a3785662ad10eb2d73d7e568ecd 100644 --- a/mace/mace.bzl +++ b/mace/mace.bzl @@ -35,3 +35,9 @@ def if_embed_binary_program(a): "//mace:embed_binary_program": a, "//conditions:default": [], }) + +def if_enable_neon(a): + return select({ + "//mace:enable_neon": a, + "//conditions:default": [], + }) diff --git a/mace/ops/BUILD b/mace/ops/BUILD index 1da2972539c157e286ca8f32460b575e247046c2..2395ded6179dc8c7102f1ca4c0096aeaedbc9e79 100644 --- a/mace/ops/BUILD +++ b/mace/ops/BUILD @@ -7,7 +7,7 @@ package( licenses(["notice"]) # Apache 2.0 -load("//mace:mace.bzl", "if_android") +load("//mace:mace.bzl", "if_android", "if_enable_neon") cc_library( name = "test", @@ -34,7 +34,8 @@ cc_library( ["*.h"], exclude = ["ops_test_util.h"], ), - copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1"], + copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1"] + + if_enable_neon(["-DMACE_ENABLE_NEON"]), deps = [ "//mace/kernels", ], diff --git a/mace/ops/addn.cc b/mace/ops/addn.cc index ba0bb38019fbfc6274d09dfa81d9efd8e83ed789..d29944dec3237ffd7a72d15317353dc9ad59cd27 100644 --- a/mace/ops/addn.cc +++ b/mace/ops/addn.cc @@ -11,12 +11,12 @@ REGISTER_CPU_OPERATOR(OpKeyBuilder("AddN") .Build(), AddNOp); -#if __ARM_NEON +#if MACE_ENABLE_NEON REGISTER_NEON_OPERATOR(OpKeyBuilder("AddN") .TypeConstraint("T") .Build(), AddNOp); -#endif // __ARM_NEON +#endif // MACE_ENABLE_NEON REGISTER_OPENCL_OPERATOR(OpKeyBuilder("AddN") .TypeConstraint("T") diff --git a/mace/ops/batch_norm.cc b/mace/ops/batch_norm.cc index 76723b2dc2c369257b79fb66b8c472752253700d..6136c814f4ff6f11bc5697295729b4b54ea8e299 100644 --- a/mace/ops/batch_norm.cc +++ b/mace/ops/batch_norm.cc @@ -11,12 +11,12 @@ REGISTER_CPU_OPERATOR(OpKeyBuilder("BatchNorm") .Build(), BatchNormOp); -#if __ARM_NEON +#if MACE_ENABLE_NEON REGISTER_NEON_OPERATOR(OpKeyBuilder("BatchNorm") .TypeConstraint("T") .Build(), BatchNormOp); -#endif // __ARM_NEON +#endif // MACE_ENABLE_NEON REGISTER_OPENCL_OPERATOR(OpKeyBuilder("BatchNorm") .TypeConstraint("T") 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/ops/conv_2d.cc b/mace/ops/conv_2d.cc index 617bd2c5600670513f67140979fd3ccee3ed6c98..ad771df67a4bb266be6e265e081fb54dcc9b9a2e 100644 --- a/mace/ops/conv_2d.cc +++ b/mace/ops/conv_2d.cc @@ -16,12 +16,12 @@ REGISTER_CPU_OPERATOR(OpKeyBuilder("Conv2D") .Build(), Conv2dOp); -#if __ARM_NEON +#if MACE_ENABLE_NEON REGISTER_NEON_OPERATOR(OpKeyBuilder("Conv2D") .TypeConstraint("T") .Build(), Conv2dOp); -#endif // __ARM_NEON +#endif // MACE_ENABLE_NEON REGISTER_OPENCL_OPERATOR(OpKeyBuilder("Conv2D") .TypeConstraint("T") diff --git a/mace/ops/depthwise_conv2d.cc b/mace/ops/depthwise_conv2d.cc index b8cb2e5be759a4838351ceb0405f075a3bbbf364..ed13d0994336a398156e2aa056ec354fc35f8d72 100644 --- a/mace/ops/depthwise_conv2d.cc +++ b/mace/ops/depthwise_conv2d.cc @@ -11,12 +11,12 @@ REGISTER_CPU_OPERATOR(OpKeyBuilder("DepthwiseConv2d") .Build(), DepthwiseConv2dOp); -#if __ARM_NEON +#if MACE_ENABLE_NEON REGISTER_NEON_OPERATOR(OpKeyBuilder("DepthwiseConv2d") .TypeConstraint("T") .Build(), DepthwiseConv2dOp); -#endif // __ARM_NEON +#endif // MACE_ENABLE_NEON REGISTER_OPENCL_OPERATOR(OpKeyBuilder("DepthwiseConv2d") .TypeConstraint("T") diff --git a/mace/ops/global_avg_pooling.cc b/mace/ops/global_avg_pooling.cc index 534378445ca59b05af2d5c7e89b46d198b14c4f4..f495c71246b9763940d8169eba5b24bb984aada0 100644 --- a/mace/ops/global_avg_pooling.cc +++ b/mace/ops/global_avg_pooling.cc @@ -11,11 +11,11 @@ REGISTER_CPU_OPERATOR(OpKeyBuilder("GlobalAvgPooling") .Build(), GlobalAvgPoolingOp); -#if __ARM_NEON +#if MACE_ENABLE_NEON REGISTER_NEON_OPERATOR(OpKeyBuilder("GlobalAvgPooling") .TypeConstraint("T") .Build(), GlobalAvgPoolingOp); -#endif // __ARM_NEON +#endif // MACE_ENABLE_NEON } // namespace mace diff --git a/mace/ops/global_avg_pooling.h b/mace/ops/global_avg_pooling.h index c5ccf3457bc0b763ab1a7a92e54f9e1b8e2c5310..55deb2a9b5119c6c8b8c0fc3d41873c744623a4f 100644 --- a/mace/ops/global_avg_pooling.h +++ b/mace/ops/global_avg_pooling.h @@ -1,4 +1,4 @@ -// +//DMACE_ENABLE_NEON // Copyright (c) 2017 XiaoMi All rights reserved. // diff --git a/mace/ops/ops_test_util.h b/mace/ops/ops_test_util.h index d03e43de91f2c79a4424a9df2efb2250b340f43b..04bb3c67cf1b896ca617f92a6abbad18bf29abf1 100644 --- a/mace/ops/ops_test_util.h +++ b/mace/ops/ops_test_util.h @@ -11,6 +11,7 @@ #include "mace/core/common.h" #include "mace/core/net.h" #include "mace/core/tensor.h" +#include "mace/core/workspace.h" #include "mace/core/runtime/opencl/opencl_runtime.h" #include "mace/kernels/opencl/helper.h" #include "mace/utils/utils.h" diff --git a/mace/ops/pooling.cc b/mace/ops/pooling.cc index 17031378f7e93ac6924f794ec352d3009181179d..3a467d1237c8508fade69d53162e2630fb48d83f 100644 --- a/mace/ops/pooling.cc +++ b/mace/ops/pooling.cc @@ -15,12 +15,12 @@ REGISTER_CPU_OPERATOR(OpKeyBuilder("Pooling") .Build(), PoolingOp); -#if __ARM_NEON +#if MACE_ENABLE_NEON REGISTER_NEON_OPERATOR(OpKeyBuilder("Pooling") .TypeConstraint("T") .Build(), PoolingOp); -#endif // __ARM_NEON +#endif // MACE_ENABLE_NEON REGISTER_OPENCL_OPERATOR(OpKeyBuilder("Pooling") .TypeConstraint("T") diff --git a/mace/ops/relu.cc b/mace/ops/relu.cc index f471ae64665f34ed9b109fdf5c3f2c1c79ce7320..0197e65cf6297f8addd0dc3acb5bf07425b6a1c7 100644 --- a/mace/ops/relu.cc +++ b/mace/ops/relu.cc @@ -11,12 +11,12 @@ REGISTER_CPU_OPERATOR(OpKeyBuilder("Relu") .Build(), ReluOp); -#if __ARM_NEON +#if MACE_ENABLE_NEON REGISTER_NEON_OPERATOR(OpKeyBuilder("Relu") .TypeConstraint("T") .Build(), ReluOp); -#endif // __ARM_NEON +#endif // MACE_ENABLE_NEON REGISTER_OPENCL_OPERATOR(OpKeyBuilder("Relu") .TypeConstraint("T") diff --git a/mace/ops/resize_bilinear.cc b/mace/ops/resize_bilinear.cc index 8eae71819537a99cc08454e1585844f7d77f52e3..89f460fec98adda501aca49388badc4b67da3db7 100644 --- a/mace/ops/resize_bilinear.cc +++ b/mace/ops/resize_bilinear.cc @@ -11,12 +11,12 @@ REGISTER_CPU_OPERATOR(OpKeyBuilder("ResizeBilinear") .Build(), ResizeBilinearOp); -#if __ARM_NEON +#if MACE_ENABLE_NEON REGISTER_NEON_OPERATOR(OpKeyBuilder("ResizeBilinear") .TypeConstraint("T") .Build(), ResizeBilinearOp); -#endif // __ARM_NEON +#endif // MACE_ENABLE_NEON REGISTER_OPENCL_OPERATOR(OpKeyBuilder("ResizeBilinear") .TypeConstraint("T") 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..5c646eb9de100b1d0efa05d0f0872b076aba3be1 --- /dev/null +++ b/mace/tools/git/gen_version_source.sh @@ -0,0 +1,24 @@ +#!/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 + +DATE_STR=$(date +%Y%m%d) +GIT_VERSION=$(git describe --long --tags) +if [[ $? != 0 ]]; then + GIT_VERSION=unknown +else + GIT_VERSION=${GIT_VERSION}-${DATE_STR} +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/bazel-adb-run.sh b/tools/bazel-adb-run.sh index e80ecd83122e4322051e42c0f0760f6c94dc297f..116e64dbfa1dd41faa5222b829604cc17a50f2ed 100755 --- a/tools/bazel-adb-run.sh +++ b/tools/bazel-adb-run.sh @@ -27,7 +27,11 @@ PROFILINE="--define profiling=true" BRANCH=$(git symbolic-ref --short HEAD) COMMIT_ID=$(git rev-parse --short HEAD) -bazel build -c opt $STRIP --verbose_failures $BAZEL_TARGET --crosstool_top=//external:android/crosstool --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --cpu=$ANDROID_ABI +bazel build -c opt $STRIP --verbose_failures $BAZEL_TARGET \ + --crosstool_top=//external:android/crosstool \ + --host_crosstool_top=@bazel_tools//tools/cpp:toolchain \ + --cpu=$ANDROID_ABI \ + --define neon=true if [ $? -ne 0 ]; then exit 1 diff --git a/tools/validate_gcn.sh b/tools/validate_gcn.sh index d97f70566f1039a372adc7dda9e33d7f5fd46180..d31d098626ad6d6531660daaa824e514147b7b30 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() { @@ -50,7 +51,6 @@ build_and_run() adb push ${MODEL_DIR}/${INPUT_FILE_NAME} ${PHONE_DATA_DIR} adb push bazel-bin/mace/examples/mace_run ${PHONE_DATA_DIR} - num_threads=${1:-4} if [[ "${TUNING_OR_NOT}" != "0" && "$EMBED_OPENCL_BINARY" != true ]];then tuning_flag=1 round=0 # only warm up @@ -63,7 +63,6 @@ build_and_run() MACE_CPP_MIN_VLOG_LEVEL=0 \ MACE_RUN_PARAMETER_PATH=${PHONE_DATA_DIR}/mace_run.config \ MACE_KERNEL_PATH=$KERNEL_DIR \ - OMP_NUM_THREADS=$num_threads \ ${PHONE_DATA_DIR}/mace_run \ --model=${PHONE_DATA_DIR}/${MACE_MODEL_NAME} \ --input=mace_input_node \ @@ -95,10 +94,15 @@ bazel-bin/mace/python/tools/tf_converter --input=${TF_MODEL_FILE_PATH} \ --model_tag=${MODEL_TAG} \ --confuse=True -echo "Step 3: Run model on the phone with files" +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 4: Run model on the phone with files" build_and_run false -echo "Step 4: Generate OpenCL binary program and config code" +echo "Step 5: Generate OpenCL binary program and config code" rm -rf ${CL_BIN_DIR} adb pull ${KERNEL_DIR} ${CL_BIN_DIR} rm -rf ${CL_CODEGEN_DIR} @@ -106,20 +110,20 @@ mkdir -p ${CL_CODEGEN_DIR} python mace/python/tools/opencl_codegen.py \ --cl_binary_dir=${CL_BIN_DIR} --output_path=${CL_CODEGEN_DIR}/opencl_compiled_program.cc -echo "Step 5: Generate tuning source file" +echo "Step 6: Generate tuning source file" adb pull ${PHONE_DATA_DIR}/mace_run.config ${CL_BIN_DIR} mkdir -p ${TUNING_CODEGEN_DIR} python mace/python/tools/binary_codegen.py \ --binary_file=${CL_BIN_DIR}/mace_run.config --output_path=${TUNING_CODEGEN_DIR}/tuning_params.cc -echo "Step 6: Run model on the phone using binary" +echo "Step 7: Run model on the phone using binary" build_and_run true -echo "Step 7: Pull the mace run result." +echo "Step 8: Pull the mace run result." rm -rf ${MODEL_DIR}/${OUTPUT_FILE_NAME} adb