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>
diff --git a/arm_compute/core/GLES_COMPUTE/GCHelpers.h b/arm_compute/core/GLES_COMPUTE/GCHelpers.h
index 475554f..8fbb5bb 100644
--- a/arm_compute/core/GLES_COMPUTE/GCHelpers.h
+++ b/arm_compute/core/GLES_COMPUTE/GCHelpers.h
@@ -32,6 +32,8 @@
 
 namespace arm_compute
 {
+namespace gles_compute
+{
 /** Helper function to create and return a unique_ptr pointed to a GLES kernel object
  *  It also calls the kernel's configuration.
  *
@@ -60,5 +62,6 @@
 
 /** Max vector width of an GLES vector */
 static constexpr unsigned int max_gc_vector_width = 16;
-}
+} // namespace gles_compute
+} // namespace arm_compute
 #endif /* __ARM_COMPUTE_GCHELPERS_H__ */
diff --git a/src/core/GLES_COMPUTE/kernels/GCGEMMInterleave4x4Kernel.cpp b/src/core/GLES_COMPUTE/kernels/GCGEMMInterleave4x4Kernel.cpp
index 4bc6731..ef47e7f 100644
--- a/src/core/GLES_COMPUTE/kernels/GCGEMMInterleave4x4Kernel.cpp
+++ b/src/core/GLES_COMPUTE/kernels/GCGEMMInterleave4x4Kernel.cpp
@@ -35,6 +35,7 @@
 #include "arm_compute/core/Window.h"
 
 using namespace arm_compute;
+using namespace arm_compute::gles_compute;
 
 GCGEMMInterleave4x4Kernel::GCGEMMInterleave4x4Kernel()
     : _input(nullptr), _output(nullptr)
diff --git a/src/core/GLES_COMPUTE/kernels/GCGEMMMatrixAdditionKernel.cpp b/src/core/GLES_COMPUTE/kernels/GCGEMMMatrixAdditionKernel.cpp
index cf5d378..43846dc 100644
--- a/src/core/GLES_COMPUTE/kernels/GCGEMMMatrixAdditionKernel.cpp
+++ b/src/core/GLES_COMPUTE/kernels/GCGEMMMatrixAdditionKernel.cpp
@@ -34,6 +34,7 @@
 #include "arm_compute/core/Window.h"
 
 using namespace arm_compute;
+using namespace arm_compute::gles_compute;
 
 GCGEMMMatrixAdditionKernel::GCGEMMMatrixAdditionKernel()
     : _input(nullptr), _output(nullptr)
diff --git a/src/core/GLES_COMPUTE/kernels/GCGEMMMatrixMultiplyKernel.cpp b/src/core/GLES_COMPUTE/kernels/GCGEMMMatrixMultiplyKernel.cpp
index 8179525..baf1a9b 100644
--- a/src/core/GLES_COMPUTE/kernels/GCGEMMMatrixMultiplyKernel.cpp
+++ b/src/core/GLES_COMPUTE/kernels/GCGEMMMatrixMultiplyKernel.cpp
@@ -40,6 +40,7 @@
 #include <string>
 
 using namespace arm_compute;
+using namespace arm_compute::gles_compute;
 
 GCGEMMMatrixMultiplyKernel::GCGEMMMatrixMultiplyKernel()
     : _input0(nullptr), _input1(nullptr), _output(nullptr)
diff --git a/src/runtime/GLES_COMPUTE/functions/GCGEMM.cpp b/src/runtime/GLES_COMPUTE/functions/GCGEMM.cpp
index c47a0e7..1c34c03 100644
--- a/src/runtime/GLES_COMPUTE/functions/GCGEMM.cpp
+++ b/src/runtime/GLES_COMPUTE/functions/GCGEMM.cpp
@@ -38,6 +38,7 @@
 #include "arm_compute/runtime/ITensorAllocator.h"
 
 using namespace arm_compute;
+using namespace arm_compute::gles_compute;
 
 GCGEMM::GCGEMM()
     : _interleave_kernel(), _transpose_kernel(), _mm_kernel(), _ma_kernel(), _tmp_a(), _tmp_b(), _is_interleaved_transposed(false), _run_addition(false)
