Line data Source code
1 : // SPDX-License-Identifier: Apache-2.0
2 : /**
3 : * Copyright (C) 2025 Sungsik Kong <ss.kong@samsung.com>
4 : *
5 : * @file bs_threadpool_manager.cpp
6 : * @date 20 May 2025
7 : * @see https://github.com/nnstreamer/nntrainer
8 : * @author Sungsik Kong <ss.kong@samsung.com>
9 : * @bug No known bugs except for NYI items
10 : * @brief BS threadpool manager class source file
11 : */
12 :
13 : #ifndef THREAD_POOL_MANAGER_CPP
14 : #define THREAD_POOL_MANAGER_CPP
15 :
16 : #include "bs_thread_pool_manager.hpp"
17 : #include <algorithm>
18 : #include <cmath>
19 : namespace nntrainer {
20 : /**
21 : * @brief Instantiate thread pool with the number of hardware concurrency.
22 : *
23 : * @return BS::thread_pool<>
24 : */
25 :
26 0 : std::size_t ThreadPoolManager::select_k_quant_thread_count(unsigned int M,
27 : unsigned int N,
28 : unsigned int K) {
29 0 : const std::size_t max_threads = std::thread::hardware_concurrency();
30 :
31 0 : const std::size_t work_size = static_cast<std::size_t>(M * N * K);
32 : std::size_t est_threads;
33 :
34 : // Use log-scale thresholds to reduce threads on smaller work sizes
35 0 : if (work_size < 1536 * 1536)
36 : est_threads = 1;
37 0 : if (work_size < 1536 * 2048)
38 0 : est_threads = 2;
39 0 : if (work_size < 2048 * 2048)
40 0 : est_threads = 4;
41 : else {
42 0 : est_threads =
43 0 : static_cast<std::size_t>(std::log2(work_size / (1536 * 1536))) + 4;
44 : }
45 0 : return std::min(est_threads, max_threads);
46 : }
47 :
48 : } // namespace nntrainer
49 :
50 : #endif // THREAD_POOL_MANAGER_CPP
|