aboutsummaryrefslogtreecommitdiff
path: root/examples/neoncl_scale_median_gaussian.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/neoncl_scale_median_gaussian.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/neoncl_scale_median_gaussian.cpp')
-rw-r--r--examples/neoncl_scale_median_gaussian.cpp145
1 files changed, 77 insertions, 68 deletions
diff --git a/examples/neoncl_scale_median_gaussian.cpp b/examples/neoncl_scale_median_gaussian.cpp
index 0b72314f7b..084005fd1b 100644
--- a/examples/neoncl_scale_median_gaussian.cpp
+++ b/examples/neoncl_scale_median_gaussian.cpp
@@ -39,91 +39,100 @@ using namespace utils;
* @param[in] argc Number of arguments
* @param[in] argv Arguments ( [optional] Path to PPM image to process )
*/
-void main_neoncl_scale_median_gaussian(int argc, char **argv)
+class NEONCLScaleMedianGaussianExample : public Example
{
- /** [NEON / OpenCL Interop] */
- PPMLoader ppm;
- CLImage src, scale_median, median_gauss, dst;
-
- CLScheduler::get().default_init();
-
- if(argc < 2)
+public:
+ void do_setup(int argc, char **argv) override
{
- // Print help
- std::cout << "Usage: ./build/cl_convolution [input_image.ppm]\n\n";
- std::cout << "No input_image provided, creating a dummy 640x480 image\n";
- // Create an empty grayscale 640x480 image
- src.allocator()->init(TensorInfo(640, 480, Format::U8));
+ /** [NEON / OpenCL Interop] */
+ PPMLoader ppm;
+
+ CLScheduler::get().default_init();
+
+ if(argc < 2)
+ {
+ // Print help
+ std::cout << "Usage: ./build/cl_convolution [input_image.ppm]\n\n";
+ std::cout << "No input_image provided, creating a dummy 640x480 image\n";
+ // Create an empty grayscale 640x480 image
+ src.allocator()->init(TensorInfo(640, 480, Format::U8));
+ }
+ else
+ {
+ ppm.open(argv[1]);
+ ppm.init_image(src, Format::U8);
+ }
+
+ TensorInfo scale_median_info(TensorInfo(src.info()->dimension(0) / 2, src.info()->dimension(1) / 2, Format::U8));
+
+ // Configure the temporary and destination images
+ scale_median.allocator()->init(scale_median_info);
+ median_gauss.allocator()->init(scale_median_info);
+ dst.allocator()->init(scale_median_info);
+
+ scale.configure(&src, &scale_median, InterpolationPolicy::NEAREST_NEIGHBOR, BorderMode::REPLICATE);
+ median.configure(&scale_median, &median_gauss, BorderMode::REPLICATE);
+ gauss.configure(&median_gauss, &dst, BorderMode::REPLICATE);
+
+ // Allocate all the images
+ src.allocator()->allocate();
+ scale_median.allocator()->allocate();
+ median_gauss.allocator()->allocate();
+ dst.allocator()->allocate();
+
+ // Fill the input image with the content of the PPM image if a filename was provided:
+ if(ppm.is_open())
+ {
+ ppm.fill_image(src);
+ const std::string output_filename = std::string(argv[1]) + "_out.ppm";
+ }
+ /** [NEON / OpenCL Interop] */
}
- else
+ void do_run() override
{
- ppm.open(argv[1]);
- ppm.init_image(src, Format::U8);
- }
-
- TensorInfo scale_median_info(TensorInfo(src.info()->dimension(0) / 2, src.info()->dimension(1) / 2, Format::U8));
+ // Enqueue and flush the OpenCL kernel:
+ scale.run();
- // Configure the temporary and destination images
- scale_median.allocator()->init(scale_median_info);
- median_gauss.allocator()->init(scale_median_info);
- dst.allocator()->init(scale_median_info);
+ // Do a blocking map of the input and output buffers of the NEON function:
+ scale_median.map();
+ median_gauss.map();
- // Declare and configure the functions to create the following pipeline: scale -> median -> gauss
- CLScale scale;
- NEMedian3x3 median;
- CLGaussian5x5 gauss;
+ // Run the NEON function:
+ median.run();
- scale.configure(&src, &scale_median, InterpolationPolicy::NEAREST_NEIGHBOR, BorderMode::REPLICATE);
- median.configure(&scale_median, &median_gauss, BorderMode::REPLICATE);
- gauss.configure(&median_gauss, &dst, BorderMode::REPLICATE);
+ // Unmap the output buffer before it's used again by OpenCL:
+ scale_median.unmap();
+ median_gauss.unmap();
- // Allocate all the images
- src.allocator()->allocate();
- scale_median.allocator()->allocate();
- median_gauss.allocator()->allocate();
- dst.allocator()->allocate();
+ // Run the final OpenCL function:
+ gauss.run();
- // Fill the input image with the content of the PPM image if a filename was provided:
- if(ppm.is_open())
- {
- ppm.fill_image(src);
+ // Make sure all the OpenCL jobs are done executing:
+ CLScheduler::get().sync();
}
-
- // Enqueue and flush the OpenCL kernel:
- scale.run();
-
- // Do a blocking map of the input and output buffers of the NEON function:
- scale_median.map();
- median_gauss.map();
-
- // Run the NEON function:
- median.run();
-
- // Unmap the output buffer before it's used again by OpenCL:
- scale_median.unmap();
- median_gauss.unmap();
-
- // Run the final OpenCL function:
- gauss.run();
-
- // Make sure all the OpenCL jobs are done executing:
- CLScheduler::get().sync();
-
- // Save the result to file:
- if(ppm.is_open())
+ void do_teardown() override
{
- const std::string output_filename = std::string(argv[1]) + "_out.ppm";
- save_to_ppm(dst, output_filename); // save_to_ppm maps and unmaps the image to store as PPM
+ // Save the result to file:
+ if(!output_filename.empty())
+ {
+ save_to_ppm(dst, output_filename); // save_to_ppm maps and unmaps the image to store as PPM
+ }
}
- /** [NEON / OpenCL Interop] */
-}
-/** Main program for convolution test
+private:
+ CLImage src{}, scale_median{}, median_gauss{}, dst{};
+ CLScale scale{};
+ NEMedian3x3 median{};
+ CLGaussian5x5 gauss{};
+ std::string output_filename{};
+};
+
+/** Main program for neon/cl scale median gaussian test
*
* @param[in] argc Number of arguments
* @param[in] argv Arguments ( [optional] Path to PPM image to process )
*/
int main(int argc, char **argv)
{
- return utils::run_example(argc, argv, main_neoncl_scale_median_gaussian);
+ return utils::run_example<NEONCLScaleMedianGaussianExample>(argc, argv);
}