COMPMID-1088: Use IMemoryRegion in interfaces where possible

-Simplifies import memory interface
-Changes the used of void** handles with appropriate interfaces.

Change-Id: I5918c855c11f46352058864623336b352162a4b7
diff --git a/arm_compute/runtime/CL/CLMemory.h b/arm_compute/runtime/CL/CLMemory.h
index edd9de8..02d3661 100644
--- a/arm_compute/runtime/CL/CLMemory.h
+++ b/arm_compute/runtime/CL/CLMemory.h
@@ -24,6 +24,8 @@
 #ifndef __ARM_COMPUTE_RUNTIME_CL_CLMEMORY_H__
 #define __ARM_COMPUTE_RUNTIME_CL_CLMEMORY_H__
 
+#include "arm_compute/runtime/IMemory.h"
+
 #include "arm_compute/core/CL/OpenCL.h"
 #include "arm_compute/runtime/CL/CLMemoryRegion.h"
 
@@ -33,7 +35,7 @@
 namespace arm_compute
 {
 /** OpenCL implementation of memory object */
-class CLMemory
+class CLMemory : public IMemory
 {
 public:
     /** Default Constructor */
@@ -59,20 +61,22 @@
     CLMemory(CLMemory &&) noexcept = default;
     /** Allow instances of this class to be move assigned */
     CLMemory &operator=(CLMemory &&) noexcept = default;
-    /** Region accessor
+    /** OpenCL Region accessor
      *
      * @return Memory region
      */
-    ICLMemoryRegion *region();
-    /** Region accessor
+    ICLMemoryRegion *cl_region();
+    /** OpenCL Region accessor
      *
      * @return Memory region
      */
-    ICLMemoryRegion *region() const;
+    ICLMemoryRegion *cl_region() const;
 
-private:
-    /** Creates empty region */
-    void create_empty_region();
+    // Inherited methods overridden:
+    IMemoryRegion *region() final;
+    IMemoryRegion *region() const final;
+    void set_region(IMemoryRegion *region) final;
+    void set_owned_region(std::unique_ptr<IMemoryRegion> region) final;
 
 private:
     ICLMemoryRegion                 *_region;
diff --git a/arm_compute/runtime/CL/CLMemoryRegion.h b/arm_compute/runtime/CL/CLMemoryRegion.h
index 01dd54e..dbfd822 100644
--- a/arm_compute/runtime/CL/CLMemoryRegion.h
+++ b/arm_compute/runtime/CL/CLMemoryRegion.h
@@ -81,9 +81,9 @@
     virtual void unmap(cl::CommandQueue &q) = 0;
 
     // Inherited methods overridden :
-    void *buffer() override;
-    void *buffer() const override;
-    void **handle() override;
+    void                          *buffer() override;
+    void                          *buffer() const override;
+    std::unique_ptr<IMemoryRegion> extract_subregion(size_t offset, size_t size) override;
 
 protected:
     cl::Context _ctx;
@@ -102,11 +102,16 @@
      * @param[in] size  Region size
      */
     CLBufferMemoryRegion(cl::Context ctx, cl_mem_flags flags, size_t size);
+    /** Constructor
+     *
+     * @param[in] buffer Buffer to be used as a memory region
+     */
+    CLBufferMemoryRegion(const cl::Buffer &buffer);
 
     // Inherited methods overridden :
-    void *ptr() override;
-    void *map(cl::CommandQueue &q, bool blocking) override;
-    void unmap(cl::CommandQueue &q) override;
+    void *ptr() final;
+    void *map(cl::CommandQueue &q, bool blocking) final;
+    void unmap(cl::CommandQueue &q) final;
 };
 
 /** OpenCL SVM memory region interface */
@@ -153,8 +158,8 @@
     CLCoarseSVMMemoryRegion(cl::Context ctx, cl_mem_flags flags, size_t size, size_t alignment);
 
     // Inherited methods overridden :
-    void *map(cl::CommandQueue &q, bool blocking) override;
-    void unmap(cl::CommandQueue &q) override;
+    void *map(cl::CommandQueue &q, bool blocking) final;
+    void unmap(cl::CommandQueue &q) final;
 };
 
 /** OpenCL fine-grain SVM memory region implementation */
@@ -171,8 +176,8 @@
     CLFineSVMMemoryRegion(cl::Context ctx, cl_mem_flags flags, size_t size, size_t alignment);
 
     // Inherited methods overridden :
-    void *map(cl::CommandQueue &q, bool blocking) override;
-    void unmap(cl::CommandQueue &q) override;
+    void *map(cl::CommandQueue &q, bool blocking) final;
+    void unmap(cl::CommandQueue &q) final;
 };
 } // namespace arm_compute
 #endif /* __ARM_COMPUTE_RUNTIME_CL_CL_MEMORY_REGION_H__ */
diff --git a/arm_compute/runtime/CL/CLTensorAllocator.h b/arm_compute/runtime/CL/CLTensorAllocator.h
index a372195..de5f482 100644
--- a/arm_compute/runtime/CL/CLTensorAllocator.h
+++ b/arm_compute/runtime/CL/CLTensorAllocator.h
@@ -103,17 +103,13 @@
     void free() override;
     /** Import an existing memory as a tensor's backing memory
      *
-     * @warning If the tensor is flagged to be managed by a memory manager,
-     *          this call will lead to an error.
-     * @warning Ownership of memory depends on the way the @ref CLMemory object was constructed
-     * @note    Calling free on a tensor with imported memory will just clear
-     *          the internal pointer value.
+     * @warning ownership of memory is not transferred
      *
-     * @param[in] memory Memory to import
+     * @param[in] buffer Buffer to import
      *
      * @return error status
      */
-    arm_compute::Status import_memory(CLMemory memory);
+    arm_compute::Status import_memory(cl::Buffer buffer);
     /** Associates the tensor with a memory group
      *
      * @param[in] associated_memory_group Memory group to associate the tensor with
@@ -130,8 +126,12 @@
     void unlock() override;
 
 private:
+    static const cl::Buffer _empty_buffer;
+
+private:
     CLMemoryGroup *_associated_memory_group; /**< Registered memory manager */
     CLMemory       _memory;                  /**< OpenCL memory */
+    uint8_t       *_mapping;                 /**< Pointer to the CPU mapping of the OpenCL buffer. */
     CLTensor      *_owner;                   /**< Owner of the allocator */
 };
 } // namespace arm_compute