Skip to content

Commit fcb9c9d

Browse files
CPU reservation is false on mac (#28544)
### Details: - *CPU reservation is false on mac* ### Tickets: - *ticket-id* --------- Co-authored-by: Wanglei Shen <wanglei.shen@intel.com>
1 parent 7054e90 commit fcb9c9d

File tree

11 files changed

+466
-60
lines changed

11 files changed

+466
-60
lines changed

src/inference/dev_api/openvino/runtime/system_conf.hpp

-7
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,6 @@ OPENVINO_RUNTIME_API bool with_cpu_x86_avx512_core_amx_fp16();
174174
*/
175175
OPENVINO_RUNTIME_API bool with_cpu_x86_avx512_core_amx();
176176

177-
/**
178-
* @brief Checks whether cpu_mapping Available
179-
* @ingroup ov_dev_api_system_conf
180-
* @return `True` is CPU mapping is available, `false` otherwise
181-
*/
182-
OPENVINO_RUNTIME_API bool is_cpu_map_available();
183-
184177
/**
185178
* @brief Get number of numa nodes
186179
* @ingroup ov_dev_api_system_conf

src/inference/src/dev/threading/cpu_streams_executor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ struct CPUStreamsExecutor::Impl {
6767
_impl->_usedNumaNodes.size()))
6868
: _impl->_usedNumaNodes.at(_streamId % _impl->_usedNumaNodes.size());
6969
#if OV_THREAD == OV_THREAD_TBB || OV_THREAD == OV_THREAD_TBB_AUTO
70-
if (is_cpu_map_available() && _impl->_config.get_streams_info_table().size() > 0) {
70+
if (_impl->_config.get_streams_info_table().size() > 0) {
7171
init_stream();
7272
}
7373
#elif OV_THREAD == OV_THREAD_OMP

src/inference/src/system_conf.cpp

+2-13
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,6 @@ std::vector<std::vector<int>> get_proc_type_table() {
271271
std::vector<std::vector<int>> get_org_proc_type_table() {
272272
return {{-1}};
273273
}
274-
bool is_cpu_map_available() {
275-
return false;
276-
}
277274
int get_num_numa_nodes() {
278275
return -1;
279276
}
@@ -313,11 +310,6 @@ int get_number_of_blocked_cores() {
313310
return cpu._blocked_cores;
314311
}
315312

316-
bool is_cpu_map_available() {
317-
CPU& cpu = cpu_info();
318-
return cpu._proc_type_table.size() > 0;
319-
}
320-
321313
int get_current_socket_id() {
322314
return 0;
323315
}
@@ -393,6 +385,7 @@ std::vector<int> get_available_numa_nodes() {
393385
return nodes;
394386
}
395387
# endif
388+
396389
int get_current_socket_id() {
397390
CPU& cpu = cpu_info();
398391
int cur_processor_id = sched_getcpu();
@@ -419,6 +412,7 @@ int get_current_numa_node_id() {
419412
return 0;
420413
}
421414
# else
415+
422416
int get_current_socket_id() {
423417
CPU& cpu = cpu_info();
424418
int cur_processor_id = GetCurrentProcessorNumber();
@@ -457,11 +451,6 @@ std::vector<std::vector<int>> get_org_proc_type_table() {
457451
return cpu._org_proc_type_table;
458452
}
459453

460-
bool is_cpu_map_available() {
461-
CPU& cpu = cpu_info();
462-
return cpu._cpu_mapping_table.size() > 0;
463-
}
464-
465454
int get_num_numa_nodes() {
466455
return cpu_info()._numa_nodes;
467456
}

src/plugins/intel_cpu/src/config.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <string>
1010

1111
#include "cpu/x64/cpu_isa_traits.hpp"
12+
#include "cpu_map_scheduling.hpp"
1213
#include "openvino/core/parallel.hpp"
1314
#include "openvino/core/type/element_type_traits.hpp"
1415
#include "openvino/runtime/intel_cpu/properties.hpp"
@@ -117,7 +118,11 @@ void Config::readProperties(const ov::AnyMap& prop, const ModelType modelType) {
117118
}
118119
} else if (key == ov::hint::enable_cpu_reservation.name()) {
119120
try {
121+
#if defined(__APPLE__)
122+
enableCpuReservation = false;
123+
#else
120124
enableCpuReservation = val.as<bool>();
125+
#endif
121126
} catch (ov::Exception&) {
122127
OPENVINO_THROW("Wrong value ",
123128
val.as<std::string>(),

src/plugins/intel_cpu/src/cpu_map_scheduling.cpp

+17-14
Original file line numberDiff line numberDiff line change
@@ -69,39 +69,42 @@ std::vector<std::vector<int>> apply_hyper_threading(bool& input_ht_hint,
6969
return result_table;
7070
}
7171

72-
bool get_cpu_pinning(bool& input_value,
73-
const bool input_changed,
74-
const bool cpu_reservation,
75-
const std::vector<std::vector<int>>& proc_type_table,
76-
const std::vector<std::vector<int>>& streams_info_table) {
72+
bool check_cpu_pinning(const bool cpu_pinning,
73+
const bool cpu_pinning_changed,
74+
const bool cpu_reservation,
75+
const std::vector<std::vector<int>>& streams_info_table) {
7776
bool result_value;
7877

7978
#if defined(__APPLE__)
8079
result_value = false;
8180
#elif defined(_WIN32)
81+
auto proc_type_table = get_proc_type_table();
8282
if (proc_type_table.size() == 1) {
83-
result_value = input_changed ? input_value : cpu_reservation;
83+
result_value = cpu_pinning_changed ? cpu_pinning : cpu_reservation;
8484
} else {
8585
result_value = false;
8686
}
8787
#else
88-
if (input_changed) {
89-
result_value = input_value;
90-
} else {
91-
result_value = true;
92-
// The following code disables pinning in case stream contains both Pcore and Ecore
88+
// The following code disables pinning in case stream contains both Pcore and Ecore
89+
auto hyper_cores_in_stream = [&]() {
9390
if (streams_info_table.size() >= 3) {
9491
if ((streams_info_table[0][PROC_TYPE] == ALL_PROC) &&
9592
(streams_info_table[1][PROC_TYPE] != EFFICIENT_CORE_PROC) &&
9693
(streams_info_table[2][PROC_TYPE] == EFFICIENT_CORE_PROC)) {
97-
result_value = cpu_reservation;
94+
return true;
9895
}
9996
}
97+
return false;
98+
};
99+
100+
result_value = cpu_pinning_changed ? cpu_pinning : true;
101+
if (!cpu_pinning_changed && !cpu_reservation) {
102+
if (hyper_cores_in_stream()) {
103+
result_value = false;
104+
}
100105
}
101106
#endif
102107

103-
input_value = result_value;
104-
105108
return result_value;
106109
}
107110

src/plugins/intel_cpu/src/cpu_map_scheduling.hpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,17 @@ std::vector<std::vector<int>> apply_hyper_threading(bool& input_ht_hint,
4040
const std::vector<std::vector<int>>& proc_type_table);
4141

4242
/**
43-
* @brief whether pinning cpu cores according to enableCpuPinning property
44-
* @param[in] input_type indicate value of property enableCpuPinning.
45-
* @param[in] input_changed indicate if value is set by user.
46-
* @param[in] cpu_reservation indicate if cpu need to be reserved
47-
* @param[in] proc_type_table indicate processors information of this platform
43+
* @brief Check enableCpuPinning in different platform
44+
* @param[in] cpu_pinning the property enableCpuPinning set by user.
45+
* @param[in] cpu_pinning_changed the property changedCpuPinning which value depends on whether user sets
46+
* enableCpuPinning. true: user sets property enableCpuPinning. false: user does not set property enableCpuPinning.
47+
* @param[in] cpu_reservation the property enableCpuReservation set by user. False by default
4848
* @param[in] streams_info_table indicate streams detail of this model
4949
* @return whether pinning threads to cpu cores
5050
*/
51-
bool get_cpu_pinning(bool& input_value,
52-
const bool input_changed,
53-
const bool cpu_reservation,
54-
const std::vector<std::vector<int>>& proc_type_table,
55-
const std::vector<std::vector<int>>& streams_info_table);
51+
bool check_cpu_pinning(const bool cpu_pinning,
52+
const bool cpu_pinning_changed,
53+
const bool cpu_reservation,
54+
const std::vector<std::vector<int>>& streams_info_table);
5655

5756
} // namespace ov::intel_cpu

