Skip to content

Commit

Permalink
增加deconv算子
Browse files Browse the repository at this point in the history
  • Loading branch information
zjhellofss committed Aug 2, 2023
1 parent 5a67527 commit cf332b5
Show file tree
Hide file tree
Showing 9 changed files with 498 additions and 99 deletions.
54 changes: 51 additions & 3 deletions bench/bench_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

// Created by fushenshen on 2023/3/15.

#include <benchmark/benchmark.h>
#include "../source/layer/details/convolution.hpp"
#include "../source/layer/details/winograd.hpp"
#include "runtime/runtime_ir.hpp"

static void BM_Convolutionk3x3s1x1(benchmark::State& state) {
using namespace kuiper_infer;
Expand All @@ -46,8 +47,8 @@ static void BM_Convolutionk3x3s1x1(benchmark::State& state) {
std::vector<sftensor> outputs(1);
std::vector<sftensor> inputs;
inputs.push_back(input);
ConvolutionLayer conv_layer(kernel_count, channels, 3, 3, 0, 0, 1, 1, 1,
false);
ConvolutionLayer conv_layer(ConvType::OpConv, kernel_count, channels, 3, 3, 0,
0, 1, 1, 1, false);
conv_layer.set_weights(weights);
for (auto _ : state) {
conv_layer.Forward(inputs, outputs);
Expand All @@ -73,3 +74,50 @@ BENCHMARK(BM_Convolutionk3x3s1x1)
BENCHMARK(BM_Convolutionk3x3s1x1)
->Args({512, 256, 20, 20})
->Unit(benchmark::kMillisecond);

static void BM_DeConvolutionk3x3s1x1(benchmark::State& state) {
using namespace kuiper_infer;

uint32_t kernel_count = state.range(0);
uint32_t channels = state.range(1);
uint32_t rows = state.range(2);
uint32_t cols = state.range(3);

sftensor input = std::make_shared<ftensor>(channels, rows, cols);
input->Fill(1.f);

std::vector<float> weight_values(kernel_count * channels * 3 * 3);
for (uint32_t k = 0; k < kernel_count * channels * 3 * 3; ++k) {
weight_values.push_back(float(k % 31));
}

std::vector<sftensor> outputs(1);
std::vector<sftensor> inputs;
inputs.push_back(input);
ConvolutionLayer conv_layer(ConvType::OpDeconv, kernel_count, channels, 3, 3,
0, 0, 1, 1, 1, false);
conv_layer.set_weights(weight_values);
for (auto _ : state) {
conv_layer.Forward(inputs, outputs);
}
}

BENCHMARK(BM_DeConvolutionk3x3s1x1)
->Args({32, 3, 320, 320})
->Unit(benchmark::kMillisecond);

BENCHMARK(BM_DeConvolutionk3x3s1x1)
->Args({64, 32, 160, 160})
->Unit(benchmark::kMillisecond);

BENCHMARK(BM_DeConvolutionk3x3s1x1)
->Args({128, 64, 80, 80})
->Unit(benchmark::kMillisecond);

BENCHMARK(BM_DeConvolutionk3x3s1x1)
->Args({256, 128, 40, 40})
->Unit(benchmark::kMillisecond);

BENCHMARK(BM_DeConvolutionk3x3s1x1)
->Args({512, 256, 20, 20})
->Unit(benchmark::kMillisecond);
16 changes: 8 additions & 8 deletions include/layer/abstract/param_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

// Created by fss on 22-11-13.

#ifndef KUIPER_INFER_SOURCE_LAYER_PARAM_LAYER_HPP_
Expand All @@ -28,7 +28,7 @@
namespace kuiper_infer {
class ParamLayer : public Layer {
public:
explicit ParamLayer(const std::string &layer_name);
explicit ParamLayer(const std::string& layer_name);

/**
* 初始化权重空间
Expand All @@ -54,39 +54,39 @@ class ParamLayer : public Layer {
* 返回权重参数
* @return 权重参数
*/
const std::vector<std::shared_ptr<Tensor<float>>> &weights() const override;
const std::vector<std::shared_ptr<Tensor<float>>>& weights() const override;

/**
* 返回偏移参数
* @return 偏移参数
*/
const std::vector<std::shared_ptr<Tensor<float>>> &bias() const override;
const std::vector<std::shared_ptr<Tensor<float>>>& bias() const override;

/**
* 设置权重参数
* @param weights 权重参数
*/
void set_weights(const std::vector<float> &weights) override;
void set_weights(const std::vector<float>& weights) override;

/**
* 设置偏移量参数
* @param bias 偏移量参数
*/
void set_bias(const std::vector<float> &bias) override;
void set_bias(const std::vector<float>& bias) override;

/**
* 设置权重参数
* @param weights 权重参数
*/
void set_weights(
const std::vector<std::shared_ptr<Tensor<float>>> &weights) override;
const std::vector<std::shared_ptr<Tensor<float>>>& weights) override;

/**
* 设置偏移量参数
* @param bias 偏移量参数
*/
void set_bias(
const std::vector<std::shared_ptr<Tensor<float>>> &bias) override;
const std::vector<std::shared_ptr<Tensor<float>>>& bias) override;

protected:
std::vector<std::shared_ptr<Tensor<float>>> weights_;
Expand Down
1 change: 1 addition & 0 deletions include/status_code.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ enum class ParseParameterAttrStatus {
kParameterMissingResizeMode = 15,
kParameterMissingDilation = 16,
kParameterMissingPaddingMode = 16,
kParameterMissingOutputPadding = 17,

kAttrMissingBias = 21,
kAttrMissingWeight = 22,
Expand Down
Loading

0 comments on commit cf332b5

Please sign in to comment.