Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPU reservation is false on mac #28544

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/inference/dev_api/openvino/runtime/system_conf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,13 @@ OPENVINO_RUNTIME_API bool with_cpu_x86_avx512_core_amx_fp16();
OPENVINO_RUNTIME_API bool with_cpu_x86_avx512_core_amx();

/**
* @brief Checks whether cpu_mapping Available
* @brief Checks whether cpu_pinning and cpu_reservation are available
* @ingroup ov_dev_api_system_conf
* @return `True` is CPU mapping is available, `false` otherwise
*/
OPENVINO_RUNTIME_API bool is_cpu_map_available();
OPENVINO_RUNTIME_API void cpu_pinning_available(bool& cpu_pinning,
const bool cpu_pinning_changed,
bool& cpu_reservation,
const std::vector<std::vector<int>>& streams_info_table);

/**
* @brief Get number of numa nodes
Expand Down
2 changes: 1 addition & 1 deletion src/inference/src/dev/threading/cpu_streams_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct CPUStreamsExecutor::Impl {
_impl->_usedNumaNodes.size()))
: _impl->_usedNumaNodes.at(_streamId % _impl->_usedNumaNodes.size());
#if OV_THREAD == OV_THREAD_TBB || OV_THREAD == OV_THREAD_TBB_AUTO
if (is_cpu_map_available() && _impl->_config.get_streams_info_table().size() > 0) {
if (_impl->_config.get_streams_info_table().size() > 0) {
init_stream();
}
#elif OV_THREAD == OV_THREAD_OMP
Expand Down
52 changes: 42 additions & 10 deletions src/inference/src/system_conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,10 @@ std::vector<std::vector<int>> get_proc_type_table() {
std::vector<std::vector<int>> get_org_proc_type_table() {
return {{-1}};
}
bool is_cpu_map_available() {
return false;
}
void cpu_pinning_available(bool& cpu_pinning,
const bool cpu_pinning_changed,
bool& cpu_reservation,
const std::vector<std::vector<int>>& streams_info_table) {}
int get_num_numa_nodes() {
return -1;
}
Expand Down Expand Up @@ -313,9 +314,15 @@ int get_number_of_blocked_cores() {
return cpu._blocked_cores;
}

bool is_cpu_map_available() {
void cpu_pinning_available(bool& cpu_pinning,
const bool cpu_pinning_changed,
bool& cpu_reservation,
const std::vector<std::vector<int>>& streams_info_table) {
CPU& cpu = cpu_info();
return cpu._proc_type_table.size() > 0;
if (cpu._cpu_mapping_table.size() == 0) {
cpu_pinning = false;
cpu_reservation = false;
}
}

int get_current_socket_id() {
Expand Down Expand Up @@ -393,6 +400,24 @@ std::vector<int> get_available_numa_nodes() {
return nodes;
}
# endif

void cpu_pinning_available(bool& cpu_pinning,
const bool cpu_pinning_changed,
bool& cpu_reservation,
const std::vector<std::vector<int>>& streams_info_table) {
if (!cpu_pinning_changed) {
cpu_pinning = true;
// The following code disables pinning in case stream contains both Pcore and Ecore
if (streams_info_table.size() >= 3) {
if ((streams_info_table[0][PROC_TYPE] == ALL_PROC) &&
(streams_info_table[1][PROC_TYPE] != EFFICIENT_CORE_PROC) &&
(streams_info_table[2][PROC_TYPE] == EFFICIENT_CORE_PROC)) {
cpu_pinning = cpu_reservation;
}
}
}
}

int get_current_socket_id() {
CPU& cpu = cpu_info();
int cur_processor_id = sched_getcpu();
Expand All @@ -419,6 +444,18 @@ int get_current_numa_node_id() {
return 0;
}
# else
void cpu_pinning_available(bool& cpu_pinning,
const bool cpu_pinning_changed,
bool& cpu_reservation,
const std::vector<std::vector<int>>& streams_info_table) {
CPU& cpu = cpu_info();
if (cpu._proc_type_table.size() == 1) {
cpu_pinning = cpu_pinning_changed ? cpu_pinning : cpu_reservation;
} else { // multiple sockets machine
cpu_pinning = false;
}
}

int get_current_socket_id() {
CPU& cpu = cpu_info();
int cur_processor_id = GetCurrentProcessorNumber();
Expand Down Expand Up @@ -457,11 +494,6 @@ std::vector<std::vector<int>> get_org_proc_type_table() {
return cpu._org_proc_type_table;
}

bool is_cpu_map_available() {
CPU& cpu = cpu_info();
return cpu._cpu_mapping_table.size() > 0;
}

int get_num_numa_nodes() {
return cpu_info()._numa_nodes;
}
Expand Down
36 changes: 0 additions & 36 deletions src/plugins/intel_cpu/src/cpu_map_scheduling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,40 +69,4 @@ std::vector<std::vector<int>> apply_hyper_threading(bool& input_ht_hint,
return result_table;
}

bool get_cpu_pinning(bool& input_value,
const bool input_changed,
const bool cpu_reservation,
const std::vector<std::vector<int>>& proc_type_table,
const std::vector<std::vector<int>>& streams_info_table) {
bool result_value;

#if defined(__APPLE__)
result_value = false;
#elif defined(_WIN32)
if (proc_type_table.size() == 1) {
result_value = input_changed ? input_value : cpu_reservation;
} else {
result_value = false;
}
#else
if (input_changed) {
result_value = input_value;
} else {
result_value = true;
// The following code disables pinning in case stream contains both Pcore and Ecore
if (streams_info_table.size() >= 3) {
if ((streams_info_table[0][PROC_TYPE] == ALL_PROC) &&
(streams_info_table[1][PROC_TYPE] != EFFICIENT_CORE_PROC) &&
(streams_info_table[2][PROC_TYPE] == EFFICIENT_CORE_PROC)) {
result_value = cpu_reservation;
}
}
}
#endif

input_value = result_value;

return result_value;
}

} // namespace ov::intel_cpu
15 changes: 0 additions & 15 deletions src/plugins/intel_cpu/src/cpu_map_scheduling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,4 @@ std::vector<std::vector<int>> apply_hyper_threading(bool& input_ht_hint,
const std::string& input_pm_hint,
const std::vector<std::vector<int>>& proc_type_table);

/**
* @brief whether pinning cpu cores according to enableCpuPinning property
* @param[in] input_type indicate value of property enableCpuPinning.
* @param[in] input_changed indicate if value is set by user.
* @param[in] cpu_reservation indicate if cpu need to be reserved
* @param[in] proc_type_table indicate processors information of this platform
* @param[in] streams_info_table indicate streams detail of this model
* @return whether pinning threads to cpu cores
*/
bool get_cpu_pinning(bool& input_value,
const bool input_changed,
const bool cpu_reservation,
const std::vector<std::vector<int>>& proc_type_table,
const std::vector<std::vector<int>>& streams_info_table);

} // namespace ov::intel_cpu
11 changes: 5 additions & 6 deletions src/plugins/intel_cpu/src/cpu_streams_calculation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,18 +732,17 @@ std::vector<std::vector<int>> generate_stream_info(const int streams,
get_streams_rank_table(streams_info_table, config.streamsRankLevel, config.numSubStreams);
}

