Move tuning and IClTensorHandle code from cl to aclCommon backend.

 * Required to enable easier future merging and rebase into experimental/GpuFsa
   as part of IVGCVSW-7380.

Signed-off-by: Cathal Corbett <cathal.corbett@arm.com>
Change-Id: I066dcf00523ff430a0908666e452548ab848bd86
diff --git a/src/backends/aclCommon/ArmComputeTuningUtils.cpp b/src/backends/aclCommon/ArmComputeTuningUtils.cpp
new file mode 100644
index 0000000..4680541
--- /dev/null
+++ b/src/backends/aclCommon/ArmComputeTuningUtils.cpp
@@ -0,0 +1,60 @@
+//
+// Copyright © 2023 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "ArmComputeTuningUtils.hpp"
+
+namespace armnn
+{
+
+IGpuAccTunedParameters* IGpuAccTunedParameters::CreateRaw(IGpuAccTunedParameters::Mode mode,
+                                                          IGpuAccTunedParameters::TuningLevel tuningLevel)
+{
+    return new ClTunedParameters(mode, tuningLevel);
+}
+
+IGpuAccTunedParametersPtr IGpuAccTunedParameters::Create(IGpuAccTunedParameters::Mode mode,
+                                                         IGpuAccTunedParameters::TuningLevel tuningLevel)
+{
+    return IGpuAccTunedParametersPtr(CreateRaw(mode, tuningLevel), &IGpuAccTunedParameters::Destroy);
+}
+
+void IGpuAccTunedParameters::Destroy(IGpuAccTunedParameters* params)
+{
+    delete params;
+}
+
+ClTunedParameters::ClTunedParameters(IGpuAccTunedParameters::Mode mode,
+                                     IGpuAccTunedParameters::TuningLevel tuningLevel)
+    : m_Mode(mode)
+    , m_TuningLevel(tuningLevel)
+    , m_Tuner(mode == ClTunedParameters::Mode::UpdateTunedParameters)
+{
+}
+
+void ClTunedParameters::Load(const char* filename)
+{
+    try
+    {
+        m_Tuner.load_from_file(filename);
+    }
+    catch (const std::exception& e)
+    {
+        throw Exception(std::string("Failed to load tuned parameters file '") + filename + "': " + e.what());
+    }
+}
+
+void ClTunedParameters::Save(const char* filename) const
+{
+    try
+    {
+        m_Tuner.save_to_file(filename);
+    }
+    catch (const std::exception& e)
+    {
+        throw Exception(std::string("Failed to save tuned parameters file to '") + filename + "': " + e.what());
+    }
+}
+
+}
\ No newline at end of file
diff --git a/src/backends/aclCommon/ArmComputeTuningUtils.hpp b/src/backends/aclCommon/ArmComputeTuningUtils.hpp
new file mode 100644
index 0000000..6d99d3f
--- /dev/null
+++ b/src/backends/aclCommon/ArmComputeTuningUtils.hpp
@@ -0,0 +1,84 @@
+//
+// Copyright © 2023 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+#pragma once
+
+#include <armnn/BackendOptions.hpp>
+#include <armnn/IRuntime.hpp>
+#include <armnn/Logging.hpp>
+
+#include <arm_compute/runtime/CL/CLTuner.h>
+#include <arm_compute/runtime/CL/CLTunerTypes.h>
+#include <arm_compute/runtime/CL/CLGEMMHeuristicsHandle.h>
+
+namespace armnn
+{
+
+enum class TuningLevel
+{
+    None,
+    Rapid,
+    Normal,
+    Exhaustive
+};
+
+inline TuningLevel ParseTuningLevel(const BackendOptions::Var& value, TuningLevel defaultValue)
+{
+    if (value.IsInt())
+    {
+        int v = value.AsInt();
+        if (v > static_cast<int>(TuningLevel::Exhaustive) ||
+            v < static_cast<int>(TuningLevel::None))
+        {
+            ARMNN_LOG(warning) << "Invalid GpuAcc tuning level ("<< v << ") selected. "
+                                  "Using default(" << static_cast<int>(defaultValue) << ")";
+        } else
+        {
+            return static_cast<TuningLevel>(v);
+        }
+    }
+    return defaultValue;
+}
+
+inline void ConfigureTuner(arm_compute::CLTuner &tuner, TuningLevel level)
+{
+    tuner.set_tune_new_kernels(true); // Turn on tuning initially.
+
+    switch (level)
+    {
+        case TuningLevel::Rapid:
+            ARMNN_LOG(info) << "Gpu tuning is activated. TuningLevel: Rapid (1)";
+            tuner.set_tuner_mode(arm_compute::CLTunerMode::RAPID);
+            break;
+        case TuningLevel::Normal:
+            ARMNN_LOG(info) << "Gpu tuning is activated. TuningLevel: Normal (2)";
+            tuner.set_tuner_mode(arm_compute::CLTunerMode::NORMAL);
+            break;
+        case TuningLevel::Exhaustive:
+            ARMNN_LOG(info) << "Gpu tuning is activated. TuningLevel: Exhaustive (3)";
+            tuner.set_tuner_mode(arm_compute::CLTunerMode::EXHAUSTIVE);
+            break;
+        case TuningLevel::None:
+        default:
+            tuner.set_tune_new_kernels(false); // Turn off tuning. Set to "use" only mode.
+            break;
+    }
+}
+
+class ClTunedParameters : public IGpuAccTunedParameters
+{
+public:
+    ClTunedParameters(IGpuAccTunedParameters::Mode mode, IGpuAccTunedParameters::TuningLevel tuningLevel);
+
+    virtual void Load(const char* filename);
+    virtual void Save(const char* filename) const;
+
+    Mode m_Mode;
+    TuningLevel m_TuningLevel;
+
+    arm_compute::CLTuner m_Tuner;
+    arm_compute::CLGEMMHeuristicsHandle m_HeuristicsHandle;
+};
+
+}
\ No newline at end of file
diff --git a/src/backends/aclCommon/CMakeLists.txt b/src/backends/aclCommon/CMakeLists.txt
index 05fbe6c..b3bf89e 100644
--- a/src/backends/aclCommon/CMakeLists.txt
+++ b/src/backends/aclCommon/CMakeLists.txt
@@ -1,5 +1,5 @@
 #
