Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
d1e89ead
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
d1e89ead
编写于
6月 02, 2021
作者:
W
wuhuanzhou
提交者:
GitHub
6月 02, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
optimize OP's compilation time implemented by Eigen, test=develop (#33218)
上级
e7541209
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
105 addition
and
31 deletion
+105
-31
paddle/fluid/operators/eigen/eigen_function.h
paddle/fluid/operators/eigen/eigen_function.h
+20
-0
paddle/fluid/operators/eigen/loss.cc
paddle/fluid/operators/eigen/loss.cc
+33
-0
paddle/fluid/operators/eigen/loss.cu
paddle/fluid/operators/eigen/loss.cu
+33
-0
paddle/fluid/operators/log_loss_op.cc
paddle/fluid/operators/log_loss_op.cc
+5
-0
paddle/fluid/operators/log_loss_op.cu
paddle/fluid/operators/log_loss_op.cu
+0
-21
paddle/fluid/operators/log_loss_op.h
paddle/fluid/operators/log_loss_op.h
+5
-6
paddle/fluid/operators/top_k_function_cuda.h
paddle/fluid/operators/top_k_function_cuda.h
+9
-4
未找到文件。
paddle/fluid/operators/eigen/eigen_function.h
浏览文件 @
d1e89ead
...
...
@@ -196,6 +196,26 @@ struct EigenRankLossGrad {
const
InType
&
left
,
const
InType
&
right
);
};
template
<
typename
EigenDevice
,
typename
T
>
struct
EigenLogLoss
{
using
InType
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
const
T
,
1
,
Eigen
::
RowMajor
,
Eigen
::
DenseIndex
>>
;
using
OutType
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
T
,
1
,
Eigen
::
RowMajor
,
Eigen
::
DenseIndex
>>
;
static
void
Eval
(
const
EigenDevice
&
dev
,
OutType
out
,
const
InType
&
pred
,
const
InType
&
label
,
const
T
&
epsilon
);
};
template
<
typename
EigenDevice
,
typename
T
>
struct
EigenLogLossGrad
{
using
InType
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
const
T
,
1
,
Eigen
::
RowMajor
,
Eigen
::
DenseIndex
>>
;
using
OutType
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
T
,
1
,
Eigen
::
RowMajor
,
Eigen
::
DenseIndex
>>
;
static
void
Eval
(
const
EigenDevice
&
dev
,
OutType
dpred
,
const
InType
&
dloss
,
const
InType
&
pred
,
const
InType
&
label
,
const
T
&
epsilon
);
};
template
<
typename
EigenDevice
,
typename
T
>
struct
EigenHingeLoss
{
using
InType
=
Eigen
::
TensorMap
<
...
...
paddle/fluid/operators/eigen/loss.cc
浏览文件 @
d1e89ead
...
...
@@ -53,6 +53,39 @@ struct EigenRankLossGrad<Eigen::DefaultDevice, T> {
template
struct
EigenRankLoss
<
Eigen
::
DefaultDevice
,
float
>;
template
struct
EigenRankLossGrad
<
Eigen
::
DefaultDevice
,
float
>;
template
<
typename
T
>
struct
EigenLogLoss
<
Eigen
::
DefaultDevice
,
T
>
{
using
InType
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
const
T
,
1
,
Eigen
::
RowMajor
,
Eigen
::
DenseIndex
>>
;
using
OutType
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
T
,
1
,
Eigen
::
RowMajor
,
Eigen
::
DenseIndex
>>
;
static
void
Eval
(
const
Eigen
::
DefaultDevice
&
dev
,
OutType
out
,
const
InType
&
pred
,
const
InType
&
label
,
const
T
&
epsilon
)
{
out
.
device
(
dev
)
=
(
-
(
label
*
(
pred
+
epsilon
).
log
())
-
((
static_cast
<
T
>
(
1
)
-
label
)
*
(
static_cast
<
T
>
(
1
)
-
pred
+
epsilon
).
log
()));
}
};
template
<
typename
T
>
struct
EigenLogLossGrad
<
Eigen
::
DefaultDevice
,
T
>
{
using
InType
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
const
T
,
1
,
Eigen
::
RowMajor
,
Eigen
::
DenseIndex
>>
;
using
OutType
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
T
,
1
,
Eigen
::
RowMajor
,
Eigen
::
DenseIndex
>>
;
static
void
Eval
(
const
Eigen
::
DefaultDevice
&
dev
,
OutType
dpred
,
const
InType
&
dloss
,
const
InType
&
pred
,
const
InType
&
label
,
const
T
&
epsilon
)
{
dpred
.
device
(
dev
)
=
dloss
*
(
-
(
label
/
(
pred
+
epsilon
))
+
((
static_cast
<
T
>
(
1
)
-
label
)
/
(
static_cast
<
T
>
(
1
)
-
pred
+
epsilon
)));
}
};
template
struct
EigenLogLoss
<
Eigen
::
DefaultDevice
,
float
>;
template
struct
EigenLogLossGrad
<
Eigen
::
DefaultDevice
,
float
>;
template
<
typename
T
>
struct
EigenHingeLoss
<
Eigen
::
DefaultDevice
,
T
>
{
using
InType
=
Eigen
::
TensorMap
<
...
...
paddle/fluid/operators/eigen/loss.cu
浏览文件 @
d1e89ead
...
...
@@ -53,6 +53,39 @@ struct EigenRankLossGrad<Eigen::GpuDevice, T> {
template
struct
EigenRankLoss
<
Eigen
::
GpuDevice
,
float
>;
template
struct
EigenRankLossGrad
<
Eigen
::
GpuDevice
,
float
>;
template
<
typename
T
>
struct
EigenLogLoss
<
Eigen
::
GpuDevice
,
T
>
{
using
InType
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
const
T
,
1
,
Eigen
::
RowMajor
,
Eigen
::
DenseIndex
>>
;
using
OutType
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
T
,
1
,
Eigen
::
RowMajor
,
Eigen
::
DenseIndex
>>
;
static
void
Eval
(
const
Eigen
::
GpuDevice
&
dev
,
OutType
out
,
const
InType
&
pred
,
const
InType
&
label
,
const
T
&
epsilon
)
{
out
.
device
(
dev
)
=
(
-
(
label
*
(
pred
+
epsilon
).
log
())
-
((
static_cast
<
T
>
(
1
)
-
label
)
*
(
static_cast
<
T
>
(
1
)
-
pred
+
epsilon
).
log
()));
}
};
template
<
typename
T
>
struct
EigenLogLossGrad
<
Eigen
::
GpuDevice
,
T
>
{
using
InType
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
const
T
,
1
,
Eigen
::
RowMajor
,
Eigen
::
DenseIndex
>>
;
using
OutType
=
Eigen
::
TensorMap
<
Eigen
::
Tensor
<
T
,
1
,
Eigen
::
RowMajor
,
Eigen
::
DenseIndex
>>
;
static
void
Eval
(
const
Eigen
::
GpuDevice
&
dev
,
OutType
dpred
,
const
InType
&
dloss
,
const
InType
&
pred
,
const
InType
&
label
,
const
T
&
epsilon
)
{
dpred
.
device
(
dev
)
=
dloss
*
(
-
(
label
/
(
pred
+
epsilon
))
+
((
static_cast
<
T
>
(
1
)
-
label
)
/
(
static_cast
<
T
>
(
1
)
-
pred
+
epsilon
)));
}
};
template
struct
EigenLogLoss
<
Eigen
::
GpuDevice
,
float
>;
template
struct
EigenLogLossGrad
<
Eigen
::
GpuDevice
,
float
>;
template
<
typename
T
>
struct
EigenHingeLoss
<
Eigen
::
GpuDevice
,
T
>
{
using
InType
=
Eigen
::
TensorMap
<
...
...
paddle/fluid/operators/log_loss_op.cc
浏览文件 @
d1e89ead
...
...
@@ -154,3 +154,8 @@ REGISTER_OP_CPU_KERNEL(
REGISTER_OP_CPU_KERNEL
(
log_loss_grad
,
ops
::
LogLossGradKernel
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
);
REGISTER_OP_CUDA_KERNEL
(
log_loss
,
ops
::
LogLossKernel
<
paddle
::
platform
::
CUDADeviceContext
,
float
>
);
REGISTER_OP_CUDA_KERNEL
(
log_loss_grad
,
ops
::
LogLossGradKernel
<
paddle
::
platform
::
CUDADeviceContext
,
float
>
);
paddle/fluid/operators/log_loss_op.cu
已删除
100644 → 0
浏览文件 @
e7541209
/* Copyright (c) 2016 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 "paddle/fluid/operators/log_loss_op.h"
namespace
ops
=
paddle
::
operators
;
REGISTER_OP_CUDA_KERNEL
(
log_loss
,
ops
::
LogLossKernel
<
paddle
::
platform
::
CUDADeviceContext
,
float
>
);
REGISTER_OP_CUDA_KERNEL
(
log_loss_grad
,
ops
::
LogLossGradKernel
<
paddle
::
platform
::
CUDADeviceContext
,
float
>
);
paddle/fluid/operators/log_loss_op.h
浏览文件 @
d1e89ead
...
...
@@ -15,6 +15,7 @@ limitations under the License. */
#pragma once
#include "paddle/fluid/framework/eigen.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/operators/eigen/eigen_function.h"
namespace
paddle
{
namespace
operators
{
...
...
@@ -40,9 +41,8 @@ class LogLossKernel : public framework::OpKernel<T> {
auto
loss
=
EigenVector
<
T
>::
Flatten
(
*
loss_out
);
auto
&
place
=
*
ctx
.
template
device_context
<
DeviceContext
>().
eigen_device
();
loss
.
device
(
place
)
=
(
-
(
label
*
(
prediction
+
epsilon
).
log
())
-
((
static_cast
<
T
>
(
1
)
-
label
)
*
(
static_cast
<
T
>
(
1
)
-
prediction
+
epsilon
).
log
()));
EigenLogLoss
<
std
::
decay_t
<
decltype
(
place
)
>
,
T
>::
Eval
(
place
,
loss
,
prediction
,
label
,
epsilon
);
}
};
...
...
@@ -64,9 +64,8 @@ class LogLossGradKernel : public framework::OpKernel<T> {
if
(
dpred
)
{
dpred
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
auto
dx
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
dpred
);
dx
.
device
(
place
)
=
dl
*
(
-
(
label
/
(
prediction
+
epsilon
))
+
((
static_cast
<
T
>
(
1
)
-
label
)
/
(
static_cast
<
T
>
(
1
)
-
prediction
+
epsilon
)));
EigenLogLossGrad
<
std
::
decay_t
<
decltype
(
place
)
>
,
T
>::
Eval
(
place
,
dx
,
dl
,
prediction
,
label
,
epsilon
);
}
}
};
...
...
paddle/fluid/operators/top_k_function_cuda.h
浏览文件 @
d1e89ead
...
...
@@ -22,6 +22,7 @@ limitations under the License. */
#ifdef __HIPCC__
#include <hipcub/hipcub.hpp>
#endif
#include "paddle/fluid/operators/eigen/eigen_function.h"
#include "paddle/fluid/operators/top_k_op.h"
#include "paddle/fluid/platform/cuda_device_function.h"
#include "paddle/fluid/platform/float16.h"
...
...
@@ -563,15 +564,19 @@ bool SortTopk(const platform::CUDADeviceContext& ctx,
const
Eigen
::
DSizes
<
Eigen
::
DenseIndex
,
2
>
slice_sizes
{
num_rows
,
k
};
auto
e_indices
=
framework
::
EigenMatrix
<
int64_t
>::
From
(
*
indices_tensor
,
dim
);
auto
e_tmp_indices
=
framework
::
EigenMatrix
<
int64_t
>::
From
(
temp_indices
);
auto
e_tmp_indices
=
framework
::
EigenMatrix
<
int64_t
>::
From
(
static_cast
<
const
Tensor
>
(
temp_indices
));
std
::
vector
<
int
>
odims
=
{
static_cast
<
int
>
(
num_rows
),
static_cast
<
int
>
(
k
)};
auto
dim
=
framework
::
make_ddim
(
odims
);
auto
e_values
=
framework
::
EigenMatrix
<
T
>::
From
(
*
out_tensor
,
dim
);
auto
e_tmp_values
=
framework
::
EigenMatrix
<
T
>::
From
(
temp_values
);
auto
e_tmp_values
=
framework
::
EigenMatrix
<
T
>::
From
(
static_cast
<
const
Tensor
>
(
temp_values
));
e_indices
.
device
(
dev
)
=
e_tmp_indices
.
slice
(
slice_indices
,
slice_sizes
);
e_values
.
device
(
dev
)
=
e_tmp_values
.
slice
(
slice_indices
,
slice_sizes
);
EigenSlice
<
std
::
decay_t
<
decltype
(
dev
)
>
,
int64_t
,
2
>::
Eval
(
dev
,
e_indices
,
e_tmp_indices
,
slice_indices
,
slice_sizes
);
EigenSlice
<
std
::
decay_t
<
decltype
(
dev
)
>
,
T
,
2
>::
Eval
(
dev
,
e_values
,
e_tmp_values
,
slice_indices
,
slice_sizes
);
}
return
true
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录