LearningModelDeviceKind Enum
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Important
For the latest documentation about Windows Machine Learning, see What is Windows ML. That documentation describes APIs that are in the Microsoft.Windows.AI.MachineLearning namespace, which ships in the Windows App SDK. Those APIs supersede the ones documented here, which are in the Windows.AI.MachineLearning namespace, and were shipped in 2018.
Defines the list of device kinds that can evaluate a machine learning model.
public enum class LearningModelDeviceKind
/// [Windows.Foundation.Metadata.ContractVersion(Windows.AI.MachineLearning.MachineLearningContract, 65536)]
enum class LearningModelDeviceKind
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.AI.MachineLearning.MachineLearningContract), 65536)]
public enum LearningModelDeviceKind
var value = Windows.AI.MachineLearning.LearningModelDeviceKind.default
Public Enum LearningModelDeviceKind
- Inheritance
-
LearningModelDeviceKind
- Attributes
Windows requirements
| Device family |
Windows 10, version 1809 (introduced in 10.0.17763.0)
|
| API contract |
Windows.AI.MachineLearning.MachineLearningContract (introduced in v1.0)
|
Fields
| Name | Value | Description |
|---|---|---|
| Default | 0 | Let the system decide which device to use. |
| Cpu | 1 | Use the CPU to evaluate the model. |
| DirectX | 2 | Use a GPU or other DirectX device to evaluate the model. |
| DirectXHighPerformance | 3 | Use the system policy-defined device for high performance. |
| DirectXMinPower | 4 | Use the system policy-defined device for minimum power. |
Examples
The following example loads a model, selects the device on which to evaluate the model, and creates an evaluation session.
private async Task LoadModelAsync(string _modelFileName, bool _useGPU)
{
LearningModel _model;
LearningModelSession _session;
try
{
// Load and create the model
var modelFile =
await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///Assets/{_modelFileName}"));
_model = await LearningModel.LoadFromStorageFileAsync(modelFile);
// Select the device to evaluate on
LearningModelDevice device = null;
if (_useGPU)
{
// Use a GPU or other DirectX device to evaluate the model.
device = new LearningModelDevice(LearningModelDeviceKind.DirectX);
}
else
{
// Use the CPU to evaluate the model.
device = new LearningModelDevice(LearningModelDeviceKind.Cpu);
}
// Create the evaluation session with the model and device.
_session = new LearningModelSession(_model, device);
}
catch (Exception ex)
{
StatusBlock.Text = $"error: {ex.Message}";
_model = null;
}
}
Remarks
If not specified, the system will decide which device to use.
Windows Server
To use this API on Windows Server, you must use Windows Server 2019 with Desktop Experience.
Thread safety
This API is thread-safe.