-# Copyright © 2017 Arm Ltd. All rights reserved.
+# Copyright © 2017, 2023 Arm Ltd and Contributors. All rights reserved.
 # SPDX-License-Identifier: MIT
 #
 
@@ -8,9 +8,12 @@
     ArmComputeTensorHandle.hpp
     ArmComputeTensorUtils.hpp
     ArmComputeTensorUtils.cpp
+    ArmComputeTuningUtils.hpp
+    ArmComputeTuningUtils.cpp
     ArmComputeUtils.hpp
     BaseMemoryManager.cpp
     BaseMemoryManager.hpp
+    IClTensorHandle.hpp
 )
 
 if(BUILD_UNIT_TESTS)
diff --git a/src/backends/cl/IClTensorHandle.hpp b/src/backends/aclCommon/IClTensorHandle.hpp
similarity index 100%
rename from src/backends/cl/IClTensorHandle.hpp
rename to src/backends/aclCommon/IClTensorHandle.hpp
diff --git a/src/backends/aclCommon/common.mk b/src/backends/aclCommon/common.mk
index 0ba966a..b113269 100644
--- a/src/backends/aclCommon/common.mk
+++ b/src/backends/aclCommon/common.mk
@@ -9,6 +9,7 @@
 
 COMMON_SOURCES := \
     ArmComputeTensorUtils.cpp \
+    ArmComputeTuningUtils.cpp \
     BaseMemoryManager.cpp
 
 # COMMON_TEST_SOURCES contains the list of files to be included
diff --git a/src/backends/cl/CMakeLists.txt b/src/backends/cl/CMakeLists.txt
index aeb90b0..20c4206 100644
--- a/src/backends/cl/CMakeLists.txt
+++ b/src/backends/cl/CMakeLists.txt
@@ -1,5 +1,5 @@
 #
