IntraopNumThreads 介面

可讓您透過 LearningModelSessionOptions ,變更 CPU 運算子之內部運算子執行執行緒集區中使用的執行緒數目。 根據預設,WinML 會將值設定為執行緒數目上限,也就是使用者 CPU 上邏輯核心數目相同的數目。 將此值設定為高於 CPU 上的邏輯核心數目,可能會導致執行緒集區效率不佳,且評估速度較慢。

範例指令碼

void SetIntraOpNumThreads(LearningModel model) {
    // Create LearningModelSessionOptions
    auto options = LearningModelSessionOptions();
    auto nativeOptions = options.as<ILearningModelSessionOptionsNative>();
 
    // Set the number of intra op threads to half of logical cores.
    uint32_t desiredThreads = std::thread::hardware_concurrency() / 2;
    nativeOptions->SetIntraOpNumThreadsOverride(desiredThreads);
 
    // Create session
    LearningModelSession session = nullptr;
    WINML_EXPECT_NO_THROW(session = LearningModelSession(model, LearningModelDeviceKind::Cpu, options));
}

需求

需求
最低支援的用戶端 Windows 10 組建 17763
最低支援的伺服器 具有桌面體驗的 Windows Server 2019
頁首 windows.ai.machinelearning.native.h

注意

使用下列資源取得 Windows ML 的說明:

  • 如需詢問或回答有關 Windows ML 的技術問題,請使用 Stack Overflow 上的 windows-machine-learning 標籤。
  • 如需回報錯誤 (bug),請在 GitHub 上提出問題。