From 3ab2d1f0f502b2035afe112b7ed6131621597af5 Mon Sep 17 00:00:00 2001 From: Reilly Grant Date: Thu, 21 Dec 2023 18:14:57 -0800 Subject: [PATCH] Add ability to specify MLContext options --- webnn-add.html | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/webnn-add.html b/webnn-add.html index 558bd3a..f12583a 100644 --- a/webnn-add.html +++ b/webnn-add.html @@ -8,6 +8,26 @@ = ?

+

+ Device preference: + +

+

+ Power preference: + +

+

+ Number of threads: + +

@@ -18,6 +38,9 @@ const aInput = document.getElementById('a'); const bInput = document.getElementById('b'); const cOutput = document.getElementById('c'); + const deviceOption = document.getElementById('device'); + const powerOption = document.getElementById('power'); + const threadsOption = document.getElementById('threads'); const buildButton = document.getElementById('build'); const computeButton = document.getElementById('compute'); const outputSpan = document.getElementById('output'); @@ -29,7 +52,14 @@ try { computeButton.disabled = true; - context = await navigator.ml.createContext(); + const options = { + devicePreference: deviceOption.value, + powerPreference: powerOption.value, + numThreads: threadsOption.value, + }; + console.log(options); + context = await navigator.ml.createContext(options); + const builder = new MLGraphBuilder(context); const operandType = {dataType: 'float32', dimensions: [1]}; const a = builder.input('a', operandType);