Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / src / mkldnn_plugin / mkldnn / os / lin / lin_omp_manager.h
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #pragma once
6
7 #include <sched.h>
8 #include <cstdio>
9 #include <cstdlib>
10 #include <cstring>
11 #include <set>
12 #include <vector>
13
14 namespace MKLDNNPlugin {
15 namespace cpu {
16
17 #ifndef __APPLE__
18
19 struct Processor {
20     unsigned processor;
21     unsigned physicalId;
22     unsigned cpuCores;
23
24     Processor();
25 };
26
27 class CpuInfoInterface {
28 public:
29     virtual ~CpuInfoInterface() {}
30
31     virtual const char *getFirstLine() = 0;
32
33     virtual const char *getNextLine() = 0;
34 };
35
36 class CpuInfo : public CpuInfoInterface {
37 public:
38     CpuInfo();
39
40     virtual ~CpuInfo();
41
42     virtual const char *getFirstLine();
43
44     virtual const char *getNextLine();
45
46 private:
47     const char *fileContentBegin;
48     const char *fileContentEnd;
49     const char *currentLine;
50
51     void loadContentFromFile(const char *fileName);
52
53     void loadContent(const char *content);
54
55     void parseLines(char *content);
56 };
57
58 class CollectionInterface {
59 public:
60     virtual ~CollectionInterface() {}
61     virtual unsigned getTotalNumberOfSockets() = 0;
62 };
63
64 class Collection : public CollectionInterface {
65 public:
66     explicit Collection(CpuInfoInterface *cpuInfo);
67
68     virtual unsigned getTotalNumberOfSockets();
69     virtual unsigned getTotalNumberOfCpuCores();
70     virtual unsigned getNumberOfProcessors();
71
72 private:
73     CpuInfoInterface &cpuInfo;
74     unsigned totalNumberOfSockets;
75     unsigned totalNumberOfCpuCores;
76     std::vector<Processor> processors;
77     Processor *currentProcessor;
78
79     Collection(const Collection &collection);
80
81     Collection &operator=(const Collection &collection);
82
83     void parseCpuInfo();
84
85     void parseCpuInfoLine(const char *cpuInfoLine);
86
87     void parseValue(const char *fieldName, const char *valueString);
88
89     void appendNewProcessor();
90
91     bool beginsWith(const char *lineBuffer, const char *text) const;
92
93     unsigned parseInteger(const char *text) const;
94
95     void collectBasicCpuInformation();
96
97     void updateCpuInformation(const Processor &processor,
98                               unsigned numberOfUniquePhysicalId);
99 };
100 #endif  // #ifndef __APPLE__
101 }  // namespace cpu
102 }  // namespace MKLDNNPlugin