arm_compute v17.09

Change-Id: I4bf8f4e6e5f84ce0d5b6f5ba570d276879f42a81
diff --git a/src/runtime/CL/functions/CLCannyEdge.cpp b/src/runtime/CL/functions/CLCannyEdge.cpp
index 1d018b8..5acb8e7 100644
--- a/src/runtime/CL/functions/CLCannyEdge.cpp
+++ b/src/runtime/CL/functions/CLCannyEdge.cpp
@@ -26,17 +26,31 @@
 #include "arm_compute/core/CL/ICLTensor.h"
 #include "arm_compute/core/CL/OpenCL.h"
 #include "arm_compute/core/Error.h"
-#include "arm_compute/core/Helpers.h"
 #include "arm_compute/core/Validate.h"
 #include "arm_compute/runtime/CL/CLScheduler.h"
 #include "arm_compute/runtime/CL/functions/CLSobel3x3.h"
 #include "arm_compute/runtime/CL/functions/CLSobel5x5.h"
 #include "arm_compute/runtime/CL/functions/CLSobel7x7.h"
+#include "support/ToolchainSupport.h"
 
 using namespace arm_compute;
 
-CLCannyEdge::CLCannyEdge()
-    : _sobel(nullptr), _gradient(), _border_mag_gradient(), _non_max_suppr(), _edge_trace(), _gx(), _gy(), _mag(), _phase(), _nonmax(), _visited(), _recorded(), _l1_list_counter(), _l1_stack()
+CLCannyEdge::CLCannyEdge(std::shared_ptr<IMemoryManager> memory_manager) // NOLINT
+    : _memory_group(std::move(memory_manager)),
+      _sobel(),
+      _gradient(),
+      _border_mag_gradient(),
+      _non_max_suppr(),
+      _edge_trace(),
+      _gx(),
+      _gy(),
+      _mag(),
+      _phase(),
+      _nonmax(),
+      _visited(),
+      _recorded(),
+      _l1_list_counter(),
+      _l1_stack()
 {
 }
 
@@ -83,22 +97,26 @@
     TensorInfo info_s32(shape_l1_stack, 1, arm_compute::DataType::S32);
     _l1_stack.allocator()->init(info_s32);
 
+    // Manage intermediate buffers
+    _memory_group.manage(&_gx);
+    _memory_group.manage(&_gy);
+
     // Configure/Init sobelNxN
     if(gradient_size == 3)
     {
-        auto k = arm_compute::cpp14::make_unique<CLSobel3x3>();
+        auto k = arm_compute::support::cpp14::make_unique<CLSobel3x3>();
         k->configure(input, &_gx, &_gy, border_mode, constant_border_value);
         _sobel = std::move(k);
     }
     else if(gradient_size == 5)
     {
-        auto k = arm_compute::cpp14::make_unique<CLSobel5x5>();
+        auto k = arm_compute::support::cpp14::make_unique<CLSobel5x5>();
         k->configure(input, &_gx, &_gy, border_mode, constant_border_value);
         _sobel = std::move(k);
     }
     else if(gradient_size == 7)
     {
-        auto k = arm_compute::cpp14::make_unique<CLSobel7x7>();
+        auto k = arm_compute::support::cpp14::make_unique<CLSobel7x7>();
         k->configure(input, &_gx, &_gy, border_mode, constant_border_value);
         _sobel = std::move(k);
     }
@@ -107,23 +125,43 @@
         ARM_COMPUTE_ERROR("Gradient %d size not supported", gradient_size);
     }
 
+    // Manage intermediate buffers
+    _memory_group.manage(&_mag);
+    _memory_group.manage(&_phase);
+
     // Configure gradient
     _gradient.configure(&_gx, &_gy, &_mag, &_phase, norm_type);
 
+    // Allocate intermediate buffers
+    _gx.allocator()->allocate();
+    _gy.allocator()->allocate();
+
+    // Manage intermediate buffers
+    _memory_group.manage(&_nonmax);
+
     // Configure non-maxima suppression
     _non_max_suppr.configure(&_mag, &_phase, &_nonmax, lower_thr, border_mode == BorderMode::UNDEFINED);
 
+    // Allocate intermediate buffers
+    _phase.allocator()->allocate();
+
     // Fill border around magnitude image as non-maxima suppression will access
     // it. If border mode is undefined filling the border is a nop.
     _border_mag_gradient.configure(&_mag, _non_max_suppr.border_size(), border_mode, constant_border_value);
 
+    // Allocate intermediate buffers
+    _mag.allocator()->allocate();
+
+    // Manage intermediate buffers
+    _memory_group.manage(&_visited);
+    _memory_group.manage(&_recorded);
+    _memory_group.manage(&_l1_stack);
+    _memory_group.manage(&_l1_list_counter);
+
     // Configure edge tracing
     _edge_trace.configure(&_nonmax, output, upper_thr, lower_thr, &_visited, &_recorded, &_l1_stack, &_l1_list_counter);
 
-    _gx.allocator()->allocate();
-    _gy.allocator()->allocate();
-    _phase.allocator()->allocate();
-    _mag.allocator()->allocate();
+    // Allocate intermediate buffers
     _visited.allocator()->allocate();
     _recorded.allocator()->allocate();
     _l1_stack.allocator()->allocate();
@@ -133,6 +171,8 @@
 
 void CLCannyEdge::run()
 {
+    _memory_group.acquire();
+
     // Run sobel
     _sobel->run();
 
@@ -152,4 +192,6 @@
     _l1_list_counter.clear(CLScheduler::get().queue());
     _l1_stack.clear(CLScheduler::get().queue());
     CLScheduler::get().enqueue(_edge_trace, true);
+
+    _memory_group.release();
 }