diff options
author | Georgios Pinitas <georgios.pinitas@arm.com> | 2018-11-14 13:16:56 +0000 |
---|---|---|
committer | Isabella Gottardi <isabella.gottardi@arm.com> | 2018-11-21 09:52:04 +0000 |
commit | df3103622b7de05f4e35b22a2c94b4a46eab4efc (patch) | |
tree | 17e10253e7a069c69d10bea0882b699b99d74b86 /arm_compute/runtime/CL | |
parent | c47ef20d69e8ea0f519fdc679435cd7037fc18fe (diff) | |
download | ComputeLibrary-df3103622b7de05f4e35b22a2c94b4a46eab4efc.tar.gz |
COMPMID-1088: Use IMemoryRegion in interfaces where possible
-Simplifies import memory interface
-Changes the used of void** handles with appropriate interfaces.
Change-Id: I5918c855c11f46352058864623336b352162a4b7
Diffstat (limited to 'arm_compute/runtime/CL')
-rw-r--r-- | arm_compute/runtime/CL/CLMemory.h | 20 | ||||
-rw-r--r-- | arm_compute/runtime/CL/CLMemoryRegion.h | 25 | ||||
-rw-r--r-- | arm_compute/runtime/CL/CLTensorAllocator.h | 14 |
3 files changed, 34 insertions, 25 deletions
diff --git a/arm_compute/runtime/CL/CLMemory.h b/arm_compute/runtime/CL/CLMemory.h index edd9de8097..02d36614ae 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 @@ public: 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 01dd54e391..dbfd8225ca 100644 --- a/arm_compute/runtime/CL/CLMemoryRegion.h +++ b/arm_compute/runtime/CL/CLMemoryRegion.h @@ -81,9 +81,9 @@ public: 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 @@ public: * @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 @@ public: 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 @@ public: 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 a372195555..de5f482d05 100644 --- a/arm_compute/runtime/CL/CLTensorAllocator.h +++ b/arm_compute/runtime/CL/CLTensorAllocator.h @@ -103,17 +103,13 @@ public: 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 @@ protected: 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 |