Fix segfault at validate_cl_gemm

Fixes segfault when exiting the program.

Change-Id: I20757f700842e6c1de9112d2915d539513434c6d
Signed-off-by: Mirko leonardo Serra laban <mirko.serra@arm.com>
Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/4484
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com>
diff --git a/tests/validate_examples/RunExample.cpp b/tests/validate_examples/RunExample.cpp
index b6ff883..aca4ddc 100644
--- a/tests/validate_examples/RunExample.cpp
+++ b/tests/validate_examples/RunExample.cpp
@@ -28,6 +28,7 @@
 
 #include "ValidateExample.h"
 #include "arm_compute/runtime/Scheduler.h"
+#include "arm_compute/runtime/CL/CLHelpers.h"
 #include "tests/AssetsLibrary.h"
 #include "tests/Globals.h"
 #include "tests/framework/Framework.h"
@@ -149,6 +150,15 @@
         }
     }
 
+#ifdef ARM_COMPUTE_CL
+    if(opencl_is_available())
+    {
+        auto ctx_dev_err = create_opencl_context_and_device();
+        ARM_COMPUTE_ERROR_ON_MSG(std::get<2>(ctx_dev_err) != CL_SUCCESS, "Failed to create OpenCL context");
+        CLScheduler::get().default_init_with_context(std::get<1>(ctx_dev_err), std::get<0>(ctx_dev_err), nullptr);
+    }
+#endif /* ARM_COMPUTE_CL */
+
     if(options.log_level->value() >= framework::LogLevel::CONFIG)
     {
         for(auto &p : printers)
@@ -159,10 +169,6 @@
 #ifdef ARM_COMPUTE_CL
             if(opencl_is_available())
             {
-                if(!CLScheduler::get().is_initialised())
-                {
-                    CLScheduler::get().default_init();
-                }
                 p->print_entry("CL_DEVICE_VERSION", CLKernelLibrary::get().get_device_version());
             }
             else