onnxruntime/winml/lib/Api/LearningModelSessionOptions.h
Ryan Lai 5ce675c3b9
Expose Onnxruntime Intra Op thread controls through WinML Native API (#4638)
* Register ILearningModelSessionOptionsNate interface

* Threading options exposed

* Add interrogator for Session options

* Add test

* Polish test

* PR comments

* Set intra op threads

* Add adapter api to grab intra op threads

* Add adapter test for getting intraop num threads

* Make ILearningModelSessionNative and update winml api test

* Make it required when building engine to set the intraop num threads

* Make test  more pretty

* Change naming of idl function

* Revert "Change naming of idl function"

This reverts commit c06916aa5bf94e3bf233ed281e508b935fc8638d.

* PR comment on naming

* Skip the test because it's influenced if it's built with openmp

Co-authored-by: Ryan Lai <ryalai96@gamil.com>
2020-07-30 17:55:26 -07:00

61 lines
2.7 KiB
C++

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#pragma once
#include "LearningModelSessionOptions.g.h"
#include <thread>
namespace WINMLP {
struct LearningModelSessionOptions : LearningModelSessionOptionsT<LearningModelSessionOptions, ILearningModelSessionOptionsNative> {
LearningModelSessionOptions() = default;
LearningModelSessionOptions(const LearningModelSessionOptions& options);
uint32_t BatchSizeOverride();
void BatchSizeOverride(uint32_t value);
bool CloseModelOnSessionCreation();
void CloseModelOnSessionCreation(bool value);
STDMETHOD(SetIntraOpNumThreadsOverride)
(uint32_t intraOpNumThreads);
uint32_t GetIntraOpNumThreads();
private:
// The batch size override property is used to inform the engine when the developer
// wants to explicitly set the batch size of a model to a fixed batch size.
//
// 0 : dont override the model batch definitions
// 1...n : override the model with the given batch size
//
// This value is a unsigned value, and users are not allowed to override models with a free batch size.
// If the model supports free dimensional batch sizes, the caller should provide 0, to not override.
//
// The default value here is 1 so that models with free dimension batch sizes (which is very common)
// can be optimized to fixed sizes.
uint32_t batch_size_override_ = 1;
// The close model on session creation property is used to inform the engine when the developer
// no longer needs the learningmodelsession after session creation.
// The engine can use the learning model during session creation to move resources rather than make copies.
//
// True : Move resources in the LearningModel in to the LearningModelSession
// False : Copy resources in the LearningModel to the LearningModelSession
//
// The default value here is False so that models are not automatically closed on session creation.
bool close_model_on_session_creation_ = false;
// The intra operator num threads property is used to control the number of threads used in the threadpool for intra operator calculations.
// The default value here is the maximum number of logical cores to ensure that the default behavior of WinML always runs the fastest.
// WARNING: Setting a number higher than the maximum number of logical cores may result in an inefficient threadpool
uint32_t intra_op_num_threads_override_ = std::thread::hardware_concurrency();
};
} // namespace WINMLP
namespace WINML::factory_implementation {
struct LearningModelSessionOptions : LearningModelSessionOptionsT<LearningModelSessionOptions, implementation::LearningModelSessionOptions> {
};
} // namespace WINML::factory_implementation