From 97b7c913dad91c45aa074d78f35cec6fb68efea1 Mon Sep 17 00:00:00 2001 From: zhangyang Date: Mon, 3 Sep 2018 11:12:27 +0800 Subject: [PATCH] format data for FPGA track --- src/fpga/api.h | 2 ++ src/fpga/bias_scale.cpp | 60 ++++++++++++++++++++++++++++++++++++++++ src/fpga/bias_scale.h | 30 ++++++++++++++++++++ src/fpga/filter.cpp | 61 +++++++++++++++++++++++++++++++++++++++++ src/fpga/filter.h | 34 +++++++++++++++++++++++ src/fpga/image.cpp | 13 +++++++++ src/fpga/image.h | 13 +++++++++ 7 files changed, 213 insertions(+) create mode 100644 src/fpga/bias_scale.cpp create mode 100644 src/fpga/bias_scale.h create mode 100644 src/fpga/filter.cpp create mode 100644 src/fpga/filter.h create mode 100644 src/fpga/image.cpp create mode 100644 src/fpga/image.h diff --git a/src/fpga/api.h b/src/fpga/api.h index 0823e19a7f..73db2bfbda 100644 --- a/src/fpga/api.h +++ b/src/fpga/api.h @@ -174,5 +174,7 @@ int ComputeFpgaConv(const struct ConvArgs& args); int ComputeFpgaPool(const struct PoolingArgs& args); int ComputeFpgaEWAdd(const struct EWAddArgs& args); +static inline int align_to_x(int num, int x) { return (num + x - 1) / x * x; } + } // namespace fpga } // namespace paddle_mobile diff --git a/src/fpga/bias_scale.cpp b/src/fpga/bias_scale.cpp new file mode 100644 index 0000000000..05ddf91d7a --- /dev/null +++ b/src/fpga/bias_scale.cpp @@ -0,0 +1,60 @@ +/* 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. */ + +#include +#include "bias_scale.h" +#include "api.h" + + +namespace paddle_mobile { + namespace fpga { + namespace bias_scale{ + + void align_element(float** data_in, int num_per_div_before_alignment, int num){ + float *ptr_unaligned = *data_in; + int div_num = (num + num_per_div_before_alignment -1) / num_per_div_before_alignment; + int num_per_div_after_alignment = align_to_x(num_per_div_before_alignment, BS_NUM_ALIGNMENT); + int num_element = 2 * div_num * num_per_div_after_alignment; //including bias & scale + float *ptr_aligned = (float*) fpga_malloc(num_element * sizeof(float)); + + memset(ptr_aligned, 0, num_element * sizeof(float)); + + + for(int i =0; i +#include "filter.h" +#include "api.h" + +namespace paddle_mobile { + namespace fpga { + namespace filter{ + + void convert_to_hwc(float** data_in, int num, int channel, int height, int width){ + + } + + + float find_max(float* data_in, int num){ + + return 0; + + + } + + + void quantize(float* data_in, int num){ + + } + + + void align_element(float** data_in, int num, int chw){ + + } + + + void align_num(float** data_in, int num_per_div_before_alignment, int num, int chw){ + + } + + + void reorder(float** data_in, int num_after_alignment, int chw){ + + } + + + void interleave(float** data_in, int num_after_alignment, int chw){ + + } + + } // namespace filter + } // namespace fpga +} // namespace paddle_mobile \ No newline at end of file diff --git a/src/fpga/filter.h b/src/fpga/filter.h new file mode 100644 index 0000000000..7bdf5f051e --- /dev/null +++ b/src/fpga/filter.h @@ -0,0 +1,34 @@ +/* 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 + + +#define FILTER_NUM_ALIGNMENT 32 //Filter number aligned to 32 +#define FILTER_ELEMENT_ALIGNMENT 16 //Filter element number aligned to 16 + +namespace paddle_mobile { + namespace fpga { + namespace filter{ + void convert_to_hwc(float** data_in, int num, int channel, int height, int width); + float find_max(float* data_in, int num); + void quantize(float* data_in, int num); + void align_element(float** data_in, int num, int chw); + void align_num(float** data_in, int num_per_div_before_alignment, int num, int chw); + void reorder(float** data_in, int num_after_alignment, int chw); + void interleave(float** data_in, int num_after_alignment, int chw); + + } // namespace filter + } // namespace fpga +} // namespace paddle_mobile \ No newline at end of file diff --git a/src/fpga/image.cpp b/src/fpga/image.cpp new file mode 100644 index 0000000000..0f798a864e --- /dev/null +++ b/src/fpga/image.cpp @@ -0,0 +1,13 @@ +/* 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. */ \ No newline at end of file diff --git a/src/fpga/image.h b/src/fpga/image.h new file mode 100644 index 0000000000..0f798a864e --- /dev/null +++ b/src/fpga/image.h @@ -0,0 +1,13 @@ +/* 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. */ \ No newline at end of file -- GitLab