aboutsummaryrefslogtreecommitdiff
path: root/examples/gc_dc.cpp
diff options
context:
space:
mode:
authorMichalis Spyrou <michalis.spyrou@arm.com>2018-01-10 14:08:50 +0000
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:43:10 +0000
commit2b5f0f2574551f59970bb9d710bafad2bc4bbd4a (patch)
treefd586f56b1285f0d6c52ecefc174eba0a9c8f157 /examples/gc_dc.cpp
parent571b18a1fca4a5ed4dd24a38cb619f4de43ba3ed (diff)
downloadComputeLibrary-2b5f0f2574551f59970bb9d710bafad2bc4bbd4a.tar.gz
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 <anthony.barbier@arm.com> Tested-by: Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'examples/gc_dc.cpp')
-rw-r--r--examples/gc_dc.cpp141
1 files changed, 74 insertions, 67 deletions
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<unsigned int, unsigned int> 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<half_float::half *>(it.ptr()) = half_float::half(1.f);
+ });
+ src.unmap();
+ }
+ void do_run() override
+ {
+ // run the layer
+ conv.run();
+ }
+ void do_teardown() override
{
- *reinterpret_cast<half_float::half *>(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<unsigned int, unsigned int> 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<GCDCExample>(argc, argv);
}