MCPcopy Create free account
hub / github.com/alibaba/MNN / _bindCPUCore

Method _bindCPUCore

source/backend/cpu/CPUBackend.cpp:81–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79}
80
81void CPURuntime::_bindCPUCore() const {
82 if (mCpuIds.empty()) {
83 return;
84 }
85 auto tid = MNNGetCurrentPid();
86 if (tid == mCurrentTID) {
87 return;
88 }
89 mCurrentTID = tid;
90 // Bind CPU Core
91 std::vector<std::pair<const int*, int>> lockCPUIndexes(mThreadNumber);
92 for (int v=0; v<mThreadNumber; ++v) {
93 lockCPUIndexes[v] = std::make_pair(mCpuIds.data(), mCpuIds.size());
94 }
95 // Set CPU Affinity
96#ifdef _OPENMP
97 auto threadsNumber = mThreadNumber;
98 std::vector<int> result(threadsNumber, 0);
99#pragma omp parallel for
100 for (int i = 0; i < threadsNumber; ++i) {
101 result[i] = MNNSetSchedAffinity(lockCPUIndexes[i].first, lockCPUIndexes[i].second);
102 }
103#endif
104#ifdef MNN_USE_THREAD_POOL
105 if (nullptr != mThreadPool) {
106 mThreadPool->active();
107 ThreadPool::TASK task = std::make_pair([&](int i) {
108 MNNSetSchedAffinity(lockCPUIndexes[i].first, lockCPUIndexes[i].second);
109 }, mThreadNumber);
110 mThreadPool->enqueue(&task, mTaskIndex);
111 mThreadPool->deactive();
112 }
113#endif
114}
115void CPURuntime::_resetThreadPool() const {
116 mThreadNumber = std::max(1, mThreadNumber);
117 mThreadNumber = std::min(mThreadNumber, MAX_THREAD_NUMBER);

Callers

nothing calls this directly

Calls 8

MNNGetCurrentPidFunction · 0.85
MNNSetSchedAffinityFunction · 0.85
activeMethod · 0.80
deactiveMethod · 0.80
emptyMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
enqueueMethod · 0.45

Tested by

no test coverage detected