Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
337eb1bf
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
337eb1bf
编写于
4月 27, 2020
作者:
H
hanbuhe
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
deleted debug code
上级
dd2b700d
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
13 addition
and
96 deletion
+13
-96
lite/backends/fpga/KD/pes/fully_connected_pe.hpp
lite/backends/fpga/KD/pes/fully_connected_pe.hpp
+13
-55
lite/backends/fpga/KD/pes/input_pe.hpp
lite/backends/fpga/KD/pes/input_pe.hpp
+0
-1
lite/backends/fpga/KD/tensor.hpp
lite/backends/fpga/KD/tensor.hpp
+0
-14
lite/backends/fpga/lite_tensor.cc
lite/backends/fpga/lite_tensor.cc
+0
-13
lite/backends/fpga/lite_tensor.h
lite/backends/fpga/lite_tensor.h
+0
-10
lite/kernels/host/one_hot_compute.cc
lite/kernels/host/one_hot_compute.cc
+0
-1
lite/operators/one_hot_op.cc
lite/operators/one_hot_op.cc
+0
-2
未找到文件。
lite/backends/fpga/KD/pes/fully_connected_pe.hpp
浏览文件 @
337eb1bf
...
...
@@ -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.0
f
;
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.0
f
;
output
->
scale
()[
1
]
=
127.0
f
/
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
lite/backends/fpga/KD/pes/input_pe.hpp
浏览文件 @
337eb1bf
...
...
@@ -29,7 +29,6 @@ class InputPE : public PE {
}
bool
dispatch
()
{
// std::cout << "input_dispatch()\n";
Tensor
*
input
=
param_
.
input
;
Tensor
*
output
=
param_
.
output
;
...
...
lite/backends/fpga/KD/tensor.hpp
浏览文件 @
337eb1bf
...
...
@@ -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.0
f
;
std
::
shared_ptr
<
PlaceHolder
>
placeHolder_
;
std
::
shared_ptr
<
Shape
>
shape_
;
// Shape* shape_ = nullptr;
DataType
dataType_
=
FP32
;
bool
aligned_
=
false
;
DataSyncStatus
synchedStatus_
=
Synched
;
...
...
lite/backends/fpga/lite_tensor.cc
浏览文件 @
337eb1bf
...
...
@@ -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
...
...
lite/backends/fpga/lite_tensor.h
浏览文件 @
337eb1bf
...
...
@@ -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
());
}
...
...
lite/kernels/host/one_hot_compute.cc
浏览文件 @
337eb1bf
...
...
@@ -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"
...
...
lite/operators/one_hot_op.cc
浏览文件 @
337eb1bf
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录