aboutsummaryrefslogtreecommitdiff
path: root/src/gpu/cl/utils/ClAuxTensorHandler.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpu/cl/utils/ClAuxTensorHandler.h')
-rw-r--r--src/gpu/cl/utils/ClAuxTensorHandler.h64
1 files changed, 53 insertions, 11 deletions
diff --git a/src/gpu/cl/utils/ClAuxTensorHandler.h b/src/gpu/cl/utils/ClAuxTensorHandler.h
index 81dc3baef4..12226699f8 100644
--- a/src/gpu/cl/utils/ClAuxTensorHandler.h
+++ b/src/gpu/cl/utils/ClAuxTensorHandler.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Arm Limited.
+ * Copyright (c) 2021, 2024 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -21,8 +21,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-#ifndef ARM_COMPUTE_CL_UTILS_CL_AUX_TENSOR_HANDLER_H
-#define ARM_COMPUTE_CL_UTILS_CL_AUX_TENSOR_HANDLER_H
+#ifndef ACL_SRC_GPU_CL_UTILS_CLAUXTENSORHANDLER_H
+#define ACL_SRC_GPU_CL_UTILS_CLAUXTENSORHANDLER_H
#include "arm_compute/core/ITensorPack.h"
#include "arm_compute/core/TensorInfo.h"
@@ -35,12 +35,39 @@ namespace arm_compute
{
namespace opencl
{
-/* Tensor handler to wrap and handle tensor allocations on workspace buffers */
+/** Tensor handler to wrap and handle tensor allocations on workspace buffers
+ *
+ * @note About memory handling using bypass_* flags
+ * See @ref arm_compute::cpu::CpuAuxTensorHandler
+ */
class CLAuxTensorHandler
{
public:
- CLAuxTensorHandler(
- int slot_id, TensorInfo &info, ITensorPack &pack, bool pack_inject = false, bool bypass_alloc = false)
+ /** Create a temporary tensor handle, by either important an existing tensor from a tensor pack, or allocating a
+ * new one.
+ *
+ * @param[in] slot_id Slot id of the tensor to be retrieved in the tensor pack
+ * If no such tensor exists in the tensor pack, a new tensor will be allocated.
+ * @param[in] info Tensor info containing requested size of the new tensor.
+ * If requested size is larger than the tensor retrieved from the tensor pack,
+ * a new tensor will be allocated.
+ * @param[in,out] pack Tensor pack to retrieve the old tensor. When @p pack_inject is true, the new
+ * tensor will also be added here.
+ * @param[in] pack_inject In case of a newly allocated tensor, whether to add this tensor back to the
+ * @p pack
+ * @param[in] bypass_alloc Bypass allocation in case of a new tensor
+ * This is to prevent unnecessary memory operations when the handler object is not
+ * used
+ * @param[in] bypass_import Bypass importation in case of a retrieved tensor
+ * This is to prevent unnecessary memory operations when the handler object is not
+ * used
+ */
+ CLAuxTensorHandler(int slot_id,
+ TensorInfo &info,
+ ITensorPack &pack,
+ bool pack_inject = false,
+ bool bypass_alloc = false,
+ bool bypass_import = false)
: _tensor()
{
if (info.total_size() == 0)
@@ -67,16 +94,31 @@ public:
}
else
{
- _tensor.allocator()->import_memory(packed_tensor->cl_buffer());
+ if (!bypass_import)
+ {
+ _tensor.allocator()->import_memory(packed_tensor->cl_buffer());
+ }
}
}
- CLAuxTensorHandler(TensorInfo &info, ICLTensor &tensor) : _tensor()
+ /** Create a temporary handle to the original tensor with a new @ref TensorInfo
+ * This is useful if we want to change a tensor's tensor info at run time without modifying the original tensor
+ *
+ * @param[in] info New tensor info to "assign" to @p tensor
+ * @param[in] tensor Tensor to be assigned a new @ref TensorInfo
+ * @param[in] bypass_import Bypass importing @p tensor's memory into the handler.
+ * This is to prevent unnecessary memory operations when the handler object is not used
+ */
+ CLAuxTensorHandler(TensorInfo &info, ICLTensor &tensor, bool bypass_import = false) : _tensor()
{
_tensor.allocator()->soft_init(info);
- if (info.total_size() <= tensor.info()->total_size())
+ if (!bypass_import)
{
- _tensor.allocator()->import_memory(tensor.cl_buffer());
+ ARM_COMPUTE_ERROR_ON(tensor.info() == nullptr);
+ if (info.total_size() <= tensor.info()->total_size())
+ {
+ _tensor.allocator()->import_memory(tensor.cl_buffer());
+ }
}
}
@@ -108,4 +150,4 @@ private:
};
} // namespace opencl
} // namespace arm_compute
-#endif /* ARM_COMPUTE_CL_UTILS_CL_AUX_TENSOR_HANDLER_H */
+#endif // ACL_SRC_GPU_CL_UTILS_CLAUXTENSORHANDLER_H