Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
094e3b8c
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 2 年 前同步成功
通知
2325
Star
20933
Fork
5424
代码
文件
提交
分支
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看板
未验证
提交
094e3b8c
编写于
1月 30, 2023
作者:
E
engineer1109
提交者:
GitHub
1月 30, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add phi tensor vector array api from fluid (#49885)
replace all TensorFromVector & TensorToVector AssignKernel async copy
上级
172d1de6
变更
39
隐藏空白更改
内联
并排
Showing
39 changed file
with
545 addition
and
102 deletion
+545
-102
paddle/fluid/framework/tensor_util.h
paddle/fluid/framework/tensor_util.h
+1
-1
paddle/phi/core/tensor_utils.cc
paddle/phi/core/tensor_utils.cc
+445
-0
paddle/phi/core/tensor_utils.h
paddle/phi/core/tensor_utils.h
+17
-0
paddle/phi/kernels/assign_kernel.cc
paddle/phi/kernels/assign_kernel.cc
+4
-6
paddle/phi/kernels/cpu/adam_kernel.cc
paddle/phi/kernels/cpu/adam_kernel.cc
+1
-2
paddle/phi/kernels/cpu/adamw_kernel.cc
paddle/phi/kernels/cpu/adamw_kernel.cc
+2
-2
paddle/phi/kernels/cpu/cross_grad_kernel.cc
paddle/phi/kernels/cpu/cross_grad_kernel.cc
+6
-6
paddle/phi/kernels/cpu/cross_kernel.cc
paddle/phi/kernels/cpu/cross_kernel.cc
+3
-3
paddle/phi/kernels/cpu/index_sample_grad_kernel.cc
paddle/phi/kernels/cpu/index_sample_grad_kernel.cc
+4
-4
paddle/phi/kernels/cpu/index_sample_kernel.cc
paddle/phi/kernels/cpu/index_sample_kernel.cc
+4
-4
paddle/phi/kernels/cpu/repeat_interleave_grad_kernel.cc
paddle/phi/kernels/cpu/repeat_interleave_grad_kernel.cc
+1
-1
paddle/phi/kernels/cpu/roll_grad_kernel.cc
paddle/phi/kernels/cpu/roll_grad_kernel.cc
+3
-3
paddle/phi/kernels/cpu/roll_kernel.cc
paddle/phi/kernels/cpu/roll_kernel.cc
+3
-3
paddle/phi/kernels/cpu/unique_consecutive_functor.h
paddle/phi/kernels/cpu/unique_consecutive_functor.h
+3
-4
paddle/phi/kernels/funcs/repeat_tensor2index_tensor.h
paddle/phi/kernels/funcs/repeat_tensor2index_tensor.h
+1
-1
paddle/phi/kernels/funcs/unique_functor.h
paddle/phi/kernels/funcs/unique_functor.h
+3
-3
paddle/phi/kernels/gpu/adam_kernel.cu
paddle/phi/kernels/gpu/adam_kernel.cu
+1
-2
paddle/phi/kernels/gpu/adamw_kernel.cu
paddle/phi/kernels/gpu/adamw_kernel.cu
+1
-2
paddle/phi/kernels/gpu/class_center_sample_kernel.cu
paddle/phi/kernels/gpu/class_center_sample_kernel.cu
+2
-2
paddle/phi/kernels/gpu/diagonal_grad_kernel.cu
paddle/phi/kernels/gpu/diagonal_grad_kernel.cu
+3
-5
paddle/phi/kernels/gpu/diagonal_kernel.cu
paddle/phi/kernels/gpu/diagonal_kernel.cu
+3
-5
paddle/phi/kernels/gpu/margin_cross_entropy_grad_kernel.cu
paddle/phi/kernels/gpu/margin_cross_entropy_grad_kernel.cu
+2
-3
paddle/phi/kernels/gpu/margin_cross_entropy_kernel.cu
paddle/phi/kernels/gpu/margin_cross_entropy_kernel.cu
+2
-3
paddle/phi/kernels/gpu/prior_box_kernel.cu
paddle/phi/kernels/gpu/prior_box_kernel.cu
+5
-5
paddle/phi/kernels/gpu/unique_consecutive_functor.h
paddle/phi/kernels/gpu/unique_consecutive_functor.h
+3
-5
paddle/phi/kernels/gpu/unique_kernel.cu
paddle/phi/kernels/gpu/unique_kernel.cu
+3
-4
paddle/phi/kernels/impl/determinant_kernel_impl.h
paddle/phi/kernels/impl/determinant_kernel_impl.h
+3
-3
paddle/phi/kernels/impl/repeat_interleave_grad_kernel_impl.h
paddle/phi/kernels/impl/repeat_interleave_grad_kernel_impl.h
+1
-1
paddle/phi/kernels/impl/repeat_interleave_kernel_impl.h
paddle/phi/kernels/impl/repeat_interleave_kernel_impl.h
+2
-2
paddle/phi/kernels/impl/set_value_kernel_impl.h
paddle/phi/kernels/impl/set_value_kernel_impl.h
+1
-1
paddle/phi/kernels/impl/slogdeterminant_kernel_impl.h
paddle/phi/kernels/impl/slogdeterminant_kernel_impl.h
+3
-3
paddle/phi/kernels/selected_rows/cpu/adam_kernel.cc
paddle/phi/kernels/selected_rows/cpu/adam_kernel.cc
+1
-2
paddle/phi/kernels/selected_rows/cpu/adamw_kernel.cc
paddle/phi/kernels/selected_rows/cpu/adamw_kernel.cc
+2
-2
paddle/phi/kernels/selected_rows/gpu/adam_kernel.cu
paddle/phi/kernels/selected_rows/gpu/adam_kernel.cu
+1
-2
paddle/phi/kernels/selected_rows/gpu/adamw_kernel.cu
paddle/phi/kernels/selected_rows/gpu/adamw_kernel.cu
+1
-1
paddle/phi/kernels/selected_rows/xpu/adam_kernel.cc
paddle/phi/kernels/selected_rows/xpu/adam_kernel.cc
+1
-1
paddle/phi/kernels/xpu/adam_kernel.cc
paddle/phi/kernels/xpu/adam_kernel.cc
+1
-1
paddle/phi/kernels/xpu/adamw_kernel.cc
paddle/phi/kernels/xpu/adamw_kernel.cc
+1
-3
paddle/phi/kernels/xpu/set_value_kernel.cc
paddle/phi/kernels/xpu/set_value_kernel.cc
+1
-1
未找到文件。
paddle/fluid/framework/tensor_util.h
浏览文件 @
094e3b8c
...
@@ -355,7 +355,7 @@ inline void TensorFromVector(const std::vector<bool>& src,
...
@@ -355,7 +355,7 @@ inline void TensorFromVector(const std::vector<bool>& src,
reinterpret_cast
<
const
platform
::
NPUDeviceContext
&>
(
ctx
).
stream
());
reinterpret_cast
<
const
platform
::
NPUDeviceContext
&>
(
ctx
).
stream
());
}
}
#endif
#endif
#ifdef PADDLE_WITH_CUSTOM_DEICE
#ifdef PADDLE_WITH_CUSTOM_DE
V
ICE
else
if
(
platform
::
is_custom_place
(
dst_place
))
{
// NOLINT
else
if
(
platform
::
is_custom_place
(
dst_place
))
{
// NOLINT
auto
stream
=
auto
stream
=
reinterpret_cast
<
const
platform
::
CustomDeviceContext
&>
(
ctx
).
stream
();
reinterpret_cast
<
const
platform
::
CustomDeviceContext
&>
(
ctx
).
stream
();
...
...
paddle/phi/core/tensor_utils.cc
浏览文件 @
094e3b8c
...
@@ -422,4 +422,449 @@ template void Copy(const OneDNNContext& dev_ctx,
...
@@ -422,4 +422,449 @@ template void Copy(const OneDNNContext& dev_ctx,
bool
blocking
,
bool
blocking
,
DenseTensor
*
dst
);
DenseTensor
*
dst
);
#endif
#endif
template
<
typename
T
>
void
TensorFromVector
(
const
std
::
vector
<
T
>&
src
,
const
phi
::
DeviceContext
&
ctx
,
phi
::
DenseTensor
*
dst
)
{
auto
dst_place
=
ctx
.
GetPlace
();
auto
src_ptr
=
static_cast
<
const
void
*>
(
src
.
data
());
phi
::
CPUPlace
src_place
;
dst
->
Resize
({
static_cast
<
int64_t
>
(
src
.
size
())});
ctx
.
template
Alloc
<
T
>(
dst
);
auto
dst_ptr
=
static_cast
<
void
*>
(
dst
->
data
<
T
>
());
auto
size
=
src
.
size
()
*
sizeof
(
T
);
if
(
paddle
::
platform
::
is_cpu_place
(
dst_place
))
{
paddle
::
memory
::
Copy
(
dst_place
,
dst_ptr
,
src_place
,
src_ptr
,
size
);
}
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
else
if
(
paddle
::
platform
::
is_gpu_place
(
dst_place
))
{
// NOLINT
paddle
::
memory
::
Copy
(
dst_place
,
dst_ptr
,
src_place
,
src_ptr
,
size
,
reinterpret_cast
<
const
phi
::
GPUContext
&>
(
ctx
).
stream
());
}
#endif
#ifdef PADDLE_WITH_CUSTOM_DEVICE
else
if
(
paddle
::
platform
::
is_custom_place
(
dst_place
))
{
// NOLINT
paddle
::
memory
::
Copy
(
dst_place
,
dst_ptr
,
src_place
,
src_ptr
,
size
,
reinterpret_cast
<
const
phi
::
CustomContext
&>
(
ctx
).
stream
());
}
#endif
#ifdef PADDLE_WITH_XPU
else
if
(
paddle
::
platform
::
is_xpu_place
(
dst_place
))
{
// NOLINT
paddle
::
memory
::
Copy
(
dst_place
,
dst_ptr
,
src_place
,
src_ptr
,
size
);
}
#endif
else
{
// NOLINT
PADDLE_THROW
(
phi
::
errors
::
Unimplemented
(
"TensorFromVector on %s is not supported."
,
dst_place
));
}
}
template
<
>
void
TensorFromVector
(
const
std
::
vector
<
bool
>&
src
,
const
phi
::
DeviceContext
&
ctx
,
phi
::
DenseTensor
*
dst
)
{
// vector<bool> has no data() member, use array instead.
// See details:
// https://stackoverflow.com/questions/46115669/why-does-stdvectorbool-have-no-data/46115714
bool
*
array
=
new
bool
[
src
.
size
()];
for
(
unsigned
int
i
=
0
;
i
<
src
.
size
();
i
++
)
{
array
[
i
]
=
static_cast
<
bool
>
(
src
[
i
]);
}
auto
dst_place
=
ctx
.
GetPlace
();
auto
src_ptr
=
static_cast
<
const
void
*>
(
array
);
phi
::
CPUPlace
src_place
{};
dst
->
Resize
({
static_cast
<
int64_t
>
(
src
.
size
())});
auto
dst_ptr
=
ctx
.
template
Alloc
<
bool
>(
dst
);
auto
size
=
src
.
size
()
*
sizeof
(
bool
);
if
(
paddle
::
platform
::
is_cpu_place
(
dst_place
))
{
paddle
::
memory
::
Copy
(
dst_place
,
dst_ptr
,
src_place
,
src_ptr
,
size
);
}
#ifdef PADDLE_WITH_CUDA
else
if
(
paddle
::
platform
::
is_gpu_place
(
dst_place
))
{
// NOLINT
paddle
::
memory
::
Copy
(
dst_place
,
dst_ptr
,
src_place
,
src_ptr
,
size
,
reinterpret_cast
<
const
phi
::
GPUContext
&>
(
ctx
).
stream
());
}
#endif
#ifdef PADDLE_WITH_CUSTOM_DEVICE
else
if
(
paddle
::
platform
::
is_custom_place
(
dst_place
))
{
// NOLINT
auto
stream
=
reinterpret_cast
<
const
phi
::
CustomContext
&>
(
ctx
).
stream
();
paddle
::
memory
::
Copy
(
dst_place
,
dst_ptr
,
src_place
,
src_ptr
,
size
,
stream
);
}
#endif
#ifdef PADDLE_WITH_XPU
else
if
(
paddle
::
platform
::
is_xpu_place
(
dst_place
))
{
// NOLINT
paddle
::
memory
::
Copy
(
dst_place
,
dst_ptr
,
src_place
,
src_ptr
,
size
);
}
#endif
else
{
// NOLINT
PADDLE_THROW
(
phi
::
errors
::
Unimplemented
(
"TensorFromVector on %s is not supported."
,
dst_place
));
}
delete
[]
array
;
}
template
void
TensorFromVector
<
int8_t
>(
const
std
::
vector
<
int8_t
>&
src
,
const
phi
::
DeviceContext
&
ctx
,
phi
::
DenseTensor
*
dst
);
template
void
TensorFromVector
<
uint8_t
>(
const
std
::
vector
<
uint8_t
>&
src
,
const
phi
::
DeviceContext
&
ctx
,
phi
::
DenseTensor
*
dst
);
template
void
TensorFromVector
<
int16_t
>(
const
std
::
vector
<
int16_t
>&
src
,
const
phi
::
DeviceContext
&
ctx
,
phi
::
DenseTensor
*
dst
);
template
void
TensorFromVector
<
int
>(
const
std
::
vector
<
int
>&
src
,
const
phi
::
DeviceContext
&
ctx
,
phi
::
DenseTensor
*
dst
);
template
void
TensorFromVector
<
int64_t
>(
const
std
::
vector
<
int64_t
>&
src
,
const
phi
::
DeviceContext
&
ctx
,
phi
::
DenseTensor
*
dst
);
template
void
TensorFromVector
<
float
>(
const
std
::
vector
<
float
>&
src
,
const
phi
::
DeviceContext
&
ctx
,
phi
::
DenseTensor
*
dst
);
template
void
TensorFromVector
<
double
>(
const
std
::
vector
<
double
>&
src
,
const
phi
::
DeviceContext
&
ctx
,
phi
::
DenseTensor
*
dst
);
template
void
TensorFromVector
<
phi
::
dtype
::
bfloat16
>(
const
std
::
vector
<
phi
::
dtype
::
bfloat16
>&
src
,
const
phi
::
DeviceContext
&
ctx
,
phi
::
DenseTensor
*
dst
);
template
void
TensorFromVector
<
phi
::
dtype
::
float16
>(
const
std
::
vector
<
phi
::
dtype
::
float16
>&
src
,
const
phi
::
DeviceContext
&
ctx
,
phi
::
DenseTensor
*
dst
);
template
void
TensorFromVector
<
phi
::
dtype
::
complex
<
float
>
>
(
const
std
::
vector
<
phi
::
dtype
::
complex
<
float
>>&
src
,
const
phi
::
DeviceContext
&
ctx
,
phi
::
DenseTensor
*
dst
);
template
void
TensorFromVector
<
phi
::
dtype
::
complex
<
double
>
>
(
const
std
::
vector
<
phi
::
dtype
::
complex
<
double
>>&
src
,
const
phi
::
DeviceContext
&
ctx
,
phi
::
DenseTensor
*
dst
);
template
<
typename
T
>
void
TensorFromArray
(
const
T
*
src
,
const
size_t
&
array_size
,
const
phi
::
DeviceContext
&
ctx
,
phi
::
DenseTensor
*
dst
)
{
auto
dst_place
=
ctx
.
GetPlace
();
auto
src_ptr
=
static_cast
<
const
void
*>
(
src
);
phi
::
CPUPlace
src_place
;
dst
->
Resize
({
static_cast
<
int64_t
>
(
array_size
)});
ctx
.
template
Alloc
<
T
>(
dst
);
auto
dst_ptr
=
static_cast
<
void
*>
(
dst
->
data
<
T
>
());
auto
size
=
array_size
*
sizeof
(
T
);
if
(
paddle
::
platform
::
is_cpu_place
(
dst_place
))
{
paddle
::
memory
::
Copy
(
dst_place
,
dst_ptr
,
src_place
,
src_ptr
,
size
);
}
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
else
if
(
paddle
::
platform
::
is_gpu_place
(
dst_place
))
{
// NOLINT
paddle
::
memory
::
Copy
(
dst_place
,
dst_ptr
,
src_place
,
src_ptr
,
size
,
reinterpret_cast
<
const
phi
::
GPUContext
&>
(
ctx
).
stream
());
}
#endif
#ifdef PADDLE_WITH_CUSTOM_DEVICE
else
if
(
paddle
::
platform
::
is_custom_place
(
dst_place
))
{
// NOLINT
paddle
::
memory
::
Copy
(
dst_place
,
dst_ptr
,
src_place
,
src_ptr
,
size
,
reinterpret_cast
<
const
phi
::
CustomContext
&>
(
ctx
).
stream
());
}
#endif
#ifdef PADDLE_WITH_XPU
else
if
(
paddle
::
platform
::
is_xpu_place
(
dst_place
))
{
// NOLINT
paddle
::
memory
::
Copy
(
dst_place
,
dst_ptr
,
src_place
,
src_ptr
,
size
);
}
#endif
else
{
// NOLINT
PADDLE_THROW
(
phi
::
errors
::
Unimplemented
(
"TensorFromArray on %s is not supported."
,
dst_place
));
}
}
template
void
TensorFromArray
<
bool
>(
const
bool
*
src
,
const
size_t
&
array_size
,
const
phi
::
DeviceContext
&
ctx
,
phi
::
DenseTensor
*
dst
);
template
void
TensorFromArray
<
int16_t
>(
const
int16_t
*
src
,
const
size_t
&
array_size
,
const
phi
::
DeviceContext
&
ctx
,
phi
::
DenseTensor
*
dst
);
template
void
TensorFromArray
<
int
>(
const
int
*
src
,
const
size_t
&
array_size
,
const
phi
::
DeviceContext
&
ctx
,
phi
::
DenseTensor
*
dst
);
template
void
TensorFromArray
<
int64_t
>(
const
int64_t
*
src
,
const
size_t
&
array_size
,
const
phi
::
DeviceContext
&
ctx
,
phi
::
DenseTensor
*
dst
);
template
void
TensorFromArray
<
float
>(
const
float
*
src
,
const
size_t
&
array_size
,
const
phi
::
DeviceContext
&
ctx
,
phi
::
DenseTensor
*
dst
);
template
void
TensorFromArray
<
double
>(
const
double
*
src
,
const
size_t
&
array_size
,
const
phi
::
DeviceContext
&
ctx
,
phi
::
DenseTensor
*
dst
);
template
void
TensorFromArray
<
phi
::
dtype
::
bfloat16
>(
const
phi
::
dtype
::
bfloat16
*
src
,
const
size_t
&
array_size
,
const
phi
::
DeviceContext
&
ctx
,
phi
::
DenseTensor
*
dst
);
template
void
TensorFromArray
<
phi
::
dtype
::
float16
>(
const
phi
::
dtype
::
float16
*
src
,
const
size_t
&
array_size
,
const
phi
::
DeviceContext
&
ctx
,
phi
::
DenseTensor
*
dst
);
template
void
TensorFromArray
<
phi
::
dtype
::
complex
<
float
>
>
(
const
phi
::
dtype
::
complex
<
float
>*
src
,
const
size_t
&
array_size
,
const
phi
::
DeviceContext
&
ctx
,
phi
::
DenseTensor
*
dst
);
template
void
TensorFromArray
<
phi
::
dtype
::
complex
<
double
>
>
(
const
phi
::
dtype
::
complex
<
double
>*
src
,
const
size_t
&
array_size
,
const
phi
::
DeviceContext
&
ctx
,
phi
::
DenseTensor
*
dst
);
template
<
typename
T
>
void
TensorToVector
(
const
phi
::
DenseTensor
&
src
,
const
phi
::
DeviceContext
&
ctx
,
std
::
vector
<
T
>*
dst
)
{
auto
src_ptr
=
static_cast
<
const
void
*>
(
src
.
data
<
T
>
());
auto
size
=
src
.
numel
()
*
sizeof
(
T
);
phi
::
CPUPlace
dst_place
{};
dst
->
resize
(
src
.
numel
());
auto
dst_ptr
=
static_cast
<
void
*>
(
dst
->
data
());
if
(
paddle
::
platform
::
is_cpu_place
(
src
.
place
()))
{
paddle
::
memory
::
Copy
(
dst_place
,
dst_ptr
,
src
.
place
(),
src_ptr
,
size
);
}
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
else
if
(
paddle
::
platform
::
is_gpu_place
(
src
.
place
()))
{
// NOLINT
paddle
::
memory
::
Copy
(
dst_place
,
dst_ptr
,
src
.
place
(),
src_ptr
,
size
,
reinterpret_cast
<
const
phi
::
GPUContext
&>
(
ctx
).
stream
());
}
#endif
#if defined(PADDLE_WITH_XPU)
else
if
(
paddle
::
platform
::
is_xpu_place
(
src
.
place
()))
{
// NOLINT
paddle
::
memory
::
Copy
(
dst_place
,
dst_ptr
,
src
.
place
(),
src_ptr
,
size
);
}
#endif
#ifdef PADDLE_WITH_CUSTOM_DEVICE
else
if
(
paddle
::
platform
::
is_custom_place
(
src
.
place
()))
{
// NOLINT
paddle
::
memory
::
Copy
(
dst_place
,
dst_ptr
,
src
.
place
(),
src_ptr
,
size
,
nullptr
);
}
#endif
else
{
// NOLINT
PADDLE_THROW
(
phi
::
errors
::
Unimplemented
(
"TensorToVector on %s is not supported."
,
src
.
place
()));
}
}
template
<
>
void
TensorToVector
(
const
phi
::
DenseTensor
&
src
,
const
phi
::
DeviceContext
&
ctx
,
std
::
vector
<
bool
>*
dst
)
{
auto
src_ptr
=
static_cast
<
const
void
*>
(
src
.
data
<
bool
>
());
auto
size
=
src
.
numel
()
*
sizeof
(
bool
);
bool
*
array
=
new
bool
[
src
.
numel
()];
phi
::
CPUPlace
dst_place
{};
dst
->
resize
(
src
.
numel
());
auto
dst_ptr
=
static_cast
<
void
*>
(
array
);
if
(
paddle
::
platform
::
is_cpu_place
(
src
.
place
()))
{
paddle
::
memory
::
Copy
(
dst_place
,
dst_ptr
,
src
.
place
(),
src_ptr
,
size
);
}
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
else
if
(
paddle
::
platform
::
is_gpu_place
(
src
.
place
()))
{
// NOLINT
paddle
::
memory
::
Copy
(
dst_place
,
dst_ptr
,
src
.
place
(),
src_ptr
,
size
,
reinterpret_cast
<
const
phi
::
GPUContext
&>
(
ctx
).
stream
());
}
#endif
#if defined(PADDLE_WITH_XPU)
else
if
(
paddle
::
platform
::
is_xpu_place
(
src
.
place
()))
{
// NOLINT
paddle
::
memory
::
Copy
(
dst_place
,
dst_ptr
,
src
.
place
(),
src_ptr
,
size
);
}
#endif
#ifdef PADDLE_WITH_CUSTOM_DEVICE
else
if
(
paddle
::
platform
::
is_custom_place
(
src
.
place
()))
{
// NOLINT
paddle
::
memory
::
Copy
(
dst_place
,
dst_ptr
,
src
.
place
(),
src_ptr
,
size
,
nullptr
);
}
#endif
for
(
unsigned
int
i
=
0
;
i
<
src
.
numel
();
i
++
)
{
(
*
dst
)[
i
]
=
static_cast
<
bool
>
(
array
[
i
]);
}
delete
[]
array
;
}
template
void
TensorToVector
(
const
phi
::
DenseTensor
&
src
,
const
phi
::
DeviceContext
&
ctx
,
std
::
vector
<
int16_t
>
*
dst
);
template
void
TensorToVector
(
const
phi
::
DenseTensor
&
src
,
const
phi
::
DeviceContext
&
ctx
,
std
::
vector
<
int
>
*
dst
);
template
void
TensorToVector
(
const
phi
::
DenseTensor
&
src
,
const
phi
::
DeviceContext
&
ctx
,
std
::
vector
<
int64_t
>
*
dst
);
template
void
TensorToVector
(
const
phi
::
DenseTensor
&
src
,
const
phi
::
DeviceContext
&
ctx
,
std
::
vector
<
float
>
*
dst
);
template
void
TensorToVector
(
const
phi
::
DenseTensor
&
src
,
const
phi
::
DeviceContext
&
ctx
,
std
::
vector
<
double
>
*
dst
);
template
void
TensorToVector
(
const
phi
::
DenseTensor
&
src
,
const
phi
::
DeviceContext
&
ctx
,
std
::
vector
<
phi
::
dtype
::
bfloat16
>
*
dst
);
template
void
TensorToVector
(
const
phi
::
DenseTensor
&
src
,
const
phi
::
DeviceContext
&
ctx
,
std
::
vector
<
phi
::
dtype
::
float16
>
*
dst
);
template
void
TensorToVector
(
const
phi
::
DenseTensor
&
src
,
const
phi
::
DeviceContext
&
ctx
,
std
::
vector
<
phi
::
dtype
::
complex
<
float
>
>*
dst
);
template
void
TensorToVector
(
const
phi
::
DenseTensor
&
src
,
const
phi
::
DeviceContext
&
ctx
,
std
::
vector
<
phi
::
dtype
::
complex
<
double
>
>*
dst
);
template
<
typename
T
>
void
TensorToVector
(
const
phi
::
DenseTensor
&
src
,
std
::
vector
<
T
>*
dst
)
{
auto
src_ptr
=
static_cast
<
const
void
*>
(
src
.
data
<
T
>
());
auto
size
=
src
.
numel
()
*
sizeof
(
T
);
phi
::
CPUPlace
dst_place
{};
dst
->
resize
(
src
.
numel
());
auto
dst_ptr
=
static_cast
<
void
*>
(
dst
->
data
());
PADDLE_ENFORCE_EQ
(
paddle
::
platform
::
is_cpu_place
(
src
.
place
()),
true
,
phi
::
errors
::
InvalidArgument
(
"The input tensor should be CPU device, but actually it is in %s."
,
src
.
place
()));
paddle
::
memory
::
Copy
(
dst_place
,
dst_ptr
,
src
.
place
(),
src_ptr
,
size
);
}
template
<
>
void
TensorToVector
(
const
phi
::
DenseTensor
&
src
,
std
::
vector
<
bool
>*
dst
)
{
auto
src_ptr
=
static_cast
<
const
void
*>
(
src
.
data
<
bool
>
());
auto
size
=
src
.
numel
()
*
sizeof
(
bool
);
bool
*
array
=
new
bool
[
src
.
numel
()];
paddle
::
platform
::
CPUPlace
dst_place
{};
dst
->
resize
(
src
.
numel
());
auto
dst_ptr
=
static_cast
<
void
*>
(
array
);
PADDLE_ENFORCE_EQ
(
paddle
::
platform
::
is_cpu_place
(
src
.
place
()),
true
,
phi
::
errors
::
InvalidArgument
(
"The input tensor should be CPU device, but actually it is in %s."
,
src
.
place
()));
paddle
::
memory
::
Copy
(
dst_place
,
dst_ptr
,
src
.
place
(),
src_ptr
,
size
);
for
(
unsigned
int
i
=
0
;
i
<
src
.
numel
();
i
++
)
{
(
*
dst
)[
i
]
=
static_cast
<
bool
>
(
array
[
i
]);
}
delete
[]
array
;
}
template
void
TensorToVector
(
const
phi
::
DenseTensor
&
src
,
std
::
vector
<
int16_t
>
*
dst
);
template
void
TensorToVector
(
const
phi
::
DenseTensor
&
src
,
std
::
vector
<
int
>
*
dst
);
template
void
TensorToVector
(
const
phi
::
DenseTensor
&
src
,
std
::
vector
<
int64_t
>
*
dst
);
template
void
TensorToVector
(
const
phi
::
DenseTensor
&
src
,
std
::
vector
<
float
>
*
dst
);
template
void
TensorToVector
(
const
phi
::
DenseTensor
&
src
,
std
::
vector
<
double
>
*
dst
);
template
void
TensorToVector
(
const
phi
::
DenseTensor
&
src
,
std
::
vector
<
phi
::
dtype
::
bfloat16
>
*
dst
);
template
void
TensorToVector
(
const
phi
::
DenseTensor
&
src
,
std
::
vector
<
phi
::
dtype
::
float16
>
*
dst
);
template
void
TensorToVector
(
const
phi
::
DenseTensor
&
src
,
std
::
vector
<
phi
::
dtype
::
complex
<
float
>
>*
dst
);
template
void
TensorToVector
(
const
phi
::
DenseTensor
&
src
,
std
::
vector
<
phi
::
dtype
::
complex
<
double
>
>*
dst
);
}
// namespace phi
}
// namespace phi
paddle/phi/core/tensor_utils.h
浏览文件 @
094e3b8c
...
@@ -15,6 +15,7 @@ limitations under the License. */
...
@@ -15,6 +15,7 @@ limitations under the License. */
#pragma once
#pragma once
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/core/device_context.h"
#include "paddle/phi/core/selected_rows.h"
#include "paddle/phi/core/selected_rows.h"
#include "paddle/phi/core/sparse_coo_tensor.h"
#include "paddle/phi/core/sparse_coo_tensor.h"
#include "paddle/phi/core/sparse_csr_tensor.h"
#include "paddle/phi/core/sparse_csr_tensor.h"
...
@@ -109,4 +110,20 @@ void Copy(const Context& dev_ctx,
...
@@ -109,4 +110,20 @@ void Copy(const Context& dev_ctx,
bool
blocking
,
bool
blocking
,
SparseCsrTensor
*
dst
);
SparseCsrTensor
*
dst
);
template
<
typename
T
>
void
TensorFromVector
(
const
std
::
vector
<
T
>&
src
,
const
phi
::
DeviceContext
&
ctx
,
phi
::
DenseTensor
*
dst
);
template
<
typename
T
>
void
TensorFromArray
(
const
T
*
src
,
const
size_t
&
array_size
,
const
phi
::
DeviceContext
&
ctx
,
phi
::
DenseTensor
*
dst
);
template
<
typename
T
>
void
TensorToVector
(
const
phi
::
DenseTensor
&
src
,
const
phi
::
DeviceContext
&
ctx
,
std
::
vector
<
T
>*
dst
);
}
// namespace phi
}
// namespace phi
paddle/phi/kernels/assign_kernel.cc
浏览文件 @
094e3b8c
...
@@ -14,7 +14,6 @@
...
@@ -14,7 +14,6 @@
#include "paddle/phi/kernels/assign_kernel.h"
#include "paddle/phi/kernels/assign_kernel.h"
#include "paddle/fluid/framework/tensor_util.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/tensor_utils.h"
#include "paddle/phi/core/tensor_utils.h"
#include "paddle/utils/optional.h"
#include "paddle/utils/optional.h"
...
@@ -25,7 +24,7 @@ template <typename Context>
...
@@ -25,7 +24,7 @@ template <typename Context>
void
AssignKernel
(
const
Context
&
dev_ctx
,
void
AssignKernel
(
const
Context
&
dev_ctx
,
const
DenseTensor
&
x
,
const
DenseTensor
&
x
,
DenseTensor
*
out
)
{
DenseTensor
*
out
)
{
p
addle
::
framework
::
TensorCopy
(
x
,
x
.
place
()
,
out
);
p
hi
::
Copy
(
dev_ctx
,
x
,
x
.
place
(),
false
,
out
);
}
}
template
<
typename
Context
>
template
<
typename
Context
>
...
@@ -65,15 +64,14 @@ typename std::enable_if<std::is_same<T, bool>::value>::type CopyVectorToTensor(
...
@@ -65,15 +64,14 @@ typename std::enable_if<std::is_same<T, bool>::value>::type CopyVectorToTensor(
for
(
const
auto
&
val
:
values
)
{
for
(
const
auto
&
val
:
values
)
{
assign_values
.
emplace_back
(
val
.
to
<
int
>
());
assign_values
.
emplace_back
(
val
.
to
<
int
>
());
}
}
p
addle
::
framework
::
TensorFromVector
(
assign_values
,
dev_ctx
,
out
);
p
hi
::
TensorFromVector
(
assign_values
,
dev_ctx
,
out
);
// use the array to replace to vector
// use the array to replace to vector
bool
*
array_ptr
=
new
T
[
assign_values
.
size
()];
bool
*
array_ptr
=
new
T
[
assign_values
.
size
()];
for
(
unsigned
int
i
=
0
;
i
<
assign_values
.
size
();
i
++
)
{
for
(
unsigned
int
i
=
0
;
i
<
assign_values
.
size
();
i
++
)
{
array_ptr
[
i
]
=
static_cast
<
T
>
(
assign_values
[
i
]);
array_ptr
[
i
]
=
static_cast
<
T
>
(
assign_values
[
i
]);
}
}
paddle
::
framework
::
TensorFromArray
(
phi
::
TensorFromArray
(
array_ptr
,
assign_values
.
size
(),
dev_ctx
,
out
);
array_ptr
,
assign_values
.
size
(),
dev_ctx
,
out
);
delete
[]
array_ptr
;
delete
[]
array_ptr
;
}
}
...
@@ -87,7 +85,7 @@ typename std::enable_if<!std::is_same<T, bool>::value>::type CopyVectorToTensor(
...
@@ -87,7 +85,7 @@ typename std::enable_if<!std::is_same<T, bool>::value>::type CopyVectorToTensor(
for
(
const
auto
&
val
:
values
)
{
for
(
const
auto
&
val
:
values
)
{
assign_values
.
emplace_back
(
val
.
to
<
T
>
());
assign_values
.
emplace_back
(
val
.
to
<
T
>
());
}
}
p
addle
::
framework
::
TensorFromVector
(
assign_values
,
dev_ctx
,
out
);
p
hi
::
TensorFromVector
(
assign_values
,
dev_ctx
,
out
);
}
}
template
<
typename
T
,
typename
Context
>
template
<
typename
T
,
typename
Context
>
...
...
paddle/phi/kernels/cpu/adam_kernel.cc
浏览文件 @
094e3b8c
...
@@ -16,7 +16,6 @@
...
@@ -16,7 +16,6 @@
#include <vector>
#include <vector>
#include "paddle/fluid/framework/tensor_util.h"
#include "paddle/fluid/operators/jit/kernels.h"
#include "paddle/fluid/operators/jit/kernels.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/kernel_registry.h"
...
@@ -61,7 +60,7 @@ void AdamDenseKernel(const Context& dev_ctx,
...
@@ -61,7 +60,7 @@ void AdamDenseKernel(const Context& dev_ctx,
errors
::
InvalidArgument
(
"Input(SkipUpdate) size must be 1, but get %d"
,
errors
::
InvalidArgument
(
"Input(SkipUpdate) size must be 1, but get %d"
,
skip_update
->
numel
()));
skip_update
->
numel
()));
std
::
vector
<
bool
>
skip_update_vec
;
std
::
vector
<
bool
>
skip_update_vec
;
p
addle
::
framework
::
TensorToVector
(
*
skip_update
,
dev_ctx
,
&
skip_update_vec
);
p
hi
::
TensorToVector
(
*
skip_update
,
dev_ctx
,
&
skip_update_vec
);
skip_update_
=
skip_update_vec
[
0
];
skip_update_
=
skip_update_vec
[
0
];
}
}
// skip_update=true, just copy input to output, and TensorCopy will call
// skip_update=true, just copy input to output, and TensorCopy will call
...
...
paddle/phi/kernels/cpu/adamw_kernel.cc
浏览文件 @
094e3b8c
...
@@ -16,11 +16,11 @@
...
@@ -16,11 +16,11 @@
#include <vector>
#include <vector>
#include "paddle/fluid/framework/tensor_util.h"
#include "paddle/fluid/operators/jit/kernels.h"
#include "paddle/fluid/operators/jit/kernels.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/common/float16.h"
#include "paddle/phi/common/float16.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/tensor_utils.h"
#include "paddle/phi/kernels/adam_kernel.h"
#include "paddle/phi/kernels/adam_kernel.h"
#include "paddle/phi/kernels/funcs/adam_functors.h"
#include "paddle/phi/kernels/funcs/adam_functors.h"
...
@@ -61,7 +61,7 @@ void AdamwDenseKernel(const Context& dev_ctx,
...
@@ -61,7 +61,7 @@ void AdamwDenseKernel(const Context& dev_ctx,
errors
::
InvalidArgument
(
"Input(SkipUpdate) size must be 1, but get %d"
,
errors
::
InvalidArgument
(
"Input(SkipUpdate) size must be 1, but get %d"
,
skip_update
->
numel
()));
skip_update
->
numel
()));
std
::
vector
<
bool
>
skip_update_vec
;
std
::
vector
<
bool
>
skip_update_vec
;
p
addle
::
framework
::
TensorToVector
(
*
skip_update
,
dev_ctx
,
&
skip_update_vec
);
p
hi
::
TensorToVector
(
*
skip_update
,
dev_ctx
,
&
skip_update_vec
);
skip_update_
=
skip_update_vec
[
0
];
skip_update_
=
skip_update_vec
[
0
];
}
}
VLOG
(
3
)
<<
"Skip update"
<<
skip_update_
;
VLOG
(
3
)
<<
"Skip update"
<<
skip_update_
;
...
...
paddle/phi/kernels/cpu/cross_grad_kernel.cc
浏览文件 @
094e3b8c
...
@@ -14,10 +14,10 @@
...
@@ -14,10 +14,10 @@
#include "paddle/phi/kernels/cross_grad_kernel.h"
#include "paddle/phi/kernels/cross_grad_kernel.h"
#include "paddle/fluid/framework/tensor_util.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/tensor_utils.h"
namespace
phi
{
namespace
phi
{
...
@@ -82,9 +82,9 @@ void CrossGradKernel(const Context &dev_ctx,
...
@@ -82,9 +82,9 @@ void CrossGradKernel(const Context &dev_ctx,
}
}
std
::
vector
<
T
>
input_x_vec
,
input_y_vec
,
input_dout_vec
;
std
::
vector
<
T
>
input_x_vec
,
input_y_vec
,
input_dout_vec
;
p
addle
::
framework
::
TensorToVector
(
input_x
,
dev_ctx
,
&
input_x_vec
);
p
hi
::
TensorToVector
(
input_x
,
dev_ctx
,
&
input_x_vec
);
p
addle
::
framework
::
TensorToVector
(
input_y
,
dev_ctx
,
&
input_y_vec
);
p
hi
::
TensorToVector
(
input_y
,
dev_ctx
,
&
input_y_vec
);
p
addle
::
framework
::
TensorToVector
(
input_out_grad
,
dev_ctx
,
&
input_dout_vec
);
p
hi
::
TensorToVector
(
input_out_grad
,
dev_ctx
,
&
input_dout_vec
);
std
::
vector
<
T
>
out_dx_vec
(
output_x_grad
->
numel
());
std
::
vector
<
T
>
out_dx_vec
(
output_x_grad
->
numel
());
std
::
vector
<
T
>
out_dy_vec
(
output_y_grad
->
numel
());
std
::
vector
<
T
>
out_dy_vec
(
output_y_grad
->
numel
());
...
@@ -106,8 +106,8 @@ void CrossGradKernel(const Context &dev_ctx,
...
@@ -106,8 +106,8 @@ void CrossGradKernel(const Context &dev_ctx,
}
}
}
}
}
}
p
addle
::
framework
::
TensorFromVector
(
out_dx_vec
,
dev_ctx
,
output_x_grad
);
p
hi
::
TensorFromVector
(
out_dx_vec
,
dev_ctx
,
output_x_grad
);
p
addle
::
framework
::
TensorFromVector
(
out_dy_vec
,
dev_ctx
,
output_y_grad
);
p
hi
::
TensorFromVector
(
out_dy_vec
,
dev_ctx
,
output_y_grad
);
output_x_grad
->
Resize
(
input_x_dims
);
output_x_grad
->
Resize
(
input_x_dims
);
output_y_grad
->
Resize
(
input_x_dims
);
output_y_grad
->
Resize
(
input_x_dims
);
}
}
...
...
paddle/phi/kernels/cpu/cross_kernel.cc
浏览文件 @
094e3b8c
...
@@ -81,8 +81,8 @@ void CrossKernel(const Context& dev_ctx,
...
@@ -81,8 +81,8 @@ void CrossKernel(const Context& dev_ctx,
}
}
std
::
vector
<
T
>
input_x_vec
,
input_y_vec
;
std
::
vector
<
T
>
input_x_vec
,
input_y_vec
;
p
addle
::
framework
::
TensorToVector
(
input_x
,
dev_ctx
,
&
input_x_vec
);
p
hi
::
TensorToVector
(
input_x
,
dev_ctx
,
&
input_x_vec
);
p
addle
::
framework
::
TensorToVector
(
input_y
,
dev_ctx
,
&
input_y_vec
);
p
hi
::
TensorToVector
(
input_y
,
dev_ctx
,
&
input_y_vec
);
std
::
vector
<
T
>
out_vec
(
output
->
numel
());
std
::
vector
<
T
>
out_vec
(
output
->
numel
());
dev_ctx
.
template
Alloc
<
T
>(
output
);
dev_ctx
.
template
Alloc
<
T
>(
output
);
...
@@ -100,7 +100,7 @@ void CrossKernel(const Context& dev_ctx,
...
@@ -100,7 +100,7 @@ void CrossKernel(const Context& dev_ctx,
}
}
}
}
}
}
p
addle
::
framework
::
TensorFromVector
(
out_vec
,
dev_ctx
,
output
);
p
hi
::
TensorFromVector
(
out_vec
,
dev_ctx
,
output
);
output
->
Resize
(
input_x_dims
);
output
->
Resize
(
input_x_dims
);
}
}
...
...
paddle/phi/kernels/cpu/index_sample_grad_kernel.cc
浏览文件 @
094e3b8c
...
@@ -14,10 +14,10 @@
...
@@ -14,10 +14,10 @@
#include "paddle/phi/kernels/index_sample_grad_kernel.h"
#include "paddle/phi/kernels/index_sample_grad_kernel.h"
#include "paddle/fluid/framework/tensor_util.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/common/data_type.h"
#include "paddle/phi/common/data_type.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/tensor_utils.h"
#include "paddle/phi/core/utils/data_type.h"
#include "paddle/phi/core/utils/data_type.h"
namespace
phi
{
namespace
phi
{
template
<
typename
T
,
typename
Context
,
typename
IndexT
=
int
>
template
<
typename
T
,
typename
Context
,
typename
IndexT
=
int
>
...
@@ -27,8 +27,8 @@ void IndexSampleGradInner(const Context& context,
...
@@ -27,8 +27,8 @@ void IndexSampleGradInner(const Context& context,
DenseTensor
*
x_grad
)
{
DenseTensor
*
x_grad
)
{
std
::
vector
<
T
>
out_grad_vec
;
std
::
vector
<
T
>
out_grad_vec
;
std
::
vector
<
IndexT
>
index_vec
;
std
::
vector
<
IndexT
>
index_vec
;
p
addle
::
framework
::
TensorToVector
(
out_grad
,
context
,
&
out_grad_vec
);
p
hi
::
TensorToVector
(
out_grad
,
context
,
&
out_grad_vec
);
p
addle
::
framework
::
TensorToVector
(
index
,
context
,
&
index_vec
);
p
hi
::
TensorToVector
(
index
,
context
,
&
index_vec
);
auto
index_dims
=
index
.
dims
();
auto
index_dims
=
index
.
dims
();
auto
x_grad_dims
=
x_grad
->
dims
();
auto
x_grad_dims
=
x_grad
->
dims
();
...
@@ -63,7 +63,7 @@ void IndexSampleGradInner(const Context& context,
...
@@ -63,7 +63,7 @@ void IndexSampleGradInner(const Context& context,
x_grad_vec
[
v_i
]
+=
out_grad_vec
[
i
];
x_grad_vec
[
v_i
]
+=
out_grad_vec
[
i
];
}
}
context
.
template
Alloc
<
T
>(
x_grad
);
context
.
template
Alloc
<
T
>(
x_grad
);
p
addle
::
framework
::
TensorFromVector
(
x_grad_vec
,
context
,
x_grad
);
p
hi
::
TensorFromVector
(
x_grad_vec
,
context
,
x_grad
);
x_grad
->
Resize
(
x_grad_dims
);
x_grad
->
Resize
(
x_grad_dims
);
}
}
...
...
paddle/phi/kernels/cpu/index_sample_kernel.cc
浏览文件 @
094e3b8c
...
@@ -21,10 +21,10 @@
...
@@ -21,10 +21,10 @@
#include <utility>
#include <utility>
#include <vector>
#include <vector>
#include "paddle/fluid/framework/tensor_util.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/common/data_type.h"
#include "paddle/phi/common/data_type.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/tensor_utils.h"
#include "paddle/phi/core/utils/data_type.h"
#include "paddle/phi/core/utils/data_type.h"
namespace
phi
{
namespace
phi
{
template
<
typename
T
,
typename
Context
,
typename
IndexT
=
int
>
template
<
typename
T
,
typename
Context
,
typename
IndexT
=
int
>
...
@@ -42,8 +42,8 @@ void IndexSampleInner(const Context &context,
...
@@ -42,8 +42,8 @@ void IndexSampleInner(const Context &context,
std
::
vector
<
T
>
input_vec
;
std
::
vector
<
T
>
input_vec
;
std
::
vector
<
IndexT
>
index_vec
;
std
::
vector
<
IndexT
>
index_vec
;
p
addle
::
framework
::
TensorToVector
(
input
,
context
,
&
input_vec
);
p
hi
::
TensorToVector
(
input
,
context
,
&
input_vec
);
p
addle
::
framework
::
TensorToVector
<
IndexT
>
(
index
,
context
,
&
index_vec
);
p
hi
::
TensorToVector
<
IndexT
>
(
index
,
context
,
&
index_vec
);
std
::
vector
<
T
>
res
(
index_ids_num
);
std
::
vector
<
T
>
res
(
index_ids_num
);
for
(
int
i
=
0
;
i
<
index_ids_num
;
i
++
)
{
for
(
int
i
=
0
;
i
<
index_ids_num
;
i
++
)
{
...
@@ -76,7 +76,7 @@ void IndexSampleInner(const Context &context,
...
@@ -76,7 +76,7 @@ void IndexSampleInner(const Context &context,
auto
ddim
=
phi
::
make_ddim
({
batch_size
,
index_length
});
auto
ddim
=
phi
::
make_ddim
({
batch_size
,
index_length
});
context
.
template
Alloc
<
T
>(
output
);
context
.
template
Alloc
<
T
>(
output
);
p
addle
::
framework
::
TensorFromVector
(
res
,
context
,
output
);
p
hi
::
TensorFromVector
(
res
,
context
,
output
);
output
->
Resize
(
ddim
);
output
->
Resize
(
ddim
);
}
}
...
...
paddle/phi/kernels/cpu/repeat_interleave_grad_kernel.cc
浏览文件 @
094e3b8c
...
@@ -94,7 +94,7 @@ void RepeatInterleaveGradKernel(const Context& ctx,
...
@@ -94,7 +94,7 @@ void RepeatInterleaveGradKernel(const Context& ctx,
std
::
fill_n
(
index_vec
.
begin
()
+
i
*
repeats
,
repeats
,
i
);
std
::
fill_n
(
index_vec
.
begin
()
+
i
*
repeats
,
repeats
,
i
);
}
}
index
.
Resize
(
phi
::
make_ddim
({
index_size
}));
index
.
Resize
(
phi
::
make_ddim
({
index_size
}));
p
addle
::
framework
::
TensorFromVector
<
int
>
(
index_vec
,
&
index
);
p
hi
::
TensorFromVector
<
int
>
(
index_vec
,
ctx
,
&
index
);
const
DenseTensor
index_copy
=
index
;
const
DenseTensor
index_copy
=
index
;
IndexSelectGradInner
<
Context
,
T
,
int
>
(
ctx
,
out_grad
,
index_copy
,
x_grad
,
dim
);
IndexSelectGradInner
<
Context
,
T
,
int
>
(
ctx
,
out_grad
,
index_copy
,
x_grad
,
dim
);
}
}
...
...
paddle/phi/kernels/cpu/roll_grad_kernel.cc
浏览文件 @
094e3b8c
...
@@ -14,8 +14,8 @@
...
@@ -14,8 +14,8 @@
#include "paddle/phi/kernels/roll_grad_kernel.h"
#include "paddle/phi/kernels/roll_grad_kernel.h"
#include "paddle/fluid/framework/tensor_util.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/tensor_utils.h"
#include "paddle/phi/kernels/cpu/roll_kernel_impl.h"
#include "paddle/phi/kernels/cpu/roll_kernel_impl.h"
namespace
phi
{
namespace
phi
{
...
@@ -28,7 +28,7 @@ void RollGradKernel(const Context& dev_ctx,
...
@@ -28,7 +28,7 @@ void RollGradKernel(const Context& dev_ctx,
const
std
::
vector
<
int64_t
>&
axis
,
const
std
::
vector
<
int64_t
>&
axis
,
DenseTensor
*
x_grad
)
{
DenseTensor
*
x_grad
)
{
std
::
vector
<
T
>
out_vec
;
std
::
vector
<
T
>
out_vec
;
p
addle
::
framework
::
TensorToVector
(
out_grad
,
dev_ctx
,
&
out_vec
);
p
hi
::
TensorToVector
(
out_grad
,
dev_ctx
,
&
out_vec
);
auto
shifts_data
=
shifts
.
GetData
();
auto
shifts_data
=
shifts
.
GetData
();
size_t
nums
=
shifts_data
.
size
();
size_t
nums
=
shifts_data
.
size
();
...
@@ -46,7 +46,7 @@ void RollGradKernel(const Context& dev_ctx,
...
@@ -46,7 +46,7 @@ void RollGradKernel(const Context& dev_ctx,
}
}
dev_ctx
.
template
Alloc
<
T
>(
x_grad
);
dev_ctx
.
template
Alloc
<
T
>(
x_grad
);
p
addle
::
framework
::
TensorFromVector
(
out_vec
,
dev_ctx
,
x_grad
);
p
hi
::
TensorFromVector
(
out_vec
,
dev_ctx
,
x_grad
);
x_grad
->
Resize
(
out_grad
.
dims
());
x_grad
->
Resize
(
out_grad
.
dims
());
}
}
...
...
paddle/phi/kernels/cpu/roll_kernel.cc
浏览文件 @
094e3b8c
...
@@ -14,10 +14,10 @@
...
@@ -14,10 +14,10 @@
#include "paddle/phi/kernels/roll_kernel.h"
#include "paddle/phi/kernels/roll_kernel.h"
#include "paddle/fluid/framework/tensor_util.h"
#include "paddle/phi/common/complex.h"
#include "paddle/phi/common/complex.h"
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/tensor_utils.h"
#include "paddle/phi/kernels/cpu/roll_kernel_impl.h"
#include "paddle/phi/kernels/cpu/roll_kernel_impl.h"
namespace
phi
{
namespace
phi
{
...
@@ -29,7 +29,7 @@ void RollKernel(const Context& dev_ctx,
...
@@ -29,7 +29,7 @@ void RollKernel(const Context& dev_ctx,
const
std
::
vector
<
int64_t
>&
axis
,
const
std
::
vector
<
int64_t
>&
axis
,
DenseTensor
*
out
)
{
DenseTensor
*
out
)
{
std
::
vector
<
T
>
out_vec
;
std
::
vector
<
T
>
out_vec
;
p
addle
::
framework
::
TensorToVector
(
x
,
dev_ctx
,
&
out_vec
);
p
hi
::
TensorToVector
(
x
,
dev_ctx
,
&
out_vec
);
auto
shifts_data
=
shifts
.
GetData
();
auto
shifts_data
=
shifts
.
GetData
();
size_t
nums
=
shifts_data
.
size
();
size_t
nums
=
shifts_data
.
size
();
...
@@ -57,7 +57,7 @@ void RollKernel(const Context& dev_ctx,
...
@@ -57,7 +57,7 @@ void RollKernel(const Context& dev_ctx,
ShiftAlongDim
(
out_vec
.
data
(),
input_dim
,
dims
[
i
],
shifts_data
[
i
]);
ShiftAlongDim
(
out_vec
.
data
(),
input_dim
,
dims
[
i
],
shifts_data
[
i
]);
}
}
dev_ctx
.
template
Alloc
<
T
>(
out
);
dev_ctx
.
template
Alloc
<
T
>(
out
);
p
addle
::
framework
::
TensorFromVector
(
out_vec
,
dev_ctx
,
out
);
p
hi
::
TensorFromVector
(
out_vec
,
dev_ctx
,
out
);
out
->
Resize
(
x
.
dims
());
out
->
Resize
(
x
.
dims
());
}
}
...
...
paddle/phi/kernels/cpu/unique_consecutive_functor.h
浏览文件 @
094e3b8c
...
@@ -14,9 +14,8 @@
...
@@ -14,9 +14,8 @@
#pragma once
#pragma once
#include "paddle/fluid/framework/tensor_util.h"
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/core/tensor_utils.h"
#include "paddle/phi/kernels/funcs/concat_and_split_functor.h"
#include "paddle/phi/kernels/funcs/concat_and_split_functor.h"
#include "paddle/phi/kernels/funcs/math_function.h"
#include "paddle/phi/kernels/funcs/math_function.h"
#include "paddle/phi/kernels/funcs/unique_functor.h"
#include "paddle/phi/kernels/funcs/unique_functor.h"
...
@@ -210,10 +209,10 @@ static void UniqueConsecutiveDim(const Context& context,
...
@@ -210,10 +209,10 @@ static void UniqueConsecutiveDim(const Context& context,
phi
::
funcs
::
TransCompute
<
Context
,
InT
>
(
phi
::
funcs
::
TransCompute
<
Context
,
InT
>
(
out_trans
.
dims
().
size
(),
context
,
out_trans
,
out
,
permute
);
out_trans
.
dims
().
size
(),
context
,
out_trans
,
out
,
permute
);
if
(
return_inverse
)
{
if
(
return_inverse
)
{
p
addle
::
framework
::
TensorFromVector
(
inverse_vec
,
context
,
inverse
);
p
hi
::
TensorFromVector
(
inverse_vec
,
context
,
inverse
);
}
}
if
(
return_counts
)
{
if
(
return_counts
)
{
p
addle
::
framework
::
TensorFromVector
(
counts_vec
,
context
,
count
);
p
hi
::
TensorFromVector
(
counts_vec
,
context
,
count
);
}
}
}
}
...
...
paddle/phi/kernels/funcs/repeat_tensor2index_tensor.h
浏览文件 @
094e3b8c
...
@@ -42,7 +42,7 @@ void RepeatsTensor2IndexTensor(const Context& ctx,
...
@@ -42,7 +42,7 @@ void RepeatsTensor2IndexTensor(const Context& ctx,
}
}
index
->
Resize
(
phi
::
make_ddim
({
index_size
}));
index
->
Resize
(
phi
::
make_ddim
({
index_size
}));
p
addle
::
framework
::
TensorFromVector
<
RepeatsT
>
(
index_vec
,
ctx
,
index
);
p
hi
::
TensorFromVector
<
RepeatsT
>
(
index_vec
,
ctx
,
index
);
}
}
}
// namespace funcs
}
// namespace funcs
}
// namespace phi
}
// namespace phi
paddle/phi/kernels/funcs/unique_functor.h
浏览文件 @
094e3b8c
...
@@ -312,15 +312,15 @@ static void UniqueDim(const Context& context,
...
@@ -312,15 +312,15 @@ static void UniqueDim(const Context& context,
out_trans
.
dims
().
size
(),
context
,
out_trans
,
out
,
permute
);
out_trans
.
dims
().
size
(),
context
,
out_trans
,
out
,
permute
);
if
(
return_inverse
)
{
if
(
return_inverse
)
{
p
addle
::
framework
::
TensorFromVector
(
inverse_vec
,
context
,
index
);
p
hi
::
TensorFromVector
(
inverse_vec
,
context
,
index
);
}
}
if
(
return_counts
)
{
if
(
return_counts
)
{
p
addle
::
framework
::
TensorFromVector
(
counts_vec
,
context
,
count
);
p
hi
::
TensorFromVector
(
counts_vec
,
context
,
count
);
}
}
if
(
return_index
)
{
if
(
return_index
)
{
p
addle
::
framework
::
TensorFromVector
(
indices_vec
,
context
,
indices
);
p
hi
::
TensorFromVector
(
indices_vec
,
context
,
indices
);
}
}
}
}
...
...
paddle/phi/kernels/gpu/adam_kernel.cu
浏览文件 @
094e3b8c
...
@@ -18,7 +18,6 @@
...
@@ -18,7 +18,6 @@
#include <vector>
#include <vector>
#include "paddle/fluid/framework/tensor_util.h"
#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/common/amp_type_traits.h"
#include "paddle/phi/common/amp_type_traits.h"
#include "paddle/phi/common/float16.h"
#include "paddle/phi/common/float16.h"
...
@@ -162,7 +161,7 @@ void AdamDenseKernel(const Context& dev_ctx,
...
@@ -162,7 +161,7 @@ void AdamDenseKernel(const Context& dev_ctx,
errors
::
InvalidArgument
(
"Input(SkipUpdate) size must be 1, but get %d"
,
errors
::
InvalidArgument
(
"Input(SkipUpdate) size must be 1, but get %d"
,
skip_update
->
numel
()));
skip_update
->
numel
()));
std
::
vector
<
bool
>
skip_update_vec
;
std
::
vector
<
bool
>
skip_update_vec
;
p
addle
::
framework
::
TensorToVector
(
*
skip_update
,
dev_ctx
,
&
skip_update_vec
);
p
hi
::
TensorToVector
(
*
skip_update
,
dev_ctx
,
&
skip_update_vec
);
skip_update_
=
skip_update_vec
[
0
];
skip_update_
=
skip_update_vec
[
0
];
}
}
// skip_update=true, just copy input to output, and TensorCopy will call
// skip_update=true, just copy input to output, and TensorCopy will call
...
...
paddle/phi/kernels/gpu/adamw_kernel.cu
浏览文件 @
094e3b8c
...
@@ -18,7 +18,6 @@
...
@@ -18,7 +18,6 @@
#include <vector>
#include <vector>
#include "paddle/fluid/framework/tensor_util.h"
#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/common/amp_type_traits.h"
#include "paddle/phi/common/amp_type_traits.h"
#include "paddle/phi/common/bfloat16.h"
#include "paddle/phi/common/bfloat16.h"
...
@@ -181,7 +180,7 @@ void AdamwDenseKernel(const Context& dev_ctx,
...
@@ -181,7 +180,7 @@ void AdamwDenseKernel(const Context& dev_ctx,
errors
::
InvalidArgument
(
"Input(SkipUpdate) size must be 1, but get %d"
,
errors
::
InvalidArgument
(
"Input(SkipUpdate) size must be 1, but get %d"
,
skip_update
->
numel
()));
skip_update
->
numel
()));
std
::
vector
<
bool
>
skip_update_vec
;
std
::
vector
<
bool
>
skip_update_vec
;
p
addle
::
framework
::
TensorToVector
(
*
skip_update
,
dev_ctx
,
&
skip_update_vec
);
p
hi
::
TensorToVector
(
*
skip_update
,
dev_ctx
,
&
skip_update_vec
);
skip_update_
=
skip_update_vec
[
0
];
skip_update_
=
skip_update_vec
[
0
];
}
}
...
...
paddle/phi/kernels/gpu/class_center_sample_kernel.cu
浏览文件 @
094e3b8c
...
@@ -31,6 +31,7 @@ namespace cub = hipcub;
...
@@ -31,6 +31,7 @@ namespace cub = hipcub;
#include "paddle/fluid/framework/tensor_util.h"
#include "paddle/fluid/framework/tensor_util.h"
#include "paddle/phi/core/enforce.h"
#include "paddle/phi/core/enforce.h"
#include "paddle/phi/core/tensor_utils.h"
#if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL)
#if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL)
#include "paddle/fluid/distributed/collective/process_group.h"
#include "paddle/fluid/distributed/collective/process_group.h"
...
@@ -344,8 +345,7 @@ void ClassCenterSampleKernel(const Context& dev_ctx,
...
@@ -344,8 +345,7 @@ void ClassCenterSampleKernel(const Context& dev_ctx,
std
::
vector
<
T
>
shard_dim_vec
(
nranks
+
1
,
0
);
std
::
vector
<
T
>
shard_dim_vec
(
nranks
+
1
,
0
);
shard_dim_vec
[
rank
+
1
]
=
num_classes
;
shard_dim_vec
[
rank
+
1
]
=
num_classes
;
DenseTensor
num_classes_per_device
;
DenseTensor
num_classes_per_device
;
paddle
::
framework
::
TensorFromVector
(
phi
::
TensorFromVector
(
shard_dim_vec
,
dev_ctx
,
&
num_classes_per_device
);
shard_dim_vec
,
dev_ctx
,
&
num_classes_per_device
);
T
*
num_classes_per_device_ptr
=
num_classes_per_device
.
data
<
T
>
();
T
*
num_classes_per_device_ptr
=
num_classes_per_device
.
data
<
T
>
();
#if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL)
#if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL)
...
...
paddle/phi/kernels/gpu/diagonal_grad_kernel.cu
浏览文件 @
094e3b8c
...
@@ -14,9 +14,9 @@
...
@@ -14,9 +14,9 @@
#include "paddle/phi/kernels/diagonal_grad_kernel.h"
#include "paddle/phi/kernels/diagonal_grad_kernel.h"
#include "paddle/fluid/framework/tensor_util.h"
#include "paddle/phi/backends/gpu/gpu_primitives.h"
#include "paddle/phi/backends/gpu/gpu_primitives.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/tensor_utils.h"
#include "paddle/phi/kernels/funcs/diagonal.h"
#include "paddle/phi/kernels/funcs/diagonal.h"
namespace
phi
{
namespace
phi
{
...
@@ -38,8 +38,7 @@ void DiagonalGradKernel(const Context& dev_ctx,
...
@@ -38,8 +38,7 @@ void DiagonalGradKernel(const Context& dev_ctx,
std
::
vector
<
int64_t
>
res_dout
=
vectorize
(
phi
::
stride
(
dout
->
dims
()));
std
::
vector
<
int64_t
>
res_dout
=
vectorize
(
phi
::
stride
(
dout
->
dims
()));
DenseTensor
dout_stride_tensor
;
DenseTensor
dout_stride_tensor
;
paddle
::
framework
::
TensorFromVector
<
int64_t
>
(
phi
::
TensorFromVector
<
int64_t
>
(
res_dout
,
dev_ctx
,
&
dout_stride_tensor
);
res_dout
,
dev_ctx
,
&
dout_stride_tensor
);
int64_t
*
dout_stride
=
dout_stride_tensor
.
data
<
int64_t
>
();
int64_t
*
dout_stride
=
dout_stride_tensor
.
data
<
int64_t
>
();
auto
*
dx
=
in_grad
;
auto
*
dx
=
in_grad
;
...
@@ -49,8 +48,7 @@ void DiagonalGradKernel(const Context& dev_ctx,
...
@@ -49,8 +48,7 @@ void DiagonalGradKernel(const Context& dev_ctx,
std
::
vector
<
int64_t
>
res_dx
=
vectorize
(
phi
::
stride
(
dx
->
dims
()));
std
::
vector
<
int64_t
>
res_dx
=
vectorize
(
phi
::
stride
(
dx
->
dims
()));
DenseTensor
dx_stride_tensor
;
DenseTensor
dx_stride_tensor
;
paddle
::
framework
::
TensorFromVector
<
int64_t
>
(
phi
::
TensorFromVector
<
int64_t
>
(
res_dx
,
dev_ctx
,
&
dx_stride_tensor
);
res_dx
,
dev_ctx
,
&
dx_stride_tensor
);
int64_t
*
dx_stride
=
dx_stride_tensor
.
data
<
int64_t
>
();
int64_t
*
dx_stride
=
dx_stride_tensor
.
data
<
int64_t
>
();
const
int64_t
offset_
=
offset
;
const
int64_t
offset_
=
offset
;
...
...
paddle/phi/kernels/gpu/diagonal_kernel.cu
浏览文件 @
094e3b8c
...
@@ -14,9 +14,9 @@
...
@@ -14,9 +14,9 @@
#include "paddle/phi/kernels/diagonal_kernel.h"
#include "paddle/phi/kernels/diagonal_kernel.h"
#include "paddle/fluid/framework/tensor_util.h"
#include "paddle/phi/backends/gpu/gpu_primitives.h"
#include "paddle/phi/backends/gpu/gpu_primitives.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/tensor_utils.h"
#include "paddle/phi/kernels/funcs/diagonal.h"
#include "paddle/phi/kernels/funcs/diagonal.h"
namespace
phi
{
namespace
phi
{
...
@@ -35,8 +35,7 @@ void DiagonalKernel(const Context& dev_ctx,
...
@@ -35,8 +35,7 @@ void DiagonalKernel(const Context& dev_ctx,
std
::
vector
<
int64_t
>
res_in
=
vectorize
(
phi
::
stride
(
input
->
dims
()));
std
::
vector
<
int64_t
>
res_in
=
vectorize
(
phi
::
stride
(
input
->
dims
()));
DenseTensor
input_stride_tensor
;
DenseTensor
input_stride_tensor
;
paddle
::
framework
::
TensorFromVector
<
int64_t
>
(
phi
::
TensorFromVector
<
int64_t
>
(
res_in
,
dev_ctx
,
&
input_stride_tensor
);
res_in
,
dev_ctx
,
&
input_stride_tensor
);
int64_t
*
input_stride
=
input_stride_tensor
.
data
<
int64_t
>
();
int64_t
*
input_stride
=
input_stride_tensor
.
data
<
int64_t
>
();
auto
*
output
=
out
;
auto
*
output
=
out
;
...
@@ -46,8 +45,7 @@ void DiagonalKernel(const Context& dev_ctx,
...
@@ -46,8 +45,7 @@ void DiagonalKernel(const Context& dev_ctx,
std
::
vector
<
int64_t
>
res_out
=
vectorize
(
phi
::
stride
(
output
->
dims
()));
std
::
vector
<
int64_t
>
res_out
=
vectorize
(
phi
::
stride
(
output
->
dims
()));
DenseTensor
output_stride_tensor
;
DenseTensor
output_stride_tensor
;
paddle
::
framework
::
TensorFromVector
<
int64_t
>
(
phi
::
TensorFromVector
<
int64_t
>
(
res_out
,
dev_ctx
,
&
output_stride_tensor
);
res_out
,
dev_ctx
,
&
output_stride_tensor
);
int64_t
*
output_stride
=
output_stride_tensor
.
data
<
int64_t
>
();
int64_t
*
output_stride
=
output_stride_tensor
.
data
<
int64_t
>
();
const
int64_t
offset_
=
offset
;
const
int64_t
offset_
=
offset
;
...
...
paddle/phi/kernels/gpu/margin_cross_entropy_grad_kernel.cu
浏览文件 @
094e3b8c
...
@@ -62,13 +62,12 @@ void GetClassInterval(const gpuStream_t& stream,
...
@@ -62,13 +62,12 @@ void GetClassInterval(const gpuStream_t& stream,
std
::
vector
<
int
>
shard_dim_vec
(
nranks
+
1
,
0
);
std
::
vector
<
int
>
shard_dim_vec
(
nranks
+
1
,
0
);
shard_dim_vec
[
rank
+
1
]
=
D
;
shard_dim_vec
[
rank
+
1
]
=
D
;
if
(
nranks
<=
1
)
{
if
(
nranks
<=
1
)
{
p
addle
::
framework
::
TensorFromVector
(
shard_dim_vec
,
dev_ctx
,
class_interval
);
p
hi
::
TensorFromVector
(
shard_dim_vec
,
dev_ctx
,
class_interval
);
return
;
return
;
}
}
#if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL)
#if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL)
DenseTensor
num_classes_per_device
;
DenseTensor
num_classes_per_device
;
paddle
::
framework
::
TensorFromVector
(
phi
::
TensorFromVector
(
shard_dim_vec
,
dev_ctx
,
&
num_classes_per_device
);
shard_dim_vec
,
dev_ctx
,
&
num_classes_per_device
);
int
*
num_classes_per_device_ptr
=
num_classes_per_device
.
data
<
int
>
();
int
*
num_classes_per_device_ptr
=
num_classes_per_device
.
data
<
int
>
();
auto
map
=
paddle
::
distributed
::
ProcessGroupMapFromGid
::
getInstance
();
auto
map
=
paddle
::
distributed
::
ProcessGroupMapFromGid
::
getInstance
();
...
...
paddle/phi/kernels/gpu/margin_cross_entropy_kernel.cu
浏览文件 @
094e3b8c
...
@@ -57,14 +57,13 @@ void GetClassInterval(const gpuStream_t& stream,
...
@@ -57,14 +57,13 @@ void GetClassInterval(const gpuStream_t& stream,
std
::
vector
<
int
>
shard_dim_vec
(
nranks
+
1
,
0
);
std
::
vector
<
int
>
shard_dim_vec
(
nranks
+
1
,
0
);
shard_dim_vec
[
rank
+
1
]
=
D
;
shard_dim_vec
[
rank
+
1
]
=
D
;
if
(
nranks
<=
1
)
{
if
(
nranks
<=
1
)
{
p
addle
::
framework
::
TensorFromVector
(
shard_dim_vec
,
dev_ctx
,
class_interval
);
p
hi
::
TensorFromVector
(
shard_dim_vec
,
dev_ctx
,
class_interval
);
return
;
return
;
}
}
#if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL)
#if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL)
DenseTensor
num_classes_per_device
;
DenseTensor
num_classes_per_device
;
paddle
::
framework
::
TensorFromVector
(
phi
::
TensorFromVector
(
shard_dim_vec
,
dev_ctx
,
&
num_classes_per_device
);
shard_dim_vec
,
dev_ctx
,
&
num_classes_per_device
);
int
*
num_classes_per_device_ptr
=
num_classes_per_device
.
data
<
int
>
();
int
*
num_classes_per_device_ptr
=
num_classes_per_device
.
data
<
int
>
();
auto
map
=
paddle
::
distributed
::
ProcessGroupMapFromGid
::
getInstance
();
auto
map
=
paddle
::
distributed
::
ProcessGroupMapFromGid
::
getInstance
();
...
...
paddle/phi/kernels/gpu/prior_box_kernel.cu
浏览文件 @
094e3b8c
...
@@ -17,10 +17,10 @@
...
@@ -17,10 +17,10 @@
#include <algorithm>
#include <algorithm>
#include <vector>
#include <vector>
#include "paddle/fluid/framework/tensor_util.h"
#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/tensor_utils.h"
namespace
phi
{
namespace
phi
{
...
@@ -160,15 +160,15 @@ void PriorBoxKernel(const Context& ctx,
...
@@ -160,15 +160,15 @@ void PriorBoxKernel(const Context& ctx,
ctx
.
template
Alloc
<
T
>(
var
);
ctx
.
template
Alloc
<
T
>(
var
);
DenseTensor
r
;
DenseTensor
r
;
p
addle
::
framework
::
TensorFromVector
(
new_aspect_ratios
,
ctx
,
&
r
);
p
hi
::
TensorFromVector
(
new_aspect_ratios
,
ctx
,
&
r
);
DenseTensor
min
;
DenseTensor
min
;
p
addle
::
framework
::
TensorFromVector
(
min_sizes
,
ctx
,
&
min
);
p
hi
::
TensorFromVector
(
min_sizes
,
ctx
,
&
min
);
T
*
max_data
=
nullptr
;
T
*
max_data
=
nullptr
;
DenseTensor
max
;
DenseTensor
max
;
if
(
max_sizes
.
size
()
>
0
)
{
if
(
max_sizes
.
size
()
>
0
)
{
p
addle
::
framework
::
TensorFromVector
(
max_sizes
,
ctx
,
&
max
);
p
hi
::
TensorFromVector
(
max_sizes
,
ctx
,
&
max
);
max_data
=
max
.
data
<
T
>
();
max_data
=
max
.
data
<
T
>
();
}
}
...
@@ -189,7 +189,7 @@ void PriorBoxKernel(const Context& ctx,
...
@@ -189,7 +189,7 @@ void PriorBoxKernel(const Context& ctx,
min_max_aspect_ratios_order
);
min_max_aspect_ratios_order
);
DenseTensor
v
;
DenseTensor
v
;
p
addle
::
framework
::
TensorFromVector
(
variances
,
ctx
,
&
v
);
p
hi
::
TensorFromVector
(
variances
,
ctx
,
&
v
);
grid
=
(
box_num
*
4
+
block
-
1
)
/
block
;
grid
=
(
box_num
*
4
+
block
-
1
)
/
block
;
SetVariance
<
T
><<<
grid
,
block
,
0
,
stream
>>>
(
SetVariance
<
T
><<<
grid
,
block
,
0
,
stream
>>>
(
var
->
data
<
T
>
(),
v
.
data
<
T
>
(),
variances
.
size
(),
box_num
*
4
);
var
->
data
<
T
>
(),
v
.
data
<
T
>
(),
variances
.
size
(),
box_num
*
4
);
...
...
paddle/phi/kernels/gpu/unique_consecutive_functor.h
浏览文件 @
094e3b8c
...
@@ -24,8 +24,6 @@
...
@@ -24,8 +24,6 @@
#include <iostream>
#include <iostream>
#include <vector>
#include <vector>
#include "paddle/fluid/framework/tensor_util.h"
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/core/tensor_utils.h"
#include "paddle/phi/core/tensor_utils.h"
#include "paddle/phi/kernels/funcs/concat_and_split_functor.h"
#include "paddle/phi/kernels/funcs/concat_and_split_functor.h"
...
@@ -293,8 +291,8 @@ void IndexSelect(const Context& context,
...
@@ -293,8 +291,8 @@ void IndexSelect(const Context& context,
std
::
vector
<
InT
>
input_vec
;
std
::
vector
<
InT
>
input_vec
;
std
::
vector
<
IndexT
>
index_vec
;
std
::
vector
<
IndexT
>
index_vec
;
p
addle
::
framework
::
TensorToVector
(
input
,
context
,
&
input_vec
);
p
hi
::
TensorToVector
(
input
,
context
,
&
input_vec
);
p
addle
::
framework
::
TensorToVector
(
index
,
context
,
&
index_vec
);
p
hi
::
TensorToVector
(
index
,
context
,
&
index_vec
);
std
::
vector
<
InT
>
out_vec
(
output
->
numel
());
std
::
vector
<
InT
>
out_vec
(
output
->
numel
());
for
(
int
i
=
0
;
i
<
index_size
;
i
++
)
{
for
(
int
i
=
0
;
i
<
index_size
;
i
++
)
{
...
@@ -331,7 +329,7 @@ void IndexSelect(const Context& context,
...
@@ -331,7 +329,7 @@ void IndexSelect(const Context& context,
}
}
}
}
context
.
template
Alloc
<
InT
>(
output
);
context
.
template
Alloc
<
InT
>(
output
);
p
addle
::
framework
::
TensorFromVector
(
out_vec
,
context
,
output
);
p
hi
::
TensorFromVector
(
out_vec
,
context
,
output
);
output
->
Resize
(
output_dim
);
output
->
Resize
(
output_dim
);
}
}
...
...
paddle/phi/kernels/gpu/unique_kernel.cu
浏览文件 @
094e3b8c
...
@@ -26,7 +26,6 @@
...
@@ -26,7 +26,6 @@
#include <iostream>
#include <iostream>
#include <vector>
#include <vector>
#include "paddle/fluid/framework/tensor_util.h" // TensorToVector()
#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/tensor_utils.h"
#include "paddle/phi/core/tensor_utils.h"
...
@@ -127,8 +126,8 @@ void IndexSelect(const Context& context,
...
@@ -127,8 +126,8 @@ void IndexSelect(const Context& context,
std
::
vector
<
InT
>
input_vec
;
std
::
vector
<
InT
>
input_vec
;
std
::
vector
<
IndexT
>
index_vec
;
std
::
vector
<
IndexT
>
index_vec
;
p
addle
::
framework
::
TensorToVector
(
input
,
context
,
&
input_vec
);
p
hi
::
TensorToVector
(
input
,
context
,
&
input_vec
);
p
addle
::
framework
::
TensorToVector
(
index
,
context
,
&
index_vec
);
p
hi
::
TensorToVector
(
index
,
context
,
&
index_vec
);
std
::
vector
<
InT
>
out_vec
(
output
->
numel
());
std
::
vector
<
InT
>
out_vec
(
output
->
numel
());
for
(
int
i
=
0
;
i
<
index_size
;
i
++
)
{
for
(
int
i
=
0
;
i
<
index_size
;
i
++
)
{
...
@@ -165,7 +164,7 @@ void IndexSelect(const Context& context,
...
@@ -165,7 +164,7 @@ void IndexSelect(const Context& context,
}
}
}
}
context
.
template
Alloc
<
IndexT
>(
output
);
context
.
template
Alloc
<
IndexT
>(
output
);
p
addle
::
framework
::
TensorFromVector
(
out_vec
,
context
,
output
);
p
hi
::
TensorFromVector
(
out_vec
,
context
,
output
);
output
->
Resize
(
output_dim
);
output
->
Resize
(
output_dim
);
}
}
...
...
paddle/phi/kernels/impl/determinant_kernel_impl.h
浏览文件 @
094e3b8c
...
@@ -20,8 +20,8 @@
...
@@ -20,8 +20,8 @@
#include <cmath>
#include <cmath>
#include <vector>
#include <vector>
#include "paddle/fluid/framework/tensor_util.h"
#include "paddle/phi/core/enforce.h"
#include "paddle/phi/core/enforce.h"
#include "paddle/phi/core/tensor_utils.h"
#include "paddle/phi/kernels/determinant_kernel.h"
#include "paddle/phi/kernels/determinant_kernel.h"
namespace
phi
{
namespace
phi
{
...
@@ -71,7 +71,7 @@ struct DeterminantFunctor {
...
@@ -71,7 +71,7 @@ struct DeterminantFunctor {
DenseTensor
*
output
)
{
DenseTensor
*
output
)
{
std
::
vector
<
T
>
input_vec
;
std
::
vector
<
T
>
input_vec
;
std
::
vector
<
T
>
output_vec
;
std
::
vector
<
T
>
output_vec
;
p
addle
::
framework
::
TensorToVector
(
input
,
dev_ctx
,
&
input_vec
);
p
hi
::
TensorToVector
(
input
,
dev_ctx
,
&
input_vec
);
for
(
int64_t
i
=
0
;
i
<
batch_count
;
++
i
)
{
// maybe can be parallel
for
(
int64_t
i
=
0
;
i
<
batch_count
;
++
i
)
{
// maybe can be parallel
auto
begin_iter
=
input_vec
.
begin
()
+
i
*
rank
*
rank
;
auto
begin_iter
=
input_vec
.
begin
()
+
i
*
rank
*
rank
;
auto
end_iter
=
input_vec
.
begin
()
+
(
i
+
1
)
*
rank
*
rank
;
auto
end_iter
=
input_vec
.
begin
()
+
(
i
+
1
)
*
rank
*
rank
;
...
@@ -85,7 +85,7 @@ struct DeterminantFunctor {
...
@@ -85,7 +85,7 @@ struct DeterminantFunctor {
}
}
output_vec
.
push_back
(
matrix
.
determinant
());
output_vec
.
push_back
(
matrix
.
determinant
());
}
}
p
addle
::
framework
::
TensorFromVector
(
output_vec
,
output
);
p
hi
::
TensorFromVector
(
output_vec
,
dev_ctx
,
output
);
}
}
};
};
...
...
paddle/phi/kernels/impl/repeat_interleave_grad_kernel_impl.h
浏览文件 @
094e3b8c
...
@@ -205,7 +205,7 @@ void RepeatInterleaveGradKernel(const Context& ctx,
...
@@ -205,7 +205,7 @@ void RepeatInterleaveGradKernel(const Context& ctx,
std
::
fill_n
(
index_vec
.
begin
()
+
i
*
repeats
,
repeats
,
i
);
std
::
fill_n
(
index_vec
.
begin
()
+
i
*
repeats
,
repeats
,
i
);
}
}
index
.
Resize
(
phi
::
make_ddim
({
index_size
}));
index
.
Resize
(
phi
::
make_ddim
({
index_size
}));
p
addle
::
framework
::
TensorFromVector
<
int
>
(
index_vec
,
ctx
,
&
index
);
p
hi
::
TensorFromVector
<
int
>
(
index_vec
,
ctx
,
&
index
);
const
int
*
index_data
=
index
.
data
<
int
>
();
const
int
*
index_data
=
index
.
data
<
int
>
();
int64_t
index_nums
=
index
.
numel
();
int64_t
index_nums
=
index
.
numel
();
...
...
paddle/phi/kernels/impl/repeat_interleave_kernel_impl.h
浏览文件 @
094e3b8c
...
@@ -75,7 +75,7 @@ void RepeatInterleaveKernel(const Context& ctx,
...
@@ -75,7 +75,7 @@ void RepeatInterleaveKernel(const Context& ctx,
index
.
Resize
(
phi
::
make_ddim
({
index_size
}));
index
.
Resize
(
phi
::
make_ddim
({
index_size
}));
if
(
place
==
cpu_place
)
{
if
(
place
==
cpu_place
)
{
DenseTensor
x_copy
=
x
;
DenseTensor
x_copy
=
x
;
p
addle
::
framework
::
TensorFromVector
<
int
>
(
index_vec
,
&
index
);
p
hi
::
TensorFromVector
<
int
>
(
index_vec
,
ctx
,
&
index
);
auto
output_dim
=
phi
::
vectorize
(
x
.
dims
());
auto
output_dim
=
phi
::
vectorize
(
x
.
dims
());
output_dim
[
dim
]
=
index_size
;
output_dim
[
dim
]
=
index_size
;
...
@@ -85,7 +85,7 @@ void RepeatInterleaveKernel(const Context& ctx,
...
@@ -85,7 +85,7 @@ void RepeatInterleaveKernel(const Context& ctx,
}
else
{
}
else
{
auto
stride_dim
=
phi
::
stride
(
input_dim
);
auto
stride_dim
=
phi
::
stride
(
input_dim
);
int64_t
stride
=
stride_dim
[
dim
];
int64_t
stride
=
stride_dim
[
dim
];
p
addle
::
framework
::
TensorFromVector
<
int
>
(
index_vec
,
ctx
,
&
index
);
p
hi
::
TensorFromVector
<
int
>
(
index_vec
,
ctx
,
&
index
);
auto
stream
=
ctx
.
stream
();
auto
stream
=
ctx
.
stream
();
auto
output_dim
=
phi
::
vectorize
(
x
.
dims
());
auto
output_dim
=
phi
::
vectorize
(
x
.
dims
());
output_dim
[
dim
]
=
index_size
;
output_dim
[
dim
]
=
index_size
;
...
...
paddle/phi/kernels/impl/set_value_kernel_impl.h
浏览文件 @
094e3b8c
...
@@ -316,7 +316,7 @@ void SetValueKernel(const Context& dev_ctx,
...
@@ -316,7 +316,7 @@ void SetValueKernel(const Context& dev_ctx,
assgin_values
.
push_back
(
val
.
to
<
T
>
());
assgin_values
.
push_back
(
val
.
to
<
T
>
());
}
}
DenseTensor
value_tensor
=
Empty
<
T
>
(
dev_ctx
,
shape
);
DenseTensor
value_tensor
=
Empty
<
T
>
(
dev_ctx
,
shape
);
p
addle
::
framework
::
TensorFromVector
(
assgin_values
,
dev_ctx
,
&
value_tensor
);
p
hi
::
TensorFromVector
(
assgin_values
,
dev_ctx
,
&
value_tensor
);
value_tensor
.
Resize
(
phi
::
make_ddim
(
shape
));
value_tensor
.
Resize
(
phi
::
make_ddim
(
shape
));
SetTensorValueKernel
<
T
,
Context
>
(
dev_ctx
,
SetTensorValueKernel
<
T
,
Context
>
(
dev_ctx
,
...
...
paddle/phi/kernels/impl/slogdeterminant_kernel_impl.h
浏览文件 @
094e3b8c
...
@@ -18,8 +18,8 @@
...
@@ -18,8 +18,8 @@
#include <cmath>
#include <cmath>
#include <vector>
#include <vector>
#include "paddle/fluid/framework/tensor_util.h"
#include "paddle/phi/core/enforce.h"
#include "paddle/phi/core/enforce.h"
#include "paddle/phi/core/tensor_utils.h"
#include "paddle/phi/kernels/impl/determinant_kernel_impl.h"
#include "paddle/phi/kernels/impl/determinant_kernel_impl.h"
#include "paddle/phi/kernels/slogdeterminant_kernel.h"
#include "paddle/phi/kernels/slogdeterminant_kernel.h"
...
@@ -41,7 +41,7 @@ struct SlogDeterminantFunctor {
...
@@ -41,7 +41,7 @@ struct SlogDeterminantFunctor {
std
::
vector
<
T
>
sign_vec
;
std
::
vector
<
T
>
sign_vec
;
std
::
vector
<
T
>
log_vec
;
std
::
vector
<
T
>
log_vec
;
std
::
vector
<
T
>
output_vec
;
std
::
vector
<
T
>
output_vec
;
p
addle
::
framework
::
TensorToVector
(
input
,
dev_ctx
,
&
input_vec
);
p
hi
::
TensorToVector
(
input
,
dev_ctx
,
&
input_vec
);
for
(
int64_t
i
=
0
;
i
<
batch_count
;
++
i
)
{
// maybe can be parallel
for
(
int64_t
i
=
0
;
i
<
batch_count
;
++
i
)
{
// maybe can be parallel
auto
begin_iter
=
input_vec
.
begin
()
+
i
*
rank
*
rank
;
auto
begin_iter
=
input_vec
.
begin
()
+
i
*
rank
*
rank
;
auto
end_iter
=
input_vec
.
begin
()
+
(
i
+
1
)
*
rank
*
rank
;
auto
end_iter
=
input_vec
.
begin
()
+
(
i
+
1
)
*
rank
*
rank
;
...
@@ -65,7 +65,7 @@ struct SlogDeterminantFunctor {
...
@@ -65,7 +65,7 @@ struct SlogDeterminantFunctor {
// merge sign_vec and log_vec as final output_vec
// merge sign_vec and log_vec as final output_vec
output_vec
.
insert
(
output_vec
.
end
(),
sign_vec
.
begin
(),
sign_vec
.
end
());
output_vec
.
insert
(
output_vec
.
end
(),
sign_vec
.
begin
(),
sign_vec
.
end
());
output_vec
.
insert
(
output_vec
.
end
(),
log_vec
.
begin
(),
log_vec
.
end
());
output_vec
.
insert
(
output_vec
.
end
(),
log_vec
.
begin
(),
log_vec
.
end
());
p
addle
::
framework
::
TensorFromVector
(
output_vec
,
output
);
p
hi
::
TensorFromVector
(
output_vec
,
dev_ctx
,
output
);
}
}
};
};
...
...
paddle/phi/kernels/selected_rows/cpu/adam_kernel.cc
浏览文件 @
094e3b8c
...
@@ -14,7 +14,6 @@
...
@@ -14,7 +14,6 @@
#include "paddle/phi/kernels/selected_rows/adam_kernel.h"
#include "paddle/phi/kernels/selected_rows/adam_kernel.h"
#include "paddle/fluid/framework/tensor_util.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/tensor_utils.h"
#include "paddle/phi/core/tensor_utils.h"
...
@@ -60,7 +59,7 @@ void AdamDenseParamSparseGradKernel(
...
@@ -60,7 +59,7 @@ void AdamDenseParamSparseGradKernel(
errors
::
InvalidArgument
(
"Input(SkipUpdate) size must be 1, but get %d"
,
errors
::
InvalidArgument
(
"Input(SkipUpdate) size must be 1, but get %d"
,
skip_update
->
numel
()));
skip_update
->
numel
()));
std
::
vector
<
bool
>
skip_update_vec
;
std
::
vector
<
bool
>
skip_update_vec
;
p
addle
::
framework
::
TensorToVector
(
*
skip_update
,
dev_ctx
,
&
skip_update_vec
);
p
hi
::
TensorToVector
(
*
skip_update
,
dev_ctx
,
&
skip_update_vec
);
skip_update_
=
skip_update_vec
[
0
];
skip_update_
=
skip_update_vec
[
0
];
}
}
// skip_update=true, just copy input to output, and TensorCopy will call
// skip_update=true, just copy input to output, and TensorCopy will call
...
...
paddle/phi/kernels/selected_rows/cpu/adamw_kernel.cc
浏览文件 @
094e3b8c
...
@@ -14,10 +14,10 @@
...
@@ -14,10 +14,10 @@
#include "paddle/phi/kernels/selected_rows/adamw_kernel.h"
#include "paddle/phi/kernels/selected_rows/adamw_kernel.h"
#include "paddle/fluid/framework/tensor_util.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/common/float16.h"
#include "paddle/phi/common/float16.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/tensor_utils.h"
#include "paddle/phi/kernels/adam_kernel.h"
#include "paddle/phi/kernels/adam_kernel.h"
#include "paddle/phi/kernels/funcs/adam_functors.h"
#include "paddle/phi/kernels/funcs/adam_functors.h"
#include "paddle/phi/kernels/selected_rows/adam_kernel.h"
#include "paddle/phi/kernels/selected_rows/adam_kernel.h"
...
@@ -61,7 +61,7 @@ void AdamwDenseParamSparseGradKernel(
...
@@ -61,7 +61,7 @@ void AdamwDenseParamSparseGradKernel(
errors
::
InvalidArgument
(
"Input(SkipUpdate) size must be 1, but get %d"
,
errors
::
InvalidArgument
(
"Input(SkipUpdate) size must be 1, but get %d"
,
skip_update
->
numel
()));
skip_update
->
numel
()));
std
::
vector
<
bool
>
skip_update_vec
;
std
::
vector
<
bool
>
skip_update_vec
;
p
addle
::
framework
::
TensorToVector
(
*
skip_update
,
dev_ctx
,
&
skip_update_vec
);
p
hi
::
TensorToVector
(
*
skip_update
,
dev_ctx
,
&
skip_update_vec
);
skip_update_
=
skip_update_vec
[
0
];
skip_update_
=
skip_update_vec
[
0
];
}
}
VLOG
(
3
)
<<
"Skip update"
<<
skip_update_
;
VLOG
(
3
)
<<
"Skip update"
<<
skip_update_
;
...
...
paddle/phi/kernels/selected_rows/gpu/adam_kernel.cu
浏览文件 @
094e3b8c
...
@@ -14,7 +14,6 @@
...
@@ -14,7 +14,6 @@
#include "paddle/phi/kernels/selected_rows/adam_kernel.h"
#include "paddle/phi/kernels/selected_rows/adam_kernel.h"
#include "paddle/fluid/framework/tensor_util.h"
#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/common/amp_type_traits.h"
#include "paddle/phi/common/amp_type_traits.h"
#include "paddle/phi/common/float16.h"
#include "paddle/phi/common/float16.h"
...
@@ -129,7 +128,7 @@ void AdamDenseParamSparseGradKernel(
...
@@ -129,7 +128,7 @@ void AdamDenseParamSparseGradKernel(
errors
::
InvalidArgument
(
"Input(SkipUpdate) size must be 1, but get %d"
,
errors
::
InvalidArgument
(
"Input(SkipUpdate) size must be 1, but get %d"
,
skip_update
->
numel
()));
skip_update
->
numel
()));
std
::
vector
<
bool
>
skip_update_vec
;
std
::
vector
<
bool
>
skip_update_vec
;
p
addle
::
framework
::
TensorToVector
(
*
skip_update
,
dev_ctx
,
&
skip_update_vec
);
p
hi
::
TensorToVector
(
*
skip_update
,
dev_ctx
,
&
skip_update_vec
);
skip_update_
=
skip_update_vec
[
0
];
skip_update_
=
skip_update_vec
[
0
];
}
}
// skip_update=true, just copy input to output, and TensorCopy will call
// skip_update=true, just copy input to output, and TensorCopy will call
...
...
paddle/phi/kernels/selected_rows/gpu/adamw_kernel.cu
浏览文件 @
094e3b8c
...
@@ -146,7 +146,7 @@ void AdamwDenseParamSparseGradKernel(
...
@@ -146,7 +146,7 @@ void AdamwDenseParamSparseGradKernel(
errors
::
InvalidArgument
(
"Input(SkipUpdate) size must be 1, but get %d"
,
errors
::
InvalidArgument
(
"Input(SkipUpdate) size must be 1, but get %d"
,
skip_update
->
numel
()));
skip_update
->
numel
()));
std
::
vector
<
bool
>
skip_update_vec
;
std
::
vector
<
bool
>
skip_update_vec
;
p
addle
::
framework
::
TensorToVector
(
*
skip_update
,
dev_ctx
,
&
skip_update_vec
);
p
hi
::
TensorToVector
(
*
skip_update
,
dev_ctx
,
&
skip_update_vec
);
skip_update_
=
skip_update_vec
[
0
];
skip_update_
=
skip_update_vec
[
0
];
}
}
...
...
paddle/phi/kernels/selected_rows/xpu/adam_kernel.cc
浏览文件 @
094e3b8c
...
@@ -156,7 +156,7 @@ void AdamDenseParamSparseGradKernel(
...
@@ -156,7 +156,7 @@ void AdamDenseParamSparseGradKernel(
errors
::
InvalidArgument
(
"Input(SkipUpdate) size must be 1, but get %d"
,
errors
::
InvalidArgument
(
"Input(SkipUpdate) size must be 1, but get %d"
,
skip_update
->
numel
()));
skip_update
->
numel
()));
std
::
vector
<
bool
>
skip_update_vec
;
std
::
vector
<
bool
>
skip_update_vec
;
p
addle
::
framework
::
TensorToVector
(
*
skip_update
,
dev_ctx
,
&
skip_update_vec
);
p
hi
::
TensorToVector
(
*
skip_update
,
dev_ctx
,
&
skip_update_vec
);
skip_update_
=
skip_update_vec
[
0
];
skip_update_
=
skip_update_vec
[
0
];
}
}
...
...
paddle/phi/kernels/xpu/adam_kernel.cc
浏览文件 @
094e3b8c
...
@@ -124,7 +124,7 @@ void AdamDenseKernel(const Context& dev_ctx,
...
@@ -124,7 +124,7 @@ void AdamDenseKernel(const Context& dev_ctx,
errors
::
InvalidArgument
(
"Input(SkipUpdate) size must be 1, but get %d"
,
errors
::
InvalidArgument
(
"Input(SkipUpdate) size must be 1, but get %d"
,
skip_update
->
numel
()));
skip_update
->
numel
()));
std
::
vector
<
bool
>
skip_update_vec
;
std
::
vector
<
bool
>
skip_update_vec
;
p
addle
::
framework
::
TensorToVector
(
*
skip_update
,
dev_ctx
,
&
skip_update_vec
);
p
hi
::
TensorToVector
(
*
skip_update
,
dev_ctx
,
&
skip_update_vec
);
skip_update_
=
skip_update_vec
[
0
];
skip_update_
=
skip_update_vec
[
0
];
}
}
...
...
paddle/phi/kernels/xpu/adamw_kernel.cc
浏览文件 @
094e3b8c
...
@@ -20,8 +20,6 @@
...
@@ -20,8 +20,6 @@
#include "paddle/phi/backends/xpu/xpu_context.h"
#include "paddle/phi/backends/xpu/xpu_context.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/tensor_utils.h"
#include "paddle/phi/core/tensor_utils.h"
// for TensorToVector
#include "paddle/fluid/framework/tensor_util.h"
namespace
phi
{
namespace
phi
{
...
@@ -61,7 +59,7 @@ void AdamwDenseKernel(const Context& dev_ctx,
...
@@ -61,7 +59,7 @@ void AdamwDenseKernel(const Context& dev_ctx,
errors
::
InvalidArgument
(
"Input(SkipUpdate) size must be 1, but get %d"
,
errors
::
InvalidArgument
(
"Input(SkipUpdate) size must be 1, but get %d"
,
skip_update
->
numel
()));
skip_update
->
numel
()));
std
::
vector
<
bool
>
skip_update_vec
;
std
::
vector
<
bool
>
skip_update_vec
;
p
addle
::
framework
::
TensorToVector
(
*
skip_update
,
dev_ctx
,
&
skip_update_vec
);
p
hi
::
TensorToVector
(
*
skip_update
,
dev_ctx
,
&
skip_update_vec
);
skip_update_
=
skip_update_vec
[
0
];
skip_update_
=
skip_update_vec
[
0
];
}
}
if
(
skip_update_
)
{
if
(
skip_update_
)
{
...
...
paddle/phi/kernels/xpu/set_value_kernel.cc
浏览文件 @
094e3b8c
...
@@ -365,7 +365,7 @@ void SetValueKernel(const Context& dev_ctx,
...
@@ -365,7 +365,7 @@ void SetValueKernel(const Context& dev_ctx,
assgin_values
.
push_back
(
val
.
to
<
T
>
());
assgin_values
.
push_back
(
val
.
to
<
T
>
());
}
}
DenseTensor
value_tensor
=
Empty
<
T
>
(
dev_ctx
,
shape
);
DenseTensor
value_tensor
=
Empty
<
T
>
(
dev_ctx
,
shape
);
p
addle
::
framework
::
TensorFromVector
(
assgin_values
,
dev_ctx
,
&
value_tensor
);
p
hi
::
TensorFromVector
(
assgin_values
,
dev_ctx
,
&
value_tensor
);
value_tensor
.
Resize
(
phi
::
make_ddim
(
shape
));
value_tensor
.
Resize
(
phi
::
make_ddim
(
shape
));
SetTensorValueKernel
<
T
,
Context
>
(
dev_ctx
,
SetTensorValueKernel
<
T
,
Context
>
(
dev_ctx
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录