From 1c5ffd612979d40730feecc4f43fa6c9f177f2e3 Mon Sep 17 00:00:00 2001 From: Joel Liang Date: Thu, 28 Dec 2017 10:09:51 +0800 Subject: APPBROWSER-359: Sync tensor in GC benchmark tests Change-Id: I22c1aa92e70d6143bbcec90e9e7de9f1ce1c1e55 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/114635 Tested-by: Jenkins Reviewed-by: Pablo Tello --- tests/Utils.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'tests/Utils.h') diff --git a/tests/Utils.h b/tests/Utils.h index df1d7a543a..bee30af2e8 100644 --- a/tests/Utils.h +++ b/tests/Utils.h @@ -32,6 +32,16 @@ #include "arm_compute/core/Types.h" #include "support/ToolchainSupport.h" +#ifdef ARM_COMPUTE_CL +#include "arm_compute/core/CL/OpenCL.h" +#include "arm_compute/runtime/CL/CLScheduler.h" +#endif /* ARM_COMPUTE_CL */ + +#ifdef ARM_COMPUTE_GC +#include "arm_compute/core/GLES_COMPUTE/OpenGLES.h" +#include "arm_compute/runtime/GLES_COMPUTE/GCTensor.h" +#endif /* ARM_COMPUTE_GC */ + #include #include #include @@ -44,6 +54,9 @@ namespace arm_compute { +#ifdef ARM_COMPUTE_CL +class CLTensor; +#endif /* ARM_COMPUTE_CL */ namespace test { /** Round floating-point value with half value rounding to positive infinity. @@ -566,6 +579,39 @@ inline std::string get_typestring(DataType data_type) ARM_COMPUTE_ERROR("NOT SUPPORTED!"); } } + +/** Sync if necessary. + */ +template +inline void sync_if_necessary() +{ +#ifdef ARM_COMPUTE_CL + if(opencl_is_available() && std::is_same::type, arm_compute::CLTensor>::value) + { + CLScheduler::get().sync(); + } +#endif /* ARM_COMPUTE_CL */ +} + +/** Sync tensor if necessary. + * + * @note: If the destination tensor not being used on OpenGL ES, GPU will optimize out the operation. + * + * @param[in] tensor Tensor to be sync. + */ +template +inline void sync_tensor_if_necessary(TensorType &tensor) +{ +#ifdef ARM_COMPUTE_GC + if(opengles31_is_available() && std::is_same::type, arm_compute::GCTensor>::value) + { + // Force sync the tensor by calling map and unmap. + IGCTensor &t = dynamic_cast(tensor); + t.map(); + t.unmap(); + } +#endif /* ARM_COMPUTE_GC */ +} } // namespace test } // namespace arm_compute #endif /* __ARM_COMPUTE_TEST_UTILS_H__ */ -- cgit v1.2.1