COMPMID-1388: Change default CLTuner to the one for the detected GPU

Sets a default tuner for the detected target if no tuner is specified in
default_init()

Change-Id: I27f1b9bbc0df91c1940315c6cc9042720cd1d3fe
Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/139630
Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Tested-by: Jenkins <bsgcomp@arm.com>
diff --git a/arm_compute/runtime/CL/CLScheduler.h b/arm_compute/runtime/CL/CLScheduler.h
index bdd779b..8eb287c 100644
--- a/arm_compute/runtime/CL/CLScheduler.h
+++ b/arm_compute/runtime/CL/CLScheduler.h
@@ -94,15 +94,6 @@
         return CLKernelLibrary::get().context();
     }
 
-    /** Accessor to set the CL context to be used by the scheduler.
-     *
-     * @param[in] context A CL context.
-     */
-    void set_context(cl::Context context)
-    {
-        CLKernelLibrary::get().set_context(context);
-    }
-
     /** Accessor for the associated CL command queue.
      *
      * @return A CL command queue.
@@ -122,6 +113,15 @@
         return _target;
     }
 
+    /** Accessor to set the CL context to be used by the scheduler.
+     *
+     * @param[in] context A CL context.
+     */
+    void set_context(cl::Context context)
+    {
+        CLKernelLibrary::get().set_context(context);
+    }
+
     /** Accessor to set the CL command queue to be used by the scheduler.
      *
      * @param[in] queue A CL command queue.
@@ -140,6 +140,15 @@
         _target = target;
     }
 
+    /** Accessor to set the CL tuner to be used by the scheduler.
+     *
+     * @param[in] tuner A CL tuner
+     */
+    void set_tuner(ICLTuner *tuner)
+    {
+        _cl_tuner = tuner;
+    }
+
     /** Blocks until all commands in the associated command queue have finished. */
     void sync()
     {
@@ -179,10 +188,11 @@
     /** Flag to ensure symbols initialisation is happening before Scheduler creation */
     static std::once_flag _initialize_symbols;
 
-    cl::CommandQueue _queue;
-    GPUTarget        _target;
-    bool             _is_initialised;
-    ICLTuner        *_cl_tuner;
+    cl::CommandQueue          _queue;
+    GPUTarget                 _target;
+    bool                      _is_initialised;
+    ICLTuner                 *_cl_tuner;
+    std::unique_ptr<ICLTuner> _cl_default_static_tuner;
 };
 }
 #endif /* __ARM_COMPUTE_CLSCHEDULER_H__ */
diff --git a/arm_compute/runtime/CL/tuners/Tuners.h b/arm_compute/runtime/CL/tuners/Tuners.h
new file mode 100644
index 0000000..a9eaa07
--- /dev/null
+++ b/arm_compute/runtime/CL/tuners/Tuners.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2018 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef __ARM_COMPUTE_TUNERS_H__
+#define __ARM_COMPUTE_TUNERS_H__
+
+#include "arm_compute/runtime/CL/tuners/BifrostTuner.h"
+#include "arm_compute/runtime/CL/tuners/MidgardTuner.h"
+
+#include <memory>
+
+namespace arm_compute
+{
+namespace tuners
+{
+/** Tuner factory class */
+class TunerFactory final
+{
+public:
+    static std::unique_ptr<ICLTuner> create_tuner(GPUTarget target)
+    {
+        GPUTarget arch = get_arch_from_target(target);
+        switch(arch)
+        {
+            case GPUTarget::BIFROST:
+                return support::cpp14::make_unique<BifrostTuner>();
+            case GPUTarget::MIDGARD:
+                return support::cpp14::make_unique<MidgardTuner>();
+            default:
+                return nullptr;
+        }
+    }
+};
+} // namespace tuners
+} // namespace arm_compute
+#endif /*__ARM_COMPUTE_TUNERS_H__ */
diff --git a/src/runtime/CL/CLScheduler.cpp b/src/runtime/CL/CLScheduler.cpp
index c348dfa..f524a91 100644
--- a/src/runtime/CL/CLScheduler.cpp
+++ b/src/runtime/CL/CLScheduler.cpp
@@ -25,6 +25,7 @@
 
 #include "arm_compute/core/CL/ICLKernel.h"
 #include "arm_compute/runtime/CL/CLTuner.h"
+#include "arm_compute/runtime/CL/tuners/Tuners.h"
 
 using namespace arm_compute;
 
@@ -41,7 +42,7 @@
 std::once_flag CLScheduler::_initialize_symbols;
 
 CLScheduler::CLScheduler()
-    : _queue(), _target(GPUTarget::MIDGARD), _is_initialised(false), _cl_tuner()
+    : _queue(), _target(GPUTarget::MIDGARD), _is_initialised(false), _cl_tuner(nullptr), _cl_default_static_tuner(nullptr)
 {
 }
 
@@ -83,11 +84,13 @@
         cl::CommandQueue queue = cl::CommandQueue(ctx, cl::Device::getDefault(), queue_properties);
         CLKernelLibrary::get().init("./cl_kernels/", ctx, cl::Device::getDefault());
         init(ctx, queue, cl::Device::getDefault(), cl_tuner);
+
+        // Create a default static tuner and set if none was provided
+        _cl_default_static_tuner = tuners::TunerFactory::create_tuner(_target);
     }
-    else
-    {
-        _cl_tuner = cl_tuner;
-    }
+
+    // Set CL tuner
+    _cl_tuner = (cl_tuner == nullptr) ? _cl_default_static_tuner.get() : cl_tuner;
 }
 
 void CLScheduler::enqueue(ICLKernel &kernel, bool flush)