-# Copyright © 2017 Arm Ltd. All rights reserved.
+# Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved.
 # SPDX-License-Identifier: MIT
 #
 
@@ -44,7 +44,6 @@
         ClTensorHandleFactory.hpp
         ClWorkloadFactory.cpp
         ClWorkloadFactory.hpp
-        IClTensorHandle.hpp
         ICLTensorProxy.hpp
         OpenClTimer.cpp
         OpenClTimer.hpp
diff --git a/src/backends/cl/ClBackendContext.cpp b/src/backends/cl/ClBackendContext.cpp
index c63fb0c..adee276 100644
--- a/src/backends/cl/ClBackendContext.cpp
+++ b/src/backends/cl/ClBackendContext.cpp
@@ -1,5 +1,5 @@
 //
-// Copyright © 2017 Arm Ltd. All rights reserved.
+// Copyright © 2017, 2023 Arm Ltd and Contributors. All rights reserved.
 // SPDX-License-Identifier: MIT
 //
 
@@ -59,84 +59,6 @@
     ClContextControl m_ClContextControl;
 };
 
-std::string LowerString(std::string value)
-{
-    std::transform(value.begin(), value.end(), value.begin(),
-                   [](unsigned char c){ return std::tolower(c); });
-
-    return value;
-}
-
-enum class TuningLevel
-{
-    None,
-    Rapid,
-    Normal,
-    Exhaustive
-};
-
-
-TuningLevel ParseTuningLevel(const BackendOptions::Var& value, TuningLevel defaultValue)
-{
-    if (value.IsInt())
-    {
-        int v = value.AsInt();
-        if (v > static_cast<int>(TuningLevel::Exhaustive) ||
-            v < static_cast<int>(TuningLevel::None))
-        {
-            ARMNN_LOG(warning) << "Invalid GpuAcc tuning level ("<< v << ") selected. "
-                                  "Using default(" << static_cast<int>(defaultValue) << ")";
-        } else
-        {
-            return static_cast<TuningLevel>(v);
-        }
-    }
-    return defaultValue;
-}
-
-bool ParseBoolean(const BackendOptions::Var& value, bool defaultValue)
-{
-    if (value.IsBool())
-    {
-        return value.AsBool();
-    }
-    return defaultValue;
-}
-
-std::string ParseFile(const BackendOptions::Var& value, std::string defaultValue)
-{
-    if (value.IsString())
-    {
-        return value.AsString();
-    }
-    return defaultValue;
-}
-
-void ConfigureTuner(arm_compute::CLTuner &tuner, TuningLevel level)
-{
-    tuner.set_tune_new_kernels(true); // Turn on tuning initially.
-
-    switch (level)
-    {
-        case TuningLevel::Rapid:
-            ARMNN_LOG(info) << "Gpu tuning is activated. TuningLevel: Rapid (1)";
-            tuner.set_tuner_mode(arm_compute::CLTunerMode::RAPID);
-            break;
-        case TuningLevel::Normal:
-            ARMNN_LOG(info) << "Gpu tuning is activated. TuningLevel: Normal (2)";
-            tuner.set_tuner_mode(arm_compute::CLTunerMode::NORMAL);
-            break;
-        case TuningLevel::Exhaustive:
-            ARMNN_LOG(info) << "Gpu tuning is activated. TuningLevel: Exhaustive (3)";
-            tuner.set_tuner_mode(arm_compute::CLTunerMode::EXHAUSTIVE);
-            break;
-        case TuningLevel::None:
-        default:
-            tuner.set_tune_new_kernels(false); // Turn off tuning. Set to "use" only mode.
-            break;
-    }
-}
-
 ClBackendContext::ClBackendContext(const IRuntime::CreationOptions& options)
     : IBackendContext(options)
     , m_TuningFile()
