Skip to content

Commit

Permalink
[Unify Tensors PR #8] Merged Tensor into DenseTensor, test=allcases (P…
Browse files Browse the repository at this point in the history
…addlePaddle#38914)

* Merged LoDTensor with Tensor,test=allcases

* Patched python level LoDTensor

* Patched python level LoDTensor

* Merge Tensor into DenseTensor

* Fixed namespace issues,test=allcases

* Fixed merge issues

* Fixed inference issues

* Fixed NPU test issues

* Fixed merge issues
  • Loading branch information
jim19930609 authored Jan 18, 2022
1 parent bfacd70 commit 2052f1e
Show file tree
Hide file tree
Showing 270 changed files with 1,212 additions and 982 deletions.
1 change: 0 additions & 1 deletion paddle/fluid/distributed/fleet.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ limitations under the License. */

namespace paddle {
namespace framework {
class Tensor;
class Scope;
class SelectedRows;
class Variable;
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/distributed/fleet_executor/dist_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ bool DistModel::LoadParameters() {
return true;
}

void DistModel::Run(const std::vector<framework::Tensor> &input_data,
std::vector<framework::Tensor> *output_data) {
void DistModel::Run(const std::vector<paddle::framework::Tensor> &input_data,
std::vector<paddle::framework::Tensor> *output_data) {
/* TODO(fleet exe dev): implement this funct */
}

Expand Down
6 changes: 3 additions & 3 deletions paddle/fluid/distributed/fleet_executor/dist_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
#include <vector>

#include "paddle/fluid/distributed/fleet_executor/fleet_executor_desc.pb.h"
#include "paddle/fluid/framework/tensor.h"
#include "paddle/fluid/platform/macros.h"
#include "paddle/fluid/platform/place.h"

namespace paddle {
namespace framework {
class ProgramDesc;
class Scope;
class Tensor;
}

namespace distributed {
Expand All @@ -45,8 +45,8 @@ class DistModel {
public:
explicit DistModel(const DistModelConfig& config) : config_(config) {}
bool Init();
void Run(const std::vector<framework::Tensor>& input_data,
std::vector<framework::Tensor>* output_data);
void Run(const std::vector<paddle::framework::Tensor>& input_data,
std::vector<paddle::framework::Tensor>* output_data);
~DistModel() = default;

private:
Expand Down
5 changes: 4 additions & 1 deletion paddle/fluid/distributed/service/brpc_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ limitations under the License. */
namespace paddle {
namespace framework {
class Variable;
class Tensor;
} // namespace framework
} // namespace paddle

namespace pten {
class DenseTensor;
} // namespace pten

namespace paddle {
namespace distributed {

Expand Down
5 changes: 4 additions & 1 deletion paddle/fluid/distributed/test/brpc_service_dense_sgd_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ class PSClient;
class PSServer;
} // namespace distributed
namespace framework {
class Tensor;
class Variable;
} // namespace framework
} // namespace paddle

namespace pten {
class DenseTensor;
} // namespace pten

namespace framework = paddle::framework;
namespace platform = paddle::platform;
namespace operators = paddle::operators;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ class PSClient;
class PSServer;
} // namespace distributed
namespace framework {
class Tensor;
class Variable;
} // namespace framework
} // namespace paddle

namespace pten {
class DenseTensor;
} // namespace pten

namespace framework = paddle::framework;
namespace platform = paddle::platform;
namespace operators = paddle::operators;
Expand Down
5 changes: 4 additions & 1 deletion paddle/fluid/eager/legacy/prepared_operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ DECLARE_bool(use_mkldnn);

namespace paddle {
namespace framework {
class Tensor;
class Variable;
} // namespace framework
namespace platform {
class DeviceContext;
} // namespace platform
} // namespace paddle

namespace pten {
class DenseTensor;
} // namespace pten

namespace egr {
namespace legacy {

Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/framework/copy_same_tensor_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static bool CopySameTensorTestMain(const DDim &dims,
if (sync_copy) {
TensorCopySync(src_tensor, dst_place, &src_tensor);
} else {
TensorCopy(src_tensor, dst_place, &src_tensor);
paddle::framework::TensorCopy(src_tensor, dst_place, &src_tensor);
platform::DeviceContextPool::Instance().Get(src_place)->Wait();
platform::DeviceContextPool::Instance().Get(dst_place)->Wait();
}
Expand Down
5 changes: 3 additions & 2 deletions paddle/fluid/framework/data_device_transform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ void TransDataDevice(const Tensor &in, const platform::Place &dst_place,

// NOTE(zhiqiu): Special case for CPU->NPU, avoid stream sync.
if (platform::is_cpu_place(in.place()) && platform::is_npu_place(dst_place)) {
TensorCopy(in, dst_place,
*platform::DeviceContextPool::Instance().Get(dst_place), out);
paddle::framework::TensorCopy(
in, dst_place, *platform::DeviceContextPool::Instance().Get(dst_place),
out);
return;
}

Expand Down
2 changes: 0 additions & 2 deletions paddle/fluid/framework/data_device_transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ limitations under the License. */
namespace paddle {
namespace framework {

class Tensor;

void TransDataDevice(const Tensor& in, const platform::Place& dst_place,
Tensor* out);

Expand Down
5 changes: 4 additions & 1 deletion paddle/fluid/framework/data_feed.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,15 @@ DECLARE_bool(enable_slotrecord_reset_shrink);
namespace paddle {
namespace framework {
class DataFeedDesc;
class Tensor;
class Scope;
class Variable;
} // namespace framework
} // namespace paddle

namespace pten {
class DenseTensor;
} // namespace pten

namespace paddle {
namespace framework {

Expand Down
1 change: 0 additions & 1 deletion paddle/fluid/framework/data_layout_transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
namespace paddle {
namespace framework {
class OpKernelType;
class Tensor;
} // namespace framework
} // namespace paddle

Expand Down
1 change: 0 additions & 1 deletion paddle/fluid/framework/data_transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace paddle {
namespace framework {

class OpKernelType;
class Tensor;
class Variable;

void TransformData(const OpKernelType &expected_kernel_type,
Expand Down
1 change: 0 additions & 1 deletion paddle/fluid/framework/data_type_transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace paddle {
namespace framework {

class OpKernelType;
class Tensor;

using KernelTypePair = std::pair<OpKernelType, OpKernelType>;

Expand Down
5 changes: 3 additions & 2 deletions paddle/fluid/framework/details/async_ssa_graph_executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ FetchResultType AsyncSSAGraphExecutor::Run(
std::vector<const LoDTensor *> lodtensor_ptrs;
lodtensor_ptrs.push_back(&(BOOST_GET(LoDTensor, val.at(fetch_idx))));
LoDTensor var;
var.MergeLoDTensor(lodtensor_ptrs, platform::CPUPlace());
MergeLoDTensor(&var, lodtensor_ptrs, platform::CPUPlace());
ret.emplace_back(var);
} else {
auto array = BOOST_GET(LoDTensorArray, val.at(fetch_idx));
Expand All @@ -179,7 +179,8 @@ FetchResultType AsyncSSAGraphExecutor::Run(
std::vector<const LoDTensor *> lodtensor_ptrs;
lodtensor_ptrs.push_back(&array[i]);
item_array.emplace_back();
item_array.back().MergeLoDTensor(lodtensor_ptrs, platform::CPUPlace());
MergeLoDTensor(&(item_array.back()), lodtensor_ptrs,
platform::CPUPlace());
}
ret.emplace_back(item_array);
}
Expand Down
6 changes: 5 additions & 1 deletion paddle/fluid/framework/details/fetch_async_op_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@
#include "paddle/fluid/framework/scope.h"
#include "paddle/fluid/platform/device_context.h"

namespace pten {
class DenseTensor;
} // namespace pten

namespace paddle {
namespace framework {
class Tensor;

namespace ir {
class Node;
} // namespace ir
} // namespace framework

namespace platform {
class DeviceContext;
} // namespace platform
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/framework/details/fetch_op_handle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void FetchOpHandle::WaitAndMergeCPUFetchVars() const {
}
auto &val = BOOST_GET(FetchList, *data_);
LoDTensor var;
var.MergeLoDTensor(tensors_ptr, platform::CPUPlace());
MergeLoDTensor(&var, tensors_ptr, platform::CPUPlace());
val.at(offset_) = std::move(var);
} else {
auto &array = BOOST_GET_CONST(LoDTensorArray, tensors_[0]);
Expand All @@ -99,7 +99,7 @@ void FetchOpHandle::WaitAndMergeCPUFetchVars() const {
tensors_ptr.push_back(&element[i]);
}
tmp_array.emplace_back();
tmp_array.back().MergeLoDTensor(tensors_ptr, platform::CPUPlace());
MergeLoDTensor(&(tmp_array.back()), tensors_ptr, platform::CPUPlace());
}
auto &val = BOOST_GET(FetchList, *data_);
val.at(offset_) = std::move(tmp_array);
Expand Down
9 changes: 4 additions & 5 deletions paddle/fluid/framework/details/gather_op_handle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@

#include "paddle/fluid/framework/details/container_cast.h"
#include "paddle/fluid/framework/details/variable_visitor.h"
namespace paddle {
namespace framework {
class Tensor;
} // namespace framework
} // namespace paddle

namespace pten {
class DenseTensor;
} // namespace pten

namespace paddle {
namespace framework {
Expand Down
8 changes: 3 additions & 5 deletions paddle/fluid/framework/details/nan_inf_utils_detail.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
#include "paddle/fluid/framework/scope.h"
#include "paddle/fluid/platform/place.h"

namespace paddle {
namespace framework {
class Tensor;
} // namespace framework
} // namespace paddle
namespace pten {
class DenseTensor;
} // namespace pten

namespace paddle {
namespace framework {
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/framework/details/parallel_ssa_graph_executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ FetchResultType ParallelSSAGraphExecutor::Run(
}
if (lodtensor_ptrs.size() != 0) {
LoDTensor var;
var.MergeLoDTensor(lodtensor_ptrs, platform::CPUPlace());
MergeLoDTensor(&var, lodtensor_ptrs, platform::CPUPlace());
ret.emplace_back(var);
} else {
LoDTensorArray var_array(lodtensorarray_ptrs[0]->size());
Expand All @@ -285,7 +285,7 @@ FetchResultType ParallelSSAGraphExecutor::Run(
for (size_t j = 0; j < lodtensorarray_ptrs.size(); ++j) {
ptrs.push_back(&(lodtensorarray_ptrs[j]->at(i)));
}
var.MergeLoDTensor(ptrs, platform::CPUPlace());
MergeLoDTensor(&var, ptrs, platform::CPUPlace());
var_array[i] = std::move(var);
}
ret.emplace_back(var_array);
Expand Down
8 changes: 3 additions & 5 deletions paddle/fluid/framework/details/scale_loss_grad_op_handle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@

#include "paddle/fluid/platform/profiler.h"

namespace paddle {
namespace framework {
class Tensor;
} // namespace framework
} // namespace paddle
namespace pten {
class DenseTensor;
} // namespace pten

namespace paddle {
namespace framework {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
namespace paddle {
namespace framework {
class Scope;
class Tensor;
class Variable;

namespace ir {
Expand All @@ -31,6 +30,10 @@ class MemOptVarInfo;
} // namespace framework
} // namespace paddle

namespace pten {
class DenseTensor;
} // namespace pten

namespace paddle {
namespace framework {
namespace details {
Expand Down
5 changes: 4 additions & 1 deletion paddle/fluid/framework/details/variable_visitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@

#include "paddle/fluid/framework/selected_rows.h"

namespace pten {
class DenseTensor;
} // namespace pten

namespace paddle {
namespace framework {
class Tensor;
class Variable;
} // namespace framework
} // namespace paddle
Expand Down
1 change: 0 additions & 1 deletion paddle/fluid/framework/details/variable_visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

namespace paddle {
namespace framework {
class Tensor;
class Variable;
} // namespace framework
} // namespace paddle
Expand Down
5 changes: 4 additions & 1 deletion paddle/fluid/framework/device_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ limitations under the License. */

#include "paddle/fluid/framework/device_worker.h"

namespace pten {
class DenseTensor;
} // namespace pten

namespace paddle {
namespace framework {

class Tensor;
class Scope;

void DeviceWorker::SetRootScope(Scope* root_scope) { root_scope_ = root_scope; }
Expand Down
1 change: 0 additions & 1 deletion paddle/fluid/framework/device_worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ limitations under the License. */

namespace paddle {
namespace framework {
class Tensor;
class ProgramDesc;
class Scope;
} // namespace framework
Expand Down
2 changes: 0 additions & 2 deletions paddle/fluid/framework/dlpack_tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
namespace paddle {
namespace framework {

class Tensor;

class DLPackTensor {
public:
using LaneType = decltype(::DLTensor::dtype.lanes); // uint16_t
Expand Down
5 changes: 4 additions & 1 deletion paddle/fluid/framework/downpour_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ limitations under the License. */
#include "paddle/fluid/framework/device_worker.h"
#include "paddle/fluid/platform/cpu_helper.h"

namespace pten {
class DenseTensor;
} // namespace pten

namespace paddle {
namespace framework {
class Tensor;
class Variable;
} // namespace framework
} // namespace paddle
Expand Down
Loading

0 comments on commit 2052f1e

Please sign in to comment.