Skip to content

Commit

Permalink
added multi datatyep im2col
Browse files Browse the repository at this point in the history
  • Loading branch information
TommiTerza committed Sep 17, 2024
1 parent a9365c8 commit a5dba92
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
34 changes: 24 additions & 10 deletions sw/applications/example_im2col/im2col_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,20 @@

#include "im2col_lib.h"

int output_data[OH_NCHW*OW_NCHW];
#if INPUT_DATATYPE == DMA_DATA_TYPE_BYTE
uint8_t output_data[OH_NCHW*OW_NCHW];
uint8_t* input_image_ptr = &input_image_nchw[0];
uint8_t* output_data_ptr = &output_data[0];
#elif INPUT_DATATYPE == DMA_DATA_TYPE_HALF_WORD
uint16_t output_data[OH_NCHW*OW_NCHW];
uint16_t* input_image_ptr = &input_image_nchw[0];
uint16_t* output_data_ptr = &output_data[0];
#elif INPUT_DATATYPE == DMA_DATA_TYPE_WORD
uint32_t output_data[OH_NCHW*OW_NCHW];
uint32_t* input_image_ptr = &input_image_nchw[0];
uint32_t* output_data_ptr = &output_data[0];
#endif

char im2col_done = 0;
int ifr_status;

Expand Down Expand Up @@ -155,20 +168,19 @@ int im2col_nchw_int32(uint8_t test_id, unsigned int *cycles)
else if (test_id == 1)
{
/* Iterate over each row of the output matrix. */
uint32_t* input_image_ptr = &input_image_nchw[0];
uint32_t* output_data_ptr = &output_data[0];

dma_config_flags_t res;

static dma_target_t tgt_src = {
.ptr = input_image_nchw,
.inc_d1_du = STRIDE_D1,
.type = DMA_DATA_TYPE_WORD
.type = INPUT_DATATYPE
};

static dma_target_t tgt_dst = {
.inc_d1_du = 1,
.inc_d2_du = 1
.inc_d2_du = 1,
.type = INPUT_DATATYPE
};

static dma_trans_t trans = {
Expand Down Expand Up @@ -305,6 +317,7 @@ int im2col_nchw_int32(uint8_t test_id, unsigned int *cycles)

input_image_ptr = &input_image_nchw[0] + index;
PRINTF_DEB("\n\rsrc_ptr: %x dst_ptr: %x\n\r", input_image_ptr, output_data_ptr);

tgt_src.ptr = input_image_ptr;
tgt_src.inc_d2_du = src_inc_d2;

Expand All @@ -321,7 +334,7 @@ int im2col_nchw_int32(uint8_t test_id, unsigned int *cycles)

dma_run(&trans);

output_data_ptr += N_PATCHES_H * N_PATCHES_W;
output_data_ptr += OW_NCHW;

PRINTF_DEB("\n\r");

Expand Down Expand Up @@ -388,8 +401,8 @@ int im2col_nchw_int32(uint8_t test_id, unsigned int *cycles)
/* Implementation of im2col algorithm using the dedicated Smart Peripheral Controller */
else if (test_id == 2)
{
uint32_t* input_image_ptr = &input_image_nchw[0];
uint32_t* output_data_ptr = &output_data[0];
input_image_ptr = &input_image_nchw[0];
output_data_ptr = &output_data[0];

dma_init(0);

Expand Down Expand Up @@ -420,7 +433,8 @@ int im2col_nchw_int32(uint8_t test_id, unsigned int *cycles)
.top_pad = TOP_PAD,
.bottom_pad = BOTTOM_PAD,
.adpt_pad_right = ADPT_PAD_RIGHT,
.adpt_pad_bottom = ADPT_PAD_BOTTOM
.adpt_pad_bottom = ADPT_PAD_BOTTOM,
.datatype = INPUT_DATATYPE
};

im2col_spc_trans.src = input_image_ptr;
Expand Down Expand Up @@ -470,7 +484,7 @@ int verify()
{
if (golden_im2col_nchw[i*OW_NCHW + j] != output_data[i*OW_NCHW + j])
{
PRINTF("ERROR: Golden: %d, Output: %d, at %d %d\n\r", golden_im2col_nchw[i*OW_NCHW + j], output_data[i*OW_NCHW + j], i, j);
PRINTF("ERROR: Golden: %d, Output: %d, at %d %d %x\n\r", golden_im2col_nchw[i*OW_NCHW + j], output_data[i*OW_NCHW + j], i, j, &output_data[i*OW_NCHW + j]);
errors ++;
}
}
Expand Down
3 changes: 3 additions & 0 deletions sw/applications/example_im2col/im2col_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
/* Defines which DMA channels are available to the SPC, depending on HW specifications */
#define SPC_CH_MASK 0b0001

/* Defines the datatype of the input */
#define INPUT_DATATYPE DMA_DATA_TYPE_WORD

/* Base address of the im2col SPC */
#define IM2COL_SPC_BASE_ADDR EXT_PERIPHERAL_START_ADDRESS + 0x4000

Expand Down
2 changes: 1 addition & 1 deletion sw/device/lib/drivers/im2col_spc/im2col.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ int run_im2col(im2col_trans_t trans){
IM2COL_SPC_BASE_ADDR );

/* Write the datatype */
write_register( DMA_DATA_TYPE_WORD,
write_register( trans.datatype,
IM2COL_SPC_DATA_TYPE_REG_OFFSET,
IM2COL_SPC_DATA_TYPE_DATA_TYPE_MASK,
IM2COL_SPC_DATA_TYPE_DATA_TYPE_OFFSET,
Expand Down
1 change: 1 addition & 0 deletions sw/device/lib/drivers/im2col_spc/im2col.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ typedef struct
uint32_t bottom_pad; /*!< Padding on the bottom. */
uint32_t adpt_pad_right; /*!< Adaptive padding on the right. */
uint32_t adpt_pad_bottom; /*!< Adaptive padding on the bottom. */
uint32_t datatype; /*!< Data type of the input. */
} im2col_trans_t;

/* Base address of the im2col SPC */
Expand Down

0 comments on commit a5dba92

Please sign in to comment.