Skip to content

Commit

Permalink
更新benchmark函数
Browse files Browse the repository at this point in the history
  • Loading branch information
zjhellofss committed Jul 26, 2023
1 parent c71f310 commit eaf501f
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 42 deletions.
42 changes: 0 additions & 42 deletions bench/bench_exp.cpp

This file was deleted.

113 changes: 113 additions & 0 deletions bench/bench_simd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
//
// Created by fss on 23-6-14.
//

#include <benchmark/benchmark.h>
#include <armadillo>
#include "../source/layer/details/activation_sse.hpp"
static void BM_SigmoidSimd(benchmark::State& state) {
using namespace kuiper_infer;
uint32_t input_c = state.range(0);
uint32_t input_h = state.range(1);
uint32_t input_w = state.range(2);
sftensor input = std::make_shared<ftensor>(input_c, input_h, input_w);

using namespace kuiper_infer::activation;
for (auto _ : state) {
ApplySSEActivation(ActivationType::kActivationSigmoid)(input, input);
}
}

BENCHMARK(BM_SigmoidSimd)->Args({255, 80, 80})->Unit(benchmark::kMillisecond);
BENCHMARK(BM_SigmoidSimd)->Args({255, 40, 40})->Unit(benchmark::kMillisecond);
BENCHMARK(BM_SigmoidSimd)->Args({255, 20, 20})->Unit(benchmark::kMillisecond);

static void BM_SigmoidArma(benchmark::State& state) {
using namespace kuiper_infer;
uint32_t input_c = state.range(0);
uint32_t input_h = state.range(1);
uint32_t input_w = state.range(2);
sftensor input = std::make_shared<ftensor>(input_c, input_h, input_w);
input->Rand();
for (auto _ : state) {
arma::fcube input_data = input->data();
input_data = 1.f / (1.f + arma::exp(-input_data));
}
}

BENCHMARK(BM_SigmoidArma)->Args({255, 80, 80})->Unit(benchmark::kMillisecond);
BENCHMARK(BM_SigmoidArma)->Args({255, 40, 40})->Unit(benchmark::kMillisecond);
BENCHMARK(BM_SigmoidArma)->Args({255, 20, 20})->Unit(benchmark::kMillisecond);

static void BM_Relu(benchmark::State& state) {
using namespace kuiper_infer;
uint32_t input_c = state.range(0);
uint32_t input_h = state.range(1);
uint32_t input_w = state.range(2);
sftensor input = std::make_shared<ftensor>(input_c, input_h, input_w);
input->Rand();
using namespace kuiper_infer::activation;
for (auto _ : state) {
for (uint32_t j = 0; j < input->size(); ++j) {
float value = input->index(j);
input->index(j) = value > 0.f ? value : 0.f;
}
}
}

BENCHMARK(BM_Relu)->Args({255, 80, 80})->Unit(benchmark::kMillisecond);
BENCHMARK(BM_Relu)->Args({255, 40, 40})->Unit(benchmark::kMillisecond);
BENCHMARK(BM_Relu)->Args({255, 20, 20})->Unit(benchmark::kMillisecond);

static void BM_ReluSimd(benchmark::State& state) {
using namespace kuiper_infer;
uint32_t input_c = state.range(0);
uint32_t input_h = state.range(1);
uint32_t input_w = state.range(2);
sftensor input = std::make_shared<ftensor>(input_c, input_h, input_w);
input->Rand();
using namespace kuiper_infer::activation;
for (auto _ : state) {
ApplySSEActivation(ActivationType::kActivationRelu)(input, input);
}
}

BENCHMARK(BM_ReluSimd)->Args({255, 80, 80})->Unit(benchmark::kMillisecond);
BENCHMARK(BM_ReluSimd)->Args({255, 40, 40})->Unit(benchmark::kMillisecond);
BENCHMARK(BM_ReluSimd)->Args({255, 20, 20})->Unit(benchmark::kMillisecond);

static void BM_SiluArma(benchmark::State& state) {
using namespace kuiper_infer;
uint32_t input_c = state.range(0);
uint32_t input_h = state.range(1);
uint32_t input_w = state.range(2);
sftensor input = std::make_shared<ftensor>(input_c, input_h, input_w);
input->Rand();
using namespace kuiper_infer::activation;
for (auto _ : state) {
arma::fcube input_data = input->data();
input_data = input_data / (1.f + arma::exp(-input_data));
}
}

BENCHMARK(BM_SiluArma)->Args({255, 80, 80})->Unit(benchmark::kMillisecond);
BENCHMARK(BM_SiluArma)->Args({255, 40, 40})->Unit(benchmark::kMillisecond);
BENCHMARK(BM_SiluArma)->Args({255, 20, 20})->Unit(benchmark::kMillisecond);


static void BM_SiluSimd(benchmark::State& state) {
using namespace kuiper_infer;
uint32_t input_c = state.range(0);
uint32_t input_h = state.range(1);
uint32_t input_w = state.range(2);
sftensor input = std::make_shared<ftensor>(input_c, input_h, input_w);
input->Rand();
using namespace kuiper_infer::activation;
for (auto _ : state) {
ApplySSEActivation(ActivationType::kActivationSilu)(input, input);
}
}

BENCHMARK(BM_SiluSimd)->Args({255, 80, 80})->Unit(benchmark::kMillisecond);
BENCHMARK(BM_SiluSimd)->Args({255, 40, 40})->Unit(benchmark::kMillisecond);
BENCHMARK(BM_SiluSimd)->Args({255, 20, 20})->Unit(benchmark::kMillisecond);

0 comments on commit eaf501f

Please sign in to comment.