Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
ee9ea48d
P
Paddle
项目概览
PaddlePaddle
/
Paddle
11 个月 前同步成功
通知
2292
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
ee9ea48d
编写于
8月 08, 2022
作者:
L
Leo Chen
提交者:
GitHub
8月 08, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
clean includes of tensor.h (#44928)
* clean tensor.h * fix gather_nd
上级
3f234db0
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
77 addition
and
138 deletion
+77
-138
paddle/fluid/eager/nan_inf_utils.cc
paddle/fluid/eager/nan_inf_utils.cc
+2
-0
paddle/fluid/framework/CMakeLists.txt
paddle/fluid/framework/CMakeLists.txt
+8
-10
paddle/fluid/framework/details/nan_inf_utils_detail.h
paddle/fluid/framework/details/nan_inf_utils_detail.h
+1
-4
paddle/fluid/framework/dlpack_tensor_test.cc
paddle/fluid/framework/dlpack_tensor_test.cc
+2
-0
paddle/fluid/framework/tensor.cc
paddle/fluid/framework/tensor.cc
+0
-29
paddle/fluid/framework/tensor.h
paddle/fluid/framework/tensor.h
+1
-49
paddle/fluid/framework/tensor_impl.h
paddle/fluid/framework/tensor_impl.h
+0
-45
paddle/fluid/framework/tensor_test.cc
paddle/fluid/framework/tensor_test.cc
+1
-0
paddle/fluid/framework/tensor_util.h
paddle/fluid/framework/tensor_util.h
+21
-0
paddle/fluid/inference/tensorrt/plugin/gather_nd_op_plugin.cu
...le/fluid/inference/tensorrt/plugin/gather_nd_op_plugin.cu
+1
-0
paddle/fluid/operators/gather_scatter_kernel.h
paddle/fluid/operators/gather_scatter_kernel.h
+2
-0
paddle/fluid/operators/math/cross_entropy.h
paddle/fluid/operators/math/cross_entropy.h
+1
-0
paddle/fluid/operators/math/sample_prob.h
paddle/fluid/operators/math/sample_prob.h
+1
-0
paddle/fluid/operators/math/softmax_impl.h
paddle/fluid/operators/math/softmax_impl.h
+4
-0
paddle/fluid/operators/math/unpooling.h
paddle/fluid/operators/math/unpooling.h
+1
-0
paddle/phi/core/dense_tensor.h
paddle/phi/core/dense_tensor.h
+31
-1
未找到文件。
paddle/fluid/eager/nan_inf_utils.cc
浏览文件 @
ee9ea48d
...
...
@@ -15,6 +15,8 @@
#include "paddle/fluid/eager/nan_inf_utils.h"
#include "paddle/fluid/framework/details/nan_inf_utils_detail.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/core/selected_rows.h"
...
...
paddle/fluid/framework/CMakeLists.txt
浏览文件 @
ee9ea48d
...
...
@@ -83,26 +83,27 @@ if(WITH_GPU)
windows_symbolic
(
tensor_util SRCS tensor_util.cu
)
nv_library
(
tensor
SRCS
tensor.cc
.tensor_util.cu
SRCS .tensor_util.cu
DEPS place memory data_type device_context dense_tensor
)
add_dependencies
(
tensor tensor_util
)
else
()
nv_library
(
tensor
SRCS tensor
.cc tensor
_util.cu
DEPS place memory data_type device_context
profiler
dense_tensor
)
SRCS tensor_util.cu
DEPS place memory data_type device_context dense_tensor
)
endif
()
elseif
(
WITH_ROCM
)
hip_library
(
tensor
SRCS tensor
.cc tensor
_util.cu
DEPS place memory data_type device_context
profiler
dense_tensor
)
SRCS tensor_util.cu
DEPS place memory data_type device_context dense_tensor
)
else
()
cc_library
(
tensor
SRCS tensor
.cc tensor
_util.cc
DEPS place memory data_type device_context
profiler
dense_tensor
)
SRCS tensor_util.cc
DEPS place memory data_type device_context dense_tensor
)
endif
()
# target_link(tensor profiler)
cc_test
(
tensor_test
...
...
@@ -1167,9 +1168,6 @@ cc_library(
op_meta_info
phi_api
)
#cc_binary(test_executor SRCS test_executor.cc DEPS executor op_registry ${GLOB_OP_LIB} ${GLOB_OPERATOR_DEPS} )
#cc_binary(new_executor SRCS new_exec_test.cc DEPS operator op_registry executor ${GLOB_OP_LIB} ${GLOB_OPERATOR_DEPS} profiler)
set
(
FLUID_FRAMEWORK_MODULES
proto_desc
memory
...
...
paddle/fluid/framework/details/nan_inf_utils_detail.h
浏览文件 @
ee9ea48d
...
...
@@ -17,12 +17,9 @@
#include <string>
#include "paddle/fluid/framework/tensor.h"
#include "paddle/fluid/platform/complex.h"
#include "paddle/fluid/platform/place.h"
namespace
phi
{
class
DenseTensor
;
}
// namespace phi
namespace
paddle
{
namespace
framework
{
namespace
details
{
...
...
paddle/fluid/framework/dlpack_tensor_test.cc
浏览文件 @
ee9ea48d
...
...
@@ -17,6 +17,8 @@
#include <glog/logging.h>
#include <gtest/gtest.h>
#include "paddle/fluid/platform/device/gpu/gpu_info.h"
namespace
paddle
{
namespace
framework
{
...
...
paddle/fluid/framework/tensor.cc
已删除
100644 → 0
浏览文件 @
3f234db0
/* 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/framework/tensor.h"
DECLARE_bool
(
use_stream_safe_cuda_allocator
);
namespace
paddle
{
namespace
memory
{
namespace
allocation
{
class
Allocation
;
}
// namespace allocation
}
// namespace memory
}
// namespace paddle
namespace
paddle
{
namespace
framework
{}
// namespace framework
}
// namespace paddle
paddle/fluid/framework/tensor.h
浏览文件 @
ee9ea48d
...
...
@@ -14,63 +14,15 @@ limitations under the License. */
#pragma once
#include <cstdint>
#include <cstring>
#include <memory>
#include <typeindex>
#include <utility>
#include <vector>
#include "paddle/fluid/framework/data_layout.h"
#include "paddle/fluid/framework/framework.pb.h"
#include "paddle/fluid/framework/data_type.h"
#include "paddle/fluid/framework/mixed_vector.h"
#include "paddle/fluid/memory/memory.h"
#include "paddle/fluid/platform/device_context.h"
#include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/platform/place.h"
#include "paddle/phi/core/ddim.h"
#include "paddle/phi/core/dense_tensor.h"
namespace
paddle
{
namespace
framework
{
using
LoD
=
std
::
vector
<
paddle
::
framework
::
Vector
<
size_t
>>
;
/*
NOTE(liym27): [ What is TensorInplaceVersion used for? ]
TensorInplaceVersion is a version counter and every Tensor has a version
counter. It's used to check whether an inplace operation will result in an
incorrect gradient calculation. Version is incremented when the data of the
Variable is modified in place.
- Question: In what scenarios will version counters be shared?
- Answer: When two Variables/VarBases share the same C++ Tensor(its Allocation
may change), both of them share the same version counter. For examples:
1. `z = paddle.assign(input=x, output=y)`, `z` shares the same version counter
of `y` because z and y is the same VarBase;
2. `y = x.detach()`, `y` shares the same version counter of `x`.
- Question: In what scenarios will version counters NOT be shared?
- Answer: Replacing a `Variable`'s data by calling `Tensor::ShareDataWith(...)`
or `Tensor::ShareBufferWith(...)`. Because they share the same Allocation but
not framework::Tensor.
- Question: Why put the inplace_version_counter_ in framework::Tensor instead
of Allocation or Variable?
- Answer:
1. Tensor can call ResetHolder() to reset the corresponding Allocation so that
the inplace_version_counter_ changes if it's in Allocation, which will lead to
confusing information about inplace version.
2. If inplace_version_counter_ is in Variable, different VariableWrappers
should be able to share the same Variable. However, a VariableWrapper hold a
Variable object but not a pointer.
*/
using
Tensor
=
phi
::
DenseTensor
;
}
// namespace framework
}
// namespace paddle
#include "paddle/fluid/framework/tensor_impl.h"
paddle/fluid/framework/tensor_impl.h
已删除
100644 → 0
浏览文件 @
3f234db0
/* 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. */
#pragma once
#include "paddle/fluid/framework/data_type.h"
#include "paddle/fluid/memory/memcpy.h"
#include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/platform/float16.h"
namespace
paddle
{
namespace
framework
{
inline
Tensor
ReshapeToMatrix
(
const
Tensor
&
src
,
int
num_col_dims
)
{
int
rank
=
src
.
dims
().
size
();
PADDLE_ENFORCE_GE
(
rank
,
2
,
platform
::
errors
::
InvalidArgument
(
"'ReshapeToMatrix()' is only used for flatten high rank "
"tensors to matrixs. The dimensions of Tensor must be "
"greater or equal than 2. "
"But received dimensions of Tensor is %d"
,
rank
));
if
(
rank
==
2
)
{
return
src
;
}
Tensor
res
;
res
.
ShareDataWith
(
src
);
res
.
Resize
(
phi
::
flatten_to_2d
(
src
.
dims
(),
num_col_dims
));
return
res
;
}
}
// namespace framework
}
// namespace paddle
paddle/fluid/framework/tensor_test.cc
浏览文件 @
ee9ea48d
...
...
@@ -13,6 +13,7 @@
// limitations under the License.
#include "paddle/fluid/framework/tensor.h"
#include "paddle/fluid/framework/tensor_util.h"
#include <gtest/gtest.h>
...
...
paddle/fluid/framework/tensor_util.h
浏览文件 @
ee9ea48d
...
...
@@ -34,6 +34,7 @@ limitations under the License. */
#include "paddle/fluid/platform/device/mlu/device_context.h"
#endif
#include "paddle/fluid/memory/memory.h"
#include "paddle/phi/core/dense_tensor.h"
namespace
paddle
{
...
...
@@ -580,6 +581,26 @@ inline void TensorToVector(const Tensor& src, std::vector<bool>* dst) {
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
LoD
&
lod
);
inline
Tensor
ReshapeToMatrix
(
const
Tensor
&
src
,
int
num_col_dims
)
{
int
rank
=
src
.
dims
().
size
();
PADDLE_ENFORCE_GE
(
rank
,
2
,
platform
::
errors
::
InvalidArgument
(
"'ReshapeToMatrix()' is only used for flatten high rank "
"tensors to matrixs. The dimensions of Tensor must be "
"greater or equal than 2. "
"But received dimensions of Tensor is %d"
,
rank
));
if
(
rank
==
2
)
{
return
src
;
}
Tensor
res
;
res
.
ShareDataWith
(
src
);
res
.
Resize
(
phi
::
flatten_to_2d
(
src
.
dims
(),
num_col_dims
));
return
res
;
}
}
// namespace framework
}
// namespace paddle
...
...
paddle/fluid/inference/tensorrt/plugin/gather_nd_op_plugin.cu
浏览文件 @
ee9ea48d
...
...
@@ -23,6 +23,7 @@
#include "NvInferRuntimeCommon.h"
#include "paddle/fluid/inference/tensorrt/plugin/gather_nd_op_plugin.h"
#include "paddle/fluid/platform/place.h"
#include "paddle/phi/backends/gpu/gpu_helper.h"
namespace
paddle
{
namespace
inference
{
...
...
paddle/fluid/operators/gather_scatter_kernel.h
浏览文件 @
ee9ea48d
...
...
@@ -13,6 +13,8 @@ See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/fluid/framework/tensor.h"
#include "paddle/fluid/platform/device_context.h"
#include "paddle/fluid/platform/float16.h"
#pragma once
...
...
paddle/fluid/operators/math/cross_entropy.h
浏览文件 @
ee9ea48d
...
...
@@ -17,6 +17,7 @@ limitations under the License. */
#include "paddle/fluid/framework/eigen.h"
#include "paddle/fluid/framework/tensor.h"
#include "paddle/fluid/platform/float16.h"
#include "paddle/phi/core/hostdevice.h"
namespace
paddle
{
...
...
paddle/fluid/operators/math/sample_prob.h
浏览文件 @
ee9ea48d
...
...
@@ -20,6 +20,7 @@ limitations under the License. */
#include "paddle/fluid/framework/eigen.h"
#include "paddle/fluid/framework/tensor.h"
#include "paddle/fluid/operators/math/sampler.h"
#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/core/ddim.h"
namespace
paddle
{
...
...
paddle/fluid/operators/math/softmax_impl.h
浏览文件 @
ee9ea48d
...
...
@@ -19,7 +19,11 @@ limitations under the License. */
#include "paddle/fluid/framework/tensor.h"
#include "paddle/fluid/operators/jit/kernels.h"
#include "paddle/fluid/operators/math/cpu_vec.h"
#include "paddle/fluid/platform/bfloat16.h"
#include "paddle/fluid/platform/cpu_info.h"
#include "paddle/fluid/platform/float16.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/backends/gpu/gpu_context.h"
namespace
paddle
{
namespace
operators
{
...
...
paddle/fluid/operators/math/unpooling.h
浏览文件 @
ee9ea48d
...
...
@@ -14,6 +14,7 @@ limitations under the License. */
#pragma once
#include "paddle/fluid/framework/tensor.h"
#include "paddle/fluid/platform/device_context.h"
namespace
paddle
{
namespace
operators
{
...
...
paddle/phi/core/dense_tensor.h
浏览文件 @
ee9ea48d
...
...
@@ -22,7 +22,7 @@ limitations under the License. */
/* @jim19930609: Move to MKLDNN_Tensor in the future
*/
#ifdef PADDLE_WITH_MKLDNN
#include "dnnl.hpp"
#include "dnnl.hpp"
// NOLINT
#endif
namespace
phi
{
...
...
@@ -174,6 +174,36 @@ class DenseTensor : public TensorBase,
/* Temporarily put InplaceVersion inside DenseTensor.
Will move to AutogradMeta as soon as we switch to Eager Dygraph.
*/
/*
NOTE(liym27): [ What is TensorInplaceVersion used for? ]
TensorInplaceVersion is a version counter and every Tensor has a version
counter. It's used to check whether an inplace operation will result in an
incorrect gradient calculation. Version is incremented when the data of the
Variable is modified in place.
- Question: In what scenarios will version counters be shared?
- Answer: When two Variables/VarBases share the same C++ Tensor(its Allocation
may change), both of them share the same version counter. For examples:
1. `z = paddle.assign(input=x, output=y)`, `z` shares the same version
counter of `y` because z and y is the same VarBase;
2. `y = x.detach()`, `y` shares the same version counter of `x`.
- Question: In what scenarios will version counters NOT be shared?
- Answer: Replacing a `Variable`'s data by calling
`Tensor::ShareDataWith(...)` or `Tensor::ShareBufferWith(...)`. Because they
share the same Allocation but not framework::Tensor.
- Question: Why put the inplace_version_counter_ in framework::Tensor instead
of Allocation or Variable?
- Answer:
1. Tensor can call ResetHolder() to reset the corresponding Allocation so
that the inplace_version_counter_ changes if it's in Allocation, which will
lead to confusing information about inplace version.
2. If inplace_version_counter_ is in Variable, different VariableWrappers
should be able to share the same Variable. However, a VariableWrapper hold a
Variable object but not a pointer.
*/
class
InplaceVersion
{
public:
bool
IsUnique
()
const
{
return
inplace_version_
==
0
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录