Closed ibelem closed 4 years ago
The root cause was that converting inputTensor of none typedArray to inputTensor of specified typedArray consumed some timing.
tensorArray = getTensorArray(src, options);
const typedArray = this._getInputTensorTypedArray();
this._inputTensor = [new typedArray(tensorArray)]; # This converting will consume some timing
Full Screen (WebNN SS Examples) | Before fixing | After fixing |
---|---|---|
FPS | FPS | |
DeepLab 224 | 12 | 16 |
DeepLab 257 Atrous | 12 | 17 |
The inference time after fixing were similar to ones before refactoring.
Thanks for documenting the root cause. So the learning is to avoid creating typed array in hot loop, is that correct?
I did type converting by
typedArray(tensorArray)
Here tensorArray is just an array from
new Array([size])
it's not ArrayBuffer type, while 'typedArray ' could be Float32Array or Uint8Array on condition.
We need avoid to type converting for those array of large size in hot loop on Camera scene , thanks @huningxin
Creation of typed array from array is expensive. Thanks for fixing that.
When trying to integrate @BruceDai's latest refactored BaseRunner.js, the FPS drops 2 (9->7) in WebNN meeting (Deeplab 257 Atrous) on i7-6700 + Ubuntu desktop.
This issue also occurs on WebML SS Examples (Linux Laptop). Good news is the inference time is faster than before.