@@ -191,17 +113,17 @@
             {
                 if (name == "KernelProfilingEnabled")
                 {
-                    kernelProfiling |= ParseBoolean(value, false);
+                    kernelProfiling |= ParseBooleanBackendOption(value, false);
                 } else if (name == "TuningFile")
                 {
-                    m_TuningFile = ParseFile(value, "");
+                    m_TuningFile = ParseStringBackendOption(value, "");
                 } else if (name == "TuningLevel")
                 {
                     tuningLevel = ParseTuningLevel(value, defaultTuningLevel);
                 }
                 else if (name == "MLGOTuningFilePath")
                 {
-                    m_MLGOTuningFile = ParseFile(value, "");
+                    m_MLGOTuningFile = ParseStringBackendOption(value, "");
                 }
             });
 
diff --git a/src/backends/cl/ClContextControl.cpp b/src/backends/cl/ClContextControl.cpp
index fd2d0f5..34eca96 100644
--- a/src/backends/cl/ClContextControl.cpp
+++ b/src/backends/cl/ClContextControl.cpp
@@ -1,5 +1,5 @@
 //
-// Copyright © 2017 Arm Ltd. All rights reserved.
+// Copyright © 2017, 2023 Arm Ltd and Contributors. All rights reserved.
 // SPDX-License-Identifier: MIT
 //
 
@@ -166,55 +166,4 @@
     DoLoadOpenClRuntime(true);
 }
 
-armnn::IGpuAccTunedParameters* IGpuAccTunedParameters::CreateRaw(armnn::IGpuAccTunedParameters::Mode mode,
-                                                                 armnn::IGpuAccTunedParameters::TuningLevel tuningLevel)
-{
-    return new ClTunedParameters(mode, tuningLevel);
-}
-
-armnn::IGpuAccTunedParametersPtr IGpuAccTunedParameters::Create(armnn::IGpuAccTunedParameters::Mode mode,
-                                                                armnn::IGpuAccTunedParameters::TuningLevel tuningLevel)
-{
-    return IGpuAccTunedParametersPtr(CreateRaw(mode, tuningLevel), &IGpuAccTunedParameters::Destroy);
-}
-
-void IGpuAccTunedParameters::Destroy(IGpuAccTunedParameters* params)
-{
-    delete params;
-}
-
-ClTunedParameters::ClTunedParameters(armnn::IGpuAccTunedParameters::Mode mode,
-                                     armnn::IGpuAccTunedParameters::TuningLevel tuningLevel)
-    : m_Mode(mode)
-    , m_TuningLevel(tuningLevel)
-    , m_Tuner(mode == ClTunedParameters::Mode::UpdateTunedParameters)
-{
-}
-
-void ClTunedParameters::Load(const char* filename)
-{
-    try
-    {
-        m_Tuner.load_from_file(filename);
-    }
-    catch (const std::exception& e)
-    {
-        throw armnn::Exception(std::string("Failed to load tuned parameters file '") + filename + "': " +
-                               e.what());
-    }
-}
-
-void ClTunedParameters::Save(const char* filename) const
-{
-    try
-    {
-        m_Tuner.save_to_file(filename);
-    }
-    catch (const std::exception& e)
-    {
-        throw armnn::Exception(std::string("Failed to save tuned parameters file to '") + filename + "': " +
-                               e.what());
-    }
-}
-
 } // namespace armnn
diff --git a/src/backends/cl/ClContextControl.hpp b/src/backends/cl/ClContextControl.hpp
index 4a640cd..7520d10 100644
--- a/src/backends/cl/ClContextControl.hpp
+++ b/src/backends/cl/ClContextControl.hpp
@@ -1,13 +1,10 @@
 //
-// Copyright © 2017 Arm Ltd. All rights reserved.
+// Copyright © 2017, 2023 Arm Ltd and Contributors. All rights reserved.
 // SPDX-License-Identifier: MIT
 //
 #pragma once
 
-#include "armnn/IRuntime.hpp"
-
-#include <arm_compute/runtime/CL/CLTuner.h>
-#include <arm_compute/runtime/CL/CLGEMMHeuristicsHandle.h>
+#include <aclCommon/ArmComputeTuningUtils.hpp>
 
 namespace armnn
 {
@@ -42,19 +39,4 @@
     bool m_ProfilingEnabled;
 };
 
