This commit applies format checker to directory `libs`.
Signed-off-by: Junghyun Kim <jh0822.kim@samsung.com>
#include "shape.h"
#include "IO_accessor.h"
-namespace nnfw {
-namespace kernel {
-namespace acl {
-
-namespace common {
-
-typedef std::function<void (void)> sync_scheduler_f;
-
-template<class TensorT, class LayerT, class ActT>
-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<void(void)> sync_scheduler_f;
+
+template <class TensorT, class LayerT, class ActT>
+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);
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<LayerT>();
l->configure(input.ptr(), weights.ptr(), bias.ptr(), output.ptr(), psinfo);
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;
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;
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<float>(), input.shape(),
- weights.ptr<float>(), weights.shape(),
- bias.ptr<float>(), bias.shape(),
- padding_left, padding_right,
- padding_top, padding_bottom,
- stride_width, stride_height,
- depth_multiplier, activation,
- output.ptr<float>(), output.shape());
+ bool bret = ACL_CORE_FUNC_NAME(
+ input.ptr<float>(), input.shape(), weights.ptr<float>(), weights.shape(), bias.ptr<float>(),
+ bias.shape(), padding_left, padding_right, padding_top, padding_bottom, stride_width,
+ stride_height, depth_multiplier, activation, output.ptr<float>(), 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;
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;
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<float>(), input.shape(),
- weights.ptr<float>(), weights.shape(),
- bias.ptr<float>(), bias.shape(),
- padding_left, padding_right,
- padding_top, padding_bottom,
- stride_width, stride_height,
- depth_multiplier, activation,
- output.ptr<float>(), output.shape());
+ bool bret = ACL_CORE_FUNC_NAME(
+ input.ptr<float>(), input.shape(), weights.ptr<float>(), weights.shape(), bias.ptr<float>(),
+ bias.shape(), padding_left, padding_right, padding_top, padding_bottom, stride_width,
+ stride_height, depth_multiplier, activation, output.ptr<float>(), 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;
int32_t activation = static_cast<int32_t>(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<float>(), input.shape(),
- weights.ptr<float>(), weights.shape(),
- bias.ptr<float>(), bias.shape(),
- padding_left, padding_right,
- padding_top, padding_bottom,
- stride_width, stride_height,
- depth_multiplier, activation,
- output.ptr<float>(), output.shape());
+ bool bret = ACL_CORE_FUNC_NAME(
+ input.ptr<float>(), input.shape(), weights.ptr<float>(), weights.shape(), bias.ptr<float>(),
+ bias.shape(), padding_left, padding_right, padding_top, padding_bottom, stride_width,
+ stride_height, depth_multiplier, activation, output.ptr<float>(), 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);
});
#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<void (void)> sync_scheduler_f;
+typedef std::function<void(void)> sync_scheduler_f;
-template<class TensorT, class LayerT, class ActT>
-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 <class TensorT, class LayerT, class ActT>
+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.
{
auto relu_f = std::make_shared<ActT>();
- 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);
#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<int32_t>(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<float>(), input.shape(),
- weights.ptr<float>(), weights.shape(),
- bias.ptr<float>(), bias.shape(),
- activation,
- output.ptr<float>(), output.shape());
+ bool bret = ACL_CORE_FUNC_NAME(input.ptr<float>(), input.shape(), weights.ptr<float>(),
+ weights.shape(), bias.ptr<float>(), bias.shape(), activation,
+ output.ptr<float>(), 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<int32_t>(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<float>(), input.shape(),
- weights.ptr<float>(), weights.shape(),
- bias.ptr<float>(), bias.shape(),
- activation,
- output.ptr<float>(), output.shape());
+ bool bret = ACL_CORE_FUNC_NAME(input.ptr<float>(), input.shape(), weights.ptr<float>(),
+ weights.shape(), bias.ptr<float>(), bias.shape(), activation,
+ output.ptr<float>(), 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;
int32_t activation = static_cast<int32_t>(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});
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<float>(), input.shape(),
- weight.ptr<float>(), weight.shape(),
- bias.ptr<float>(), bias.shape(),
- activation,
- output.ptr<float>(), output.shape());
+ bool bret = ACL_CORE_FUNC_NAME(input.ptr<float>(), input.shape(), weight.ptr<float>(),
+ weight.shape(), bias.ptr<float>(), bias.shape(), activation,
+ output.ptr<float>(), 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;
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<float>(), input.shape(),
- weight.ptr<float>(), weight.shape(),
- bias.ptr<float>(), bias.shape(),
- activation,
- output.ptr<float>(), output.shape());
+ bool bret = ACL_CORE_FUNC_NAME(input.ptr<float>(), input.shape(), weight.ptr<float>(),
+ weight.shape(), bias.ptr<float>(), bias.shape(), activation,
+ output.ptr<float>(), 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<int32_t>(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<float>(), input.shape(),
- weight.ptr<float>(), weight.shape(),
- bias.ptr<float>(), bias.shape(),
- activation,
- output.ptr<float>(), output.shape());
+ bool bret = ACL_CORE_FUNC_NAME(input.ptr<float>(), input.shape(), weight.ptr<float>(),
+ weight.shape(), bias.ptr<float>(), bias.shape(), activation,
+ output.ptr<float>(), 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);
}
-
#include <cassert>
-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);
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);
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];
uint32_t offset = getElementOffset(_inputShape, nth, ch, row, col);
- *reinterpret_cast<float *>(tensor.ptr_to_element(id)) =
- *(_inputData + offset);
+ *reinterpret_cast<float *>(tensor.ptr_to_element(id)) = *(_inputData + offset);
});
return true;
}
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<float *>(tensor.ptr_to_element(id)) =
- *(_inputData + offset);
+ *reinterpret_cast<float *>(tensor.ptr_to_element(id)) = *(_inputData + offset);
});
return true;
}
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<float *>(tensor.ptr_to_element(id)) =
- *(_inputData + offset);
+ *reinterpret_cast<float *>(tensor.ptr_to_element(id)) = *(_inputData + offset);
});
return true;
}
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];
uint32_t offset = getElementOffset(_filterShape, nth, ch, row, col);
- *reinterpret_cast<float *>(tensor.ptr_to_element(id)) =
- *(_filterData + offset);
+ *reinterpret_cast<float *>(tensor.ptr_to_element(id)) = *(_filterData + offset);
});
return true;
}
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<float *>(tensor.ptr_to_element(id)) =
- *(_filterData + offset);
+ *reinterpret_cast<float *>(tensor.ptr_to_element(id)) = *(_filterData + offset);
});
return true;
}
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<float *>(tensor.ptr_to_element(id)) =
- *(_biasData + offset);
+ *reinterpret_cast<float *>(tensor.ptr_to_element(id)) = *(_biasData + offset);
});
return true;
}
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];
uint32_t offset = getElementOffset(_outputShape, nth, ch, row, col);
- *(_outputData + offset) =
- *reinterpret_cast<float *>(tensor.ptr_to_element(id));
+ *(_outputData + offset) = *reinterpret_cast<float *>(tensor.ptr_to_element(id));
});
return false; // end the network
}
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<float *>(tensor.ptr_to_element(id));
+ *(_outputData + offset) = *reinterpret_cast<float *>(tensor.ptr_to_element(id));
});
return false; // end the network
}
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<float *>(tensor.ptr_to_element(id));
+ *(_outputData + offset) = *reinterpret_cast<float *>(tensor.ptr_to_element(id));
});
return false; // end the network
}
#include <OperationsUtils.h> // 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<typename AccessorType>
-inline void TensorAccess(arm_compute::CLTensor& tensor, const float* data,
- const nnfw::rt::Shape& shape)
+template <typename AccessorType>
+inline void TensorAccess(arm_compute::CLTensor &tensor, const float *data,
+ const nnfw::rt::Shape &shape)
{
tensor.map();
AccessorType accessor(data, shape);
tensor.unmap();
}
-template<typename AccessorType>
-inline void TensorAccess(arm_compute::CLTensor& tensor, float* data,
- const nnfw::rt::Shape& shape)
+template <typename AccessorType>
+inline void TensorAccess(arm_compute::CLTensor &tensor, float *data, const nnfw::rt::Shape &shape)
{
tensor.map();
AccessorType accessor(data, shape);
tensor.unmap();
}
-template<typename AccessorType>
-inline void TensorAccess(arm_compute::Tensor& tensor, const float* data,
- const nnfw::rt::Shape& shape)
+template <typename AccessorType>
+inline void TensorAccess(arm_compute::Tensor &tensor, const float *data,
+ const nnfw::rt::Shape &shape)
{
AccessorType accessor(data, shape);
accessor.access_tensor(tensor);
}
-template<typename AccessorType>
-inline void TensorAccess(arm_compute::Tensor& tensor, float* data,
- const nnfw::rt::Shape& shape)
+template <typename AccessorType>
+inline void TensorAccess(arm_compute::Tensor &tensor, float *data, const nnfw::rt::Shape &shape)
{
AccessorType accessor(data, shape);
accessor.access_tensor(tensor);
#include <arm_compute/runtime/CL/CLScheduler.h>
#include <kernel/acl/nnfw_kernel_acl.h>
-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
#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<void (void)> sync_scheduler_f;
+typedef std::function<void(void)> sync_scheduler_f;
-template<class TensorT, class LayerT>
-bool reshapeGeneric(const void* inputData, const nnfw::rt::Shape& inputShape,
- void* outputData, const nnfw::rt::Shape& outputShape,
- sync_scheduler_f sync_scheduler) {
+template <class TensorT, class LayerT>
+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);
input.allocate();
output.allocate();
- TensorAccess<InputAccessor>(input.ref(), (float*)inputData, inputShape);
+ TensorAccess<InputAccessor>(input.ref(), (float *)inputData, inputShape);
l.run();
sync_scheduler();
- TensorAccess<OutputAccessor>(output.ref(), (float*)outputData, outputShape);
+ TensorAccess<OutputAccessor>(output.ref(), (float *)outputData, outputShape);
return true;
}
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);
-
}
#include <arm_compute/runtime/Tensor.h>
#include <arm_compute/runtime/CL/CLTensor.h>
-namespace nnfw {
-namespace kernel {
-namespace acl {
+namespace nnfw
+{
+namespace kernel
+{
+namespace acl
+{
-template<class TensorT>
-class UniqueTensor
+template <class TensorT> 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
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; }
#include "../IO_accessor.h"
#include "../shape.h"
-namespace nnfw {
-namespace kernel {
-namespace acl {
+namespace nnfw
+{
+namespace kernel
+{
+namespace acl
+{
-bool concatenationFloat32(const std::vector<const float*>& inputDataPtrs,
- const std::vector<nnfw::rt::Shape>& inputShapes, int32_t axis,
- float* outputData, const nnfw::rt::Shape& outputShape)
+bool concatenationFloat32(const std::vector<const float *> &inputDataPtrs,
+ const std::vector<nnfw::rt::Shape> &inputShapes, int32_t axis,
+ float *outputData, const nnfw::rt::Shape &outputShape)
{
if (axis != 3)
{
}
assert(inputDataPtrs.size() == inputShapes.size());
- std::vector<arm_compute::CLTensor*> inputPtrs;
- std::vector<arm_compute::ICLTensor*> inputIptrs;
+ std::vector<arm_compute::CLTensor *> inputPtrs;
+ std::vector<arm_compute::ICLTensor *> inputIptrs;
arm_compute::CLTensor output;
// init Tensors
std::vector<nnfw::rt::Shape>::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);
// allocate Tensors
it_inputShape = inputShapes.begin();
- std::vector<const float*>::const_iterator it_inputData = inputDataPtrs.begin();
+ std::vector<const float *>::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<InputAccessor>(*inputPtr, inputData, inputShape);
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<const float*> 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<const float *> inputDataPtrs;
std::vector<nnfw::rt::Shape> 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);
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);
#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));
fns.emplace_back(conv_f);
- util::insertFusedActivationLayer<CLUniqueTensor, arm_compute::CLActivationLayer>(output, activation, fns);
+ util::insertFusedActivationLayer<CLUniqueTensor, arm_compute::CLActivationLayer>(output,
+ activation, fns);
input.allocate();
output.allocate();
nnfw::support::acl::feature::Reader<float> acl_ifm_reader{input.ptr()};
std::cout << "NNAPI IFM:" << std::endl;
- std::cout << nnfw::util::feature::TextFormatter<float>{ifm_shape, nnapi_ifm_reader} << std::endl;
+ std::cout << nnfw::util::feature::TextFormatter<float>{ifm_shape, nnapi_ifm_reader}
+ << std::endl;
std::cout << "ARM Compute IFM:" << std::endl;
std::cout << nnfw::util::feature::TextFormatter<float>{ifm_shape, acl_ifm_reader} << std::endl;
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;
int32_t stride_height = 1;
int32_t activation = static_cast<int32_t>(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);
}
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;
int32_t stride_height = 1;
int32_t activation = static_cast<int32_t>(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);
}
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;
int32_t stride_height = 1;
int32_t activation = static_cast<int32_t>(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);
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;
int32_t stride_height = 1;
int32_t activation = static_cast<int32_t>(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);
#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<CLUniqueTensor, arm_compute::CLDepthwiseConvolutionLayer,
- 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);
+ 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
-
#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<CLUniqueTensor, arm_compute::CLFullyConnectedLayer,
- arm_compute::CLActivationLayer>(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
#include <cassert>
-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<std::shared_ptr<arm_compute::IFunction>> 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));
input.allocate();
output.allocate();
- util::insertFusedActivationLayer<CLUniqueTensor, arm_compute::CLActivationLayer>(output, activation, fns);
+ util::insertFusedActivationLayer<CLUniqueTensor, arm_compute::CLActivationLayer>(output,
+ activation, fns);
TensorAccess<InputAccessor>(input.ref(), inputData, 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<std::shared_ptr<arm_compute::IFunction>> 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));
input.allocate();
output.allocate();
- util::insertFusedActivationLayer<CLUniqueTensor, arm_compute::CLActivationLayer>(output, activation, fns);
+ util::insertFusedActivationLayer<CLUniqueTensor, arm_compute::CLActivationLayer>(output,
+ activation, fns);
TensorAccess<InputAccessor>(input.ref(), inputData, inputShape);
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;
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<float>(), inputShape,
- padding_left, padding_right,
- padding_top, padding_bottom,
- stride_width, stride_height,
- filter_width, filter_height,
- activation,
- outputData, outputShape);
+ bret = maxPoolFloat32(input.ptr<float>(), 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;
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<float>(), inputShape,
- padding_left, padding_right,
- padding_top, padding_bottom,
- stride_width, stride_height,
- filter_width, filter_height,
- activation,
- outputData, outputShape);
+ bret = maxPoolFloat32(input.ptr<float>(), 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;
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<float>(), inputShape,
- padding_left, padding_right,
- padding_top, padding_bottom,
- stride_width, stride_height,
- filter_width, filter_height,
- activation,
- outputData, outputShape);
+ bret = maxPoolFloat32(input.ptr<float>(), 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;
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<float>(), input.shape(),
- padding_left, padding_right,
- padding_top, padding_bottom,
- stride_width, stride_height,
- filter_width, filter_height,
- activation,
- output.ptr<float>(), output.shape());
+ bool bret = maxPoolFloat32(input.ptr<float>(), input.shape(), padding_left, padding_right,
+ padding_top, padding_bottom, stride_width, stride_height, filter_width,
+ filter_height, activation, output.ptr<float>(), 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;
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<float>(), input.shape(),
- padding_left, padding_right,
- padding_top, padding_bottom,
- stride_width, stride_height,
- filter_width, filter_height,
- activation,
- output.ptr<float>(), output.shape());
+ bool bret = maxPoolFloat32(input.ptr<float>(), input.shape(), padding_left, padding_right,
+ padding_top, padding_bottom, stride_width, stride_height, filter_width,
+ filter_height, activation, output.ptr<float>(), 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;
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<float>(), inputShape,
- padding_left, padding_right,
- padding_top, padding_bottom,
- stride_width, stride_height,
- filter_width, filter_height,
- activation,
- outputData, outputShape);
+ bret = averagePoolFloat32(input.ptr<float>(), 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;
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<float>(), inputShape,
- padding_left, padding_right,
- padding_top, padding_bottom,
- stride_width, stride_height,
- filter_width, filter_height,
- activation,
- outputData, outputShape);
+ bret = averagePoolFloat32(input.ptr<float>(), 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;
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<float>(), inputShape,
- padding_left, padding_right,
- padding_top, padding_bottom,
- stride_width, stride_height,
- filter_width, filter_height,
- activation,
- outputData, outputShape);
+ bret = averagePoolFloat32(input.ptr<float>(), 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<uint32_t> dims = {1,3,3,1};
+ std::vector<uint32_t> dims = {1, 3, 3, 1};
util::TensorWrapper input(dims);
util::TensorWrapper output(dims);
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<float>(), input.shape(),
- padding_left, padding_right,
- padding_top, padding_bottom,
- stride_width, stride_height,
- filter_width, filter_height,
- activation,
- output.ptr<float>(), output.shape());
+ bool bret =
+ averagePoolFloat32(input.ptr<float>(), input.shape(), padding_left, padding_right,
+ padding_top, padding_bottom, stride_width, stride_height, filter_width,
+ filter_height, activation, output.ptr<float>(), 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;
TEST(KernelACL_TC, averagePoolFloat32_35x35to35x35)
{
- int32_t N=35;
- std::vector<uint32_t> dims = {1,35,35,768};
+ int32_t N = 35;
+ std::vector<uint32_t> dims = {1, 35, 35, 768};
util::TensorWrapper input(dims);
util::TensorWrapper output(dims);
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<float>(), input.shape(),
- padding_left, padding_right,
- padding_top, padding_bottom,
- stride_width, stride_height,
- filter_width, filter_height,
- activation,
- output.ptr<float>(), output.shape());
+ bool bret =
+ averagePoolFloat32(input.ptr<float>(), input.shape(), padding_left, padding_right,
+ padding_top, padding_bottom, stride_width, stride_height, filter_width,
+ filter_height, activation, output.ptr<float>(), 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;
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<float>(), input.shape(),
- padding_left, padding_right,
- padding_top, padding_bottom,
- stride_width, stride_height,
- filter_width, filter_height,
- activation,
- output.ptr<float>(), output.shape());
+ bool bret =
+ averagePoolFloat32(input.ptr<float>(), input.shape(), padding_left, padding_right,
+ padding_top, padding_bottom, stride_width, stride_height, filter_width,
+ filter_height, activation, output.ptr<float>(), 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);
}
#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<CLUniqueTensor, arm_compute::CLReshapeLayer>
- (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<CLUniqueTensor, arm_compute::CLReshapeLayer>(
+ inputData, inputShape, outputData, outputShape, sync_scheduler);
}
} // namespace acl
#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);
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;
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);
}
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;
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);
}
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;
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;
public:
virtual ~TestEnvironment() = default;
- virtual void SetUp()
- {
- nnfw::kernel::acl::Initialize();
- }
+ virtual void SetUp() { nnfw::kernel::acl::Initialize(); }
virtual void TearDown()
{
}
};
-static ::testing::Environment* const testingenv =
- ::testing::AddGlobalTestEnvironment(new TestEnvironment);
+static ::testing::Environment *const testingenv =
+ ::testing::AddGlobalTestEnvironment(new TestEnvironment);
#include "../IO_accessor.h"
#include "../shape.h"
-namespace nnfw {
-namespace kernel {
-namespace acl {
-namespace neon {
-
-bool concatenationFloat32(const std::vector<const float*>& inputDataPtrs,
- const std::vector<nnfw::rt::Shape>& inputShapes, int32_t axis,
- float* outputData, const nnfw::rt::Shape& outputShape)
+namespace nnfw
+{
+namespace kernel
+{
+namespace acl
+{
+namespace neon
+{
+
+bool concatenationFloat32(const std::vector<const float *> &inputDataPtrs,
+ const std::vector<nnfw::rt::Shape> &inputShapes, int32_t axis,
+ float *outputData, const nnfw::rt::Shape &outputShape)
{
if (axis != 3)
{
}
assert(inputDataPtrs.size() == inputShapes.size());
- std::vector<arm_compute::Tensor*> inputPtrs;
- std::vector<arm_compute::ITensor*> inputIptrs;
+ std::vector<arm_compute::Tensor *> inputPtrs;
+ std::vector<arm_compute::ITensor *> inputIptrs;
arm_compute::Tensor output;
// init Tensors
std::vector<nnfw::rt::Shape>::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);
// allocate Tensors
it_inputShape = inputShapes.begin();
- std::vector<const float*>::const_iterator it_inputData = inputDataPtrs.begin();
+ std::vector<const float *>::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<InputAccessor>(*inputPtr, inputData, inputShape);
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<const float*> 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<const float *> inputDataPtrs;
std::vector<nnfw::rt::Shape> 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);
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);
#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));
fns.emplace_back(conv_f);
- util::insertFusedActivationLayer<NEUniqueTensor, arm_compute::NEActivationLayer>(output, activation, fns);
+ util::insertFusedActivationLayer<NEUniqueTensor, arm_compute::NEActivationLayer>(output,
+ activation, fns);
input.allocate();
output.allocate();
{
auto ifm_shape = nnfw::support::nnapi::feature::asFeatureShape(inputShape);
nnfw::support::nnapi::feature::Reader<float> nnapi_ifm_reader{ifm_shape, inputData};
- nnfw::support::acl::feature::Reader<float> acl_ifm_reader{ input.ptr() };
+ nnfw::support::acl::feature::Reader<float> acl_ifm_reader{input.ptr()};
std::cout << "NNAPI IFM:" << std::endl;
- std::cout << nnfw::util::feature::TextFormatter<float>{ifm_shape, nnapi_ifm_reader} << std::endl;
+ std::cout << nnfw::util::feature::TextFormatter<float>{ifm_shape, nnapi_ifm_reader}
+ << std::endl;
std::cout << "ARM Compute IFM:" << std::endl;
std::cout << nnfw::util::feature::TextFormatter<float>{ifm_shape, acl_ifm_reader} << std::endl;
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;
int32_t stride_height = 1;
int32_t activation = static_cast<int32_t>(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);
}
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;
int32_t stride_height = 1;
int32_t activation = static_cast<int32_t>(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);
}
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;
int32_t stride_height = 1;
int32_t activation = static_cast<int32_t>(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);
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;
int32_t stride_height = 1;
int32_t activation = static_cast<int32_t>(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);
#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<NEUniqueTensor, arm_compute::NEDepthwiseConvolutionLayer,
- 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);
+ 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
#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<NEUniqueTensor, arm_compute::NEFullyConnectedLayer,
- arm_compute::NEActivationLayer>(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
-
#define ACL_TEST(tc, t) TEST(tc, neon_##t)
#include "../FullyConnected.test.h"
-
#include <cassert>
-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<std::shared_ptr<arm_compute::IFunction>> 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));
fns.emplace_back(pool_f);
- util::insertFusedActivationLayer<NEUniqueTensor, arm_compute::NEActivationLayer>(output, activation, fns);
+ util::insertFusedActivationLayer<NEUniqueTensor, arm_compute::NEActivationLayer>(output,
+ activation, fns);
input.allocate();
output.allocate();
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<std::shared_ptr<arm_compute::IFunction>> 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));
fns.emplace_back(pool_f);
- util::insertFusedActivationLayer<NEUniqueTensor, arm_compute::NEActivationLayer>(output, activation, fns);
+ util::insertFusedActivationLayer<NEUniqueTensor, arm_compute::NEActivationLayer>(output,
+ activation, fns);
input.allocate();
output.allocate();
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;
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<float>(), 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<float>(), 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;
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<float>(), 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<float>(), 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;
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<float>(), 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<float>(), 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;
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<float>(), input.shape(),
- padding_left, padding_right,
- padding_top, padding_bottom,
- stride_width, stride_height,
- filter_width, filter_height,
- activation,
- output.ptr<float>(), output.shape());
+ bool bret =
+ neon::maxPoolFloat32(input.ptr<float>(), input.shape(), padding_left, padding_right,
+ padding_top, padding_bottom, stride_width, stride_height, filter_width,
+ filter_height, activation, output.ptr<float>(), 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;
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<float>(), input.shape(),
- padding_left, padding_right,
- padding_top, padding_bottom,
- stride_width, stride_height,
- filter_width, filter_height,
- activation,
- output.ptr<float>(), output.shape());
+ bool bret =
+ neon::maxPoolFloat32(input.ptr<float>(), input.shape(), padding_left, padding_right,
+ padding_top, padding_bottom, stride_width, stride_height, filter_width,
+ filter_height, activation, output.ptr<float>(), 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;
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<float>(), 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<float>(), 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;
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<float>(), 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<float>(), 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;
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<float>(), 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<float>(), 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<uint32_t> dims = {1,35,35,192};
+ std::vector<uint32_t> dims = {1, 35, 35, 192};
util::TensorWrapper input(dims);
util::TensorWrapper output(dims);
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<float>(), input.shape(),
- padding_left, padding_right,
- padding_top, padding_bottom,
- stride_width, stride_height,
- filter_width, filter_height,
- activation,
- output.ptr<float>(), output.shape());
+ bool bret = neon::averagePoolFloat32(input.ptr<float>(), input.shape(), padding_left,
+ padding_right, padding_top, padding_bottom, stride_width,
+ stride_height, filter_width, filter_height, activation,
+ output.ptr<float>(), 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;
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<float>(), input.shape(),
- padding_left, padding_right,
- padding_top, padding_bottom,
- stride_width, stride_height,
- filter_width, filter_height,
- activation,
- output.ptr<float>(), output.shape());
+ bool bret = neon::averagePoolFloat32(input.ptr<float>(), input.shape(), padding_left,
+ padding_right, padding_top, padding_bottom, stride_width,
+ stride_height, filter_width, filter_height, activation,
+ output.ptr<float>(), 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);
}
#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<NEUniqueTensor, arm_compute::NEReshapeLayer>
- (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<NEUniqueTensor, arm_compute::NEReshapeLayer>(
+ inputData, inputShape, outputData, outputShape, sync_scheduler);
}
} // namespace neon
} // namespace acl
} // namespace kernel
} // namespace nnfw
-
#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);
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;
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);
}
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;
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);
}
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;
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;
#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);
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);
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.
#include <arm_compute/runtime/IFunction.h>
#include <cassert>
-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<class TensorT, class ActT>
-void insertFusedActivationLayer(TensorT& out, int activation,
- std::vector<std::shared_ptr<arm_compute::IFunction>>& 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 <class TensorT, class ActT>
+void insertFusedActivationLayer(TensorT &out, int activation,
+ std::vector<std::shared_ptr<arm_compute::IFunction>> &fns)
+{
auto relu_f = std::make_shared<ActT>();
- 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);
// 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:
//
// 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
namespace feature
{
-template<typename T> class Reader;
+template <typename T> class Reader;
-template<> class Reader<float> final : public nnfw::util::feature::Reader<float>
+template <> class Reader<float> final : public nnfw::util::feature::Reader<float>
{
public:
Reader(arm_compute::ITensor *tensor) : _tensor{tensor}
float *ptr_to_element(uint32_t ch, uint32_t row, uint32_t col) const
{
// ARM Compute uses CHW ordering
- return reinterpret_cast<float *>(_tensor->ptr_to_element(arm_compute::Coordinates{col, row, ch}));
+ return reinterpret_cast<float *>(
+ _tensor->ptr_to_element(arm_compute::Coordinates{col, row, ch}));
}
private:
#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++;
}
// 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;
}
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);
#include <cassert>
#include <functional>
-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<uint32_t> dims,
- OperandType type = OperandType::FLOAT32,
- float scale = 1.0,
- int32_t offset = 0)
- :_shape{type, dims, scale, offset}
+ TensorWrapper(std::vector<uint32_t> 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<class T>
- T at(const uint32_t& idx) const {
- return reinterpret_cast<T*>(_data)[idx];
- }
+ template <class T> T at(const uint32_t &idx) const { return reinterpret_cast<T *>(_data)[idx]; }
- template<class T>
- T& at(const uint32_t& idx) {
- return reinterpret_cast<T*>(_data)[idx];
- }
+ template <class T> T &at(const uint32_t &idx) { return reinterpret_cast<T *>(_data)[idx]; }
- template<class T>
- T* ptr() { return reinterpret_cast<T*>(_data); }
+ template <class T> T *ptr() { return reinterpret_cast<T *>(_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<float>(i) = f;
}
}
typedef std::function<float(uint32_t n, uint32_t c, uint32_t h, uint32_t w)> funcInit4;
- void initValue(funcInit4 f) {
+ void initValue(funcInit4 f)
+ {
assert(_shape.dimensions.size() == 4);
int N = _shape.dimensions[0];
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<float>(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<float>(offset) = f(n, c, h, w);
}
}
}
}
typedef std::function<float(uint32_t c, uint32_t h, uint32_t w)> 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<float>(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<float>(offset) = f(c, h, w);
}
}
}
}
typedef std::function<float(uint32_t h, uint32_t w)> 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<float>(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<float>(offset) = f(h, w);
}
}
}
typedef std::function<float(uint32_t w)> 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<float>(offset) = f(w);
}
}
- void initValue(std::vector<float> v) {
+ void initValue(std::vector<float> 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<float>(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);
// currently, we support only FLOAT32.
assert(_shape.type == OperandType::FLOAT32);
- for( uint32_t i = 0; i < _num_elems; ++i ) {
- if( std::fabs(static_cast<float>(at<float>(i) - t.at<float>(i))) > 0.001f ) {
- std::cout << "Comparing [" << i << "] " << at<float>(i) << "," << t.at<float>(i) << std::endl;
+ for (uint32_t i = 0; i < _num_elems; ++i)
+ {
+ if (std::fabs(static_cast<float>(at<float>(i) - t.at<float>(i))) > 0.001f)
+ {
+ std::cout << "Comparing [" << i << "] " << at<float>(i) << "," << t.at<float>(i)
+ << std::endl;
return false;
}
}
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
{
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;
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<float> &expected,
- const nnfw::support::tflite::TensorView<float> &obtained,
- int id) const
+bool TfLiteInterpMatchApp::compareSingleTensorView(
+ const nnfw::support::tflite::TensorView<float> &expected,
+ const nnfw::support::tflite::TensorView<float> &obtained, int id) const
{
DiffSummary summary;
// 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;
{
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;
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;
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<float> dist(0.0f, 2.0f);
return dist(_rand);
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;
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))
namespace tflite
{
-TensorView<float>::TensorView(const nnfw::util::tensor::Shape &shape, float *base) : _shape{shape}, _base{base}
+TensorView<float>::TensorView(const nnfw::util::tensor::Shape &shape, float *base)
+ : _shape{shape}, _base{base}
{
// Set 'stride'
_stride.init(_shape);
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<float> view{shape, value};
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)
return acc;
}
-template <typename T> Accumulator<T> measure(T &out)
-{
- return Accumulator<T>(out);
-}
+template <typename T> Accumulator<T> measure(T &out) { return Accumulator<T>(out); }
} // namespace benchmark
} // namespace util
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);
}
}
public:
Index(int32_t ch, int32_t row, int32_t col) : _ch{ch}, _row{row}, _col{col}
{
- // DO NOTHING
+ // DO NOTHING
}
public:
namespace feature
{
-template<typename T> class Object final : public Reader<T>
+template <typename T> class Object final : public Reader<T>
{
public:
- using Generator = std::function<T (const Shape &shape, const Index &index)>;
+ using Generator = std::function<T(const Shape &shape, const Index &index)>;
public:
Object(const Shape &shape, const Generator &fn) : _shape{shape}
{
// DO NOTHING
}
-
};
} // namespace feature
template <typename T> class TextFormatter
{
public:
- TextFormatter(const Shape &shape, const Reader<T> &data)
- : _shape(shape), _data(data)
+ TextFormatter(const Shape &shape, const Reader<T> &data) : _shape(shape), _data(data)
{
// DO NOTHING
}
const Reader<T> &_data;
};
-template <typename T>
-std::ostream &operator<<(std::ostream &os, const TextFormatter<T> &fmt)
+template <typename T> std::ostream &operator<<(std::ostream &os, const TextFormatter<T> &fmt)
{
const auto &shape = fmt.shape();
namespace kernel
{
-template<typename T> class RandomObject final : public Reader<T>
+template <typename T> class RandomObject final : public Reader<T>
{
public:
RandomObject(const Shape &shape) : _shape{shape}
struct Index
{
public:
- Index(size_t rank)
- {
- _offsets.resize(rank);
- }
+ Index(size_t rank) { _offsets.resize(rank); }
public:
Index(std::initializer_list<int32_t> offsets) : _offsets{offsets}
namespace tensor
{
-template<typename T> class Object final : public Reader<T>
+template <typename T> class Object final : public Reader<T>
{
public:
- using Generator = std::function<T (const Shape &shape, const Index &index)>;
+ using Generator = std::function<T(const Shape &shape, const Index &index)>;
public:
Object(const Shape &shape, const Generator &fn) : _shape{shape}
_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;
class Shape
{
public:
- Shape(size_t rank)
- {
- _dimensions.resize(rank);
- }
+ Shape(size_t rank) { _dimensions.resize(rank); }
public:
Shape(const std::initializer_list<int32_t> &dimensions) : _dimensions{dimensions}
{
public:
Zipper(const Shape &shape, const Reader<T> &lhs, const Reader<T> &rhs)
- : _shape{shape}, _lhs{lhs}, _rhs{rhs}
+ : _shape{shape}, _lhs{lhs}, _rhs{rhs}
{
// DO NOTHING
}
public:
template <typename Callable> 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:
const Reader<T> &_rhs;
};
-template<typename T, typename Callable>
+template <typename T, typename Callable>
const Zipper<T> &operator<<(const Zipper<T> &zipper, Callable cb)
{
zipper.zip(cb);
return zipper;
}
-template<typename T>
-Zipper<T> zip(const Shape &shape, const Reader<T> &lhs, const Reader<T> &rhs)
+template <typename T> Zipper<T> zip(const Shape &shape, const Reader<T> &lhs, const Reader<T> &rhs)
{
return Zipper<T>{shape, lhs, rhs};
}
#include <vector>
-template <typename T>
-bool operator==(const std::vector<T> &lhs, const std::vector<T> &rhs)
+template <typename T> bool operator==(const std::vector<T> &lhs, const std::vector<T> &rhs)
{
if (lhs.size() != rhs.size())
{
namespace vector
{
-template<typename T> class Object final : public Reader<T>
+template <typename T> class Object final : public Reader<T>
{
public:
- using Generator = std::function<T (int32_t size, int32_t offset)>;
+ using Generator = std::function<T(int32_t size, int32_t offset)>;
public:
Object(int32_t size, const Generator &gen) : _size{size}
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)
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)
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;
}