1
1
'use strict' ;
2
2
3
- const ExecutionArray = [ 'sync' , 'async' ] ;
4
-
5
3
// https://webmachinelearning.github.io/webnn/#enumdef-mloperanddatatype
6
4
const TypedArrayDict = {
7
5
// workaround use Uint16 for Float16
@@ -793,25 +791,7 @@ const buildGraph = (operationName, builder, resources, buildFunc) => {
793
791
} ;
794
792
795
793
/**
796
- * Build a graph, synchronously compile graph and execute, then check computed results.
797
- * @param {String } operationName - An operation name
798
- * @param {MLContext } context - A ML context
799
- * @param {MLGraphBuilder } builder - A ML graph builder
800
- * @param {Object } resources - Resources used for building a graph
801
- * @param {Function } buildFunc - A build function for an operation
802
- */
803
- const runSync = ( operationName , context , builder , resources , buildFunc ) => {
804
- // build a graph
805
- const [ namedOutputOperands , inputs , outputs ] = buildGraph ( operationName , builder , resources , buildFunc ) ;
806
- // synchronously compile the graph up to the output operand
807
- const graph = builder . buildSync ( namedOutputOperands ) ;
808
- // synchronously execute the compiled graph.
809
- context . computeSync ( graph , inputs , outputs ) ;
810
- checkResults ( operationName , namedOutputOperands , outputs , resources ) ;
811
- } ;
812
-
813
- /**
814
- * Build a graph, asynchronously compile graph and execute, then check computed results.
794
+ * Build a graph, compile graph and execute, then check computed results.
815
795
* @param {String } operationName - An operation name
816
796
* @param {MLContext } context - A ML context
817
797
* @param {MLGraphBuilder } builder - A ML graph builder
@@ -821,9 +801,9 @@ const runSync = (operationName, context, builder, resources, buildFunc) => {
821
801
const run = async ( operationName , context , builder , resources , buildFunc ) => {
822
802
// build a graph
823
803
const [ namedOutputOperands , inputs , outputs ] = buildGraph ( operationName , builder , resources , buildFunc ) ;
824
- // asynchronously compile the graph up to the output operand
804
+ // compile the graph up to the output operand
825
805
const graph = await builder . build ( namedOutputOperands ) ;
826
- // asynchronously execute the compiled graph
806
+ // execute the compiled graph
827
807
const result = await context . compute ( graph , inputs , outputs ) ;
828
808
checkResults ( operationName , namedOutputOperands , result . outputs , resources ) ;
829
809
} ;
@@ -842,41 +822,18 @@ const testWebNNOperation = (operationName, buildFunc, deviceType = 'cpu') => {
842
822
operationNameArray = operationName ;
843
823
}
844
824
845
- ExecutionArray . forEach ( executionType => {
846
- const isSync = executionType === 'sync' ;
847
- if ( self . GLOBAL . isWindow ( ) && isSync ) {
848
- return ;
849
- }
850
- let context ;
851
- let builder ;
852
- if ( isSync ) {
853
- // test sync
854
- operationNameArray . forEach ( ( subOperationName ) => {
855
- const tests = loadTests ( subOperationName ) ;
856
- setup ( ( ) => {
857
- context = navigator . ml . createContextSync ( { deviceType} ) ;
858
- builder = new MLGraphBuilder ( context ) ;
859
- } ) ;
860
- for ( const subTest of tests ) {
861
- test ( ( ) => {
862
- runSync ( subOperationName , context , builder , subTest , buildFunc ) ;
863
- } , `${ subTest . name } / ${ executionType } ` ) ;
864
- }
865
- } ) ;
866
- } else {
867
- // test async
868
- operationNameArray . forEach ( ( subOperationName ) => {
869
- const tests = loadTests ( subOperationName ) ;
870
- promise_setup ( async ( ) => {
871
- context = await navigator . ml . createContext ( { deviceType} ) ;
872
- builder = new MLGraphBuilder ( context ) ;
873
- } ) ;
874
- for ( const subTest of tests ) {
875
- promise_test ( async ( ) => {
876
- await run ( subOperationName , context , builder , subTest , buildFunc ) ;
877
- } , `${ subTest . name } / ${ executionType } ` ) ;
878
- }
879
- } ) ;
825
+ let context ;
826
+ let builder ;
827
+ operationNameArray . forEach ( ( subOperationName ) => {
828
+ const tests = loadTests ( subOperationName ) ;
829
+ promise_setup ( async ( ) => {
830
+ context = await navigator . ml . createContext ( { deviceType} ) ;
831
+ builder = new MLGraphBuilder ( context ) ;
832
+ } ) ;
833
+ for ( const subTest of tests ) {
834
+ promise_test ( async ( ) => {
835
+ await run ( subOperationName , context , builder , subTest , buildFunc ) ;
836
+ } , `${ subTest . name } ` ) ;
880
837
}
881
838
} ) ;
882
839
} ;
0 commit comments