Skip to content

Commit

Permalink
Add new Conv2D layer to benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
d-kicinski committed Apr 26, 2021
1 parent 4eb4e68 commit f48f025
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions benchmark/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <chrono>
#include <tensor/nn/conv2d.hpp>
#include <tensor/nn/conv2d_naive.hpp>
#include <tensor/nn/conv2d_im2col.hpp>
#include <tensor/nn/feed_forward.hpp>
#include <tensor/tensor.hpp>

Expand Down Expand Up @@ -74,32 +75,55 @@ auto benchmark_linear() -> void
}
}

auto benchmark_conv2d() -> void
auto benchmark_conv2d_naive() -> void
{
auto input = ts::Tensor<float, 4>(16, 64, 64, 3);
auto output = ts::Tensor<float, 4>();
{
auto layer = ts::Conv2D::create(3, 24, 3, 1,
auto layer = ts::naive::Conv2D::create(3, 24, 3, 1,
ts::Activation::NONE, false);
auto time_fw = benchmark([&](){ output = layer(input); }, 100);
auto time_bw = benchmark([&](){ layer.backward(output); }, 100);
std::cout << "Conv2D::forward " << time_fw << " us" << std::endl;
std::cout << "Conv2D::backward " << time_bw << " us" << std::endl;
std::cout << "naive::Conv2D::forward " << time_fw << " us" << std::endl;
std::cout << "naive::Conv2D::backward " << time_bw << " us" << std::endl;
}
{
auto layer = ts::Conv2D::create(3, 24, 3, 1,
auto layer = ts::naive::Conv2D::create(3, 24, 3, 1,
ts::Activation::RELU, false);
auto time_fw = benchmark([&](){ output = layer(input); }, 100);
auto time_bw = benchmark([&](){ layer.backward(output); }, 100);
std::cout << "Conv2D[ReLU]::forward " << time_fw << " us" << std::endl;
std::cout << "Conv2D[ReLU]::backward " << time_bw << " us" << std::endl;
std::cout << "naive::Conv2D[ReLU]::forward " << time_fw << " us" << std::endl;
std::cout << "naive::Conv2D[ReLU]::backward " << time_bw << " us" << std::endl;
}
}

auto benchmark_conv2d_im2col() -> void
{
auto input = ts::Tensor<float, 4>(16, 3, 64, 64);
auto output = ts::Tensor<float, 4>();
{
auto layer = ts::im2col::Conv2D::create(3, 24, 3, 1, 0, 1,
ts::Activation::NONE, false);
auto time_fw = benchmark([&](){ output = layer(input); }, 100);
auto time_bw = benchmark([&](){ layer.backward(output); }, 100);
std::cout << "im2col::Conv2D::forward " << time_fw << " us" << std::endl;
std::cout << "im2col::Conv2D::backward " << time_bw << " us" << std::endl;
}
{
auto layer = ts::im2col::Conv2D::create(3, 24, 3, 1, 0, 1,
ts::Activation::RELU, false);
auto time_fw = benchmark([&](){ output = layer(input); }, 100);
auto time_bw = benchmark([&](){ layer.backward(output); }, 100);
std::cout << "im2col::Conv2D[ReLU]::forward " << time_fw << " us" << std::endl;
std::cout << "im2col::Conv2D[ReLU]::backward " << time_bw << " us" << std::endl;
}
}

auto main() -> int
{
benchmark_matrix_multiply();
benchmark_linear();
benchmark_conv2d();
benchmark_conv2d_naive();
benchmark_conv2d_im2col();
return 0;
}

0 comments on commit f48f025

Please sign in to comment.