Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
25ecd206
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
25ecd206
编写于
1月 11, 2018
作者:
X
xuwei06
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use CopyFromVector for assign_value_op
上级
237385cf
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
8 addition
and
39 deletion
+8
-39
paddle/framework/tensor_util.h
paddle/framework/tensor_util.h
+2
-2
paddle/operators/assign_value_op.cc
paddle/operators/assign_value_op.cc
+2
-11
paddle/operators/assign_value_op.cu.cc
paddle/operators/assign_value_op.cu.cc
+2
-19
paddle/operators/assign_value_op.h
paddle/operators/assign_value_op.h
+2
-7
未找到文件。
paddle/framework/tensor_util.h
浏览文件 @
25ecd206
...
@@ -116,8 +116,8 @@ inline void Copy(const Tensor& src, const platform::Place& dst_place,
...
@@ -116,8 +116,8 @@ inline void Copy(const Tensor& src, const platform::Place& dst_place,
* @param[in] src The external tensor.
* @param[in] src The external tensor.
* @param[in] ctx The device context contains device resources.
* @param[in] ctx The device context contains device resources.
*
*
* * @note CopyFromVector
assumes that the tensor has been resized
* * @note CopyFromVector
will resize dst to an 1D tensor with the same
*
before invoking
.
*
size as src
.
*/
*/
template
<
typename
T
>
template
<
typename
T
>
inline
void
CopyFromVector
(
const
std
::
vector
<
T
>&
src
,
inline
void
CopyFromVector
(
const
std
::
vector
<
T
>&
src
,
...
...
paddle/operators/assign_value_op.cc
浏览文件 @
25ecd206
...
@@ -63,20 +63,11 @@ $$Out = values$$
...
@@ -63,20 +63,11 @@ $$Out = values$$
}
}
};
};
template
<
typename
T
>
class
AssignValueCPUKernel
:
public
AssignValueKernel
<
T
>
{
protected:
virtual
void
Copy
(
void
*
dst
,
const
void
*
src
,
size_t
size
,
const
framework
::
ExecutionContext
&
ctx
)
const
{
std
::
memcpy
(
dst
,
src
,
size
);
}
};
}
// namespace operators
}
// namespace operators
}
// namespace paddle
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
namespace
ops
=
paddle
::
operators
;
REGISTER_OPERATOR
(
assign_value
,
ops
::
AssignValueOp
,
ops
::
AssignValueOpMaker
);
REGISTER_OPERATOR
(
assign_value
,
ops
::
AssignValueOp
,
ops
::
AssignValueOpMaker
);
REGISTER_OP_CPU_KERNEL
(
assign_value
,
ops
::
AssignValue
CPU
Kernel
<
int
>
,
REGISTER_OP_CPU_KERNEL
(
assign_value
,
ops
::
AssignValueKernel
<
int
>
,
ops
::
AssignValue
CPUKernel
<
float
>
)
ops
::
AssignValue
Kernel
<
float
>
);
paddle/operators/assign_value_op.cu.cc
浏览文件 @
25ecd206
...
@@ -14,23 +14,6 @@ limitations under the License. */
...
@@ -14,23 +14,6 @@ limitations under the License. */
#include "paddle/operators/assign_value_op.h"
#include "paddle/operators/assign_value_op.h"
namespace
paddle
{
namespace
operators
{
template
<
typename
T
>
class
AssignValueGPUKernel
:
public
AssignValueKernel
<
T
>
{
protected:
virtual
void
Copy
(
void
*
dst
,
const
void
*
src
,
size_t
size
,
const
framework
::
ExecutionContext
&
ctx
)
const
{
auto
&
dev_ctx
=
ctx
.
template
device_context
<
platform
::
CUDADeviceContext
>();
paddle
::
platform
::
GpuMemcpyAsync
(
dst
,
src
,
size
,
cudaMemcpyHostToDevice
,
dev_ctx
.
stream
());
}
};
}
// namespace operators
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
namespace
ops
=
paddle
::
operators
;
REGISTER_OP_CUDA_KERNEL
(
assign_value
,
ops
::
AssignValue
GPU
Kernel
<
int
>
,
REGISTER_OP_CUDA_KERNEL
(
assign_value
,
ops
::
AssignValueKernel
<
int
>
,
ops
::
AssignValue
GPU
Kernel
<
float
>
);
ops
::
AssignValueKernel
<
float
>
);
paddle/operators/assign_value_op.h
浏览文件 @
25ecd206
...
@@ -27,8 +27,6 @@ class AssignValueKernel : public framework::OpKernel<T> {
...
@@ -27,8 +27,6 @@ class AssignValueKernel : public framework::OpKernel<T> {
virtual
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
{
virtual
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
{
auto
shape
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"shape"
);
auto
shape
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"shape"
);
auto
*
out
=
ctx
.
Output
<
framework
::
Tensor
>
(
"Out"
);
auto
*
out
=
ctx
.
Output
<
framework
::
Tensor
>
(
"Out"
);
out
->
Resize
(
framework
::
make_ddim
(
shape
));
auto
*
dst
=
out
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
int
dtype
=
ctx
.
Attr
<
int
>
(
"dtype"
);
int
dtype
=
ctx
.
Attr
<
int
>
(
"dtype"
);
const
char
*
value_name
=
nullptr
;
const
char
*
value_name
=
nullptr
;
switch
(
dtype
)
{
switch
(
dtype
)
{
...
@@ -43,12 +41,9 @@ class AssignValueKernel : public framework::OpKernel<T> {
...
@@ -43,12 +41,9 @@ class AssignValueKernel : public framework::OpKernel<T> {
break
;
break
;
}
}
auto
values
=
ctx
.
Attr
<
std
::
vector
<
T
>>
(
value_name
);
auto
values
=
ctx
.
Attr
<
std
::
vector
<
T
>>
(
value_name
);
Copy
(
dst
,
values
.
data
(),
sizeof
(
T
)
*
values
.
size
(),
ctx
);
framework
::
CopyFromVector
(
values
,
ctx
.
device_context
(),
out
);
out
->
Resize
(
framework
::
make_ddim
(
shape
));
}
}
protected:
virtual
void
Copy
(
void
*
dst
,
const
void
*
src
,
size_t
size
,
const
framework
::
ExecutionContext
&
ctx
)
const
=
0
;
};
};
}
// namespace operators
}
// namespace operators
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录