summaryrefslogtreecommitdiff
path: root/libs/kernel/acl/src/DepthwiseConv2D.test.h
diff options
context:
space:
mode:
Diffstat (limited to 'libs/kernel/acl/src/DepthwiseConv2D.test.h')
-rw-r--r--libs/kernel/acl/src/DepthwiseConv2D.test.h245
1 files changed, 245 insertions, 0 deletions
diff --git a/libs/kernel/acl/src/DepthwiseConv2D.test.h b/libs/kernel/acl/src/DepthwiseConv2D.test.h
new file mode 100644
index 000000000..b2c8592ee
--- /dev/null
+++ b/libs/kernel/acl/src/DepthwiseConv2D.test.h
@@ -0,0 +1,245 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+#include <OperationsUtils.h>
+#include <kernel/acl/nnfw_kernel_acl.h>
+#include <kernel/acl/DepthwiseConv2D.h>
+
+// TODO: fix include path in CMakeFiles
+#include "util.h"
+
+#ifndef ACL_TEST
+#error "ACL_TEST should be defined first!"
+#endif // ACL_TEST
+
+#ifndef ACL_CORE_FUNC_NAME
+#error "ACL_CORE_FUNC_NAME should be defined first!"
+#endif // ACL_CORE_FUNC_NAME
+
+using namespace nnfw::kernel::acl;
+
+ACL_TEST(KernelACL_TC, dwise_conv2d_1) {
+ uint32_t input_n = 1;
+ uint32_t input_h = 3;
+ uint32_t input_w = 3;
+ uint32_t input_c = 1;
+ uint32_t filter_h = 3;
+ uint32_t filter_w = 3;
+ uint32_t filter_c = 1;
+ uint32_t out_h = 1;
+ uint32_t out_w = 1;
+
+ int32_t padding_left = 0;
+ int32_t padding_right = 0;
+ int32_t padding_top = 0;
+ int32_t padding_bottom = 0;
+ int32_t stride_width = 1;
+ int32_t stride_height = 1;
+ int32_t depth_multiplier = 1;
+
+ util::TensorWrapper input({input_n, input_h, input_w, input_c});
+ util::TensorWrapper weights({1, filter_h, filter_w, filter_c});
+ util::TensorWrapper bias({filter_c});
+ util::TensorWrapper output({1, out_h, out_w, filter_c});
+
+ int32_t activation = static_cast<int32_t>(FusedActivationFunc::RELU);
+
+ input.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) {
+ uint32_t N = input_n;
+ uint32_t H = input_h;
+ uint32_t W = input_w;
+ uint32_t C = input_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 H = filter_h;
+ 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;
+ });
+
+ 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;
+ });
+
+ EXPECT_EQ(output, expected);
+}
+
+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 input_c = 3;
+ uint32_t filter_h = 3;
+ uint32_t filter_w = 3;
+ uint32_t filter_c = input_c;
+ uint32_t out_h = 1;
+ uint32_t out_w = 1;
+
+ int32_t padding_left = 0;
+ int32_t padding_right = 0;
+ int32_t padding_top = 0;
+ int32_t padding_bottom = 0;
+ int32_t stride_width = 1;
+ int32_t stride_height = 1;
+ int32_t depth_multiplier = 1;
+
+ util::TensorWrapper input({input_n, input_h, input_w, input_c});
+ util::TensorWrapper weights({1, filter_h, filter_w, filter_c});
+ util::TensorWrapper bias({filter_c});
+ util::TensorWrapper output({1, out_h, out_w, filter_c});
+
+ int32_t activation = static_cast<int32_t>(FusedActivationFunc::RELU);
+
+ input.initValue([&](uint32_t n, uint32_t c, uint32_t h, uint32_t w) {
+ uint32_t N = input_n;
+ uint32_t H = input_h;
+ uint32_t W = input_w;
+ uint32_t C = input_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 H = filter_h;
+ 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;
+ });
+
+ 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
+ });
+
+ EXPECT_EQ(output, expected);
+}
+
+ACL_TEST(KernelACL_TC, dwise_conv2d_inception_1) {
+ uint32_t input_n = 1;
+ uint32_t input_h = 112;
+ uint32_t input_w = 112;
+ uint32_t input_c = 32;
+ uint32_t filter_h = 3;
+ uint32_t filter_w = 3;
+ uint32_t filter_c = input_c;
+ uint32_t out_h = 112;
+ uint32_t out_w = 112;
+
+ int32_t padding_left = 1;
+ int32_t padding_right = 1;
+ int32_t padding_top = 1;
+ int32_t padding_bottom = 1;
+ int32_t stride_width = 1;
+ int32_t stride_height = 1;
+ int32_t depth_multiplier = 1;
+
+ util::TensorWrapper input({input_n, input_h, input_w, input_c});
+ util::TensorWrapper weights({1, filter_h, filter_w, filter_c});
+ util::TensorWrapper bias({filter_c});
+ util::TensorWrapper output({1, out_h, out_w, filter_c});
+
+ 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;
+ });
+
+ 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 )
+ v -= 3.f;
+ 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) )
+ v += 1.f;
+
+ // Assumption: negative numbers cannot appear because
+ // only positive numbers exist in the input and weights.
+ float ret = c*c*v;
+ return std::min(ret, 6.f);
+ });
+
+ EXPECT_EQ(output, expected);
+}