diff --git a/tests/GLES_COMPUTE/Helper.h b/tests/GLES_COMPUTE/Helper.h
index 5f6460a..c2cd7c0 100644
--- a/tests/GLES_COMPUTE/Helper.h
+++ b/tests/GLES_COMPUTE/Helper.h
@@ -91,23 +91,6 @@
     std::cout << name << ":" << std::endl;
     std::cout << s.str().c_str();
     t.unmap();
-
-    return;
-}
-
-/** Helper to sync tensor, if tensor is not used, GPU have optimized the operation.
- *
- * @param[in] tensor Tensor to be sync.
- *
- * @return Empty @ref GCTensor with the specified shape and data type.
- */
-inline void force_sync_tensor(ITensor &tensor)
-{
-    IGCTensor &t = dynamic_cast<IGCTensor &>(tensor);
-    t.map();
-    t.unmap();
-
-    return;
 }
 } // namespace gles_compute
 } // namespace test
diff --git a/tests/Utils.h b/tests/Utils.h
index df1d7a5..bee30af 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 @@
             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__ */
diff --git a/tests/benchmark/fixtures/ActivationLayerFixture.h b/tests/benchmark/fixtures/ActivationLayerFixture.h
index 9ded063..11fabf8 100644
--- a/tests/benchmark/fixtures/ActivationLayerFixture.h
+++ b/tests/benchmark/fixtures/ActivationLayerFixture.h
@@ -66,6 +66,12 @@
         act_layer.run();
     }
 
+    void sync()
+    {
+        sync_if_necessary<TensorType>();
+        sync_tensor_if_necessary<TensorType>(dst);
+    }
+
     void teardown()
     {
         src.allocator()->free();
diff --git a/tests/benchmark/fixtures/AlexNetFixture.h b/tests/benchmark/fixtures/AlexNetFixture.h
index 961f4e8..a543ba2 100644
--- a/tests/benchmark/fixtures/AlexNetFixture.h
+++ b/tests/benchmark/fixtures/AlexNetFixture.h
@@ -65,6 +65,11 @@
         network.run();
     }
 