auto cpu_pinning = get_cpu_pinning(config.enableCpuPinning,
config.changedCpuPinning,
config.enableCpuReservation,
proc_type_table,
streams_info_table);
cpu_pinning_available(config.enableCpuPinning,
config.changedCpuPinning,
config.enableCpuReservation,
streams_info_table);

config.streamExecutorConfig = IStreamsExecutor::Config{"CPUStreamsExecutor",
config.streams,
config.threadsPerStream,
ov::hint::SchedulingCoreType::ANY_CORE,
config.enableCpuReservation,
cpu_pinning,
config.enableCpuPinning,
true,
std::move(streams_info_table),
{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#include "openvino/runtime/system_conf.hpp"
#include "utils/properties_test.hpp"

#if defined(_WIN32)
# include <windows.h>
#endif

namespace {

TEST_F(OVClassConfigTestCPU, smoke_CpuExecNetworkSupportedPropertiesAreAvailable) {
Expand Down Expand Up @@ -159,6 +163,47 @@ TEST_F(OVClassConfigTestCPU, smoke_CpuExecNetworkCheckModelZeroStreams) {
ASSERT_EQ(streams, value);
}

TEST_F(OVClassConfigTestCPU, smoke_CpuExecNetworkCheckCpuReservation) {
ov::Core ie;
int32_t threads = 1;
int32_t res_threads = -1;
bool cpu_reservation = true;
bool res_cpu_reservation = false;
bool cpu_pinning = false;
bool res_cpu_pinning = false;

#if defined(__APPLE__)
cpu_reservation = false;
cpu_pinning = false;
#elif defined(__linux__)
cpu_pinning = true;
#elif defined(_WIN32)
ULONG highestNodeNumber = 0;
if (!GetNumaHighestNodeNumber(&highestNodeNumber)) {
std::cout << "Error getting highest NUMA node number: " << GetLastError() << std::endl;
return;
}
if (highestNodeNumber > 0) {
cpu_pinning = false;
} else {
cpu_pinning = true;
}
#endif

OV_ASSERT_NO_THROW(ie.set_property(deviceName, ov::hint::performance_mode(ov::hint::PerformanceMode::LATENCY)));

ov::AnyMap config = {{ov::inference_num_threads.name(), threads}, {ov::hint::enable_cpu_reservation.name(), true}};
ov::CompiledModel compiledModel = ie.compile_model(model, deviceName, config);

OV_ASSERT_NO_THROW(res_threads = compiledModel.get_property(ov::inference_num_threads));
OV_ASSERT_NO_THROW(res_cpu_reservation = compiledModel.get_property(ov::hint::enable_cpu_reservation));
OV_ASSERT_NO_THROW(res_cpu_pinning = compiledModel.get_property(ov::hint::enable_cpu_pinning));

ASSERT_EQ(res_threads, threads);
ASSERT_EQ(res_cpu_reservation, cpu_reservation);
ASSERT_EQ(res_cpu_pinning, cpu_pinning);
}

TEST_F(OVClassConfigTestCPU, smoke_CpuExecNetworkCheckSparseWeigthsDecompressionRate) {
ov::Core core;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@
#include "openvino/runtime/properties.hpp"
#include "openvino/util/file_util.hpp"

#if defined(_WIN32)
# include <windows.h>
#endif

using namespace testing;
using Device = std::string;
using Config = ov::AnyMap;
using CpuReservationTest = ::testing::Test;

#if (defined(__linux__) || defined(__WIN32))
TEST_F(CpuReservationTest, Mutiple_CompiledModel_Reservation) {
std::vector<std::shared_ptr<ov::Model>> models;
Config config = {ov::enable_profiling(true)};
Expand Down Expand Up @@ -72,19 +77,34 @@ TEST_F(CpuReservationTest, Cpu_Reservation_NoAvailableCores) {
EXPECT_THROW(core->compile_model(models[0], target_device, property_config), ov::Exception);
}

#if defined(__linux__)
TEST_F(CpuReservationTest, Cpu_Reservation_CpuPinning) {
std::vector<std::shared_ptr<ov::Model>> models;
Config config = {ov::enable_profiling(true)};
Device target_device(ov::test::utils::DEVICE_CPU);
models.emplace_back(ov::test::utils::make_2_input_subtract());
bool cpu_pinning = false;

#if defined(__linux__)
cpu_pinning = true;
#elif defined(_WIN32)
ULONG highestNodeNumber = 0;
if (!GetNumaHighestNodeNumber(&highestNodeNumber)) {
std::cout << "Error getting highest NUMA node number: " << GetLastError() << std::endl;
return;
}
if (highestNodeNumber > 0) {
cpu_pinning = false;
} else {
cpu_pinning = true;
}
#endif

std::shared_ptr<ov::Core> core = ov::test::utils::PluginCache::get().core();
core->set_property(target_device, config);
ov::AnyMap property_config = {{ov::inference_num_threads.name(), 1},
{ov::hint::enable_cpu_reservation.name(), true}};
auto compiled_model = core->compile_model(models[0], target_device, property_config);
auto cpu_pinning = compiled_model.get_property(ov::hint::enable_cpu_pinning.name());
ASSERT_EQ(cpu_pinning, true);
auto res_cpu_pinning = compiled_model.get_property(ov::hint::enable_cpu_pinning.name());
ASSERT_EQ(res_cpu_pinning, cpu_pinning);
}
#endif
Loading
Loading