Skip to content

Commit

Permalink
Add print statements for 4 dimensions benchmark (#5148)
Browse files Browse the repository at this point in the history
  • Loading branch information
Deepdive543443 authored Nov 15, 2023
1 parent 4136de3 commit 465debe
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
3 changes: 3 additions & 0 deletions benchmark/benchncnn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ static std::vector<ncnn::Mat> parse_shape_list(char* s)
const std::vector<int>& shape = shapes[i];
switch (shape.size())
{
case 4:
mats.push_back(ncnn::Mat(shape[0], shape[1], shape[2], shape[3]));
break;
case 3:
mats.push_back(ncnn::Mat(shape[0], shape[1], shape[2]));
break;
Expand Down
52 changes: 52 additions & 0 deletions src/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
#include "layer/convolutiondepthwise.h"
#include "layer/deconvolution.h"
#include "layer/deconvolutiondepthwise.h"
#include "layer/convolution3d.h"
#include "layer/convolutiondepthwise3d.h"
#include "layer/deconvolution3d.h"
#include "layer/deconvolutiondepthwise3d.h"

#include <stdio.h>
#endif // NCNN_BENCHMARK
Expand Down Expand Up @@ -111,6 +115,10 @@ void benchmark(const Layer* layer, const Mat& bottom_blob, Mat& top_blob, double
{
sprintf(in_shape_str, "[%3d, %3d, %3d *%d]", bottom_blob.w, bottom_blob.h, bottom_blob.c, bottom_blob.elempack);
}
if (bottom_blob.dims == 4)
{
sprintf(in_shape_str, "[%3d, %3d, %3d, %3d *%d]", bottom_blob.w, bottom_blob.h, bottom_blob.d, bottom_blob.c, bottom_blob.elempack);
}

if (top_blob.dims == 1)
{
Expand All @@ -124,6 +132,10 @@ void benchmark(const Layer* layer, const Mat& bottom_blob, Mat& top_blob, double
{
sprintf(out_shape_str, "[%3d, %3d, %3d *%d]", top_blob.w, top_blob.h, top_blob.c, top_blob.elempack);
}
if (top_blob.dims == 4)
{
sprintf(out_shape_str, "[%3d, %3d, %3d, %3d *%d]", top_blob.w, top_blob.h, top_blob.d, top_blob.c, top_blob.elempack);
}

fprintf(stderr, " | %22s -> %-22s", in_shape_str, out_shape_str);

Expand Down Expand Up @@ -159,6 +171,46 @@ void benchmark(const Layer* layer, const Mat& bottom_blob, Mat& top_blob, double
((DeconvolutionDepthWise*)layer)->stride_w,
((DeconvolutionDepthWise*)layer)->stride_h);
}
else if (layer->type == "Convolution3D")
{
fprintf(stderr, " kernel: %1d x %1d x %1d stride: %1d x %1d x %1d",
((Convolution3D*)layer)->kernel_w,
((Convolution3D*)layer)->kernel_h,
((Convolution3D*)layer)->kernel_d,
((Convolution3D*)layer)->stride_w,
((Convolution3D*)layer)->stride_h,
((Convolution3D*)layer)->stride_d);
}
else if (layer->type == "ConvolutionDepthWise3D")
{
fprintf(stderr, " kernel: %1d x %1d x %1d stride: %1d x %1d x %1d",
((ConvolutionDepthWise3D*)layer)->kernel_w,
((ConvolutionDepthWise3D*)layer)->kernel_h,
((ConvolutionDepthWise3D*)layer)->kernel_d,
((ConvolutionDepthWise3D*)layer)->stride_w,
((ConvolutionDepthWise3D*)layer)->stride_h,
((ConvolutionDepthWise3D*)layer)->stride_d);
}
else if (layer->type == "Deconvolution3D")
{
fprintf(stderr, " kernel: %1d x %1d x %1d stride: %1d x %1d x %1d",
((Deconvolution3D*)layer)->kernel_w,
((Deconvolution3D*)layer)->kernel_h,
((Deconvolution3D*)layer)->kernel_d,
((Deconvolution3D*)layer)->stride_w,
((Deconvolution3D*)layer)->stride_h,
((Deconvolution3D*)layer)->stride_d);
}
else if (layer->type == "DeconvolutionDepthWise3D")
{
fprintf(stderr, " kernel: %1d x %1d x %1d stride: %1d x %1d x %1d",
((DeconvolutionDepthWise3D*)layer)->kernel_w,
((DeconvolutionDepthWise3D*)layer)->kernel_h,
((DeconvolutionDepthWise3D*)layer)->kernel_d,
((DeconvolutionDepthWise3D*)layer)->stride_w,
((DeconvolutionDepthWise3D*)layer)->stride_h,
((DeconvolutionDepthWise3D*)layer)->stride_d);
}
fprintf(stderr, "\n");
}

Expand Down
1 change: 1 addition & 0 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ int NetPrivate::forward_layer(int layer_index, std::vector<Mat>& blob_mats, cons
bottom_blob.dims = blob_mats[bottom_blob_index].dims;
bottom_blob.w = blob_mats[bottom_blob_index].w;
bottom_blob.h = blob_mats[bottom_blob_index].h;
bottom_blob.d = blob_mats[bottom_blob_index].d;
bottom_blob.c = blob_mats[bottom_blob_index].c;
bottom_blob.elempack = blob_mats[bottom_blob_index].elempack;
bottom_blob.elemsize = blob_mats[bottom_blob_index].elemsize;
Expand Down

0 comments on commit 465debe

Please sign in to comment.