From a87bbe6545472fd9037906136206c6abf2f80495 Mon Sep 17 00:00:00 2001 From: Shridhar Rasal Date: Thu, 16 Aug 2018 11:24:08 +0530 Subject: [PATCH] darknet: odla: align naming conventions - update naming changes for upsampling layer - fix some compilation issues with c99 --- src/converter_layer.c | 23 ++++++++++++++--------- src/odla_layer.c | 10 ++++++---- src/upsample_odla_layer.c | 14 +++++++------- src/upsample_odla_layer.h | 4 ++-- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/converter_layer.c b/src/converter_layer.c index 0ea393812fe..7b5291e0460 100644 --- a/src/converter_layer.c +++ b/src/converter_layer.c @@ -31,9 +31,11 @@ converter_layer make_converter_layer(int batch, int w, int h, int c, void convert_nchw_to_nhwc(uint8_t *in, int w, int h, int c, uint8_t *out) { - for (int i = 0; i < c; i++) { - for (int j = 0; j < h; j++) { - for (int k = 0; k < w; k++) { + int i, j, k; + + for (i = 0; i < c; i++) { + for (j = 0; j < h; j++) { + for (k = 0; k < w; k++) { out[j*w*c + c*k + i] = in[w*h*i + w*j + k]; } } @@ -42,9 +44,11 @@ void convert_nchw_to_nhwc(uint8_t *in, int w, int h, int c, uint8_t *out) void convert_fd_to_nchw(float *in, int w, int h, int c, float *out) { - for (int i = 0; i < c; i++) { - for (int j = 0; j < h; j++) { - for (int k = 0; k < w; k++) { + int i, j, k; + + for (i = 0; i < c; i++) { + for (j = 0; j < h; j++) { + for (k = 0; k < w; k++) { out[w*h*i + w*j + k] = in[w*32*h*(i/32) + w*32*j + i]; } } @@ -54,13 +58,14 @@ void convert_fd_to_nchw(float *in, int w, int h, int c, float *out) static void odla_dump_image_data(uint8_t *data, int w, int h, int c) { FILE *fp; + int i, j, k; fp = fopen("image_input.txt", "w"); fprintf(fp, "blobs {\n"); - for (int i = 0; i < c; i++) { - for (int j = 0; j < h; j++) { - for (int k = 0; k < w; k++) { + for (i = 0; i < c; i++) { + for (j = 0; j < h; j++) { + for (k = 0; k < w; k++) { fprintf(fp, " double_data: %u\n", data[w*h*i + w*j + k]); } } diff --git a/src/odla_layer.c b/src/odla_layer.c index 5a964fee594..865084768a5 100644 --- a/src/odla_layer.c +++ b/src/odla_layer.c @@ -25,6 +25,7 @@ extern int odla_output_size(void *runtime, int index); static void odla_dump_data(const char *filename, int8_t *data, int w, int h, int c) { FILE *fp; + int i, j, k; fp = fopen(filename, "w"); @@ -32,9 +33,9 @@ static void odla_dump_data(const char *filename, int8_t *data, int w, int h, int unsigned int surface_stride = line_stride * h; fprintf(fp, "blobs {\n"); - for (int i = 0; i < c; i++) { - for (int j = 0; j < h; j++) { - for (int k = 0; k < w; k++) { + for (i = 0; i < c; i++) { + for (j = 0; j < h; j++) { + for (k = 0; k < w; k++) { int surface_index = i / 32; fprintf(fp, " double_data: %d\n", data[surface_stride*surface_index + line_stride*j + 32*k + i%32]); } @@ -118,6 +119,7 @@ void resize_odla_layer(layer *l, int w, int h) void forward_odla_layer(const layer l, network net) { int8_t *input = (int8_t *)l.input_tensors[l.input_tensor].buffer; + int i; fprintf(stderr, "copying input to tensor index %d\n", l.input_tensor); @@ -139,7 +141,7 @@ void forward_odla_layer(const layer l, network net) fprintf(stderr, "%s %d: Executing in ODLA... \n", __func__, __LINE__); odla_execute(l.odla_runtime, l.odla_instance); - for (int i = 0; i < l.num_output; i++) { + for (i = 0; i < l.num_output; i++) { char filename[80]; snprintf(filename, sizeof(filename), "output_%02d_%02d.dimg", l.layer_index, i); odla_dump_data(filename, (int8_t *)l.output_tensors[i].buffer, l.output_tensors[i].w, l.output_tensors[i].h, l.output_tensors[i].c); diff --git a/src/upsample_odla_layer.c b/src/upsample_odla_layer.c index 05c38e133c6..8426d9a8d65 100644 --- a/src/upsample_odla_layer.c +++ b/src/upsample_odla_layer.c @@ -6,7 +6,7 @@ layer make_upsample_odla_layer(int batch, int w, int h, int c, int stride, int output_layer, int tensor) { layer l = {0}; - l.type = UPSAMPLE; + l.type = UPSAMPLE_ODLA; l.batch = batch; l.w = w; l.h = h; @@ -21,8 +21,8 @@ layer make_upsample_odla_layer(int batch, int w, int h, int c, int stride, int o l.forward = forward_upsample_odla_layer; - if(l.reverse) fprintf(stderr, "downsample_dla %2dx %4d x%4d x%4d -> %4d x%4d x%4d\n", stride, w, h, c, l.out_w, l.out_h, l.out_c); - else fprintf(stderr, "upsample_dla %2dx %4d x%4d x%4d -> %4d x%4d x%4d\n", stride, w, h, c, l.out_w, l.out_h, l.out_c); + if(l.reverse) fprintf(stderr, "downsample_odla %2dx %4d x%4d x%4d -> %4d x%4d x%4d\n", stride, w, h, c, l.out_w, l.out_h, l.out_c); + else fprintf(stderr, "upsample_odla %2dx %4d x%4d x%4d -> %4d x%4d x%4d\n", stride, w, h, c, l.out_w, l.out_h, l.out_c); return l; } @@ -39,7 +39,7 @@ void *cubecpy(void *dst, const void *src){ return dst; } -void upsample_dla(int8_t *in, int w, int h, int c, int batch, int stride, int forward, int8_t *out) +void upsample_odla(int8_t *in, int w, int h, int c, int batch, int stride, int forward, int8_t *out) { int i, j, k, b; @@ -47,8 +47,8 @@ void upsample_dla(int8_t *in, int w, int h, int c, int batch, int stride, int fo for(k = 0; k < c; ++k){ for(j = 0; j < h*stride; ++j){ for(i = 0; i < w*stride; ++i){ - int in_index = b*w*h*c*ATOMIC_CUBE + k*w*h + (j/stride)*w + i/stride; - int out_index = b*w*h*c*stride*stride*ATOMIC_CUBE + k*w*h*stride*stride + j*w*stride + i; + int in_index = b*w*h*c*ATOMIC_CUBE + k*w*h*ATOMIC_CUBE + (j/stride)*w*ATOMIC_CUBE + i/stride*ATOMIC_CUBE; + int out_index = b*w*h*c*stride*stride*ATOMIC_CUBE + k*w*h*stride*stride*ATOMIC_CUBE + j*w*stride*ATOMIC_CUBE + i*ATOMIC_CUBE; if(forward) cubecpy(out + out_index, in + in_index); } } @@ -64,5 +64,5 @@ void forward_upsample_odla_layer(const layer l, network net) output_layer = &net.layers[l.upsample_output_layer]; output = output_layer->output_tensors[l.upsample_output_tensor].buffer; - upsample_dla(net.input_i8, l.w, l.h, l.c, l.batch, l.stride, 1, output); + upsample_odla(net.input_i8, l.w, l.h, l.c, l.batch, l.stride, 1, output); } diff --git a/src/upsample_odla_layer.h b/src/upsample_odla_layer.h index 7050c190490..7ec95add7d1 100644 --- a/src/upsample_odla_layer.h +++ b/src/upsample_odla_layer.h @@ -1,5 +1,5 @@ -#ifndef UPSAMPLE_DLA_LAYER_H -#define UPSAMPLE_DLA_LAYER_H +#ifndef UPSAMPLE_ODLA_LAYER_H +#define UPSAMPLE_ODLA_LAYER_H #include "darknet.h" #define ATOMIC_CUBE 32