arm_compute v17.06
diff --git a/src/runtime/CPP/CPPScheduler.cpp b/src/runtime/CPP/CPPScheduler.cpp
index 210dbb7..8869330 100644
--- a/src/runtime/CPP/CPPScheduler.cpp
+++ b/src/runtime/CPP/CPPScheduler.cpp
@@ -35,14 +35,6 @@
using namespace arm_compute;
-#ifdef NO_MULTI_THREADING
-namespace
-{
-void delete_threads(Thread *t)
-{
-}
-}
-#else /* NO_MULTI_THREADING */
class arm_compute::Thread
{
public:
@@ -162,7 +154,6 @@
delete[] t;
}
} // namespace
-#endif /* NO_MULTI_THREADING */
CPPScheduler &CPPScheduler::get()
{
@@ -170,49 +161,39 @@
return scheduler;
}
+unsigned int CPPScheduler::num_threads() const
+{
+ return _num_threads;
+}
+
CPPScheduler::CPPScheduler()
- : _num_threads(0), _threads(nullptr, delete_threads)
+ : _num_threads(std::thread::hardware_concurrency()),
+ _threads(std::unique_ptr<Thread[], void(*)(Thread *)>(new Thread[std::thread::hardware_concurrency() - 1], delete_threads))
{
- force_number_of_threads(0);
}
-void CPPScheduler::force_number_of_threads(int num_threads)
+void CPPScheduler::set_num_threads(unsigned int num_threads)
{
-#ifdef NO_MULTI_THREADING
- ARM_COMPUTE_ERROR_ON(num_threads > 1);
- _num_threads = 1;
-#else /* NO_MULTI_THREADING */
- _num_threads = num_threads > 0 ? num_threads : std::thread::hardware_concurrency();
- ARM_COMPUTE_ERROR_ON(_num_threads < 1);
-
- if(_num_threads > 1)
- {
- _threads = std::unique_ptr<Thread[], void (*)(Thread *)>(new Thread[_num_threads - 1], delete_threads);
- }
- else
- {
- _threads = nullptr;
- }
-#endif /* NO_MULTI_THREADING */
+ const unsigned int num_cores = std::thread::hardware_concurrency();
+ _num_threads = num_threads == 0 ? num_cores : num_threads;
}
-void CPPScheduler::multithread(ICPPKernel *kernel, const size_t split_dimension)
+void CPPScheduler::schedule(ICPPKernel *kernel, unsigned int split_dimension)
{
ARM_COMPUTE_ERROR_ON_MSG(!kernel, "The child class didn't set the kernel");
/** [Scheduler example] */
- const Window &max_window = kernel->window();
- const int num_iterations = max_window.num_iterations(split_dimension);
- int num_threads = std::min(num_iterations, _num_threads);
+ const Window &max_window = kernel->window();
+ const unsigned int num_iterations = max_window.num_iterations(split_dimension);
+ const unsigned int num_threads = std::min(num_iterations, _num_threads);
if(!kernel->is_parallelisable() || 1 == num_threads)
{
kernel->run(max_window);
}
-#ifndef NO_MULTI_THREADING
else
{
- for(int t = 0; t < num_threads; ++t)
+ for(unsigned int t = 0; t < num_threads; ++t)
{
Window win = max_window.split_window(split_dimension, t, num_threads);
win.set_thread_id(t);
@@ -230,7 +211,7 @@
try
{
- for(int t = 1; t < num_threads; ++t)
+ for(unsigned int t = 1; t < num_threads; ++t)
{
_threads[t - 1].wait();
}
@@ -240,6 +221,5 @@
std::cout << "Caught system_error with code " << e.code() << " meaning " << e.what() << '\n';
}
}
-#endif /* NO_MULTI_THREADING */
/** [Scheduler example] */
}
diff --git a/src/runtime/CPP/SingleThreadScheduler.cpp b/src/runtime/CPP/SingleThreadScheduler.cpp
new file mode 100644
index 0000000..f086813
--- /dev/null
+++ b/src/runtime/CPP/SingleThreadScheduler.cpp
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2017 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.
+ */
+#include "arm_compute/runtime/SingleThreadScheduler.h"
+
+#include "arm_compute/core/CPP/ICPPKernel.h"
+#include "arm_compute/core/Error.h"
+#include "arm_compute/core/Utils.h"
+
+using namespace arm_compute;
+
+SingleThreadScheduler &SingleThreadScheduler::get()
+{
+ static SingleThreadScheduler scheduler;
+ return scheduler;
+}
+
+void SingleThreadScheduler::set_num_threads(unsigned int num_threads)
+{
+ ARM_COMPUTE_UNUSED(num_threads);
+}
+
+void SingleThreadScheduler::schedule(ICPPKernel *kernel, unsigned int split_dimension)
+{
+ ARM_COMPUTE_UNUSED(split_dimension);
+ kernel->run(kernel->window());
+}
+
+unsigned int SingleThreadScheduler::num_threads() const
+{
+ return 1;
+}