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)23inline int ResolveMaxThreads(int max_threads) { 24 if (max_threads == 0) { 25 #ifdef _WIN32 26 SYSTEM_INFO sysinfo; 27 GetSystemInfo(&sysinfo); 28 return sysinfo.dwNumberOfProcessors; 29 #else 30 static const int hardware_threads_count = 31 static_cast<int>(sysconf(_SC_NPROCESSORS_CONF)); 32 return hardware_threads_count; 33 #endif 34 } 35 return max_threads; 36 } 37 38 template <typename WorkersPool> 39 class SimpleContext { 40 public: SimpleContext(int max_num_threads,WorkersPool * pool)41 SimpleContext(int max_num_threads, WorkersPool* pool) 42 : max_num_threads_(max_num_threads), pool_(pool) {} 43 workers_pool()44 WorkersPool* workers_pool() { return pool_; } 45 max_num_threads()46 int max_num_threads() { return max_num_threads_; } 47 48 private: 49 int max_num_threads_; 50 WorkersPool* pool_; 51 }; 52 53 } // namespace meta 54 } // namespace gemmlowp 55 56 #endif // GEMMLOWP_META_MULTI_THREAD_COMMON_H_ 57