| 448 | return new EagerBufferAllocator(BufferAllocator::Allocator::createRecurse(mStaticAllocator.get())); |
| 449 | } |
| 450 | CPUBackend::CPUBackend(const CPURuntime* runtime, BackendConfig::PrecisionMode precision, BackendConfig::MemoryMode memory, MNNForwardType type, size_t flags) : Backend(type) { |
| 451 | #ifdef LOG_VERBOSE |
| 452 | MNN_PRINT("cpu backend create\n"); |
| 453 | #endif |
| 454 | mMemory = memory; |
| 455 | mRuntime = const_cast<CPURuntime*>(runtime); |
| 456 | auto core = MNNGetCoreFunctions(); |
| 457 | mThreadNumber = mRuntime->mThreadNumber; |
| 458 | mRelatedFunctions = &core->int8MatmulRelatedFunctions; |
| 459 | |
| 460 | // Compute Group Rate |
| 461 | do { |
| 462 | if (mThreadNumber <= 1 || mRuntime->mPower == BackendConfig::Power_Low) { |
| 463 | break; |
| 464 | } |
| 465 | auto rate = mRuntime->hint().cpuDecreaseRate; |
| 466 | if (rate >= 100 || rate <= 0) { |
| 467 | break; |
| 468 | } |
| 469 | auto cpuInfo = MNNGetCPUInfo(); |
| 470 | if (cpuInfo->groups.size() < 2) { |
| 471 | break; |
| 472 | } |
| 473 | if (cpuInfo->i8mm) { |
| 474 | mComputeI = 28.f; |
| 475 | } else if (cpuInfo->dot) { |
| 476 | mComputeI = 14.f; |
| 477 | } else { |
| 478 | mComputeI = 7.f; |
| 479 | } |
| 480 | mGroupWithComputeRate.clear(); |
| 481 | float decreaseRate = (float)(rate) / 100.0f; |
| 482 | int validCpuSize = (int)(cpuInfo->groups[cpuInfo->groups.size()-1].ids.size()); |
| 483 | int groupIndex = (int)cpuInfo->groups.size()-2; |
| 484 | validCpuSize = ALIMIN(validCpuSize, mThreadNumber); |
| 485 | float totalComputeRate = 1.0f * validCpuSize; |
| 486 | mGroupWithComputeRate.emplace_back(std::make_pair(totalComputeRate, validCpuSize)); |
| 487 | float currentRate = 1.0f; |
| 488 | while (validCpuSize < mThreadNumber && groupIndex >= 0) { |
| 489 | auto& group = cpuInfo->groups[groupIndex]; |
| 490 | int selectSize = ALIMIN(mThreadNumber - validCpuSize, (int)group.ids.size()); |
| 491 | validCpuSize += group.ids.size(); |
| 492 | currentRate *= decreaseRate; |
| 493 | totalComputeRate += currentRate * selectSize; |
| 494 | mGroupWithComputeRate.emplace_back(std::make_pair(currentRate * selectSize, selectSize)); |
| 495 | groupIndex--; |
| 496 | } |
| 497 | for (auto& g : mGroupWithComputeRate) { |
| 498 | g.first = g.first / totalComputeRate; |
| 499 | } |
| 500 | } while (false); |
| 501 | auto dynamicAlloc = mRuntime->mSharedDmaInfo; |
| 502 | if (nullptr == dynamicAlloc.get()) { |
| 503 | mDmaInfo.reset(new CPURuntime::DynamicAllocator); |
| 504 | mDmaInfo->mDynamicAllocator.reset(mRuntime->createDynamicBufferAlloctor(0)); |
| 505 | mDmaInfo->mCurrentDynamicAllocator = mDmaInfo->mDynamicAllocator.get(); |
| 506 | mDmaInfo->mCacheGroup.resize(MNN_CPU_MAX_BUFFER_INDEX); |
| 507 | for (int i=0; i<mDmaInfo->mCacheGroup.size(); ++i) { |
nothing calls this directly
no test coverage detected