Platform/ECM3532/M3/framework/executor/src/reorder_conv2d_kernel.c
//[Cout H W Cin]
/* This function reorders a kernel in the m3 [Cout H W Cin] to the dsp [Cout Cin H W] format.  
 * This will be done by the compiler where by it will produce different kernel formats 
 * for the M3 and the dsp.  But since this is not yet in place, this function has been created.
 * As this fuunction will be removed eventually, no attempt is made to optimize its speed.
 */
[Cout H W Cin]
This function reorders a kernel in the m3 [Cout H W Cin] to the dsp [Cout Cin H W] format.
This will be done by the compiler where by it will produce different kernel formats
for the M3 and the dsp.  But since this is not yet in place, this function has been created.
As this fuunction will be removed eventually, no attempt is made to optimize its speed.
[ Cout H W Cin ] This function reorders a kernel in the m3 [ Cout H W Cin ] to the dsp [ Cout Cin H W ] format . This will be done by the compiler where by it will produce different kernel formats for the M3 and the dsp . But since this is not yet in place this function has been created . As this fuunction will be removed eventually no attempt is made to optimize its speed .
void reorder_conv2d_kernel(int8_t *in, int8_t *out, uint16_t H, uint16_t W, uint16_t C_in, uint16_t C_out)
{
  uint16_t kh, kw, kc_in, kc_out;
  uint32_t dsp_linear_address, m3_linear_address;
  for(kc_out = 0; kc_out < C_out; kc_out++){
    for (kh = 0; kh < H; kh++){
      for (kw = 0; kw < W; kw++){
        for (kc_in = 0; kc_in < C_in; kc_in++){
	  dsp_linear_address = kw + W*(kh + H*(kc_in + kc_out*C_in)); 
          m3_linear_address = kc_in + C_in*(kw + W * (kh + kc_out * H)); 
          *(out + dsp_linear_address) = (int8_t)(*(in + m3_linear_address));
	}
      }
    }
  }
}
void reorder_conv2d_kernel ( int8_t * in , int8_t * out , uint16_t H , uint16_t W , uint16_t C_in , uint16_t C_out ) { uint16_t kh , kw , kc_in , kc_out ; uint32_t dsp_linear_address , m3_linear_address ; for ( kc_out = 0 ; kc_out < C_out ; kc_out ++ ) { for ( kh = 0 ; kh < H ; kh ++ ) { for ( kw = 0 ; kw < W ; kw ++ ) { for ( kc_in = 0 ; kc_in < C_in ; kc_in ++ ) { dsp_linear_address = kw + W * ( kh + H * ( kc_in + kc_out * C_in ) ) ; m3_linear_address = kc_in + C_in * ( kw + W * ( kh + kc_out * H ) ) ; * ( out + dsp_linear_address ) = ( int8_t ) ( * ( in + m3_linear_address ) ) ; } } } } }
[Cout H W Cin]
This function reorders a kernel in the m3 [Cout H W Cin] to the dsp [Cout Cin H W] format.
[ Cout H W Cin ] This function reorders a kernel in the m3 [ Cout H W Cin ] to the dsp [ Cout Cin H W ] format .
/* in = array of input kernel values in m3 format */ /* out = reordered array of kernel values in dsp format */ /* H = height of kernel */ /* W = width of kernel */ /* C_in = # of channels for a kernel */ /* C_out = # of kernels */ //dsp[kc_out, kc_in, kh, kw] = m3[kc_out, kh, kw, kc_in] //dsp_linear_address = kw + kh*W + kc_in*H*W + kc_out*C_in*H*W;  //m3_linear_address = kc_in + kw*C_in + kh*C_in*W + k_cout*W*H*C_in;