LearningModelDevice(LearningModelDeviceKind) コンストラクター

定義

public:
 LearningModelDevice(LearningModelDeviceKind deviceKind);
 LearningModelDevice(LearningModelDeviceKind const& deviceKind);
public LearningModelDevice(LearningModelDeviceKind deviceKind);
function LearningModelDevice(deviceKind)
Public Sub New (deviceKind As LearningModelDeviceKind)

パラメーター

deviceKind
LearningModelDeviceKind

モデルを評価するために指定 された LearningModelDeviceKind

次の例では、モデルを読み込み、モデルを評価するデバイスを選択して評価します。

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;
    }
}

注釈

Windows Server

Windows Server でこの API を使用するには、Windows Server 2019 デスクトップ エクスペリエンスを使用する必要があります。

スレッド セーフ

この API はスレッド セーフです。

DirectX デバイスの使用

DirectX オプションのいずれかをこのコンストラクターに渡す場合は、ハードウェア デバイスが見つかる必要があります。 ハードウェア デバイスが存在しない場合は、ERROR_NOT_FOUNDが表示されます。 CPU にフォールバックすることを選択した場合は、このエラー コードを使用できます。 このコンストラクターを呼び出す前に独自のハードウェア検出を行うには、 DXGI API を使用します

注意

現時点では、このコンストラクターは成功し、DirectX ハードウェア デバイスが見つからない場合 DXGI_ADAPTER_FLAG_SOFTWARE ソフトウェア アダプターを誤って返します。

適用対象