api.h 4.7 KB
Newer Older
H
hanbuhe 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

#pragma once

17
#include <string>
Z
zhangyang 已提交
18 19
#include "fpga/common/fpga_common.h"
#include "fpga/common/pe.h"
Z
zhangyang 已提交
20
#include "framework/tensor.h"
H
hanbuhe 已提交
21

Z
zhangyang 已提交
22
namespace paddle_mobile {
H
hanbuhe 已提交
23 24
namespace fpga {

25 26 27 28 29 30
void format_image(framework::Tensor* image_tensor);
void format_ofm(framework::Tensor* ofm_tensor);
void format_fp16_ofm(framework::Tensor* ofm_tensor);  // only allocate memory
void format_fp16_ofm(framework::Tensor* ofm_tensor, framework::DDim dims);
void format_fp32_ofm(framework::Tensor* ofm_tensor);

Z
zhangyang 已提交
31
float filter_find_max(framework::Tensor* filter_tensor);
32 33 34
int get_filter_num_per_div(framework::Tensor* filter_tensor, int group_num);
int get_deconv_filter_num_per_div(framework::Tensor* filter_tensor,
                                  int group_num, int stride);
Z
zhangyang 已提交
35

36 37
int get_plit_num(framework::Tensor* filter_tensor);
int get_deconv_plit_num(framework::Tensor* filter_tensor, int stride);
38

39
int get_aligned_filter_element_num(int chw);
Z
zhangyang 已提交
40 41
void format_filter(framework::Tensor* filter_tensor, float max_value,
                   int group_num);
Z
zhangyang 已提交
42
void format_fc_filter(framework::Tensor* filter_tensor, float max_value);
43 44 45
void format_bias_scale_array(float** bias_scale_array,
                             int element_num_per_division, int num);
void format_bias_array(float** bias_array, int num);
Z
zhangyang 已提交
46
void format_concat_output(framework::Tensor* out, int height, int width,
47 48
                          int image_num, uint32_t* channel_num);

Z
zhangyang 已提交
49 50
void fill_split_arg(struct SplitConvArgs* arg, framework::Tensor* input,
                    framework::Tensor* out, framework::Tensor* filter,
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
                    ActivationType activation_enable,
                    int16_t leaky_relu_negative_slope, int group_num,
                    int stride_h, int stride_w, int padding_h, int padding_w,
                    float* bs_ptr);
void fill_deconv_arg(struct DeconvArgs* arg, framework::Tensor* input,
                     framework::Tensor* out, framework::Tensor* filter,
                     ActivationType activation_enable,
                     int16_t leaky_relu_negative_slope, int group_num,
                     int stride_h, int stride_w, int padding_h, int padding_w,
                     float* bs_ptr);
void fill_dwconv_arg(struct DWconvArgs* arg, framework::Tensor* input,
                     framework::Tensor* out, framework::Tensor* filter,
                     ActivationType activation_enable,
                     int16_t leaky_relu_negative_slope, int stride_h,
                     int stride_w, int padding_h, int padding_w,
                     float* bias_ptr);
void fill_DWDeconv_arg(struct DWDeconvArgs* arg, framework::Tensor* input,
                       framework::Tensor* out, framework::Tensor* filter,
                       ActivationType activation_enable,
                       int16_t leaky_relu_negative_slope, int stride_h,
                       int stride_w, int padding_h, int padding_w,
                       float* bs_ptr);

void format_deconv_filter(framework::Tensor* filter_tensor, float max_value,
                          int group_num, int stride);
void format_dwconv_filter(framework::Tensor* filter_tensor, float* scale_ptr);
void format_conv_data(framework::Tensor* filter_tensor,
                      framework::Tensor* ofm_tensor, float** bs_ptr, int group);
void format_deconv_data(framework::Tensor* filter_tensor,
                        framework::Tensor* ofm_tensor, float** bs_ptr,
                        int group, int sub_conv_n);
void format_dwconv_data(framework::Tensor* filter_tensor,
                        framework::Tensor* ofm_tensor, float* scale_ptr,
                        float** bias_ptr);
void format_DWDeconv_data(framework::Tensor* filter_tensor,
                          framework::Tensor* ofm_tensor, float** bs_ptr,
                          int group, int sub_conv_n);

template <typename Dtype>
void savefile(std::string filename, void* buffer, int dataSize, Dtype tmp) {
  float data;
  std::ofstream out(filename.c_str());
  for (int i = 0; i < dataSize; ++i) {
    data = (((Dtype*)buffer)[i]);  // NOLINT
    out << data << std::endl;
  }
  out.close();
  return;
}
100

H
hanbuhe 已提交
101
}  // namespace fpga
Z
zhangyang 已提交
102
}  // namespace paddle_mobile