Skip to content

v2.1

Choose a tag to compare

@YingkunZhou YingkunZhou released this 21 Nov 03:45
· 26 commits to main since this release

add x86_64 linux and windows support

  • tflite (2.16.1) build by myself
  • MNN (commit id: 630d59310c3e949560866b07d8edc9232e89ec0a) build by myself
  • onnxruntime v1.20.0 (official link)
  • ncnn (official link)
  • openvino (2024.4.0) build by myself with minor modificaiton
diff --git a/src/inference/src/os/cpu_map_info.hpp b/src/inference/src/os/cpu_map_info.hpp
index 497b25c3b6..2cc6cef768 100644
--- a/src/inference/src/os/cpu_map_info.hpp
+++ b/src/inference/src/os/cpu_map_info.hpp
@@ -53,6 +53,39 @@ public:
     std::map<int, int> _numaid_mapping_table;
     std::mutex _cpu_mutex;
     int _socket_idx = 0;
+
+private:
+    /**
+     * @brief      Sort proc_type_table by CPU ID on which application is running. The numa node containing this CPU ID
+     * will move to first row.
+     * @param[in]  _processor_id CPU ID on which application is running.
+     * @param[in] _proc_type_table summary table of number of processors per type
+     * @param[in] _cpu_mapping_table CPU mapping table for each processor
+     * @return
+     */
+    void sort_table_by_cpu_id(const int _processor_id,
+                              std::vector<std::vector<int>>& _proc_type_table,
+                              const std::vector<std::vector<int>>& _cpu_mapping_table) {
+        int current_numa_node = 0;
+        int current_socket = 0;
+
+        for (auto& row : _cpu_mapping_table) {
+            if (_processor_id == row[CPU_MAP_PROCESSOR_ID]) {
+                current_numa_node = row[CPU_MAP_NUMA_NODE_ID];
+                current_socket = row[CPU_MAP_SOCKET_ID];
+                break;
+            }
+        }
+        for (size_t i = 1; i < _proc_type_table.size(); i++) {
+            if ((current_numa_node == _proc_type_table[i][PROC_NUMA_NODE_ID]) &&
+                (current_socket == _proc_type_table[i][PROC_SOCKET_ID])) {
+                std::rotate(_proc_type_table.begin() + 1, _proc_type_table.begin() + i, _proc_type_table.end());
+                break;
+            }
+        }
+    };
+
+    friend class LinuxSortProcTableTests;
 };
 
 CPU& cpu_info();
diff --git a/src/inference/src/os/lin/lin_system_conf.cpp b/src/inference/src/os/lin/lin_system_conf.cpp
index 2dcf9eaa4d..37d6119688 100644
--- a/src/inference/src/os/lin/lin_system_conf.cpp
+++ b/src/inference/src/os/lin/lin_system_conf.cpp
@@ -1,3 +1,4 @@
+
 // Copyright (C) 2018-2024 Intel Corporation
 // SPDX-License-Identifier: Apache-2.0
 //
@@ -12,6 +13,7 @@
 #include <vector>
 
 #include "dev/threading/parallel_custom_arena.hpp"
+#include "dev/threading/thread_affinity.hpp"
 #include "openvino/core/except.hpp"
 #include "openvino/runtime/system_conf.hpp"
 #include "os/cpu_map_info.hpp"
@@ -114,10 +116,11 @@ CPU::CPU() {
     };
 
     auto check_valid_cpu = [&]() {
-        cpu_set_t mask;
-        CPU_ZERO(&mask);
+        ov::threading::CpuSet mask;
+        int ncpus = 0;
+        std::tie(mask, ncpus) = ov::threading::get_process_mask();
 
-        if ((_processors == 0) || (sched_getaffinity(0, sizeof(cpu_set_t), &mask) == -1)) {
+        if ((_processors == 0) || mask == nullptr) {
             return -1;
         }
 
@@ -128,7 +131,7 @@ CPU::CPU() {
 
         numa_node_list.assign(_sockets, std::vector<int>());
         for (int i = 0; i < _processors; i++) {
-            if (CPU_ISSET(i, &mask)) {
+            if (CPU_ISSET(i, mask)) {
                 valid_cpu_mapping_table.emplace_back(_cpu_mapping_table[i]);
                 if (_cpu_mapping_table[i][CPU_MAP_CORE_TYPE] == MAIN_CORE_PROC) {
                     phy_core_list.emplace_back(_cpu_mapping_table[i][CPU_MAP_CORE_ID]);
@@ -280,6 +283,11 @@ CPU::CPU() {
         OPENVINO_THROW("CPU affinity check failed. No CPU is eligible to run inference.");
     };
 
+    if (_proc_type_table.size() > 1) {
+        int cur_processor_id = sched_getcpu();
+        sort_table_by_cpu_id(cur_processor_id, _proc_type_table, _cpu_mapping_table);
+    }
+
     _org_proc_type_table = _proc_type_table;
 
     cpu_debug();
@@ -775,3 +783,4 @@ void update_valid_processor_linux(const std::vector<int> phy_core_list,
 };
 
 }  // namespace ov
+