+    void sync()
+    {
+        network.sync();
+    }
+
     void teardown()
     {
         network.clear();
diff --git a/tests/benchmark/fixtures/BatchNormalizationLayerFixture.h b/tests/benchmark/fixtures/BatchNormalizationLayerFixture.h
index 55411a4..5f32e77 100644
--- a/tests/benchmark/fixtures/BatchNormalizationLayerFixture.h
+++ b/tests/benchmark/fixtures/BatchNormalizationLayerFixture.h
@@ -29,12 +29,6 @@
 #include "tests/Globals.h"
 #include "tests/Utils.h"
 #include "tests/framework/Fixture.h"
-#ifdef ARM_COMPUTE_GC
-#include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h"
-#include "tests/GLES_COMPUTE/Helper.h"
-
-using namespace arm_compute::test::gles_compute;
-#endif /* ARM_COMPUTE_GC */
 
 namespace arm_compute
 {
@@ -82,12 +76,12 @@
     void run()
     {
         batch_norm_layer.run();
-#ifdef ARM_COMPUTE_GC
-        if(opengles31_is_available() && std::is_same<typename std::decay<TensorType>::type, arm_compute::GCTensor>::value)
-        {
-            force_sync_tensor(dst);
-        }
-#endif /* ARM_COMPUTE_GC */
+    }
+
+    void sync()
+    {
+        sync_if_necessary<TensorType>();
+        sync_tensor_if_necessary<TensorType>(dst);
     }
 
     void teardown()
diff --git a/tests/benchmark/fixtures/ConvolutionLayerFixture.h b/tests/benchmark/fixtures/ConvolutionLayerFixture.h
index b526cc3..4031607 100644
--- a/tests/benchmark/fixtures/ConvolutionLayerFixture.h
+++ b/tests/benchmark/fixtures/ConvolutionLayerFixture.h
@@ -30,13 +30,6 @@
 #include "tests/Utils.h"
 #include "tests/framework/Fixture.h"
 
-#ifdef ARM_COMPUTE_GC
-#include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h"
-#include "tests/GLES_COMPUTE/Helper.h"
-
-using namespace arm_compute::test::gles_compute;
-#endif /* ARM_COMPUTE_GC */
-
 namespace arm_compute
 {
 namespace test
@@ -78,12 +71,12 @@
     void run()
     {
         conv_layer.run();
-#ifdef ARM_COMPUTE_GC
-        if(opengles31_is_available() && std::is_same<typename std::decay<TensorType>::type, arm_compute::GCTensor>::value)
-        {
-            force_sync_tensor(dst);
-        }
-#endif /* ARM_COMPUTE_GC */
+    }
+
+    void sync()
+    {
+        sync_if_necessary<TensorType>();
+        sync_tensor_if_necessary<TensorType>(dst);
     }
 
     void teardown()
diff --git a/tests/benchmark/fixtures/DepthConcatenateLayerFixture.h b/tests/benchmark/fixtures/DepthConcatenateLayerFixture.h
index 221f34c..523a41b 100644
--- a/tests/benchmark/fixtures/DepthConcatenateLayerFixture.h
+++ b/tests/benchmark/fixtures/DepthConcatenateLayerFixture.h
@@ -123,6 +123,12 @@
         _depth_concat.run();
     }
 
+    void sync()
+    {
+        sync_if_necessary<TensorType>();
+        sync_tensor_if_necessary<TensorType>(_dst);
+    }
+
     void teardown()
     {
         for(auto &src : _srcs)
diff --git a/tests/benchmark/fixtures/DepthwiseConvolutionLayerFixture.h b/tests/benchmark/fixtures/DepthwiseConvolutionLayerFixture.h
index 19ebb4e..d505ba3 100644
--- a/tests/benchmark/fixtures/DepthwiseConvolutionLayerFixture.h
+++ b/tests/benchmark/fixtures/DepthwiseConvolutionLayerFixture.h
@@ -72,6 +72,12 @@
         depth_conv.run();
     }
 
+    void sync()
+    {
+        sync_if_necessary<TensorType>();
+        sync_tensor_if_necessary<TensorType>(dst);
+    }
+
     void teardown()
     {
         src.allocator()->free();
diff --git a/tests/benchmark/fixtures/DepthwiseSeparableConvolutionLayerFixture.h b/tests/benchmark/fixtures/DepthwiseSeparableConvolutionLayerFixture.h
index fa15440..c841996 100644
--- a/tests/benchmark/fixtures/DepthwiseSeparableConvolutionLayerFixture.h
+++ b/tests/benchmark/fixtures/DepthwiseSeparableConvolutionLayerFixture.h
@@ -83,6 +83,12 @@
         depth_sep_conv_layer.run();
     }
 
+    void sync()
+    {
+        sync_if_necessary<TensorType>();
+        sync_tensor_if_necessary<TensorType>(dst);
+    }
+
     void teardown()
     {
         src.allocator()->free();
diff --git a/tests/benchmark/fixtures/DequantizationLayerFixture.h b/tests/benchmark/fixtures/DequantizationLayerFixture.h
index 30e05f9..4251a96 100644
--- a/tests/benchmark/fixtures/DequantizationLayerFixture.h
+++ b/tests/benchmark/fixtures/DequantizationLayerFixture.h
@@ -73,6 +73,12 @@
         dequantization_func.run();
     }
 
+    void sync()
+    {
+        sync_if_necessary<TensorType>();
+        sync_tensor_if_necessary<TensorType>(dst);
+    }
+
     void teardown()
     {
         src.allocator()->free();
diff --git a/tests/benchmark/fixtures/FlattenLayerFixture.h b/tests/benchmark/fixtures/FlattenLayerFixture.h
index 67f5f01..f6e44a2 100644
--- a/tests/benchmark/fixtures/FlattenLayerFixture.h
+++ b/tests/benchmark/fixtures/FlattenLayerFixture.h
@@ -68,6 +68,12 @@
         flatten_func.run();
     }
 
+    void sync()
+    {
+        sync_if_necessary<TensorType>();
+        sync_tensor_if_necessary<TensorType>(dst);
+    }
+
     void teardown()
     {
         src.allocator()->free();
diff --git a/tests/benchmark/fixtures/FloorFixture.h b/tests/benchmark/fixtures/FloorFixture.h
index 8de87b8..b6bb896 100644
--- a/tests/benchmark/fixtures/FloorFixture.h
+++ b/tests/benchmark/fixtures/FloorFixture.h
@@ -62,6 +62,12 @@
         floor_func.run();
     }
 
+    void sync()
+    {
+        sync_if_necessary<TensorType>();
+        sync_tensor_if_necessary<TensorType>(dst);
+    }
+
     void teardown()
     {
         src.allocator()->free();
diff --git a/tests/benchmark/fixtures/FullyConnectedLayerFixture.h b/tests/benchmark/fixtures/FullyConnectedLayerFixture.h
index ef08c4a..08c2ef9 100644
--- a/tests/benchmark/fixtures/FullyConnectedLayerFixture.h
+++ b/tests/benchmark/fixtures/FullyConnectedLayerFixture.h
@@ -30,13 +30,6 @@
 #include "tests/Utils.h"
 #include "tests/framework/Fixture.h"
 
-#ifdef ARM_COMPUTE_GC
-#include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h"
-#include "tests/GLES_COMPUTE/Helper.h"
-
-using namespace arm_compute::test::gles_compute;
-#endif /* ARM_COMPUTE_GC */
-
 namespace arm_compute
 {
 namespace test
@@ -78,12 +71,12 @@
     void run()
     {
         fc_layer.run();
-#ifdef ARM_COMPUTE_GC
-        if(opengles31_is_available() && std::is_same<typename std::decay<TensorType>::type, arm_compute::GCTensor>::value)
-        {
-            force_sync_tensor(dst);
-        }
-#endif /* ARM_COMPUTE_GC */
+    }
+
+    void sync()
+    {
+        sync_if_necessary<TensorType>();
+        sync_tensor_if_necessary<TensorType>(dst);
     }
 
     void teardown()
diff --git a/tests/benchmark/fixtures/GEMMFixture.h b/tests/benchmark/fixtures/GEMMFixture.h
index 0c41c67..d1eded0 100644
--- a/tests/benchmark/fixtures/GEMMFixture.h
+++ b/tests/benchmark/fixtures/GEMMFixture.h
@@ -69,6 +69,12 @@
         gemm.run();
     }
 
+    void sync()
+    {
+        sync_if_necessary<TensorType>();
+        sync_tensor_if_necessary<TensorType>(dst);
+    }
+
     void teardown()
     {
         a.allocator()->free();
diff --git a/tests/benchmark/fixtures/GEMMInterleave4x4Fixture.h b/tests/benchmark/fixtures/GEMMInterleave4x4Fixture.h
index e55e092..293ceff 100644
--- a/tests/benchmark/fixtures/GEMMInterleave4x4Fixture.h
+++ b/tests/benchmark/fixtures/GEMMInterleave4x4Fixture.h
@@ -69,6 +69,12 @@
         gemm.run();
     }
 
+    void sync()
+    {
+        sync_if_necessary<TensorType>();
+        sync_tensor_if_necessary<TensorType>(b);
+    }
+
     void teardown()
     {
         a.allocator()->free();
diff --git a/tests/benchmark/fixtures/GEMMLowpFixture.h b/tests/benchmark/fixtures/GEMMLowpFixture.h
index 4bd7dfd..1b64591 100644
--- a/tests/benchmark/fixtures/GEMMLowpFixture.h
+++ b/tests/benchmark/fixtures/GEMMLowpFixture.h
@@ -72,6 +72,12 @@
         gemmlowp.run();
     }
 
+    void sync()
+    {
+        sync_if_necessary<TensorType>();
+        sync_tensor_if_necessary<TensorType>(c);
+    }
+
     void teardown()
     {
         a.allocator()->free();
diff --git a/tests/benchmark/fixtures/L2NormalizeLayerFixture.h b/tests/benchmark/fixtures/L2NormalizeLayerFixture.h
index 296a2e9..ae5b1a1 100644
--- a/tests/benchmark/fixtures/L2NormalizeLayerFixture.h
+++ b/tests/benchmark/fixtures/L2NormalizeLayerFixture.h
@@ -64,6 +64,12 @@
         l2norm_func.run();
     }
 
+    void sync()
+    {
+        sync_if_necessary<TensorType>();
+        sync_tensor_if_necessary<TensorType>(dst);
+    }
+
     void teardown()
     {
         src.allocator()->free();
diff --git a/tests/benchmark/fixtures/LeNet5Fixture.h b/tests/benchmark/fixtures/LeNet5Fixture.h
index 77a09d3..191daa2 100644
--- a/tests/benchmark/fixtures/LeNet5Fixture.h
+++ b/tests/benchmark/fixtures/LeNet5Fixture.h
@@ -57,6 +57,11 @@
         network.run();
     }
 
+    void sync()
+    {
+        network.sync();
+    }
+
     void teardown()
     {
         network.clear();
diff --git a/tests/benchmark/fixtures/MobileNetFixture.h b/tests/benchmark/fixtures/MobileNetFixture.h
index 660205c..165b269 100644
--- a/tests/benchmark/fixtures/MobileNetFixture.h
+++ b/tests/benchmark/fixtures/MobileNetFixture.h
@@ -58,6 +58,11 @@
         network.run();
     }
 
+    void sync()
+    {
+        network.sync();
+    }
+
     void teardown()
     {
         network.clear();
diff --git a/tests/benchmark/fixtures/MobileNetV1Fixture.h b/tests/benchmark/fixtures/MobileNetV1Fixture.h
index 07333dd..54b0d09 100644
--- a/tests/benchmark/fixtures/MobileNetV1Fixture.h
+++ b/tests/benchmark/fixtures/MobileNetV1Fixture.h
@@ -61,6 +61,11 @@
         network.run();
     }
 
+    void sync()
+    {
+        network.sync();
+    }
+
     void teardown()
     {
         network.clear();
diff --git a/tests/benchmark/fixtures/NormalizationLayerFixture.h b/tests/benchmark/fixtures/NormalizationLayerFixture.h
index 41dd8a7..cbe20d5 100644
--- a/tests/benchmark/fixtures/NormalizationLayerFixture.h
+++ b/tests/benchmark/fixtures/NormalizationLayerFixture.h
@@ -66,6 +66,12 @@
         norm_layer.run();
     }
 
+    void sync()
+    {
+        sync_if_necessary<TensorType>();
+        sync_tensor_if_necessary<TensorType>(dst);
+    }
+
     void teardown()
     {
         src.allocator()->free();
diff --git a/tests/benchmark/fixtures/NormalizePlanarYUVLayerFixture.h b/tests/benchmark/fixtures/NormalizePlanarYUVLayerFixture.h
index 9234353..a84aa26 100644
--- a/tests/benchmark/fixtures/NormalizePlanarYUVLayerFixture.h
+++ b/tests/benchmark/fixtures/NormalizePlanarYUVLayerFixture.h
@@ -29,12 +29,6 @@
 #include "tests/Globals.h"
 #include "tests/Utils.h"
 #include "tests/framework/Fixture.h"
-#ifdef ARM_COMPUTE_GC
-#include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h"
-#include "tests/GLES_COMPUTE/Helper.h"
-
-using namespace arm_compute::test::gles_compute;
-#endif /* ARM_COMPUTE_GC */
 
 namespace arm_compute
 {
@@ -75,12 +69,12 @@
     void run()
     {
         normalize_planar_yuv_layer.run();
-#ifdef ARM_COMPUTE_GC
-        if(opengles31_is_available() && std::is_same<typename std::decay<TensorType>::type, arm_compute::GCTensor>::value)
-        {
-            force_sync_tensor(dst);
-        }
-#endif /* ARM_COMPUTE_GC */
+    }
+
+    void sync()
+    {
+        sync_if_necessary<TensorType>();
+        sync_tensor_if_necessary<TensorType>(dst);
     }
 
     void teardown()
diff --git a/tests/benchmark/fixtures/PoolingLayerFixture.h b/tests/benchmark/fixtures/PoolingLayerFixture.h
index 2060301..47deda9 100644
--- a/tests/benchmark/fixtures/PoolingLayerFixture.h
+++ b/tests/benchmark/fixtures/PoolingLayerFixture.h
@@ -67,6 +67,12 @@
         pool_layer.run();
     }
 
+    void sync()
+    {
+        sync_if_necessary<TensorType>();
+        sync_tensor_if_necessary<TensorType>(dst);
+    }
+
     void teardown()
     {
         src.allocator()->free();
diff --git a/tests/benchmark/fixtures/QuantizationLayerFixture.h b/tests/benchmark/fixtures/QuantizationLayerFixture.h
index 5981f99..0843962 100644
--- a/tests/benchmark/fixtures/QuantizationLayerFixture.h
+++ b/tests/benchmark/fixtures/QuantizationLayerFixture.h
@@ -63,6 +63,12 @@
         quantization_func.run();
     }
 
+    void sync()
+    {
+        sync_if_necessary<TensorType>();
+        sync_tensor_if_necessary<TensorType>(dst);
+    }
+
     void teardown()
     {
         src.allocator()->free();
diff --git a/tests/benchmark/fixtures/ROIPoolingLayerFixture.h b/tests/benchmark/fixtures/ROIPoolingLayerFixture.h
index 76c2280..9013218 100644
--- a/tests/benchmark/fixtures/ROIPoolingLayerFixture.h
+++ b/tests/benchmark/fixtures/ROIPoolingLayerFixture.h
@@ -78,6 +78,12 @@
         roi_pool.run();
     }
 
+    void sync()
+    {
+        sync_if_necessary<TensorType>();
+        sync_tensor_if_necessary<TensorType>(dst);
+    }
+
     void teardown()
     {
         src.allocator()->free();
diff --git a/tests/benchmark/fixtures/ReshapeLayerFixture.h b/tests/benchmark/fixtures/ReshapeLayerFixture.h
index 4f65e9d..b92377c 100644
--- a/tests/benchmark/fixtures/ReshapeLayerFixture.h
+++ b/tests/benchmark/fixtures/ReshapeLayerFixture.h
@@ -64,6 +64,12 @@
         reshape_func.run();
     }
 
+    void sync()
+    {
+        sync_if_necessary<TensorType>();
+        sync_tensor_if_necessary<TensorType>(dst);
+    }
+
     void teardown()
     {
         src.allocator()->free();
diff --git a/tests/benchmark/fixtures/ScaleFixture.h b/tests/benchmark/fixtures/ScaleFixture.h
index 1ba191b..21a6391 100644
--- a/tests/benchmark/fixtures/ScaleFixture.h
+++ b/tests/benchmark/fixtures/ScaleFixture.h
@@ -81,6 +81,12 @@
         scale_func.run();
     }
 
+    void sync()
+    {
+        sync_if_necessary<TensorType>();
+        sync_tensor_if_necessary<TensorType>(dst);
+    }
+
     void teardown()
     {
         src.allocator()->free();
diff --git a/tests/benchmark/fixtures/ScaleLayerFixture.h b/tests/benchmark/fixtures/ScaleLayerFixture.h
index 94cc678..f34a003 100644
--- a/tests/benchmark/fixtures/ScaleLayerFixture.h
+++ b/tests/benchmark/fixtures/ScaleLayerFixture.h
@@ -31,13 +31,6 @@
 #include "tests/framework/Asserts.h"
 #include "tests/framework/Fixture.h"
 
-#ifdef ARM_COMPUTE_GC
-#include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h"
-#include "tests/GLES_COMPUTE/Helper.h"
-
-using namespace arm_compute::test::gles_compute;
-#endif /* ARM_COMPUTE_GC */
-
 namespace arm_compute
 {
 namespace test
@@ -83,12 +76,12 @@
     void run()
     {
         scale_layer.run();
-#ifdef ARM_COMPUTE_GC
-        if(opengles31_is_available() && std::is_same<typename std::decay<TensorType>::type, arm_compute::GCTensor>::value)
-        {
-            force_sync_tensor(dst);
-        }
-#endif /* ARM_COMPUTE_GC */
+    }
+
+    void sync()
+    {
+        sync_if_necessary<TensorType>();
+        sync_tensor_if_necessary<TensorType>(dst);
     }
 
     void teardown()
diff --git a/tests/benchmark/fixtures/SoftmaxLayerFixture.h b/tests/benchmark/fixtures/SoftmaxLayerFixture.h
index 50b2726..f3657da 100644
--- a/tests/benchmark/fixtures/SoftmaxLayerFixture.h
+++ b/tests/benchmark/fixtures/SoftmaxLayerFixture.h
@@ -31,13 +31,6 @@
 #include "tests/framework/Asserts.h"
 #include "tests/framework/Fixture.h"
 
-#ifdef ARM_COMPUTE_GC
-#include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h"
-#include "tests/GLES_COMPUTE/Helper.h"
-
-using namespace arm_compute::test::gles_compute;
-#endif /* ARM_COMPUTE_GC */
-
 namespace arm_compute
 {
 namespace test
@@ -73,12 +66,12 @@
     void run()
     {
         smx_layer.run();
-#ifdef ARM_COMPUTE_GC
-        if(opengles31_is_available() && std::is_same<typename std::decay<TensorType>::type, arm_compute::GCTensor>::value)
-        {
-            force_sync_tensor(dst);
-        }
-#endif /* ARM_COMPUTE_GC */
+    }
+
+    void sync()
+    {
+        sync_if_necessary<TensorType>();
+        sync_tensor_if_necessary<TensorType>(dst);
     }
 
     void teardown()
diff --git a/tests/benchmark/fixtures/TransposeFixture.h b/tests/benchmark/fixtures/TransposeFixture.h
index 19d2194..bc2d6d6 100644
--- a/tests/benchmark/fixtures/TransposeFixture.h
+++ b/tests/benchmark/fixtures/TransposeFixture.h
@@ -67,6 +67,12 @@
         transpose.run();
     }
 
+    void sync()
+    {
+        sync_if_necessary<TensorType>();
+        sync_tensor_if_necessary<TensorType>(dst);
+    }
+
     void teardown()
     {
         src.allocator()->free();
diff --git a/tests/framework/Framework.cpp b/tests/framework/Framework.cpp
index d1fb28d..79a77d9 100644
--- a/tests/framework/Framework.cpp
+++ b/tests/framework/Framework.cpp
@@ -25,16 +25,6 @@
 
 #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/GCScheduler.h"
-#endif /* ARM_COMPUTE_GC */
-
 #include <chrono>
 #include <iostream>
 #include <sstream>
@@ -310,18 +300,7 @@
                     profiler.start();
                 }
                 test_case->do_run();
-#ifdef ARM_COMPUTE_CL
-                if(opencl_is_available())
-                {
-                    CLScheduler::get().sync();
-                }
-#endif /* ARM_COMPUTE_CL */
-#ifdef ARM_COMPUTE_GC
-                if(opengles31_is_available())
-                {
-                    GCScheduler::get().sync();
-                }
-#endif /* ARM_COMPUTE_GC */
+                test_case->do_sync();
                 if(_num_iterations == 1 || i != 0)
                 {
                     profiler.stop();
diff --git a/tests/framework/Macros.h b/tests/framework/Macros.h
index 7aabb75..deca1ef 100644
--- a/tests/framework/Macros.h
+++ b/tests/framework/Macros.h
@@ -114,6 +114,11 @@
     {                        \
         FIXTURE::run();      \
     }
+#define FIXTURE_SYNC(FIXTURE) \
+    void do_sync() override   \
+    {                         \
+        FIXTURE::sync();      \
+    }
 #define FIXTURE_TEARDOWN(FIXTURE) \
     void do_teardown() override   \
     {                             \
@@ -223,6 +228,7 @@
         TEST_CASE_CONSTRUCTOR(TEST_NAME)                                            \
         FIXTURE_SETUP(FIXTURE)                                                      \
         FIXTURE_RUN(FIXTURE)                                                        \
+        FIXTURE_SYNC(FIXTURE)                                                       \
         FIXTURE_TEARDOWN(FIXTURE)                                                   \
     };                                                                              \
     TEST_REGISTRAR(TEST_NAME, MODE, STATUS)
@@ -244,6 +250,7 @@
         DATA_TEST_CASE_CONSTRUCTOR(TEST_NAME, DATASET)                                                                              \
         FIXTURE_DATA_SETUP(FIXTURE)                                                                                                 \
         FIXTURE_RUN(FIXTURE)                                                                                                        \
+        FIXTURE_SYNC(FIXTURE)                                                                                                       \
         FIXTURE_TEARDOWN(FIXTURE)                                                                                                   \
     };                                                                                                                              \
     DATA_TEST_REGISTRAR(TEST_NAME, MODE, STATUS, DATASET)
diff --git a/tests/framework/TestCase.h b/tests/framework/TestCase.h
index dbb9312..18dd12e 100644
--- a/tests/framework/TestCase.h
+++ b/tests/framework/TestCase.h
@@ -42,6 +42,7 @@
 public:
     virtual void do_setup() {};
     virtual void do_run() {};
+    virtual void do_sync() {};
     virtual void do_teardown() {};
 
     /** Default destructor. */
diff --git a/tests/networks/AlexNetNetwork.h b/tests/networks/AlexNetNetwork.h
index 448cf319..819111f 100644
--- a/tests/networks/AlexNetNetwork.h
+++ b/tests/networks/AlexNetNetwork.h
@@ -564,6 +564,13 @@
         smx.run();
     }
 
+    /** Sync the results */
+    void sync()
+    {
+        sync_if_necessary<TensorType>();
+        sync_tensor_if_necessary<TensorType>(output);
+    }
+
 private:
     struct DirectConv
     {
diff --git a/tests/networks/LeNet5Network.h b/tests/networks/LeNet5Network.h
index f8aac30..a46489f 100644
--- a/tests/networks/LeNet5Network.h
+++ b/tests/networks/LeNet5Network.h
@@ -230,6 +230,13 @@
         smx.run();
     }
 
+    /** Sync the results */
+    void sync()
+    {
+        sync_if_necessary<TensorType>();
+        sync_tensor_if_necessary<TensorType>(output);
+    }
+
 private:
     unsigned int _batches{ 0 };
 
diff --git a/tests/networks/MobileNetNetwork.h b/tests/networks/MobileNetNetwork.h
index 1bc8ad9..8c3cb1f 100644
--- a/tests/networks/MobileNetNetwork.h
+++ b/tests/networks/MobileNetNetwork.h
@@ -251,6 +251,13 @@
         reshape.run();
     }
 
+    /** Sync the results */
+    void sync()
+    {
+        sync_if_necessary<TensorType>();
+        sync_tensor_if_necessary<TensorType>(output);
+    }
+
 private:
     void depthwise_conv_block_init(unsigned int idx, unsigned int ifm, unsigned int ofm)
     {
diff --git a/tests/networks/MobileNetV1Network.h b/tests/networks/MobileNetV1Network.h
index dbe3f49..0957c6b 100644
--- a/tests/networks/MobileNetV1Network.h
+++ b/tests/networks/MobileNetV1Network.h
@@ -300,6 +300,13 @@
         smx.run();
     }
 
+    /** Sync the results */
+    void sync()
+    {
+        sync_if_necessary<TensorType>();
+        sync_tensor_if_necessary<TensorType>(output);
+    }
+
 private:
     void depthwise_conv_block_init(unsigned int idx, unsigned int ifm, unsigned int ofm)
     {