提交 337eb1bf 编写于 作者: H hanbuhe

deleted debug code

上级 dd2b700d
......@@ -14,8 +14,6 @@ limitations under the License. */
#pragma once
#include <math.h>
#include <cmath>
#include <vector>
#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<float>(FP32, shape);
Shape shape(NCHW, {num, filter_channel, height, width});
Tensor* conv_filter = new Tensor();
float* new_filter_data = conv_filter->mutableData<float>(FP32, shape);
float* filter_data = param_.filter->data<float>();
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<float>(FP32, sb_shape);
float* bias_data = convParam_.bias()->mutableData<float>(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<float>()[i];
}
// for (int i = 0; i < num; i++) {
// scale_data[i] = 1.0f;
// bias_data[i] = param_.bias->data<float>()[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<float16>(),
0,
aligned_input_.shape().channel() * sizeof(float16));
memcpy(
aligned_input_.data<float16>() + n * aligned_input_.shape().channel(),
param_.input->data<float16>() + 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
......@@ -29,7 +29,6 @@ class InputPE : public PE {
}
bool dispatch() {
// std::cout << "input_dispatch()\n";
Tensor* input = param_.input;
Tensor* output = param_.output;
......
......@@ -110,11 +110,7 @@ class Tensor {
template <typename Dtype>
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<Dtype>();
}
......@@ -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<Dtype>();
......@@ -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));
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> placeHolder_;
std::shared_ptr<Shape> shape_;
// Shape* shape_ = nullptr;
DataType dataType_ = FP32;
bool aligned_ = false;
DataSyncStatus synchedStatus_ = Synched;
......
......@@ -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<void>(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<void>(),
other.ZynqTensor()->data<void>(),
other.ZynqTensor()->shape().numel() * sizeof(float));
// memcpy()
// std::cout << "after copyFrom\n";
}
} // namespace lite
......
......@@ -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<int64_t> &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<zynqmp::Tensor> zynq_tensor_;
template <typename T>
......@@ -220,7 +215,6 @@ class TensorLite {
template <typename T, typename R>
R *TensorLite::mutable_data() {
std::vector<int> 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());
}
......
......@@ -16,7 +16,6 @@
#include <utility>
#include <vector>
// #include "lite/backends/fpga/KD/debugger.hpp"
#include "lite/kernels/host/one_hot_compute.h"
#include "lite/utils/paddle_enforce.h"
......
......@@ -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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册