From 546f8a238f4d01bf33fd107202b73bf96bb3b602 Mon Sep 17 00:00:00 2001 From: liutuo Date: Mon, 19 Mar 2018 16:49:13 +0800 Subject: [PATCH] fix issue 149 google C++ coding style --- mace/core/operator.cc | 54 +++++++++++++----------- mace/ops/activation.cc | 2 + mace/ops/activation.h | 4 ++ mace/ops/activation_benchmark.cc | 6 +++ mace/ops/activation_test.cc | 4 ++ mace/ops/addn.cc | 2 + mace/ops/addn.h | 2 + mace/ops/addn_benchmark.cc | 6 +++ mace/ops/addn_test.cc | 15 ++++--- mace/ops/batch_norm.cc | 2 + mace/ops/batch_norm.h | 2 + mace/ops/batch_norm_benchmark.cc | 5 +++ mace/ops/batch_norm_test.cc | 35 +++++++++------ mace/ops/batch_to_space.cc | 2 + mace/ops/batch_to_space.h | 9 ++-- mace/ops/batch_to_space_benchmark.cc | 6 +++ mace/ops/bias_add.cc | 2 + mace/ops/bias_add.h | 8 ++-- mace/ops/bias_add_benchmark.cc | 6 +++ mace/ops/bias_add_test.cc | 29 ++++++++----- mace/ops/buffer_to_image.cc | 2 + mace/ops/buffer_to_image.h | 2 + mace/ops/buffer_to_image_test.cc | 8 +++- mace/ops/channel_shuffle.cc | 2 + mace/ops/channel_shuffle.h | 2 + mace/ops/channel_shuffle_benchmark.cc | 45 +++++++++++--------- mace/ops/channel_shuffle_test.cc | 35 +++++++++------ mace/ops/concat.cc | 2 + mace/ops/concat.h | 5 +++ mace/ops/concat_benchmark.cc | 5 +++ mace/ops/concat_test.cc | 24 ++++++++--- mace/ops/conv_2d.cc | 2 + mace/ops/conv_2d.h | 2 + mace/ops/conv_2d_benchmark.cc | 4 ++ mace/ops/conv_2d_test.cc | 21 ++++++--- mace/ops/conv_pool_2d_base.h | 4 ++ mace/ops/core_test.cc | 4 ++ mace/ops/depthwise_conv2d.cc | 2 + mace/ops/depthwise_conv2d.h | 3 ++ mace/ops/depthwise_conv2d_benchmark.cc | 4 ++ mace/ops/depthwise_conv2d_test.cc | 17 +++++--- mace/ops/eltwise.cc | 2 + mace/ops/eltwise.h | 8 ++-- mace/ops/eltwise_benchmark.cc | 8 +++- mace/ops/eltwise_test.cc | 4 ++ mace/ops/folded_batch_norm.cc | 2 + mace/ops/folded_batch_norm.h | 4 ++ mace/ops/folded_batch_norm_test.cc | 47 ++++++++++++--------- mace/ops/fully_connected.cc | 2 + mace/ops/fully_connected.h | 4 ++ mace/ops/fully_connected_benchmark.cc | 7 +++ mace/ops/fully_connected_test.cc | 7 ++- mace/ops/fused_conv_2d.cc | 2 + mace/ops/fused_conv_2d.h | 3 ++ mace/ops/fused_conv_2d_test.cc | 28 ++++++++---- mace/ops/global_avg_pooling.cc | 2 + mace/ops/global_avg_pooling.h | 4 ++ mace/ops/global_avg_pooling_benchmark.cc | 9 +++- mace/ops/global_avg_pooling_test.cc | 8 +++- mace/ops/image_to_buffer.cc | 2 + mace/ops/image_to_buffer.h | 3 ++ mace/ops/matmul.cc | 2 + mace/ops/matmul.h | 2 + mace/ops/matmul_benchmark.cc | 7 +++ mace/ops/matmul_test.cc | 8 +++- mace/ops/ops_test_util.h | 16 +++++-- mace/ops/pooling.cc | 2 + mace/ops/pooling.h | 6 ++- mace/ops/pooling_benchmark.cc | 9 +++- mace/ops/pooling_test.cc | 8 +++- mace/ops/reshape.cc | 2 + mace/ops/reshape.h | 4 ++ mace/ops/reshape_test.cc | 8 +++- mace/ops/resize_bilinear.cc | 2 + mace/ops/resize_bilinear.h | 8 ++-- mace/ops/resize_bilinear_benchmark.cc | 5 +++ mace/ops/resize_bilinear_test.cc | 32 ++++++++------ mace/ops/slice.cc | 2 + mace/ops/slice.h | 5 +++ mace/ops/slice_benchmark.cc | 6 ++- mace/ops/slice_test.cc | 24 +++++++---- mace/ops/softmax.cc | 2 + mace/ops/softmax.h | 8 ++-- mace/ops/softmax_benchmark.cc | 7 +++ mace/ops/softmax_test.cc | 4 ++ mace/ops/space_to_batch.cc | 2 + mace/ops/space_to_batch.h | 3 ++ mace/ops/space_to_batch_benchmark.cc | 6 +++ mace/ops/space_to_batch_test.cc | 9 +++- mace/ops/winograd_convolution_test.cc | 16 +++---- mace/ops/winograd_inverse_transform.cc | 2 + mace/ops/winograd_inverse_transform.h | 3 ++ mace/ops/winograd_transform.cc | 2 + mace/ops/winograd_transform.h | 2 + mace/ops/winograd_transform_benchmark.cc | 5 +++ 95 files changed, 583 insertions(+), 198 deletions(-) diff --git a/mace/core/operator.cc b/mace/core/operator.cc index ae6ca107..ad3c8e58 100644 --- a/mace/core/operator.cc +++ b/mace/core/operator.cc @@ -62,6 +62,8 @@ std::unique_ptr OperatorRegistry::CreateOperator( } } +namespace ops { + extern void Register_Activation(OperatorRegistry *op_registry); extern void Register_AddN(OperatorRegistry *op_registry); extern void Register_BatchNorm(OperatorRegistry *op_registry); @@ -88,32 +90,34 @@ extern void Register_Eltwise(OperatorRegistry *op_registry); extern void Register_FullyConnected(OperatorRegistry *op_registry); extern void Register_Slice(OperatorRegistry *op_registry); +} // namespace ops + OperatorRegistry::OperatorRegistry() { - Register_Activation(this); - Register_AddN(this); - Register_BatchNorm(this); - Register_BatchToSpaceND(this); - Register_BiasAdd(this); - Register_BufferToImage(this); - Register_ChannelShuffle(this); - Register_Concat(this); - Register_Conv2D(this); - Register_DepthwiseConv2d(this); - Register_FoldedBatchNorm(this); - Register_FusedConv2D(this); - Register_GlobalAvgPooling(this); - Register_ImageToBuffer(this); - Register_Pooling(this); - Register_ResizeBilinear(this); - Register_Softmax(this); - Register_SpaceToBatchND(this); - Register_MatMul(this); - Register_WinogradTransform(this); - Register_WinogradInverseTransform(this); - Register_Reshape(this); - Register_Eltwise(this); - Register_FullyConnected(this); - Register_Slice(this); + ops::Register_Activation(this); + ops::Register_AddN(this); + ops::Register_BatchNorm(this); + ops::Register_BatchToSpaceND(this); + ops::Register_BiasAdd(this); + ops::Register_BufferToImage(this); + ops::Register_ChannelShuffle(this); + ops::Register_Concat(this); + ops::Register_Conv2D(this); + ops::Register_DepthwiseConv2d(this); + ops::Register_FoldedBatchNorm(this); + ops::Register_FusedConv2D(this); + ops::Register_GlobalAvgPooling(this); + ops::Register_ImageToBuffer(this); + ops::Register_Pooling(this); + ops::Register_ResizeBilinear(this); + ops::Register_Softmax(this); + ops::Register_SpaceToBatchND(this); + ops::Register_MatMul(this); + ops::Register_WinogradTransform(this); + ops::Register_WinogradInverseTransform(this); + ops::Register_Reshape(this); + ops::Register_Eltwise(this); + ops::Register_FullyConnected(this); + ops::Register_Slice(this); } } // namespace mace diff --git a/mace/ops/activation.cc b/mace/ops/activation.cc index 204896c3..d7a00080 100644 --- a/mace/ops/activation.cc +++ b/mace/ops/activation.cc @@ -5,6 +5,7 @@ #include "mace/ops/activation.h" namespace mace { +namespace ops { void Register_Activation(OperatorRegistry *op_registry) { REGISTER_OPERATOR(op_registry, OpKeyBuilder("Activation") @@ -26,4 +27,5 @@ void Register_Activation(OperatorRegistry *op_registry) { ActivationOp); } +} // namespace ops } // namespace mace diff --git a/mace/ops/activation.h b/mace/ops/activation.h index 12761927..bfe91591 100644 --- a/mace/ops/activation.h +++ b/mace/ops/activation.h @@ -5,10 +5,13 @@ #ifndef MACE_OPS_ACTIVATION_H_ #define MACE_OPS_ACTIVATION_H_ +#include + #include "mace/core/operator.h" #include "mace/kernels/activation.h" namespace mace { +namespace ops { template class ActivationOp : public Operator { @@ -36,6 +39,7 @@ class ActivationOp : public Operator { kernels::ActivationFunctor functor_; }; +} // namespace ops } // namespace mace #endif // MACE_OPS_ACTIVATION_H_ diff --git a/mace/ops/activation_benchmark.cc b/mace/ops/activation_benchmark.cc index 4e904fce..d80099d7 100644 --- a/mace/ops/activation_benchmark.cc +++ b/mace/ops/activation_benchmark.cc @@ -3,11 +3,15 @@ // #include + #include "mace/core/operator.h" #include "mace/core/testing/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { +namespace ops { +namespace test { + template static void ReluBenchmark( int iters, int batch, int channels, int height, int width) { @@ -316,4 +320,6 @@ BM_SIGMOID(1, 3, 512, 512); BM_SIGMOID(1, 32, 112, 112); BM_SIGMOID(1, 64, 256, 256); +} // namespace test +} // namespace ops } // namespace mace diff --git a/mace/ops/activation_test.cc b/mace/ops/activation_test.cc index 77f8e745..82006c56 100644 --- a/mace/ops/activation_test.cc +++ b/mace/ops/activation_test.cc @@ -6,6 +6,8 @@ #include "mace/ops/ops_test_util.h" namespace mace { +namespace ops { +namespace test { class ActivationOpTest : public OpsTestBase {}; @@ -365,4 +367,6 @@ TEST_F(ActivationOpTest, OPENCLSimpleSigmoid) { TestSimpleSigmoid(); } +} // namespace test +} // namespace ops } // namespace mace diff --git a/mace/ops/addn.cc b/mace/ops/addn.cc index 2a18e458..8e253cf1 100644 --- a/mace/ops/addn.cc +++ b/mace/ops/addn.cc @@ -5,6 +5,7 @@ #include "mace/ops/addn.h" namespace mace { +namespace ops { void Register_AddN(OperatorRegistry *op_registry) { REGISTER_OPERATOR(op_registry, OpKeyBuilder("AddN") @@ -26,4 +27,5 @@ void Register_AddN(OperatorRegistry *op_registry) { AddNOp); } +} // namespace ops } // namespace mace diff --git a/mace/ops/addn.h b/mace/ops/addn.h index 5824844b..24a91660 100644 --- a/mace/ops/addn.h +++ b/mace/ops/addn.h @@ -11,6 +11,7 @@ #include "mace/kernels/addn.h" namespace mace { +namespace ops { template class AddNOp : public Operator { @@ -40,6 +41,7 @@ class AddNOp : public Operator { kernels::AddNFunctor functor_; }; +} // namespace ops } // namespace mace #endif // MACE_OPS_ADDN_H_ diff --git a/mace/ops/addn_benchmark.cc b/mace/ops/addn_benchmark.cc index 85c7853d..79d3aca3 100644 --- a/mace/ops/addn_benchmark.cc +++ b/mace/ops/addn_benchmark.cc @@ -3,11 +3,15 @@ // #include + #include "mace/core/operator.h" #include "mace/core/testing/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { +namespace ops { +namespace test { + template static void AddNBenchmark(int iters, int inputs, int n, int h, int w, int c) { mace::testing::StopTiming(); @@ -75,4 +79,6 @@ BM_ADDN(4, 1, 128, 128, 3); BM_ADDN(2, 1, 256, 256, 3); BM_ADDN(2, 1, 512, 512, 3); +} // namespace test +} // namespace ops } // namespace mace diff --git a/mace/ops/addn_test.cc b/mace/ops/addn_test.cc index c061e40c..779d930b 100644 --- a/mace/ops/addn_test.cc +++ b/mace/ops/addn_test.cc @@ -6,6 +6,8 @@ #include "mace/ops/ops_test_util.h" namespace mace { +namespace ops { +namespace test { class AddnOpTest : public OpsTestBase {}; @@ -66,11 +68,12 @@ void RandomTest() { for (int round = 0; round < 10; ++round) { // generate random input - index_t n = 1 + (rand() % 5); - index_t h = 1 + (rand() % 100); - index_t w = 1 + (rand() % 100); - index_t c = 1 + (rand() % 32); - int input_num = 2 + rand() % 3; + static unsigned int seed = 123; + index_t n = 1 + (rand_r(&seed) % 5); + index_t h = 1 + (rand_r(&seed) % 100); + index_t w = 1 + (rand_r(&seed) % 100); + index_t c = 1 + (rand_r(&seed) % 32); + int input_num = 2 + rand_r(&seed) % 3; // Construct graph OpsTestNet net; auto op_def = OpDefBuilder("AddN", "AddNTest"); @@ -117,4 +120,6 @@ void RandomTest() { TEST_F(AddnOpTest, OPENCLRandom) { RandomTest(); } +} // namespace test +} // namespace ops } // namespace mace diff --git a/mace/ops/batch_norm.cc b/mace/ops/batch_norm.cc index e0754fee..6e804cd1 100644 --- a/mace/ops/batch_norm.cc +++ b/mace/ops/batch_norm.cc @@ -5,6 +5,7 @@ #include "mace/ops/batch_norm.h" namespace mace { +namespace ops { void Register_BatchNorm(OperatorRegistry *op_registry) { REGISTER_OPERATOR(op_registry, OpKeyBuilder("BatchNorm") @@ -26,4 +27,5 @@ void Register_BatchNorm(OperatorRegistry *op_registry) { BatchNormOp); } +} // namespace ops } // namespace mace diff --git a/mace/ops/batch_norm.h b/mace/ops/batch_norm.h index 96b1af13..f22c52b5 100644 --- a/mace/ops/batch_norm.h +++ b/mace/ops/batch_norm.h @@ -10,6 +10,7 @@ #include "mace/kernels/batch_norm.h" namespace mace { +namespace ops { template class BatchNormOp : public Operator { @@ -55,6 +56,7 @@ class BatchNormOp : public Operator { OP_OUTPUT_TAGS(OUTPUT); }; +} // namespace ops } // namespace mace #endif // MACE_OPS_BATCH_NORM_H_ diff --git a/mace/ops/batch_norm_benchmark.cc b/mace/ops/batch_norm_benchmark.cc index 5091e26e..cdd4c693 100644 --- a/mace/ops/batch_norm_benchmark.cc +++ b/mace/ops/batch_norm_benchmark.cc @@ -8,6 +8,9 @@ #include "mace/ops/ops_test_util.h" namespace mace { +namespace ops { +namespace test { + template static void BatchNorm( int iters, int batch, int channels, int height, int width) { @@ -101,4 +104,6 @@ BM_BATCH_NORM(1, 1024, 7, 7); BM_BATCH_NORM(32, 1, 256, 256); BM_BATCH_NORM(32, 3, 256, 256); +} // namespace test +} // namespace ops } // namespace mace diff --git a/mace/ops/batch_norm_test.cc b/mace/ops/batch_norm_test.cc index 5c2f7038..9f88afaf 100644 --- a/mace/ops/batch_norm_test.cc +++ b/mace/ops/batch_norm_test.cc @@ -6,6 +6,8 @@ #include "mace/ops/ops_test_util.h" namespace mace { +namespace ops { +namespace test { class BatchNormOpTest : public OpsTestBase {}; @@ -75,11 +77,12 @@ TEST_F(BatchNormOpTest, SimpleCPU) { Simple(); } TEST_F(BatchNormOpTest, SimpleOPENCL) { Simple(); } TEST_F(BatchNormOpTest, SimpleRandomOPENCL) { - srand(time(NULL)); + // srand(time(NULL)); // generate random input - index_t batch = 1 + rand() % 10; - index_t channels = 3 + rand() % 50; + static unsigned int seed = 123; + index_t batch = 1 + rand_r(&seed) % 10; + index_t channels = 3 + rand_r(&seed) % 50; index_t height = 64; index_t width = 64; @@ -147,11 +150,12 @@ TEST_F(BatchNormOpTest, SimpleRandomOPENCL) { } TEST_F(BatchNormOpTest, SimpleRandomHalfOPENCL) { - srand(time(NULL)); + // srand(time(NULL)); // generate random input - index_t batch = 1 + rand() % 10; - index_t channels = 3 + rand() % 50; + static unsigned int seed = 123; + index_t batch = 1 + rand_r(&seed) % 10; + index_t channels = 3 + rand_r(&seed) % 50; index_t height = 64; index_t width = 64; @@ -220,11 +224,12 @@ TEST_F(BatchNormOpTest, SimpleRandomHalfOPENCL) { } TEST_F(BatchNormOpTest, ComplexRandomOPENCL) { - srand(time(NULL)); + // srand(time(NULL)); // generate random input - index_t batch = 1 + rand() % 10; - index_t channels = 3 + rand() % 50; + static unsigned int seed = 123; + index_t batch = 1 + rand_r(&seed) % 10; + index_t channels = 3 + rand_r(&seed) % 50; index_t height = 103; index_t width = 113; @@ -292,11 +297,12 @@ TEST_F(BatchNormOpTest, ComplexRandomOPENCL) { } TEST_F(BatchNormOpTest, ComplexRandomHalfOPENCL) { - srand(time(NULL)); + // srand(time(NULL)); // generate random input - index_t batch = 1 + rand() % 10; - index_t channels = 3 + rand() % 50; + static unsigned int seed = 123; + index_t batch = 1 + rand_r(&seed) % 10; + index_t channels = 3 + rand_r(&seed) % 50; index_t height = 103; index_t width = 113; @@ -363,4 +369,7 @@ TEST_F(BatchNormOpTest, ComplexRandomHalfOPENCL) { kernels::BufferType::IN_OUT_CHANNEL); ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 0.5); } -} + +} // namespace test +} // namespace ops +} // namespace mace diff --git a/mace/ops/batch_to_space.cc b/mace/ops/batch_to_space.cc index 83a79fba..878e79f4 100644 --- a/mace/ops/batch_to_space.cc +++ b/mace/ops/batch_to_space.cc @@ -5,6 +5,7 @@ #include "mace/ops/batch_to_space.h" namespace mace { +namespace ops { void Register_BatchToSpaceND(OperatorRegistry *op_registry) { REGISTER_OPERATOR(op_registry, OpKeyBuilder("BatchToSpaceND") @@ -19,4 +20,5 @@ void Register_BatchToSpaceND(OperatorRegistry *op_registry) { BatchToSpaceNDOp); } +} // namespace ops } // namespace mace diff --git a/mace/ops/batch_to_space.h b/mace/ops/batch_to_space.h index 91d2c0c6..51157aa7 100644 --- a/mace/ops/batch_to_space.h +++ b/mace/ops/batch_to_space.h @@ -2,15 +2,17 @@ // Copyright (c) 2017 XiaoMi All rights reserved. // -#ifndef MACE_OPS_SPACE_TO_BATCH_H_ -#define MACE_OPS_SPACE_TO_BATCH_H_ +#ifndef MACE_OPS_BATCH_TO_SPACE_H_ +#define MACE_OPS_BATCH_TO_SPACE_H_ #include +#include #include "mace/core/operator.h" #include "mace/kernels/space_to_batch.h" namespace mace { +namespace ops { template class BatchToSpaceNDOp : public Operator { @@ -68,6 +70,7 @@ class BatchToSpaceNDOp : public Operator { OP_OUTPUT_TAGS(OUTPUT); }; +} // namespace ops } // namespace mace -#endif // MACE_OPS_SPACE_TO_BATCH_H_ +#endif // MACE_OPS_BATCH_TO_SPACE_H_ diff --git a/mace/ops/batch_to_space_benchmark.cc b/mace/ops/batch_to_space_benchmark.cc index aa68adc4..9d85d7d9 100644 --- a/mace/ops/batch_to_space_benchmark.cc +++ b/mace/ops/batch_to_space_benchmark.cc @@ -7,6 +7,9 @@ #include "mace/ops/ops_test_util.h" namespace mace { +namespace ops { +namespace test { + template static void BMBatchToSpace( int iters, int batch, int channels, int height, int width, int arg) { @@ -53,4 +56,7 @@ static void BMBatchToSpace( BM_BATCH_TO_SPACE(128, 8, 8, 128, 2); BM_BATCH_TO_SPACE(4, 128, 128, 32, 2); BM_BATCH_TO_SPACE(16, 64, 64, 32, 4); + +} // namespace test +} // namespace ops } // namespace mace diff --git a/mace/ops/bias_add.cc b/mace/ops/bias_add.cc index 44b147ea..aeeabc49 100644 --- a/mace/ops/bias_add.cc +++ b/mace/ops/bias_add.cc @@ -5,6 +5,7 @@ #include "mace/ops/bias_add.h" namespace mace { +namespace ops { void Register_BiasAdd(OperatorRegistry *op_registry) { REGISTER_OPERATOR(op_registry, OpKeyBuilder("BiasAdd") @@ -26,4 +27,5 @@ void Register_BiasAdd(OperatorRegistry *op_registry) { BiasAddOp); } +} // namespace ops } // namespace mace diff --git a/mace/ops/bias_add.h b/mace/ops/bias_add.h index ddc88f73..686dd673 100644 --- a/mace/ops/bias_add.h +++ b/mace/ops/bias_add.h @@ -2,13 +2,14 @@ // Copyright (c) 2017 XiaoMi All rights reserved. // -#ifndef MACE_BIAS_ADD_H_ -#define MACE_BIAS_ADD_H_ +#ifndef MACE_OPS_BIAS_ADD_H_ +#define MACE_OPS_BIAS_ADD_H_ #include "mace/core/operator.h" #include "mace/kernels/bias_add.h" namespace mace { +namespace ops { template class BiasAddOp : public Operator { @@ -40,6 +41,7 @@ class BiasAddOp : public Operator { OP_OUTPUT_TAGS(OUTPUT); }; +} // namespace ops } // namespace mace -#endif // MACE_BIAS_ADD_H_ +#endif // MACE_OPS_BIAS_ADD_H_ diff --git a/mace/ops/bias_add_benchmark.cc b/mace/ops/bias_add_benchmark.cc index 8af9405b..1ba0fac2 100644 --- a/mace/ops/bias_add_benchmark.cc +++ b/mace/ops/bias_add_benchmark.cc @@ -8,6 +8,9 @@ #include "mace/ops/ops_test_util.h" namespace mace { +namespace ops { +namespace test { + template static void BiasAdd(int iters, int batch, int channels, int height, int width) { mace::testing::StopTiming(); @@ -77,4 +80,7 @@ BM_BIAS_ADD(1, 512, 14, 14); BM_BIAS_ADD(1, 1024, 7, 7); BM_BIAS_ADD(32, 1, 256, 256); BM_BIAS_ADD(32, 3, 256, 256); + +} // namespace test +} // namespace ops } // namespace mace diff --git a/mace/ops/bias_add_test.cc b/mace/ops/bias_add_test.cc index 91bc96e4..e3645114 100644 --- a/mace/ops/bias_add_test.cc +++ b/mace/ops/bias_add_test.cc @@ -6,6 +6,8 @@ #include "mace/ops/ops_test_util.h" namespace mace { +namespace ops { +namespace test { class BiasAddOpTest : public OpsTestBase {}; @@ -60,13 +62,14 @@ TEST_F(BiasAddOpTest, BiasAddSimpleOPENCL) { } TEST_F(BiasAddOpTest, SimpleRandomOPENCL) { - srand(time(NULL)); + // srand(time(NULL)); // generate random input - index_t batch = 1 + rand() % 10; - index_t channels = 3 + rand() % 50; - index_t height = 64 + rand() % 50; - index_t width = 64 + rand() % 50; + static unsigned int seed = 123; + index_t batch = 1 + rand_r(&seed) % 10; + index_t channels = 3 + rand_r(&seed) % 50; + index_t height = 64 + rand_r(&seed) % 50; + index_t width = 64 + rand_r(&seed) % 50; // Construct graph OpsTestNet net; @@ -110,13 +113,14 @@ TEST_F(BiasAddOpTest, SimpleRandomOPENCL) { } TEST_F(BiasAddOpTest, ComplexRandomOPENCL) { - srand(time(NULL)); + // srand(time(NULL)); // generate random input - index_t batch = 1 + rand() % 10; - index_t channels = 3 + rand() % 50; - index_t height = 103 + rand() % 100; - index_t width = 113 + rand() % 100; + static unsigned int seed = 123; + index_t batch = 1 + rand_r(&seed) % 10; + index_t channels = 3 + rand_r(&seed) % 50; + index_t height = 103 + rand_r(&seed) % 100; + index_t width = 113 + rand_r(&seed) % 100; // Construct graph OpsTestNet net; @@ -158,4 +162,7 @@ TEST_F(BiasAddOpTest, ComplexRandomOPENCL) { kernels::BufferType::IN_OUT_CHANNEL); ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 1e-2); } -} + +} // namespace test +} // namespace ops +} // namespace mace diff --git a/mace/ops/buffer_to_image.cc b/mace/ops/buffer_to_image.cc index 718374de..abeccde0 100644 --- a/mace/ops/buffer_to_image.cc +++ b/mace/ops/buffer_to_image.cc @@ -5,6 +5,7 @@ #include "mace/ops/buffer_to_image.h" namespace mace { +namespace ops { void Register_BufferToImage(OperatorRegistry *op_registry) { REGISTER_OPERATOR(op_registry, OpKeyBuilder("BufferToImage") @@ -20,4 +21,5 @@ void Register_BufferToImage(OperatorRegistry *op_registry) { BufferToImageOp); } +} // namespace ops } // namespace mace diff --git a/mace/ops/buffer_to_image.h b/mace/ops/buffer_to_image.h index d1d8621b..a50bebd3 100644 --- a/mace/ops/buffer_to_image.h +++ b/mace/ops/buffer_to_image.h @@ -9,6 +9,7 @@ #include "mace/kernels/buffer_to_image.h" namespace mace { +namespace ops { template class BufferToImageOp : public Operator { @@ -36,5 +37,6 @@ class BufferToImageOp : public Operator { OP_OUTPUT_TAGS(OUTPUT); }; +} // namespace ops } // namespace mace #endif // MACE_OPS_BUFFER_TO_IMAGE_H_ diff --git a/mace/ops/buffer_to_image_test.cc b/mace/ops/buffer_to_image_test.cc index 04baa382..1d6d55ad 100644 --- a/mace/ops/buffer_to_image_test.cc +++ b/mace/ops/buffer_to_image_test.cc @@ -5,7 +5,9 @@ #include "gtest/gtest.h" #include "mace/ops/ops_test_util.h" -using namespace mace; +namespace mace { +namespace ops { +namespace test { template void TestBidirectionTransform(const int type, @@ -188,3 +190,7 @@ TEST(BufferToImageTest, ArgStringHalfToHalfSmall) { TestStringHalfBidirectionTransform( kernels::ARGUMENT, {2}, input_data); } + +} // namespace test +} // namespace ops +} // namespace mace diff --git a/mace/ops/channel_shuffle.cc b/mace/ops/channel_shuffle.cc index 9e00da6f..c1c5df9c 100644 --- a/mace/ops/channel_shuffle.cc +++ b/mace/ops/channel_shuffle.cc @@ -5,6 +5,7 @@ #include "mace/ops/channel_shuffle.h" namespace mace { +namespace ops { void Register_ChannelShuffle(OperatorRegistry *op_registry) { REGISTER_OPERATOR(op_registry, OpKeyBuilder("ChannelShuffle") @@ -24,4 +25,5 @@ void Register_ChannelShuffle(OperatorRegistry *op_registry) { ChannelShuffleOp); } +} // namespace ops } // namespace mace diff --git a/mace/ops/channel_shuffle.h b/mace/ops/channel_shuffle.h index 5de47d66..93cbfd40 100644 --- a/mace/ops/channel_shuffle.h +++ b/mace/ops/channel_shuffle.h @@ -11,6 +11,7 @@ #include "mace/kernels/channel_shuffle.h" namespace mace { +namespace ops { template class ChannelShuffleOp : public Operator { @@ -42,6 +43,7 @@ class ChannelShuffleOp : public Operator { kernels::ChannelShuffleFunctor functor_; }; +} // namespace ops } // namespace mace #endif // MACE_OPS_CHANNEL_SHUFFLE_H_ diff --git a/mace/ops/channel_shuffle_benchmark.cc b/mace/ops/channel_shuffle_benchmark.cc index 7f403b56..5fa1f6bd 100644 --- a/mace/ops/channel_shuffle_benchmark.cc +++ b/mace/ops/channel_shuffle_benchmark.cc @@ -7,10 +7,12 @@ #include "mace/ops/ops_test_util.h" namespace mace { +namespace ops { +namespace test { -template +template static void ChannelShuffle( - int iters, int batch, int channels, int height, int width, int group) { + int iters, int batch, int channels, int height, int width, int group) { mace::testing::StopTiming(); OpsTestNet net; @@ -23,15 +25,15 @@ static void ChannelShuffle( kernels::BufferType::IN_OUT_CHANNEL); OpDefBuilder("ChannelShuffle", "ChannelShuffleTest") - .Input("InputImage") - .Output("Output") - .AddIntArg("group", group) - .Finalize(net.NewOperatorDef()); + .Input("InputImage") + .Output("Output") + .AddIntArg("group", group) + .Finalize(net.NewOperatorDef()); } else { OpDefBuilder("Softmax", "SoftmaxBM") - .Input("Input") - .Output("Output") - .Finalize(net.NewOperatorDef()); + .Input("Input") + .Output("Output") + .Finalize(net.NewOperatorDef()); } // Warm-up @@ -47,18 +49,19 @@ static void ChannelShuffle( net.Sync(); } -#define BM_CHANNEL_SHUFFLE_MACRO(N, C, H, W, G, TYPE, DEVICE) \ - static void BM_CHANNEL_SHUFFLE_##N##_##C##_##H##_##W##_##G##_##TYPE##_##DEVICE( \ - int iters) { \ - const int64_t tot = static_cast(iters) * N * C * H * W; \ - mace::testing::MaccProcessed(tot); \ - mace::testing::BytesProcessed(tot *(sizeof(TYPE))); \ - ChannelShuffle(iters, N, C, H, W, G); \ - } \ +#define BM_CHANNEL_SHUFFLE_MACRO(N, C, H, W, G, TYPE, DEVICE) \ + static void \ + BM_CHANNEL_SHUFFLE_##N##_##C##_##H##_##W##_##G##_##TYPE##_##DEVICE( \ + int iters) { \ + const int64_t tot = static_cast(iters) * N * C * H * W; \ + mace::testing::MaccProcessed(tot); \ + mace::testing::BytesProcessed(tot *(sizeof(TYPE))); \ + ChannelShuffle(iters, N, C, H, W, G); \ + } \ BENCHMARK(BM_CHANNEL_SHUFFLE_##N##_##C##_##H##_##W##_##G##_##TYPE##_##DEVICE) -#define BM_CHANNEL_SHUFFLE(N, C, H, W, G) \ - BM_CHANNEL_SHUFFLE_MACRO(N, C, H, W, G, float, CPU); \ +#define BM_CHANNEL_SHUFFLE(N, C, H, W, G) \ + BM_CHANNEL_SHUFFLE_MACRO(N, C, H, W, G, float, CPU); \ BM_CHANNEL_SHUFFLE_MACRO(N, C, H, W, G, float, OPENCL); \ BM_CHANNEL_SHUFFLE_MACRO(N, C, H, W, G, half, OPENCL); @@ -66,4 +69,6 @@ BM_CHANNEL_SHUFFLE(1, 64, 64, 64, 8); BM_CHANNEL_SHUFFLE(1, 64, 128, 128, 8); BM_CHANNEL_SHUFFLE(1, 64, 256, 256, 8); -} // namespace mace +} // namespace test +} // namespace ops +} // namespace mace diff --git a/mace/ops/channel_shuffle_test.cc b/mace/ops/channel_shuffle_test.cc index 879e563e..6de9904c 100644 --- a/mace/ops/channel_shuffle_test.cc +++ b/mace/ops/channel_shuffle_test.cc @@ -1,10 +1,13 @@ // // Copyright (c) 2017 XiaoMi All rights reserved. // + #include "mace/core/operator.h" #include "mace/ops/ops_test_util.h" -using namespace mace; +namespace mace { +namespace ops { +namespace test { class ChannelShuffleOpTest : public OpsTestBase {}; @@ -38,30 +41,34 @@ TEST_F(ChannelShuffleOpTest, C16G4_OPENCL) { // Add input data net.AddInputFromArray( - "Input", {1, 1, 2, 16}, - {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}); + "Input", {1, 1, 2, 16}, + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}); BufferToImage(net, "Input", "InputImage", - kernels::BufferType::IN_OUT_CHANNEL); - + kernels::BufferType::IN_OUT_CHANNEL); OpDefBuilder("ChannelShuffle", "ChannelShuffleTest") - .Input("InputImage") - .Output("OutputImage") - .AddIntArg("group", 4) - .Finalize(net.NewOperatorDef()); + .Input("InputImage") + .Output("OutputImage") + .AddIntArg("group", 4) + .Finalize(net.NewOperatorDef()); // Run net.RunOp(DeviceType::OPENCL); // Transfer output ImageToBuffer(net, "OutputImage", "Output", - kernels::BufferType::IN_OUT_CHANNEL); + kernels::BufferType::IN_OUT_CHANNEL); // Check auto expected = CreateTensor( - {1, 1, 2, 16}, {0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, - 16, 20, 24, 28, 17, 21, 25, 29, 18, 22, 26, 30, 19, 23, 27, 31}); + {1, 1, 2, 16}, + {0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, + 16, 20, 24, 28, 17, 21, 25, 29, 18, 22, 26, 30, 19, 23, 27, 31}); ExpectTensorNear(*expected, *net.GetOutput("Output"), 0.001); -} \ No newline at end of file +} + +} // namespace test +} // namespace ops +} // namespace mace diff --git a/mace/ops/concat.cc b/mace/ops/concat.cc index 361fce51..2e6dbc8f 100644 --- a/mace/ops/concat.cc +++ b/mace/ops/concat.cc @@ -5,6 +5,7 @@ #include "mace/ops/concat.h" namespace mace { +namespace ops { void Register_Concat(OperatorRegistry *op_registry) { REGISTER_OPERATOR(op_registry, OpKeyBuilder("Concat") @@ -25,4 +26,5 @@ void Register_Concat(OperatorRegistry *op_registry) { ConcatOp); } +} // namespace ops } // namespace mace diff --git a/mace/ops/concat.h b/mace/ops/concat.h index cadd5293..b791619d 100644 --- a/mace/ops/concat.h +++ b/mace/ops/concat.h @@ -5,9 +5,13 @@ #ifndef MACE_OPS_CONCAT_H_ #define MACE_OPS_CONCAT_H_ +#include + #include "mace/core/operator.h" #include "mace/kernels/concat.h" + namespace mace { +namespace ops { template class ConcatOp : public Operator { @@ -41,6 +45,7 @@ class ConcatOp : public Operator { OP_OUTPUT_TAGS(OUTPUT); }; +} // namespace ops } // namespace mace #endif // MACE_OPS_CONCAT_H_ diff --git a/mace/ops/concat_benchmark.cc b/mace/ops/concat_benchmark.cc index bbbbc126..6e98d03c 100644 --- a/mace/ops/concat_benchmark.cc +++ b/mace/ops/concat_benchmark.cc @@ -7,6 +7,9 @@ #include "mace/ops/ops_test_util.h" namespace mace { +namespace ops { +namespace test { + template static void ConcatHelper(int iters, int concat_dim, int dim1) { mace::testing::StopTiming(); @@ -106,4 +109,6 @@ BM_CONCAT_OPENCL_MACRO(3, 32, 32, 64, half); BM_CONCAT_OPENCL_MACRO(3, 32, 32, 128, half); BM_CONCAT_OPENCL_MACRO(3, 32, 32, 256, half); +} // namespace test +} // namespace ops } // namespace mace diff --git a/mace/ops/concat_test.cc b/mace/ops/concat_test.cc index 2e061ad4..f48a25b3 100644 --- a/mace/ops/concat_test.cc +++ b/mace/ops/concat_test.cc @@ -2,11 +2,16 @@ // Copyright (c) 2017 XiaoMi All rights reserved. // -#include "mace/ops/concat.h" +#include +#include + #include "gmock/gmock.h" #include "mace/ops/ops_test_util.h" +#include "mace/ops/concat.h" -using namespace mace; +namespace mace { +namespace ops { +namespace test { class ConcatOpTest : public OpsTestBase {}; @@ -87,10 +92,11 @@ TEST_F(ConcatOpTest, CPUSimpleVertical) { } TEST_F(ConcatOpTest, CPURandom) { - srand(time(nullptr)); + // srand(time(nullptr)); + static unsigned int seed = 123; int dim = 5; - int num_inputs = 2 + rand() % 10; - int axis = rand() % dim; + int num_inputs = 2 + rand_r(&seed) % 10; + int axis = rand_r(&seed) % dim; // Construct graph OpsTestNet net; auto builder = OpDefBuilder("Concat", "ConcatTest"); @@ -108,7 +114,7 @@ TEST_F(ConcatOpTest, CPURandom) { std::vector input_ptrs(num_inputs, nullptr); index_t concat_axis_size = 0; for (int i = 0; i < num_inputs; ++i) { - input_shapes[i][axis] = 1 + rand() % dim; + input_shapes[i][axis] = 1 + rand_r(&seed) % dim; concat_axis_size += input_shapes[i][axis]; GenerateRandomRealTypeData(input_shapes[i], inputs[i]); input_ptrs[i] = inputs[i].data(); @@ -216,4 +222,8 @@ TEST_F(ConcatOpTest, OPENCLUnAligned) { TEST_F(ConcatOpTest, OPENCLAlignedMultiInput) { OpenclRandomTest( {{3, 32, 32, 32}, {3, 32, 32, 32}, {3, 32, 32, 32}, {3, 32, 32, 32}}, 3); -} \ No newline at end of file +} + +} // namespace test +} // namespace ops +} // namespace mace diff --git a/mace/ops/conv_2d.cc b/mace/ops/conv_2d.cc index 0185c1d1..cf45d9df 100644 --- a/mace/ops/conv_2d.cc +++ b/mace/ops/conv_2d.cc @@ -5,6 +5,7 @@ #include "mace/ops/conv_2d.h" namespace mace { +namespace ops { void Register_Conv2D(OperatorRegistry *op_registry) { REGISTER_OPERATOR(op_registry, OpKeyBuilder("Conv2D") @@ -26,4 +27,5 @@ void Register_Conv2D(OperatorRegistry *op_registry) { Conv2dOp); } +} // namespace ops } // namespace mace diff --git a/mace/ops/conv_2d.h b/mace/ops/conv_2d.h index c441b0b4..08f1bab2 100644 --- a/mace/ops/conv_2d.h +++ b/mace/ops/conv_2d.h @@ -12,6 +12,7 @@ #include "mace/ops/conv_pool_2d_base.h" namespace mace { +namespace ops { template class Conv2dOp : public ConvPool2dOpBase { @@ -44,6 +45,7 @@ class Conv2dOp : public ConvPool2dOpBase { OP_OUTPUT_TAGS(OUTPUT); }; +} // namespace ops } // namespace mace #endif // MACE_OPS_CONV_2D_H_ diff --git a/mace/ops/conv_2d_benchmark.cc b/mace/ops/conv_2d_benchmark.cc index 05af6a09..5399d0ad 100644 --- a/mace/ops/conv_2d_benchmark.cc +++ b/mace/ops/conv_2d_benchmark.cc @@ -10,6 +10,8 @@ #include "mace/ops/ops_test_util.h" namespace mace { +namespace ops { +namespace test { template static void Conv2d(int iters, @@ -139,4 +141,6 @@ BM_CONV_2D(1, 32, 256, 256, 3, 3, 1, 4, VALID, 32); BM_CONV_2D(1, 128, 56, 56, 1, 1, 1, 1, SAME, 128); BM_CONV_2D(1, 1024, 7, 7, 1, 1, 1, 1, SAME, 1024); +} // namespace test +} // namespace ops } // namespace mace diff --git a/mace/ops/conv_2d_test.cc b/mace/ops/conv_2d_test.cc index 086f7328..ee344d71 100644 --- a/mace/ops/conv_2d_test.cc +++ b/mace/ops/conv_2d_test.cc @@ -2,11 +2,15 @@ // Copyright (c) 2017 XiaoMi All rights reserved. // -#include "mace/ops/conv_2d.h" #include +#include + +#include "mace/ops/conv_2d.h" #include "mace/ops/ops_test_util.h" -using namespace mace; +namespace mace { +namespace ops { +namespace test { class Conv2dOpTest : public OpsTestBase {}; @@ -347,14 +351,15 @@ static void TestComplexConvNxNS12(const std::vector &shape, testing::internal::LogToStderr(); auto func = [&](int kernel_h, int kernel_w, int stride_h, int stride_w, Padding type) { - srand(time(NULL)); + // srand(time(NULL)); // generate random input - index_t batch = 3 + (rand() % 10); + static unsigned int seed = 123; + index_t batch = 3 + (rand_r(&seed) % 10); index_t height = shape[0]; index_t width = shape[1]; - index_t input_channels = shape[2] + (rand() % 10); - index_t output_channels = shape[3] + (rand() % 10); + index_t input_channels = shape[2] + (rand_r(&seed) % 10); + index_t output_channels = shape[3] + (rand_r(&seed) % 10); // Construct graph OpsTestNet net; OpDefBuilder("Conv2D", "Conv2dTest") @@ -729,3 +734,7 @@ TEST_F(Conv2dOpTest, OPENCLAlignedPad2) { TEST_F(Conv2dOpTest, OPENCLUnalignedPad4) { TestArbitraryPadConvNxN({107, 113, 5, 7}, {4, 4}); } + +} // namespace test +} // namespace ops +} // namespace mace diff --git a/mace/ops/conv_pool_2d_base.h b/mace/ops/conv_pool_2d_base.h index c3db95ab..a6f1299d 100644 --- a/mace/ops/conv_pool_2d_base.h +++ b/mace/ops/conv_pool_2d_base.h @@ -5,10 +5,13 @@ #ifndef MACE_OPS_CONV_POOL_2D_BASE_H_ #define MACE_OPS_CONV_POOL_2D_BASE_H_ +#include + #include "mace/core/operator.h" #include "mace/kernels/conv_pool_2d_util.h" namespace mace { +namespace ops { template class ConvPool2dOpBase : public Operator { @@ -29,6 +32,7 @@ class ConvPool2dOpBase : public Operator { std::vector dilations_; }; +} // namespace ops } // namespace mace #endif // MACE_OPS_CONV_POOL_2D_BASE_H_ diff --git a/mace/ops/core_test.cc b/mace/ops/core_test.cc index 5c4f6efa..3d533e5d 100644 --- a/mace/ops/core_test.cc +++ b/mace/ops/core_test.cc @@ -5,6 +5,8 @@ #include "mace/ops/ops_test_util.h" namespace mace { +namespace ops { +namespace test { TEST(CoreTest, INIT_MODE) { std::vector op_defs; @@ -56,4 +58,6 @@ TEST(CoreTest, INIT_MODE) { 1e-5); } +} // namespace test +} // namespace ops } // namespace mace diff --git a/mace/ops/depthwise_conv2d.cc b/mace/ops/depthwise_conv2d.cc index a6fb9eb4..112cb031 100644 --- a/mace/ops/depthwise_conv2d.cc +++ b/mace/ops/depthwise_conv2d.cc @@ -5,6 +5,7 @@ #include "mace/ops/depthwise_conv2d.h" namespace mace { +namespace ops { void Register_DepthwiseConv2d(OperatorRegistry *op_registry) { REGISTER_OPERATOR(op_registry, OpKeyBuilder("DepthwiseConv2d") @@ -26,4 +27,5 @@ void Register_DepthwiseConv2d(OperatorRegistry *op_registry) { DepthwiseConv2dOp); } +} // namespace ops } // namespace mace diff --git a/mace/ops/depthwise_conv2d.h b/mace/ops/depthwise_conv2d.h index 0678ba07..f7abd689 100644 --- a/mace/ops/depthwise_conv2d.h +++ b/mace/ops/depthwise_conv2d.h @@ -6,6 +6,7 @@ #define MACE_OPS_DEPTHWISE_CONV2D_H_ #include +#include #include "mace/core/operator.h" #include "mace/kernels/conv_2d.h" @@ -13,6 +14,7 @@ #include "mace/ops/conv_pool_2d_base.h" namespace mace { +namespace ops { template class DepthwiseConv2dOp : public ConvPool2dOpBase { @@ -48,6 +50,7 @@ class DepthwiseConv2dOp : public ConvPool2dOpBase { OP_OUTPUT_TAGS(OUTPUT); }; +} // namespace ops } // namespace mace #endif // MACE_OPS_DEPTHWISE_CONV2D_H_ diff --git a/mace/ops/depthwise_conv2d_benchmark.cc b/mace/ops/depthwise_conv2d_benchmark.cc index 6ba3b000..2d7ec655 100644 --- a/mace/ops/depthwise_conv2d_benchmark.cc +++ b/mace/ops/depthwise_conv2d_benchmark.cc @@ -10,6 +10,8 @@ #include "mace/ops/ops_test_util.h" namespace mace { +namespace ops { +namespace test { template static void DepthwiseConv2d(int iters, @@ -121,4 +123,6 @@ BM_DEPTHWISE_CONV_2D(1, 64, 33, 31, 3, 3, 2, SAME, 1); BM_DEPTHWISE_CONV_2D(1, 3, 512, 512, 3, 3, 2, VALID, 1); BM_DEPTHWISE_CONV_2D(1, 3, 512, 512, 3, 3, 2, SAME, 1); +} // namespace test +} // namespace ops } // namespace mace diff --git a/mace/ops/depthwise_conv2d_test.cc b/mace/ops/depthwise_conv2d_test.cc index 840d13aa..9b621910 100644 --- a/mace/ops/depthwise_conv2d_test.cc +++ b/mace/ops/depthwise_conv2d_test.cc @@ -5,9 +5,9 @@ #include "mace/ops/conv_2d.h" #include "mace/ops/ops_test_util.h" -using namespace mace; - -namespace { +namespace mace { +namespace ops { +namespace test { class DepthwiseConv2dOpTest : public OpsTestBase {}; @@ -207,11 +207,12 @@ void TestNxNS12(const index_t height, const index_t width) { testing::internal::LogToStderr(); auto func = [&](int kernel_h, int kernel_w, int stride_h, int stride_w, Padding type) { - srand(time(NULL)); + // srand(time(NULL)); // generate random input - index_t batch = 1 + rand() % 5; - index_t input_channels = 3 + rand() % 16; + static unsigned int seed = 123; + index_t batch = 1 + rand_r(&seed) % 5; + index_t input_channels = 3 + rand_r(&seed) % 16; index_t multiplier = 1; // Construct graph OpsTestNet net; @@ -316,4 +317,6 @@ TEST_F(DepthwiseConv2dOpTest, OpenCLUnalignedNxNS12Half) { TestNxNS12(107, 113); } -} // namespace +} // namespace test +} // namespace ops +} // namespace mace diff --git a/mace/ops/eltwise.cc b/mace/ops/eltwise.cc index 88d7d43f..5c49f356 100644 --- a/mace/ops/eltwise.cc +++ b/mace/ops/eltwise.cc @@ -5,6 +5,7 @@ #include "mace/ops/eltwise.h" namespace mace { +namespace ops { void Register_Eltwise(OperatorRegistry *op_registry) { REGISTER_OPERATOR(op_registry, OpKeyBuilder("Eltwise") @@ -26,4 +27,5 @@ void Register_Eltwise(OperatorRegistry *op_registry) { EltwiseOp); } +} // namespace ops } // namespace mace diff --git a/mace/ops/eltwise.h b/mace/ops/eltwise.h index 621a8f2b..f68622e5 100644 --- a/mace/ops/eltwise.h +++ b/mace/ops/eltwise.h @@ -2,13 +2,14 @@ // Copyright (c) 2017 XiaoMi All rights reserved. // -#ifndef MACE_OPS_RESHAPE_H_ -#define MACE_OPS_RESHAPE_H_ +#ifndef MACE_OPS_ELTWISE_H_ +#define MACE_OPS_ELTWISE_H_ #include "mace/core/operator.h" #include "mace/kernels/eltwise.h" namespace mace { +namespace ops { template class EltwiseOp : public Operator { @@ -44,6 +45,7 @@ class EltwiseOp : public Operator { OP_OUTPUT_TAGS(OUTPUT); }; +} // namespace ops } // namespace mace -#endif // MACE_OPS_RESHAPE_H_ +#endif // MACE_OPS_ELTWISE_H_ diff --git a/mace/ops/eltwise_benchmark.cc b/mace/ops/eltwise_benchmark.cc index 8dcb243a..25917890 100644 --- a/mace/ops/eltwise_benchmark.cc +++ b/mace/ops/eltwise_benchmark.cc @@ -2,13 +2,17 @@ // Copyright (c) 2017 XiaoMi All rights reserved. // -#include "mace/kernels/eltwise.h" #include + #include "mace/core/operator.h" #include "mace/core/testing/test_benchmark.h" +#include "mace/kernels/eltwise.h" #include "mace/ops/ops_test_util.h" namespace mace { +namespace ops { +namespace test { + template static void EltwiseBenchmark( int iters, kernels::EltwiseType type, int n, int h, int w, int c) { @@ -81,4 +85,6 @@ BM_ELTWISE(0, 1, 240, 240, 256); BM_ELTWISE(1, 1, 240, 240, 256); BM_ELTWISE(2, 1, 240, 240, 256); +} // namespace test +} // namespace ops } // namespace mace diff --git a/mace/ops/eltwise_test.cc b/mace/ops/eltwise_test.cc index ae8cf5f0..28d73843 100644 --- a/mace/ops/eltwise_test.cc +++ b/mace/ops/eltwise_test.cc @@ -7,6 +7,8 @@ #include "mace/ops/ops_test_util.h" namespace mace { +namespace ops { +namespace test { class EltwiseOpTest : public OpsTestBase {}; @@ -170,4 +172,6 @@ TEST_F(EltwiseOpTest, OPENCLRandomHalf) { {13, 32, 32, 64}); } +} // namespace test +} // namespace ops } // namespace mace diff --git a/mace/ops/folded_batch_norm.cc b/mace/ops/folded_batch_norm.cc index 5847ab94..10cc3927 100644 --- a/mace/ops/folded_batch_norm.cc +++ b/mace/ops/folded_batch_norm.cc @@ -5,6 +5,7 @@ #include "mace/ops/folded_batch_norm.h" namespace mace { +namespace ops { void Register_FoldedBatchNorm(OperatorRegistry *op_registry) { REGISTER_OPERATOR(op_registry, OpKeyBuilder("FoldedBatchNorm") @@ -26,4 +27,5 @@ void Register_FoldedBatchNorm(OperatorRegistry *op_registry) { FoldedBatchNormOp); } +} // namespace ops } // namespace mace diff --git a/mace/ops/folded_batch_norm.h b/mace/ops/folded_batch_norm.h index 28f7f99a..dd2f7b17 100644 --- a/mace/ops/folded_batch_norm.h +++ b/mace/ops/folded_batch_norm.h @@ -5,10 +5,13 @@ #ifndef MACE_OPS_FOLDED_BATCH_NORM_H_ #define MACE_OPS_FOLDED_BATCH_NORM_H_ +#include + #include "mace/core/operator.h" #include "mace/kernels/batch_norm.h" namespace mace { +namespace ops { template class FoldedBatchNormOp : public Operator { @@ -48,6 +51,7 @@ class FoldedBatchNormOp : public Operator { OP_OUTPUT_TAGS(OUTPUT); }; +} // namespace ops } // namespace mace #endif // MACE_OPS_FOLDED_BATCH_NORM_H_ diff --git a/mace/ops/folded_batch_norm_test.cc b/mace/ops/folded_batch_norm_test.cc index 77bf351d..a786dfef 100644 --- a/mace/ops/folded_batch_norm_test.cc +++ b/mace/ops/folded_batch_norm_test.cc @@ -6,6 +6,8 @@ #include "mace/ops/ops_test_util.h" namespace mace { +namespace ops { +namespace test { class FoldedBatchNormOpTest : public OpsTestBase {}; @@ -14,12 +16,12 @@ void CalculateScaleOffset(const std::vector &gamma, const std::vector &mean, const std::vector &var, const float epsilon, - std::vector &scale, - std::vector &offset) { + std::vector *scale, + std::vector *offset) { size_t size = gamma.size(); for (int i = 0; i < size; ++i) { - scale[i] = gamma[i] / std::sqrt(var[i] + epsilon); - offset[i] = offset[i] - mean[i] * scale[i]; + (*scale)[i] = gamma[i] / std::sqrt(var[i] + epsilon); + (*offset)[i] = (*offset)[i] - mean[i] * (*scale)[i]; } } @@ -32,7 +34,7 @@ void Simple() { {5, 5, 7, 7, 9, 9, 11, 11, 13, 13, 15, 15}); std::vector scale(1); std::vector offset(1); - CalculateScaleOffset({4.0f}, {2.0}, {10}, {11.67f}, 1e-3, scale, offset); + CalculateScaleOffset({4.0f}, {2.0}, {10}, {11.67f}, 1e-3, &scale, &offset); net.AddInputFromArray("Scale", {1}, scale); net.AddInputFromArray("Offset", {1}, offset); @@ -172,11 +174,12 @@ width}); */ TEST_F(FoldedBatchNormOpTest, SimpleRandomOPENCL) { - srand(time(NULL)); + // srand(time(NULL)); // generate random input - index_t batch = 1 + rand() % 10; - index_t channels = 3 + rand() % 50; + static unsigned int seed = 123; + index_t batch = 1 + rand_r(&seed) % 10; + index_t channels = 3 + rand_r(&seed) % 50; index_t height = 64; index_t width = 64; @@ -227,11 +230,11 @@ TEST_F(FoldedBatchNormOpTest, SimpleRandomOPENCL) { } TEST_F(FoldedBatchNormOpTest, SimpleRandomHalfOPENCL) { - srand(time(NULL)); - + // srand(time(NULL)); // generate random input - index_t batch = 1 + rand() % 10; - index_t channels = 3 + rand() % 50; + static unsigned int seed = 123; + index_t batch = 1 + rand_r(&seed) % 10; + index_t channels = 3 + rand_r(&seed) % 50; index_t height = 64; index_t width = 64; @@ -283,11 +286,11 @@ TEST_F(FoldedBatchNormOpTest, SimpleRandomHalfOPENCL) { } TEST_F(FoldedBatchNormOpTest, ComplexRandomOPENCL) { - srand(time(NULL)); - + // srand(time(NULL)); + static unsigned int seed = 123; // generate random input - index_t batch = 1 + rand() % 10; - index_t channels = 3 + rand() % 50; + index_t batch = 1 + rand_r(&seed) % 10; + index_t channels = 3 + rand_r(&seed) % 50; index_t height = 103; index_t width = 113; @@ -337,11 +340,12 @@ TEST_F(FoldedBatchNormOpTest, ComplexRandomOPENCL) { } TEST_F(FoldedBatchNormOpTest, ComplexRandomHalfOPENCL) { - srand(time(NULL)); + // srand(time(NULL)); // generate random input - index_t batch = 1 + rand() % 10; - index_t channels = 3 + rand() % 50; + static unsigned int seed = 123; + index_t batch = 1 + rand_r(&seed) % 10; + index_t channels = 3 + rand_r(&seed) % 50; index_t height = 103; index_t width = 113; @@ -390,4 +394,7 @@ TEST_F(FoldedBatchNormOpTest, ComplexRandomHalfOPENCL) { kernels::BufferType::IN_OUT_CHANNEL); ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 0.5); } -} + +} // namespace test +} // namespace ops +} // namespace mace diff --git a/mace/ops/fully_connected.cc b/mace/ops/fully_connected.cc index 7f9df74c..dd4c5b87 100644 --- a/mace/ops/fully_connected.cc +++ b/mace/ops/fully_connected.cc @@ -5,6 +5,7 @@ #include "mace/ops/fully_connected.h" namespace mace { +namespace ops { void Register_FullyConnected(OperatorRegistry *op_registry) { REGISTER_OPERATOR(op_registry, OpKeyBuilder("FC") @@ -26,4 +27,5 @@ void Register_FullyConnected(OperatorRegistry *op_registry) { FullyConnectedOp); } +} // namespace ops } // namespace mace diff --git a/mace/ops/fully_connected.h b/mace/ops/fully_connected.h index 282804a5..5ac305ff 100644 --- a/mace/ops/fully_connected.h +++ b/mace/ops/fully_connected.h @@ -5,10 +5,13 @@ #ifndef MACE_OPS_FULLY_CONNECTED_H_ #define MACE_OPS_FULLY_CONNECTED_H_ +#include + #include "mace/core/operator.h" #include "mace/kernels/fully_connected.h" namespace mace { +namespace ops { template class FullyConnectedOp : public Operator { @@ -46,6 +49,7 @@ class FullyConnectedOp : public Operator { OP_OUTPUT_TAGS(OUTPUT); }; +} // namespace ops } // namespace mace #endif // MACE_OPS_FULLY_CONNECTED_H_ diff --git a/mace/ops/fully_connected_benchmark.cc b/mace/ops/fully_connected_benchmark.cc index 5078b124..da9749c4 100644 --- a/mace/ops/fully_connected_benchmark.cc +++ b/mace/ops/fully_connected_benchmark.cc @@ -3,11 +3,15 @@ // #include + #include "mace/core/operator.h" #include "mace/core/testing/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { +namespace ops { +namespace test { + template static void FCBenchmark( int iters, int batch, int height, int width, int channel, int out_channel) { @@ -83,4 +87,7 @@ BM_FC(1, 16, 16, 32, 32); BM_FC(1, 8, 8, 32, 1000); BM_FC(1, 2, 2, 512, 2); BM_FC(1, 7, 7, 512, 4096); + +} // namespace test +} // namespace ops } // namespace mace diff --git a/mace/ops/fully_connected_test.cc b/mace/ops/fully_connected_test.cc index c50e6952..09a0b04f 100644 --- a/mace/ops/fully_connected_test.cc +++ b/mace/ops/fully_connected_test.cc @@ -3,10 +3,13 @@ // #include + #include "mace/core/operator.h" #include "mace/ops/ops_test_util.h" namespace mace { +namespace ops { +namespace test { class FullyConnectedOpTest : public OpsTestBase {}; @@ -263,4 +266,6 @@ TEST_F(FullyConnectedOpTest, OPENCLHalfWidthFormatAligned) { TestWXFormat(1, 16, 32, 32, 32); } -} +} // namespace test +} // namespace ops +} // namespace mace diff --git a/mace/ops/fused_conv_2d.cc b/mace/ops/fused_conv_2d.cc index 4a0245f5..d4b5de4f 100644 --- a/mace/ops/fused_conv_2d.cc +++ b/mace/ops/fused_conv_2d.cc @@ -5,6 +5,7 @@ #include "mace/ops/fused_conv_2d.h" namespace mace { +namespace ops { void Register_FusedConv2D(OperatorRegistry *op_registry) { REGISTER_OPERATOR(op_registry, OpKeyBuilder("FusedConv2D") @@ -26,4 +27,5 @@ void Register_FusedConv2D(OperatorRegistry *op_registry) { FusedConv2dOp); } +} // namespace ops } // namespace mace diff --git a/mace/ops/fused_conv_2d.h b/mace/ops/fused_conv_2d.h index 0184f92f..db9c6e3a 100644 --- a/mace/ops/fused_conv_2d.h +++ b/mace/ops/fused_conv_2d.h @@ -6,12 +6,14 @@ #define MACE_OPS_FUSED_CONV_2D_H_ #include +#include #include "mace/core/operator.h" #include "mace/kernels/conv_2d.h" #include "mace/ops/conv_pool_2d_base.h" namespace mace { +namespace ops { template class FusedConv2dOp : public ConvPool2dOpBase { @@ -46,6 +48,7 @@ class FusedConv2dOp : public ConvPool2dOpBase { OP_OUTPUT_TAGS(OUTPUT); }; +} // namespace ops } // namespace mace #endif // MACE_OPS_FUSED_CONV_2D_H_ diff --git a/mace/ops/fused_conv_2d_test.cc b/mace/ops/fused_conv_2d_test.cc index ad64be0d..1d46679a 100644 --- a/mace/ops/fused_conv_2d_test.cc +++ b/mace/ops/fused_conv_2d_test.cc @@ -2,10 +2,14 @@ // Copyright (c) 2017 XiaoMi All rights reserved. // +#include + #include "mace/ops/fused_conv_2d.h" #include "mace/ops/ops_test_util.h" -using namespace mace; +namespace mace { +namespace ops { +namespace test { class FusedConv2dOpTest : public OpsTestBase {}; @@ -274,14 +278,15 @@ static void TestComplexConvNxNS12(const std::vector &shape) { testing::internal::LogToStderr(); auto func = [&](int kernel_h, int kernel_w, int stride_h, int stride_w, Padding type) { - srand(time(NULL)); + // srand(time(NULL)); // generate random input - index_t batch = 3 + (rand() % 10); + static unsigned int seed = 123; + index_t batch = 3 + (rand_r(&seed) % 10); index_t height = shape[0]; index_t width = shape[1]; - index_t input_channels = shape[2] + (rand() % 10); - index_t output_channels = shape[3] + (rand() % 10); + index_t input_channels = shape[2] + (rand_r(&seed) % 10); + index_t output_channels = shape[3] + (rand_r(&seed) % 10); // Construct graph OpsTestNet net; OpDefBuilder("FusedConv2D", "FusedConv2dTest") @@ -350,14 +355,15 @@ static void TestHalfComplexConvNxNS12(const std::vector &shape) { testing::internal::LogToStderr(); auto func = [&](int kernel_h, int kernel_w, int stride_h, int stride_w, Padding type) { - srand(time(NULL)); + // srand(time(NULL)); // generate random input - index_t batch = 3 + (rand() % 10); + static unsigned int seed = 123; + index_t batch = 3 + (rand_r(&seed) % 10); index_t height = shape[0]; index_t width = shape[1]; - index_t input_channels = shape[2] + (rand() % 10); - index_t output_channels = shape[3] + (rand() % 10); + index_t input_channels = shape[2] + (rand_r(&seed) % 10); + index_t output_channels = shape[3] + (rand_r(&seed) % 10); // Construct graph OpsTestNet net; OpDefBuilder("FusedConv2D", "FusedConv2dTest") @@ -676,3 +682,7 @@ TEST_F(FusedConv2dOpTest, OPENCL15X15AtrousConvD4) { TestGeneralHalfAtrousConv({63, 71}, {15, 15, 16, 16}, {2, 2}); } + +} // namespace test +} // namespace ops +} // namespace mace diff --git a/mace/ops/global_avg_pooling.cc b/mace/ops/global_avg_pooling.cc index 65d34b49..5421f1ce 100644 --- a/mace/ops/global_avg_pooling.cc +++ b/mace/ops/global_avg_pooling.cc @@ -5,6 +5,7 @@ #include "mace/ops/global_avg_pooling.h" namespace mace { +namespace ops { void Register_GlobalAvgPooling(OperatorRegistry *op_registry) { REGISTER_OPERATOR(op_registry, OpKeyBuilder("GlobalAvgPooling") @@ -14,4 +15,5 @@ void Register_GlobalAvgPooling(OperatorRegistry *op_registry) { GlobalAvgPoolingOp); } +} // namespace ops } // namespace mace diff --git a/mace/ops/global_avg_pooling.h b/mace/ops/global_avg_pooling.h index dc1cda9e..59ab7452 100644 --- a/mace/ops/global_avg_pooling.h +++ b/mace/ops/global_avg_pooling.h @@ -5,10 +5,13 @@ #ifndef MACE_OPS_GLOBAL_AVG_POOLING_H_ #define MACE_OPS_GLOBAL_AVG_POOLING_H_ +#include + #include "mace/core/operator.h" #include "mace/kernels/global_avg_pooling.h" namespace mace { +namespace ops { template class GlobalAvgPoolingOp : public Operator { @@ -38,6 +41,7 @@ class GlobalAvgPoolingOp : public Operator { OP_OUTPUT_TAGS(OUTPUT); }; +} // namespace ops } // namespace mace #endif // MACE_OPS_GLOBAL_AVG_POOLING_H_ diff --git a/mace/ops/global_avg_pooling_benchmark.cc b/mace/ops/global_avg_pooling_benchmark.cc index 1ea07c4b..0e8126bc 100644 --- a/mace/ops/global_avg_pooling_benchmark.cc +++ b/mace/ops/global_avg_pooling_benchmark.cc @@ -7,8 +7,9 @@ #include "mace/core/testing/test_benchmark.h" #include "mace/ops/ops_test_util.h" -using namespace mace; -using namespace mace::kernels; +namespace mace { +namespace ops { +namespace test { template static void GlobalAvgPooling( @@ -53,3 +54,7 @@ static void GlobalAvgPooling( BM_GLOBAL_AVG_POOLING(1, 3, 7, 7); BM_GLOBAL_AVG_POOLING(1, 3, 64, 64); BM_GLOBAL_AVG_POOLING(1, 3, 256, 256); + +} // namespace test +} // namespace ops +} // namespace mace diff --git a/mace/ops/global_avg_pooling_test.cc b/mace/ops/global_avg_pooling_test.cc index a00ffc36..8b82f7ab 100644 --- a/mace/ops/global_avg_pooling_test.cc +++ b/mace/ops/global_avg_pooling_test.cc @@ -4,7 +4,9 @@ #include "mace/core/operator.h" #include "mace/ops/ops_test_util.h" -using namespace mace; +namespace mace { +namespace ops { +namespace test { class GlobalAvgPoolingOpTest : public OpsTestBase {}; @@ -31,3 +33,7 @@ TEST_F(GlobalAvgPoolingOpTest, 3x7x7_CPU) { ExpectTensorNear(*expected, *net.GetOutput("Output"), 0.001); } + +} // namespace test +} // namespace ops +} // namespace mace diff --git a/mace/ops/image_to_buffer.cc b/mace/ops/image_to_buffer.cc index d5031539..6ea1d8db 100644 --- a/mace/ops/image_to_buffer.cc +++ b/mace/ops/image_to_buffer.cc @@ -5,6 +5,7 @@ #include "mace/ops/image_to_buffer.h" namespace mace { +namespace ops { void Register_ImageToBuffer(OperatorRegistry *op_registry) { REGISTER_OPERATOR(op_registry, OpKeyBuilder("ImageToBuffer") @@ -20,4 +21,5 @@ void Register_ImageToBuffer(OperatorRegistry *op_registry) { ImageToBufferOp); } +} // namespace ops } // namespace mace diff --git a/mace/ops/image_to_buffer.h b/mace/ops/image_to_buffer.h index 22169b4e..b786d309 100644 --- a/mace/ops/image_to_buffer.h +++ b/mace/ops/image_to_buffer.h @@ -9,6 +9,7 @@ #include "mace/kernels/buffer_to_image.h" namespace mace { +namespace ops { template class ImageToBufferOp : public Operator { @@ -35,5 +36,7 @@ class ImageToBufferOp : public Operator { OP_OUTPUT_TAGS(OUTPUT); }; +} // namespace ops } // namespace mace + #endif // MACE_OPS_IMAGE_TO_BUFFER_H_ diff --git a/mace/ops/matmul.cc b/mace/ops/matmul.cc index e8a178cb..3ebe99a9 100644 --- a/mace/ops/matmul.cc +++ b/mace/ops/matmul.cc @@ -5,6 +5,7 @@ #include "mace/ops/matmul.h" namespace mace { +namespace ops { void Register_MatMul(OperatorRegistry *op_registry) { REGISTER_OPERATOR(op_registry, OpKeyBuilder("MatMul") @@ -26,4 +27,5 @@ void Register_MatMul(OperatorRegistry *op_registry) { MatMulOp); } +} // namespace ops } // namespace mace diff --git a/mace/ops/matmul.h b/mace/ops/matmul.h index b45ae35a..b8bca6a2 100644 --- a/mace/ops/matmul.h +++ b/mace/ops/matmul.h @@ -9,6 +9,7 @@ #include "mace/kernels/matmul.h" namespace mace { +namespace ops { template class MatMulOp : public Operator { @@ -35,6 +36,7 @@ class MatMulOp : public Operator { kernels::MatMulFunctor functor_; }; +} // namespace ops } // namespace mace #endif // MACE_OPS_MATMUL_H_ diff --git a/mace/ops/matmul_benchmark.cc b/mace/ops/matmul_benchmark.cc index c83b872a..5c136f57 100644 --- a/mace/ops/matmul_benchmark.cc +++ b/mace/ops/matmul_benchmark.cc @@ -3,11 +3,15 @@ // #include + #include "mace/core/operator.h" #include "mace/core/testing/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { +namespace ops { +namespace test { + template static void MatMulBenchmark( int iters, int batch, int height, int channels, int out_width) { @@ -71,4 +75,7 @@ BM_MATMUL(16, 32, 128, 3969); BM_MATMUL(16, 128, 128, 49); BM_MATMUL(16, 128, 128, 961); BM_MATMUL(16, 128, 128, 3969); + +} // namespace test +} // namespace ops } // namespace mace diff --git a/mace/ops/matmul_test.cc b/mace/ops/matmul_test.cc index d8b80ead..237b8f13 100644 --- a/mace/ops/matmul_test.cc +++ b/mace/ops/matmul_test.cc @@ -3,10 +3,13 @@ // #include + #include "mace/core/operator.h" #include "mace/ops/ops_test_util.h" namespace mace { +namespace ops { +namespace test { class MatMulOpTest : public OpsTestBase {}; @@ -170,4 +173,7 @@ TEST_F(MatMulOpTest, OPENCLHalfUnAlignedWithBatch) { Complex(16, 32, 64, 64); Complex(31, 31, 61, 67); } -} + +} // namespace test +} // namespace ops +} // namespace mace diff --git a/mace/ops/ops_test_util.h b/mace/ops/ops_test_util.h index 3003fffe..b782115b 100644 --- a/mace/ops/ops_test_util.h +++ b/mace/ops/ops_test_util.h @@ -2,10 +2,14 @@ // Copyright (c) 2017 XiaoMi All rights reserved. // -#ifndef MACE_OPS_TEST_UTIL_H_ -#define MACE_OPS_TEST_UTIL_H_ +#ifndef MACE_OPS_OPS_TEST_UTIL_H_ +#define MACE_OPS_OPS_TEST_UTIL_H_ #include +#include +#include +#include +#include #include "gtest/gtest.h" #include "mace/core/net.h" @@ -16,6 +20,8 @@ #include "mace/utils/utils.h" namespace mace { +namespace ops { +namespace test { class OpDefBuilder { public: @@ -95,7 +101,7 @@ class OpDefBuilder { class OpsTestNet { public: - OpsTestNet() : op_registry_(new OperatorRegistry()){}; + OpsTestNet() : op_registry_(new OperatorRegistry()) {} template void AddInputFromArray(const std::string &name, @@ -412,6 +418,8 @@ void ImageToBuffer(OpsTestNet &net, net.Sync(); } +} // namespace test +} // namespace ops } // namespace mace -#endif // MACE_OPS_TEST_UTIL_H_ +#endif // MACE_OPS_OPS_TEST_UTIL_H_ diff --git a/mace/ops/pooling.cc b/mace/ops/pooling.cc index f761f545..166a71ad 100644 --- a/mace/ops/pooling.cc +++ b/mace/ops/pooling.cc @@ -5,6 +5,7 @@ #include "mace/ops/pooling.h" namespace mace { +namespace ops { void Register_Pooling(OperatorRegistry *op_registry) { REGISTER_OPERATOR(op_registry, OpKeyBuilder("Pooling") @@ -30,4 +31,5 @@ void Register_Pooling(OperatorRegistry *op_registry) { PoolingOp); } +} // namespace ops } // namespace mace diff --git a/mace/ops/pooling.h b/mace/ops/pooling.h index b88093ab..1033ad6e 100644 --- a/mace/ops/pooling.h +++ b/mace/ops/pooling.h @@ -5,11 +5,14 @@ #ifndef MACE_OPS_POOLING_H_ #define MACE_OPS_POOLING_H_ +#include + #include "mace/core/operator.h" #include "mace/kernels/pooling.h" #include "mace/ops/conv_pool_2d_base.h" namespace mace { +namespace ops { template class PoolingOp : public ConvPool2dOpBase { @@ -25,7 +28,7 @@ class PoolingOp : public ConvPool2dOpBase { this->strides_.data(), this->padding_type_, this->paddings_, - this->dilations_.data()){}; + this->dilations_.data()) {} bool Run(StatsFuture *future) override { const Tensor *input = this->Input(INPUT); @@ -44,6 +47,7 @@ class PoolingOp : public ConvPool2dOpBase { OP_OUTPUT_TAGS(OUTPUT); }; +} // namespace ops } // namespace mace #endif // MACE_OPS_POOLING_H_ diff --git a/mace/ops/pooling_benchmark.cc b/mace/ops/pooling_benchmark.cc index dae7e1af..af6688ab 100644 --- a/mace/ops/pooling_benchmark.cc +++ b/mace/ops/pooling_benchmark.cc @@ -8,8 +8,9 @@ #include "mace/kernels/conv_pool_2d_util.h" #include "mace/ops/ops_test_util.h" -using namespace mace; -using namespace mace::kernels; +namespace mace { +namespace ops { +namespace test { template static void Pooling(int iters, @@ -70,3 +71,7 @@ BM_POOLING(1, 3, 129, 129, 2, 2, SAME, MAX); BM_POOLING(1, 3, 257, 257, 2, 2, SAME, MAX); BM_POOLING(1, 3, 513, 513, 2, 2, SAME, MAX); BM_POOLING(1, 3, 1025, 1025, 2, 2, SAME, MAX); + +} // namespace test +} // namespace ops +} // namespace mace diff --git a/mace/ops/pooling_test.cc b/mace/ops/pooling_test.cc index 8bababc8..e57e5716 100644 --- a/mace/ops/pooling_test.cc +++ b/mace/ops/pooling_test.cc @@ -9,7 +9,9 @@ #include "mace/ops/conv_pool_2d_base.h" #include "mace/ops/ops_test_util.h" -using namespace mace; +namespace mace { +namespace ops { +namespace test { class PoolingOpTest : public OpsTestBase {}; @@ -393,3 +395,7 @@ TEST_F(PoolingOpTest, OPENCLUnAlignedLargeKernelAvgPooling) { AvgPoolingTest({3, 31, 37, 128}, {8, 8}, {8, 8}, Padding::SAME); } + +} // namespace test +} // namespace ops +} // namespace mace diff --git a/mace/ops/reshape.cc b/mace/ops/reshape.cc index df528603..26dff665 100644 --- a/mace/ops/reshape.cc +++ b/mace/ops/reshape.cc @@ -5,6 +5,7 @@ #include "mace/ops/reshape.h" namespace mace { +namespace ops { void Register_Reshape(OperatorRegistry *op_registry) { REGISTER_OPERATOR(op_registry, OpKeyBuilder("Reshape") @@ -14,4 +15,5 @@ void Register_Reshape(OperatorRegistry *op_registry) { ReshapeOp); } +} // namespace ops } // namespace mace diff --git a/mace/ops/reshape.h b/mace/ops/reshape.h index a4aec715..e7f1a80a 100644 --- a/mace/ops/reshape.h +++ b/mace/ops/reshape.h @@ -5,10 +5,13 @@ #ifndef MACE_OPS_RESHAPE_H_ #define MACE_OPS_RESHAPE_H_ +#include + #include "mace/core/operator.h" #include "mace/kernels/reshape.h" namespace mace { +namespace ops { template class ReshapeOp : public Operator { @@ -61,6 +64,7 @@ class ReshapeOp : public Operator { OP_OUTPUT_TAGS(OUTPUT); }; +} // namespace ops } // namespace mace #endif // MACE_OPS_RESHAPE_H_ diff --git a/mace/ops/reshape_test.cc b/mace/ops/reshape_test.cc index 851f33cc..e8c363a6 100644 --- a/mace/ops/reshape_test.cc +++ b/mace/ops/reshape_test.cc @@ -6,7 +6,9 @@ #include "mace/core/operator.h" #include "mace/ops/ops_test_util.h" -using namespace mace; +namespace mace { +namespace ops { +namespace test { class ReshapeTest : public OpsTestBase {}; @@ -53,3 +55,7 @@ TEST_F(ReshapeTest, Complex) { TestReshape({1, 2, 3, 4}, {-1, 1}, {24, 1}); TestReshape({1, 2, 3, 4}, {1, 3, 8}, {1, 3, 8}); } + +} // namespace test +} // namespace ops +} // namespace mace diff --git a/mace/ops/resize_bilinear.cc b/mace/ops/resize_bilinear.cc index d304c24c..a7449a3c 100644 --- a/mace/ops/resize_bilinear.cc +++ b/mace/ops/resize_bilinear.cc @@ -5,6 +5,7 @@ #include "mace/ops/resize_bilinear.h" namespace mace { +namespace ops { void Register_ResizeBilinear(OperatorRegistry *op_registry) { REGISTER_OPERATOR(op_registry, OpKeyBuilder("ResizeBilinear") @@ -26,4 +27,5 @@ void Register_ResizeBilinear(OperatorRegistry *op_registry) { ResizeBilinearOp); } +} // namespace ops } // namespace mace diff --git a/mace/ops/resize_bilinear.h b/mace/ops/resize_bilinear.h index bea852b5..1fc72748 100644 --- a/mace/ops/resize_bilinear.h +++ b/mace/ops/resize_bilinear.h @@ -2,13 +2,14 @@ // Copyright (c) 2017 XiaoMi All rights reserved. // -#ifndef MACE_RESIZE_BILINEAR_H -#define MACE_RESIZE_BILINEAR_H +#ifndef MACE_OPS_RESIZE_BILINEAR_H_ +#define MACE_OPS_RESIZE_BILINEAR_H_ #include "mace/core/operator.h" #include "mace/kernels/resize_bilinear.h" namespace mace { +namespace ops { template class ResizeBilinearOp : public Operator { @@ -34,6 +35,7 @@ class ResizeBilinearOp : public Operator { kernels::ResizeBilinearFunctor functor_; }; +} // namespace ops } // namespace mace -#endif // MACE_RESIZE_BILINEAR_H +#endif // MACE_OPS_RESIZE_BILINEAR_H_ diff --git a/mace/ops/resize_bilinear_benchmark.cc b/mace/ops/resize_bilinear_benchmark.cc index 9daee298..6e19a000 100644 --- a/mace/ops/resize_bilinear_benchmark.cc +++ b/mace/ops/resize_bilinear_benchmark.cc @@ -8,6 +8,9 @@ #include "mace/ops/ops_test_util.h" namespace mace { +namespace ops { +namespace test { + template static void ResizeBilinearBenchmark(int iters, int batch, @@ -84,4 +87,6 @@ BM_RESIZE_BILINEAR(1, 128, 240, 240, 480, 480); BM_RESIZE_BILINEAR(1, 3, 4032, 3016, 480, 480); BM_RESIZE_BILINEAR(1, 3, 480, 480, 4032, 3016); +} // namespace test +} // namespace ops } // namespace mace diff --git a/mace/ops/resize_bilinear_test.cc b/mace/ops/resize_bilinear_test.cc index 1b3bf618..ae87a2f8 100644 --- a/mace/ops/resize_bilinear_test.cc +++ b/mace/ops/resize_bilinear_test.cc @@ -2,11 +2,15 @@ // Copyright (c) 2017 XiaoMi All rights reserved. // -#include "mace/ops/resize_bilinear.h" +#include + #include "mace/core/operator.h" +#include "mace/ops/resize_bilinear.h" #include "mace/ops/ops_test_util.h" -using namespace mace; +namespace mace { +namespace ops { +namespace test { class ResizeBilinearTest : public OpsTestBase {}; @@ -61,17 +65,17 @@ TEST_F(ResizeBilinearTest, ResizeBilinearWAlignCorners) { template void TestRandomResizeBilinear() { - srand(time(nullptr)); + // srand(time(nullptr)); testing::internal::LogToStderr(); - + static unsigned int seed = 123; for (int round = 0; round < 10; ++round) { - int batch = 1 + rand() % 5; - int channels = 1 + rand() % 100; - int height = 1 + rand() % 100; - int width = 1 + rand() % 100; - int in_height = 1 + rand() % 100; - int in_width = 1 + rand() % 100; - int align_corners = rand() % 1; + int batch = 1 + rand_r(&seed) % 5; + int channels = 1 + rand_r(&seed) % 100; + int height = 1 + rand_r(&seed) % 100; + int width = 1 + rand_r(&seed) % 100; + int in_height = 1 + rand_r(&seed) % 100; + int in_width = 1 + rand_r(&seed) % 100; + int align_corners = rand_r(&seed) % 1; // Construct graph OpsTestNet net; @@ -106,7 +110,7 @@ void TestRandomResizeBilinear() { ImageToBuffer(net, "OutputImage", "DeviceOutput", kernels::BufferType::IN_OUT_CHANNEL); } else { - // TODO support NEON + // TODO(someone): support NEON } // Check ExpectTensorNear(expected, *net.GetOutput("DeviceOutput"), 0.001); @@ -122,3 +126,7 @@ TEST_F(ResizeBilinearTest, NEONRandomResizeBilinear) { TEST_F(ResizeBilinearTest, OPENCLRandomResizeBilinear) { TestRandomResizeBilinear(); } + +} // namespace test +} // namespace ops +} // namespace mace diff --git a/mace/ops/slice.cc b/mace/ops/slice.cc index 6de3da40..d482b028 100644 --- a/mace/ops/slice.cc +++ b/mace/ops/slice.cc @@ -5,6 +5,7 @@ #include "mace/ops/slice.h" namespace mace { +namespace ops { void Register_Slice(OperatorRegistry *op_registry) { REGISTER_OPERATOR(op_registry, OpKeyBuilder("Slice") @@ -25,4 +26,5 @@ void Register_Slice(OperatorRegistry *op_registry) { SliceOp); } +} // namespace ops } // namespace mace diff --git a/mace/ops/slice.h b/mace/ops/slice.h index 41106a63..466914f3 100644 --- a/mace/ops/slice.h +++ b/mace/ops/slice.h @@ -5,9 +5,13 @@ #ifndef MACE_OPS_SLICE_H_ #define MACE_OPS_SLICE_H_ +#include + #include "mace/core/operator.h" #include "mace/kernels/slice.h" + namespace mace { +namespace ops { template class SliceOp : public Operator { @@ -32,6 +36,7 @@ class SliceOp : public Operator { OP_INPUT_TAGS(INPUT); }; +} // namespace ops } // namespace mace #endif // MACE_OPS_SLICE_H_ diff --git a/mace/ops/slice_benchmark.cc b/mace/ops/slice_benchmark.cc index 5273f592..a0aeb90a 100644 --- a/mace/ops/slice_benchmark.cc +++ b/mace/ops/slice_benchmark.cc @@ -7,6 +7,9 @@ #include "mace/ops/ops_test_util.h" namespace mace { +namespace ops { +namespace test { + template static void BMSliceHelper(int iters, const std::vector &input_shape, @@ -75,5 +78,6 @@ BM_SLICE(1, 32, 32, 256, 2); BM_SLICE(1, 128, 128, 32, 2); BM_SLICE(1, 128, 128, 128, 2); - +} // namespace test +} // namespace ops } // namespace mace diff --git a/mace/ops/slice_test.cc b/mace/ops/slice_test.cc index ff65fffa..0958ed95 100644 --- a/mace/ops/slice_test.cc +++ b/mace/ops/slice_test.cc @@ -2,22 +2,27 @@ // Copyright (c) 2017 XiaoMi All rights reserved. // +#include + +#include "gmock/gmock.h" #include "mace/ops/slice.h" #include "mace/ops/ops_test_util.h" -#include "gmock/gmock.h" -using namespace mace; +namespace mace { +namespace ops { +namespace test { class SliceOpTest : public OpsTestBase {}; template void RandomTest(const int num_outputs) { - srand(time(nullptr)); - const index_t output_channels = 4 * (1 + rand() % 10); + // srand(time(nullptr)); + static unsigned int seed = 123; + const index_t output_channels = 4 * (1 + rand_r(&seed) % 10); const index_t input_channels = num_outputs * output_channels; - const index_t batch = 3 + (rand() % 10); - const index_t height = 13 + (rand() % 10); - const index_t width = 17 + (rand() % 10); + const index_t batch = 3 + (rand_r(&seed) % 10); + const index_t height = 13 + (rand_r(&seed) % 10); + const index_t width = 17 + (rand_r(&seed) % 10); // Construct graph OpsTestNet net; @@ -47,7 +52,6 @@ void RandomTest(const int num_outputs) { builder = builder.Output(MakeString("Output", i)); } builder.Finalize(net.NewOperatorDef()); - } // Run @@ -97,3 +101,7 @@ TEST_F(SliceOpTest, OPENCLHalf) { RandomTest(4); RandomTest(11); } + +} // namespace test +} // namespace ops +} // namespace mace diff --git a/mace/ops/softmax.cc b/mace/ops/softmax.cc index 7b68e762..6b8ead81 100644 --- a/mace/ops/softmax.cc +++ b/mace/ops/softmax.cc @@ -5,6 +5,7 @@ #include "mace/ops/softmax.h" namespace mace { +namespace ops { void Register_Softmax(OperatorRegistry *op_registry) { REGISTER_OPERATOR(op_registry, OpKeyBuilder("Softmax") @@ -26,4 +27,5 @@ void Register_Softmax(OperatorRegistry *op_registry) { SoftmaxOp); } +} // namespace ops } // namespace mace diff --git a/mace/ops/softmax.h b/mace/ops/softmax.h index 3eebabe0..0aedaa3c 100644 --- a/mace/ops/softmax.h +++ b/mace/ops/softmax.h @@ -2,13 +2,14 @@ // Copyright (c) 2017 XiaoMi All rights reserved. // -#ifndef MACE_SOFTMAX_H_ -#define MACE_SOFTMAX_H_ +#ifndef MACE_OPS_SOFTMAX_H_ +#define MACE_OPS_SOFTMAX_H_ #include "mace/core/operator.h" #include "mace/kernels/softmax.h" namespace mace { +namespace ops { template class SoftmaxOp : public Operator { @@ -34,6 +35,7 @@ class SoftmaxOp : public Operator { OP_OUTPUT_TAGS(OUTPUT); }; +} // namespace ops } // namespace mace -#endif // MACE_SOFTMAX_H_ +#endif // MACE_OPS_SOFTMAX_H_ diff --git a/mace/ops/softmax_benchmark.cc b/mace/ops/softmax_benchmark.cc index 4f2e8ce8..bd40f4f7 100644 --- a/mace/ops/softmax_benchmark.cc +++ b/mace/ops/softmax_benchmark.cc @@ -3,11 +3,15 @@ // #include + #include "mace/core/operator.h" #include "mace/core/testing/test_benchmark.h" #include "mace/ops/ops_test_util.h" namespace mace { +namespace ops { +namespace test { + template static void SoftmaxBenchmark( int iters, int batch, int channels, int height, int width) { @@ -66,4 +70,7 @@ BM_SOFTMAX(1, 3, 512, 512); BM_SOFTMAX(1, 4, 512, 512); BM_SOFTMAX(1, 10, 256, 256); BM_SOFTMAX(1, 1024, 7, 7); + +} // namespace test +} // namespace ops } // namespace mace diff --git a/mace/ops/softmax_test.cc b/mace/ops/softmax_test.cc index 68c4e4e6..b53b9465 100644 --- a/mace/ops/softmax_test.cc +++ b/mace/ops/softmax_test.cc @@ -6,6 +6,8 @@ #include "mace/ops/ops_test_util.h" namespace mace { +namespace ops { +namespace test { class SoftmaxOpTest : public OpsTestBase {}; @@ -102,4 +104,6 @@ TEST_F(SoftmaxOpTest, OPENCLUnAligned) { Complex({5, 211, 107, 1}); } +} // namespace test +} // namespace ops } // namespace mace diff --git a/mace/ops/space_to_batch.cc b/mace/ops/space_to_batch.cc index 89957f67..009f4abe 100644 --- a/mace/ops/space_to_batch.cc +++ b/mace/ops/space_to_batch.cc @@ -5,6 +5,7 @@ #include "mace/ops/space_to_batch.h" namespace mace { +namespace ops { void Register_SpaceToBatchND(OperatorRegistry *op_registry) { REGISTER_OPERATOR(op_registry, OpKeyBuilder("SpaceToBatchND") @@ -19,4 +20,5 @@ void Register_SpaceToBatchND(OperatorRegistry *op_registry) { SpaceToBatchNDOp); } +} // namespace ops } // namespace mace diff --git a/mace/ops/space_to_batch.h b/mace/ops/space_to_batch.h index b25c5895..dd051fa9 100644 --- a/mace/ops/space_to_batch.h +++ b/mace/ops/space_to_batch.h @@ -6,11 +6,13 @@ #define MACE_OPS_SPACE_TO_BATCH_H_ #include +#include #include "mace/core/operator.h" #include "mace/kernels/space_to_batch.h" namespace mace { +namespace ops { template class SpaceToBatchNDOp : public Operator { @@ -71,6 +73,7 @@ class SpaceToBatchNDOp : public Operator { OP_OUTPUT_TAGS(OUTPUT); }; +} // namespace ops } // namespace mace #endif // MACE_OPS_SPACE_TO_BATCH_H_ diff --git a/mace/ops/space_to_batch_benchmark.cc b/mace/ops/space_to_batch_benchmark.cc index db72ce54..f00409b5 100644 --- a/mace/ops/space_to_batch_benchmark.cc +++ b/mace/ops/space_to_batch_benchmark.cc @@ -7,6 +7,9 @@ #include "mace/ops/ops_test_util.h" namespace mace { +namespace ops { +namespace test { + template static void BMSpaceToBatch( int iters, int batch, int height, int width, int channels, int shape) { @@ -55,4 +58,7 @@ static void BMSpaceToBatch( BM_SPACE_TO_BATCH(128, 16, 16, 128, 2); BM_SPACE_TO_BATCH(1, 256, 256, 32, 2); BM_SPACE_TO_BATCH(1, 256, 256, 32, 4); + +} // namespace test +} // namespace ops } // namespace mace diff --git a/mace/ops/space_to_batch_test.cc b/mace/ops/space_to_batch_test.cc index b9cb14f6..588483b5 100644 --- a/mace/ops/space_to_batch_test.cc +++ b/mace/ops/space_to_batch_test.cc @@ -3,10 +3,13 @@ // #include + #include "gtest/gtest.h" #include "mace/ops/ops_test_util.h" -using namespace mace; +namespace mace { +namespace ops { +namespace test { template void RunSpaceToBatch(const std::vector &input_shape, @@ -216,3 +219,7 @@ TEST(SpaceToBatchTest, MultiBatchAndChannelData) { // {2, 2, 2, 2}, // space_tensor.get()); //} + +} // namespace test +} // namespace ops +} // namespace mace diff --git a/mace/ops/winograd_convolution_test.cc b/mace/ops/winograd_convolution_test.cc index 41e8478a..6c96f0cc 100644 --- a/mace/ops/winograd_convolution_test.cc +++ b/mace/ops/winograd_convolution_test.cc @@ -3,11 +3,14 @@ // #include + #include "mace/core/operator.h" #include "mace/kernels/conv_pool_2d_util.h" #include "mace/ops/ops_test_util.h" namespace mace { +namespace ops { +namespace test { class WinogradConvlutionTest : public OpsTestBase {}; @@ -39,7 +42,7 @@ void WinogradConvolution(const index_t batch, const index_t in_channels, const index_t out_channels, const Padding padding) { - srand(time(NULL)); + // srand(time(NULL)); // Construct graph OpsTestNet net; @@ -156,7 +159,7 @@ void WinogradConvolutionWithPad(const index_t batch, const index_t in_channels, const index_t out_channels, const int padding) { - srand(time(NULL)); + // srand(time(NULL)); // Construct graph OpsTestNet net; @@ -245,9 +248,6 @@ void WinogradConvolutionWithPad(const index_t batch, } } -TEST_F(WinogradConvlutionTest, UnAlignedConvolutionPad2) { - WinogradConvolutionWithPad(1, 64, 64, 40, 19, 2); - WinogradConvolutionWithPad(1, 32, 32, 96, 109, 2); -} - -} +} // namespace test +} // namespace ops +} // namespace mace diff --git a/mace/ops/winograd_inverse_transform.cc b/mace/ops/winograd_inverse_transform.cc index 677fe3e7..47d1148b 100644 --- a/mace/ops/winograd_inverse_transform.cc +++ b/mace/ops/winograd_inverse_transform.cc @@ -5,6 +5,7 @@ #include "mace/ops/winograd_inverse_transform.h" namespace mace { +namespace ops { void Register_WinogradInverseTransform(OperatorRegistry *op_registry) { REGISTER_OPERATOR(op_registry, OpKeyBuilder("WinogradInverseTransform") @@ -19,4 +20,5 @@ void Register_WinogradInverseTransform(OperatorRegistry *op_registry) { WinogradInverseTransformOp); } +} // namespace ops } // namespace mace diff --git a/mace/ops/winograd_inverse_transform.h b/mace/ops/winograd_inverse_transform.h index 4ea49289..55be83b7 100644 --- a/mace/ops/winograd_inverse_transform.h +++ b/mace/ops/winograd_inverse_transform.h @@ -6,12 +6,14 @@ #define MACE_OPS_WINOGRAD_INVERSE_TRANSFORM_H_ #include +#include #include "mace/core/operator.h" #include "mace/kernels/activation.h" #include "mace/kernels/winograd_transform.h" namespace mace { +namespace ops { template class WinogradInverseTransformOp : public Operator { @@ -42,6 +44,7 @@ class WinogradInverseTransformOp : public Operator { OP_OUTPUT_TAGS(OUTPUT); }; +} // namespace ops } // namespace mace #endif // MACE_OPS_WINOGRAD_INVERSE_TRANSFORM_H_ diff --git a/mace/ops/winograd_transform.cc b/mace/ops/winograd_transform.cc index e7cd8688..f8aa4f62 100644 --- a/mace/ops/winograd_transform.cc +++ b/mace/ops/winograd_transform.cc @@ -5,6 +5,7 @@ #include "mace/ops/winograd_transform.h" namespace mace { +namespace ops { void Register_WinogradTransform(OperatorRegistry *op_registry) { REGISTER_OPERATOR(op_registry, OpKeyBuilder("WinogradTransform") @@ -19,4 +20,5 @@ void Register_WinogradTransform(OperatorRegistry *op_registry) { WinogradTransformOp); } +} // namespace ops } // namespace mace diff --git a/mace/ops/winograd_transform.h b/mace/ops/winograd_transform.h index e225adc7..c9476fc8 100644 --- a/mace/ops/winograd_transform.h +++ b/mace/ops/winograd_transform.h @@ -11,6 +11,7 @@ #include "mace/kernels/winograd_transform.h" namespace mace { +namespace ops { template class WinogradTransformOp : public Operator { @@ -37,6 +38,7 @@ class WinogradTransformOp : public Operator { OP_OUTPUT_TAGS(OUTPUT); }; +} // namespace ops } // namespace mace #endif // MACE_OPS_WINOGRAD_TRANSFORM_H_ diff --git a/mace/ops/winograd_transform_benchmark.cc b/mace/ops/winograd_transform_benchmark.cc index 23f7249b..bb20d186 100644 --- a/mace/ops/winograd_transform_benchmark.cc +++ b/mace/ops/winograd_transform_benchmark.cc @@ -7,6 +7,9 @@ #include "mace/ops/ops_test_util.h" namespace mace { +namespace ops { +namespace test { + template static void BMWinogradTransform( int iters, int batch, int height, int width, int channels) { @@ -105,4 +108,6 @@ BM_WINOGRAD_INVERSE_TRANSFORM(1, 14, 14, 32); BM_WINOGRAD_INVERSE_TRANSFORM(1, 62, 62, 32); BM_WINOGRAD_INVERSE_TRANSFORM(1, 126, 126, 32); +} // namespace test +} // namespace ops } // namespace mace -- GitLab