One: Compiler FE: Convert StridedSlice to Reshape

Created on 16 Jul 2021  路  5Comments  路  Source: Samsung/ONE

WHAT

StridedSlice can be converted into Reshape, e.g.,

A = input of shape [1, 1, 1, 32]
B = StridedSlice(A, begin =[0,0,0,0], end=[1,1,1,32], shrinkAxisMask=0b0001) 

is same with

A = input of shape [1, 1, 1, 32]
C = Reshape(A, [1,1,32])

WHY

In backend, implementation of Reshape is generally simpler than that of strided_slice.

Therefore, converting strided_slice to reshape in this case could generally improve performance.

Most helpful comment

Where to implement

I found

https://github.com/Samsung/ONE/blob/2dc8f730a5184f96a59b0cf57833d0228f8e1741/compiler/circle2circle/src/Circle2Circle.cpp#L198-L202

Likewise, can I make the following option?

  arser.add_argument("--substitute_strided_slice_to_reshape")

All 5 comments

Condition

With a op below,

  • A = input
  • B = StridedSlice(A, ...)

If all conditions below are true

  • begin[i] == 0
  • end[i] = A.dim[i]
  • shrinkAxisMask[s] == 1 (s'th bit is 1)
  • end[s] = 1

Convert strided_slice to the following Reshape

  • Reshape(A, new_shape)

    • d = 0

    • for 0 <= x < A.shape.rank()



      • if x == s, continue


      • else new_shape[d++] = A.shape.dim[x]



Where to implement

I found

https://github.com/Samsung/ONE/blob/2dc8f730a5184f96a59b0cf57833d0228f8e1741/compiler/circle2circle/src/Circle2Circle.cpp#L198-L202

Likewise, can I make the following option?

  arser.add_argument("--substitute_strided_slice_to_reshape")

@hyunsik-yoon , please add a test in circle2circle-dredd-recipe-test to check it's working.

/cc @jinevening This optimization is enable GRU we're trying to enable these days.

all done.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mhs4670go picture mhs4670go  路  3Comments

binarman picture binarman  路  3Comments

kishcs picture kishcs  路  3Comments

jinevening picture jinevening  路  3Comments

mhs4670go picture mhs4670go  路  4Comments