intel / webml-polyfill

Deprecated, the Web Neural Network Polyfill project has been moved to https://github.com/webmachinelearning/webnn-polyfill
Apache License 2.0
161 stars 42 forks source link

StridedSlice op support for DeepSpeech model #1019

Open miaobin opened 5 years ago

miaobin commented 5 years ago

StridedSlice in the DeepSpeech model: StridedSlice

  NNAPI ONNX clDNN MKLDNN DML MPS BNNS
Op ANEURALNETWORKS_STRIDED_SLICE Slice Not Supported Reorder DML_SLICE_OPERATOR_DESC MPSNDArrayStridedSlice Not Supported
inputs inputs: An n-D tensor, specifying the tensor to be sliced. data : T Tensor of data to extract slices from.     InputTensor: A pointer to a constant DML_TENSOR_DESC containing the description of the tensor to extract slices from.    
  begin: begin, a 1-D tensor of ANEURALNETWORKS_TENSOR_INT32. The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input0). starts : Tind 1-D tensor of starting indices of corresponding axis in axes     DimensionCount: The number of dimensions. This field determines the size of the Offsets, Sizes, and Strides arrays. This value must match the DimensionCount of the input and output tensors.    
  end: end, a 1-D tensor of ANEURALNETWORKS_TENSOR_INT32. The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input0). ends : Tind 1-D tensor of ending indices (exclusive) of corresponding axis in axes     Offsets: A pointer to a constant array of UINT containing the starting index of each dimension to slice from the input tensor.    
  strides: strides, a 1-D tensor of ANEURALNETWORKS_TENSOR_INT32. The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input0). The entries must be non-zero. axes (optional) : Tind 1-D tensor of axes that starts and ends apply to. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data).     Sizes: A pointer to a constant array of UINT containing the size of each dimension of the slice, in elements. The values in this array must match the sizes specified in the output tensor.    
  begin_mask: begin_mask, an ANEURALNETWORKS_INT32 scalar. If the ith bit of begin_mask is set, begin[i] is ignored and the fullest possible range in that dimension is used instead. steps (optional) : Tind 1-D tensor of slice step of corresponding axis in axes. Default to 1.     Strides: A pointer to a constant array of UINT containing the element strides for each dimension in the slice.    
  end_mask: end_mask, an ANEURALNETWORKS_INT32 scalar. If the ith bit of end_mask is set, end[i] is ignored and the fullest possible range in that dimension is used instead.            
  shrink_axis_mask: shrink_axis_mask, an ANEURALNETWORKS_INT32 scalar. If the ith bit of shrink_axis_mask is set, the ith dimension specification shrinks the dimensionality by 1, taking on the value at index begin[i]. In this case, the ith specification must define a slice of size 1, e.g. begin[i] = x, end[i] = x + 1.            
outputs outputs: A tensor of the same OperandCode as input0 and rank (n - k), where k is the number of bits set in shrink_axis_mask. For a ANEURALNETWORKS_TENSOR_QUANT8_ASYMM tensor, the scale and zeroPoint must be the same as input0. output : T Sliced data tensor.     OutputTensor: A pointer to a constant DML_TENSOR_DESC containing the description of the tensor to write the sliced data results to.    

Now, StridedSlice is working well with WebGL backend. And I am trying to support it with WASM backend. Because only four dimensions tensor is supported in tflite, I need do some workaround.

miaobin commented 5 years ago

I can only find Slice op form the website of ONNX and DML. @fujunwei @lisa0314 Please help fill in above table, thanks!

lisa0314 commented 5 years ago

@miaobin BNNS has been updated. Thanks!

ibelem commented 5 years ago

@fujunwei Please update MPSNDArrayStridedSlice which is incorrect.

fujunwei commented 5 years ago

Yes, it can extract a subset of source array using specified slice strides, but it's MPSKernel not MPSNNGraph node, it's a bit complicated to support in current design.

miaobin commented 5 years ago

Update the table.

pinzhenx commented 5 years ago

MKLDNN updated. It can be implemented by primitive reorder on submemory.

ibelem commented 5 years ago

@pinzhenx Good to know, thanks for the sharing! :) @lisa0314