From 2b5f0f2574551f59970bb9d710bafad2bc4bbd4a Mon Sep 17 00:00:00 2001 From: Michalis Spyrou Date: Wed, 10 Jan 2018 14:08:50 +0000 Subject: COMPMID-782 Port examples to the new format Change-Id: Ib178a97c080ff650094d02ee49e2a0aa22376dd0 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/115717 Reviewed-by: Anthony Barbier Tested-by: Jenkins --- examples/gc_dc.cpp | 141 ++++++++++++++++++++++++++++------------------------- 1 file changed, 74 insertions(+), 67 deletions(-) (limited to 'examples/gc_dc.cpp') diff --git a/examples/gc_dc.cpp b/examples/gc_dc.cpp index 174c88458d..8b6f4414e0 100644 --- a/examples/gc_dc.cpp +++ b/examples/gc_dc.cpp @@ -33,84 +33,91 @@ using namespace arm_compute; using namespace utils; -namespace +class GCDCExample : public Example { -TensorShape get_output_shape(TensorShape in_shape, TensorShape kernel_shape, const PadStrideInfo &info) -{ - TensorShape out_shape(in_shape); - const std::pair scaled_dims = scaled_dimensions(in_shape.x(), - in_shape.y(), - kernel_shape.x(), - kernel_shape.y(), - info); - out_shape.set(0, scaled_dims.first); - out_shape.set(1, scaled_dims.second); - out_shape.set(2, kernel_shape[3]); - return out_shape; -} -} // namespace - -void main_gc_dc(int argc, char **argv) -{ - ARM_COMPUTE_UNUSED(argc); - ARM_COMPUTE_UNUSED(argv); +public: + void do_setup(int argc, char **argv) override + { + ARM_COMPUTE_UNUSED(argc); + ARM_COMPUTE_UNUSED(argv); - // init instance - GCScheduler::get().default_init(); + // init instance + GCScheduler::get().default_init(); - const TensorShape src_shape = TensorShape{ 11U /* W */, 13U /* H */, 4U /* C */, 3U /* N */ }; - const unsigned int kernel_size = 3; - const int stride_x = 1; - const int stride_y = 1; - const int pad_x = 0; - const int pad_y = 0; - const unsigned int num_kernels = 256; - const DataType data_type = DataType::F16; + const TensorShape src_shape = TensorShape{ 11U /* W */, 13U /* H */, 4U /* C */, 3U /* N */ }; + const unsigned int kernel_size = 3; + const int stride_x = 1; + const int stride_y = 1; + const int pad_x = 0; + const int pad_y = 0; + const unsigned int num_kernels = 256; + const DataType data_type = DataType::F16; - // generate shape - const TensorShape weights_shape(kernel_size, kernel_size, src_shape.z(), num_kernels); - const TensorShape bias_shape(num_kernels); - const PadStrideInfo pad_info(stride_x, stride_y, pad_x, pad_y, DimensionRoundingType::FLOOR); + // generate shape + const TensorShape weights_shape(kernel_size, kernel_size, src_shape.z(), num_kernels); + const TensorShape bias_shape(num_kernels); + const PadStrideInfo pad_info(stride_x, stride_y, pad_x, pad_y, DimensionRoundingType::FLOOR); - // output shape should be 9*11*256*3 (W*H*C*N) - const TensorShape dst_shape = get_output_shape(src_shape, weights_shape, pad_info); + // output shape should be 9*11*256*3 (W*H*C*N) + const TensorShape dst_shape = get_output_shape(src_shape, weights_shape, pad_info); - // create tensors - GCTensor src, weights, bias, dst; - src.allocator()->init(TensorInfo(src_shape, 1, data_type)); - weights.allocator()->init(TensorInfo(weights_shape, 1, data_type)); - bias.allocator()->init(TensorInfo(bias_shape, 1, data_type)); - dst.allocator()->init(TensorInfo(dst_shape, 1, data_type)); + // create tensors + src.allocator()->init(TensorInfo(src_shape, 1, data_type)); + weights.allocator()->init(TensorInfo(weights_shape, 1, data_type)); + bias.allocator()->init(TensorInfo(bias_shape, 1, data_type)); + dst.allocator()->init(TensorInfo(dst_shape, 1, data_type)); - // configure layer - GCDirectConvolutionLayer conv; - conv.configure(&src, &weights, &bias, &dst, pad_info); + // configure layer + conv.configure(&src, &weights, &bias, &dst, pad_info); - // allocate tensors - src.allocator()->allocate(); - weights.allocator()->allocate(); - bias.allocator()->allocate(); - dst.allocator()->allocate(); + // allocate tensors + src.allocator()->allocate(); + weights.allocator()->allocate(); + bias.allocator()->allocate(); + dst.allocator()->allocate(); - // To demonstrate how to fill tensor with some values... - src.map(); - Window window; - window.use_tensor_dimensions(src_shape); - Iterator it(&src, window); - execute_window_loop(window, [&](const Coordinates & id) + // To demonstrate how to fill tensor with some values... + src.map(); + Window window; + window.use_tensor_dimensions(src_shape); + Iterator it(&src, window); + execute_window_loop(window, [&](const Coordinates & id) + { + *reinterpret_cast(it.ptr()) = half_float::half(1.f); + }); + src.unmap(); + } + void do_run() override + { + // run the layer + conv.run(); + } + void do_teardown() override { - *reinterpret_cast(it.ptr()) = half_float::half(1.f); - }); - src.unmap(); + // check result + dst.map(); + // do something + dst.unmap(); + } - // run the layer - conv.run(); +private: + GCTensor src{}, weights{}, bias{}, dst{}; + GCDirectConvolutionLayer conv{}; - // check result - dst.map(); - // do something - dst.unmap(); -} + TensorShape get_output_shape(TensorShape in_shape, TensorShape kernel_shape, const PadStrideInfo &info) + { + TensorShape out_shape(in_shape); + const std::pair scaled_dims = scaled_dimensions(in_shape.x(), + in_shape.y(), + kernel_shape.x(), + kernel_shape.y(), + info); + out_shape.set(0, scaled_dims.first); + out_shape.set(1, scaled_dims.second); + out_shape.set(2, kernel_shape[3]); + return out_shape; + } +}; /** Main program for directconvolution test * @@ -119,5 +126,5 @@ void main_gc_dc(int argc, char **argv) */ int main(int argc, char **argv) { - return utils::run_example(argc, argv, main_gc_dc); + return utils::run_example(argc, argv); } -- cgit v1.2.1