aboutsummaryrefslogtreecommitdiff
path: root/arm_compute
diff options
context:
space:
mode:
authorGeorgios Pinitas <georgios.pinitas@arm.com>2019-07-25 13:31:10 +0100
committerGeorgios Pinitas <georgios.pinitas@arm.com>2019-09-09 11:22:01 +0000
commit12833d063259cb7809a97a4262f821efdc40554f (patch)
tree455333091c9eeba97079a385e0186f56076f5169 /arm_compute
parented0e35bfe15bad01387504afc15b8553e585bdb9 (diff)
downloadComputeLibrary-12833d063259cb7809a97a4262f821efdc40554f.tar.gz
COMPMID-2204: RuntimeContext interface for NEON functions.
This patch creates the interfaces for the runtime context for NEON. Only the Neon backend implements the context which currently only holds an instance of the scheduler. The NEActivationLayer function has been updated to use the new context interface and the corresponding validation tests ported. Change-Id: I32e7e6aa888796dcbbfc5039b1e7f784a24f47da Signed-off-by: Pablo Tello <pablo.tello@arm.com> Reviewed-on: https://review.mlplatform.org/c/1851 Comments-Addressed: Arm Jenkins <bsgcomp@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: Michele Di Giorgio <michele.digiorgio@arm.com>
Diffstat (limited to 'arm_compute')
-rw-r--r--arm_compute/runtime/CL/functions/CLActivationLayer.h15
-rw-r--r--arm_compute/runtime/CPP/CPPScheduler.h21
-rw-r--r--arm_compute/runtime/DeviceProperties.h41
-rw-r--r--arm_compute/runtime/GLES_COMPUTE/functions/GCActivationLayer.h17
-rw-r--r--arm_compute/runtime/IAssetManager.h40
-rw-r--r--arm_compute/runtime/IRuntimeContext.h61
-rw-r--r--arm_compute/runtime/NEON/INESimpleFunctionNoBorder.h19
-rw-r--r--arm_compute/runtime/NEON/functions/NEActivationLayer.h14
-rw-r--r--arm_compute/runtime/OMP/OMPScheduler.h16
-rw-r--r--arm_compute/runtime/RuntimeContext.h64
-rw-r--r--arm_compute/runtime/Scheduler.h8
-rw-r--r--arm_compute/runtime/SchedulerFactory.h58
-rw-r--r--arm_compute/runtime/SingleThreadScheduler.h17
-rw-r--r--arm_compute/runtime/Utils.h13
14 files changed, 361 insertions, 43 deletions
diff --git a/arm_compute/runtime/CL/functions/CLActivationLayer.h b/arm_compute/runtime/CL/functions/CLActivationLayer.h
index c10c5301c2..1201d7d355 100644
--- a/arm_compute/runtime/CL/functions/CLActivationLayer.h
+++ b/arm_compute/runtime/CL/functions/CLActivationLayer.h
@@ -39,6 +39,19 @@ class ICLTensor;
class CLActivationLayer : public ICLSimpleFunction
{
public:
+ /** Constructor
+ *
+ * @param[in] ctx Runtime context to be used by the function
+ */
+ CLActivationLayer(void *ctx = nullptr);
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ CLActivationLayer(const CLActivationLayer &) = delete;
+ /** Default move constructor */
+ CLActivationLayer(CLActivationLayer &&) = default;
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ CLActivationLayer &operator=(const CLActivationLayer &) = delete;
+ /** Default move assignment operator */
+ CLActivationLayer &operator=(CLActivationLayer &&) = default;
/** Set the input and output tensor.
*
* @note If the output tensor is a nullptr or is equal to the input, the activation function will be performed in-place
@@ -60,5 +73,5 @@ public:
*/
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const ActivationLayerInfo &act_info);
};
-}
+} // namespace arm_compute
#endif /* __ARM_COMPUTE_CLACTIVATIONLAYER_H__ */
diff --git a/arm_compute/runtime/CPP/CPPScheduler.h b/arm_compute/runtime/CPP/CPPScheduler.h
index 17ed8310a4..69cd25f994 100644
--- a/arm_compute/runtime/CPP/CPPScheduler.h
+++ b/arm_compute/runtime/CPP/CPPScheduler.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2018 ARM Limited.
+ * Copyright (c) 2016-2019 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -26,14 +26,18 @@
#include "arm_compute/runtime/IScheduler.h"
-#include <list>
+#include <memory>
namespace arm_compute
{
/** C++11 implementation of a pool of threads to automatically split a kernel's execution among several threads. */
-class CPPScheduler : public IScheduler
+class CPPScheduler final : public IScheduler
{
public:
+ /** Constructor: create a pool of threads. */
+ CPPScheduler();
+ /** Default destructor */
+ ~CPPScheduler();
/** Sets the number of threads the scheduler will use to run the kernels.
*
* @param[in] num_threads If set to 0, then the maximum number of threads supported by C++11 will be used, otherwise the number of threads specified.
@@ -47,6 +51,7 @@ public:
/** Access the scheduler singleton
*
+ * @note this method has been deprecated and will be remover in the upcoming releases
* @return The scheduler
*/
static CPPScheduler &get();
@@ -69,12 +74,8 @@ protected:
void run_workloads(std::vector<Workload> &workloads) override;
private:
- class Thread;
- /** Constructor: create a pool of threads. */
- CPPScheduler();
-
- unsigned int _num_threads;
- std::list<Thread> _threads;
+ struct Impl;
+ std::unique_ptr<Impl> _impl;
};
-}
+} // namespace arm_compute
#endif /* __ARM_COMPUTE_CPPSCHEDULER_H__ */
diff --git a/arm_compute/runtime/DeviceProperties.h b/arm_compute/runtime/DeviceProperties.h
new file mode 100644
index 0000000000..b411124a04
--- /dev/null
+++ b/arm_compute/runtime/DeviceProperties.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2019 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_DEVICE_PROPERTIES_H__
+#define __ARM_COMPUTE_DEVICE_PROPERTIES_H__
+
+#include "arm_compute/core/CPP/CPPTypes.h"
+
+namespace arm_compute
+{
+/** Device properties */
+struct DeviceProperties
+{
+ std::string name{ "unknown" };
+ CPUInfo cpu_info{}; // initialised upon creating in the constructor
+
+ DeviceProperties();
+};
+
+} // namespace arm_compute
+#endif /*__ARM_COMPUTE_DEVICE_PROPERTIES_H__ */
diff --git a/arm_compute/runtime/GLES_COMPUTE/functions/GCActivationLayer.h b/arm_compute/runtime/GLES_COMPUTE/functions/GCActivationLayer.h
index b43456b2cd..5e0effe902 100644
--- a/arm_compute/runtime/GLES_COMPUTE/functions/GCActivationLayer.h
+++ b/arm_compute/runtime/GLES_COMPUTE/functions/GCActivationLayer.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 ARM Limited.
+ * Copyright (c) 2017-2019 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -38,6 +38,19 @@ class IGCTensor;
class GCActivationLayer : public IGCSimpleFunction
{
public:
+ /** Constructor
+ *
+ * @param[in] ctx Runtime context to be used by the function
+ */
+ GCActivationLayer(void *ctx = nullptr);
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ GCActivationLayer(const GCActivationLayer &) = delete;
+ /** Default move constructor */
+ GCActivationLayer(GCActivationLayer &&) = default;
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ GCActivationLayer &operator=(const GCActivationLayer &) = delete;
+ /** Default move assignment operator */
+ GCActivationLayer &operator=(GCActivationLayer &&) = default;
/** Set the input and output tensor.
*
* @note If the output tensor is a nullptr, the activation function will be performed in-place
@@ -49,5 +62,5 @@ public:
*/
void configure(IGCTensor *input, IGCTensor *output, ActivationLayerInfo act_info);
};
-}
+} // namespace arm_compute
#endif /* __ARM_COMPUTE_GCACTIVATIONLAYER_H__ */
diff --git a/arm_compute/runtime/IAssetManager.h b/arm_compute/runtime/IAssetManager.h
new file mode 100644
index 0000000000..d6f501a9e0
--- /dev/null
+++ b/arm_compute/runtime/IAssetManager.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2019 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_IASSET_MANAGER_H__
+#define __ARM_COMPUTE_IASSET_MANAGER_H__
+
+namespace arm_compute
+{
+/** Asset manager interface */
+class IAssetManager
+{
+public:
+ /** Memory manager accessor
+ *
+ * @return Memory manager
+ */
+ virtual IMemoryManager *memory_manager() = 0;
+};
+} // namespace arm_compute
+#endif /*__ARM_COMPUTE_IASSET_MANAGER_H__ */
diff --git a/arm_compute/runtime/IRuntimeContext.h b/arm_compute/runtime/IRuntimeContext.h
new file mode 100644
index 0000000000..f928085682
--- /dev/null
+++ b/arm_compute/runtime/IRuntimeContext.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2019 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_IRUNTIME_CONTEXT_H__
+#define __ARM_COMPUTE_IRUNTIME_CONTEXT_H__
+
+namespace arm_compute
+{
+// Forward declarations
+class IScheduler;
+class IAssetManager;
+class DeviceProperties;
+
+/** Context interface */
+class IRuntimeContext
+{
+public:
+ /** Destructor */
+ virtual ~IRuntimeContext() = default;
+ /** Scheduler accessor
+ *
+ * @note Scheduler is used to schedule workloads
+ *
+ * @return The scheduler registered to the context
+ */
+ virtual IScheduler *scheduler() = 0;
+ /** Asset manager accessor
+ *
+ * @note Asset manager is used to manage objects/tensors within functions
+ *
+ * @return The asset manager registered to the context
+ */
+ virtual IAssetManager *asset_manager() = 0;
+ /** Device propertied accessor
+ *
+ * @return Device properties
+ */
+ virtual const DeviceProperties &properties() = 0;
+};
+} // namespace arm_compute
+#endif /*__ARM_COMPUTE_IRUNTIME_CONTEXT_H__ */
diff --git a/arm_compute/runtime/NEON/INESimpleFunctionNoBorder.h b/arm_compute/runtime/NEON/INESimpleFunctionNoBorder.h
index 6765b5f937..d0c3a9beb5 100644
--- a/arm_compute/runtime/NEON/INESimpleFunctionNoBorder.h
+++ b/arm_compute/runtime/NEON/INESimpleFunctionNoBorder.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018 ARM Limited.
+ * Copyright (c) 2018-2019 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -26,6 +26,7 @@
#include "arm_compute/core/NEON/INEKernel.h"
#include "arm_compute/runtime/IFunction.h"
+#include "arm_compute/runtime/IRuntimeContext.h"
#include <memory>
@@ -35,14 +36,26 @@ namespace arm_compute
class INESimpleFunctionNoBorder : public IFunction
{
public:
- /** Constructor */
- INESimpleFunctionNoBorder();
+ /** Constructor
+ *
+ * @param[in] ctx Runtime context to be used by the function
+ */
+ INESimpleFunctionNoBorder(IRuntimeContext *ctx = nullptr);
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ INESimpleFunctionNoBorder(const INESimpleFunctionNoBorder &) = delete;
+ /** Default move constructor */
+ INESimpleFunctionNoBorder(INESimpleFunctionNoBorder &&) = default;
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ INESimpleFunctionNoBorder &operator=(const INESimpleFunctionNoBorder &) = delete;
+ /** Default move assignment operator */
+ INESimpleFunctionNoBorder &operator=(INESimpleFunctionNoBorder &&) = default;
// Inherited methods overridden:
void run() override final;
protected:
std::unique_ptr<INEKernel> _kernel; /**< Kernel to run */
+ IRuntimeContext *_ctx; /**< Context to use */
};
} // namespace arm_compute
#endif /*__ARM_COMPUTE_INESIMPLEFUNCTIONNOBORDER_H__ */
diff --git a/arm_compute/runtime/NEON/functions/NEActivationLayer.h b/arm_compute/runtime/NEON/functions/NEActivationLayer.h
index c0b5f7ab37..d383da4f32 100644
--- a/arm_compute/runtime/NEON/functions/NEActivationLayer.h
+++ b/arm_compute/runtime/NEON/functions/NEActivationLayer.h
@@ -30,6 +30,7 @@
namespace arm_compute
{
+// Forward declarations
class ITensor;
/** Basic function to run @ref NEActivationLayerKernel
@@ -39,6 +40,19 @@ class ITensor;
class NEActivationLayer : public INESimpleFunctionNoBorder
{
public:
+ /** Constructor
+ *
+ * @param[in] ctx Runtime context to be used by the function
+ */
+ NEActivationLayer(IRuntimeContext *ctx = nullptr);
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ NEActivationLayer(const NEActivationLayer &) = delete;
+ /** Default move constructor */
+ NEActivationLayer(NEActivationLayer &&) = default;
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ NEActivationLayer &operator=(const NEActivationLayer &) = delete;
+ /** Default move assignment operator */
+ NEActivationLayer &operator=(NEActivationLayer &&) = default;
/** Set the input and output tensor.
*
* @note If the output tensor is a nullptr or is equal to the input, the activation function will be performed in-place
diff --git a/arm_compute/runtime/OMP/OMPScheduler.h b/arm_compute/runtime/OMP/OMPScheduler.h
index ff9bf052fd..5934ee1c12 100644
--- a/arm_compute/runtime/OMP/OMPScheduler.h
+++ b/arm_compute/runtime/OMP/OMPScheduler.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2018 ARM Limited.
+ * Copyright (c) 2017-2019 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -29,9 +29,11 @@
namespace arm_compute
{
/** Pool of threads to automatically split a kernel's execution among several threads. */
-class OMPScheduler : public IScheduler
+class OMPScheduler final : public IScheduler
{
public:
+ /** Constructor. */
+ OMPScheduler();
/** Sets the number of threads the scheduler will use to run the kernels.
*
* @param[in] num_threads If set to 0, then the number returned by omp_get_max_threads() will be used, otherwise the number of threads specified.
@@ -42,11 +44,6 @@ public:
* @return Number of threads available in OMPScheduler.
*/
unsigned int num_threads() const override;
- /** Access the scheduler singleton
- *
- * @return The scheduler
- */
- static OMPScheduler &get();
/** Multithread the execution of the passed kernel if possible.
*
* The kernel will run on a single thread if any of these conditions is true:
@@ -68,10 +65,7 @@ protected:
void run_workloads(std::vector<Workload> &workloads) override;
private:
- /** Constructor. */
- OMPScheduler();
-
unsigned int _num_threads;
};
-}
+} // namespace arm_compute
#endif /* __ARM_COMPUTE_OMPSCHEDULER_H__ */
diff --git a/arm_compute/runtime/RuntimeContext.h b/arm_compute/runtime/RuntimeContext.h
new file mode 100644
index 0000000000..564ba78e63
--- /dev/null
+++ b/arm_compute/runtime/RuntimeContext.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2019 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_RUNTIME_CONTEXT_H__
+#define __ARM_COMPUTE_RUNTIME_CONTEXT_H__
+
+#include "arm_compute/runtime/DeviceProperties.h"
+#include "arm_compute/runtime/IRuntimeContext.h"
+
+#include <memory>
+
+namespace arm_compute
+{
+/** Runtime context */
+class RuntimeContext : public IRuntimeContext
+{
+public:
+ /** Default Constructor */
+ RuntimeContext();
+ /** Destructor */
+ ~RuntimeContext() = default;
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ RuntimeContext(const RuntimeContext &) = delete;
+ /** Default move constructor */
+ RuntimeContext(RuntimeContext &&) = default;
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ RuntimeContext &operator=(const RuntimeContext &) = delete;
+ /** Default move assignment operator */
+ RuntimeContext &operator=(RuntimeContext &&) = default;
+ /** CPU Scheduler setter */
+ void set_scheduler(IScheduler *scheduler);
+
+ // Inherited overridden methods
+ IScheduler *scheduler() override;
+ IAssetManager *asset_manager() override;
+ const DeviceProperties &properties() override;
+
+private:
+ std::unique_ptr<IScheduler> _owned_scheduler{ nullptr };
+ IScheduler *_scheduler{ nullptr };
+ DeviceProperties _device_props{};
+};
+} // namespace arm_compute
+#endif /*__ARM_COMPUTE_RUNTIME_CONTEXT_H__ */
diff --git a/arm_compute/runtime/Scheduler.h b/arm_compute/runtime/Scheduler.h
index 7e10461b5a..89263fd176 100644
--- a/arm_compute/runtime/Scheduler.h
+++ b/arm_compute/runtime/Scheduler.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2018 ARM Limited.
+ * Copyright (c) 2017-2019 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -25,6 +25,8 @@
#define __ARM_COMPUTE_SCHEDULER_H__
#include "arm_compute/runtime/IScheduler.h"
+
+#include <map>
#include <memory>
namespace arm_compute
@@ -74,7 +76,9 @@ public:
private:
static Type _scheduler_type;
static std::shared_ptr<IScheduler> _custom_scheduler;
+ static std::map<Type, std::unique_ptr<IScheduler>> _schedulers;
+
Scheduler();
};
-}
+} // namespace arm_compute
#endif /* __ARM_COMPUTE_SCHEDULER_H__ */
diff --git a/arm_compute/runtime/SchedulerFactory.h b/arm_compute/runtime/SchedulerFactory.h
new file mode 100644
index 0000000000..3e35655a19
--- /dev/null
+++ b/arm_compute/runtime/SchedulerFactory.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2019 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_SCHEDULER_FACTORY_H__
+#define __ARM_COMPUTE_SCHEDULER_FACTORY_H__
+
+#include "arm_compute/runtime/IScheduler.h"
+
+#include <memory>
+
+namespace arm_compute
+{
+/** Scheduler Factory */
+class SchedulerFactory
+{
+public:
+ /** Scheduler type */
+ enum class Type
+ {
+ ST, /**< Single thread. */
+ CPP, /**< C++11 threads. */
+ OMP, /**< OpenMP. */
+ };
+
+public:
+ /** Create a scheduler depending on the scheduler type
+ *
+ * @param[in] type Type of scheduler to create
+ *
+ * @return Scheduler
+ */
+ static std::unique_ptr<IScheduler> create(Type type = _default_type);
+
+private:
+ static const Type _default_type;
+};
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_SCHEDULER_H__ */
diff --git a/arm_compute/runtime/SingleThreadScheduler.h b/arm_compute/runtime/SingleThreadScheduler.h
index 7c084efeaf..9ea0f0818e 100644
--- a/arm_compute/runtime/SingleThreadScheduler.h
+++ b/arm_compute/runtime/SingleThreadScheduler.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2018 ARM Limited.
+ * Copyright (c) 2017-2019 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -29,9 +29,11 @@
namespace arm_compute
{
/** Pool of threads to automatically split a kernel's execution among several threads. */
-class SingleThreadScheduler : public IScheduler
+class SingleThreadScheduler final : public IScheduler
{
public:
+ /** Constructor. */
+ SingleThreadScheduler() = default;
/** Sets the number of threads the scheduler will use to run the kernels.
*
* @param[in] num_threads This is ignored for this scheduler as the number of threads is always one.
@@ -42,11 +44,6 @@ public:
* @return Number of threads available in SingleThreadScheduler.
*/
unsigned int num_threads() const override;
- /** Access the scheduler singleton
- *
- * @return The scheduler
- */
- static SingleThreadScheduler &get();
/** Runs the kernel in the same thread as the caller synchronously.
*
* @param[in] kernel Kernel to execute.
@@ -60,10 +57,6 @@ protected:
* @param[in] workloads Workloads to run
*/
void run_workloads(std::vector<Workload> &workloads) override;
-
-private:
- /** Constructor. */
- SingleThreadScheduler() = default;
};
-}
+} // namespace arm_compute
#endif /* __ARM_COMPUTE_SINGLETHREADSCHEDULER_H__ */
diff --git a/arm_compute/runtime/Utils.h b/arm_compute/runtime/Utils.h
index 2f037a0621..15c0042a33 100644
--- a/arm_compute/runtime/Utils.h
+++ b/arm_compute/runtime/Utils.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 ARM Limited.
+ * Copyright (c) 2017-2019 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -24,6 +24,7 @@
#ifndef __ARM_COMPUTE_RUNTIME_UTILS_H__
#define __ARM_COMPUTE_RUNTIME_UTILS_H__
+#include "arm_compute/runtime/IRuntimeContext.h"
#include "arm_compute/runtime/Scheduler.h"
#include <string>
@@ -37,5 +38,13 @@ namespace arm_compute
* @return The string describing the scheduler type.
*/
const std::string &string_from_scheduler_type(Scheduler::Type t);
-}
+
+/** Schedules a kernel using the context if not nullptr else uses the legacy scheduling flow.
+ *
+ * @param[in] ctx Context to use.
+ * @param[in] kernel Kernel to schedule.
+ * @param[in] hints Hints to use.
+ */
+void schedule_kernel_on_ctx(IRuntimeContext *ctx, ICPPKernel *kernel, const IScheduler::Hints &hints);
+} // namespace arm_compute
#endif /* __ARM_COMPUTE_RUNTIME_UTILS_H__ */