parameters: (self)
docstring: analyze reduce case
docstring_summary: analyze reduce case
docstring_tokens: analyze reduce case
function: def reduce_analyze(self):
          """analyze reduce case"""
          thread_x, thread_y = 32, 32
          reduce_op = None
          for op in self.ops:
              if PrimLib.iter_type(op) == PrimLib.REDUCE:
                  if reduce_op:
                      raise RuntimeError(
                          "Not support multiply reduce op in a graph now.")
                  reduce_op = op
          if not reduce_op:
              raise RuntimeError("Wrong analyze for reduce!")
          shape = reduce_op.inputs[0].shape
          reduce_axis = reduce_op.attrs['reduce_axis']
          total_space = self.prod(shape)
          red_space = shape[reduce_axis[0]]
          for i in range(1, len(reduce_axis)):
              red_space *= shape[reduce_axis[i]]
          dtype_size = PrimLib.dtype_bytes(reduce_op.output.dtype)
  
          weight = self._cal_weight(self.ops)  # reduce + injective
          block_x = (total_space // red_space + thread_y - 1) // thread_y
          block_w = (weight + block_x - 1) // block_x
          waves = (block_x + self.MAX_BLOCK - 1) // self.MAX_BLOCK
          self.block_num = min(self.MAX_BLOCK, block_x)
          all_reduce = 10  # 1 reduce init + 3 sync + 5 bin + 1 write
          self.block_weight = (block_w + all_reduce *
                               dtype_size * thread_x * thread_y) * waves
function_tokens: def reduce_analyze ( self ) : thread_x , thread_y = 32 , 32 reduce_op = None for op in self . ops : if PrimLib . iter_type ( op ) == PrimLib . REDUCE : if reduce_op : raise RuntimeError ( "Not support multiply reduce op in a graph now." ) reduce_op = op if not reduce_op : raise RuntimeError ( "Wrong analyze for reduce!" ) shape = reduce_op . inputs [ 0 ] . shape reduce_axis = reduce_op . attrs [ 'reduce_axis' ] total_space = self . prod ( shape ) red_space = shape [ reduce_axis [ 0 ] ] for i in range ( 1 , len ( reduce_axis ) ) : red_space *= shape [ reduce_axis [ i ] ] dtype_size = PrimLib . dtype_bytes ( reduce_op . output . dtype ) weight = self . _cal_weight ( self . ops ) # reduce + injective block_x = ( total_space // red_space + thread_y - 1 ) // thread_y block_w = ( weight + block_x - 1 ) // block_x waves = ( block_x + self . MAX_BLOCK - 1 ) // self . MAX_BLOCK self . block_num = min ( self . MAX_BLOCK , block_x ) all_reduce = 10 # 1 reduce init + 3 sync + 5 bin + 1 write self . block_weight = ( block_w + all_reduce * dtype_size * thread_x * thread_y ) * waves