2 * Copyright (c) 2017, 2018 ARM Limited.
4 * SPDX-License-Identifier: MIT
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 #ifndef ARM_COMPUTE_GC
25 #error "This example needs to be built with -DARM_COMPUTE_GC"
26 #endif /* ARM_COMPUTE_GC */
28 #include "arm_compute/runtime/GLES_COMPUTE/GCFunctions.h"
29 #include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h"
30 #include "half/half.hpp"
31 #include "utils/Utils.h"
33 using namespace arm_compute;
34 using namespace utils;
36 class GCDCExample : public Example
39 void do_setup(int argc, char **argv) override
41 ARM_COMPUTE_UNUSED(argc);
42 ARM_COMPUTE_UNUSED(argv);
45 GCScheduler::get().default_init();
47 const TensorShape src_shape = TensorShape{ 11U /* W */, 13U /* H */, 4U /* C */, 3U /* N */ };
48 const unsigned int kernel_size = 3;
49 const int stride_x = 1;
50 const int stride_y = 1;
53 const unsigned int num_kernels = 256;
54 const DataType data_type = DataType::F16;
57 const TensorShape weights_shape(kernel_size, kernel_size, src_shape.z(), num_kernels);
58 const TensorShape bias_shape(num_kernels);
59 const PadStrideInfo pad_info(stride_x, stride_y, pad_x, pad_y, DimensionRoundingType::FLOOR);
61 // output shape should be 9*11*256*3 (W*H*C*N)
62 const TensorShape dst_shape = get_output_shape(src_shape, weights_shape, pad_info);
65 src.allocator()->init(TensorInfo(src_shape, 1, data_type));
66 weights.allocator()->init(TensorInfo(weights_shape, 1, data_type));
67 bias.allocator()->init(TensorInfo(bias_shape, 1, data_type));
68 dst.allocator()->init(TensorInfo(dst_shape, 1, data_type));
71 conv.configure(&src, &weights, &bias, &dst, pad_info);
74 src.allocator()->allocate();
75 weights.allocator()->allocate();
76 bias.allocator()->allocate();
77 dst.allocator()->allocate();
79 // To demonstrate how to fill tensor with some values...
82 window.use_tensor_dimensions(src_shape);
83 Iterator it(&src, window);
84 execute_window_loop(window, [&](const Coordinates & id)
86 *reinterpret_cast<half_float::half *>(it.ptr()) = half_float::half(1.f);
90 void do_run() override
95 void do_teardown() override
104 GCTensor src{}, weights{}, bias{}, dst{};
105 GCDirectConvolutionLayer conv{};
107 TensorShape get_output_shape(TensorShape in_shape, TensorShape kernel_shape, const PadStrideInfo &info)
109 TensorShape out_shape(in_shape);
110 const std::pair<unsigned int, unsigned int> scaled_dims = scaled_dimensions(in_shape.x(),
115 out_shape.set(0, scaled_dims.first);
116 out_shape.set(1, scaled_dims.second);
117 out_shape.set(2, kernel_shape[3]);
122 /** Main program for directconvolution test
124 * @param[in] argc Number of arguments
125 * @param[in] argv Arguments
127 int main(int argc, char **argv)
129 return utils::run_example<GCDCExample>(argc, argv);