Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
99 | pmbaty | 1 | /* |
2 | Texel - A UCI chess engine. |
||
3 | Copyright (C) 2014 Peter Ă–sterlund, peterosterlund2@gmail.com |
||
4 | |||
5 | This program is free software: you can redistribute it and/or modify |
||
6 | it under the terms of the GNU General Public License as published by |
||
7 | the Free Software Foundation, either version 3 of the License, or |
||
8 | (at your option) any later version. |
||
9 | |||
10 | This program is distributed in the hope that it will be useful, |
||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
13 | GNU General Public License for more details. |
||
14 | |||
15 | You should have received a copy of the GNU General Public License |
||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
17 | */ |
||
18 | |||
19 | /* |
||
20 | * numa.hpp |
||
21 | * |
||
22 | * Created on: Jul 24, 2014 |
||
23 | * Author: petero |
||
24 | */ |
||
25 | |||
26 | #ifndef NUMA_HPP_ |
||
27 | #define NUMA_HPP_ |
||
28 | |||
29 | #include <vector> |
||
30 | |||
31 | |||
32 | /** Bind search threads to suitable NUMA nodes. */ |
||
33 | class Numa { |
||
34 | public: |
||
35 | /** Get singleton instance. */ |
||
36 | static Numa& instance(); |
||
37 | |||
38 | /** Disable NUMA awareness. Useful when running several single-threaded |
||
39 | * test games simultaneously on NUMA hardware. */ |
||
40 | void disable(); |
||
41 | |||
42 | /** Preferred node for a given search thread. */ |
||
43 | int nodeForThread(int threadNo) const; |
||
44 | |||
45 | /** Bind current thread to NUMA node determined by nodeForThread(). */ |
||
46 | void bindThread(int threadNo) const; |
||
47 | |||
48 | /** Return true if threadNo runs on the same NUMA node as thread 0. */ |
||
49 | bool isMainNode(int threadNo) const; |
||
50 | |||
51 | private: |
||
52 | Numa(); |
||
53 | |||
54 | /** Thread number to node number. */ |
||
55 | std::vector<int> threadToNode; |
||
56 | |||
57 | struct NodeInfo { |
||
58 | explicit NodeInfo(int n = 0, int c = 0, int t = 0); |
||
59 | int node; |
||
60 | int numCores; |
||
61 | int numThreads; |
||
62 | }; |
||
63 | }; |
||
64 | |||
65 | inline |
||
66 | Numa::NodeInfo::NodeInfo(int n, int c, int t) |
||
67 | : node(n), numCores(c), numThreads(t) { |
||
68 | } |
||
69 | |||
70 | #endif /* NUMA_HPP_ */ |