src/plugins/intel_cpu/src/cpu_streams_calculation.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -729,18 +729,17 @@ std::vector<std::vector<int>> generate_stream_info(const int streams,
729729
get_streams_rank_table(streams_info_table, config.streamsRankLevel, config.numSubStreams);
730730
}
731731

732-
auto cpu_pinning = get_cpu_pinning(config.enableCpuPinning,
733-
config.changedCpuPinning,
734-
config.enableCpuReservation,
735-
proc_type_table,
736-
streams_info_table);
732+
config.enableCpuPinning = check_cpu_pinning(config.enableCpuPinning,
733+
config.changedCpuPinning,
734+
config.enableCpuReservation,
735+
streams_info_table);
737736

738737
config.streamExecutorConfig = IStreamsExecutor::Config{"CPUStreamsExecutor",
739738
config.streams,
740739
config.threadsPerStream,
741740
ov::hint::SchedulingCoreType::ANY_CORE,
742741
config.enableCpuReservation,
743-
cpu_pinning,
742+
config.enableCpuPinning,
744743
true,
745744
std::move(streams_info_table),
746745
{},

src/plugins/intel_cpu/tests/functional/custom/behavior/ov_executable_network/properties.cpp

+45
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
#include "openvino/runtime/system_conf.hpp"
1313
#include "utils/properties_test.hpp"
1414

15+
#if defined(_WIN32)
16+
# include <windows.h>
17+
#endif
18+
1519
namespace {
1620

1721
TEST_F(OVClassConfigTestCPU, smoke_CpuExecNetworkSupportedPropertiesAreAvailable) {
@@ -159,6 +163,47 @@ TEST_F(OVClassConfigTestCPU, smoke_CpuExecNetworkCheckModelZeroStreams) {
159163
ASSERT_EQ(streams, value);
160164
}
161165

166+
TEST_F(OVClassConfigTestCPU, smoke_CpuExecNetworkCheckCpuReservation) {
167+
ov::Core ie;
168+
int32_t threads = 1;
169+
int32_t res_threads = -1;
170+
bool cpu_reservation = true;
171+
bool res_cpu_reservation = false;
172+
bool cpu_pinning = false;
173+
bool res_cpu_pinning = false;
174+
175+
#if defined(__APPLE__)
176+
cpu_reservation = false;
177+
cpu_pinning = false;
178+
#elif defined(__linux__)
179+
cpu_pinning = true;
180+
#elif defined(_WIN32)
181+
ULONG highestNodeNumber = 0;
182+
if (!GetNumaHighestNodeNumber(&highestNodeNumber)) {
183+
std::cout << "Error getting highest NUMA node number: " << GetLastError() << std::endl;
184+
return;
185+
}
186+
if (highestNodeNumber > 0) {
187+
cpu_pinning = false;
188+
} else {
189+
cpu_pinning = true;
190+
}
191+
#endif
192+
193+
OV_ASSERT_NO_THROW(ie.set_property(deviceName, ov::hint::performance_mode(ov::hint::PerformanceMode::LATENCY)));
194+
195+
ov::AnyMap config = {{ov::inference_num_threads.name(), threads}, {ov::hint::enable_cpu_reservation.name(), true}};
196+
ov::CompiledModel compiledModel = ie.compile_model(model, deviceName, config);
197+
198+
OV_ASSERT_NO_THROW(res_threads = compiledModel.get_property(ov::inference_num_threads));
199+
OV_ASSERT_NO_THROW(res_cpu_reservation = compiledModel.get_property(ov::hint::enable_cpu_reservation));
200+
OV_ASSERT_NO_THROW(res_cpu_pinning = compiledModel.get_property(ov::hint::enable_cpu_pinning));
201+
202+
ASSERT_EQ(res_threads, threads);
203+
ASSERT_EQ(res_cpu_reservation, cpu_reservation);
204+
ASSERT_EQ(res_cpu_pinning, cpu_pinning);
205+
}
206+
162207
TEST_F(OVClassConfigTestCPU, smoke_CpuExecNetworkCheckSparseWeigthsDecompressionRate) {
163208
ov::Core core;
164209

src/plugins/intel_cpu/tests/functional/shared_tests_instances/behavior/compiled_model/cpu_reservation_test.cpp

+22-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
#include "openvino/runtime/properties.hpp"
1616
#include "openvino/util/file_util.hpp"
1717

18+
#if defined(_WIN32)
19+
# include <windows.h>
20+
#endif
21+
1822
using namespace testing;
1923
using Device = std::string;
2024
using Config = ov::AnyMap;
@@ -80,14 +84,30 @@ TEST_F(DISABLED_CpuReservationTest, Cpu_Reservation_CpuPinning) {
8084
Config config = {ov::enable_profiling(true)};
8185
Device target_device(ov::test::utils::DEVICE_CPU);
8286
models.emplace_back(ov::test::utils::make_2_input_subtract());
87+
bool cpu_pinning = false;
88+
89+
#if defined(__linux__)
90+
cpu_pinning = true;
91+
#elif defined(_WIN32)
92+
ULONG highestNodeNumber = 0;
93+
if (!GetNumaHighestNodeNumber(&highestNodeNumber)) {
94+
std::cout << "Error getting highest NUMA node number: " << GetLastError() << std::endl;
95+
return;
96+
}
97+
if (highestNodeNumber > 0) {
98+
cpu_pinning = false;
99+
} else {
100+
cpu_pinning = true;
101+
}
102+
#endif
83103

84104
std::shared_ptr<ov::Core> core = ov::test::utils::PluginCache::get().core();
85105
core->set_property(target_device, config);
86106
ov::AnyMap property_config = {{ov::inference_num_threads.name(), 1},
87107
{ov::hint::enable_cpu_reservation.name(), true}};
88108
auto compiled_model = core->compile_model(models[0], target_device, property_config);
89-
auto cpu_pinning = compiled_model.get_property(ov::hint::enable_cpu_pinning.name());
90-
ASSERT_EQ(cpu_pinning, true);
109+
auto res_cpu_pinning = compiled_model.get_property(ov::hint::enable_cpu_pinning.name());
110+
ASSERT_EQ(res_cpu_pinning, cpu_pinning);
91111
}
92112

93113
TEST_F(CpuReservationTest, Cpu_Reservation_CompiledModel_Release) {

0 commit comments

Comments
 (0)