From 4d0351cf322df51baa5a445f637008992aa37809 Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Wed, 3 Apr 2019 15:11:16 +0100 Subject: COMPMID-2057: Implement and test import memory interfaces. Change-Id: I1559bea47ae6403177d248e2f7be47d5f1a6513f Signed-off-by: Georgios Pinitas Reviewed-on: https://review.mlplatform.org/c/956 Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins Reviewed-by: Michalis Spyrou --- src/core/CL/OpenCL.cpp | 29 ++++++++++++++++++++++++++++- src/runtime/CL/CLTensorAllocator.cpp | 6 +++--- src/runtime/TensorAllocator.cpp | 6 +++--- 3 files changed, 34 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/core/CL/OpenCL.cpp b/src/core/CL/OpenCL.cpp index 6725f36a5d..ef03a5a302 100644 --- a/src/core/CL/OpenCL.cpp +++ b/src/core/CL/OpenCL.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 ARM Limited. + * Copyright (c) 2017-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -120,6 +120,9 @@ bool CLSymbols::load(const std::string &library) LOAD_FUNCTION_PTR(clEnqueueMarker, handle); LOAD_FUNCTION_PTR(clWaitForEvents, handle); + // Third-party extensions + LOAD_FUNCTION_PTR(clImportMemoryARM, handle); + #undef LOAD_FUNCTION_PTR //Don't call dlclose(handle) or all the symbols will be unloaded ! @@ -919,3 +922,27 @@ clGetEventProfilingInfo(cl_event event, return CL_OUT_OF_RESOURCES; } } + +cl_mem +clImportMemoryARM(cl_context context, + cl_mem_flags flags, + const cl_import_properties_arm *properties, + void *memory, + size_t size, + cl_int *errcode_ret) +{ + arm_compute::CLSymbols::get().load_default(); + auto func = arm_compute::CLSymbols::get().clImportMemoryARM_ptr; + if(func != nullptr) + { + return func(context, flags, properties, memory, size, errcode_ret); + } + else + { + if(errcode_ret != nullptr) + { + *errcode_ret = CL_OUT_OF_RESOURCES; + } + return nullptr; + } +} \ No newline at end of file diff --git a/src/runtime/CL/CLTensorAllocator.cpp b/src/runtime/CL/CLTensorAllocator.cpp index 0307498335..2ce64551ae 100644 --- a/src/runtime/CL/CLTensorAllocator.cpp +++ b/src/runtime/CL/CLTensorAllocator.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2018 ARM Limited. + * Copyright (c) 2016-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -101,10 +101,10 @@ void CLTensorAllocator::free() info().set_is_resizable(true); } -arm_compute::Status CLTensorAllocator::import_memory(cl::Buffer buffer) +Status CLTensorAllocator::import_memory(cl::Buffer buffer) { ARM_COMPUTE_RETURN_ERROR_ON(buffer.get() == nullptr); - ARM_COMPUTE_RETURN_ERROR_ON(buffer.getInfo() == 0); + ARM_COMPUTE_RETURN_ERROR_ON(buffer.getInfo() < info().total_size()); ARM_COMPUTE_RETURN_ERROR_ON(buffer.getInfo().get() != CLScheduler::get().context().get()); ARM_COMPUTE_RETURN_ERROR_ON(_associated_memory_group != nullptr); diff --git a/src/runtime/TensorAllocator.cpp b/src/runtime/TensorAllocator.cpp index 38edb8ba03..0612d751f0 100644 --- a/src/runtime/TensorAllocator.cpp +++ b/src/runtime/TensorAllocator.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2018 ARM Limited. + * Copyright (c) 2016-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -149,11 +149,11 @@ void TensorAllocator::free() info().set_is_resizable(true); } -arm_compute::Status TensorAllocator::import_memory(void *memory, size_t size) +Status TensorAllocator::import_memory(void *memory) { ARM_COMPUTE_RETURN_ERROR_ON(memory == nullptr); - ARM_COMPUTE_RETURN_ERROR_ON(size == 0); ARM_COMPUTE_RETURN_ERROR_ON(_associated_memory_group != nullptr); + ARM_COMPUTE_RETURN_ERROR_ON(alignment() != 0 && !arm_compute::utility::check_aligned(memory, alignment())); _memory.set_owned_region(support::cpp14::make_unique(memory, info().total_size())); info().set_is_resizable(false); -- cgit v1.2.1