From 337eb1bf15a090492f3882ce32f72b7ab8a7671c Mon Sep 17 00:00:00 2001 From: hanbuhe Date: Mon, 27 Apr 2020 14:44:53 +0800 Subject: [PATCH] deleted debug code --- .../fpga/KD/pes/fully_connected_pe.hpp | 68 ++++--------------- lite/backends/fpga/KD/pes/input_pe.hpp | 1 - lite/backends/fpga/KD/tensor.hpp | 14 ---- lite/backends/fpga/lite_tensor.cc | 13 ---- lite/backends/fpga/lite_tensor.h | 10 --- lite/kernels/host/one_hot_compute.cc | 1 - lite/operators/one_hot_op.cc | 2 - 7 files changed, 13 insertions(+), 96 deletions(-) diff --git a/lite/backends/fpga/KD/pes/fully_connected_pe.hpp b/lite/backends/fpga/KD/pes/fully_connected_pe.hpp index 56433ac19f..686a2cd9ad 100644 --- a/lite/backends/fpga/KD/pes/fully_connected_pe.hpp +++ b/lite/backends/fpga/KD/pes/fully_connected_pe.hpp @@ -14,8 +14,6 @@ limitations under the License. */ #pragma once -#include -#include #include #include "lite/backends/fpga/KD/pe.hpp" @@ -55,42 +53,32 @@ class FullyConnectedPE : public PE { int height = param_.input->shape().height(); int width = param_.input->shape().width(); - // int filter_channel = chw / height / width; + int filter_channel = chw / height / width; int channel = param_.output->shape().channel(); - Shape shape(NCHW, {num, chw_aligned, 1, 1}); - float* new_filter_data = conv_filter_.mutableData(FP32, shape); + Shape shape(NCHW, {num, filter_channel, height, width}); + Tensor* conv_filter = new Tensor(); + float* new_filter_data = conv_filter->mutableData(FP32, shape); float* filter_data = param_.filter->data(); - memset(new_filter_data, 0, num * chw_aligned * sizeof(float)); - for (int i = 0; i < num; i++) { for (int j = 0; j < chw; j++) { float scale = filter_data[j * num + i]; - new_filter_data[i * chw_aligned + j] = scale; + new_filter_data[i * chw + j] = scale; } } + conv_filter->flush(); convParam_.filter = conv_filter; - conv_filter_.flush(); - convParam_.filter = &conv_filter_; - // param_.filter->saveToFile("param_filter", true); - // conv_filter->saveToFile("conv_filter", true); - // exit(-1); - - Shape sb_shape(N, {num}); + Shape sb_shape(N, {channel}); float* scale_data = convParam_.scale()->mutableData(FP32, sb_shape); float* bias_data = convParam_.bias()->mutableData(FP32, sb_shape); - for (int i = 0; i < num; i++) { + for (int i = 0; i < channel; i++) { scale_data[i] = 1.0f; bias_data[i] = param_.bias->data()[i]; } - // for (int i = 0; i < num; i++) { - // scale_data[i] = 1.0f; - // bias_data[i] = param_.bias->data()[i]; - // } convParam_.scale()->flush(); convParam_.bias()->flush(); @@ -126,41 +114,14 @@ class FullyConnectedPE : public PE { output->flush(); output->scale()[0] = max / 127.0f; output->scale()[1] = 127.0f / max; - output->saveToFile("cpu_compute", true); - // exit(-1); - } - - void batch_to_w() { - ConvParam& convParam_ = convPE_.param(); - - int channel = param_.input->shape().channel(); - param_.input->invalidate(); - - int remainder = - aligned_input_.shape().channel() - param_.input->shape().channel(); - - float max = 0; - for (int n = 0; n < param_.input->shape().num(); n++) { - memset(aligned_input_.data(), - 0, - aligned_input_.shape().channel() * sizeof(float16)); - memcpy( - aligned_input_.data() + n * aligned_input_.shape().channel(), - param_.input->data() + n * channel, - channel * sizeof(float16)); - aligned_input_.copyScaleFrom(param_.input); - aligned_input_.flush(); - } - - convPE_.dispatch(); } bool dispatch() { - // batch_to_w(); - // return 1; - // cpu_compute1(); - // return 1; - + // int num = param_.filter->shape().channel(); + // if (num == 2) { + // cpu_compute(); + // return 1; + // } else { return convPE_.dispatch(); // } } @@ -169,10 +130,7 @@ class FullyConnectedPE : public PE { private: FullyConnectedParam param_; - Tensor aligned_input_; - Tensor aligned_output_; ConvPE convPE_; - Tensor conv_filter_; }; } // namespace zynqmp } // namespace paddle diff --git a/lite/backends/fpga/KD/pes/input_pe.hpp b/lite/backends/fpga/KD/pes/input_pe.hpp index d8f9a15c6a..380c85e17e 100755 --- a/lite/backends/fpga/KD/pes/input_pe.hpp +++ b/lite/backends/fpga/KD/pes/input_pe.hpp @@ -29,7 +29,6 @@ class InputPE : public PE { } bool dispatch() { - // std::cout << "input_dispatch()\n"; Tensor* input = param_.input; Tensor* output = param_.output; diff --git a/lite/backends/fpga/KD/tensor.hpp b/lite/backends/fpga/KD/tensor.hpp index a19d55a64d..1e1793faae 100644 --- a/lite/backends/fpga/KD/tensor.hpp +++ b/lite/backends/fpga/KD/tensor.hpp @@ -110,11 +110,7 @@ class Tensor { template Dtype* mutableData(DataType dataType, const Shape& shape) { - // std::cout << "enter \n"; - // std::cout << "before new shape\n"; - // this->shape_ = new Shape(shape); this->shape_.reset(new Shape(shape)); - // std::cout << "new shape \n"; this->dataType_ = dataType; return mutableData(); } @@ -123,14 +119,11 @@ class Tensor { Dtype* mutableData() { size_t memorySize = shape_->memorySize(CellSize(dataType_)) * mem_scale_factor_; - // std::cout << "mem_size:" << memorySize << std::endl; if (placeHolder_ != nullptr) { - // std::cout << "placeHolder_ not null"<< std::endl; if (memorySize > placeHolder_->memorySize()) { placeHolder_.reset(new PlaceHolder(memorySize)); } } else { - // std::cout << "placeHolder_ null"<< std::endl; placeHolder_.reset(new PlaceHolder(memorySize)); } return data(); @@ -256,16 +249,11 @@ class Tensor { void shareDataWith(Tensor* src) { shareDataWith(src, src->shape()); } void shareDataWith(Tensor* src, const Shape& shape, int offset = 0) { - // if (shape_ != nullptr) { - // delete shape_; - // } - this->placeHolder_ = src->placeHolder_; this->dataType_ = src->dataType_; this->aligned_ = src->aligned_; this->dateLocation_ = src->dateLocation_; this->offset = offset; - // shape_ = new Shape(const_cast(shape)); shape_.reset(new Shape(shape)); } @@ -312,7 +300,6 @@ class Tensor { void flush() { if (released) { - // std::cout << "flush::" << this << std::endl; return; } @@ -474,7 +461,6 @@ class Tensor { float mem_scale_factor_ = 1.0f; std::shared_ptr placeHolder_; std::shared_ptr shape_; - // Shape* shape_ = nullptr; DataType dataType_ = FP32; bool aligned_ = false; DataSyncStatus synchedStatus_ = Synched; diff --git a/lite/backends/fpga/lite_tensor.cc b/lite/backends/fpga/lite_tensor.cc index 6ec9f6866a..5308640495 100755 --- a/lite/backends/fpga/lite_tensor.cc +++ b/lite/backends/fpga/lite_tensor.cc @@ -81,8 +81,6 @@ void TensorLite::ShareDataWith(const TensorLite &other) { void *TensorLite::mutable_data(size_t memory_size) { memory_size_ = memory_size; // TODO(chonwhite) delete buffer; buffer_->ResetLazy(target_, memory_size_); - // throw -1; - // std::cout << memory_size << std::endl; return buffer_->data(); } @@ -92,34 +90,23 @@ void *TensorLite::mutable_data(TargetType target, size_t memory_size) { } void TensorLite::CopyDataFrom(const TensorLite &other) { - // std::cout << "other11:: "<< &other << std::endl; dims_ = other.dims_; target_ = other.target_; lod_ = other.lod_; - // std::cout << "before dataType\n"; if (zynq_tensor_.get() == nullptr) { zynq_tensor_.reset(new zynqmp::Tensor()); } auto dt = zynq_tensor_->dataType(); - // std::cout << "after dataType\n"; - - // std::cout << "before resize\n"; Resize(other.dims()); auto shape = other.zynq_tensor_->shape(); - // std::cout << "after resize\n"; zynq_tensor_->mutableData(zynq_tensor_->dataType(), shape); - // std::cout << "after mutableData\n"; - // std::cout << "ZynqTensor():" << this->ZynqTensor() << std::endl; - // std::cout << "other Tensor():" << other.ZynqTensor() << std::endl; // this->ZynqTensor()->copyFrom(other.ZynqTensor()); memcpy(this->ZynqTensor()->data(), other.ZynqTensor()->data(), other.ZynqTensor()->shape().numel() * sizeof(float)); - // memcpy() - // std::cout << "after copyFrom\n"; } } // namespace lite diff --git a/lite/backends/fpga/lite_tensor.h b/lite/backends/fpga/lite_tensor.h index f83bed541e..0feaef6dbe 100644 --- a/lite/backends/fpga/lite_tensor.h +++ b/lite/backends/fpga/lite_tensor.h @@ -82,7 +82,6 @@ class DDimLite { } ~DDimLite() { - // std::cout << "free DDimLite\n"; } private: @@ -114,10 +113,7 @@ class TensorLite { } void Resize(const DDimLite &ddim) { - // std::cout << "Resize \n"; - // std::cout << "ddim:" << & ddim << std::endl; dims_ = ddim; - // std::cout << "after Reize \n"; } void Resize(const std::vector &x) { dims_ = DDimLite(x); } @@ -210,7 +206,6 @@ class TensorLite { size_t memory_size_{}; size_t offset_{0}; - // zynqmp::Tensor *zynq_tensor_ = new zynqmp::Tensor(); std::shared_ptr zynq_tensor_; template @@ -220,7 +215,6 @@ class TensorLite { template R *TensorLite::mutable_data() { std::vector v; - // std::cout << "mutable_data \n"; for (int i = 0; i < dims_.size(); i++) { v.push_back(dims_[i]); } @@ -243,7 +237,6 @@ R *TensorLite::mutable_data() { break; } zynqmp::Shape input_shape(layout_type, v); - // std::cout << "input_shape \n"; zynqmp::DataType data_type = zynqmp::FP32; if (typeid(T) == typeid(float)) { data_type = zynqmp::FP32; @@ -251,9 +244,6 @@ R *TensorLite::mutable_data() { if (typeid(T) == typeid(zynqmp::float16)) { data_type = zynqmp::FP16; } - // std::cout << "mutableData \n"; - // std::cout << "zynq_tensor_:" << zynq_tensor_.get() << std::endl; - if (zynq_tensor_.get() == nullptr) { zynq_tensor_.reset(new zynqmp::Tensor()); } diff --git a/lite/kernels/host/one_hot_compute.cc b/lite/kernels/host/one_hot_compute.cc index e1bf4c103b..97e98a7ef5 100755 --- a/lite/kernels/host/one_hot_compute.cc +++ b/lite/kernels/host/one_hot_compute.cc @@ -16,7 +16,6 @@ #include #include -// #include "lite/backends/fpga/KD/debugger.hpp" #include "lite/kernels/host/one_hot_compute.h" #include "lite/utils/paddle_enforce.h" diff --git a/lite/operators/one_hot_op.cc b/lite/operators/one_hot_op.cc index ebab9e2067..397326abf7 100644 --- a/lite/operators/one_hot_op.cc +++ b/lite/operators/one_hot_op.cc @@ -15,8 +15,6 @@ #include "lite/operators/one_hot_op.h" #include "lite/core/op_registry.h" -// #include "lite/backends/fpga/KD/debugger.hpp" - namespace paddle { namespace lite { namespace operators { -- GitLab