From 2371ab46a1212d8a7d1356ae0a11dbe7455b3fe8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EA=B9=80=EC=A0=95=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Senior=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Tue, 15 May 2018 16:49:16 +0900 Subject: [PATCH] Apply .FORMATCHECKED to libs (#1215) This commit applies format checker to directory `libs`. Signed-off-by: Junghyun Kim --- libs/.FORMATCHECKED | 0 libs/kernel/acl/src/DepthwiseConv2D.h | 46 ++-- libs/kernel/acl/src/DepthwiseConv2D.test.h | 107 +++------ libs/kernel/acl/src/FullyConnected.h | 51 +++-- libs/kernel/acl/src/FullyConnected.test.h | 187 ++++++--------- libs/kernel/acl/src/IO_accessor.cpp | 137 +++++------ libs/kernel/acl/src/IO_accessor.h | 139 ++++++------ libs/kernel/acl/src/Init_acl.cpp | 14 +- libs/kernel/acl/src/Reshape.h | 26 ++- libs/kernel/acl/src/Reshape.test.h | 11 +- libs/kernel/acl/src/UniqueTensor.h | 27 +-- libs/kernel/acl/src/cl/Concatenation.cpp | 29 +-- libs/kernel/acl/src/cl/Concatenation.test.cpp | 20 +- libs/kernel/acl/src/cl/Conv2D.cpp | 36 +-- libs/kernel/acl/src/cl/Conv2D.test.cpp | 122 ++++------ libs/kernel/acl/src/cl/DepthwiseConv2D.cpp | 47 ++-- libs/kernel/acl/src/cl/FullyConnected.cpp | 33 ++- libs/kernel/acl/src/cl/Pooling.cpp | 67 +++--- libs/kernel/acl/src/cl/Pooling.test.cpp | 275 ++++++++--------------- libs/kernel/acl/src/cl/Reshape.cpp | 22 +- libs/kernel/acl/src/cl/Softmax.cpp | 14 +- libs/kernel/acl/src/cl/Softmax.test.cpp | 20 +- libs/kernel/acl/src/gtest_env.cpp | 9 +- libs/kernel/acl/src/neon/Concatenation.cpp | 34 +-- libs/kernel/acl/src/neon/Concatenation.test.cpp | 20 +- libs/kernel/acl/src/neon/Conv2D.cpp | 41 ++-- libs/kernel/acl/src/neon/Conv2D.test.cpp | 122 ++++------ libs/kernel/acl/src/neon/DepthwiseConv2D.cpp | 44 ++-- libs/kernel/acl/src/neon/FullyConnected.cpp | 36 +-- libs/kernel/acl/src/neon/FullyConnected.test.cpp | 1 - libs/kernel/acl/src/neon/Pooling.cpp | 70 +++--- libs/kernel/acl/src/neon/Pooling.test.cpp | 250 +++++++-------------- libs/kernel/acl/src/neon/Reshape.cpp | 32 +-- libs/kernel/acl/src/neon/Softmax.cpp | 17 +- libs/kernel/acl/src/neon/Softmax.test.cpp | 20 +- libs/kernel/acl/src/shape.cpp | 42 ++-- libs/kernel/acl/src/shape.h | 65 +++--- libs/kernel/acl/src/support.cpp | 2 +- libs/kernel/acl/src/support.h | 9 +- libs/kernel/acl/src/util.cpp | 78 ++++--- libs/kernel/acl/src/util.h | 139 +++++++----- libs/support/tflite/src/Diff.cpp | 60 ++--- libs/support/tflite/src/TensorView.cpp | 3 +- libs/support/tflite/src/TensorView.test.cpp | 2 +- libs/util/examples/tensor_index_iterator.cpp | 3 +- libs/util/include/util/benchmark.h | 5 +- libs/util/include/util/environment.h | 5 +- libs/util/include/util/feature/Index.h | 2 +- libs/util/include/util/feature/Object.h | 4 +- libs/util/include/util/feature/Shape.h | 1 - libs/util/include/util/feature/TextFormatter.h | 6 +- libs/util/include/util/kernel/RandomObject.h | 2 +- libs/util/include/util/tensor/Index.h | 5 +- libs/util/include/util/tensor/Object.h | 15 +- libs/util/include/util/tensor/Shape.h | 5 +- libs/util/include/util/tensor/Zipper.h | 13 +- libs/util/include/util/vector.h | 3 +- libs/util/include/util/vector/Object.h | 4 +- libs/util/src/environment.cpp | 4 +- libs/util/src/tensor/Shape.cpp | 2 +- 60 files changed, 1143 insertions(+), 1462 deletions(-) create mode 100644 libs/.FORMATCHECKED diff --git a/libs/.FORMATCHECKED b/libs/.FORMATCHECKED new file mode 100644 index 0000000..e69de29 diff --git a/libs/kernel/acl/src/DepthwiseConv2D.h b/libs/kernel/acl/src/DepthwiseConv2D.h index 8af8d4f..0aa5ee6 100644 --- a/libs/kernel/acl/src/DepthwiseConv2D.h +++ b/libs/kernel/acl/src/DepthwiseConv2D.h @@ -25,24 +25,27 @@ #include "shape.h" #include "IO_accessor.h" -namespace nnfw { -namespace kernel { -namespace acl { - -namespace common { - -typedef std::function sync_scheduler_f; - -template -bool depthwiseConvFloat32(const float* inputData, const nnfw::rt::Shape& inputShape, - const float* filterData, const nnfw::rt::Shape& filterShape, - const float* biasData, const nnfw::rt::Shape& biasShape, - int32_t padding_left, int32_t padding_right, - int32_t padding_top, int32_t padding_bottom, - int32_t stride_width, int32_t stride_height, - int32_t depth_multiplier, int32_t activation, - float* outputData, const nnfw::rt::Shape& outputShape, - sync_scheduler_f sync_scheduler) { +namespace nnfw +{ +namespace kernel +{ +namespace acl +{ + +namespace common +{ + +typedef std::function sync_scheduler_f; + +template +bool depthwiseConvFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, + const float *filterData, const nnfw::rt::Shape &filterShape, + const float *biasData, const nnfw::rt::Shape &biasShape, + int32_t padding_left, int32_t padding_right, int32_t padding_top, + int32_t padding_bottom, int32_t stride_width, int32_t stride_height, + int32_t depth_multiplier, int32_t activation, float *outputData, + const nnfw::rt::Shape &outputShape, sync_scheduler_f sync_scheduler) +{ auto inputShapeACL = util::fromNNShape(inputShape); auto weightsShapeACL = util::fromNNShape(filterShape); auto biasShapeACL = util::fromNNShape(biasShape); @@ -53,10 +56,9 @@ bool depthwiseConvFloat32(const float* inputData, const nnfw::rt::Shape& inputSh TensorT bias(arm_compute::TensorInfo(biasShapeACL, arm_compute::Format::F32)); TensorT output(arm_compute::TensorInfo(outputShapeACL, arm_compute::Format::F32)); - arm_compute::PadStrideInfo psinfo = arm_compute::PadStrideInfo(stride_width, stride_height, - padding_left, padding_right, - padding_top, padding_bottom, - arm_compute::DimensionRoundingType::FLOOR); + arm_compute::PadStrideInfo psinfo = arm_compute::PadStrideInfo( + stride_width, stride_height, padding_left, padding_right, padding_top, padding_bottom, + arm_compute::DimensionRoundingType::FLOOR); auto l = std::make_shared(); l->configure(input.ptr(), weights.ptr(), bias.ptr(), output.ptr(), psinfo); diff --git a/libs/kernel/acl/src/DepthwiseConv2D.test.h b/libs/kernel/acl/src/DepthwiseConv2D.test.h index b2c8592..b459cd7 100644 --- a/libs/kernel/acl/src/DepthwiseConv2D.test.h +++ b/libs/kernel/acl/src/DepthwiseConv2D.test.h @@ -32,7 +32,8 @@ using namespace nnfw::kernel::acl; -ACL_TEST(KernelACL_TC, dwise_conv2d_1) { +ACL_TEST(KernelACL_TC, dwise_conv2d_1) +{ uint32_t input_n = 1; uint32_t input_h = 3; uint32_t input_w = 3; @@ -64,7 +65,7 @@ ACL_TEST(KernelACL_TC, dwise_conv2d_1) { uint32_t W = input_w; uint32_t C = input_c; - return n*H*W*C + h*W*C + w*C + c; + return n * H * W * C + h * W * C + w * C + c; }); weights.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { uint32_t N = 1; @@ -72,35 +73,26 @@ ACL_TEST(KernelACL_TC, dwise_conv2d_1) { uint32_t W = filter_w; uint32_t C = filter_c; - return n*H*W*C + h*W*C + w*C + c; - }); - bias.initValue([](uint32_t w) { - return 0.f; - }); - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 0.f; + return n * H * W * C + h * W * C + w * C + c; }); + bias.initValue([](uint32_t w) { return 0.f; }); + output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); - bool bret = ACL_CORE_FUNC_NAME(input.ptr(), input.shape(), - weights.ptr(), weights.shape(), - bias.ptr(), bias.shape(), - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - depth_multiplier, activation, - output.ptr(), output.shape()); + bool bret = ACL_CORE_FUNC_NAME( + input.ptr(), input.shape(), weights.ptr(), weights.shape(), bias.ptr(), + bias.shape(), padding_left, padding_right, padding_top, padding_bottom, stride_width, + stride_height, depth_multiplier, activation, output.ptr(), output.shape()); EXPECT_EQ(bret, true); util::TensorWrapper expected({1, out_h, out_w, filter_c}); - expected.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 204.f; - }); + expected.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 204.f; }); EXPECT_EQ(output, expected); } -ACL_TEST(KernelACL_TC, dwise_conv2d_multi_channel) { +ACL_TEST(KernelACL_TC, dwise_conv2d_multi_channel) +{ uint32_t input_n = 1; uint32_t input_h = 3; uint32_t input_w = 3; @@ -132,7 +124,7 @@ ACL_TEST(KernelACL_TC, dwise_conv2d_multi_channel) { uint32_t W = input_w; uint32_t C = input_c; - return n*H*W*C + h*W*C + w*C + c; + return n * H * W * C + h * W * C + w * C + c; }); weights.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { uint32_t N = 1; @@ -140,37 +132,26 @@ ACL_TEST(KernelACL_TC, dwise_conv2d_multi_channel) { uint32_t W = filter_w; uint32_t C = filter_c; - return n*H*W*C + h*W*C + w*C + c; - }); - bias.initValue([](uint32_t w) { - return 0.f; - }); - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 0.f; + return n * H * W * C + h * W * C + w * C + c; }); + bias.initValue([](uint32_t w) { return 0.f; }); + output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); - bool bret = ACL_CORE_FUNC_NAME(input.ptr(), input.shape(), - weights.ptr(), weights.shape(), - bias.ptr(), bias.shape(), - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - depth_multiplier, activation, - output.ptr(), output.shape()); + bool bret = ACL_CORE_FUNC_NAME( + input.ptr(), input.shape(), weights.ptr(), weights.shape(), bias.ptr(), + bias.shape(), padding_left, padding_right, padding_top, padding_bottom, stride_width, + stride_height, depth_multiplier, activation, output.ptr(), output.shape()); EXPECT_EQ(bret, true); util::TensorWrapper expected({1, out_h, out_w, filter_c}); - expected.initValue({ - 1836.f, - 2061.f, - 2304.f - }); + expected.initValue({1836.f, 2061.f, 2304.f}); EXPECT_EQ(output, expected); } -ACL_TEST(KernelACL_TC, dwise_conv2d_inception_1) { +ACL_TEST(KernelACL_TC, dwise_conv2d_inception_1) +{ uint32_t input_n = 1; uint32_t input_h = 112; uint32_t input_w = 112; @@ -196,48 +177,34 @@ ACL_TEST(KernelACL_TC, dwise_conv2d_inception_1) { int32_t activation = static_cast(FusedActivationFunc::RELU6); - input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return c; - }); - weights.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return c; - }); - bias.initValue([](uint32_t w) { - return 0.f; - }); - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 0.f; - }); + input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return c; }); + weights.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return c; }); + bias.initValue([](uint32_t w) { return 0.f; }); + output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); - bool bret = ACL_CORE_FUNC_NAME(input.ptr(), input.shape(), - weights.ptr(), weights.shape(), - bias.ptr(), bias.shape(), - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - depth_multiplier, activation, - output.ptr(), output.shape()); + bool bret = ACL_CORE_FUNC_NAME( + input.ptr(), input.shape(), weights.ptr(), weights.shape(), bias.ptr(), + bias.shape(), padding_left, padding_right, padding_top, padding_bottom, stride_width, + stride_height, depth_multiplier, activation, output.ptr(), output.shape()); EXPECT_EQ(bret, true); util::TensorWrapper expected({1, out_h, out_w, filter_c}); expected.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { float v = 9.f; - if( h == 0 || h == out_h-1 ) + if (h == 0 || h == out_h - 1) v -= 3.f; - if( w == 0 || w == out_w-1 ) + if (w == 0 || w == out_w - 1) v -= 3.f; // four corners - if( (w == 0 && h == 0) - || (w == 0 && h == out_h-1) - || (w == out_w-1 && h == 0) - || (w == out_w-1 && h == out_h-1) ) + if ((w == 0 && h == 0) || (w == 0 && h == out_h - 1) || (w == out_w - 1 && h == 0) || + (w == out_w - 1 && h == out_h - 1)) v += 1.f; // Assumption: negative numbers cannot appear because // only positive numbers exist in the input and weights. - float ret = c*c*v; + float ret = c * c * v; return std::min(ret, 6.f); }); diff --git a/libs/kernel/acl/src/FullyConnected.h b/libs/kernel/acl/src/FullyConnected.h index 5030a85..f04f91a 100644 --- a/libs/kernel/acl/src/FullyConnected.h +++ b/libs/kernel/acl/src/FullyConnected.h @@ -25,56 +25,62 @@ #include "shape.h" #include "IO_accessor.h" -namespace nnfw { -namespace kernel { -namespace acl { +namespace nnfw +{ +namespace kernel +{ +namespace acl +{ -namespace common { +namespace common +{ -typedef std::function sync_scheduler_f; +typedef std::function sync_scheduler_f; -template -bool fullyConnectedFloat32(const float* inputData, const nnfw::rt::Shape& inputShape, - const float* weightsData, const nnfw::rt::Shape& weightsShape, - const float* biasData, const nnfw::rt::Shape& biasShape, - int32_t activation, - float* outputData, const nnfw::rt::Shape& outputShape, - sync_scheduler_f sync_scheduler) { +template +bool fullyConnectedFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, + const float *weightsData, const nnfw::rt::Shape &weightsShape, + const float *biasData, const nnfw::rt::Shape &biasShape, + int32_t activation, float *outputData, + const nnfw::rt::Shape &outputShape, sync_scheduler_f sync_scheduler) +{ - // NNAPI specification: https://developer.android.com/ndk/reference/group___neural_networks.html#ggaabbe492c60331b13038e39d4207940e0aaada7a3dbaf4676aba560c933ff610c5 + // NNAPI specification: + // https://developer.android.com/ndk/reference/group___neural_networks.html#ggaabbe492c60331b13038e39d4207940e0aaada7a3dbaf4676aba560c933ff610c5 // According to the NNAPI Specification, // INPUT // 1. input rank is up to 4. // 2. if input rank > 2, it is flattened to rank 2 [batch_size, input_size] nnfw::rt::Shape flattenedInputShape = inputShape; - switch(inputShape.dimensions.size()) { - case 1: + switch (inputShape.dimensions.size()) + { + case 1: { assert("Need to be implemented." && 0); break; } - case 2: + case 2: { // DO NOTHING. break; } - case 3: + case 3: { assert("Need to be implemented." && 0); break; } - case 4: + case 4: { auto N = inputShape.dimensions[0]; auto H = inputShape.dimensions[1]; auto W = inputShape.dimensions[2]; auto C = inputShape.dimensions[3]; - flattenedInputShape.dimensions = {N, H*W*C}; + flattenedInputShape.dimensions = {N, H * W * C}; break; } - default: - assert(inputShape.dimensions.size() <= 4); + default: + assert(inputShape.dimensions.size() <= 4); } // Finally, flattenedInputShape is a 2D tensor. @@ -110,7 +116,8 @@ bool fullyConnectedFloat32(const float* inputData, const nnfw::rt::Shape& inputS { auto relu_f = std::make_shared(); - const arm_compute::ActivationLayerInfo relu_info{arm_compute::ActivationLayerInfo::ActivationFunction::RELU}; + const arm_compute::ActivationLayerInfo relu_info{ + arm_compute::ActivationLayerInfo::ActivationFunction::RELU}; // Do in-place update relu_f->configure(output.ptr(), nullptr, relu_info); diff --git a/libs/kernel/acl/src/FullyConnected.test.h b/libs/kernel/acl/src/FullyConnected.test.h index 01bbff8..7c64e74 100644 --- a/libs/kernel/acl/src/FullyConnected.test.h +++ b/libs/kernel/acl/src/FullyConnected.test.h @@ -31,89 +31,68 @@ #endif // ACL_CORE_FUNC_NAME using namespace nnfw::kernel::acl; -using fullyConnectedFloat32T = bool (*)(const float* inputData, const nnfw::rt::Shape& inputShape, - const float* weightsData, const nnfw::rt::Shape& weightsShape, - const float* biasData, const nnfw::rt::Shape& biasShape, - int32_t activation, - float* outputData, const nnfw::rt::Shape& outputShape); +using fullyConnectedFloat32T = bool (*)(const float *inputData, const nnfw::rt::Shape &inputShape, + const float *weightsData, + const nnfw::rt::Shape &weightsShape, const float *biasData, + const nnfw::rt::Shape &biasShape, int32_t activation, + float *outputData, const nnfw::rt::Shape &outputShape); -ACL_TEST(KernelACL_TC, fcFloat32_1) { +ACL_TEST(KernelACL_TC, fcFloat32_1) +{ - util::TensorWrapper input({1,1,1,100}); - util::TensorWrapper weights({1,100}); + util::TensorWrapper input({1, 1, 1, 100}); + util::TensorWrapper weights({1, 100}); util::TensorWrapper bias({1}); - util::TensorWrapper output({1,1}); + util::TensorWrapper output({1, 1}); int32_t activation = static_cast(FusedActivationFunc::RELU); - input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 1.f; - }); - weights.initValue([](uint32_t h, uint32_t w) { - return 1.f; - }); - bias.initValue([](uint32_t w) { - return 0.f; - }); - output.initValue([](uint32_t h, uint32_t w) { - return 0.f; - }); + input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.f; }); + weights.initValue([](uint32_t h, uint32_t w) { return 1.f; }); + bias.initValue([](uint32_t w) { return 0.f; }); + output.initValue([](uint32_t h, uint32_t w) { return 0.f; }); - bool bret = ACL_CORE_FUNC_NAME(input.ptr(), input.shape(), - weights.ptr(), weights.shape(), - bias.ptr(), bias.shape(), - activation, - output.ptr(), output.shape()); + bool bret = ACL_CORE_FUNC_NAME(input.ptr(), input.shape(), weights.ptr(), + weights.shape(), bias.ptr(), bias.shape(), activation, + output.ptr(), output.shape()); EXPECT_EQ(bret, true); - util::TensorWrapper expected({1,1}); - expected.initValue([](uint32_t h, uint32_t w) { - return 100.f; - }); + util::TensorWrapper expected({1, 1}); + expected.initValue([](uint32_t h, uint32_t w) { return 100.f; }); EXPECT_EQ(output, expected); } -ACL_TEST(KernelACL_TC, fcFloat32_relu) { +ACL_TEST(KernelACL_TC, fcFloat32_relu) +{ - util::TensorWrapper input({1,1,1,100}); - util::TensorWrapper weights({1,100}); + util::TensorWrapper input({1, 1, 1, 100}); + util::TensorWrapper weights({1, 100}); util::TensorWrapper bias({1}); - util::TensorWrapper output({1,1}); + util::TensorWrapper output({1, 1}); int32_t activation = static_cast(FusedActivationFunc::RELU); - input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 1.f; - }); - weights.initValue([](uint32_t h, uint32_t w) { - return -1.f; - }); - bias.initValue([](uint32_t w) { - return 0.f; - }); - output.initValue([](uint32_t h, uint32_t w) { - return 0.f; - }); + input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.f; }); + weights.initValue([](uint32_t h, uint32_t w) { return -1.f; }); + bias.initValue([](uint32_t w) { return 0.f; }); + output.initValue([](uint32_t h, uint32_t w) { return 0.f; }); - bool bret = ACL_CORE_FUNC_NAME(input.ptr(), input.shape(), - weights.ptr(), weights.shape(), - bias.ptr(), bias.shape(), - activation, - output.ptr(), output.shape()); + bool bret = ACL_CORE_FUNC_NAME(input.ptr(), input.shape(), weights.ptr(), + weights.shape(), bias.ptr(), bias.shape(), activation, + output.ptr(), output.shape()); EXPECT_EQ(bret, true); - util::TensorWrapper expected({1,1}); - expected.initValue([](uint32_t h, uint32_t w) { - return 0.f; - }); + util::TensorWrapper expected({1, 1}); + expected.initValue([](uint32_t h, uint32_t w) { return 0.f; }); EXPECT_EQ(output, expected); } -ACL_TEST(KernelACL_TC, fcFloat32_conv_fc) { +ACL_TEST(KernelACL_TC, fcFloat32_conv_fc) +{ uint32_t input_n = 1; uint32_t input_c = 5; uint32_t input_h = 4; @@ -123,7 +102,7 @@ ACL_TEST(KernelACL_TC, fcFloat32_conv_fc) { int32_t activation = static_cast(FusedActivationFunc::RELU); util::TensorWrapper input({input_n, input_h, input_w, input_c}); - util::TensorWrapper weight({weight_n, input_c*input_h*input_w}); + util::TensorWrapper weight({weight_n, input_c * input_h * input_w}); util::TensorWrapper bias({weight_n}); util::TensorWrapper output({1, weight_n}); @@ -133,45 +112,34 @@ ACL_TEST(KernelACL_TC, fcFloat32_conv_fc) { uint32_t W = input_w; uint32_t C = input_c; - return n*H*W*C + h*W*C + w*C + c; + return n * H * W * C + h * W * C + w * C + c; }); weight.initValue([&](uint32_t h, uint32_t w) { uint32_t H = weight_n; - uint32_t W = input_c*input_h*input_w; + uint32_t W = input_c * input_h * input_w; - return h*W + w; + return h * W + w; }); - bias.initValue([](uint32_t w) { - return 0.f; - }); + bias.initValue([](uint32_t w) { return 0.f; }); - output.initValue([](uint32_t h, uint32_t w) { - return 0.f; - }); + output.initValue([](uint32_t h, uint32_t w) { return 0.f; }); - bool bret = ACL_CORE_FUNC_NAME(input.ptr(), input.shape(), - weight.ptr(), weight.shape(), - bias.ptr(), bias.shape(), - activation, - output.ptr(), output.shape()); + bool bret = ACL_CORE_FUNC_NAME(input.ptr(), input.shape(), weight.ptr(), + weight.shape(), bias.ptr(), bias.shape(), activation, + output.ptr(), output.shape()); EXPECT_EQ(bret, true); util::TensorWrapper expected({1, weight_n}); - expected.initValue({ - 167480.f, - 420280.f, - 673080.f, - 925880.f, - 1178680.f, - 1431480.f}); + expected.initValue({167480.f, 420280.f, 673080.f, 925880.f, 1178680.f, 1431480.f}); EXPECT_EQ(output, expected); } -ACL_TEST(KernelACL_TC, fcFloat32_fc_fc) { +ACL_TEST(KernelACL_TC, fcFloat32_fc_fc) +{ uint32_t input_n = 6; uint32_t weight_n = 6; @@ -191,76 +159,53 @@ ACL_TEST(KernelACL_TC, fcFloat32_fc_fc) { uint32_t H = weight_n; uint32_t W = input_n; - return (float)(h*W + w); + return (float)(h * W + w); }); - bias.initValue([](uint32_t w) { - return 0.f; - }); + bias.initValue([](uint32_t w) { return 0.f; }); - output.initValue([](uint32_t h, uint32_t w) { - return 0.f; - }); + output.initValue([](uint32_t h, uint32_t w) { return 0.f; }); - bool bret = ACL_CORE_FUNC_NAME(input.ptr(), input.shape(), - weight.ptr(), weight.shape(), - bias.ptr(), bias.shape(), - activation, - output.ptr(), output.shape()); + bool bret = ACL_CORE_FUNC_NAME(input.ptr(), input.shape(), weight.ptr(), + weight.shape(), bias.ptr(), bias.shape(), activation, + output.ptr(), output.shape()); EXPECT_EQ(bret, true); util::TensorWrapper expected({1, weight_n}); expected.initValue({ - 55.f, - 145.f, - 235.f, - 325.f, - 415.f, - 505.f, + 55.f, 145.f, 235.f, 325.f, 415.f, 505.f, }); EXPECT_EQ(output, expected); } -ACL_TEST(KernelACL_TC, fcFloat32_inceptionv3) { +ACL_TEST(KernelACL_TC, fcFloat32_inceptionv3) +{ uint32_t input_c = 2048; uint32_t weight_n = 1008; - util::TensorWrapper input({1,1,1,input_c}); - util::TensorWrapper weight({weight_n,input_c}); + util::TensorWrapper input({1, 1, 1, input_c}); + util::TensorWrapper weight({weight_n, input_c}); util::TensorWrapper bias({weight_n}); util::TensorWrapper output({1, weight_n}); int32_t activation = static_cast(FusedActivationFunc::RELU); - input.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 1.f; - }); - weight.initValue([&](uint32_t h, uint32_t w) { - return (float)h; - }); - bias.initValue([](uint32_t w) { - return 0.f; - }); - output.initValue([](uint32_t h, uint32_t w) { - return 0.f; - }); + input.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.f; }); + weight.initValue([&](uint32_t h, uint32_t w) { return (float)h; }); + bias.initValue([](uint32_t w) { return 0.f; }); + output.initValue([](uint32_t h, uint32_t w) { return 0.f; }); - bool bret = ACL_CORE_FUNC_NAME(input.ptr(), input.shape(), - weight.ptr(), weight.shape(), - bias.ptr(), bias.shape(), - activation, - output.ptr(), output.shape()); + bool bret = ACL_CORE_FUNC_NAME(input.ptr(), input.shape(), weight.ptr(), + weight.shape(), bias.ptr(), bias.shape(), activation, + output.ptr(), output.shape()); EXPECT_EQ(bret, true); util::TensorWrapper expected({1, weight_n}); - expected.initValue([&](uint32_t h, uint32_t w) { - return w*input_c; - }); + expected.initValue([&](uint32_t h, uint32_t w) { return w * input_c; }); EXPECT_EQ(output, expected); } - diff --git a/libs/kernel/acl/src/IO_accessor.cpp b/libs/kernel/acl/src/IO_accessor.cpp index de03ef2..6282668 100644 --- a/libs/kernel/acl/src/IO_accessor.cpp +++ b/libs/kernel/acl/src/IO_accessor.cpp @@ -18,83 +18,82 @@ #include -namespace nnfw { -namespace kernel { -namespace acl { +namespace nnfw +{ +namespace kernel +{ +namespace acl +{ -InputAccessor::InputAccessor(const float* inputData, const nnfw::rt::Shape& inputShape) - : _inputData(inputData) - , _inputShape(inputShape) +InputAccessor::InputAccessor(const float *inputData, const nnfw::rt::Shape &inputShape) + : _inputData(inputData), _inputShape(inputShape) { } -MatrixInputAccessor::MatrixInputAccessor(const float* inputData, const nnfw::rt::Shape& inputShape) - : _inputData(inputData) - , _inputShape(inputShape) +MatrixInputAccessor::MatrixInputAccessor(const float *inputData, const nnfw::rt::Shape &inputShape) + : _inputData(inputData), _inputShape(inputShape) { } -VectorInputAccessor::VectorInputAccessor(const float* inputData, const nnfw::rt::Shape& inputShape) - : _inputData(inputData) - , _inputShape(inputShape) +VectorInputAccessor::VectorInputAccessor(const float *inputData, const nnfw::rt::Shape &inputShape) + : _inputData(inputData), _inputShape(inputShape) { } -WeightAccessor::WeightAccessor(const float* filterData, const nnfw::rt::Shape& filterShape) - : _filterData(filterData) - , _filterShape(filterShape) +WeightAccessor::WeightAccessor(const float *filterData, const nnfw::rt::Shape &filterShape) + : _filterData(filterData), _filterShape(filterShape) { } -MatrixWeightAccessor::MatrixWeightAccessor(const float* filterData, const nnfw::rt::Shape& filterShape) - : _filterData(filterData) - , _filterShape(filterShape) +MatrixWeightAccessor::MatrixWeightAccessor(const float *filterData, + const nnfw::rt::Shape &filterShape) + : _filterData(filterData), _filterShape(filterShape) { } -BiasAccessor::BiasAccessor(const float* biasData, const nnfw::rt::Shape& biasShape) - : _biasData(biasData) - , _biasShape(biasShape) +BiasAccessor::BiasAccessor(const float *biasData, const nnfw::rt::Shape &biasShape) + : _biasData(biasData), _biasShape(biasShape) { } -OutputAccessor::OutputAccessor(float* outputData, const nnfw::rt::Shape& outputShape) - : _outputData(outputData) - , _outputShape(outputShape) +OutputAccessor::OutputAccessor(float *outputData, const nnfw::rt::Shape &outputShape) + : _outputData(outputData), _outputShape(outputShape) { } -MatrixOutputAccessor::MatrixOutputAccessor(float* outputData, const nnfw::rt::Shape& outputShape) - : _outputData(outputData) - , _outputShape(outputShape) +MatrixOutputAccessor::MatrixOutputAccessor(float *outputData, const nnfw::rt::Shape &outputShape) + : _outputData(outputData), _outputShape(outputShape) { } -VectorOutputAccessor::VectorOutputAccessor(float* outputData, const nnfw::rt::Shape& outputShape) - : _outputData(outputData) - , _outputShape(outputShape) +VectorOutputAccessor::VectorOutputAccessor(float *outputData, const nnfw::rt::Shape &outputShape) + : _outputData(outputData), _outputShape(outputShape) { } -static uint32_t getOffsetNCHW(const nnfw::rt::Shape& shape, const arm_compute::Coordinates& id) +static uint32_t getOffsetNCHW(const nnfw::rt::Shape &shape, const arm_compute::Coordinates &id) { // get offset for ACL(NCHW) from data of NNAPI(NHWC) - uint32_t num = getSizeOfDimension(shape, 0); + uint32_t num = getSizeOfDimension(shape, 0); uint32_t height = getSizeOfDimension(shape, 1); - uint32_t width = getSizeOfDimension(shape, 2); - uint32_t chann = getSizeOfDimension(shape, 3); + uint32_t width = getSizeOfDimension(shape, 2); + uint32_t chann = getSizeOfDimension(shape, 3); uint32_t stride = 1; uint32_t offset = 0; uint32_t numdim = id.num_dimensions(); - offset += numdim > 0 ? id[0] * stride : 0; stride *= width; - offset += numdim > 1 ? id[1] * stride : 0; stride *= height; - offset += numdim > 2 ? id[2] * stride : 0; stride *= chann; - offset += numdim > 3 ? id[3] * stride : 0; stride *= num; + offset += numdim > 0 ? id[0] * stride : 0; + stride *= width; + offset += numdim > 1 ? id[1] * stride : 0; + stride *= height; + offset += numdim > 2 ? id[2] * stride : 0; + stride *= chann; + offset += numdim > 3 ? id[3] * stride : 0; + stride *= num; return offset; } -static uint32_t getElementOffset(const nnfw::rt::Shape& shape, - uint32_t ch, uint32_t row, uint32_t col) +static uint32_t getElementOffset(const nnfw::rt::Shape &shape, uint32_t ch, uint32_t row, + uint32_t col) { assert(getSizeOfDimension(shape, 0) == 1); assert(shape.dimensions.size() == 4); @@ -113,8 +112,8 @@ static uint32_t getElementOffset(const nnfw::rt::Shape& shape, return offset; } -static uint32_t getElementOffset(const nnfw::rt::Shape& shape, - uint32_t nth, uint32_t ch, uint32_t row, uint32_t col) +static uint32_t getElementOffset(const nnfw::rt::Shape &shape, uint32_t nth, uint32_t ch, + uint32_t row, uint32_t col) { assert(shape.dimensions.size() == 4); @@ -139,8 +138,7 @@ bool InputAccessor::access_tensor(arm_compute::ITensor &tensor) arm_compute::Window window; window.use_tensor_dimensions(tensor.info()->tensor_shape()); - execute_window_loop(window, [&](const arm_compute::Coordinates& id) - { + execute_window_loop(window, [&](const arm_compute::Coordinates &id) { const uint32_t nth = id[3]; const uint32_t ch = id[2]; const uint32_t row = id[1]; @@ -148,8 +146,7 @@ bool InputAccessor::access_tensor(arm_compute::ITensor &tensor) uint32_t offset = getElementOffset(_inputShape, nth, ch, row, col); - *reinterpret_cast(tensor.ptr_to_element(id)) = - *(_inputData + offset); + *reinterpret_cast(tensor.ptr_to_element(id)) = *(_inputData + offset); }); return true; } @@ -161,16 +158,14 @@ bool MatrixInputAccessor::access_tensor(arm_compute::ITensor &tensor) assert(tensor.info()->tensor_shape().num_dimensions() <= 2); - execute_window_loop(window, [&](const arm_compute::Coordinates& id) - { + execute_window_loop(window, [&](const arm_compute::Coordinates &id) { const auto row = id[1]; const auto col = id[0]; const auto W = tensor.info()->tensor_shape().x(); const auto offset = row * W + col; - *reinterpret_cast(tensor.ptr_to_element(id)) = - *(_inputData + offset); + *reinterpret_cast(tensor.ptr_to_element(id)) = *(_inputData + offset); }); return true; } @@ -182,12 +177,10 @@ bool VectorInputAccessor::access_tensor(arm_compute::ITensor &tensor) assert(tensor.info()->tensor_shape().num_dimensions() == 1); - execute_window_loop(window, [&](const arm_compute::Coordinates& id) - { + execute_window_loop(window, [&](const arm_compute::Coordinates &id) { uint32_t offset = id[0]; - *reinterpret_cast(tensor.ptr_to_element(id)) = - *(_inputData + offset); + *reinterpret_cast(tensor.ptr_to_element(id)) = *(_inputData + offset); }); return true; } @@ -197,8 +190,7 @@ bool WeightAccessor::access_tensor(arm_compute::ITensor &tensor) arm_compute::Window window; window.use_tensor_dimensions(tensor.info()->tensor_shape()); - execute_window_loop(window, [&](const arm_compute::Coordinates& id) - { + execute_window_loop(window, [&](const arm_compute::Coordinates &id) { const uint32_t nth = id[3]; const uint32_t ch = id[2]; const uint32_t row = id[1]; @@ -206,8 +198,7 @@ bool WeightAccessor::access_tensor(arm_compute::ITensor &tensor) uint32_t offset = getElementOffset(_filterShape, nth, ch, row, col); - *reinterpret_cast(tensor.ptr_to_element(id)) = - *(_filterData + offset); + *reinterpret_cast(tensor.ptr_to_element(id)) = *(_filterData + offset); }); return true; } @@ -219,16 +210,14 @@ bool MatrixWeightAccessor::access_tensor(arm_compute::ITensor &tensor) assert(tensor.info()->tensor_shape().num_dimensions() <= 2); - execute_window_loop(window, [&](const arm_compute::Coordinates& id) - { + execute_window_loop(window, [&](const arm_compute::Coordinates &id) { const auto row = id[1]; const auto col = id[0]; const auto W = tensor.info()->tensor_shape().x(); uint32_t offset = row * W + col; - *reinterpret_cast(tensor.ptr_to_element(id)) = - *(_filterData + offset); + *reinterpret_cast(tensor.ptr_to_element(id)) = *(_filterData + offset); }); return true; } @@ -238,11 +227,9 @@ bool BiasAccessor::access_tensor(arm_compute::ITensor &tensor) arm_compute::Window window; window.use_tensor_dimensions(tensor.info()->tensor_shape()); - execute_window_loop(window, [&](const arm_compute::Coordinates& id) - { + execute_window_loop(window, [&](const arm_compute::Coordinates &id) { uint32_t offset = getOffsetNCHW(_biasShape, id); - *reinterpret_cast(tensor.ptr_to_element(id)) = - *(_biasData + offset); + *reinterpret_cast(tensor.ptr_to_element(id)) = *(_biasData + offset); }); return true; } @@ -252,8 +239,7 @@ bool OutputAccessor::access_tensor(arm_compute::ITensor &tensor) arm_compute::Window window; window.use_tensor_dimensions(tensor.info()->tensor_shape()); - execute_window_loop(window, [&](const arm_compute::Coordinates& id) - { + execute_window_loop(window, [&](const arm_compute::Coordinates &id) { const uint32_t nth = id[3]; const uint32_t ch = id[2]; const uint32_t row = id[1]; @@ -261,8 +247,7 @@ bool OutputAccessor::access_tensor(arm_compute::ITensor &tensor) uint32_t offset = getElementOffset(_outputShape, nth, ch, row, col); - *(_outputData + offset) = - *reinterpret_cast(tensor.ptr_to_element(id)); + *(_outputData + offset) = *reinterpret_cast(tensor.ptr_to_element(id)); }); return false; // end the network } @@ -274,14 +259,12 @@ bool VectorOutputAccessor::access_tensor(arm_compute::ITensor &tensor) assert(tensor.info()->tensor_shape().num_dimensions() == 1); - execute_window_loop(window, [&](const arm_compute::Coordinates& id) - { + execute_window_loop(window, [&](const arm_compute::Coordinates &id) { const uint32_t x = id[0]; uint32_t offset = x; - *(_outputData + offset) = - *reinterpret_cast(tensor.ptr_to_element(id)); + *(_outputData + offset) = *reinterpret_cast(tensor.ptr_to_element(id)); }); return false; // end the network } @@ -293,16 +276,14 @@ bool MatrixOutputAccessor::access_tensor(arm_compute::ITensor &tensor) assert(tensor.info()->tensor_shape().num_dimensions() <= 2); - execute_window_loop(window, [&](const arm_compute::Coordinates& id) - { + execute_window_loop(window, [&](const arm_compute::Coordinates &id) { const auto row = id[1]; const auto col = id[0]; const auto W = tensor.info()->tensor_shape().x(); const auto offset = row * W + col; - *(_outputData + offset) = - *reinterpret_cast(tensor.ptr_to_element(id)); + *(_outputData + offset) = *reinterpret_cast(tensor.ptr_to_element(id)); }); return false; // end the network } diff --git a/libs/kernel/acl/src/IO_accessor.h b/libs/kernel/acl/src/IO_accessor.h index e7670f1..ad53cc5 100644 --- a/libs/kernel/acl/src/IO_accessor.h +++ b/libs/kernel/acl/src/IO_accessor.h @@ -23,139 +23,142 @@ #include // for nnfw::rt::Shape -namespace nnfw { -namespace kernel { -namespace acl { +namespace nnfw +{ +namespace kernel +{ +namespace acl +{ class InputAccessor : public arm_compute::graph::ITensorAccessor { public: - InputAccessor(const float* inputData, const nnfw::rt::Shape& inputShape); - InputAccessor(InputAccessor&&) = default; + InputAccessor(const float *inputData, const nnfw::rt::Shape &inputShape); + InputAccessor(InputAccessor &&) = default; - // Inherited methods overriden: - bool access_tensor(arm_compute::ITensor& tensor) override; + // Inherited methods overriden: + bool access_tensor(arm_compute::ITensor &tensor) override; private: - const float* _inputData; - const nnfw::rt::Shape& _inputShape; + const float *_inputData; + const nnfw::rt::Shape &_inputShape; }; class MatrixInputAccessor : public arm_compute::graph::ITensorAccessor { public: - MatrixInputAccessor(const float* inputData, const nnfw::rt::Shape& inputShape); - MatrixInputAccessor(MatrixInputAccessor&&) = default; + MatrixInputAccessor(const float *inputData, const nnfw::rt::Shape &inputShape); + MatrixInputAccessor(MatrixInputAccessor &&) = default; - // Inherited methods overriden: - bool access_tensor(arm_compute::ITensor& tensor) override; + // Inherited methods overriden: + bool access_tensor(arm_compute::ITensor &tensor) override; private: - const float* _inputData; - const nnfw::rt::Shape& _inputShape; + const float *_inputData; + const nnfw::rt::Shape &_inputShape; }; class VectorInputAccessor : public arm_compute::graph::ITensorAccessor { public: - VectorInputAccessor(const float* inputData, const nnfw::rt::Shape& inputShape); - VectorInputAccessor(VectorInputAccessor&&) = default; + VectorInputAccessor(const float *inputData, const nnfw::rt::Shape &inputShape); + VectorInputAccessor(VectorInputAccessor &&) = default; - // Inherited methods overriden: - bool access_tensor(arm_compute::ITensor& tensor) override; + // Inherited methods overriden: + bool access_tensor(arm_compute::ITensor &tensor) override; private: - const float* _inputData; - const nnfw::rt::Shape& _inputShape; + const float *_inputData; + const nnfw::rt::Shape &_inputShape; }; class WeightAccessor : public arm_compute::graph::ITensorAccessor { public: - WeightAccessor(const float* filterData, const nnfw::rt::Shape& filterShape); - WeightAccessor(WeightAccessor&&) = default; + WeightAccessor(const float *filterData, const nnfw::rt::Shape &filterShape); + WeightAccessor(WeightAccessor &&) = default; - // Inherited methods overriden: - bool access_tensor(arm_compute::ITensor& tensor) override; + // Inherited methods overriden: + bool access_tensor(arm_compute::ITensor &tensor) override; private: - const float* _filterData; - const nnfw::rt::Shape& _filterShape; + const float *_filterData; + const nnfw::rt::Shape &_filterShape; }; class MatrixWeightAccessor : public arm_compute::graph::ITensorAccessor { public: - MatrixWeightAccessor(const float* filterData, const nnfw::rt::Shape& filterShape); - MatrixWeightAccessor(MatrixWeightAccessor&&) = default; + MatrixWeightAccessor(const float *filterData, const nnfw::rt::Shape &filterShape); + MatrixWeightAccessor(MatrixWeightAccessor &&) = default; - // Inherited methods overriden: - bool access_tensor(arm_compute::ITensor& tensor) override; + // Inherited methods overriden: + bool access_tensor(arm_compute::ITensor &tensor) override; private: - const float* _filterData; - const nnfw::rt::Shape& _filterShape; + const float *_filterData; + const nnfw::rt::Shape &_filterShape; }; class BiasAccessor : public arm_compute::graph::ITensorAccessor { public: - BiasAccessor(const float* biasData, const nnfw::rt::Shape& biasShape); - BiasAccessor(BiasAccessor&&) = default; + BiasAccessor(const float *biasData, const nnfw::rt::Shape &biasShape); + BiasAccessor(BiasAccessor &&) = default; - // Inherited methods overriden: - bool access_tensor(arm_compute::ITensor& tensor) override; + // Inherited methods overriden: + bool access_tensor(arm_compute::ITensor &tensor) override; private: - const float* _biasData; - const nnfw::rt::Shape& _biasShape; + const float *_biasData; + const nnfw::rt::Shape &_biasShape; }; class OutputAccessor : public arm_compute::graph::ITensorAccessor { public: - OutputAccessor(float* outputData, const nnfw::rt::Shape& outputShape); - OutputAccessor(OutputAccessor&&) = default; + OutputAccessor(float *outputData, const nnfw::rt::Shape &outputShape); + OutputAccessor(OutputAccessor &&) = default; - // Inherited methods overriden: - bool access_tensor(arm_compute::ITensor& tensor) override; + // Inherited methods overriden: + bool access_tensor(arm_compute::ITensor &tensor) override; private: - float* _outputData; - const nnfw::rt::Shape& _outputShape; + float *_outputData; + const nnfw::rt::Shape &_outputShape; }; class MatrixOutputAccessor : public arm_compute::graph::ITensorAccessor { public: - MatrixOutputAccessor(float* outputData, const nnfw::rt::Shape& outputShape); - MatrixOutputAccessor(MatrixOutputAccessor&&) = default; + MatrixOutputAccessor(float *outputData, const nnfw::rt::Shape &outputShape); + MatrixOutputAccessor(MatrixOutputAccessor &&) = default; - // Inherited methods overriden: - bool access_tensor(arm_compute::ITensor& tensor) override; + // Inherited methods overriden: + bool access_tensor(arm_compute::ITensor &tensor) override; private: - float* _outputData; - const nnfw::rt::Shape& _outputShape; + float *_outputData; + const nnfw::rt::Shape &_outputShape; }; class VectorOutputAccessor : public arm_compute::graph::ITensorAccessor { public: - VectorOutputAccessor(float* outputData, const nnfw::rt::Shape& outputShape); - VectorOutputAccessor(VectorOutputAccessor&&) = default; + VectorOutputAccessor(float *outputData, const nnfw::rt::Shape &outputShape); + VectorOutputAccessor(VectorOutputAccessor &&) = default; - // Inherited methods overriden: - bool access_tensor(arm_compute::ITensor& tensor) override; + // Inherited methods overriden: + bool access_tensor(arm_compute::ITensor &tensor) override; private: - float* _outputData; - const nnfw::rt::Shape& _outputShape; + float *_outputData; + const nnfw::rt::Shape &_outputShape; }; -template -inline void TensorAccess(arm_compute::CLTensor& tensor, const float* data, - const nnfw::rt::Shape& shape) +template +inline void TensorAccess(arm_compute::CLTensor &tensor, const float *data, + const nnfw::rt::Shape &shape) { tensor.map(); AccessorType accessor(data, shape); @@ -163,9 +166,8 @@ inline void TensorAccess(arm_compute::CLTensor& tensor, const float* data, tensor.unmap(); } -template -inline void TensorAccess(arm_compute::CLTensor& tensor, float* data, - const nnfw::rt::Shape& shape) +template +inline void TensorAccess(arm_compute::CLTensor &tensor, float *data, const nnfw::rt::Shape &shape) { tensor.map(); AccessorType accessor(data, shape); @@ -173,17 +175,16 @@ inline void TensorAccess(arm_compute::CLTensor& tensor, float* data, tensor.unmap(); } -template -inline void TensorAccess(arm_compute::Tensor& tensor, const float* data, - const nnfw::rt::Shape& shape) +template +inline void TensorAccess(arm_compute::Tensor &tensor, const float *data, + const nnfw::rt::Shape &shape) { AccessorType accessor(data, shape); accessor.access_tensor(tensor); } -template -inline void TensorAccess(arm_compute::Tensor& tensor, float* data, - const nnfw::rt::Shape& shape) +template +inline void TensorAccess(arm_compute::Tensor &tensor, float *data, const nnfw::rt::Shape &shape) { AccessorType accessor(data, shape); accessor.access_tensor(tensor); diff --git a/libs/kernel/acl/src/Init_acl.cpp b/libs/kernel/acl/src/Init_acl.cpp index cabf079..c2c8d79 100644 --- a/libs/kernel/acl/src/Init_acl.cpp +++ b/libs/kernel/acl/src/Init_acl.cpp @@ -17,15 +17,15 @@ #include #include -namespace nnfw { -namespace kernel { -namespace acl { +namespace nnfw +{ +namespace kernel +{ +namespace acl +{ // This will do one time initialization but can be called multiple times -void Initialize(void) -{ - arm_compute::CLScheduler::get().default_init(); -} +void Initialize(void) { arm_compute::CLScheduler::get().default_init(); } } // namespace acl } // namespace kernel diff --git a/libs/kernel/acl/src/Reshape.h b/libs/kernel/acl/src/Reshape.h index ebd8247..00bd743 100644 --- a/libs/kernel/acl/src/Reshape.h +++ b/libs/kernel/acl/src/Reshape.h @@ -24,18 +24,22 @@ #include "IO_accessor.h" #include "shape.h" -namespace nnfw { -namespace kernel { -namespace acl { +namespace nnfw +{ +namespace kernel +{ +namespace acl +{ -namespace common { +namespace common +{ -typedef std::function sync_scheduler_f; +typedef std::function sync_scheduler_f; -template -bool reshapeGeneric(const void* inputData, const nnfw::rt::Shape& inputShape, - void* outputData, const nnfw::rt::Shape& outputShape, - sync_scheduler_f sync_scheduler) { +template +bool reshapeGeneric(const void *inputData, const nnfw::rt::Shape &inputShape, void *outputData, + const nnfw::rt::Shape &outputShape, sync_scheduler_f sync_scheduler) +{ auto input_shape = util::fromNNShape(inputShape); auto output_shape = util::fromNNShape(outputShape); @@ -50,13 +54,13 @@ bool reshapeGeneric(const void* inputData, const nnfw::rt::Shape& inputShape, input.allocate(); output.allocate(); - TensorAccess(input.ref(), (float*)inputData, inputShape); + TensorAccess(input.ref(), (float *)inputData, inputShape); l.run(); sync_scheduler(); - TensorAccess(output.ref(), (float*)outputData, outputShape); + TensorAccess(output.ref(), (float *)outputData, outputShape); return true; } diff --git a/libs/kernel/acl/src/Reshape.test.h b/libs/kernel/acl/src/Reshape.test.h index a96a896..a666aea 100644 --- a/libs/kernel/acl/src/Reshape.test.h +++ b/libs/kernel/acl/src/Reshape.test.h @@ -32,20 +32,19 @@ using namespace nnfw::kernel::acl; -ACL_TEST(KernelACL_TC, reshape_1) { - const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1,1,9,1}, 1.0, 0}; +ACL_TEST(KernelACL_TC, reshape_1) +{ + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 1, 9, 1}, 1.0, 0}; float inputData[9] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f}; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; float outputData[9] = {0}; - bool bret = ACL_CORE_FUNC_NAME(inputData, inputShape, - outputData, outputShape); + bool bret = ACL_CORE_FUNC_NAME(inputData, inputShape, outputData, outputShape); EXPECT_EQ(bret, true); float expectData[9] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f}; bret = util::compareData(outputData, expectData, outputShape); EXPECT_EQ(bret, true); - } diff --git a/libs/kernel/acl/src/UniqueTensor.h b/libs/kernel/acl/src/UniqueTensor.h index d9182c8..af00f49 100644 --- a/libs/kernel/acl/src/UniqueTensor.h +++ b/libs/kernel/acl/src/UniqueTensor.h @@ -20,18 +20,17 @@ #include #include -namespace nnfw { -namespace kernel { -namespace acl { +namespace nnfw +{ +namespace kernel +{ +namespace acl +{ -template -class UniqueTensor +template class UniqueTensor { public: - UniqueTensor(const ::arm_compute::TensorInfo &info) - { - _tensor.allocator()->init(info); - } + UniqueTensor(const ::arm_compute::TensorInfo &info) { _tensor.allocator()->init(info); } public: // Both copy and move are not allowed @@ -39,16 +38,10 @@ public: UniqueTensor(UniqueTensor &&) = delete; public: - ~UniqueTensor() - { - _tensor.allocator()->free(); - } + ~UniqueTensor() { _tensor.allocator()->free(); } public: - void allocate() - { - _tensor.allocator()->allocate(); - } + void allocate() { _tensor.allocator()->allocate(); } public: TensorT &ref(void) { return _tensor; } diff --git a/libs/kernel/acl/src/cl/Concatenation.cpp b/libs/kernel/acl/src/cl/Concatenation.cpp index 9376006..effaa64 100644 --- a/libs/kernel/acl/src/cl/Concatenation.cpp +++ b/libs/kernel/acl/src/cl/Concatenation.cpp @@ -24,13 +24,16 @@ #include "../IO_accessor.h" #include "../shape.h" -namespace nnfw { -namespace kernel { -namespace acl { +namespace nnfw +{ +namespace kernel +{ +namespace acl +{ -bool concatenationFloat32(const std::vector& inputDataPtrs, - const std::vector& inputShapes, int32_t axis, - float* outputData, const nnfw::rt::Shape& outputShape) +bool concatenationFloat32(const std::vector &inputDataPtrs, + const std::vector &inputShapes, int32_t axis, + float *outputData, const nnfw::rt::Shape &outputShape) { if (axis != 3) { @@ -39,17 +42,17 @@ bool concatenationFloat32(const std::vector& inputDataPtrs, } assert(inputDataPtrs.size() == inputShapes.size()); - std::vector inputPtrs; - std::vector inputIptrs; + std::vector inputPtrs; + std::vector inputIptrs; arm_compute::CLTensor output; // init Tensors std::vector::const_iterator it_inputShape = inputShapes.begin(); for (auto inputData : inputDataPtrs) { - const nnfw::rt::Shape& inputShape = *it_inputShape; + const nnfw::rt::Shape &inputShape = *it_inputShape; arm_compute::TensorShape input_shape = util::fromNNShape(inputShape); - arm_compute::CLTensor* inputPtr = new arm_compute::CLTensor(); + arm_compute::CLTensor *inputPtr = new arm_compute::CLTensor(); inputPtr->allocator()->init(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); inputPtrs.push_back(inputPtr); @@ -66,13 +69,13 @@ bool concatenationFloat32(const std::vector& inputDataPtrs, // allocate Tensors it_inputShape = inputShapes.begin(); - std::vector::const_iterator it_inputData = inputDataPtrs.begin(); + std::vector::const_iterator it_inputData = inputDataPtrs.begin(); for (auto inputPtr : inputPtrs) { inputPtr->allocator()->allocate(); - const float* inputData = *it_inputData; - const nnfw::rt::Shape& inputShape = *it_inputShape; + const float *inputData = *it_inputData; + const nnfw::rt::Shape &inputShape = *it_inputShape; TensorAccess(*inputPtr, inputData, inputShape); diff --git a/libs/kernel/acl/src/cl/Concatenation.test.cpp b/libs/kernel/acl/src/cl/Concatenation.test.cpp index b2c5a58..40b22cf 100644 --- a/libs/kernel/acl/src/cl/Concatenation.test.cpp +++ b/libs/kernel/acl/src/cl/Concatenation.test.cpp @@ -27,17 +27,17 @@ using namespace nnfw::kernel::acl; TEST(KernelACL_TC, concatFloat32_1) { float inputData_1[6] = { - 1, 2, 3, 4, 5, 6 // [ [ [1],[2],[3] ], [ [4],[5],[6] ] ] + 1, 2, 3, 4, 5, 6 // [ [ [1],[2],[3] ], [ [4],[5],[6] ] ] }; float inputData_2[6] = { - 7, 8, 9, 10, 11, 12 // [ [ [7],[8],[9] ], [ [10],[11],[12] ] ] + 7, 8, 9, 10, 11, 12 // [ [ [7],[8],[9] ], [ [10],[11],[12] ] ] }; - const nnfw::rt::Shape inputShape_1 = { OperandType::FLOAT32, {1,2,3,1}, 1.0, 0 }; - const nnfw::rt::Shape inputShape_2 = { OperandType::FLOAT32, {1,2,3,1}, 1.0, 0 }; - std::vector inputDataPtrs; + const nnfw::rt::Shape inputShape_1 = {OperandType::FLOAT32, {1, 2, 3, 1}, 1.0, 0}; + const nnfw::rt::Shape inputShape_2 = {OperandType::FLOAT32, {1, 2, 3, 1}, 1.0, 0}; + std::vector inputDataPtrs; std::vector inputShapes; float outputData[12]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,2,3,2}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 2, 3, 2}, 1.0, 0}; bool bret; inputDataPtrs.push_back(inputData_1); @@ -47,14 +47,10 @@ TEST(KernelACL_TC, concatFloat32_1) util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - bret = concatenationFloat32(inputDataPtrs, inputShapes, 3, - outputData, outputShape); + bret = concatenationFloat32(inputDataPtrs, inputShapes, 3, outputData, outputShape); EXPECT_EQ(bret, true); - float expectNCHW[] = { - 1, 2, 3, 4, 5, 6, - 7, 8, 9, 10, 11, 12 - }; + float expectNCHW[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; float expectData[12]; // [ [ [1,7],[2,8],[3,9] ], [ [4,10],[5,11],[6,12] ] ] util::NCHW2NHWC(expectNCHW, expectData, outputShape); bret = util::compareData(outputData, expectData, outputShape); diff --git a/libs/kernel/acl/src/cl/Conv2D.cpp b/libs/kernel/acl/src/cl/Conv2D.cpp index f71bbeb..c464c51 100644 --- a/libs/kernel/acl/src/cl/Conv2D.cpp +++ b/libs/kernel/acl/src/cl/Conv2D.cpp @@ -32,29 +32,29 @@ #include "support/nnapi/feature/Reader.h" -namespace nnfw { -namespace kernel { -namespace acl { +namespace nnfw +{ +namespace kernel +{ +namespace acl +{ static int verbose = 0; -bool convFloat32(const float* inputData, const nnfw::rt::Shape& inputShape, - const float* filterData, const nnfw::rt::Shape& filterShape, - const float* biasData, const nnfw::rt::Shape& biasShape, - int32_t padding_left, int32_t padding_right, - int32_t padding_top, int32_t padding_bottom, - int32_t stride_width, int32_t stride_height, - int32_t activation, - float* outputData, const nnfw::rt::Shape& outputShape) +bool convFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, const float *filterData, + const nnfw::rt::Shape &filterShape, const float *biasData, + const nnfw::rt::Shape &biasShape, int32_t padding_left, int32_t padding_right, + int32_t padding_top, int32_t padding_bottom, int32_t stride_width, + int32_t stride_height, int32_t activation, float *outputData, + const nnfw::rt::Shape &outputShape) { arm_compute::TensorShape input_shape = util::fromNNShape(inputShape); arm_compute::TensorShape filter_shape = util::fromNNShape(filterShape); arm_compute::TensorShape bias_shape = util::fromVectorNNShape(biasShape); arm_compute::TensorShape output_shape = util::fromNNShape(outputShape); - arm_compute::PadStrideInfo conv_info = arm_compute::PadStrideInfo(stride_width, stride_height, - padding_left, padding_right, - padding_top, padding_bottom, - arm_compute::DimensionRoundingType::FLOOR); + arm_compute::PadStrideInfo conv_info = arm_compute::PadStrideInfo( + stride_width, stride_height, padding_left, padding_right, padding_top, padding_bottom, + arm_compute::DimensionRoundingType::FLOOR); CLUniqueTensor input(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); CLUniqueTensor output(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); @@ -69,7 +69,8 @@ bool convFloat32(const float* inputData, const nnfw::rt::Shape& inputShape, fns.emplace_back(conv_f); - util::insertFusedActivationLayer(output, activation, fns); + util::insertFusedActivationLayer(output, + activation, fns); input.allocate(); output.allocate(); @@ -89,7 +90,8 @@ bool convFloat32(const float* inputData, const nnfw::rt::Shape& inputShape, nnfw::support::acl::feature::Reader acl_ifm_reader{input.ptr()}; std::cout << "NNAPI IFM:" << std::endl; - std::cout << nnfw::util::feature::TextFormatter{ifm_shape, nnapi_ifm_reader} << std::endl; + std::cout << nnfw::util::feature::TextFormatter{ifm_shape, nnapi_ifm_reader} + << std::endl; std::cout << "ARM Compute IFM:" << std::endl; std::cout << nnfw::util::feature::TextFormatter{ifm_shape, acl_ifm_reader} << std::endl; diff --git a/libs/kernel/acl/src/cl/Conv2D.test.cpp b/libs/kernel/acl/src/cl/Conv2D.test.cpp index e34cdee..421e659 100644 --- a/libs/kernel/acl/src/cl/Conv2D.test.cpp +++ b/libs/kernel/acl/src/cl/Conv2D.test.cpp @@ -27,11 +27,11 @@ using namespace nnfw::kernel::acl; TEST(KernelACL_TC, convFloat32_3x3to1x1) { float inputData[9]; - const nnfw::rt::Shape inputShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; float filterData[9]; - const nnfw::rt::Shape filterShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; - float biasData[1] = { 1.0 }; - const nnfw::rt::Shape biasShape = { OperandType::FLOAT32, {1}, 1.0, 0 }; + const nnfw::rt::Shape filterShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; + float biasData[1] = {1.0}; + const nnfw::rt::Shape biasShape = {OperandType::FLOAT32, {1}, 1.0, 0}; int32_t padding_left = 0; int32_t padding_right = 0; int32_t padding_top = 0; @@ -40,24 +40,19 @@ TEST(KernelACL_TC, convFloat32_3x3to1x1) int32_t stride_height = 1; int32_t activation = static_cast(FusedActivationFunc::RELU); float outputData[1]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,1,1,1}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 1, 1}, 1.0, 0}; bool bret; util::initData(inputData, sizeof(inputData) / sizeof(inputData[0]), 1.0); util::initData(filterData, sizeof(filterData) / sizeof(filterData[0]), 1.0); util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - bret = convFloat32(inputData, inputShape, - filterData, filterShape, - biasData, biasShape, - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - activation, - outputData, outputShape); + bret = convFloat32(inputData, inputShape, filterData, filterShape, biasData, biasShape, + padding_left, padding_right, padding_top, padding_bottom, stride_width, + stride_height, activation, outputData, outputShape); EXPECT_EQ(bret, true); - float expectData[] = { 10.0f }; + float expectData[] = {10.0f}; bret = util::compareData(outputData, expectData, outputShape); EXPECT_EQ(bret, true); } @@ -65,11 +60,11 @@ TEST(KernelACL_TC, convFloat32_3x3to1x1) TEST(KernelACL_TC, convFloat32_3x3to3x3) { float inputData[9]; - const nnfw::rt::Shape inputShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; float filterData[9]; - const nnfw::rt::Shape filterShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; - float biasData[1] = { 1.0 }; - const nnfw::rt::Shape biasShape = { OperandType::FLOAT32, {1}, 1.0, 0 }; + const nnfw::rt::Shape filterShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; + float biasData[1] = {1.0}; + const nnfw::rt::Shape biasShape = {OperandType::FLOAT32, {1}, 1.0, 0}; int32_t padding_left = 1; int32_t padding_right = 1; int32_t padding_top = 1; @@ -78,28 +73,19 @@ TEST(KernelACL_TC, convFloat32_3x3to3x3) int32_t stride_height = 1; int32_t activation = static_cast(FusedActivationFunc::RELU); float outputData[9]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; bool bret; util::initData(inputData, sizeof(inputData) / sizeof(inputData[0]), 1.0); util::initData(filterData, sizeof(filterData) / sizeof(filterData[0]), 1.0); util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - bret = convFloat32(inputData, inputShape, - filterData, filterShape, - biasData, biasShape, - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - activation, - outputData, outputShape); + bret = convFloat32(inputData, inputShape, filterData, filterShape, biasData, biasShape, + padding_left, padding_right, padding_top, padding_bottom, stride_width, + stride_height, activation, outputData, outputShape); EXPECT_EQ(bret, true); - float expectData[] = { - 5.0f, 7.0f, 5.0f, - 7.0f, 10.0f, 7.0f, - 5.0f, 7.0f, 5.0f - }; + float expectData[] = {5.0f, 7.0f, 5.0f, 7.0f, 10.0f, 7.0f, 5.0f, 7.0f, 5.0f}; bret = util::compareData(outputData, expectData, outputShape); EXPECT_EQ(bret, true); } @@ -107,11 +93,11 @@ TEST(KernelACL_TC, convFloat32_3x3to3x3) TEST(KernelACL_TC, convFloat32_3x3to3x3_RELU) { float inputData[9]; - const nnfw::rt::Shape inputShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; float filterData[9]; - const nnfw::rt::Shape filterShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; - float biasData[1] = { -5.0f }; - const nnfw::rt::Shape biasShape = { OperandType::FLOAT32, {1}, 1.0, 0 }; + const nnfw::rt::Shape filterShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; + float biasData[1] = {-5.0f}; + const nnfw::rt::Shape biasShape = {OperandType::FLOAT32, {1}, 1.0, 0}; int32_t padding_left = 1; int32_t padding_right = 1; int32_t padding_top = 1; @@ -120,29 +106,19 @@ TEST(KernelACL_TC, convFloat32_3x3to3x3_RELU) int32_t stride_height = 1; int32_t activation = static_cast(FusedActivationFunc::RELU); float outputData[9]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; bool bret; util::initData(inputData, sizeof(inputData) / sizeof(inputData[0]), 1.0); util::initData(filterData, sizeof(filterData) / sizeof(filterData[0]), 1.0); util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - bret = convFloat32(inputData, inputShape, - filterData, filterShape, - biasData, biasShape, - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - activation, - outputData, outputShape); + bret = convFloat32(inputData, inputShape, filterData, filterShape, biasData, biasShape, + padding_left, padding_right, padding_top, padding_bottom, stride_width, + stride_height, activation, outputData, outputShape); EXPECT_EQ(bret, true); - float expectData[] = - { - 0.0f, 1.0f, 0.0f, - 1.0f, 4.0f, 1.0f, - 0.0f, 1.0f, 0.0f - }; + float expectData[] = {0.0f, 1.0f, 0.0f, 1.0f, 4.0f, 1.0f, 0.0f, 1.0f, 0.0f}; bret = util::compareData(outputData, expectData, outputShape); EXPECT_EQ(bret, true); @@ -150,19 +126,12 @@ TEST(KernelACL_TC, convFloat32_3x3to3x3_RELU) TEST(KernelACL_TC, convFloat32_3x5to3x3) { - float inputData[15] = { - 1,2,3,4,5, - 6,7,8,9,10, - 11,12,13,14,15 - }; - const nnfw::rt::Shape inputShape = { OperandType::FLOAT32, {1,3,5,1}, 1.0, 0 }; - float filterData[18] = { - 1,1,1, 1,1,1, 1,1,1, - 2,2,2, 2,2,2, 2,2,2 - }; - const nnfw::rt::Shape filterShape = { OperandType::FLOAT32, {2,3,3,1}, 1.0, 0 }; - float biasData[2] = { 1.0, 1.0 }; - const nnfw::rt::Shape biasShape = { OperandType::FLOAT32, {2}, 1.0, 0 }; + float inputData[15] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 5, 1}, 1.0, 0}; + float filterData[18] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2}; + const nnfw::rt::Shape filterShape = {OperandType::FLOAT32, {2, 3, 3, 1}, 1.0, 0}; + float biasData[2] = {1.0, 1.0}; + const nnfw::rt::Shape biasShape = {OperandType::FLOAT32, {2}, 1.0, 0}; int32_t padding_left = 1; int32_t padding_right = 1; int32_t padding_top = 1; @@ -171,30 +140,21 @@ TEST(KernelACL_TC, convFloat32_3x5to3x3) int32_t stride_height = 1; int32_t activation = static_cast(FusedActivationFunc::RELU); float outputData[30]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,3,5,2}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 3, 5, 2}, 1.0, 0}; bool bret; util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - bret = convFloat32(inputData, inputShape, - filterData, filterShape, - biasData, biasShape, - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - activation, - outputData, outputShape); + bret = convFloat32(inputData, inputShape, filterData, filterShape, biasData, biasShape, + padding_left, padding_right, padding_top, padding_bottom, stride_width, + stride_height, activation, outputData, outputShape); EXPECT_EQ(bret, true); - float expectNCHW[] = { - 17.0f, 28.0f, 34.0f, 40.0f, 29.0f, - 40.0f, 64.0f, 73.0f, 82.0f, 58.0f, - 37.0f, 58.0f, 64.0f, 70.0f, 49.0f, + float expectNCHW[] = {17.0f, 28.0f, 34.0f, 40.0f, 29.0f, 40.0f, 64.0f, 73.0f, + 82.0f, 58.0f, 37.0f, 58.0f, 64.0f, 70.0f, 49.0f, - 33.0f, 55.0f, 67.0f, 79.0f, 57.0f, - 79.0f, 127.0f, 145.0f, 163.0f, 115.0f, - 73.0f, 115.0f, 127.0f, 139.0f, 97.0f - }; + 33.0f, 55.0f, 67.0f, 79.0f, 57.0f, 79.0f, 127.0f, 145.0f, + 163.0f, 115.0f, 73.0f, 115.0f, 127.0f, 139.0f, 97.0f}; float expectData[30]; util::NCHW2NHWC(expectNCHW, expectData, outputShape); bret = util::compareData(outputData, expectData, outputShape); diff --git a/libs/kernel/acl/src/cl/DepthwiseConv2D.cpp b/libs/kernel/acl/src/cl/DepthwiseConv2D.cpp index 98ad3ec..bedfd97 100644 --- a/libs/kernel/acl/src/cl/DepthwiseConv2D.cpp +++ b/libs/kernel/acl/src/cl/DepthwiseConv2D.cpp @@ -26,35 +26,30 @@ #include "../UniqueTensor.h" #include "../DepthwiseConv2D.h" -namespace nnfw { -namespace kernel { -namespace acl { - -static void sync_scheduler() { - arm_compute::CLScheduler::get().sync(); -} - -bool depthwiseConvFloat32(const float* inputData, const nnfw::rt::Shape& inputShape, - const float* filterData, const nnfw::rt::Shape& filterShape, - const float* biasData, const nnfw::rt::Shape& biasShape, - int32_t padding_left, int32_t padding_right, - int32_t padding_top, int32_t padding_bottom, - int32_t stride_width, int32_t stride_height, - int32_t depth_multiplier, int32_t activation, - float* outputData, const nnfw::rt::Shape& outputShape) { +namespace nnfw +{ +namespace kernel +{ +namespace acl +{ + +static void sync_scheduler() { arm_compute::CLScheduler::get().sync(); } + +bool depthwiseConvFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, + const float *filterData, const nnfw::rt::Shape &filterShape, + const float *biasData, const nnfw::rt::Shape &biasShape, + int32_t padding_left, int32_t padding_right, int32_t padding_top, + int32_t padding_bottom, int32_t stride_width, int32_t stride_height, + int32_t depth_multiplier, int32_t activation, float *outputData, + const nnfw::rt::Shape &outputShape) +{ return common::depthwiseConvFloat32(inputData, inputShape, - filterData, filterShape, - biasData, biasShape, - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - depth_multiplier, activation, - outputData, outputShape, - sync_scheduler); + arm_compute::CLActivationLayer>( + inputData, inputShape, filterData, filterShape, biasData, biasShape, padding_left, + padding_right, padding_top, padding_bottom, stride_width, stride_height, depth_multiplier, + activation, outputData, outputShape, sync_scheduler); } } // namespace acl } // namespace kernel } // namespace nnfw - diff --git a/libs/kernel/acl/src/cl/FullyConnected.cpp b/libs/kernel/acl/src/cl/FullyConnected.cpp index 62fee4e..318edda 100644 --- a/libs/kernel/acl/src/cl/FullyConnected.cpp +++ b/libs/kernel/acl/src/cl/FullyConnected.cpp @@ -26,26 +26,25 @@ #include "../UniqueTensor.h" #include "../FullyConnected.h" -namespace nnfw { -namespace kernel { -namespace acl { +namespace nnfw +{ +namespace kernel +{ +namespace acl +{ -void sync_scheduler() { - arm_compute::CLScheduler::get().sync(); -} +void sync_scheduler() { arm_compute::CLScheduler::get().sync(); } -bool fullyConnectedFloat32(const float* inputData, const nnfw::rt::Shape& inputShape, - const float* weightsData, const nnfw::rt::Shape& weightsShape, - const float* biasData, const nnfw::rt::Shape& biasShape, - int32_t activation, - float* outputData, const nnfw::rt::Shape& outputShape) { +bool fullyConnectedFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, + const float *weightsData, const nnfw::rt::Shape &weightsShape, + const float *biasData, const nnfw::rt::Shape &biasShape, + int32_t activation, float *outputData, + const nnfw::rt::Shape &outputShape) +{ return common::fullyConnectedFloat32(inputData, inputShape, - weightsData, weightsShape, - biasData, biasShape, - activation, - outputData, outputShape, - sync_scheduler); + arm_compute::CLActivationLayer>( + inputData, inputShape, weightsData, weightsShape, biasData, biasShape, activation, outputData, + outputShape, sync_scheduler); } } // namespace acl diff --git a/libs/kernel/acl/src/cl/Pooling.cpp b/libs/kernel/acl/src/cl/Pooling.cpp index 5fb5318..21e4925 100644 --- a/libs/kernel/acl/src/cl/Pooling.cpp +++ b/libs/kernel/acl/src/cl/Pooling.cpp @@ -23,31 +23,31 @@ #include -namespace nnfw { -namespace kernel { -namespace acl { - -bool maxPoolFloat32(const float* inputData, const nnfw::rt::Shape& inputShape, - int32_t padding_left, int32_t padding_right, - int32_t padding_top, int32_t padding_bottom, - int32_t stride_width, int32_t stride_height, - int32_t filter_width, int32_t filter_height, - int32_t activation, - float* outputData, const nnfw::rt::Shape& outputShape) +namespace nnfw +{ +namespace kernel +{ +namespace acl +{ + +bool maxPoolFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, int32_t padding_left, + int32_t padding_right, int32_t padding_top, int32_t padding_bottom, + int32_t stride_width, int32_t stride_height, int32_t filter_width, + int32_t filter_height, int32_t activation, float *outputData, + const nnfw::rt::Shape &outputShape) { arm_compute::TensorShape input_shape = util::fromNNShape(inputShape); arm_compute::TensorShape output_shape = util::fromNNShape(outputShape); std::vector> fns; - arm_compute::PadStrideInfo pad_info = arm_compute::PadStrideInfo(stride_width, stride_height, - padding_left, padding_right, - padding_top, padding_bottom, - arm_compute::DimensionRoundingType::FLOOR); + arm_compute::PadStrideInfo pad_info = arm_compute::PadStrideInfo( + stride_width, stride_height, padding_left, padding_right, padding_top, padding_bottom, + arm_compute::DimensionRoundingType::FLOOR); - arm_compute::PoolingLayerInfo maxpool_info = arm_compute::PoolingLayerInfo(arm_compute::PoolingType::MAX, - arm_compute::Size2D(filter_width,filter_height), - pad_info, false); + arm_compute::PoolingLayerInfo maxpool_info = arm_compute::PoolingLayerInfo( + arm_compute::PoolingType::MAX, arm_compute::Size2D(filter_width, filter_height), pad_info, + false); CLUniqueTensor input(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); CLUniqueTensor output(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); @@ -60,7 +60,8 @@ bool maxPoolFloat32(const float* inputData, const nnfw::rt::Shape& inputShape, input.allocate(); output.allocate(); - util::insertFusedActivationLayer(output, activation, fns); + util::insertFusedActivationLayer(output, + activation, fns); TensorAccess(input.ref(), inputData, inputShape); @@ -76,27 +77,24 @@ bool maxPoolFloat32(const float* inputData, const nnfw::rt::Shape& inputShape, return true; } -bool averagePoolFloat32(const float* inputData, const nnfw::rt::Shape& inputShape, - int32_t padding_left, int32_t padding_right, - int32_t padding_top, int32_t padding_bottom, - int32_t stride_width, int32_t stride_height, - int32_t filter_width, int32_t filter_height, - int32_t activation, - float* outputData, const nnfw::rt::Shape& outputShape) +bool averagePoolFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, + int32_t padding_left, int32_t padding_right, int32_t padding_top, + int32_t padding_bottom, int32_t stride_width, int32_t stride_height, + int32_t filter_width, int32_t filter_height, int32_t activation, + float *outputData, const nnfw::rt::Shape &outputShape) { arm_compute::TensorShape input_shape = util::fromNNShape(inputShape); arm_compute::TensorShape output_shape = util::fromNNShape(outputShape); std::vector> fns; - arm_compute::PadStrideInfo pad_info = arm_compute::PadStrideInfo(stride_width, stride_height, - padding_left, padding_right, - padding_top, padding_bottom, - arm_compute::DimensionRoundingType::FLOOR); + arm_compute::PadStrideInfo pad_info = arm_compute::PadStrideInfo( + stride_width, stride_height, padding_left, padding_right, padding_top, padding_bottom, + arm_compute::DimensionRoundingType::FLOOR); - arm_compute::PoolingLayerInfo pool_info = arm_compute::PoolingLayerInfo(arm_compute::PoolingType::AVG, - arm_compute::Size2D(filter_width,filter_height), - pad_info, true); + arm_compute::PoolingLayerInfo pool_info = arm_compute::PoolingLayerInfo( + arm_compute::PoolingType::AVG, arm_compute::Size2D(filter_width, filter_height), pad_info, + true); CLUniqueTensor input(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); CLUniqueTensor output(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); @@ -109,7 +107,8 @@ bool averagePoolFloat32(const float* inputData, const nnfw::rt::Shape& inputShap input.allocate(); output.allocate(); - util::insertFusedActivationLayer(output, activation, fns); + util::insertFusedActivationLayer(output, + activation, fns); TensorAccess(input.ref(), inputData, inputShape); diff --git a/libs/kernel/acl/src/cl/Pooling.test.cpp b/libs/kernel/acl/src/cl/Pooling.test.cpp index 8112e7a..0971e21 100644 --- a/libs/kernel/acl/src/cl/Pooling.test.cpp +++ b/libs/kernel/acl/src/cl/Pooling.test.cpp @@ -26,8 +26,8 @@ using namespace nnfw::kernel::acl; TEST(KernelACL_TC, maxPoolFloat32_3x3to1x1) { - util::TensorWrapper input({1,3,3,1}); - const nnfw::rt::Shape inputShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; + util::TensorWrapper input({1, 3, 3, 1}); + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; int32_t padding_left = 0; int32_t padding_right = 0; int32_t padding_top = 0; @@ -38,36 +38,30 @@ TEST(KernelACL_TC, maxPoolFloat32_3x3to1x1) int32_t filter_height = 3; float outputData[1]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,1,1,1}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 1, 1}, 1.0, 0}; bool bret; float value = 1.0f; - input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return value++; - }); + input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return value++; }); util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); int32_t activation = ANEURALNETWORKS_FUSED_NONE; - bret = maxPoolFloat32(input.ptr(), inputShape, - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - filter_width, filter_height, - activation, - outputData, outputShape); + bret = maxPoolFloat32(input.ptr(), inputShape, padding_left, padding_right, padding_top, + padding_bottom, stride_width, stride_height, filter_width, filter_height, + activation, outputData, outputShape); EXPECT_EQ(bret, true); - float expectData[] = { 9.0f }; + float expectData[] = {9.0f}; bret = util::compareData(outputData, expectData, outputShape); EXPECT_EQ(bret, true); } TEST(KernelACL_TC, maxPoolFloat32_3x3to1x1_RELU) { - util::TensorWrapper input({1,3,3,1}); - const nnfw::rt::Shape inputShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; + util::TensorWrapper input({1, 3, 3, 1}); + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; int32_t padding_left = 0; int32_t padding_right = 0; int32_t padding_top = 0; @@ -78,36 +72,30 @@ TEST(KernelACL_TC, maxPoolFloat32_3x3to1x1_RELU) int32_t filter_height = 3; float outputData[1]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,1,1,1}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 1, 1}, 1.0, 0}; bool bret; float value = -1.0f; - input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return value--; - }); + input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return value--; }); util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); int32_t activation = ANEURALNETWORKS_FUSED_RELU; - bret = maxPoolFloat32(input.ptr(), inputShape, - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - filter_width, filter_height, - activation, - outputData, outputShape); + bret = maxPoolFloat32(input.ptr(), inputShape, padding_left, padding_right, padding_top, + padding_bottom, stride_width, stride_height, filter_width, filter_height, + activation, outputData, outputShape); EXPECT_EQ(bret, true); - float expectData[] = { 0.0f }; + float expectData[] = {0.0f}; bret = util::compareData(outputData, expectData, outputShape); EXPECT_EQ(bret, true); } TEST(KernelACL_TC, maxPoolFloat32_3x3to2x2) { - util::TensorWrapper input({1,3,3,1}); - const nnfw::rt::Shape inputShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; + util::TensorWrapper input({1, 3, 3, 1}); + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; int32_t padding_left = 0; int32_t padding_right = 1; int32_t padding_top = 0; @@ -118,39 +106,30 @@ TEST(KernelACL_TC, maxPoolFloat32_3x3to2x2) int32_t filter_height = 2; float outputData[4]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,2,2,1}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 2, 2, 1}, 1.0, 0}; bool bret; float value = 1.0f; - input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return value++; - }); + input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return value++; }); util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); int32_t activation = ANEURALNETWORKS_FUSED_NONE; - bret = maxPoolFloat32(input.ptr(), inputShape, - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - filter_width, filter_height, - activation, - outputData, outputShape); + bret = maxPoolFloat32(input.ptr(), inputShape, padding_left, padding_right, padding_top, + padding_bottom, stride_width, stride_height, filter_width, filter_height, + activation, outputData, outputShape); EXPECT_EQ(bret, true); - float expectData[] = { - 5.0f, 6.0f, - 8.0f, 9.0f - }; + float expectData[] = {5.0f, 6.0f, 8.0f, 9.0f}; bret = util::compareData(outputData, expectData, outputShape); EXPECT_EQ(bret, true); } TEST(KernelACL_TC, maxPoolFloat32_147x147to73x73) { - util::TensorWrapper input({1,147,147,64}); - util::TensorWrapper output({1,73,73,64}); + util::TensorWrapper input({1, 147, 147, 64}); + util::TensorWrapper output({1, 73, 73, 64}); int32_t padding_left = 0; int32_t padding_right = 0; @@ -161,37 +140,27 @@ TEST(KernelACL_TC, maxPoolFloat32_147x147to73x73) int32_t filter_width = 3; int32_t filter_height = 3; - input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 1.0f; - }); + input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 0.f; - }); + output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); int32_t activation = ANEURALNETWORKS_FUSED_NONE; - bool bret = maxPoolFloat32(input.ptr(), input.shape(), - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - filter_width, filter_height, - activation, - output.ptr(), output.shape()); + bool bret = maxPoolFloat32(input.ptr(), input.shape(), padding_left, padding_right, + padding_top, padding_bottom, stride_width, stride_height, filter_width, + filter_height, activation, output.ptr(), output.shape()); EXPECT_EQ(bret, true); - util::TensorWrapper expected({1,73,73,64}); - expected.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 1.0f; - }); + util::TensorWrapper expected({1, 73, 73, 64}); + expected.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); EXPECT_EQ(output, expected); } TEST(KernelACL_TC, maxPoolFloat32_71x71to35x35) { - util::TensorWrapper input({1,71,71,192}); - util::TensorWrapper output({1,35,35,192}); + util::TensorWrapper input({1, 71, 71, 192}); + util::TensorWrapper output({1, 35, 35, 192}); int32_t padding_left = 0; int32_t padding_right = 0; @@ -202,37 +171,27 @@ TEST(KernelACL_TC, maxPoolFloat32_71x71to35x35) int32_t filter_width = 3; int32_t filter_height = 3; - input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 1.0f; - }); + input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 0.f; - }); + output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); int32_t activation = ANEURALNETWORKS_FUSED_NONE; - bool bret = maxPoolFloat32(input.ptr(), input.shape(), - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - filter_width, filter_height, - activation, - output.ptr(), output.shape()); + bool bret = maxPoolFloat32(input.ptr(), input.shape(), padding_left, padding_right, + padding_top, padding_bottom, stride_width, stride_height, filter_width, + filter_height, activation, output.ptr(), output.shape()); EXPECT_EQ(bret, true); - util::TensorWrapper expected({1,35,35,192}); - expected.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 1.0f; - }); + util::TensorWrapper expected({1, 35, 35, 192}); + expected.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); EXPECT_EQ(output, expected); } TEST(KernelACL_TC, averagePoolFloat32_3x3to1x1) { - util::TensorWrapper input({1,3,3,1}); - const nnfw::rt::Shape inputShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; + util::TensorWrapper input({1, 3, 3, 1}); + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; int32_t padding_left = 0; int32_t padding_right = 0; int32_t padding_top = 0; @@ -243,36 +202,30 @@ TEST(KernelACL_TC, averagePoolFloat32_3x3to1x1) int32_t filter_height = 3; float outputData[1]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,1,1,1}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 1, 1}, 1.0, 0}; bool bret; float value = 1.0f; - input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return value++; - }); + input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return value++; }); util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); int32_t activation = ANEURALNETWORKS_FUSED_NONE; - bret = averagePoolFloat32(input.ptr(), inputShape, - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - filter_width, filter_height, - activation, - outputData, outputShape); + bret = averagePoolFloat32(input.ptr(), inputShape, padding_left, padding_right, + padding_top, padding_bottom, stride_width, stride_height, filter_width, + filter_height, activation, outputData, outputShape); EXPECT_EQ(bret, true); - float expectData[] = { 5.0f }; + float expectData[] = {5.0f}; bret = util::compareData(outputData, expectData, outputShape); EXPECT_EQ(bret, true); } TEST(KernelACL_TC, averagePoolFloat32_3x3to1x1_RELU) { - util::TensorWrapper input({1,3,3,1}); - const nnfw::rt::Shape inputShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; + util::TensorWrapper input({1, 3, 3, 1}); + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; int32_t padding_left = 0; int32_t padding_right = 0; int32_t padding_top = 0; @@ -283,36 +236,30 @@ TEST(KernelACL_TC, averagePoolFloat32_3x3to1x1_RELU) int32_t filter_height = 3; float outputData[1]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,1,1,1}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 1, 1}, 1.0, 0}; bool bret; float value = 3.0f; - input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return value--; - }); + input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return value--; }); util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); int32_t activation = ANEURALNETWORKS_FUSED_RELU; - bret = averagePoolFloat32(input.ptr(), inputShape, - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - filter_width, filter_height, - activation, - outputData, outputShape); + bret = averagePoolFloat32(input.ptr(), inputShape, padding_left, padding_right, + padding_top, padding_bottom, stride_width, stride_height, filter_width, + filter_height, activation, outputData, outputShape); EXPECT_EQ(bret, true); - float expectData[] = { 0.0f }; + float expectData[] = {0.0f}; bret = util::compareData(outputData, expectData, outputShape); EXPECT_EQ(bret, true); } TEST(KernelACL_TC, averagePoolFloat32_3x3to2x2) { - util::TensorWrapper input({1,3,3,1}); - const nnfw::rt::Shape inputShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; + util::TensorWrapper input({1, 3, 3, 1}); + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; int32_t padding_left = 0; int32_t padding_right = 0; int32_t padding_top = 0; @@ -323,38 +270,29 @@ TEST(KernelACL_TC, averagePoolFloat32_3x3to2x2) int32_t filter_height = 2; float outputData[4]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,2,2,1}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 2, 2, 1}, 1.0, 0}; bool bret; float value = 1.0f; - input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return value++; - }); + input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return value++; }); util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); int32_t activation = ANEURALNETWORKS_FUSED_NONE; - bret = averagePoolFloat32(input.ptr(), inputShape, - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - filter_width, filter_height, - activation, - outputData, outputShape); + bret = averagePoolFloat32(input.ptr(), inputShape, padding_left, padding_right, + padding_top, padding_bottom, stride_width, stride_height, filter_width, + filter_height, activation, outputData, outputShape); EXPECT_EQ(bret, true); - float expectData[] = { - 3.0f, 4.0f, - 6.0f, 7.0f - }; + float expectData[] = {3.0f, 4.0f, 6.0f, 7.0f}; bret = util::compareData(outputData, expectData, outputShape); EXPECT_EQ(bret, true); } TEST(KernelACL_TC, averagePoolFloat32_3x3to3x3) { - std::vector dims = {1,3,3,1}; + std::vector dims = {1, 3, 3, 1}; util::TensorWrapper input(dims); util::TensorWrapper output(dims); @@ -367,28 +305,21 @@ TEST(KernelACL_TC, averagePoolFloat32_3x3to3x3) int32_t filter_width = 3; int32_t filter_height = 3; - int32_t value=1.0f; - input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return value++; - }); + int32_t value = 1.0f; + input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return value++; }); - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 0.f; - }); + output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); int32_t activation = ANEURALNETWORKS_FUSED_NONE; - bool bret = averagePoolFloat32(input.ptr(), input.shape(), - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - filter_width, filter_height, - activation, - output.ptr(), output.shape()); + bool bret = + averagePoolFloat32(input.ptr(), input.shape(), padding_left, padding_right, + padding_top, padding_bottom, stride_width, stride_height, filter_width, + filter_height, activation, output.ptr(), output.shape()); EXPECT_EQ(bret, true); util::TensorWrapper expected(dims); - float v=2.5f; + float v = 2.5f; expected.initValue([&v](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { v = v + 0.5f; return v; @@ -399,8 +330,8 @@ TEST(KernelACL_TC, averagePoolFloat32_3x3to3x3) TEST(KernelACL_TC, averagePoolFloat32_35x35to35x35) { - int32_t N=35; - std::vector dims = {1,35,35,768}; + int32_t N = 35; + std::vector dims = {1, 35, 35, 768}; util::TensorWrapper input(dims); util::TensorWrapper output(dims); @@ -413,37 +344,28 @@ TEST(KernelACL_TC, averagePoolFloat32_35x35to35x35) int32_t filter_width = 3; int32_t filter_height = 3; - input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 1.0f; - }); + input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 0.f; - }); + output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); int32_t activation = ANEURALNETWORKS_FUSED_NONE; - bool bret = averagePoolFloat32(input.ptr(), input.shape(), - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - filter_width, filter_height, - activation, - output.ptr(), output.shape()); + bool bret = + averagePoolFloat32(input.ptr(), input.shape(), padding_left, padding_right, + padding_top, padding_bottom, stride_width, stride_height, filter_width, + filter_height, activation, output.ptr(), output.shape()); EXPECT_EQ(bret, true); util::TensorWrapper expected(dims); - expected.initValue([&N](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 1.0f; - }); + expected.initValue([&N](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); EXPECT_EQ(output, expected); } TEST(KernelACL_TC, averagePoolFloat32_8x8to1x1) { - util::TensorWrapper input({1,8,8,2048}); - util::TensorWrapper output({1,1,1,2048}); + util::TensorWrapper input({1, 8, 8, 2048}); + util::TensorWrapper output({1, 1, 1, 2048}); int32_t padding_left = 0; int32_t padding_right = 0; @@ -454,29 +376,20 @@ TEST(KernelACL_TC, averagePoolFloat32_8x8to1x1) int32_t filter_width = 8; int32_t filter_height = 8; - input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 1.0f; - }); + input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 0.f; - }); + output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); int32_t activation = ANEURALNETWORKS_FUSED_NONE; - bool bret = averagePoolFloat32(input.ptr(), input.shape(), - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - filter_width, filter_height, - activation, - output.ptr(), output.shape()); + bool bret = + averagePoolFloat32(input.ptr(), input.shape(), padding_left, padding_right, + padding_top, padding_bottom, stride_width, stride_height, filter_width, + filter_height, activation, output.ptr(), output.shape()); EXPECT_EQ(bret, true); - util::TensorWrapper expected({1,1,1,2048}); - expected.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 1.0f; - }); + util::TensorWrapper expected({1, 1, 1, 2048}); + expected.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); EXPECT_EQ(output, expected); } diff --git a/libs/kernel/acl/src/cl/Reshape.cpp b/libs/kernel/acl/src/cl/Reshape.cpp index 69e2fdf..707333e 100644 --- a/libs/kernel/acl/src/cl/Reshape.cpp +++ b/libs/kernel/acl/src/cl/Reshape.cpp @@ -24,18 +24,20 @@ #include "../UniqueTensor.h" #include "../Reshape.h" -namespace nnfw { -namespace kernel { -namespace acl { +namespace nnfw +{ +namespace kernel +{ +namespace acl +{ -static void sync_scheduler() { - arm_compute::CLScheduler::get().sync(); -} +static void sync_scheduler() { arm_compute::CLScheduler::get().sync(); } -bool reshapeGeneric(const void* inputData, const nnfw::rt::Shape& inputShape, - void* outputData, const nnfw::rt::Shape& outputShape) { - return common::reshapeGeneric - (inputData, inputShape, outputData, outputShape, sync_scheduler); +bool reshapeGeneric(const void *inputData, const nnfw::rt::Shape &inputShape, void *outputData, + const nnfw::rt::Shape &outputShape) +{ + return common::reshapeGeneric( + inputData, inputShape, outputData, outputShape, sync_scheduler); } } // namespace acl diff --git a/libs/kernel/acl/src/cl/Softmax.cpp b/libs/kernel/acl/src/cl/Softmax.cpp index 1b2a336..09a430a 100644 --- a/libs/kernel/acl/src/cl/Softmax.cpp +++ b/libs/kernel/acl/src/cl/Softmax.cpp @@ -24,13 +24,15 @@ #include "../UniqueTensor.h" #include "../util.h" -namespace nnfw { -namespace kernel { -namespace acl { +namespace nnfw +{ +namespace kernel +{ +namespace acl +{ -bool softmaxFloat32(const float* inputData, const nnfw::rt::Shape& inputShape, - const float beta, - float* outputData, const nnfw::rt::Shape& outputShape) +bool softmaxFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, const float beta, + float *outputData, const nnfw::rt::Shape &outputShape) { arm_compute::TensorShape input_shape = util::fromNNShape(inputShape); arm_compute::TensorShape output_shape = util::fromNNShape(outputShape); diff --git a/libs/kernel/acl/src/cl/Softmax.test.cpp b/libs/kernel/acl/src/cl/Softmax.test.cpp index 8ee8b41..d121314 100644 --- a/libs/kernel/acl/src/cl/Softmax.test.cpp +++ b/libs/kernel/acl/src/cl/Softmax.test.cpp @@ -27,9 +27,9 @@ using namespace nnfw::kernel::acl; TEST(KernelACL_TC, softmaxFloat32_1xn) { float inputData[4]; - const nnfw::rt::Shape inputShape = { OperandType::FLOAT32, {1,4}, 1.0, 0 }; + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 4}, 1.0, 0}; float outputData[4]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,4}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 4}, 1.0, 0}; const float beta = 1.0f; bool bret; @@ -39,7 +39,7 @@ TEST(KernelACL_TC, softmaxFloat32_1xn) bret = softmaxFloat32(inputData, inputShape, beta, outputData, outputShape); EXPECT_EQ(bret, true); - float expectData[] = { 0.25f, 0.25f, 0.25f, 0.25f }; + float expectData[] = {0.25f, 0.25f, 0.25f, 0.25f}; bret = util::compareData(outputData, expectData, outputShape); EXPECT_EQ(bret, true); } @@ -47,9 +47,9 @@ TEST(KernelACL_TC, softmaxFloat32_1xn) TEST(KernelACL_TC, softmaxFloat32_4d) { float inputData[4]; - const nnfw::rt::Shape inputShape = { OperandType::FLOAT32, {1,1,4,1}, 1.0, 0 }; + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 1, 4, 1}, 1.0, 0}; float outputData[4]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,1,4,1}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 4, 1}, 1.0, 0}; const float beta = 1.0f; bool bret; @@ -59,7 +59,7 @@ TEST(KernelACL_TC, softmaxFloat32_4d) bret = softmaxFloat32(inputData, inputShape, beta, outputData, outputShape); EXPECT_EQ(bret, true); - float expectData[] = { 0.25f, 0.25f, 0.25f, 0.25f }; + float expectData[] = {0.25f, 0.25f, 0.25f, 0.25f}; bret = util::compareData(outputData, expectData, outputShape); EXPECT_EQ(bret, true); } @@ -67,9 +67,9 @@ TEST(KernelACL_TC, softmaxFloat32_4d) TEST(KernelACL_TC, softmaxFloat32_1xn_seq) { float inputData[4]; - const nnfw::rt::Shape inputShape = { OperandType::FLOAT32, {1,4}, 1.0, 0 }; + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 4}, 1.0, 0}; float outputData[4]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,4}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 4}, 1.0, 0}; const float beta = 1.0f; bool bret; @@ -87,9 +87,9 @@ TEST(KernelACL_TC, softmaxFloat32_1xn_seq) TEST(KernelACL_TC, softmaxFloat32_4d_seq) { float inputData[4]; - const nnfw::rt::Shape inputShape = { OperandType::FLOAT32, {1,1,4,1}, 1.0, 0 }; + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 1, 4, 1}, 1.0, 0}; float outputData[4]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,1,4,1}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 4, 1}, 1.0, 0}; const float beta = 1.0f; bool bret; diff --git a/libs/kernel/acl/src/gtest_env.cpp b/libs/kernel/acl/src/gtest_env.cpp index f6fc52f..d17fcbe 100644 --- a/libs/kernel/acl/src/gtest_env.cpp +++ b/libs/kernel/acl/src/gtest_env.cpp @@ -22,10 +22,7 @@ class TestEnvironment : public ::testing::Environment public: virtual ~TestEnvironment() = default; - virtual void SetUp() - { - nnfw::kernel::acl::Initialize(); - } + virtual void SetUp() { nnfw::kernel::acl::Initialize(); } virtual void TearDown() { @@ -33,5 +30,5 @@ public: } }; -static ::testing::Environment* const testingenv = - ::testing::AddGlobalTestEnvironment(new TestEnvironment); +static ::testing::Environment *const testingenv = + ::testing::AddGlobalTestEnvironment(new TestEnvironment); diff --git a/libs/kernel/acl/src/neon/Concatenation.cpp b/libs/kernel/acl/src/neon/Concatenation.cpp index 8738a9d..2b494eb 100644 --- a/libs/kernel/acl/src/neon/Concatenation.cpp +++ b/libs/kernel/acl/src/neon/Concatenation.cpp @@ -24,14 +24,18 @@ #include "../IO_accessor.h" #include "../shape.h" -namespace nnfw { -namespace kernel { -namespace acl { -namespace neon { - -bool concatenationFloat32(const std::vector& inputDataPtrs, - const std::vector& inputShapes, int32_t axis, - float* outputData, const nnfw::rt::Shape& outputShape) +namespace nnfw +{ +namespace kernel +{ +namespace acl +{ +namespace neon +{ + +bool concatenationFloat32(const std::vector &inputDataPtrs, + const std::vector &inputShapes, int32_t axis, + float *outputData, const nnfw::rt::Shape &outputShape) { if (axis != 3) { @@ -40,17 +44,17 @@ bool concatenationFloat32(const std::vector& inputDataPtrs, } assert(inputDataPtrs.size() == inputShapes.size()); - std::vector inputPtrs; - std::vector inputIptrs; + std::vector inputPtrs; + std::vector inputIptrs; arm_compute::Tensor output; // init Tensors std::vector::const_iterator it_inputShape = inputShapes.begin(); for (auto inputData : inputDataPtrs) { - const nnfw::rt::Shape& inputShape = *it_inputShape; + const nnfw::rt::Shape &inputShape = *it_inputShape; arm_compute::TensorShape input_shape = util::fromNNShape(inputShape); - arm_compute::Tensor* inputPtr = new arm_compute::Tensor(); + arm_compute::Tensor *inputPtr = new arm_compute::Tensor(); inputPtr->allocator()->init(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); inputPtrs.push_back(inputPtr); @@ -67,13 +71,13 @@ bool concatenationFloat32(const std::vector& inputDataPtrs, // allocate Tensors it_inputShape = inputShapes.begin(); - std::vector::const_iterator it_inputData = inputDataPtrs.begin(); + std::vector::const_iterator it_inputData = inputDataPtrs.begin(); for (auto inputPtr : inputPtrs) { inputPtr->allocator()->allocate(); - const float* inputData = *it_inputData; - const nnfw::rt::Shape& inputShape = *it_inputShape; + const float *inputData = *it_inputData; + const nnfw::rt::Shape &inputShape = *it_inputShape; TensorAccess(*inputPtr, inputData, inputShape); diff --git a/libs/kernel/acl/src/neon/Concatenation.test.cpp b/libs/kernel/acl/src/neon/Concatenation.test.cpp index 03b05bd..4fe2451 100644 --- a/libs/kernel/acl/src/neon/Concatenation.test.cpp +++ b/libs/kernel/acl/src/neon/Concatenation.test.cpp @@ -27,17 +27,17 @@ using namespace nnfw::kernel::acl; TEST(KernelACL_TC, neon_concatFloat32_1) { float inputData_1[6] = { - 1, 2, 3, 4, 5, 6 // [ [ [1],[2],[3] ], [ [4],[5],[6] ] ] + 1, 2, 3, 4, 5, 6 // [ [ [1],[2],[3] ], [ [4],[5],[6] ] ] }; float inputData_2[6] = { - 7, 8, 9, 10, 11, 12 // [ [ [7],[8],[9] ], [ [10],[11],[12] ] ] + 7, 8, 9, 10, 11, 12 // [ [ [7],[8],[9] ], [ [10],[11],[12] ] ] }; - const nnfw::rt::Shape inputShape_1 = { OperandType::FLOAT32, {1,2,3,1}, 1.0, 0 }; - const nnfw::rt::Shape inputShape_2 = { OperandType::FLOAT32, {1,2,3,1}, 1.0, 0 }; - std::vector inputDataPtrs; + const nnfw::rt::Shape inputShape_1 = {OperandType::FLOAT32, {1, 2, 3, 1}, 1.0, 0}; + const nnfw::rt::Shape inputShape_2 = {OperandType::FLOAT32, {1, 2, 3, 1}, 1.0, 0}; + std::vector inputDataPtrs; std::vector inputShapes; float outputData[12]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,2,3,2}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 2, 3, 2}, 1.0, 0}; bool bret; inputDataPtrs.push_back(inputData_1); @@ -47,14 +47,10 @@ TEST(KernelACL_TC, neon_concatFloat32_1) util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - bret = neon::concatenationFloat32(inputDataPtrs, inputShapes, 3, - outputData, outputShape); + bret = neon::concatenationFloat32(inputDataPtrs, inputShapes, 3, outputData, outputShape); EXPECT_EQ(bret, true); - float expectNCHW[] = { - 1, 2, 3, 4, 5, 6, - 7, 8, 9, 10, 11, 12 - }; + float expectNCHW[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; float expectData[12]; // [ [ [1,7],[2,8],[3,9] ], [ [4,10],[5,11],[6,12] ] ] util::NCHW2NHWC(expectNCHW, expectData, outputShape); bret = util::compareData(outputData, expectData, outputShape); diff --git a/libs/kernel/acl/src/neon/Conv2D.cpp b/libs/kernel/acl/src/neon/Conv2D.cpp index 8c0e8a4..87372d7 100644 --- a/libs/kernel/acl/src/neon/Conv2D.cpp +++ b/libs/kernel/acl/src/neon/Conv2D.cpp @@ -32,30 +32,31 @@ #include "support/nnapi/feature/Reader.h" -namespace nnfw { -namespace kernel { -namespace acl { -namespace neon { +namespace nnfw +{ +namespace kernel +{ +namespace acl +{ +namespace neon +{ static int verbose = 0; -bool convFloat32(const float* inputData, const nnfw::rt::Shape& inputShape, - const float* filterData, const nnfw::rt::Shape& filterShape, - const float* biasData, const nnfw::rt::Shape& biasShape, - int32_t padding_left, int32_t padding_right, - int32_t padding_top, int32_t padding_bottom, - int32_t stride_width, int32_t stride_height, - int32_t activation, - float* outputData, const nnfw::rt::Shape& outputShape) +bool convFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, const float *filterData, + const nnfw::rt::Shape &filterShape, const float *biasData, + const nnfw::rt::Shape &biasShape, int32_t padding_left, int32_t padding_right, + int32_t padding_top, int32_t padding_bottom, int32_t stride_width, + int32_t stride_height, int32_t activation, float *outputData, + const nnfw::rt::Shape &outputShape) { arm_compute::TensorShape input_shape = util::fromNNShape(inputShape); arm_compute::TensorShape filter_shape = util::fromNNShape(filterShape); arm_compute::TensorShape bias_shape = util::fromVectorNNShape(biasShape); arm_compute::TensorShape output_shape = util::fromNNShape(outputShape); - arm_compute::PadStrideInfo conv_info = arm_compute::PadStrideInfo(stride_width, stride_height, - padding_left, padding_right, - padding_top, padding_bottom, - arm_compute::DimensionRoundingType::FLOOR); + arm_compute::PadStrideInfo conv_info = arm_compute::PadStrideInfo( + stride_width, stride_height, padding_left, padding_right, padding_top, padding_bottom, + arm_compute::DimensionRoundingType::FLOOR); NEUniqueTensor input(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); NEUniqueTensor output(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); @@ -70,7 +71,8 @@ bool convFloat32(const float* inputData, const nnfw::rt::Shape& inputShape, fns.emplace_back(conv_f); - util::insertFusedActivationLayer(output, activation, fns); + util::insertFusedActivationLayer(output, + activation, fns); input.allocate(); output.allocate(); @@ -86,10 +88,11 @@ bool convFloat32(const float* inputData, const nnfw::rt::Shape& inputShape, { auto ifm_shape = nnfw::support::nnapi::feature::asFeatureShape(inputShape); nnfw::support::nnapi::feature::Reader nnapi_ifm_reader{ifm_shape, inputData}; - nnfw::support::acl::feature::Reader acl_ifm_reader{ input.ptr() }; + nnfw::support::acl::feature::Reader acl_ifm_reader{input.ptr()}; std::cout << "NNAPI IFM:" << std::endl; - std::cout << nnfw::util::feature::TextFormatter{ifm_shape, nnapi_ifm_reader} << std::endl; + std::cout << nnfw::util::feature::TextFormatter{ifm_shape, nnapi_ifm_reader} + << std::endl; std::cout << "ARM Compute IFM:" << std::endl; std::cout << nnfw::util::feature::TextFormatter{ifm_shape, acl_ifm_reader} << std::endl; diff --git a/libs/kernel/acl/src/neon/Conv2D.test.cpp b/libs/kernel/acl/src/neon/Conv2D.test.cpp index 6a3de1c..3adb938 100644 --- a/libs/kernel/acl/src/neon/Conv2D.test.cpp +++ b/libs/kernel/acl/src/neon/Conv2D.test.cpp @@ -27,11 +27,11 @@ using namespace nnfw::kernel::acl; TEST(KernelACL_TC, neon_convFloat32_3x3to1x1) { float inputData[9]; - const nnfw::rt::Shape inputShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; float filterData[9]; - const nnfw::rt::Shape filterShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; - float biasData[1] = { 1.0 }; - const nnfw::rt::Shape biasShape = { OperandType::FLOAT32, {1}, 1.0, 0 }; + const nnfw::rt::Shape filterShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; + float biasData[1] = {1.0}; + const nnfw::rt::Shape biasShape = {OperandType::FLOAT32, {1}, 1.0, 0}; int32_t padding_left = 0; int32_t padding_right = 0; int32_t padding_top = 0; @@ -40,24 +40,19 @@ TEST(KernelACL_TC, neon_convFloat32_3x3to1x1) int32_t stride_height = 1; int32_t activation = static_cast(FusedActivationFunc::RELU); float outputData[1]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,1,1,1}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 1, 1}, 1.0, 0}; bool bret; util::initData(inputData, sizeof(inputData) / sizeof(inputData[0]), 1.0); util::initData(filterData, sizeof(filterData) / sizeof(filterData[0]), 1.0); util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - bret = neon::convFloat32(inputData, inputShape, - filterData, filterShape, - biasData, biasShape, - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - activation, - outputData, outputShape); + bret = neon::convFloat32(inputData, inputShape, filterData, filterShape, biasData, biasShape, + padding_left, padding_right, padding_top, padding_bottom, stride_width, + stride_height, activation, outputData, outputShape); EXPECT_EQ(bret, true); - float expectData[] = { 10.0f }; + float expectData[] = {10.0f}; bret = util::compareData(outputData, expectData, outputShape); EXPECT_EQ(bret, true); } @@ -65,11 +60,11 @@ TEST(KernelACL_TC, neon_convFloat32_3x3to1x1) TEST(KernelACL_TC, neon_convFloat32_3x3to3x3) { float inputData[9]; - const nnfw::rt::Shape inputShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; float filterData[9]; - const nnfw::rt::Shape filterShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; - float biasData[1] = { 1.0 }; - const nnfw::rt::Shape biasShape = { OperandType::FLOAT32, {1}, 1.0, 0 }; + const nnfw::rt::Shape filterShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; + float biasData[1] = {1.0}; + const nnfw::rt::Shape biasShape = {OperandType::FLOAT32, {1}, 1.0, 0}; int32_t padding_left = 1; int32_t padding_right = 1; int32_t padding_top = 1; @@ -78,28 +73,19 @@ TEST(KernelACL_TC, neon_convFloat32_3x3to3x3) int32_t stride_height = 1; int32_t activation = static_cast(FusedActivationFunc::RELU); float outputData[9]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; bool bret; util::initData(inputData, sizeof(inputData) / sizeof(inputData[0]), 1.0); util::initData(filterData, sizeof(filterData) / sizeof(filterData[0]), 1.0); util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - bret = neon::convFloat32(inputData, inputShape, - filterData, filterShape, - biasData, biasShape, - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - activation, - outputData, outputShape); + bret = neon::convFloat32(inputData, inputShape, filterData, filterShape, biasData, biasShape, + padding_left, padding_right, padding_top, padding_bottom, stride_width, + stride_height, activation, outputData, outputShape); EXPECT_EQ(bret, true); - float expectData[] = { - 5.0f, 7.0f, 5.0f, - 7.0f, 10.0f, 7.0f, - 5.0f, 7.0f, 5.0f - }; + float expectData[] = {5.0f, 7.0f, 5.0f, 7.0f, 10.0f, 7.0f, 5.0f, 7.0f, 5.0f}; bret = util::compareData(outputData, expectData, outputShape); EXPECT_EQ(bret, true); } @@ -107,11 +93,11 @@ TEST(KernelACL_TC, neon_convFloat32_3x3to3x3) TEST(KernelACL_TC, neon_convFloat32_3x3to3x3_RELU) { float inputData[9]; - const nnfw::rt::Shape inputShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; float filterData[9]; - const nnfw::rt::Shape filterShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; - float biasData[1] = { -5.0f }; - const nnfw::rt::Shape biasShape = { OperandType::FLOAT32, {1}, 1.0, 0 }; + const nnfw::rt::Shape filterShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; + float biasData[1] = {-5.0f}; + const nnfw::rt::Shape biasShape = {OperandType::FLOAT32, {1}, 1.0, 0}; int32_t padding_left = 1; int32_t padding_right = 1; int32_t padding_top = 1; @@ -120,29 +106,19 @@ TEST(KernelACL_TC, neon_convFloat32_3x3to3x3_RELU) int32_t stride_height = 1; int32_t activation = static_cast(FusedActivationFunc::RELU); float outputData[9]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; bool bret; util::initData(inputData, sizeof(inputData) / sizeof(inputData[0]), 1.0); util::initData(filterData, sizeof(filterData) / sizeof(filterData[0]), 1.0); util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - bret = neon::convFloat32(inputData, inputShape, - filterData, filterShape, - biasData, biasShape, - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - activation, - outputData, outputShape); + bret = neon::convFloat32(inputData, inputShape, filterData, filterShape, biasData, biasShape, + padding_left, padding_right, padding_top, padding_bottom, stride_width, + stride_height, activation, outputData, outputShape); EXPECT_EQ(bret, true); - float expectData[] = - { - 0.0f, 1.0f, 0.0f, - 1.0f, 4.0f, 1.0f, - 0.0f, 1.0f, 0.0f - }; + float expectData[] = {0.0f, 1.0f, 0.0f, 1.0f, 4.0f, 1.0f, 0.0f, 1.0f, 0.0f}; bret = util::compareData(outputData, expectData, outputShape); EXPECT_EQ(bret, true); @@ -150,19 +126,12 @@ TEST(KernelACL_TC, neon_convFloat32_3x3to3x3_RELU) TEST(KernelACL_TC, neon_convFloat32_3x5to3x3) { - float inputData[15] = { - 1,2,3,4,5, - 6,7,8,9,10, - 11,12,13,14,15 - }; - const nnfw::rt::Shape inputShape = { OperandType::FLOAT32, {1,3,5,1}, 1.0, 0 }; - float filterData[18] = { - 1,1,1, 1,1,1, 1,1,1, - 2,2,2, 2,2,2, 2,2,2 - }; - const nnfw::rt::Shape filterShape = { OperandType::FLOAT32, {2,3,3,1}, 1.0, 0 }; - float biasData[2] = { 1.0, 1.0 }; - const nnfw::rt::Shape biasShape = { OperandType::FLOAT32, {2}, 1.0, 0 }; + float inputData[15] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 5, 1}, 1.0, 0}; + float filterData[18] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2}; + const nnfw::rt::Shape filterShape = {OperandType::FLOAT32, {2, 3, 3, 1}, 1.0, 0}; + float biasData[2] = {1.0, 1.0}; + const nnfw::rt::Shape biasShape = {OperandType::FLOAT32, {2}, 1.0, 0}; int32_t padding_left = 1; int32_t padding_right = 1; int32_t padding_top = 1; @@ -171,30 +140,21 @@ TEST(KernelACL_TC, neon_convFloat32_3x5to3x3) int32_t stride_height = 1; int32_t activation = static_cast(FusedActivationFunc::RELU); float outputData[30]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,3,5,2}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 3, 5, 2}, 1.0, 0}; bool bret; util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); - bret = neon::convFloat32(inputData, inputShape, - filterData, filterShape, - biasData, biasShape, - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - activation, - outputData, outputShape); + bret = neon::convFloat32(inputData, inputShape, filterData, filterShape, biasData, biasShape, + padding_left, padding_right, padding_top, padding_bottom, stride_width, + stride_height, activation, outputData, outputShape); EXPECT_EQ(bret, true); - float expectNCHW[] = { - 17.0f, 28.0f, 34.0f, 40.0f, 29.0f, - 40.0f, 64.0f, 73.0f, 82.0f, 58.0f, - 37.0f, 58.0f, 64.0f, 70.0f, 49.0f, + float expectNCHW[] = {17.0f, 28.0f, 34.0f, 40.0f, 29.0f, 40.0f, 64.0f, 73.0f, + 82.0f, 58.0f, 37.0f, 58.0f, 64.0f, 70.0f, 49.0f, - 33.0f, 55.0f, 67.0f, 79.0f, 57.0f, - 79.0f, 127.0f, 145.0f, 163.0f, 115.0f, - 73.0f, 115.0f, 127.0f, 139.0f, 97.0f - }; + 33.0f, 55.0f, 67.0f, 79.0f, 57.0f, 79.0f, 127.0f, 145.0f, + 163.0f, 115.0f, 73.0f, 115.0f, 127.0f, 139.0f, 97.0f}; float expectData[30]; util::NCHW2NHWC(expectNCHW, expectData, outputShape); bret = util::compareData(outputData, expectData, outputShape); diff --git a/libs/kernel/acl/src/neon/DepthwiseConv2D.cpp b/libs/kernel/acl/src/neon/DepthwiseConv2D.cpp index 94ca085..b40a65c 100644 --- a/libs/kernel/acl/src/neon/DepthwiseConv2D.cpp +++ b/libs/kernel/acl/src/neon/DepthwiseConv2D.cpp @@ -27,32 +27,30 @@ #include "../UniqueTensor.h" #include "../DepthwiseConv2D.h" -namespace nnfw { -namespace kernel { -namespace acl { +namespace nnfw +{ +namespace kernel +{ +namespace acl +{ -namespace neon { -static void sync_scheduler() { -} +namespace neon +{ +static void sync_scheduler() {} -bool depthwiseConvFloat32(const float* inputData, const nnfw::rt::Shape& inputShape, - const float* filterData, const nnfw::rt::Shape& filterShape, - const float* biasData, const nnfw::rt::Shape& biasShape, - int32_t padding_left, int32_t padding_right, - int32_t padding_top, int32_t padding_bottom, - int32_t stride_width, int32_t stride_height, - int32_t depth_multiplier, int32_t activation, - float* outputData, const nnfw::rt::Shape& outputShape) { +bool depthwiseConvFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, + const float *filterData, const nnfw::rt::Shape &filterShape, + const float *biasData, const nnfw::rt::Shape &biasShape, + int32_t padding_left, int32_t padding_right, int32_t padding_top, + int32_t padding_bottom, int32_t stride_width, int32_t stride_height, + int32_t depth_multiplier, int32_t activation, float *outputData, + const nnfw::rt::Shape &outputShape) +{ return common::depthwiseConvFloat32(inputData, inputShape, - filterData, filterShape, - biasData, biasShape, - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - depth_multiplier, activation, - outputData, outputShape, - sync_scheduler); + arm_compute::NEActivationLayer>( + inputData, inputShape, filterData, filterShape, biasData, biasShape, padding_left, + padding_right, padding_top, padding_bottom, stride_width, stride_height, depth_multiplier, + activation, outputData, outputShape, sync_scheduler); } } // namespace neon diff --git a/libs/kernel/acl/src/neon/FullyConnected.cpp b/libs/kernel/acl/src/neon/FullyConnected.cpp index 397dd17..c245925 100644 --- a/libs/kernel/acl/src/neon/FullyConnected.cpp +++ b/libs/kernel/acl/src/neon/FullyConnected.cpp @@ -27,32 +27,32 @@ #include "../UniqueTensor.h" #include "../FullyConnected.h" -namespace nnfw { -namespace kernel { -namespace acl { +namespace nnfw +{ +namespace kernel +{ +namespace acl +{ -namespace neon { +namespace neon +{ -void sync_scheduler() { -} +void sync_scheduler() {} -bool fullyConnectedFloat32(const float* inputData, const nnfw::rt::Shape& inputShape, - const float* weightsData, const nnfw::rt::Shape& weightsShape, - const float* biasData, const nnfw::rt::Shape& biasShape, - int32_t activation, - float* outputData, const nnfw::rt::Shape& outputShape) { +bool fullyConnectedFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, + const float *weightsData, const nnfw::rt::Shape &weightsShape, + const float *biasData, const nnfw::rt::Shape &biasShape, + int32_t activation, float *outputData, + const nnfw::rt::Shape &outputShape) +{ return common::fullyConnectedFloat32(inputData, inputShape, - weightsData, weightsShape, - biasData, biasShape, - activation, - outputData, outputShape, - sync_scheduler); + arm_compute::NEActivationLayer>( + inputData, inputShape, weightsData, weightsShape, biasData, biasShape, activation, outputData, + outputShape, sync_scheduler); } } // namespace neon } // namespace acl } // namespace kernel } // namespace nnfw - diff --git a/libs/kernel/acl/src/neon/FullyConnected.test.cpp b/libs/kernel/acl/src/neon/FullyConnected.test.cpp index d4c95e4..baf0681 100644 --- a/libs/kernel/acl/src/neon/FullyConnected.test.cpp +++ b/libs/kernel/acl/src/neon/FullyConnected.test.cpp @@ -18,4 +18,3 @@ #define ACL_TEST(tc, t) TEST(tc, neon_##t) #include "../FullyConnected.test.h" - diff --git a/libs/kernel/acl/src/neon/Pooling.cpp b/libs/kernel/acl/src/neon/Pooling.cpp index 0cf5831..d1665e5 100644 --- a/libs/kernel/acl/src/neon/Pooling.cpp +++ b/libs/kernel/acl/src/neon/Pooling.cpp @@ -23,32 +23,33 @@ #include -namespace nnfw { -namespace kernel { -namespace acl { -namespace neon { - -bool maxPoolFloat32(const float* inputData, const nnfw::rt::Shape& inputShape, - int32_t padding_left, int32_t padding_right, - int32_t padding_top, int32_t padding_bottom, - int32_t stride_width, int32_t stride_height, - int32_t filter_width, int32_t filter_height, - int32_t activation, - float* outputData, const nnfw::rt::Shape& outputShape) +namespace nnfw +{ +namespace kernel +{ +namespace acl +{ +namespace neon +{ + +bool maxPoolFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, int32_t padding_left, + int32_t padding_right, int32_t padding_top, int32_t padding_bottom, + int32_t stride_width, int32_t stride_height, int32_t filter_width, + int32_t filter_height, int32_t activation, float *outputData, + const nnfw::rt::Shape &outputShape) { arm_compute::TensorShape input_shape = util::fromNNShape(inputShape); arm_compute::TensorShape output_shape = util::fromNNShape(outputShape); std::vector> fns; - arm_compute::PadStrideInfo pad_info = arm_compute::PadStrideInfo(stride_width, stride_height, - padding_left, padding_right, - padding_top, padding_bottom, - arm_compute::DimensionRoundingType::FLOOR); + arm_compute::PadStrideInfo pad_info = arm_compute::PadStrideInfo( + stride_width, stride_height, padding_left, padding_right, padding_top, padding_bottom, + arm_compute::DimensionRoundingType::FLOOR); - arm_compute::PoolingLayerInfo maxpool_info = arm_compute::PoolingLayerInfo(arm_compute::PoolingType::MAX, - arm_compute::Size2D(filter_width,filter_height), - pad_info, false); + arm_compute::PoolingLayerInfo maxpool_info = arm_compute::PoolingLayerInfo( + arm_compute::PoolingType::MAX, arm_compute::Size2D(filter_width, filter_height), pad_info, + false); NEUniqueTensor input(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); NEUniqueTensor output(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); @@ -58,7 +59,8 @@ bool maxPoolFloat32(const float* inputData, const nnfw::rt::Shape& inputShape, fns.emplace_back(pool_f); - util::insertFusedActivationLayer(output, activation, fns); + util::insertFusedActivationLayer(output, + activation, fns); input.allocate(); output.allocate(); @@ -75,27 +77,24 @@ bool maxPoolFloat32(const float* inputData, const nnfw::rt::Shape& inputShape, return true; } -bool averagePoolFloat32(const float* inputData, const nnfw::rt::Shape& inputShape, - int32_t padding_left, int32_t padding_right, - int32_t padding_top, int32_t padding_bottom, - int32_t stride_width, int32_t stride_height, - int32_t filter_width, int32_t filter_height, - int32_t activation, - float* outputData, const nnfw::rt::Shape& outputShape) +bool averagePoolFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, + int32_t padding_left, int32_t padding_right, int32_t padding_top, + int32_t padding_bottom, int32_t stride_width, int32_t stride_height, + int32_t filter_width, int32_t filter_height, int32_t activation, + float *outputData, const nnfw::rt::Shape &outputShape) { arm_compute::TensorShape input_shape = util::fromNNShape(inputShape); arm_compute::TensorShape output_shape = util::fromNNShape(outputShape); std::vector> fns; - arm_compute::PadStrideInfo pad_info = arm_compute::PadStrideInfo(stride_width, stride_height, - padding_left, padding_right, - padding_top, padding_bottom, - arm_compute::DimensionRoundingType::FLOOR); + arm_compute::PadStrideInfo pad_info = arm_compute::PadStrideInfo( + stride_width, stride_height, padding_left, padding_right, padding_top, padding_bottom, + arm_compute::DimensionRoundingType::FLOOR); - arm_compute::PoolingLayerInfo pool_info = arm_compute::PoolingLayerInfo(arm_compute::PoolingType::AVG, - arm_compute::Size2D(filter_width,filter_height), - pad_info, true); + arm_compute::PoolingLayerInfo pool_info = arm_compute::PoolingLayerInfo( + arm_compute::PoolingType::AVG, arm_compute::Size2D(filter_width, filter_height), pad_info, + true); NEUniqueTensor input(arm_compute::TensorInfo(input_shape, arm_compute::Format::F32)); NEUniqueTensor output(arm_compute::TensorInfo(output_shape, arm_compute::Format::F32)); @@ -105,7 +104,8 @@ bool averagePoolFloat32(const float* inputData, const nnfw::rt::Shape& inputShap fns.emplace_back(pool_f); - util::insertFusedActivationLayer(output, activation, fns); + util::insertFusedActivationLayer(output, + activation, fns); input.allocate(); output.allocate(); diff --git a/libs/kernel/acl/src/neon/Pooling.test.cpp b/libs/kernel/acl/src/neon/Pooling.test.cpp index 4e65939..07159a6 100644 --- a/libs/kernel/acl/src/neon/Pooling.test.cpp +++ b/libs/kernel/acl/src/neon/Pooling.test.cpp @@ -26,8 +26,8 @@ using namespace nnfw::kernel::acl; TEST(KernelACL_TC, neon_maxPoolFloat32_3x3to1x1) { - util::TensorWrapper input({1,3,3,1}); - const nnfw::rt::Shape inputShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; + util::TensorWrapper input({1, 3, 3, 1}); + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; int32_t padding_left = 0; int32_t padding_right = 0; int32_t padding_top = 0; @@ -38,36 +38,30 @@ TEST(KernelACL_TC, neon_maxPoolFloat32_3x3to1x1) int32_t filter_height = 3; float outputData[1]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,1,1,1}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 1, 1}, 1.0, 0}; bool bret; float value = 1.0f; - input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return value++; - }); + input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return value++; }); util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); int32_t activation = ANEURALNETWORKS_FUSED_NONE; - bret = neon::maxPoolFloat32(input.ptr(), inputShape, - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - filter_width, filter_height, - activation, - outputData, outputShape); + bret = neon::maxPoolFloat32(input.ptr(), inputShape, padding_left, padding_right, + padding_top, padding_bottom, stride_width, stride_height, + filter_width, filter_height, activation, outputData, outputShape); EXPECT_EQ(bret, true); - float expectData[] = { 9.0f }; + float expectData[] = {9.0f}; bret = util::compareData(outputData, expectData, outputShape); EXPECT_EQ(bret, true); } TEST(KernelACL_TC, neon_maxPoolFloat32_3x3to1x1_RELU) { - util::TensorWrapper input({1,3,3,1}); - const nnfw::rt::Shape inputShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; + util::TensorWrapper input({1, 3, 3, 1}); + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; int32_t padding_left = 0; int32_t padding_right = 0; int32_t padding_top = 0; @@ -78,36 +72,30 @@ TEST(KernelACL_TC, neon_maxPoolFloat32_3x3to1x1_RELU) int32_t filter_height = 3; float outputData[1]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,1,1,1}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 1, 1}, 1.0, 0}; bool bret; float value = -1.0f; - input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return value--; - }); + input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return value--; }); util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); int32_t activation = ANEURALNETWORKS_FUSED_RELU; - bret = neon::maxPoolFloat32(input.ptr(), inputShape, - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - filter_width, filter_height, - activation, - outputData, outputShape); + bret = neon::maxPoolFloat32(input.ptr(), inputShape, padding_left, padding_right, + padding_top, padding_bottom, stride_width, stride_height, + filter_width, filter_height, activation, outputData, outputShape); EXPECT_EQ(bret, true); - float expectData[] = { 0.0f }; + float expectData[] = {0.0f}; bret = util::compareData(outputData, expectData, outputShape); EXPECT_EQ(bret, true); } TEST(KernelACL_TC, neon_maxPoolFloat32_3x3to2x2) { - util::TensorWrapper input({1,3,3,1}); - const nnfw::rt::Shape inputShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; + util::TensorWrapper input({1, 3, 3, 1}); + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; int32_t padding_left = 0; int32_t padding_right = 1; int32_t padding_top = 0; @@ -118,39 +106,30 @@ TEST(KernelACL_TC, neon_maxPoolFloat32_3x3to2x2) int32_t filter_height = 2; float outputData[4]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,2,2,1}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 2, 2, 1}, 1.0, 0}; bool bret; float value = 1.0f; - input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return value++; - }); + input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return value++; }); util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); int32_t activation = ANEURALNETWORKS_FUSED_NONE; - bret = neon::maxPoolFloat32(input.ptr(), inputShape, - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - filter_width, filter_height, - activation, - outputData, outputShape); + bret = neon::maxPoolFloat32(input.ptr(), inputShape, padding_left, padding_right, + padding_top, padding_bottom, stride_width, stride_height, + filter_width, filter_height, activation, outputData, outputShape); EXPECT_EQ(bret, true); - float expectData[] = { - 5.0f, 6.0f, - 8.0f, 9.0f - }; + float expectData[] = {5.0f, 6.0f, 8.0f, 9.0f}; bret = util::compareData(outputData, expectData, outputShape); EXPECT_EQ(bret, true); } TEST(KernelACL_TC, neon_maxPoolFloat32_147x147to73x73) { - util::TensorWrapper input({1,147,147,64}); - util::TensorWrapper output({1,73,73,64}); + util::TensorWrapper input({1, 147, 147, 64}); + util::TensorWrapper output({1, 73, 73, 64}); int32_t padding_left = 0; int32_t padding_right = 0; @@ -161,37 +140,28 @@ TEST(KernelACL_TC, neon_maxPoolFloat32_147x147to73x73) int32_t filter_width = 3; int32_t filter_height = 3; - input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 1.0f; - }); + input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 0.f; - }); + output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); int32_t activation = ANEURALNETWORKS_FUSED_NONE; - bool bret = neon::maxPoolFloat32(input.ptr(), input.shape(), - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - filter_width, filter_height, - activation, - output.ptr(), output.shape()); + bool bret = + neon::maxPoolFloat32(input.ptr(), input.shape(), padding_left, padding_right, + padding_top, padding_bottom, stride_width, stride_height, filter_width, + filter_height, activation, output.ptr(), output.shape()); EXPECT_EQ(bret, true); - util::TensorWrapper expected({1,73,73,64}); - expected.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 1.0f; - }); + util::TensorWrapper expected({1, 73, 73, 64}); + expected.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); EXPECT_EQ(output, expected); } TEST(KernelACL_TC, neon_maxPoolFloat32_71x71to35x35) { - util::TensorWrapper input({1,71,71,192}); - util::TensorWrapper output({1,35,35,192}); + util::TensorWrapper input({1, 71, 71, 192}); + util::TensorWrapper output({1, 35, 35, 192}); int32_t padding_left = 0; int32_t padding_right = 0; @@ -202,37 +172,28 @@ TEST(KernelACL_TC, neon_maxPoolFloat32_71x71to35x35) int32_t filter_width = 3; int32_t filter_height = 3; - input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 1.0f; - }); + input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 0.f; - }); + output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); int32_t activation = ANEURALNETWORKS_FUSED_NONE; - bool bret = neon::maxPoolFloat32(input.ptr(), input.shape(), - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - filter_width, filter_height, - activation, - output.ptr(), output.shape()); + bool bret = + neon::maxPoolFloat32(input.ptr(), input.shape(), padding_left, padding_right, + padding_top, padding_bottom, stride_width, stride_height, filter_width, + filter_height, activation, output.ptr(), output.shape()); EXPECT_EQ(bret, true); - util::TensorWrapper expected({1,35,35,192}); - expected.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 1.0f; - }); + util::TensorWrapper expected({1, 35, 35, 192}); + expected.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); EXPECT_EQ(output, expected); } TEST(KernelACL_TC, neon_averagePoolFloat32_3x3to1x1) { - util::TensorWrapper input({1,3,3,1}); - const nnfw::rt::Shape inputShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; + util::TensorWrapper input({1, 3, 3, 1}); + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; int32_t padding_left = 0; int32_t padding_right = 0; int32_t padding_top = 0; @@ -243,36 +204,30 @@ TEST(KernelACL_TC, neon_averagePoolFloat32_3x3to1x1) int32_t filter_height = 3; float outputData[1]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,1,1,1}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 1, 1}, 1.0, 0}; bool bret; float value = 1.0f; - input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return value++; - }); + input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return value++; }); util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); int32_t activation = ANEURALNETWORKS_FUSED_NONE; - bret = neon::averagePoolFloat32(input.ptr(), inputShape, - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - filter_width, filter_height, - activation, - outputData, outputShape); + bret = neon::averagePoolFloat32(input.ptr(), inputShape, padding_left, padding_right, + padding_top, padding_bottom, stride_width, stride_height, + filter_width, filter_height, activation, outputData, outputShape); EXPECT_EQ(bret, true); - float expectData[] = { 5.0f }; + float expectData[] = {5.0f}; bret = util::compareData(outputData, expectData, outputShape); EXPECT_EQ(bret, true); } TEST(KernelACL_TC, neon_averagePoolFloat32_3x3to1x1_RELU) { - util::TensorWrapper input({1,3,3,1}); - const nnfw::rt::Shape inputShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; + util::TensorWrapper input({1, 3, 3, 1}); + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; int32_t padding_left = 0; int32_t padding_right = 0; int32_t padding_top = 0; @@ -283,36 +238,30 @@ TEST(KernelACL_TC, neon_averagePoolFloat32_3x3to1x1_RELU) int32_t filter_height = 3; float outputData[1]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,1,1,1}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 1, 1}, 1.0, 0}; bool bret; float value = 3.0f; - input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return value--; - }); + input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return value--; }); util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); int32_t activation = ANEURALNETWORKS_FUSED_RELU; - bret = neon::averagePoolFloat32(input.ptr(), inputShape, - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - filter_width, filter_height, - activation, - outputData, outputShape); + bret = neon::averagePoolFloat32(input.ptr(), inputShape, padding_left, padding_right, + padding_top, padding_bottom, stride_width, stride_height, + filter_width, filter_height, activation, outputData, outputShape); EXPECT_EQ(bret, true); - float expectData[] = { 0.0f }; + float expectData[] = {0.0f}; bret = util::compareData(outputData, expectData, outputShape); EXPECT_EQ(bret, true); } TEST(KernelACL_TC, neon_averagePoolFloat32_3x3to2x2) { - util::TensorWrapper input({1,3,3,1}); - const nnfw::rt::Shape inputShape = { OperandType::FLOAT32, {1,3,3,1}, 1.0, 0 }; + util::TensorWrapper input({1, 3, 3, 1}); + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 3, 3, 1}, 1.0, 0}; int32_t padding_left = 0; int32_t padding_right = 0; int32_t padding_top = 0; @@ -323,38 +272,29 @@ TEST(KernelACL_TC, neon_averagePoolFloat32_3x3to2x2) int32_t filter_height = 2; float outputData[4]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,2,2,1}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 2, 2, 1}, 1.0, 0}; bool bret; float value = 1.0f; - input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return value++; - }); + input.initValue([&value](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return value++; }); util::initData(outputData, sizeof(outputData) / sizeof(outputData[0]), 0.0); int32_t activation = ANEURALNETWORKS_FUSED_NONE; - bret = neon::averagePoolFloat32(input.ptr(), inputShape, - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - filter_width, filter_height, - activation, - outputData, outputShape); + bret = neon::averagePoolFloat32(input.ptr(), inputShape, padding_left, padding_right, + padding_top, padding_bottom, stride_width, stride_height, + filter_width, filter_height, activation, outputData, outputShape); EXPECT_EQ(bret, true); - float expectData[] = { - 3.0f, 4.0f, - 6.0f, 7.0f - }; + float expectData[] = {3.0f, 4.0f, 6.0f, 7.0f}; bret = util::compareData(outputData, expectData, outputShape); EXPECT_EQ(bret, true); } TEST(KernelACL_TC, neon_averagePoolFloat32_35x35to35x35) { - std::vector dims = {1,35,35,192}; + std::vector dims = {1, 35, 35, 192}; util::TensorWrapper input(dims); util::TensorWrapper output(dims); @@ -367,37 +307,28 @@ TEST(KernelACL_TC, neon_averagePoolFloat32_35x35to35x35) int32_t filter_width = 3; int32_t filter_height = 3; - input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 1.0f; - }); + input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 0.f; - }); + output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); int32_t activation = ANEURALNETWORKS_FUSED_NONE; - bool bret = neon::averagePoolFloat32(input.ptr(), input.shape(), - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - filter_width, filter_height, - activation, - output.ptr(), output.shape()); + bool bret = neon::averagePoolFloat32(input.ptr(), input.shape(), padding_left, + padding_right, padding_top, padding_bottom, stride_width, + stride_height, filter_width, filter_height, activation, + output.ptr(), output.shape()); EXPECT_EQ(bret, true); util::TensorWrapper expected(dims); - expected.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 1.0f; - }); + expected.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); EXPECT_EQ(output, expected); } TEST(KernelACL_TC, neon_averagePoolFloat32_8x8to1x1) { - util::TensorWrapper input({1,8,8,2048}); - util::TensorWrapper output({1,1,1,2048}); + util::TensorWrapper input({1, 8, 8, 2048}); + util::TensorWrapper output({1, 1, 1, 2048}); int32_t padding_left = 0; int32_t padding_right = 0; @@ -408,29 +339,20 @@ TEST(KernelACL_TC, neon_averagePoolFloat32_8x8to1x1) int32_t filter_width = 8; int32_t filter_height = 8; - input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 1.0f; - }); + input.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); - output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 0.f; - }); + output.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 0.f; }); int32_t activation = ANEURALNETWORKS_FUSED_NONE; - bool bret = neon::averagePoolFloat32(input.ptr(), input.shape(), - padding_left, padding_right, - padding_top, padding_bottom, - stride_width, stride_height, - filter_width, filter_height, - activation, - output.ptr(), output.shape()); + bool bret = neon::averagePoolFloat32(input.ptr(), input.shape(), padding_left, + padding_right, padding_top, padding_bottom, stride_width, + stride_height, filter_width, filter_height, activation, + output.ptr(), output.shape()); EXPECT_EQ(bret, true); - util::TensorWrapper expected({1,1,1,2048}); - expected.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { - return 1.0f; - }); + util::TensorWrapper expected({1, 1, 1, 2048}); + expected.initValue([](uint32_t n, uint32_t c, uint32_t h, uint32_t w) { return 1.0f; }); EXPECT_EQ(output, expected); } diff --git a/libs/kernel/acl/src/neon/Reshape.cpp b/libs/kernel/acl/src/neon/Reshape.cpp index e7b0e77..4774dab 100644 --- a/libs/kernel/acl/src/neon/Reshape.cpp +++ b/libs/kernel/acl/src/neon/Reshape.cpp @@ -24,20 +24,23 @@ #include "../UniqueTensor.h" #include "../Reshape.h" -namespace nnfw { -namespace kernel { -namespace acl { - -namespace neon { - -static void sync_scheduler() { - arm_compute::CLScheduler::get().sync(); -} - -bool reshapeGeneric(const void* inputData, const nnfw::rt::Shape& inputShape, - void* outputData, const nnfw::rt::Shape& outputShape) { - return common::reshapeGeneric - (inputData, inputShape, outputData, outputShape, sync_scheduler); +namespace nnfw +{ +namespace kernel +{ +namespace acl +{ + +namespace neon +{ + +static void sync_scheduler() { arm_compute::CLScheduler::get().sync(); } + +bool reshapeGeneric(const void *inputData, const nnfw::rt::Shape &inputShape, void *outputData, + const nnfw::rt::Shape &outputShape) +{ + return common::reshapeGeneric( + inputData, inputShape, outputData, outputShape, sync_scheduler); } } // namespace neon @@ -45,4 +48,3 @@ bool reshapeGeneric(const void* inputData, const nnfw::rt::Shape& inputShape, } // namespace acl } // namespace kernel } // namespace nnfw - diff --git a/libs/kernel/acl/src/neon/Softmax.cpp b/libs/kernel/acl/src/neon/Softmax.cpp index 6934485..49ad32e 100644 --- a/libs/kernel/acl/src/neon/Softmax.cpp +++ b/libs/kernel/acl/src/neon/Softmax.cpp @@ -24,14 +24,17 @@ #include "../util.h" #include "../UniqueTensor.h" -namespace nnfw { -namespace kernel { -namespace acl { -namespace neon { +namespace nnfw +{ +namespace kernel +{ +namespace acl +{ +namespace neon +{ -bool softmaxFloat32(const float* inputData, const nnfw::rt::Shape& inputShape, - const float beta, - float* outputData, const nnfw::rt::Shape& outputShape) +bool softmaxFloat32(const float *inputData, const nnfw::rt::Shape &inputShape, const float beta, + float *outputData, const nnfw::rt::Shape &outputShape) { arm_compute::TensorShape input_shape = util::fromNNShape(inputShape); arm_compute::TensorShape output_shape = util::fromNNShape(outputShape); diff --git a/libs/kernel/acl/src/neon/Softmax.test.cpp b/libs/kernel/acl/src/neon/Softmax.test.cpp index 988f550..d33e476 100644 --- a/libs/kernel/acl/src/neon/Softmax.test.cpp +++ b/libs/kernel/acl/src/neon/Softmax.test.cpp @@ -27,9 +27,9 @@ using namespace nnfw::kernel::acl; TEST(KernelACL_TC, neon_softmaxFloat32_1xn) { float inputData[4]; - const nnfw::rt::Shape inputShape = { OperandType::FLOAT32, {1,4}, 1.0, 0 }; + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 4}, 1.0, 0}; float outputData[4]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,4}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 4}, 1.0, 0}; const float beta = 1.0f; bool bret; @@ -39,7 +39,7 @@ TEST(KernelACL_TC, neon_softmaxFloat32_1xn) bret = neon::softmaxFloat32(inputData, inputShape, beta, outputData, outputShape); EXPECT_EQ(bret, true); - float expectData[] = { 0.25f, 0.25f, 0.25f, 0.25f }; + float expectData[] = {0.25f, 0.25f, 0.25f, 0.25f}; bret = util::compareData(outputData, expectData, outputShape); EXPECT_EQ(bret, true); } @@ -47,9 +47,9 @@ TEST(KernelACL_TC, neon_softmaxFloat32_1xn) TEST(KernelACL_TC, neon_softmaxFloat32_4d) { float inputData[4]; - const nnfw::rt::Shape inputShape = { OperandType::FLOAT32, {1,1,4,1}, 1.0, 0 }; + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 1, 4, 1}, 1.0, 0}; float outputData[4]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,1,4,1}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 4, 1}, 1.0, 0}; const float beta = 1.0f; bool bret; @@ -59,7 +59,7 @@ TEST(KernelACL_TC, neon_softmaxFloat32_4d) bret = neon::softmaxFloat32(inputData, inputShape, beta, outputData, outputShape); EXPECT_EQ(bret, true); - float expectData[] = { 0.25f, 0.25f, 0.25f, 0.25f }; + float expectData[] = {0.25f, 0.25f, 0.25f, 0.25f}; bret = util::compareData(outputData, expectData, outputShape); EXPECT_EQ(bret, true); } @@ -67,9 +67,9 @@ TEST(KernelACL_TC, neon_softmaxFloat32_4d) TEST(KernelACL_TC, neon_softmaxFloat32_1xn_seq) { float inputData[4]; - const nnfw::rt::Shape inputShape = { OperandType::FLOAT32, {1,1,4,1}, 1.0, 0 }; + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 1, 4, 1}, 1.0, 0}; float outputData[4]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,1,4,1}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 4, 1}, 1.0, 0}; const float beta = 1.0f; bool bret; @@ -87,9 +87,9 @@ TEST(KernelACL_TC, neon_softmaxFloat32_1xn_seq) TEST(KernelACL_TC, neon_softmaxFloat32_4d_seq) { float inputData[4]; - const nnfw::rt::Shape inputShape = { OperandType::FLOAT32, {1,1,4,1}, 1.0, 0 }; + const nnfw::rt::Shape inputShape = {OperandType::FLOAT32, {1, 1, 4, 1}, 1.0, 0}; float outputData[4]; - const nnfw::rt::Shape outputShape = { OperandType::FLOAT32, {1,1,4,1}, 1.0, 0 }; + const nnfw::rt::Shape outputShape = {OperandType::FLOAT32, {1, 1, 4, 1}, 1.0, 0}; const float beta = 1.0f; bool bret; diff --git a/libs/kernel/acl/src/shape.cpp b/libs/kernel/acl/src/shape.cpp index 3c976ae..ff91a64 100644 --- a/libs/kernel/acl/src/shape.cpp +++ b/libs/kernel/acl/src/shape.cpp @@ -18,27 +18,35 @@ #include "shape.h" -namespace nnfw { -namespace rt { +namespace nnfw +{ +namespace rt +{ // TODO remove from this source and use it from runtime -uint32_t getSizeOfDimension(const Shape& shape, uint32_t dimensionIdx) { - if (dimensionIdx >= shape.dimensions.size()) { - // TODO, log the error - return 0; - } - return shape.dimensions[dimensionIdx]; +uint32_t getSizeOfDimension(const Shape &shape, uint32_t dimensionIdx) +{ + if (dimensionIdx >= shape.dimensions.size()) + { + // TODO, log the error + return 0; + } + return shape.dimensions[dimensionIdx]; } } // namespace rt } // namespace nnfw -namespace nnfw { -namespace kernel { -namespace acl { -namespace util { +namespace nnfw +{ +namespace kernel +{ +namespace acl +{ +namespace util +{ -arm_compute::TensorShape fromVectorNNShape(const nnfw::rt::Shape& shape) +arm_compute::TensorShape fromVectorNNShape(const nnfw::rt::Shape &shape) { assert(shape.dimensions.size() == 1); @@ -47,7 +55,7 @@ arm_compute::TensorShape fromVectorNNShape(const nnfw::rt::Shape& shape) return arm_compute::TensorShape(len); } -arm_compute::TensorShape fromMatrixNNShape(const nnfw::rt::Shape& shape) +arm_compute::TensorShape fromMatrixNNShape(const nnfw::rt::Shape &shape) { assert(shape.dimensions.size() == 2); @@ -57,11 +65,11 @@ arm_compute::TensorShape fromMatrixNNShape(const nnfw::rt::Shape& shape) return arm_compute::TensorShape(c, n); } -arm_compute::TensorShape fromNNShape(const nnfw::rt::Shape& shape) +arm_compute::TensorShape fromNNShape(const nnfw::rt::Shape &shape) { - if( shape.dimensions.size() == 1 ) + if (shape.dimensions.size() == 1) return fromVectorNNShape(shape); - else if( shape.dimensions.size() == 2 ) + else if (shape.dimensions.size() == 2) return fromMatrixNNShape(shape); // TODO: need to treat 3D tensors. diff --git a/libs/kernel/acl/src/shape.h b/libs/kernel/acl/src/shape.h index 902115e..b70a2bb 100644 --- a/libs/kernel/acl/src/shape.h +++ b/libs/kernel/acl/src/shape.h @@ -23,63 +23,74 @@ #include #include -namespace nnfw { -namespace rt { +namespace nnfw +{ +namespace rt +{ // TODO remove from this source and use it from runtime -uint32_t getSizeOfDimension(const Shape& shape, uint32_t dimensionIdx); +uint32_t getSizeOfDimension(const Shape &shape, uint32_t dimensionIdx); } // namespace rt } // namespace nnfw -namespace nnfw { -namespace kernel { -namespace acl { -namespace util { - -arm_compute::TensorShape fromVectorNNShape(const nnfw::rt::Shape& shape); -arm_compute::TensorShape fromNNShape(const nnfw::rt::Shape& shape); - -template -void insertFusedActivationLayer(TensorT& out, int activation, - std::vector>& fns) { +namespace nnfw +{ +namespace kernel +{ +namespace acl +{ +namespace util +{ + +arm_compute::TensorShape fromVectorNNShape(const nnfw::rt::Shape &shape); +arm_compute::TensorShape fromNNShape(const nnfw::rt::Shape &shape); + +template +void insertFusedActivationLayer(TensorT &out, int activation, + std::vector> &fns) +{ auto relu_f = std::make_shared(); - switch(activation) { - case ANEURALNETWORKS_FUSED_NONE: - // DO NOTHING - return; + switch (activation) + { + case ANEURALNETWORKS_FUSED_NONE: + // DO NOTHING + return; - case ANEURALNETWORKS_FUSED_RELU: + case ANEURALNETWORKS_FUSED_RELU: { - const arm_compute::ActivationLayerInfo relu_info(arm_compute::ActivationLayerInfo::ActivationFunction::RELU); + const arm_compute::ActivationLayerInfo relu_info( + arm_compute::ActivationLayerInfo::ActivationFunction::RELU); // Do in-place update relu_f->configure(out.ptr(), nullptr, relu_info); } break; - case ANEURALNETWORKS_FUSED_RELU1: + case ANEURALNETWORKS_FUSED_RELU1: { - const arm_compute::ActivationLayerInfo relu_info(arm_compute::ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 1.f); + const arm_compute::ActivationLayerInfo relu_info( + arm_compute::ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 1.f); // Do in-place update relu_f->configure(out.ptr(), nullptr, relu_info); } break; - case ANEURALNETWORKS_FUSED_RELU6: + case ANEURALNETWORKS_FUSED_RELU6: { - const arm_compute::ActivationLayerInfo relu_info(arm_compute::ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 6.f); + const arm_compute::ActivationLayerInfo relu_info( + arm_compute::ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 6.f); // Do in-place update relu_f->configure(out.ptr(), nullptr, relu_info); } break; - default: - assert("Undefined activation type." && 0); - break; + default: + assert("Undefined activation type." && 0); + break; } fns.emplace_back(relu_f); diff --git a/libs/kernel/acl/src/support.cpp b/libs/kernel/acl/src/support.cpp index d04aef5..621f7fb 100644 --- a/libs/kernel/acl/src/support.cpp +++ b/libs/kernel/acl/src/support.cpp @@ -27,7 +27,7 @@ namespace feature // TODO Extract this function as utility function // NOTE It is not a good design to access nnfw::rt::Shape nnfw_support_nnapi lib -nnfw::util::feature::Shape asFeatureShape(const nnfw::rt::Shape& shape) +nnfw::util::feature::Shape asFeatureShape(const nnfw::rt::Shape &shape) { // NNAPI assumes the following ordering: // diff --git a/libs/kernel/acl/src/support.h b/libs/kernel/acl/src/support.h index 751d2c6..065c08d 100644 --- a/libs/kernel/acl/src/support.h +++ b/libs/kernel/acl/src/support.h @@ -38,7 +38,7 @@ namespace feature // TODO Extract this function as utility function // NOTE It is not a good design to access nnfw::rt::Shape nnfw_support_nnapi lib -nnfw::util::feature::Shape asFeatureShape(const nnfw::rt::Shape& shape); +nnfw::util::feature::Shape asFeatureShape(const nnfw::rt::Shape &shape); } // namespace feature } // namespace nnapi @@ -58,9 +58,9 @@ namespace acl namespace feature { -template class Reader; +template class Reader; -template<> class Reader final : public nnfw::util::feature::Reader +template <> class Reader final : public nnfw::util::feature::Reader { public: Reader(arm_compute::ITensor *tensor) : _tensor{tensor} @@ -78,7 +78,8 @@ private: float *ptr_to_element(uint32_t ch, uint32_t row, uint32_t col) const { // ARM Compute uses CHW ordering - return reinterpret_cast(_tensor->ptr_to_element(arm_compute::Coordinates{col, row, ch})); + return reinterpret_cast( + _tensor->ptr_to_element(arm_compute::Coordinates{col, row, ch})); } private: diff --git a/libs/kernel/acl/src/util.cpp b/libs/kernel/acl/src/util.cpp index 7e5df53..bf4f08b 100644 --- a/libs/kernel/acl/src/util.cpp +++ b/libs/kernel/acl/src/util.cpp @@ -18,21 +18,27 @@ #include "util.h" -namespace nnfw { -namespace kernel { -namespace acl { -namespace util { +namespace nnfw +{ +namespace kernel +{ +namespace acl +{ +namespace util +{ -void initData(float* data, int num, float value) +void initData(float *data, int num, float value) { - for (int i = 0; i < num; i++) { + for (int i = 0; i < num; i++) + { *(data + i) = value; } } -void initData_Increasing(float* data, int num, float value) +void initData_Increasing(float *data, int num, float value) { - for (int i = 0; i < num; i++) { + for (int i = 0; i < num; i++) + { *(data + i) = value; value++; } @@ -41,34 +47,38 @@ void initData_Increasing(float* data, int num, float value) // compareData // return true if result == expected with the shape info, // otherwise false -bool compareData(const float* result, const float* expected, const nnfw::rt::Shape& shape) +bool compareData(const float *result, const float *expected, const nnfw::rt::Shape &shape) { if (shape.dimensions.size() == 4) { - // TODO fix indentation - uint32_t height = nnfw::rt::getSizeOfDimension(shape, 1); - uint32_t width = nnfw::rt::getSizeOfDimension(shape, 2); - uint32_t numitems = height * width; - for (int item = 0; item < numitems; item++) { - if (!::nnfw::util::fp32::epsilon_equal(*(result + item), *(expected + item), 1)) { - LOG(ERROR) << "compareData failed: result " << *(result + item) - << ", expected " << *(expected + item) - << ", diff " << ::nnfw::util::fp32::relative_diff(*(result + item), *(expected + item)) - << std::endl; - return false; + // TODO fix indentation + uint32_t height = nnfw::rt::getSizeOfDimension(shape, 1); + uint32_t width = nnfw::rt::getSizeOfDimension(shape, 2); + uint32_t numitems = height * width; + for (int item = 0; item < numitems; item++) + { + if (!::nnfw::util::fp32::epsilon_equal(*(result + item), *(expected + item), 1)) + { + LOG(ERROR) << "compareData failed: result " << *(result + item) << ", expected " + << *(expected + item) << ", diff " + << ::nnfw::util::fp32::relative_diff(*(result + item), *(expected + item)) + << std::endl; + return false; + } } } - } else if (shape.dimensions.size() == 2) { uint32_t height = nnfw::rt::getSizeOfDimension(shape, 0); - uint32_t width = nnfw::rt::getSizeOfDimension(shape, 1); + uint32_t width = nnfw::rt::getSizeOfDimension(shape, 1); uint32_t numitems = height * width; - for (int item = 0; item < numitems; item++) { - if (!::nnfw::util::fp32::epsilon_equal(*(result + item), *(expected + item), 1)) { - LOG(ERROR) << "compareData failed: result " << *(result + item) - << ", expected " << *(expected + item) - << ", diff " << ::nnfw::util::fp32::relative_diff(*(result + item), *(expected + item)) + for (int item = 0; item < numitems; item++) + { + if (!::nnfw::util::fp32::epsilon_equal(*(result + item), *(expected + item), 1)) + { + LOG(ERROR) << "compareData failed: result " << *(result + item) << ", expected " + << *(expected + item) << ", diff " + << ::nnfw::util::fp32::relative_diff(*(result + item), *(expected + item)) << std::endl; return false; } @@ -82,17 +92,21 @@ bool compareData(const float* result, const float* expected, const nnfw::rt::Sha return true; } -void NCHW2NHWC(const float* nchw, float* nhwc, const nnfw::rt::Shape& shape) +void NCHW2NHWC(const float *nchw, float *nhwc, const nnfw::rt::Shape &shape) { uint32_t N = nnfw::rt::getSizeOfDimension(shape, 0); uint32_t H = nnfw::rt::getSizeOfDimension(shape, 1); uint32_t W = nnfw::rt::getSizeOfDimension(shape, 2); uint32_t C = nnfw::rt::getSizeOfDimension(shape, 3); - for (uint32_t n = 0; n < N; n++) { - for (uint32_t c = 0; c < C; c++) { - for (uint32_t h = 0; h < H; h++) { - for (uint32_t w = 0; w < W; w++) { + for (uint32_t n = 0; n < N; n++) + { + for (uint32_t c = 0; c < C; c++) + { + for (uint32_t h = 0; h < H; h++) + { + for (uint32_t w = 0; w < W; w++) + { uint32_t soffset = w + (h * W) + (c * W * H) + (n * W * H * C); uint32_t doffset = c + (w * C) + (h * C * W) + (n * C * W * H); *(nhwc + doffset) = *(nchw + soffset); diff --git a/libs/kernel/acl/src/util.h b/libs/kernel/acl/src/util.h index 48ed027..976c6eb 100644 --- a/libs/kernel/acl/src/util.h +++ b/libs/kernel/acl/src/util.h @@ -22,65 +22,61 @@ #include #include -namespace nnfw { -namespace kernel { -namespace acl { -namespace util { +namespace nnfw +{ +namespace kernel +{ +namespace acl +{ +namespace util +{ // TODO: make a separate module. -class TensorWrapper { +class TensorWrapper +{ public: - TensorWrapper(std::vector dims, - OperandType type = OperandType::FLOAT32, - float scale = 1.0, - int32_t offset = 0) - :_shape{type, dims, scale, offset} + TensorWrapper(std::vector dims, OperandType type = OperandType::FLOAT32, + float scale = 1.0, int32_t offset = 0) + : _shape{type, dims, scale, offset} { // currently, we support only FLOAT32 for now. - assert( type == OperandType::FLOAT32); + assert(type == OperandType::FLOAT32); uint32_t size_bytes = sizeof(float); _num_elems = 1; - for( auto& d: dims ) { + for (auto &d : dims) + { _num_elems *= d; } _data = new uint8_t[_num_elems * size_bytes]; } - ~TensorWrapper() { - delete [] _data; - } + ~TensorWrapper() { delete[] _data; } - const nnfw::rt::Shape shape() const { - return _shape; - } + const nnfw::rt::Shape shape() const { return _shape; } uint32_t num_elems() const { return _num_elems; } - template - T at(const uint32_t& idx) const { - return reinterpret_cast(_data)[idx]; - } + template T at(const uint32_t &idx) const { return reinterpret_cast(_data)[idx]; } - template - T& at(const uint32_t& idx) { - return reinterpret_cast(_data)[idx]; - } + template T &at(const uint32_t &idx) { return reinterpret_cast(_data)[idx]; } - template - T* ptr() { return reinterpret_cast(_data); } + template T *ptr() { return reinterpret_cast(_data); } - void initValue(float f) { - for( uint32_t i = 0; i < _num_elems; ++i ) { + void initValue(float f) + { + for (uint32_t i = 0; i < _num_elems; ++i) + { at(i) = f; } } typedef std::function funcInit4; - void initValue(funcInit4 f) { + void initValue(funcInit4 f) + { assert(_shape.dimensions.size() == 4); int N = _shape.dimensions[0]; @@ -88,12 +84,16 @@ public: int W = _shape.dimensions[2]; int C = _shape.dimensions[3]; - for(int n = 0; n < N; ++n) { - for(int h = 0; h < H; ++h) { - for(int w = 0; w < W; ++w) { - for(int c = 0; c < C; ++c) { - uint32_t offset = n*H*W*C + h*W*C + w*C + c; - at(offset) = f(n,c,h,w); + for (int n = 0; n < N; ++n) + { + for (int h = 0; h < H; ++h) + { + for (int w = 0; w < W; ++w) + { + for (int c = 0; c < C; ++c) + { + uint32_t offset = n * H * W * C + h * W * C + w * C + c; + at(offset) = f(n, c, h, w); } } } @@ -101,58 +101,70 @@ public: } typedef std::function funcInit3; - void initValue(funcInit3 f) { + void initValue(funcInit3 f) + { assert(_shape.dimensions.size() == 3); int C = _shape.dimensions[0]; int H = _shape.dimensions[1]; int W = _shape.dimensions[2]; - for(int h = 0; h < H; ++h) { - for(int w = 0; w < W; ++w) { - for(int c = 0; c < C; ++c) { - uint32_t offset = h*W*C + w*C + c; - at(offset) = f(c,h,w); + for (int h = 0; h < H; ++h) + { + for (int w = 0; w < W; ++w) + { + for (int c = 0; c < C; ++c) + { + uint32_t offset = h * W * C + w * C + c; + at(offset) = f(c, h, w); } } } } typedef std::function funcInit2; - void initValue(funcInit2 f) { + void initValue(funcInit2 f) + { assert(_shape.dimensions.size() == 2); int H = _shape.dimensions[0]; int W = _shape.dimensions[1]; - for(int h = 0; h < H; ++h) { - for(int w = 0; w < W; ++w) { - uint32_t offset = h*W + w; - at(offset) = f(h,w); + for (int h = 0; h < H; ++h) + { + for (int w = 0; w < W; ++w) + { + uint32_t offset = h * W + w; + at(offset) = f(h, w); } } } typedef std::function funcInit1; - void initValue(funcInit1 f) { + void initValue(funcInit1 f) + { assert(_shape.dimensions.size() == 1); int W = _shape.dimensions[0]; - for(int w = 0; w < W; ++w) { + for (int w = 0; w < W; ++w) + { uint32_t offset = w; at(offset) = f(w); } } - void initValue(std::vector v) { + void initValue(std::vector v) + { assert(v.size() == _num_elems); - for( uint32_t i = 0; i < _num_elems; ++i ) { + for (uint32_t i = 0; i < _num_elems; ++i) + { at(i) = v[i]; } } - bool operator==(const TensorWrapper &t) const { + bool operator==(const TensorWrapper &t) const + { // compare the shape assert(num_elems() == t.num_elems()); assert(_shape.type == t.shape().type); @@ -163,9 +175,12 @@ public: // currently, we support only FLOAT32. assert(_shape.type == OperandType::FLOAT32); - for( uint32_t i = 0; i < _num_elems; ++i ) { - if( std::fabs(static_cast(at(i) - t.at(i))) > 0.001f ) { - std::cout << "Comparing [" << i << "] " << at(i) << "," << t.at(i) << std::endl; + for (uint32_t i = 0; i < _num_elems; ++i) + { + if (std::fabs(static_cast(at(i) - t.at(i))) > 0.001f) + { + std::cout << "Comparing [" << i << "] " << at(i) << "," << t.at(i) + << std::endl; return false; } } @@ -175,15 +190,15 @@ public: private: nnfw::rt::Shape _shape; - uint32_t _num_elems; - uint8_t* _data; + uint32_t _num_elems; + uint8_t *_data; }; -void initData(float* data, int num, float value); -bool compareData(const float* result, const float* expected, const nnfw::rt::Shape& shape); -void initData_Increasing(float* data, int num, float value); +void initData(float *data, int num, float value); +bool compareData(const float *result, const float *expected, const nnfw::rt::Shape &shape); +void initData_Increasing(float *data, int num, float value); -void NCHW2NHWC(const float* nchw, float* nhwc, const nnfw::rt::Shape& shape); +void NCHW2NHWC(const float *nchw, float *nhwc, const nnfw::rt::Shape &shape); } // namespace util } // namespace acl diff --git a/libs/support/tflite/src/Diff.cpp b/libs/support/tflite/src/Diff.cpp index d5e788c..871d014 100644 --- a/libs/support/tflite/src/Diff.cpp +++ b/libs/support/tflite/src/Diff.cpp @@ -28,11 +28,12 @@ class DiffSummary : public TfLiteTensorComparator::Observer { public: DiffSummary() - : max_abs_diff_index(0), max_abs_diff_value{0.0f}, - max_rel_diff_index(0), max_rel_diff_value{0.0f} + : max_abs_diff_index(0), max_abs_diff_value{0.0f}, max_rel_diff_index(0), + max_rel_diff_value{0.0f} { // DO NOTHING } + public: void notify(const nnfw::util::tensor::Index &index, float expected, float obtained) override; @@ -81,33 +82,32 @@ TfLiteTensorComparator::compare(const nnfw::support::tflite::TensorView & assert(expected.shape() == obtained.shape()); nnfw::util::tensor::zip(expected.shape(), expected, obtained) << - [&] (const nnfw::util::tensor::Index &index, float expected_value, float obtained_value) - { - const auto relative_diff = nnfw::util::fp32::relative_diff(expected_value, obtained_value); + [&](const nnfw::util::tensor::Index &index, float expected_value, float obtained_value) { + const auto relative_diff = nnfw::util::fp32::relative_diff(expected_value, obtained_value); - if (!_compare_fn(expected_value, obtained_value)) - { - TfLiteTensorDiff diff(index); + if (!_compare_fn(expected_value, obtained_value)) + { + TfLiteTensorDiff diff(index); - diff.expected = expected_value; - diff.obtained = obtained_value; + diff.expected = expected_value; + diff.obtained = obtained_value; - res.emplace_back(diff); - } + res.emplace_back(diff); + } - // Update max_diff_index, if necessary - if (observer != nullptr) - { - observer->notify(index, expected_value, obtained_value); - } - }; + // Update max_diff_index, if necessary + if (observer != nullptr) + { + observer->notify(index, expected_value, obtained_value); + } + }; return res; } -bool TfLiteInterpMatchApp::compareSingleTensorView(const nnfw::support::tflite::TensorView &expected, - const nnfw::support::tflite::TensorView &obtained, - int id) const +bool TfLiteInterpMatchApp::compareSingleTensorView( + const nnfw::support::tflite::TensorView &expected, + const nnfw::support::tflite::TensorView &obtained, int id) const { DiffSummary summary; @@ -126,7 +126,8 @@ bool TfLiteInterpMatchApp::compareSingleTensorView(const nnfw::support::tflite:: // Print out max_diff if (summary.max_abs_diff_value > 0) { - std::cout << " Max absolute diff at [" << nnfw::util::tensor::IndexFormatter(summary.max_abs_diff_index) << "]" << std::endl; + std::cout << " Max absolute diff at [" + << nnfw::util::tensor::IndexFormatter(summary.max_abs_diff_index) << "]" << std::endl; std::cout << " expected: " << summary.max_abs_diff_expected << std::endl; std::cout << " obtained: " << summary.max_abs_diff_obtained << std::endl; std::cout << " absolute diff: " << summary.max_abs_diff_value << std::endl; @@ -136,7 +137,8 @@ bool TfLiteInterpMatchApp::compareSingleTensorView(const nnfw::support::tflite:: { const auto tolerance_level = summary.max_rel_diff_value / FLT_EPSILON; - std::cout << " Max relative diff at [" << nnfw::util::tensor::IndexFormatter(summary.max_rel_diff_index) << "]" << std::endl; + std::cout << " Max relative diff at [" + << nnfw::util::tensor::IndexFormatter(summary.max_rel_diff_index) << "]" << std::endl; std::cout << " expected: " << summary.max_rel_diff_expected << std::endl; std::cout << " obtained: " << summary.max_rel_diff_obtained << std::endl; std::cout << " relative diff: " << summary.max_rel_diff_value << std::endl; @@ -154,7 +156,8 @@ bool TfLiteInterpMatchApp::compareSingleTensorView(const nnfw::support::tflite:: const auto relative_diff = nnfw::util::fp32::relative_diff(diff.expected, diff.obtained); const auto tolerance_level = relative_diff / FLT_EPSILON; - std::cout << " Diff at [" << nnfw::util::tensor::IndexFormatter(diff.index) << "]" << std::endl; + std::cout << " Diff at [" << nnfw::util::tensor::IndexFormatter(diff.index) << "]" + << std::endl; std::cout << " expected: " << diff.expected << std::endl; std::cout << " obtained: " << diff.obtained << std::endl; std::cout << " absolute diff: " << absolute_diff << std::endl; @@ -206,8 +209,7 @@ int RandomTestRunner::run(const nnfw::support::tflite::interp::Builder &builder) assert(pure->inputs() == nnapi->inputs()); // Fill IFM with random numbers - auto ifm_gen = [this] (const nnfw::util::tensor::Shape &, const nnfw::util::tensor::Index &) - { + auto ifm_gen = [this](const nnfw::util::tensor::Shape &, const nnfw::util::tensor::Index &) { // TODO Allow users to set min/max and distribution std::normal_distribution dist(0.0f, 2.0f); return dist(_rand); @@ -224,8 +226,7 @@ int RandomTestRunner::run(const nnfw::support::tflite::interp::Builder &builder) assert(pure_view.shape() == data.shape()); - nnfw::util::tensor::iterate(pure_view.shape()) << [&] (const nnfw::util::tensor::Index &ind) - { + nnfw::util::tensor::iterate(pure_view.shape()) << [&](const nnfw::util::tensor::Index &ind) { const auto value = data.at(ind); pure_view.at(ind) = value; @@ -244,8 +245,7 @@ int RandomTestRunner::run(const nnfw::support::tflite::interp::Builder &builder) const auto tolerance = _param.tolerance; - auto equals = [tolerance] (float lhs, float rhs) - { + auto equals = [tolerance](float lhs, float rhs) { // NOTE Hybrid approach // TODO Allow users to set tolerance for absolute_epsilon_equal if (nnfw::util::fp32::absolute_epsilon_equal(lhs, rhs)) diff --git a/libs/support/tflite/src/TensorView.cpp b/libs/support/tflite/src/TensorView.cpp index 9e164ac..2618d1c 100644 --- a/libs/support/tflite/src/TensorView.cpp +++ b/libs/support/tflite/src/TensorView.cpp @@ -25,7 +25,8 @@ namespace support namespace tflite { -TensorView::TensorView(const nnfw::util::tensor::Shape &shape, float *base) : _shape{shape}, _base{base} +TensorView::TensorView(const nnfw::util::tensor::Shape &shape, float *base) + : _shape{shape}, _base{base} { // Set 'stride' _stride.init(_shape); diff --git a/libs/support/tflite/src/TensorView.test.cpp b/libs/support/tflite/src/TensorView.test.cpp index 75993a6..61a2723 100644 --- a/libs/support/tflite/src/TensorView.test.cpp +++ b/libs/support/tflite/src/TensorView.test.cpp @@ -20,7 +20,7 @@ int main(int argc, char **argv) { - float value[6] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f }; + float value[6] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f}; const nnfw::util::tensor::Shape shape{2, 3}; const nnfw::support::tflite::TensorView view{shape, value}; diff --git a/libs/util/examples/tensor_index_iterator.cpp b/libs/util/examples/tensor_index_iterator.cpp index a05d78d..01346ee 100644 --- a/libs/util/examples/tensor_index_iterator.cpp +++ b/libs/util/examples/tensor_index_iterator.cpp @@ -24,8 +24,7 @@ int main(int argc, char **argv) std::cout << "Iterate over tensor{3, 4, 3, 4}" << std::endl; - nnfw::util::tensor::iterate(shape) << [] (const nnfw::util::tensor::Index &index) - { + nnfw::util::tensor::iterate(shape) << [](const nnfw::util::tensor::Index &index) { std::cout << "rank: " << index.rank() << std::endl; for (size_t d = 0; d < index.rank(); ++d) diff --git a/libs/util/include/util/benchmark.h b/libs/util/include/util/benchmark.h index c451edd..b07656c 100644 --- a/libs/util/include/util/benchmark.h +++ b/libs/util/include/util/benchmark.h @@ -54,10 +54,7 @@ Accumulator &operator<<(Accumulator &&acc, Callable cb) return acc; } -template Accumulator measure(T &out) -{ - return Accumulator(out); -} +template Accumulator measure(T &out) { return Accumulator(out); } } // namespace benchmark } // namespace util diff --git a/libs/util/include/util/environment.h b/libs/util/include/util/environment.h index fa9dd51..2445272 100644 --- a/libs/util/include/util/environment.h +++ b/libs/util/include/util/environment.h @@ -22,9 +22,8 @@ namespace nnfw namespace util { -int get_env_int(const char* name); -bool get_env_bool(const char* name); - +int get_env_int(const char *name); +bool get_env_bool(const char *name); } } diff --git a/libs/util/include/util/feature/Index.h b/libs/util/include/util/feature/Index.h index e778166..d8ac32a 100644 --- a/libs/util/include/util/feature/Index.h +++ b/libs/util/include/util/feature/Index.h @@ -34,7 +34,7 @@ public: public: Index(int32_t ch, int32_t row, int32_t col) : _ch{ch}, _row{row}, _col{col} { - // DO NOTHING + // DO NOTHING } public: diff --git a/libs/util/include/util/feature/Object.h b/libs/util/include/util/feature/Object.h index ca217b4..ce66c24 100644 --- a/libs/util/include/util/feature/Object.h +++ b/libs/util/include/util/feature/Object.h @@ -30,10 +30,10 @@ namespace util namespace feature { -template class Object final : public Reader +template class Object final : public Reader { public: - using Generator = std::function; + using Generator = std::function; public: Object(const Shape &shape, const Generator &fn) : _shape{shape} diff --git a/libs/util/include/util/feature/Shape.h b/libs/util/include/util/feature/Shape.h index e05c97f..64c926e 100644 --- a/libs/util/include/util/feature/Shape.h +++ b/libs/util/include/util/feature/Shape.h @@ -37,7 +37,6 @@ struct Shape { // DO NOTHING } - }; } // namespace feature diff --git a/libs/util/include/util/feature/TextFormatter.h b/libs/util/include/util/feature/TextFormatter.h index 91b4c9f..de5c4c1 100644 --- a/libs/util/include/util/feature/TextFormatter.h +++ b/libs/util/include/util/feature/TextFormatter.h @@ -34,8 +34,7 @@ namespace feature template class TextFormatter { public: - TextFormatter(const Shape &shape, const Reader &data) - : _shape(shape), _data(data) + TextFormatter(const Shape &shape, const Reader &data) : _shape(shape), _data(data) { // DO NOTHING } @@ -49,8 +48,7 @@ private: const Reader &_data; }; -template -std::ostream &operator<<(std::ostream &os, const TextFormatter &fmt) +template std::ostream &operator<<(std::ostream &os, const TextFormatter &fmt) { const auto &shape = fmt.shape(); diff --git a/libs/util/include/util/kernel/RandomObject.h b/libs/util/include/util/kernel/RandomObject.h index ceed7a0..d6fca9a 100644 --- a/libs/util/include/util/kernel/RandomObject.h +++ b/libs/util/include/util/kernel/RandomObject.h @@ -29,7 +29,7 @@ namespace util namespace kernel { -template class RandomObject final : public Reader +template class RandomObject final : public Reader { public: RandomObject(const Shape &shape) : _shape{shape} diff --git a/libs/util/include/util/tensor/Index.h b/libs/util/include/util/tensor/Index.h index e74b092..9d17b14 100644 --- a/libs/util/include/util/tensor/Index.h +++ b/libs/util/include/util/tensor/Index.h @@ -33,10 +33,7 @@ namespace tensor struct Index { public: - Index(size_t rank) - { - _offsets.resize(rank); - } + Index(size_t rank) { _offsets.resize(rank); } public: Index(std::initializer_list offsets) : _offsets{offsets} diff --git a/libs/util/include/util/tensor/Object.h b/libs/util/include/util/tensor/Object.h index 839bce2..7afd089 100644 --- a/libs/util/include/util/tensor/Object.h +++ b/libs/util/include/util/tensor/Object.h @@ -32,10 +32,10 @@ namespace util namespace tensor { -template class Object final : public Reader +template class Object final : public Reader { public: - using Generator = std::function; + using Generator = std::function; public: Object(const Shape &shape, const Generator &fn) : _shape{shape} @@ -47,20 +47,15 @@ public: _values.resize(_shape.dim(0) * _stride.at(0)); // Set 'value' - iterate(_shape) << [this, &fn] (const Index &index) - { - _values.at(_stride.offset(index)) = fn(_shape, index); - }; + iterate(_shape) << + [this, &fn](const Index &index) { _values.at(_stride.offset(index)) = fn(_shape, index); }; } public: const Shape &shape(void) const { return _shape; } public: - T at(const Index &index) const override - { - return _values.at(_stride.offset(index)); - } + T at(const Index &index) const override { return _values.at(_stride.offset(index)); } private: Shape _shape; diff --git a/libs/util/include/util/tensor/Shape.h b/libs/util/include/util/tensor/Shape.h index d4edeaa..c9d8c46 100644 --- a/libs/util/include/util/tensor/Shape.h +++ b/libs/util/include/util/tensor/Shape.h @@ -32,10 +32,7 @@ namespace tensor class Shape { public: - Shape(size_t rank) - { - _dimensions.resize(rank); - } + Shape(size_t rank) { _dimensions.resize(rank); } public: Shape(const std::initializer_list &dimensions) : _dimensions{dimensions} diff --git a/libs/util/include/util/tensor/Zipper.h b/libs/util/include/util/tensor/Zipper.h index fc2d94e..5d40736 100644 --- a/libs/util/include/util/tensor/Zipper.h +++ b/libs/util/include/util/tensor/Zipper.h @@ -32,7 +32,7 @@ template class Zipper { public: Zipper(const Shape &shape, const Reader &lhs, const Reader &rhs) - : _shape{shape}, _lhs{lhs}, _rhs{rhs} + : _shape{shape}, _lhs{lhs}, _rhs{rhs} { // DO NOTHING } @@ -40,10 +40,8 @@ public: public: template void zip(Callable cb) const { - iterate(_shape) << [this, &cb] (const Index &index) - { - cb(index, _lhs.at(index), _rhs.at(index)); - }; + iterate(_shape) << + [this, &cb](const Index &index) { cb(index, _lhs.at(index), _rhs.at(index)); }; } private: @@ -52,15 +50,14 @@ private: const Reader &_rhs; }; -template +template const Zipper &operator<<(const Zipper &zipper, Callable cb) { zipper.zip(cb); return zipper; } -template -Zipper zip(const Shape &shape, const Reader &lhs, const Reader &rhs) +template Zipper zip(const Shape &shape, const Reader &lhs, const Reader &rhs) { return Zipper{shape, lhs, rhs}; } diff --git a/libs/util/include/util/vector.h b/libs/util/include/util/vector.h index 49a58a4..02f7825 100644 --- a/libs/util/include/util/vector.h +++ b/libs/util/include/util/vector.h @@ -19,8 +19,7 @@ #include -template -bool operator==(const std::vector &lhs, const std::vector &rhs) +template bool operator==(const std::vector &lhs, const std::vector &rhs) { if (lhs.size() != rhs.size()) { diff --git a/libs/util/include/util/vector/Object.h b/libs/util/include/util/vector/Object.h index b1bc521..407c06d 100644 --- a/libs/util/include/util/vector/Object.h +++ b/libs/util/include/util/vector/Object.h @@ -29,10 +29,10 @@ namespace util namespace vector { -template class Object final : public Reader +template class Object final : public Reader { public: - using Generator = std::function; + using Generator = std::function; public: Object(int32_t size, const Generator &gen) : _size{size} diff --git a/libs/util/src/environment.cpp b/libs/util/src/environment.cpp index dca6c5c..dd57e0c 100644 --- a/libs/util/src/environment.cpp +++ b/libs/util/src/environment.cpp @@ -25,7 +25,7 @@ namespace nnfw namespace util { -int get_env_int(const char* name) +int get_env_int(const char *name) { const char *value = std::getenv(name); if (value != nullptr) @@ -33,7 +33,7 @@ int get_env_int(const char* name) return 0; } -bool get_env_bool(const char* name) +bool get_env_bool(const char *name) { const char *value = std::getenv(name); if (value != nullptr) diff --git a/libs/util/src/tensor/Shape.cpp b/libs/util/src/tensor/Shape.cpp index d177d13..450b6f8 100644 --- a/libs/util/src/tensor/Shape.cpp +++ b/libs/util/src/tensor/Shape.cpp @@ -32,7 +32,7 @@ bool operator==(const Shape &lhs, const Shape &rhs) for (size_t axis = 0; axis < lhs.rank(); ++axis) { - if(lhs.dim(axis) != rhs.dim(axis)) + if (lhs.dim(axis) != rhs.dim(axis)) { return false; } -- 2.7.4