-
Notifications
You must be signed in to change notification settings - Fork 261
tune default cpu properties #4323
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
Changes from all commits
59d9a31
192bd7c
481a0df
77716b7
974d688
e4a4edf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,19 +91,7 @@ ModelManager::ModelManager(const std::string& modelCacheDirectory, MetricRegistr | |
| modelCacheDirectory(modelCacheDirectory), | ||
| metricRegistry(registry), | ||
| pythonBackend(pythonBackend) { | ||
| try { | ||
| this->ieCore = std::make_unique<ov::Core>(); | ||
| ov::AnyMap cpuProperties; | ||
| Status status = applyDefaultCpuProperties(cpuProperties); | ||
| if (!status.ok()) { | ||
| SPDLOG_CRITICAL("Failed to apply default CPU properties. Reason: {}", status.string()); | ||
| throw std::runtime_error("Failed to apply default CPU properties"); | ||
| } | ||
| this->ieCore->set_property("CPU", cpuProperties); | ||
| } catch (const std::exception& ex) { | ||
| SPDLOG_CRITICAL("Failed to initialize OpenVINO Core with CPU properties. Reason: {}", ex.what()); | ||
| throw; | ||
| } | ||
| this->ieCore = std::make_unique<ov::Core>(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will models loaded by GenAI also inherit those settings?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, genai is using different ov::core object |
||
|
|
||
| OV_LOGGER("ov::Core(): {}", reinterpret_cast<void*>(this->ieCore.get())); | ||
| // Take --cache_dir from CLI | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,47 +150,48 @@ Status validatePluginConfiguration(const plugin_config_t& pluginConfig, const st | |
| return StatusCode::OK; | ||
| } | ||
|
|
||
| Status applyDefaultCpuProperties(ov::AnyMap& properties) { | ||
| #ifdef __linux__ | ||
| try { | ||
| if (!isRunningInDocker()) { | ||
| return StatusCode::OK; | ||
| } | ||
| const uint16_t coreCount = getCoreCount(); | ||
|
|
||
| if (properties.find(ov::hint::enable_cpu_pinning.name()) == properties.end()) { | ||
| const bool cpuPinning = getDockerCpuQuota() <= 0; | ||
| properties[ov::hint::enable_cpu_pinning.name()] = cpuPinning; | ||
| SPDLOG_DEBUG("applyDefaultCpuProperties: setting enable_cpu_pinning to {}", cpuPinning); | ||
| } | ||
| Status applyDefaultCpuProperties(ov::AnyMap& properties, uint16_t coreCount, uint16_t physicalCoresPerSocket, uint16_t socketsCount, uint16_t dockerCpuQuota) { | ||
| if (properties.find(ov::hint::enable_cpu_pinning.name()) == properties.end()) { | ||
| const bool cpuPinning = dockerCpuQuota <= 0; | ||
| properties[ov::hint::enable_cpu_pinning.name()] = cpuPinning; | ||
| SPDLOG_DEBUG("applyDefaultCpuProperties, DockerCPUQuota: {} - setting enable_cpu_pinning to {}", dockerCpuQuota, cpuPinning); | ||
| } | ||
|
|
||
| bool isThroughput = false; | ||
| const auto perfIt = properties.find(ov::hint::performance_mode.name()); | ||
| if (perfIt != properties.end()) { | ||
| bool isThroughput = false; | ||
| const auto perfIt = properties.find(ov::hint::performance_mode.name()); | ||
| if (perfIt != properties.end()) { | ||
| try { | ||
| isThroughput = (perfIt->second.as<ov::hint::PerformanceMode>() == ov::hint::PerformanceMode::THROUGHPUT); | ||
|
Comment on lines
+160
to
+164
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tests are added to ensure detection of throughput mode, socket count can be 0. It is unlikely to exceed uint16 |
||
| } catch (...) { | ||
| try { | ||
| isThroughput = (perfIt->second.as<ov::hint::PerformanceMode>() == ov::hint::PerformanceMode::THROUGHPUT); | ||
| isThroughput = (perfIt->second.as<std::string>() == "THROUGHPUT"); | ||
| } catch (...) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. log error?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not necessarily error, in case of unexpected problem with detecting performance mode, there will be just default properties. It is not expected to reach this state. Exception is to avoid error in such unexpected situation.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even in such case logging what happen is helpful. Otherwise you don't have a clue what was set unless running under debugger. |
||
| try { | ||
| isThroughput = (perfIt->second.as<std::string>() == "THROUGHPUT"); | ||
| } catch (...) { | ||
| } | ||
| } | ||
| if (isThroughput && properties.find(ov::num_streams.name()) == properties.end()) { | ||
| properties[ov::num_streams.name()] = static_cast<int>(coreCount); | ||
| SPDLOG_DEBUG("applyDefaultCpuProperties: setting num_streams to {} (THROUGHPUT hint active)", coreCount); | ||
| } | ||
| } | ||
| if (isThroughput && properties.find(ov::num_streams.name()) == properties.end()) { | ||
| int numStreams = std::min(static_cast<int>(coreCount), static_cast<int>(physicalCoresPerSocket * socketsCount)); | ||
| properties[ov::num_streams.name()] = numStreams; | ||
| SPDLOG_DEBUG("applyDefaultCpuProperties, CoreCount: {}, PhysicalCoresPerSocket: {}, SocketsCount: {} - setting num_streams to {} (THROUGHPUT hint active)", coreCount, physicalCoresPerSocket, socketsCount, numStreams); | ||
| } | ||
| } | ||
|
|
||
| if (properties.find(ov::inference_num_threads.name()) == properties.end()) { | ||
| int numThreads; | ||
| if (isThroughput) { | ||
| numThreads = static_cast<int>(coreCount); | ||
| } else { | ||
| numThreads = std::min(static_cast<int>(coreCount), static_cast<int>(getPhysicalCoresPerSocket())); | ||
| } | ||
| if (properties.find(ov::inference_num_threads.name()) == properties.end()) { | ||
| if (coreCount <= physicalCoresPerSocket * socketsCount) { | ||
| int numThreads = static_cast<int>(coreCount); | ||
| properties[ov::inference_num_threads.name()] = numThreads; | ||
| SPDLOG_DEBUG("applyDefaultCpuProperties: setting inference_num_threads to {}", numThreads); | ||
| SPDLOG_DEBUG("applyDefaultCpuProperties: CoreCount: {}, PhysicalCoresPerSocket: {}, SocketsCount: {}, setting inference_num_threads to {}", coreCount, physicalCoresPerSocket, socketsCount, numThreads); | ||
| } | ||
| } | ||
| return StatusCode::OK; | ||
| } | ||
|
|
||
| Status applyDefaultCpuProperties(ov::AnyMap& properties) { | ||
| #ifdef __linux__ | ||
| try { | ||
| if (!isRunningInDocker()) { | ||
| return StatusCode::OK; | ||
| } | ||
| return applyDefaultCpuProperties(properties, getCoreCount(), getPhysicalCoresPerSocket(), getSocketsCount(), getDockerCpuQuota()); | ||
| } catch (const std::exception& ex) { | ||
| SPDLOG_WARN("Exception while applying default CPU properties: {}", ex.what()); | ||
| } catch (...) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tuning CPU properties in container is expected only in CPU device.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about AUTO device?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point from copilot and Adrian.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in AUTO plugin it is not possible to set those properties.
HETERO plugin is a corner case. For simplicity it will be better to keep default OV settings.