aboutsummaryrefslogtreecommitdiff
path: root/tests/Utils.h
diff options
context:
space:
mode:
authorJoel Liang <joel.liang@arm.com>2017-12-28 10:09:51 +0800
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:42:33 +0000
commit1c5ffd612979d40730feecc4f43fa6c9f177f2e3 (patch)
tree510367ba70fcad4374d2cf9cdccdb3bc715c216c /tests/Utils.h
parentc5a7e59655b61ad617fa34a4fb00e1a007c8255a (diff)
downloadComputeLibrary-1c5ffd612979d40730feecc4f43fa6c9f177f2e3.tar.gz
APPBROWSER-359: Sync tensor in GC benchmark tests
Change-Id: I22c1aa92e70d6143bbcec90e9e7de9f1ce1c1e55 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/114635 Tested-by: Jenkins <bsgcomp@arm.com> Reviewed-by: Pablo Tello <pablo.tello@arm.com>
Diffstat (limited to 'tests/Utils.h')
-rw-r--r--tests/Utils.h46
1 files changed, 46 insertions, 0 deletions
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 <cmath>
#include <cstddef>
#include <limits>
@@ -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 <typename TensorType>
+inline void sync_if_necessary()
+{
+#ifdef ARM_COMPUTE_CL
+ if(opencl_is_available() && std::is_same<typename std::decay<TensorType>::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 <typename TensorType>
+inline void sync_tensor_if_necessary(TensorType &tensor)
+{
+#ifdef ARM_COMPUTE_GC
+ if(opengles31_is_available() && std::is_same<typename std::decay<TensorType>::type, arm_compute::GCTensor>::value)
+ {
+ // Force sync the tensor by calling map and unmap.
+ IGCTensor &t = dynamic_cast<IGCTensor &>(tensor);
+ t.map();
+ t.unmap();
+ }
+#endif /* ARM_COMPUTE_GC */
+}
} // namespace test
} // namespace arm_compute
#endif /* __ARM_COMPUTE_TEST_UTILS_H__ */