-class ClTunedParameters : public IGpuAccTunedParameters
-{
-public:
-    ClTunedParameters(armnn::IGpuAccTunedParameters::Mode mode, armnn::IGpuAccTunedParameters::TuningLevel tuningLevel);
-
-    virtual void Load(const char* filename);
-    virtual void Save(const char* filename) const;
-
-    Mode m_Mode;
-    TuningLevel m_TuningLevel;
-
-    arm_compute::CLTuner m_Tuner;
-    arm_compute::CLGEMMHeuristicsHandle m_HeuristicsHandle;
-};
-
 } // namespace armnn
diff --git a/src/backends/cl/ClImportTensorHandle.hpp b/src/backends/cl/ClImportTensorHandle.hpp
index 889a2ad..a03a4e9 100644
--- a/src/backends/cl/ClImportTensorHandle.hpp
+++ b/src/backends/cl/ClImportTensorHandle.hpp
@@ -1,5 +1,5 @@
 //
-// Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
+// Copyright © 2022-2023 Arm Ltd and Contributors. All rights reserved.
 // SPDX-License-Identifier: MIT
 //
 
@@ -19,7 +19,7 @@
 #include <arm_compute/core/TensorShape.h>
 #include <arm_compute/core/Coordinates.h>
 
-#include <cl/IClTensorHandle.hpp>
+#include <aclCommon/IClTensorHandle.hpp>
 
 #include <CL/cl_ext.h>
 #include <arm_compute/core/CL/CLKernelLibrary.h>
diff --git a/src/backends/cl/ClTensorHandle.hpp b/src/backends/cl/ClTensorHandle.hpp
index f63f1fa..3d750f9 100644
--- a/src/backends/cl/ClTensorHandle.hpp
+++ b/src/backends/cl/ClTensorHandle.hpp
@@ -1,5 +1,5 @@
 //
-// Copyright © 2017 Arm Ltd. All rights reserved.
+// Copyright © 2017, 2023 Arm Ltd and Contributors. All rights reserved.
 // SPDX-License-Identifier: MIT
 //
 #pragma once
@@ -18,7 +18,7 @@
 #include <arm_compute/core/TensorShape.h>
 #include <arm_compute/core/Coordinates.h>
 
-#include <cl/IClTensorHandle.hpp>
+#include <aclCommon/IClTensorHandle.hpp>
 
 namespace armnn
 {
diff --git a/src/backends/cl/test/CMakeLists.txt b/src/backends/cl/test/CMakeLists.txt
index ec1d0a6..6568d48 100644
--- a/src/backends/cl/test/CMakeLists.txt
+++ b/src/backends/cl/test/CMakeLists.txt
@@ -1,5 +1,5 @@
 #
-# Copyright © 2017 Arm Ltd. All rights reserved.
+# Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved.
 # SPDX-License-Identifier: MIT
 #
 
@@ -8,6 +8,7 @@
     ClContextControlFixture.hpp
     ClContextSerializerTests.cpp
     ClCustomAllocatorTests.cpp
+    ClDefaultAllocatorTests.cpp
     ClCreateWorkloadTests.cpp
     ClEndToEndTests.cpp
     ClImportTensorHandleFactoryTests.cpp
@@ -18,7 +19,6 @@
     ClOptimizedNetworkTests.cpp
     ClRuntimeTests.cpp
     ClWorkloadFactoryHelper.hpp
-    DefaultAllocatorTests.cpp
     Fp16SupportTest.cpp
     ICLTensorProxyTests.cpp
     OpenClTimerTest.cpp
diff --git a/src/backends/cl/test/DefaultAllocatorTests.cpp b/src/backends/cl/test/ClDefaultAllocatorTests.cpp
similarity index 98%
rename from src/backends/cl/test/DefaultAllocatorTests.cpp
rename to src/backends/cl/test/ClDefaultAllocatorTests.cpp
index eaa30c8..411a480 100644
--- a/src/backends/cl/test/DefaultAllocatorTests.cpp
+++ b/src/backends/cl/test/ClDefaultAllocatorTests.cpp
@@ -1,5 +1,5 @@
 //
-// Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
+// Copyright © 2021, 2023 Arm Ltd and Contributors. All rights reserved.
 // SPDX-License-Identifier: MIT
 //