提交 ee725558 编写于 作者: L Liangliang He

Merge branch 'mace-api' into 'master'

Add version api.

See merge request !176
...@@ -32,6 +32,14 @@ config_setting( ...@@ -32,6 +32,14 @@ config_setting(
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )
config_setting(
name = "enable_neon",
define_values = {
"neon": "true",
},
visibility = ["//visibility:public"],
)
config_setting( config_setting(
name = "embed_binary_program", name = "embed_binary_program",
define_values = { define_values = {
......
...@@ -15,6 +15,7 @@ cc_library( ...@@ -15,6 +15,7 @@ cc_library(
deps = [ deps = [
"//mace/core", "//mace/core",
"//mace/ops", "//mace/ops",
'//mace/codegen:version_lib',
] + if_embed_binary_program([ ] + if_embed_binary_program([
'//mace/codegen:generated_opencl_lib', '//mace/codegen:generated_opencl_lib',
'//mace/codegen:generated_tuning_lib', '//mace/codegen:generated_tuning_lib',
...@@ -34,3 +35,13 @@ cc_library( ...@@ -34,3 +35,13 @@ cc_library(
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1"], copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1"],
linkstatic = 1, 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",
]
)
...@@ -35,7 +35,7 @@ cc_library( ...@@ -35,7 +35,7 @@ cc_library(
cc_library( cc_library(
name = "core", name = "core",
srcs = glob(["*.cc"]), srcs = glob(["*.cc"]),
hdrs = glob(["*.h"]), hdrs = glob(["*.h", "public/*.h"]),
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1"], copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1"],
linkopts = if_android(["-pie"]), linkopts = if_android(["-pie"]),
deps = [ deps = [
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include <malloc.h> #include <malloc.h>
#include "mace/core/common.h" #include "mace/core/common.h"
#include "mace/core/registry.h" #include "mace/core/registry.h"
#include "mace/core/mace.h" #include "mace/core/public/mace.h"
#include "mace/core/types.h" #include "mace/core/types.h"
namespace mace { namespace mace {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <map> #include <map>
#include "mace/core/common.h" #include "mace/core/common.h"
#include "mace/core/mace.h" #include "mace/core/public/mace.h"
namespace mace { namespace mace {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Copyright (c) 2017 XiaoMi All rights reserved. // 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/types.h"
#include "mace/core/net.h" #include "mace/core/net.h"
#include "mace/core/workspace.h" #include "mace/core/workspace.h"
...@@ -495,8 +495,7 @@ MaceEngine::MaceEngine(const NetDef *net_def, DeviceType device_type): ...@@ -495,8 +495,7 @@ MaceEngine::MaceEngine(const NetDef *net_def, DeviceType device_type):
ws_->CreateTensor("mace_input_node:0", GetDeviceAllocator(device_type_), DT_FLOAT); ws_->CreateTensor("mace_input_node:0", GetDeviceAllocator(device_type_), DT_FLOAT);
net_ = std::move(CreateNet(*net_def, ws_.get(), device_type)); net_ = std::move(CreateNet(*net_def, ws_.get(), device_type));
} }
MaceEngine::~MaceEngine() { MaceEngine::~MaceEngine(){}
}
const float *MaceEngine::Run(const float *input, const float *MaceEngine::Run(const float *input,
const std::vector<index_t> &input_shape, const std::vector<index_t> &input_shape,
std::vector<int64_t> &output_shape) { std::vector<int64_t> &output_shape) {
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#define MACE_CORE_NET_H_ #define MACE_CORE_NET_H_
#include "mace/core/common.h" #include "mace/core/common.h"
#include "mace/core/mace.h" #include "mace/core/public/mace.h"
namespace mace { namespace mace {
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "mace/core/registry.h" #include "mace/core/registry.h"
#include "mace/core/tensor.h" #include "mace/core/tensor.h"
#include "mace/core/workspace.h" #include "mace/core/workspace.h"
#include "mace/core/mace.h" #include "mace/core/public/mace.h"
namespace mace { namespace mace {
......
//
// 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_
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "mace/core/common.h" #include "mace/core/common.h"
#include "mace/core/tensor.h" #include "mace/core/tensor.h"
#include "mace/core/mace.h" #include "mace/core/public/mace.h"
namespace mace { namespace mace {
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "mace/core/common.h" #include "mace/core/common.h"
#include "mace/utils/logging.h" #include "mace/utils/logging.h"
#include "mace/core/types.h" #include "mace/core/types.h"
#include "mace/core/mace.h" #include "mace/core/public/mace.h"
namespace mace { namespace mace {
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#define MACE_CORE_TYPES_H_ #define MACE_CORE_TYPES_H_
#include "mace/core/common.h" #include "mace/core/common.h"
#include "mace/core/mace.h" #include "mace/core/public/mace.h"
#include "mace/core/half.h" #include "mace/core/half.h"
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "mace/core/common.h" #include "mace/core/common.h"
#include "mace/core/tensor.h" #include "mace/core/tensor.h"
#include "mace/core/mace.h" #include "mace/core/public/mace.h"
namespace mace { namespace mace {
......
# Examples # 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( cc_binary(
name = "helloworld", name = "helloworld",
...@@ -7,7 +7,7 @@ cc_binary( ...@@ -7,7 +7,7 @@ cc_binary(
"helloworld.cc", "helloworld.cc",
], ],
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1"], copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1"],
linkopts = ["-fopenmp"], linkopts = if_enable_neon(["-fopenmp"]),
deps = [ deps = [
"//mace/core", "//mace/core",
"//mace/ops", "//mace/ops",
...@@ -20,7 +20,7 @@ cc_test( ...@@ -20,7 +20,7 @@ cc_test(
testonly = 1, testonly = 1,
srcs = ["benchmark_example.cc"], srcs = ["benchmark_example.cc"],
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1"], copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1"],
linkopts = ["-fopenmp"], linkopts = if_enable_neon(["-fopenmp"]),
linkstatic = 1, linkstatic = 1,
deps = [ deps = [
"//mace/core", "//mace/core",
...@@ -32,7 +32,7 @@ cc_binary( ...@@ -32,7 +32,7 @@ cc_binary(
name = "mace_run", name = "mace_run",
srcs = ["mace_run.cc"], srcs = ["mace_run.cc"],
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1"], copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1"],
linkopts = ["-fopenmp"], linkopts = if_enable_neon(["-fopenmp"]),
linkstatic = 1, linkstatic = 1,
deps = [ deps = [
"//mace/codegen:generated_models_lib", "//mace/codegen:generated_models_lib",
......
...@@ -17,10 +17,12 @@ ...@@ -17,10 +17,12 @@
#include <iostream> #include <iostream>
#include <cstdlib> #include <cstdlib>
#include "mace/utils/command_line_flags.h" #include "mace/utils/command_line_flags.h"
#include "mace/core/mace.h"
#include "mace/utils/logging.h" #include "mace/utils/logging.h"
#include "mace/utils/env_time.h" #include "mace/utils/env_time.h"
#include "mace/core/public/mace.h"
#include "mace/core/public/version.h"
using namespace std; using namespace std;
using namespace mace; using namespace mace;
...@@ -82,7 +84,9 @@ int main(int argc, char **argv) { ...@@ -82,7 +84,9 @@ int main(int argc, char **argv) {
return -1; 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 << "input: " << input_node << std::endl
<< "output: " << output_node << std::endl << "output: " << output_node << std::endl
<< "input_shape: " << input_shape << std::endl << "input_shape: " << input_shape << std::endl
......
...@@ -7,22 +7,22 @@ package( ...@@ -7,22 +7,22 @@ package(
licenses(["notice"]) # Apache 2.0 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( cc_library(
name = "kernels", name = "kernels",
srcs = glob(["*.cc", "opencl/*.cc"]) + if_android_arm64(glob([ srcs = glob(["*.cc", "opencl/*.cc"]) + if_enable_neon(glob([
"neon/*.cc", "neon/*.cc",
])), ])),
hdrs = glob(["*.h", "opencl/*.h"]) + if_android_arm64(glob([ hdrs = glob(["*.h", "opencl/*.h"]) + if_enable_neon(glob([
"neon/*.h", "neon/*.h",
])), ])),
copts = [ copts = [
"-std=c++11", "-std=c++11",
"-fopenmp",
"-D_GLIBCXX_USE_C99_MATH_TR1", "-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"]), linkopts = if_android(["-lm"]),
deps = [ deps = [
"//mace/core", "//mace/core",
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "mace/core/future.h" #include "mace/core/future.h"
#include "mace/core/tensor.h" #include "mace/core/tensor.h"
#include "mace/core/mace.h" #include "mace/core/public/mace.h"
namespace mace { namespace mace {
namespace kernels { namespace kernels {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "mace/core/future.h" #include "mace/core/future.h"
#include "mace/core/tensor.h" #include "mace/core/tensor.h"
#include "mace/core/mace.h" #include "mace/core/public/mace.h"
namespace mace { namespace mace {
namespace kernels { namespace kernels {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "mace/core/common.h" #include "mace/core/common.h"
#include "mace/core/future.h" #include "mace/core/future.h"
#include "mace/core/types.h" #include "mace/core/types.h"
#include "mace/core/mace.h" #include "mace/core/public/mace.h"
#include "mace/core/tensor.h" #include "mace/core/tensor.h"
namespace mace { namespace mace {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "mace/core/future.h" #include "mace/core/future.h"
#include "mace/core/common.h" #include "mace/core/common.h"
#include "mace/kernels/conv_pool_2d_util.h" #include "mace/kernels/conv_pool_2d_util.h"
#include "mace/core/mace.h" #include "mace/core/public/mace.h"
namespace mace { namespace mace {
namespace kernels { namespace kernels {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "mace/core/future.h" #include "mace/core/future.h"
#include "mace/core/tensor.h" #include "mace/core/tensor.h"
#include "mace/core/mace.h" #include "mace/core/public/mace.h"
namespace mace { namespace mace {
namespace kernels { namespace kernels {
......
...@@ -35,3 +35,9 @@ def if_embed_binary_program(a): ...@@ -35,3 +35,9 @@ def if_embed_binary_program(a):
"//mace:embed_binary_program": a, "//mace:embed_binary_program": a,
"//conditions:default": [], "//conditions:default": [],
}) })
def if_enable_neon(a):
return select({
"//mace:enable_neon": a,
"//conditions:default": [],
})
...@@ -7,7 +7,7 @@ package( ...@@ -7,7 +7,7 @@ package(
licenses(["notice"]) # Apache 2.0 licenses(["notice"]) # Apache 2.0
load("//mace:mace.bzl", "if_android") load("//mace:mace.bzl", "if_android", "if_enable_neon")
cc_library( cc_library(
name = "test", name = "test",
...@@ -34,7 +34,8 @@ cc_library( ...@@ -34,7 +34,8 @@ cc_library(
["*.h"], ["*.h"],
exclude = ["ops_test_util.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 = [ deps = [
"//mace/kernels", "//mace/kernels",
], ],
......
...@@ -11,12 +11,12 @@ REGISTER_CPU_OPERATOR(OpKeyBuilder("AddN") ...@@ -11,12 +11,12 @@ REGISTER_CPU_OPERATOR(OpKeyBuilder("AddN")
.Build(), .Build(),
AddNOp<DeviceType::CPU, float>); AddNOp<DeviceType::CPU, float>);
#if __ARM_NEON #if MACE_ENABLE_NEON
REGISTER_NEON_OPERATOR(OpKeyBuilder("AddN") REGISTER_NEON_OPERATOR(OpKeyBuilder("AddN")
.TypeConstraint<float>("T") .TypeConstraint<float>("T")
.Build(), .Build(),
AddNOp<DeviceType::NEON, float>); AddNOp<DeviceType::NEON, float>);
#endif // __ARM_NEON #endif // MACE_ENABLE_NEON
REGISTER_OPENCL_OPERATOR(OpKeyBuilder("AddN") REGISTER_OPENCL_OPERATOR(OpKeyBuilder("AddN")
.TypeConstraint<float>("T") .TypeConstraint<float>("T")
......
...@@ -11,12 +11,12 @@ REGISTER_CPU_OPERATOR(OpKeyBuilder("BatchNorm") ...@@ -11,12 +11,12 @@ REGISTER_CPU_OPERATOR(OpKeyBuilder("BatchNorm")
.Build(), .Build(),
BatchNormOp<DeviceType::CPU, float>); BatchNormOp<DeviceType::CPU, float>);
#if __ARM_NEON #if MACE_ENABLE_NEON
REGISTER_NEON_OPERATOR(OpKeyBuilder("BatchNorm") REGISTER_NEON_OPERATOR(OpKeyBuilder("BatchNorm")
.TypeConstraint<float>("T") .TypeConstraint<float>("T")
.Build(), .Build(),
BatchNormOp<DeviceType::NEON, float>); BatchNormOp<DeviceType::NEON, float>);
#endif // __ARM_NEON #endif // MACE_ENABLE_NEON
REGISTER_OPENCL_OPERATOR(OpKeyBuilder("BatchNorm") REGISTER_OPENCL_OPERATOR(OpKeyBuilder("BatchNorm")
.TypeConstraint<float>("T") .TypeConstraint<float>("T")
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include "mace/core/operator.h" #include "mace/core/operator.h"
#include "mace/kernels/concat.h" #include "mace/kernels/concat.h"
#include "mace/core/mace.h"
namespace mace { namespace mace {
template <DeviceType D, typename T> template <DeviceType D, typename T>
......
...@@ -16,12 +16,12 @@ REGISTER_CPU_OPERATOR(OpKeyBuilder("Conv2D") ...@@ -16,12 +16,12 @@ REGISTER_CPU_OPERATOR(OpKeyBuilder("Conv2D")
.Build(), .Build(),
Conv2dOp<DeviceType::CPU, half>); Conv2dOp<DeviceType::CPU, half>);
#if __ARM_NEON #if MACE_ENABLE_NEON
REGISTER_NEON_OPERATOR(OpKeyBuilder("Conv2D") REGISTER_NEON_OPERATOR(OpKeyBuilder("Conv2D")
.TypeConstraint<float>("T") .TypeConstraint<float>("T")
.Build(), .Build(),
Conv2dOp<DeviceType::NEON, float>); Conv2dOp<DeviceType::NEON, float>);
#endif // __ARM_NEON #endif // MACE_ENABLE_NEON
REGISTER_OPENCL_OPERATOR(OpKeyBuilder("Conv2D") REGISTER_OPENCL_OPERATOR(OpKeyBuilder("Conv2D")
.TypeConstraint<float>("T") .TypeConstraint<float>("T")
......
...@@ -11,12 +11,12 @@ REGISTER_CPU_OPERATOR(OpKeyBuilder("DepthwiseConv2d") ...@@ -11,12 +11,12 @@ REGISTER_CPU_OPERATOR(OpKeyBuilder("DepthwiseConv2d")
.Build(), .Build(),
DepthwiseConv2dOp<DeviceType::CPU, float>); DepthwiseConv2dOp<DeviceType::CPU, float>);
#if __ARM_NEON #if MACE_ENABLE_NEON
REGISTER_NEON_OPERATOR(OpKeyBuilder("DepthwiseConv2d") REGISTER_NEON_OPERATOR(OpKeyBuilder("DepthwiseConv2d")
.TypeConstraint<float>("T") .TypeConstraint<float>("T")
.Build(), .Build(),
DepthwiseConv2dOp<DeviceType::NEON, float>); DepthwiseConv2dOp<DeviceType::NEON, float>);
#endif // __ARM_NEON #endif // MACE_ENABLE_NEON
REGISTER_OPENCL_OPERATOR(OpKeyBuilder("DepthwiseConv2d") REGISTER_OPENCL_OPERATOR(OpKeyBuilder("DepthwiseConv2d")
.TypeConstraint<float>("T") .TypeConstraint<float>("T")
......
...@@ -11,11 +11,11 @@ REGISTER_CPU_OPERATOR(OpKeyBuilder("GlobalAvgPooling") ...@@ -11,11 +11,11 @@ REGISTER_CPU_OPERATOR(OpKeyBuilder("GlobalAvgPooling")
.Build(), .Build(),
GlobalAvgPoolingOp<DeviceType::CPU, float>); GlobalAvgPoolingOp<DeviceType::CPU, float>);
#if __ARM_NEON #if MACE_ENABLE_NEON
REGISTER_NEON_OPERATOR(OpKeyBuilder("GlobalAvgPooling") REGISTER_NEON_OPERATOR(OpKeyBuilder("GlobalAvgPooling")
.TypeConstraint<float>("T") .TypeConstraint<float>("T")
.Build(), .Build(),
GlobalAvgPoolingOp<DeviceType::NEON, float>); GlobalAvgPoolingOp<DeviceType::NEON, float>);
#endif // __ARM_NEON #endif // MACE_ENABLE_NEON
} // namespace mace } // namespace mace
// //DMACE_ENABLE_NEON
// Copyright (c) 2017 XiaoMi All rights reserved. // Copyright (c) 2017 XiaoMi All rights reserved.
// //
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "mace/core/common.h" #include "mace/core/common.h"
#include "mace/core/net.h" #include "mace/core/net.h"
#include "mace/core/tensor.h" #include "mace/core/tensor.h"
#include "mace/core/workspace.h"
#include "mace/core/runtime/opencl/opencl_runtime.h" #include "mace/core/runtime/opencl/opencl_runtime.h"
#include "mace/kernels/opencl/helper.h" #include "mace/kernels/opencl/helper.h"
#include "mace/utils/utils.h" #include "mace/utils/utils.h"
......
...@@ -15,12 +15,12 @@ REGISTER_CPU_OPERATOR(OpKeyBuilder("Pooling") ...@@ -15,12 +15,12 @@ REGISTER_CPU_OPERATOR(OpKeyBuilder("Pooling")
.Build(), .Build(),
PoolingOp<DeviceType::CPU, half>); PoolingOp<DeviceType::CPU, half>);
#if __ARM_NEON #if MACE_ENABLE_NEON
REGISTER_NEON_OPERATOR(OpKeyBuilder("Pooling") REGISTER_NEON_OPERATOR(OpKeyBuilder("Pooling")
.TypeConstraint<float>("T") .TypeConstraint<float>("T")
.Build(), .Build(),
PoolingOp<DeviceType::NEON, float>); PoolingOp<DeviceType::NEON, float>);
#endif // __ARM_NEON #endif // MACE_ENABLE_NEON
REGISTER_OPENCL_OPERATOR(OpKeyBuilder("Pooling") REGISTER_OPENCL_OPERATOR(OpKeyBuilder("Pooling")
.TypeConstraint<float>("T") .TypeConstraint<float>("T")
......
...@@ -11,12 +11,12 @@ REGISTER_CPU_OPERATOR(OpKeyBuilder("Relu") ...@@ -11,12 +11,12 @@ REGISTER_CPU_OPERATOR(OpKeyBuilder("Relu")
.Build(), .Build(),
ReluOp<DeviceType::CPU, float>); ReluOp<DeviceType::CPU, float>);
#if __ARM_NEON #if MACE_ENABLE_NEON
REGISTER_NEON_OPERATOR(OpKeyBuilder("Relu") REGISTER_NEON_OPERATOR(OpKeyBuilder("Relu")
.TypeConstraint<float>("T") .TypeConstraint<float>("T")
.Build(), .Build(),
ReluOp<DeviceType::NEON, float>); ReluOp<DeviceType::NEON, float>);
#endif // __ARM_NEON #endif // MACE_ENABLE_NEON
REGISTER_OPENCL_OPERATOR(OpKeyBuilder("Relu") REGISTER_OPENCL_OPERATOR(OpKeyBuilder("Relu")
.TypeConstraint<float>("T") .TypeConstraint<float>("T")
......
...@@ -11,12 +11,12 @@ REGISTER_CPU_OPERATOR(OpKeyBuilder("ResizeBilinear") ...@@ -11,12 +11,12 @@ REGISTER_CPU_OPERATOR(OpKeyBuilder("ResizeBilinear")
.Build(), .Build(),
ResizeBilinearOp<DeviceType::CPU, float>); ResizeBilinearOp<DeviceType::CPU, float>);
#if __ARM_NEON #if MACE_ENABLE_NEON
REGISTER_NEON_OPERATOR(OpKeyBuilder("ResizeBilinear") REGISTER_NEON_OPERATOR(OpKeyBuilder("ResizeBilinear")
.TypeConstraint<float>("T") .TypeConstraint<float>("T")
.Build(), .Build(),
ResizeBilinearOp<DeviceType::NEON, float>); ResizeBilinearOp<DeviceType::NEON, float>);
#endif // __ARM_NEON #endif // MACE_ENABLE_NEON
REGISTER_OPENCL_OPERATOR(OpKeyBuilder("ResizeBilinear") REGISTER_OPENCL_OPERATOR(OpKeyBuilder("ResizeBilinear")
.TypeConstraint<float>("T") .TypeConstraint<float>("T")
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
{% if mode == 0 %} {% if mode == 0 %}
#include <vector> #include <vector>
#include "mace/core/mace.h" #include "mace/core/public/mace.h"
namespace {{tag}}{ namespace {{tag}}{
...@@ -24,7 +24,7 @@ void Create{{tensor.name}}(std::vector<mace::TensorProto> &tensors) { ...@@ -24,7 +24,7 @@ void Create{{tensor.name}}(std::vector<mace::TensorProto> &tensors) {
{% elif mode == 1 %} {% elif mode == 1 %}
#include <vector> #include <vector>
#include <string> #include <string>
#include "mace/core/mace.h" #include "mace/core/public/mace.h"
namespace { namespace {
static void UpdateOp(mace::OperatorDef &op, static void UpdateOp(mace::OperatorDef &op,
...@@ -95,7 +95,7 @@ void CreateOperator{{i}}(mace::OperatorDef &op) { ...@@ -95,7 +95,7 @@ void CreateOperator{{i}}(mace::OperatorDef &op) {
{% else %} {% else %}
#include <vector> #include <vector>
#include <string> #include <string>
#include "mace/core/mace.h" #include "mace/core/public/mace.h"
namespace {{tag}} { namespace {{tag}} {
......
#!/usr/bin/env bash
#
# Copyright (c) 2017 XiaoMi All rights reserved.
#
OUTPUT_FILENAME=$1
if [[ -z "${OUTPUT_FILENAME}}" ]]; then
echo "Usage: $0 <filename>"
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 <<EOF > ${OUTPUT_FILENAME}
#include "mace/core/public/version.h"
const char *MaceVersion() { return MACE_VERSION_STRING; }
const char *MaceGitVersion() { return "${GIT_VERSION}"; }
EOF
...@@ -27,7 +27,11 @@ PROFILINE="--define profiling=true" ...@@ -27,7 +27,11 @@ PROFILINE="--define profiling=true"
BRANCH=$(git symbolic-ref --short HEAD) BRANCH=$(git symbolic-ref --short HEAD)
COMMIT_ID=$(git rev-parse --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 if [ $? -ne 0 ]; then
exit 1 exit 1
......
...@@ -27,6 +27,7 @@ CL_CODEGEN_DIR=${CODEGEN_DIR}/opencl ...@@ -27,6 +27,7 @@ CL_CODEGEN_DIR=${CODEGEN_DIR}/opencl
CL_BIN_DIR=${CODEGEN_DIR}/opencl_bin CL_BIN_DIR=${CODEGEN_DIR}/opencl_bin
TUNING_CODEGEN_DIR=${CODEGEN_DIR}/tuning TUNING_CODEGEN_DIR=${CODEGEN_DIR}/tuning
TUNING_OR_NOT=${3:-0} TUNING_OR_NOT=${3:-0}
VERSION_SOURCE_PATH=${CODEGEN_DIR}/version
build_and_run() build_and_run()
{ {
...@@ -50,7 +51,6 @@ build_and_run() ...@@ -50,7 +51,6 @@ build_and_run()
adb push ${MODEL_DIR}/${INPUT_FILE_NAME} ${PHONE_DATA_DIR} adb push ${MODEL_DIR}/${INPUT_FILE_NAME} ${PHONE_DATA_DIR}
adb push bazel-bin/mace/examples/mace_run ${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 if [[ "${TUNING_OR_NOT}" != "0" && "$EMBED_OPENCL_BINARY" != true ]];then
tuning_flag=1 tuning_flag=1
round=0 # only warm up round=0 # only warm up
...@@ -63,7 +63,6 @@ build_and_run() ...@@ -63,7 +63,6 @@ build_and_run()
MACE_CPP_MIN_VLOG_LEVEL=0 \ MACE_CPP_MIN_VLOG_LEVEL=0 \
MACE_RUN_PARAMETER_PATH=${PHONE_DATA_DIR}/mace_run.config \ MACE_RUN_PARAMETER_PATH=${PHONE_DATA_DIR}/mace_run.config \
MACE_KERNEL_PATH=$KERNEL_DIR \ MACE_KERNEL_PATH=$KERNEL_DIR \
OMP_NUM_THREADS=$num_threads \
${PHONE_DATA_DIR}/mace_run \ ${PHONE_DATA_DIR}/mace_run \
--model=${PHONE_DATA_DIR}/${MACE_MODEL_NAME} \ --model=${PHONE_DATA_DIR}/${MACE_MODEL_NAME} \
--input=mace_input_node \ --input=mace_input_node \
...@@ -95,10 +94,15 @@ bazel-bin/mace/python/tools/tf_converter --input=${TF_MODEL_FILE_PATH} \ ...@@ -95,10 +94,15 @@ bazel-bin/mace/python/tools/tf_converter --input=${TF_MODEL_FILE_PATH} \
--model_tag=${MODEL_TAG} \ --model_tag=${MODEL_TAG} \
--confuse=True --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 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} rm -rf ${CL_BIN_DIR}
adb pull ${KERNEL_DIR} ${CL_BIN_DIR} adb pull ${KERNEL_DIR} ${CL_BIN_DIR}
rm -rf ${CL_CODEGEN_DIR} rm -rf ${CL_CODEGEN_DIR}
...@@ -106,20 +110,20 @@ mkdir -p ${CL_CODEGEN_DIR} ...@@ -106,20 +110,20 @@ mkdir -p ${CL_CODEGEN_DIR}
python mace/python/tools/opencl_codegen.py \ python mace/python/tools/opencl_codegen.py \
--cl_binary_dir=${CL_BIN_DIR} --output_path=${CL_CODEGEN_DIR}/opencl_compiled_program.cc --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} adb pull ${PHONE_DATA_DIR}/mace_run.config ${CL_BIN_DIR}
mkdir -p ${TUNING_CODEGEN_DIR} mkdir -p ${TUNING_CODEGEN_DIR}
python mace/python/tools/binary_codegen.py \ python mace/python/tools/binary_codegen.py \
--binary_file=${CL_BIN_DIR}/mace_run.config --output_path=${TUNING_CODEGEN_DIR}/tuning_params.cc --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 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} rm -rf ${MODEL_DIR}/${OUTPUT_FILE_NAME}
adb </dev/null pull ${PHONE_DATA_DIR}/${OUTPUT_FILE_NAME} ${MODEL_DIR} adb </dev/null pull ${PHONE_DATA_DIR}/${OUTPUT_FILE_NAME} ${MODEL_DIR}
echo "Step 8: Validate the result" echo "Step 9: Validate the result"
python tools/validate.py --model_file ${TF_MODEL_FILE_PATH} \ python tools/validate.py --model_file ${TF_MODEL_FILE_PATH} \
--input_file ${MODEL_DIR}/${INPUT_FILE_NAME} \ --input_file ${MODEL_DIR}/${INPUT_FILE_NAME} \
--mace_out_file ${MODEL_DIR}/${OUTPUT_FILE_NAME} \ --mace_out_file ${MODEL_DIR}/${OUTPUT_FILE_NAME} \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册