2 * Copyright (c) 2016, 2017 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 #define ARM_COMPUTE_CL /* So that OpenCL exceptions get caught too */
25 #include "arm_compute/core/Types.h"
26 #include "arm_compute/runtime/CL/CLFunctions.h"
27 #include "arm_compute/runtime/CL/CLScheduler.h"
28 #include "test_helpers/Utils.h"
30 using namespace arm_compute;
31 using namespace test_helpers;
33 /** Gaussian 3x3 matrix
35 const int16_t gaussian3x3[] =
42 /** Gaussian 5x5 matrix
44 const int16_t gaussian5x5[] =
53 void main_cl_convolution(int argc, const char **argv)
56 CLImage src, tmp, dst;
58 CLScheduler::get().default_init();
63 std::cout << "Usage: ./build/cl_convolution [input_image.ppm]\n\n";
64 std::cout << "No input_image provided, creating a dummy 640x480 image\n";
65 // Create an empty grayscale 640x480 image
66 src.allocator()->init(TensorInfo(640, 480, Format::U8));
71 ppm.init_image(src, Format::U8);
74 // Configure the temporary and destination images
75 tmp.allocator()->init(*src.info());
76 dst.allocator()->init(*src.info());
78 CLConvolution3x3 conv3x3;
79 CLConvolution5x5 conv5x5;
81 // Apply a Gaussian 3x3 filter to the source image followed by a Gaussian 5x5:
82 conv3x3.configure(&src, &tmp, gaussian3x3, 0 /* Let arm_compute calculate the scale */, BorderMode::UNDEFINED);
83 conv5x5.configure(&tmp, &dst, gaussian5x5, 0 /* Let arm_compute calculate the scale */, BorderMode::UNDEFINED);
85 // Allocate all the images
86 src.allocator()->allocate();
87 tmp.allocator()->allocate();
88 dst.allocator()->allocate();
89 // Fill the input image with the content of the PPM image if a filename was provided:
95 // Execute the functions:
99 // Make sure all the OpenCL jobs are done executing:
100 CLScheduler::get().sync();
102 // Save the result to file:
105 const std::string output_filename = std::string(argv[1]) + "_out.ppm";
106 save_to_ppm(dst, output_filename); // save_to_ppm maps and unmaps the image to store as PPM
110 /** Main program for convolution test
112 * @param[in] argc Number of arguments
113 * @param[in] argv Arguments ( [optional] Path to PPM image to process )
115 int main(int argc, const char **argv)
117 return test_helpers::run_example(argc, argv, main_cl_convolution);