| 265 | } |
| 266 | |
| 267 | Backend* CPURuntime::onCreate(const BackendConfig* config, Backend* origin) const { |
| 268 | { |
| 269 | mCpuIds = hint().cpuIds; |
| 270 | _validateCpuIds(); |
| 271 | mCpuMask = MNNGetCPUMask(mCpuIds); |
| 272 | _resetThreadPool(); |
| 273 | } |
| 274 | if (hint().midMemoryPath.size() > 0) { |
| 275 | if (mDynamicMmap.empty()) { |
| 276 | // Only support set featuremap dir once |
| 277 | mDynamicMmap.resize(2); |
| 278 | auto mmapMem = BufferAllocator::Allocator::createMmap(hint().midMemoryPath.c_str(), "", "dynamic"); |
| 279 | for (auto& buf : mDynamicMmap) { |
| 280 | buf.root = mmapMem; |
| 281 | } |
| 282 | } |
| 283 | } |
| 284 | if (hint().weightMemoryPath.size() > 0) { |
| 285 | // forward_type, precision_type, memory_type, power_type |
| 286 | std::string prefix = "0_0_0_0_"; |
| 287 | prefix[2] += mPrecision; |
| 288 | prefix[4] += mMemory; |
| 289 | prefix[6] += mPower; |
| 290 | // prefix += hint().modelUUID + "_"; |
| 291 | bool autoRemove = true; |
| 292 | bool syncValid = false; |
| 293 | if (hint().useCachedMmap) { |
| 294 | autoRemove = false; |
| 295 | std::string fileName = MNNFilePathConcat(hint().weightMemoryPath, prefix + "sync.static"); |
| 296 | syncValid = MNNFileExist(fileName.c_str()); |
| 297 | const_cast<RuntimeHint&>(hint()).useCachedMmap += syncValid; |
| 298 | } |
| 299 | if (nullptr == mStaticAllocatorMMap.get()) { |
| 300 | // Only support set weightmap dir once |
| 301 | mStaticAllocatorRaw = mStaticAllocator; |
| 302 | auto mmapMem = BufferAllocator::Allocator::createMmap(hint().weightMemoryPath.c_str(), prefix.c_str(), "static", autoRemove, syncValid); |
| 303 | size_t mmapSize = static_cast<size_t>(hint().mmapFileSize) * 1024 * 1024; |
| 304 | mStaticAllocator.reset(new EagerBufferAllocator(mmapMem, 32, mmapSize)); |
| 305 | mStaticAllocatorMMap = mStaticAllocator; |
| 306 | } |
| 307 | } |
| 308 | auto precision = mPrecision; |
| 309 | auto memory = mMemory; |
| 310 | size_t flags = mFlags; |
| 311 | if (nullptr != origin) { |
| 312 | auto cpuBn = static_cast<CPUBackend*>(origin); |
| 313 | mSharedDmaInfo = cpuBn->mDmaInfo; |
| 314 | } |
| 315 | if (nullptr != config) { |
| 316 | precision = config->precision; |
| 317 | flags = config->flags; |
| 318 | memory = config->memory; |
| 319 | } |
| 320 | #ifdef LOG_VERBOSE |
| 321 | MNN_PRINT("cpu backend was created by runtime:%p\n", this); |
| 322 | #endif |
| 323 | CPUBackend* res = nullptr; |
| 324 | auto initThreadNumber = hint().initThreadNumber; |
nothing calls this directly
no test coverage detected