• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The Gemmlowp Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef GEMMLOWP_META_MULTI_THREAD_COMMON_H_
16 #define GEMMLOWP_META_MULTI_THREAD_COMMON_H_
17 
18 #include "../internal/multi_thread_gemm.h"
19 
20 namespace gemmlowp {
21 namespace meta {
22 
ResolveMaxThreads(int max_threads)23 inline int ResolveMaxThreads(int max_threads) {
24   if (max_threads == 0) {
25     static const int hardware_threads_count =
26         static_cast<int>(sysconf(_SC_NPROCESSORS_CONF));
27     return hardware_threads_count;
28   }
29   return max_threads;
30 }
31 
32 template <typename WorkersPool>
33 class SimpleContext {
34  public:
SimpleContext(int max_num_threads,WorkersPool * pool)35   SimpleContext(int max_num_threads, WorkersPool* pool)
36       : max_num_threads_(max_num_threads), pool_(pool) {}
37 
workers_pool()38   WorkersPool* workers_pool() { return pool_; }
39 
max_num_threads()40   int max_num_threads() { return max_num_threads_; }
41 
42  private:
43   int max_num_threads_;
44   WorkersPool* pool_;
45 };
46 
47 }  // namespace meta
48 }  // namespace gemmlowp
49 
50 #endif  // GEMMLOWP_META_MULTI_THREAD_COMMON_H_
51