未验证 提交 1cb12ff5 编写于 作者: C Chen Weihang 提交者: GitHub

Remove the declaration of using LoDTensor in framework/lod_tensor.h (Part2) (#46953)

* remove using lodtensor part2

* resolve code format error

* resolve conflict

* resolve conflict

* replace added frameworrk tensor
上级 6ef5d343
...@@ -153,7 +153,7 @@ TEST(Operator, CPUtoGPU) { ...@@ -153,7 +153,7 @@ TEST(Operator, CPUtoGPU) {
gpu_op->Run(scope, cuda_place); gpu_op->Run(scope, cuda_place);
VLOG(3) << "after gpu_op run"; VLOG(3) << "after gpu_op run";
// auto* output2_ptr = output2->Get<LoDTensor>().data<float>(); // auto* output2_ptr = output2->Get<phi::DenseTensor>().data<float>();
paddle::platform::DeviceContextPool& pool = paddle::platform::DeviceContextPool& pool =
paddle::platform::DeviceContextPool::Instance(); paddle::platform::DeviceContextPool::Instance();
auto dev_ctx = pool.Get(cuda_place); auto dev_ctx = pool.Get(cuda_place);
......
...@@ -188,7 +188,7 @@ void DataFeed::AddFeedVar(Variable* var, const std::string& name) { ...@@ -188,7 +188,7 @@ void DataFeed::AddFeedVar(Variable* var, const std::string& name) {
if (var == nullptr) { if (var == nullptr) {
feed_vec_[i] = nullptr; feed_vec_[i] = nullptr;
} else { } else {
feed_vec_[i] = var->GetMutable<LoDTensor>(); feed_vec_[i] = var->GetMutable<phi::DenseTensor>();
} }
} }
} }
...@@ -257,7 +257,7 @@ void DataFeed::CheckStart() { ...@@ -257,7 +257,7 @@ void DataFeed::CheckStart() {
void DataFeed::AssignFeedVar(const Scope& scope) { void DataFeed::AssignFeedVar(const Scope& scope) {
CheckInit(); CheckInit();
for (size_t i = 0; i < use_slots_.size(); ++i) { for (size_t i = 0; i < use_slots_.size(); ++i) {
feed_vec_[i] = scope.FindVar(use_slots_[i])->GetMutable<LoDTensor>(); feed_vec_[i] = scope.FindVar(use_slots_[i])->GetMutable<phi::DenseTensor>();
} }
} }
...@@ -1889,7 +1889,8 @@ void PaddleBoxDataFeed::AssignFeedVar(const Scope& scope) { ...@@ -1889,7 +1889,8 @@ void PaddleBoxDataFeed::AssignFeedVar(const Scope& scope) {
// set rank offset memory // set rank offset memory
int phase = GetCurrentPhase(); // join: 1, update: 0 int phase = GetCurrentPhase(); // join: 1, update: 0
if (enable_pv_merge_ && phase == 1) { if (enable_pv_merge_ && phase == 1) {
rank_offset_ = scope.FindVar(rank_offset_name_)->GetMutable<LoDTensor>(); rank_offset_ =
scope.FindVar(rank_offset_name_)->GetMutable<phi::DenseTensor>();
} }
} }
...@@ -2478,7 +2479,7 @@ void SlotRecordInMemoryDataFeed::AssignFeedVar(const Scope& scope) { ...@@ -2478,7 +2479,7 @@ void SlotRecordInMemoryDataFeed::AssignFeedVar(const Scope& scope) {
CheckInit(); CheckInit();
for (int i = 0; i < use_slot_size_; ++i) { for (int i = 0; i < use_slot_size_; ++i) {
feed_vec_[i] = feed_vec_[i] =
scope.FindVar(used_slots_info_[i].slot)->GetMutable<LoDTensor>(); scope.FindVar(used_slots_info_[i].slot)->GetMutable<phi::DenseTensor>();
} }
} }
...@@ -2717,8 +2718,8 @@ void SlotRecordInMemoryDataFeed::BuildSlotBatchGPU(const int ins_num) { ...@@ -2717,8 +2718,8 @@ void SlotRecordInMemoryDataFeed::BuildSlotBatchGPU(const int ins_num) {
// alloc gpu memory // alloc gpu memory
pack_->resize_tensor(); pack_->resize_tensor();
LoDTensor& float_tensor = pack_->float_tensor(); phi::DenseTensor& float_tensor = pack_->float_tensor();
LoDTensor& uint64_tensor = pack_->uint64_tensor(); phi::DenseTensor& uint64_tensor = pack_->uint64_tensor();
int64_t float_offset = 0; int64_t float_offset = 0;
int64_t uint64_offset = 0; int64_t uint64_offset = 0;
......
...@@ -219,7 +219,7 @@ int GraphDataGenerator::AcquireInstance(BufState *state) { ...@@ -219,7 +219,7 @@ int GraphDataGenerator::AcquireInstance(BufState *state) {
return 0; return 0;
} }
// TODO opt // TODO(fengdanlei): opt
__global__ void GraphFillFeatureKernel(uint64_t *id_tensor, __global__ void GraphFillFeatureKernel(uint64_t *id_tensor,
int *fill_ins_num, int *fill_ins_num,
uint64_t *walk, uint64_t *walk,
...@@ -319,7 +319,7 @@ __global__ void GraphFillSlotKernel(uint64_t *id_tensor, ...@@ -319,7 +319,7 @@ __global__ void GraphFillSlotKernel(uint64_t *id_tensor,
CUDA_KERNEL_LOOP(idx, len) { CUDA_KERNEL_LOOP(idx, len) {
int slot_idx = idx / total_ins; int slot_idx = idx / total_ins;
int ins_idx = idx % total_ins; int ins_idx = idx % total_ins;
((uint64_t *)(id_tensor[slot_idx]))[ins_idx] = ((uint64_t *)(id_tensor[slot_idx]))[ins_idx] = // NOLINT
feature_buf[ins_idx * slot_num + slot_idx]; feature_buf[ins_idx * slot_num + slot_idx];
} }
} }
...@@ -330,7 +330,7 @@ __global__ void GraphFillSlotLodKernelOpt(uint64_t *id_tensor, ...@@ -330,7 +330,7 @@ __global__ void GraphFillSlotLodKernelOpt(uint64_t *id_tensor,
CUDA_KERNEL_LOOP(idx, len) { CUDA_KERNEL_LOOP(idx, len) {
int slot_idx = idx / total_ins; int slot_idx = idx / total_ins;
int ins_idx = idx % total_ins; int ins_idx = idx % total_ins;
((uint64_t *)(id_tensor[slot_idx]))[ins_idx] = ins_idx; ((uint64_t *)(id_tensor[slot_idx]))[ins_idx] = ins_idx; // NOLINT
} }
} }
...@@ -365,12 +365,12 @@ int GraphDataGenerator::FillInsBuf() { ...@@ -365,12 +365,12 @@ int GraphDataGenerator::FillInsBuf() {
FillFeatureBuf(d_walk_, d_feature_); FillFeatureBuf(d_walk_, d_feature_);
if (debug_mode_) { if (debug_mode_) {
int len = buf_size_ > 5000 ? 5000 : buf_size_; int len = buf_size_ > 5000 ? 5000 : buf_size_;
uint64_t h_walk[len]; uint64_t h_walk[len]; // NOLINT
cudaMemcpy(h_walk, cudaMemcpy(h_walk,
d_walk_->ptr(), d_walk_->ptr(),
len * sizeof(uint64_t), len * sizeof(uint64_t),
cudaMemcpyDeviceToHost); cudaMemcpyDeviceToHost);
uint64_t h_feature[len * slot_num_]; uint64_t h_feature[len * slot_num_]; // NOLINT
cudaMemcpy(h_feature, cudaMemcpy(h_feature,
d_feature_->ptr(), d_feature_->ptr(),
len * slot_num_ * sizeof(uint64_t), len * slot_num_ * sizeof(uint64_t),
...@@ -431,7 +431,7 @@ int GraphDataGenerator::FillInsBuf() { ...@@ -431,7 +431,7 @@ int GraphDataGenerator::FillInsBuf() {
ins_buf_pair_len_ += h_pair_num; ins_buf_pair_len_ += h_pair_num;
if (debug_mode_) { if (debug_mode_) {
uint64_t h_ins_buf[ins_buf_pair_len_ * 2]; uint64_t h_ins_buf[ins_buf_pair_len_ * 2]; // NOLINT
cudaMemcpy(h_ins_buf, cudaMemcpy(h_ins_buf,
ins_buf, ins_buf,
2 * ins_buf_pair_len_ * sizeof(uint64_t), 2 * ins_buf_pair_len_ * sizeof(uint64_t),
...@@ -446,7 +446,7 @@ int GraphDataGenerator::FillInsBuf() { ...@@ -446,7 +446,7 @@ int GraphDataGenerator::FillInsBuf() {
if (!FLAGS_enable_opt_get_features && slot_num_ > 0) { if (!FLAGS_enable_opt_get_features && slot_num_ > 0) {
uint64_t *feature_buf = uint64_t *feature_buf =
reinterpret_cast<uint64_t *>(d_feature_buf_->ptr()); reinterpret_cast<uint64_t *>(d_feature_buf_->ptr());
uint64_t h_feature_buf[(batch_size_ * 2 * 2) * slot_num_]; uint64_t h_feature_buf[(batch_size_ * 2 * 2) * slot_num_]; // NOLINT
cudaMemcpy(h_feature_buf, cudaMemcpy(h_feature_buf,
feature_buf, feature_buf,
(batch_size_ * 2 * 2) * slot_num_ * sizeof(uint64_t), (batch_size_ * 2 * 2) * slot_num_ * sizeof(uint64_t),
...@@ -574,7 +574,7 @@ int GraphDataGenerator::GenerateBatch() { ...@@ -574,7 +574,7 @@ int GraphDataGenerator::GenerateBatch() {
0, 0,
stream_>>>(clk_tensor_ptr_, total_instance); stream_>>>(clk_tensor_ptr_, total_instance);
} else { } else {
ins_cursor = (uint64_t *)id_tensor_ptr_; ins_cursor = (uint64_t *)id_tensor_ptr_; // NOLINT
} }
if (slot_num_ > 0) { if (slot_num_ > 0) {
...@@ -583,12 +583,12 @@ int GraphDataGenerator::GenerateBatch() { ...@@ -583,12 +583,12 @@ int GraphDataGenerator::GenerateBatch() {
FillFeatureBuf(ins_cursor, feature_buf, total_instance); FillFeatureBuf(ins_cursor, feature_buf, total_instance);
// FillFeatureBuf(id_tensor_ptr_, feature_buf, total_instance); // FillFeatureBuf(id_tensor_ptr_, feature_buf, total_instance);
if (debug_mode_) { if (debug_mode_) {
uint64_t h_walk[total_instance]; uint64_t h_walk[total_instance]; // NOLINT
cudaMemcpy(h_walk, cudaMemcpy(h_walk,
ins_cursor, ins_cursor,
total_instance * sizeof(uint64_t), total_instance * sizeof(uint64_t),
cudaMemcpyDeviceToHost); cudaMemcpyDeviceToHost);
uint64_t h_feature[total_instance * slot_num_]; uint64_t h_feature[total_instance * slot_num_]; // NOLINT
cudaMemcpy(h_feature, cudaMemcpy(h_feature,
feature_buf, feature_buf,
total_instance * slot_num_ * sizeof(uint64_t), total_instance * slot_num_ * sizeof(uint64_t),
...@@ -608,16 +608,17 @@ int GraphDataGenerator::GenerateBatch() { ...@@ -608,16 +608,17 @@ int GraphDataGenerator::GenerateBatch() {
GraphFillSlotKernel<<<GET_BLOCKS(total_instance * slot_num_), GraphFillSlotKernel<<<GET_BLOCKS(total_instance * slot_num_),
CUDA_NUM_THREADS, CUDA_NUM_THREADS,
0, 0,
stream_>>>((uint64_t *)d_slot_tensor_ptr_->ptr(), stream_>>>(
feature_buf, (uint64_t *)d_slot_tensor_ptr_->ptr(), // NOLINT
total_instance * slot_num_, feature_buf,
total_instance, total_instance * slot_num_,
slot_num_); total_instance,
slot_num_);
GraphFillSlotLodKernelOpt<<<GET_BLOCKS((total_instance + 1) * slot_num_), GraphFillSlotLodKernelOpt<<<GET_BLOCKS((total_instance + 1) * slot_num_),
CUDA_NUM_THREADS, CUDA_NUM_THREADS,
0, 0,
stream_>>>( stream_>>>(
(uint64_t *)d_slot_lod_tensor_ptr_->ptr(), (uint64_t *)d_slot_lod_tensor_ptr_->ptr(), // NOLINT
(total_instance + 1) * slot_num_, (total_instance + 1) * slot_num_,
total_instance + 1); total_instance + 1);
} else { } else {
...@@ -828,7 +829,7 @@ void GraphDataGenerator::FillOneStep(uint64_t *d_start_ids, ...@@ -828,7 +829,7 @@ void GraphDataGenerator::FillOneStep(uint64_t *d_start_ids,
int *h_prefix_sum = new int[len + 1]; int *h_prefix_sum = new int[len + 1];
int *h_actual_size = new int[len]; int *h_actual_size = new int[len];
int *h_offset2idx = new int[once_max_sample_keynum]; int *h_offset2idx = new int[once_max_sample_keynum];
uint64_t h_sample_keys[once_max_sample_keynum]; uint64_t h_sample_keys[once_max_sample_keynum]; // NOLINT
cudaMemcpy(h_offset2idx, cudaMemcpy(h_offset2idx,
d_tmp_sampleidx2row, d_tmp_sampleidx2row,
once_max_sample_keynum * sizeof(int), once_max_sample_keynum * sizeof(int),
...@@ -870,11 +871,12 @@ int GraphDataGenerator::FillFeatureBuf( ...@@ -870,11 +871,12 @@ int GraphDataGenerator::FillFeatureBuf(
platform::CUDADeviceGuard guard(gpuid_); platform::CUDADeviceGuard guard(gpuid_);
auto gpu_graph_ptr = GraphGpuWrapper::GetInstance(); auto gpu_graph_ptr = GraphGpuWrapper::GetInstance();
int ret = gpu_graph_ptr->get_feature_of_nodes(gpuid_, int ret = gpu_graph_ptr->get_feature_of_nodes(
(uint64_t *)d_walk->ptr(), gpuid_,
(uint64_t *)d_feature->ptr(), (uint64_t *)d_walk->ptr(), // NOLINT
buf_size_, (uint64_t *)d_feature->ptr(), // NOLINT
slot_num_); buf_size_,
slot_num_);
return ret; return ret;
} }
...@@ -1044,8 +1046,9 @@ int GraphDataGenerator::FillWalkBuf(std::shared_ptr<phi::Allocation> d_walk) { ...@@ -1044,8 +1046,9 @@ int GraphDataGenerator::FillWalkBuf(std::shared_ptr<phi::Allocation> d_walk) {
return total_row != 0; return total_row != 0;
} }
void GraphDataGenerator::AllocResource(const paddle::platform::Place &place, void GraphDataGenerator::AllocResource(
std::vector<LoDTensor *> feed_vec) { const paddle::platform::Place &place,
std::vector<phi::DenseTensor *> feed_vec) {
place_ = place; place_ = place;
gpuid_ = place_.GetDeviceId(); gpuid_ = place_.GetDeviceId();
VLOG(3) << "gpuid " << gpuid_; VLOG(3) << "gpuid " << gpuid_;
...@@ -1195,7 +1198,7 @@ void GraphDataGenerator::SetConfig( ...@@ -1195,7 +1198,7 @@ void GraphDataGenerator::SetConfig(
meta_path_[i].push_back(iter->second); meta_path_[i].push_back(iter->second);
} }
} }
}; }
} // namespace framework } // namespace framework
} // namespace paddle } // namespace paddle
......
...@@ -402,7 +402,7 @@ class CustomParser { ...@@ -402,7 +402,7 @@ class CustomParser {
const char* str, const char* str,
std::vector<Record>* instances) { std::vector<Record>* instances) {
return 0; return 0;
}; }
virtual bool ParseOneInstance( virtual bool ParseOneInstance(
const std::string& line, const std::string& line,
std::function<void(std::vector<SlotRecord>&, int)> std::function<void(std::vector<SlotRecord>&, int)>
...@@ -562,8 +562,8 @@ class MiniBatchGpuPack { ...@@ -562,8 +562,8 @@ class MiniBatchGpuPack {
} }
} }
} }
LoDTensor& float_tensor(void) { return float_tensor_; } phi::DenseTensor& float_tensor(void) { return float_tensor_; }
LoDTensor& uint64_tensor(void) { return uint64_tensor_; } phi::DenseTensor& uint64_tensor(void) { return uint64_tensor_; }
HostBuffer<size_t>& offsets(void) { return offsets_; } HostBuffer<size_t>& offsets(void) { return offsets_; }
HostBuffer<void*>& h_tensor_ptrs(void) { return h_tensor_ptrs_; } HostBuffer<void*>& h_tensor_ptrs(void) { return h_tensor_ptrs_; }
...@@ -628,9 +628,9 @@ class MiniBatchGpuPack { ...@@ -628,9 +628,9 @@ class MiniBatchGpuPack {
const SlotRecord* batch_ins_ = nullptr; const SlotRecord* batch_ins_ = nullptr;
// uint64 tensor // uint64 tensor
LoDTensor uint64_tensor_; phi::DenseTensor uint64_tensor_;
// float tensor // float tensor
LoDTensor float_tensor_; phi::DenseTensor float_tensor_;
// batch // batch
HostBuffer<size_t> offsets_; HostBuffer<size_t> offsets_;
HostBuffer<void*> h_tensor_ptrs_; HostBuffer<void*> h_tensor_ptrs_;
...@@ -892,11 +892,11 @@ struct BufState { ...@@ -892,11 +892,11 @@ struct BufState {
class GraphDataGenerator { class GraphDataGenerator {
public: public:
GraphDataGenerator(){}; GraphDataGenerator() {}
virtual ~GraphDataGenerator(){}; virtual ~GraphDataGenerator() {}
void SetConfig(const paddle::framework::DataFeedDesc& data_feed_desc); void SetConfig(const paddle::framework::DataFeedDesc& data_feed_desc);
void AllocResource(const paddle::platform::Place& place, void AllocResource(const paddle::platform::Place& place,
std::vector<LoDTensor*> feed_vec); std::vector<phi::DenseTensor*> feed_vec);
int AcquireInstance(BufState* state); int AcquireInstance(BufState* state);
int GenerateBatch(); int GenerateBatch();
int FillWalkBuf(std::shared_ptr<phi::Allocation> d_walk); int FillWalkBuf(std::shared_ptr<phi::Allocation> d_walk);
...@@ -906,7 +906,7 @@ class GraphDataGenerator { ...@@ -906,7 +906,7 @@ class GraphDataGenerator {
void FillOneStep(uint64_t* start_ids, void FillOneStep(uint64_t* start_ids,
uint64_t* walk, uint64_t* walk,
int len, int len,
NeighborSampleResult& sample_res, NeighborSampleResult& sample_res, // NOLINT
int cur_degree, int cur_degree,
int step, int step,
int* len_per_row); int* len_per_row);
...@@ -935,7 +935,7 @@ class GraphDataGenerator { ...@@ -935,7 +935,7 @@ class GraphDataGenerator {
int64_t* clk_tensor_ptr_; int64_t* clk_tensor_ptr_;
cudaStream_t stream_; cudaStream_t stream_;
paddle::platform::Place place_; paddle::platform::Place place_;
std::vector<LoDTensor*> feed_vec_; std::vector<phi::DenseTensor*> feed_vec_;
std::vector<size_t> offset_; std::vector<size_t> offset_;
std::shared_ptr<phi::Allocation> d_prefix_sum_; std::shared_ptr<phi::Allocation> d_prefix_sum_;
std::vector<std::shared_ptr<phi::Allocation>> d_device_keys_; std::vector<std::shared_ptr<phi::Allocation>> d_device_keys_;
...@@ -1106,9 +1106,9 @@ class DataFeed { ...@@ -1106,9 +1106,9 @@ class DataFeed {
use_slots_index_; // -1: not used; >=0: the index of use_slots_ use_slots_index_; // -1: not used; >=0: the index of use_slots_
// The data read by DataFeed will be stored here // The data read by DataFeed will be stored here
std::vector<LoDTensor*> feed_vec_; std::vector<phi::DenseTensor*> feed_vec_;
LoDTensor* rank_offset_; phi::DenseTensor* rank_offset_;
// the batch size defined by user // the batch size defined by user
int default_batch_size_; int default_batch_size_;
...@@ -1599,7 +1599,7 @@ class MultiSlotInMemoryDataFeed : public InMemoryDataFeed<Record> { ...@@ -1599,7 +1599,7 @@ class MultiSlotInMemoryDataFeed : public InMemoryDataFeed<Record> {
virtual bool ParseOneInstanceFromPipe(Record* instance); virtual bool ParseOneInstanceFromPipe(Record* instance);
virtual void ParseOneInstanceFromSo(const char* str, virtual void ParseOneInstanceFromSo(const char* str,
Record* instance, Record* instance,
CustomParser* parser){}; CustomParser* parser) {}
virtual int ParseInstanceFromSo(int len, virtual int ParseInstanceFromSo(int len,
const char* str, const char* str,
std::vector<Record>* instances, std::vector<Record>* instances,
......
...@@ -122,9 +122,9 @@ void TransformData(const OpKernelType &expected_kernel_type, ...@@ -122,9 +122,9 @@ void TransformData(const OpKernelType &expected_kernel_type,
void SetTensorToVariable(const Variable &in_var, void SetTensorToVariable(const Variable &in_var,
const phi::DenseTensor &tensor, const phi::DenseTensor &tensor,
Variable *out_var) { Variable *out_var) {
if (in_var.IsType<LoDTensor>()) { if (in_var.IsType<phi::DenseTensor>()) {
auto &in_lod_tensor = in_var.Get<LoDTensor>(); auto &in_lod_tensor = in_var.Get<phi::DenseTensor>();
auto *tran_lod_tensor = out_var->GetMutable<LoDTensor>(); auto *tran_lod_tensor = out_var->GetMutable<phi::DenseTensor>();
tran_lod_tensor->set_lod(in_lod_tensor.lod()); tran_lod_tensor->set_lod(in_lod_tensor.lod());
tran_lod_tensor->set_layout(in_lod_tensor.layout()); tran_lod_tensor->set_layout(in_lod_tensor.layout());
#ifdef PADDLE_WITH_MKLDNN #ifdef PADDLE_WITH_MKLDNN
...@@ -139,7 +139,8 @@ void SetTensorToVariable(const Variable &in_var, ...@@ -139,7 +139,8 @@ void SetTensorToVariable(const Variable &in_var,
trans_selected_rows->mutable_value()->ShareDataWith(tensor); trans_selected_rows->mutable_value()->ShareDataWith(tensor);
} else { } else {
PADDLE_THROW(platform::errors::Unavailable( PADDLE_THROW(platform::errors::Unavailable(
"Unsupported variable type, only supports LoDTensor or SelectedRows, " "Unsupported variable type, only supports phi::DenseTensor or "
"SelectedRows, "
"but the input variable type is %s.", "but the input variable type is %s.",
ToTypeName(in_var.Type()))); ToTypeName(in_var.Type())));
} }
......
...@@ -131,7 +131,7 @@ void AllReduceOpHandle::AllReduceImpl( ...@@ -131,7 +131,7 @@ void AllReduceOpHandle::AllReduceImpl(
var, var,
platform::errors::NotFound("Variable %s is not found in local scope.", platform::errors::NotFound("Variable %s is not found in local scope.",
in_var_handles[i]->name())); in_var_handles[i]->name()));
auto &lod_tensor = var->Get<LoDTensor>(); auto &lod_tensor = var->Get<phi::DenseTensor>();
if (i == 0) { if (i == 0) {
numel = static_cast<int64_t>(lod_tensor.numel()); numel = static_cast<int64_t>(lod_tensor.numel());
...@@ -246,7 +246,7 @@ void AllReduceOpHandle::AllReduceFunc( ...@@ -246,7 +246,7 @@ void AllReduceOpHandle::AllReduceFunc(
} else { // Special handle CPU only Operator's gradient. Like CRF } else { // Special handle CPU only Operator's gradient. Like CRF
auto &trg = *local_exec_scopes_[0] auto &trg = *local_exec_scopes_[0]
->FindVar(out_var_names[0]) ->FindVar(out_var_names[0])
->GetMutable<LoDTensor>(); ->GetMutable<phi::DenseTensor>();
// Reduce All phi::DenseTensor to trg in CPU // Reduce All phi::DenseTensor to trg in CPU
ReduceBufferData func(lod_tensor_data, trg.data(), numel); ReduceBufferData func(lod_tensor_data, trg.data(), numel);
......
...@@ -177,9 +177,10 @@ FetchResultType AsyncSSAGraphExecutor::Run( ...@@ -177,9 +177,10 @@ FetchResultType AsyncSSAGraphExecutor::Run(
auto &val = PADDLE_GET(FetchList, fetch_data); auto &val = PADDLE_GET(FetchList, fetch_data);
for (size_t fetch_idx = 0; fetch_idx < fetch_tensors.size(); ++fetch_idx) { for (size_t fetch_idx = 0; fetch_idx < fetch_tensors.size(); ++fetch_idx) {
if (data_is_lod_tensor(val.at(fetch_idx))) { if (data_is_lod_tensor(val.at(fetch_idx))) {
std::vector<const LoDTensor *> lodtensor_ptrs; std::vector<const phi::DenseTensor *> lodtensor_ptrs;
lodtensor_ptrs.push_back(&(PADDLE_GET(LoDTensor, val.at(fetch_idx)))); lodtensor_ptrs.push_back(
LoDTensor var; &(PADDLE_GET(phi::DenseTensor, val.at(fetch_idx))));
phi::DenseTensor var;
MergeLoDTensor(&var, lodtensor_ptrs, platform::CPUPlace()); MergeLoDTensor(&var, lodtensor_ptrs, platform::CPUPlace());
ret.emplace_back(var); ret.emplace_back(var);
} else { } else {
...@@ -187,7 +188,7 @@ FetchResultType AsyncSSAGraphExecutor::Run( ...@@ -187,7 +188,7 @@ FetchResultType AsyncSSAGraphExecutor::Run(
LoDTensorArray item_array; LoDTensorArray item_array;
item_array.reserve(array.size()); item_array.reserve(array.size());
for (size_t i = 0; i < array.size(); ++i) { for (size_t i = 0; i < array.size(); ++i) {
std::vector<const LoDTensor *> lodtensor_ptrs; std::vector<const phi::DenseTensor *> lodtensor_ptrs;
lodtensor_ptrs.push_back(&array[i]); lodtensor_ptrs.push_back(&array[i]);
item_array.emplace_back(); item_array.emplace_back();
MergeLoDTensor( MergeLoDTensor(
......
...@@ -150,8 +150,9 @@ void EagerDeletionOpHandle::RunImpl() { ...@@ -150,8 +150,9 @@ void EagerDeletionOpHandle::RunImpl() {
Variable *var = vars_[i]; Variable *var = vars_[i];
if (var->IsType<LoDTensor>()) { if (var->IsType<phi::DenseTensor>()) {
garbages.emplace_back(var->GetMutable<LoDTensor>()->MoveMemoryHolder()); garbages.emplace_back(
var->GetMutable<phi::DenseTensor>()->MoveMemoryHolder());
} else if (var->IsType<phi::SelectedRows>()) { } else if (var->IsType<phi::SelectedRows>()) {
garbages.emplace_back(var->GetMutable<phi::SelectedRows>() garbages.emplace_back(var->GetMutable<phi::SelectedRows>()
->mutable_value() ->mutable_value()
......
...@@ -45,7 +45,7 @@ void FetchAsyncOpHandle::RecordWaitEventOnCtx( ...@@ -45,7 +45,7 @@ void FetchAsyncOpHandle::RecordWaitEventOnCtx(
"No nodes need to wait FetchAsyncOp. Unexpceted Error.")); "No nodes need to wait FetchAsyncOp. Unexpceted Error."));
} }
static void CheckTensorAttrs(const LoDTensor *tensor, static void CheckTensorAttrs(const phi::DenseTensor *tensor,
const proto::VarType::Type &type, const proto::VarType::Type &type,
const DataLayout &layout, const DataLayout &layout,
const DDim &dims, const DDim &dims,
...@@ -145,8 +145,8 @@ static void TransData(const phi::DenseTensor *src_item, ...@@ -145,8 +145,8 @@ static void TransData(const phi::DenseTensor *src_item,
} }
void FetchAsyncOpHandle::FetchMergedLodTensor( void FetchAsyncOpHandle::FetchMergedLodTensor(
const std::vector<const LoDTensor *> &src_lodtensors, const std::vector<const phi::DenseTensor *> &src_lodtensors,
LoDTensor *dst_lodtensor) { phi::DenseTensor *dst_lodtensor) {
// calc dst type,layout,dim,lod and calc check dim // calc dst type,layout,dim,lod and calc check dim
proto::VarType::Type new_type = proto::VarType::FP32; proto::VarType::Type new_type = proto::VarType::FP32;
phi::DataLayout new_layout; phi::DataLayout new_layout;
...@@ -245,15 +245,15 @@ void FetchAsyncOpHandle::RunImpl() { ...@@ -245,15 +245,15 @@ void FetchAsyncOpHandle::RunImpl() {
if (return_merged_) { if (return_merged_) {
auto &val = PADDLE_GET(FetchList, *data_); auto &val = PADDLE_GET(FetchList, *data_);
if (src_vars[0]->IsType<LoDTensor>()) { if (src_vars[0]->IsType<phi::DenseTensor>()) {
// to lodtensor type // to lodtensor type
std::vector<const LoDTensor *> src_lodtensors; std::vector<const phi::DenseTensor *> src_lodtensors;
src_lodtensors.reserve(src_vars.size()); src_lodtensors.reserve(src_vars.size());
for (size_t i = 0; i < src_vars.size(); ++i) { for (size_t i = 0; i < src_vars.size(); ++i) {
src_lodtensors.emplace_back(&src_vars[i]->Get<phi::DenseTensor>()); src_lodtensors.emplace_back(&src_vars[i]->Get<phi::DenseTensor>());
} }
LoDTensor dst_lodtensor; phi::DenseTensor dst_lodtensor;
FetchMergedLodTensor(src_lodtensors, &dst_lodtensor); FetchMergedLodTensor(src_lodtensors, &dst_lodtensor);
val.at(offset_) = std::move(dst_lodtensor); val.at(offset_) = std::move(dst_lodtensor);
} else { } else {
...@@ -269,7 +269,7 @@ void FetchAsyncOpHandle::RunImpl() { ...@@ -269,7 +269,7 @@ void FetchAsyncOpHandle::RunImpl() {
dst_lodtensor_array.resize(src_lodtensor_arrays[0]->size()); dst_lodtensor_array.resize(src_lodtensor_arrays[0]->size());
for (size_t i = 0; i < dst_lodtensor_array.size(); ++i) { for (size_t i = 0; i < dst_lodtensor_array.size(); ++i) {
std::vector<const LoDTensor *> src_lodtensors; std::vector<const phi::DenseTensor *> src_lodtensors;
src_lodtensors.reserve(src_lodtensor_arrays.size()); src_lodtensors.reserve(src_lodtensor_arrays.size());
for (size_t j = 0; j < src_lodtensor_arrays.size(); ++j) { for (size_t j = 0; j < src_lodtensor_arrays.size(); ++j) {
src_lodtensors.emplace_back(&(*src_lodtensor_arrays[j])[i]); src_lodtensors.emplace_back(&(*src_lodtensor_arrays[j])[i]);
...@@ -284,9 +284,9 @@ void FetchAsyncOpHandle::RunImpl() { ...@@ -284,9 +284,9 @@ void FetchAsyncOpHandle::RunImpl() {
dst_tensors.reserve(src_vars.size()); dst_tensors.reserve(src_vars.size());
for (size_t i = 0; i < src_vars.size(); ++i) { for (size_t i = 0; i < src_vars.size(); ++i) {
if (src_vars[i]->IsType<LoDTensor>()) { if (src_vars[i]->IsType<phi::DenseTensor>()) {
auto &t = src_vars[i]->Get<phi::DenseTensor>(); auto &t = src_vars[i]->Get<phi::DenseTensor>();
LoDTensor item; phi::DenseTensor item;
TransData(&t, &item, *dev_ctxes_[t.place()]); TransData(&t, &item, *dev_ctxes_[t.place()]);
dst_tensors.emplace_back(std::move(item)); dst_tensors.emplace_back(std::move(item));
} else { } else {
......
...@@ -62,8 +62,8 @@ struct FetchAsyncOpHandle : public OpHandleBase { ...@@ -62,8 +62,8 @@ struct FetchAsyncOpHandle : public OpHandleBase {
std::vector<Scope *> GetLocalScopes() override { return *local_scopes_; } std::vector<Scope *> GetLocalScopes() override { return *local_scopes_; }
void FetchMergedLodTensor( void FetchMergedLodTensor(
const std::vector<const LoDTensor *> &src_lodtensors, const std::vector<const phi::DenseTensor *> &src_lodtensors,
LoDTensor *dst_lodtensor); phi::DenseTensor *dst_lodtensor);
private: private:
FetchResultType *data_; FetchResultType *data_;
......
...@@ -74,18 +74,20 @@ static void CheckDims(const framework::DDim &tensor_dims, ...@@ -74,18 +74,20 @@ static void CheckDims(const framework::DDim &tensor_dims,
void FetchOpHandle::WaitAndMergeCPUFetchVars() const { void FetchOpHandle::WaitAndMergeCPUFetchVars() const {
if (return_merged_) { if (return_merged_) {
if (data_is_lod_tensor(tensors_[0])) { if (data_is_lod_tensor(tensors_[0])) {
const auto &tensor_dims = PADDLE_GET_CONST(LoDTensor, tensors_[0]).dims(); const auto &tensor_dims =
PADDLE_GET_CONST(phi::DenseTensor, tensors_[0]).dims();
for (size_t i = 1; i < tensors_.size(); i++) { for (size_t i = 1; i < tensors_.size(); i++) {
const auto &ele_dims = PADDLE_GET_CONST(LoDTensor, tensors_[i]).dims(); const auto &ele_dims =
PADDLE_GET_CONST(phi::DenseTensor, tensors_[i]).dims();
CheckDims(tensor_dims, ele_dims, offset_); CheckDims(tensor_dims, ele_dims, offset_);
} }
std::vector<const LoDTensor *> tensors_ptr; std::vector<const phi::DenseTensor *> tensors_ptr;
tensors_ptr.reserve(tensors_.size()); tensors_ptr.reserve(tensors_.size());
for (auto &t : tensors_) { for (auto &t : tensors_) {
tensors_ptr.emplace_back(&PADDLE_GET_CONST(LoDTensor, t)); tensors_ptr.emplace_back(&PADDLE_GET_CONST(phi::DenseTensor, t));
} }
auto &val = PADDLE_GET(FetchList, *data_); auto &val = PADDLE_GET(FetchList, *data_);
LoDTensor var; phi::DenseTensor var;
MergeLoDTensor(&var, tensors_ptr, platform::CPUPlace()); MergeLoDTensor(&var, tensors_ptr, platform::CPUPlace());
val.at(offset_) = std::move(var); val.at(offset_) = std::move(var);
} else { } else {
...@@ -94,7 +96,7 @@ void FetchOpHandle::WaitAndMergeCPUFetchVars() const { ...@@ -94,7 +96,7 @@ void FetchOpHandle::WaitAndMergeCPUFetchVars() const {
tmp_array.reserve(array.size()); tmp_array.reserve(array.size());
for (size_t i = 0; i < array.size(); ++i) { for (size_t i = 0; i < array.size(); ++i) {
const auto &tensor_dims = array[i].dims(); const auto &tensor_dims = array[i].dims();
std::vector<const LoDTensor *> tensors_ptr; std::vector<const phi::DenseTensor *> tensors_ptr;
tensors_ptr.reserve(tensors_.size()); tensors_ptr.reserve(tensors_.size());
tensors_ptr.push_back(&array[i]); tensors_ptr.push_back(&array[i]);
for (size_t j = 1; j < tensors_.size(); ++j) { for (size_t j = 1; j < tensors_.size(); ++j) {
...@@ -149,9 +151,9 @@ void FetchOpHandle::RunImpl() { ...@@ -149,9 +151,9 @@ void FetchOpHandle::RunImpl() {
platform::errors::NotFound( platform::errors::NotFound(
"Cannot find variable %s in execution scope.", var_handle->name())); "Cannot find variable %s in execution scope.", var_handle->name()));
if (var->IsType<LoDTensor>()) { if (var->IsType<phi::DenseTensor>()) {
auto &t = var->Get<phi::DenseTensor>(); auto &t = var->Get<phi::DenseTensor>();
auto &item = PADDLE_GET(LoDTensor, tensors_[i]); auto &item = PADDLE_GET(phi::DenseTensor, tensors_[i]);
TransData(t, &item); TransData(t, &item);
} else { } else {
auto &t = var->Get<framework::LoDTensorArray>(); auto &t = var->Get<framework::LoDTensorArray>();
......
...@@ -27,7 +27,8 @@ namespace paddle { ...@@ -27,7 +27,8 @@ namespace paddle {
namespace framework { namespace framework {
namespace details { namespace details {
typedef std::vector<std::vector<std::pair<std::string, const LoDTensor *>>> typedef std::vector<
std::vector<std::pair<std::string, const phi::DenseTensor *>>>
GradientAndLoDTensor; GradientAndLoDTensor;
#if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL) #if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL)
...@@ -238,10 +239,9 @@ void FusedAllReduceOpHandle::FusedAllReduceFunc( ...@@ -238,10 +239,9 @@ void FusedAllReduceOpHandle::FusedAllReduceFunc(
std::sort( std::sort(
g_tensor.begin(), g_tensor.begin(),
g_tensor.end(), g_tensor.end(),
[](const std::pair<std::string, const LoDTensor *> &grad1, [](const std::pair<std::string, const phi::DenseTensor *> &grad1,
const std::pair<std::string, const LoDTensor *> &grad2) -> bool { const std::pair<std::string, const phi::DenseTensor *> &grad2)
return grad1.second->data() < grad2.second->data(); -> bool { return grad1.second->data() < grad2.second->data(); });
});
size_t size_of_dtype = framework::SizeOfType(dtype); size_t size_of_dtype = framework::SizeOfType(dtype);
for (size_t k = 1; k < g_tensor.size(); ++k) { for (size_t k = 1; k < g_tensor.size(); ++k) {
...@@ -320,7 +320,7 @@ bool FusedAllReduceOpHandle::InputIsInDifferentPlace( ...@@ -320,7 +320,7 @@ bool FusedAllReduceOpHandle::InputIsInDifferentPlace(
var, var,
platform::errors::NotFound( platform::errors::NotFound(
"The variable '%s' is not found in local scope.", var_name)); "The variable '%s' is not found in local scope.", var_name));
auto &lod_tensor = var->Get<LoDTensor>(); auto &lod_tensor = var->Get<phi::DenseTensor>();
if (!platform::is_same_place(lod_tensor.place(), places_.at(scope_idx))) { if (!platform::is_same_place(lod_tensor.place(), places_.at(scope_idx))) {
return true; return true;
} }
...@@ -333,7 +333,8 @@ void FusedAllReduceOpHandle::GetGradLoDTensor( ...@@ -333,7 +333,8 @@ void FusedAllReduceOpHandle::GetGradLoDTensor(
const size_t &scope_idx, const size_t &scope_idx,
const std::vector<VarHandle *> &in_var_handles, const std::vector<VarHandle *> &in_var_handles,
const std::vector<VarHandle *> &out_var_handles, const std::vector<VarHandle *> &out_var_handles,
std::vector<std::pair<std::string, const LoDTensor *>> *grad_tensor) const { std::vector<std::pair<std::string, const phi::DenseTensor *>> *grad_tensor)
const {
auto *local_scope = local_exec_scopes_[scope_idx]; auto *local_scope = local_exec_scopes_[scope_idx];
size_t place_num = places_.size(); size_t place_num = places_.size();
for (size_t j = 0; j < in_var_handles.size(); j += place_num) { for (size_t j = 0; j < in_var_handles.size(); j += place_num) {
...@@ -352,7 +353,7 @@ void FusedAllReduceOpHandle::GetGradLoDTensor( ...@@ -352,7 +353,7 @@ void FusedAllReduceOpHandle::GetGradLoDTensor(
var, var,
platform::errors::NotFound( platform::errors::NotFound(
"The variable '%s' is not found in local scope.", var_name)); "The variable '%s' is not found in local scope.", var_name));
auto &lod_tensor = var->Get<LoDTensor>(); auto &lod_tensor = var->Get<phi::DenseTensor>();
PADDLE_ENFORCE_EQ( PADDLE_ENFORCE_EQ(
platform::is_same_place(lod_tensor.place(), places_.at(scope_idx)), platform::is_same_place(lod_tensor.place(), places_.at(scope_idx)),
...@@ -366,7 +367,8 @@ void FusedAllReduceOpHandle::GetGradLoDTensor( ...@@ -366,7 +367,8 @@ void FusedAllReduceOpHandle::GetGradLoDTensor(
} }
void FusedAllReduceOpHandle::GetDTypeAndNumel( void FusedAllReduceOpHandle::GetDTypeAndNumel(
const std::vector<std::pair<std::string, const LoDTensor *>> &grad_tensor, const std::vector<std::pair<std::string, const phi::DenseTensor *>>
&grad_tensor,
proto::VarType::Type *dtype, proto::VarType::Type *dtype,
int64_t *numel) const { int64_t *numel) const {
*numel = 0; *numel = 0;
......
...@@ -82,16 +82,18 @@ struct FusedAllReduceOpHandle : public AllReduceOpHandle { ...@@ -82,16 +82,18 @@ struct FusedAllReduceOpHandle : public AllReduceOpHandle {
// Check the dtype of the input // Check the dtype of the input
void GetDTypeAndNumel( void GetDTypeAndNumel(
const std::vector<std::pair<std::string, const LoDTensor *>> &g_tensor, const std::vector<std::pair<std::string, const phi::DenseTensor *>>
&g_tensor,
proto::VarType::Type *dtype, proto::VarType::Type *dtype,
int64_t *total_num) const; int64_t *total_num) const;
// Get gradient's name and LoDTensor // Get gradient's name and phi::DenseTensor
void GetGradLoDTensor(const size_t &scope_idx, void GetGradLoDTensor(
const std::vector<VarHandle *> &in_var_handles, const size_t &scope_idx,
const std::vector<VarHandle *> &out_var_handles, const std::vector<VarHandle *> &in_var_handles,
std::vector<std::pair<std::string, const LoDTensor *>> const std::vector<VarHandle *> &out_var_handles,
*grad_tensor) const; std::vector<std::pair<std::string, const phi::DenseTensor *>>
*grad_tensor) const;
bool InputIsInDifferentPlace( bool InputIsInDifferentPlace(
const std::vector<VarHandle *> &in_var_handles) const; const std::vector<VarHandle *> &in_var_handles) const;
......
...@@ -65,7 +65,7 @@ void GradMergeAllReduceOpHandle::RunImpl() { ...@@ -65,7 +65,7 @@ void GradMergeAllReduceOpHandle::RunImpl() {
PADDLE_ENFORCE_NOT_NULL(cond_var, PADDLE_ENFORCE_NOT_NULL(cond_var,
platform::errors::NotFound( platform::errors::NotFound(
"Variable %s is not found in scope.", cond_var)); "Variable %s is not found in scope.", cond_var));
bool cond = *cond_var->Get<LoDTensor>().data<bool>(); bool cond = *cond_var->Get<phi::DenseTensor>().data<bool>();
if (cond) { if (cond) {
AllReduceOpHandle::RunImpl(); AllReduceOpHandle::RunImpl();
...@@ -123,7 +123,7 @@ void FusedGradMergeAllReduceOpHandle::RunImpl() { ...@@ -123,7 +123,7 @@ void FusedGradMergeAllReduceOpHandle::RunImpl() {
PADDLE_ENFORCE_NOT_NULL(cond_var, PADDLE_ENFORCE_NOT_NULL(cond_var,
platform::errors::NotFound( platform::errors::NotFound(
"Variable %s is not found in scope.", cond_var)); "Variable %s is not found in scope.", cond_var));
bool cond = *cond_var->Get<LoDTensor>().data<bool>(); bool cond = *cond_var->Get<phi::DenseTensor>().data<bool>();
if (cond) { if (cond) {
VLOG(10) << "run fused grad merge all reduce"; VLOG(10) << "run fused grad merge all reduce";
......
...@@ -270,7 +270,7 @@ FetchResultType ParallelSSAGraphExecutor::Run( ...@@ -270,7 +270,7 @@ FetchResultType ParallelSSAGraphExecutor::Run(
FetchList ret; FetchList ret;
ret.reserve(fetch_tensors.size()); ret.reserve(fetch_tensors.size());
for (size_t fetch_idx = 0; fetch_idx < fetch_tensors.size(); ++fetch_idx) { for (size_t fetch_idx = 0; fetch_idx < fetch_tensors.size(); ++fetch_idx) {
std::vector<const LoDTensor *> lodtensor_ptrs; std::vector<const phi::DenseTensor *> lodtensor_ptrs;
lodtensor_ptrs.reserve(place_num); lodtensor_ptrs.reserve(place_num);
std::vector<const LoDTensorArray *> lodtensorarray_ptrs; std::vector<const LoDTensorArray *> lodtensorarray_ptrs;
lodtensorarray_ptrs.reserve(place_num); lodtensorarray_ptrs.reserve(place_num);
...@@ -282,21 +282,21 @@ FetchResultType ParallelSSAGraphExecutor::Run( ...@@ -282,21 +282,21 @@ FetchResultType ParallelSSAGraphExecutor::Run(
PADDLE_GET_CONST(FetchList, fetch_data[scope_idx]); PADDLE_GET_CONST(FetchList, fetch_data[scope_idx]);
if (data_is_lod_tensor(fetch_list[fetch_idx])) { if (data_is_lod_tensor(fetch_list[fetch_idx])) {
lodtensor_ptrs.push_back( lodtensor_ptrs.push_back(
&(PADDLE_GET_CONST(LoDTensor, fetch_list[fetch_idx]))); &(PADDLE_GET_CONST(phi::DenseTensor, fetch_list[fetch_idx])));
} else { } else {
lodtensorarray_ptrs.push_back( lodtensorarray_ptrs.push_back(
&(PADDLE_GET_CONST(LoDTensorArray, fetch_list[fetch_idx]))); &(PADDLE_GET_CONST(LoDTensorArray, fetch_list[fetch_idx])));
} }
} }
if (lodtensor_ptrs.size() != 0) { if (lodtensor_ptrs.size() != 0) {
LoDTensor var; phi::DenseTensor var;
MergeLoDTensor(&var, lodtensor_ptrs, platform::CPUPlace()); MergeLoDTensor(&var, lodtensor_ptrs, platform::CPUPlace());
ret.emplace_back(var); ret.emplace_back(var);
} else { } else {
LoDTensorArray var_array(lodtensorarray_ptrs[0]->size()); LoDTensorArray var_array(lodtensorarray_ptrs[0]->size());
for (size_t i = 0; i < lodtensorarray_ptrs[0]->size(); ++i) { for (size_t i = 0; i < lodtensorarray_ptrs[0]->size(); ++i) {
LoDTensor var; phi::DenseTensor var;
std::vector<const LoDTensor *> ptrs; std::vector<const phi::DenseTensor *> ptrs;
for (size_t j = 0; j < lodtensorarray_ptrs.size(); ++j) { for (size_t j = 0; j < lodtensorarray_ptrs.size(); ++j) {
ptrs.push_back(&(lodtensorarray_ptrs[j]->at(i))); ptrs.push_back(&(lodtensorarray_ptrs[j]->at(i)));
} }
...@@ -323,7 +323,7 @@ FetchResultType ParallelSSAGraphExecutor::Run( ...@@ -323,7 +323,7 @@ FetchResultType ParallelSSAGraphExecutor::Run(
fetch_list[fetch_idx].size(), fetch_list[fetch_idx].size(),
1, 1,
platform::errors::Fatal("Each place must have only one fetched " platform::errors::Fatal("Each place must have only one fetched "
"LoDTensor/LoDTensorArray!")); "phi::DenseTensor/LoDTensorArray!"));
ret.back().emplace_back(fetch_list[fetch_idx][0]); ret.back().emplace_back(fetch_list[fetch_idx][0]);
} }
} }
......
...@@ -30,10 +30,11 @@ namespace framework { ...@@ -30,10 +30,11 @@ namespace framework {
namespace details { namespace details {
struct ReduceLoDTensor { struct ReduceLoDTensor {
const std::vector<const LoDTensor *> &src_tensors_; const std::vector<const phi::DenseTensor *> &src_tensors_;
LoDTensor &dst_tensor_; phi::DenseTensor &dst_tensor_;
ReduceLoDTensor(const std::vector<const LoDTensor *> &src, LoDTensor *dst) ReduceLoDTensor(const std::vector<const phi::DenseTensor *> &src,
phi::DenseTensor *dst)
: src_tensors_(src), dst_tensor_(*dst) {} : src_tensors_(src), dst_tensor_(*dst) {}
template <typename T> template <typename T>
......
...@@ -150,8 +150,8 @@ void ReduceOpHandle::RunImpl() { ...@@ -150,8 +150,8 @@ void ReduceOpHandle::RunImpl() {
} }
}); });
} else { } else {
std::vector<const LoDTensor *> lod_tensors = std::vector<const phi::DenseTensor *> lod_tensors =
GetInputValues<LoDTensor>(in_var_handles, var_scopes); GetInputValues<phi::DenseTensor>(in_var_handles, var_scopes);
if (paddle::platform::is_cpu_place(lod_tensors[0]->place())) { if (paddle::platform::is_cpu_place(lod_tensors[0]->place())) {
WaitInputVarGenerated(); WaitInputVarGenerated();
......
...@@ -107,7 +107,7 @@ void ScaleLossGradOpHandle::RunImpl() { ...@@ -107,7 +107,7 @@ void ScaleLossGradOpHandle::RunImpl() {
} }
void ScaleLossGradOpHandle::RunOnVar(Variable *var, bool record_event) { void ScaleLossGradOpHandle::RunOnVar(Variable *var, bool record_event) {
auto *tensor = var->GetMutable<LoDTensor>(); auto *tensor = var->GetMutable<phi::DenseTensor>();
tensor->Resize(phi::make_ddim({1})); tensor->Resize(phi::make_ddim({1}));
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
......
...@@ -32,8 +32,9 @@ static constexpr double kMB = 1 / (1024 * 1024); ...@@ -32,8 +32,9 @@ static constexpr double kMB = 1 / (1024 * 1024);
static void GetTensors(Variable *var, static void GetTensors(Variable *var,
std::unordered_set<phi::DenseTensor *> *tensor_set) { std::unordered_set<phi::DenseTensor *> *tensor_set) {
if (var->IsType<LoDTensor>() && var->Get<LoDTensor>().IsInitialized()) { if (var->IsType<phi::DenseTensor>() &&
tensor_set->insert(var->GetMutable<LoDTensor>()); var->Get<phi::DenseTensor>().IsInitialized()) {
tensor_set->insert(var->GetMutable<phi::DenseTensor>());
} else if (var->IsType<phi::SelectedRows>() && } else if (var->IsType<phi::SelectedRows>() &&
var->Get<phi::SelectedRows>().value().IsInitialized()) { var->Get<phi::SelectedRows>().value().IsInitialized()) {
tensor_set->insert(var->GetMutable<phi::SelectedRows>()->mutable_value()); tensor_set->insert(var->GetMutable<phi::SelectedRows>()->mutable_value());
......
...@@ -133,7 +133,7 @@ FetchResultType ScopeBufferedSSAGraphExecutor::Run( ...@@ -133,7 +133,7 @@ FetchResultType ScopeBufferedSSAGraphExecutor::Run(
bool ScopeBufferedSSAGraphExecutor::DropScopeOrNot() const { bool ScopeBufferedSSAGraphExecutor::DropScopeOrNot() const {
for (auto &var : tensor_array_vars_) { for (auto &var : tensor_array_vars_) {
auto tensor_array = var->GetMutable<LoDTensorArray>(); auto tensor_array = var->GetMutable<LoDTensorArray>();
for (LoDTensor &tensor : *tensor_array) { for (phi::DenseTensor &tensor : *tensor_array) {
if (tensor.IsInitialized()) { if (tensor.IsInitialized()) {
return true; return true;
} }
......
...@@ -41,21 +41,21 @@ namespace details { ...@@ -41,21 +41,21 @@ namespace details {
// TODO(zjl): support SelectedRows // TODO(zjl): support SelectedRows
static inline const phi::DenseTensor &GetTensorFromVar(const Variable *var) { static inline const phi::DenseTensor &GetTensorFromVar(const Variable *var) {
if (var->IsType<LoDTensor>()) { if (var->IsType<phi::DenseTensor>()) {
return var->Get<LoDTensor>(); return var->Get<phi::DenseTensor>();
} else { } else {
PADDLE_THROW(platform::errors::InvalidArgument( PADDLE_THROW(platform::errors::InvalidArgument(
"Variable must be type of LoDTensor, but received %s.", "Variable must be type of phi::DenseTensor, but received %s.",
framework::ToTypeName(var->Type()))); framework::ToTypeName(var->Type())));
} }
} }
static inline phi::DenseTensor *GetMutableTensorFromVar(Variable *var) { static inline phi::DenseTensor *GetMutableTensorFromVar(Variable *var) {
if (var->IsType<LoDTensor>()) { if (var->IsType<phi::DenseTensor>()) {
return var->GetMutable<LoDTensor>(); return var->GetMutable<phi::DenseTensor>();
} else { } else {
PADDLE_THROW(platform::errors::InvalidArgument( PADDLE_THROW(platform::errors::InvalidArgument(
"Variable must be type of LoDTensor, but received %s.", "Variable must be type of phi::DenseTensor, but received %s.",
framework::ToTypeName(var->Type()))); framework::ToTypeName(var->Type())));
} }
} }
......
...@@ -66,7 +66,8 @@ SparseAllReduceOpHandle::SparseAllReduceOpHandle( ...@@ -66,7 +66,8 @@ SparseAllReduceOpHandle::SparseAllReduceOpHandle(
platform::errors::NotFound("Variable %s is not found in scope.", platform::errors::NotFound("Variable %s is not found in scope.",
nranks_name)); nranks_name));
float *dgc_nranks = nranks_var->GetMutable<LoDTensor>()->data<float>(); float *dgc_nranks =
nranks_var->GetMutable<phi::DenseTensor>()->data<float>();
*dgc_nranks = nranks; *dgc_nranks = nranks;
VLOG(10) << "dgc_nranks=" << *dgc_nranks; VLOG(10) << "dgc_nranks=" << *dgc_nranks;
} }
...@@ -97,9 +98,9 @@ void SparseAllReduceOpHandle::RunImplEncoded() { ...@@ -97,9 +98,9 @@ void SparseAllReduceOpHandle::RunImplEncoded() {
in_var_handles.size(), in_var_handles.size(),
out_var_handles.size())); out_var_handles.size()));
std::vector<const LoDTensor *> ins; std::vector<const phi::DenseTensor *> ins;
std::vector<LoDTensor *> gathers; std::vector<phi::DenseTensor *> gathers;
std::vector<LoDTensor *> outs; std::vector<phi::DenseTensor *> outs;
int k = -1; int k = -1;
for (size_t i = 0; i < local_scopes_.size(); ++i) { for (size_t i = 0; i < local_scopes_.size(); ++i) {
auto *local_scope = local_exec_scopes_[i]; auto *local_scope = local_exec_scopes_[i];
...@@ -112,7 +113,7 @@ void SparseAllReduceOpHandle::RunImplEncoded() { ...@@ -112,7 +113,7 @@ void SparseAllReduceOpHandle::RunImplEncoded() {
in_var, in_var,
platform::errors::NotFound("Variable %s is not found in scope.", platform::errors::NotFound("Variable %s is not found in scope.",
encode_var_name)); encode_var_name));
auto &in = in_var->Get<LoDTensor>(); auto &in = in_var->Get<phi::DenseTensor>();
ins.emplace_back(&in); ins.emplace_back(&in);
auto gather_var_name = original_name + g_dgc_gather; auto gather_var_name = original_name + g_dgc_gather;
...@@ -121,11 +122,11 @@ void SparseAllReduceOpHandle::RunImplEncoded() { ...@@ -121,11 +122,11 @@ void SparseAllReduceOpHandle::RunImplEncoded() {
gather_var, gather_var,
platform::errors::NotFound("Variable %s is not found in scope.", platform::errors::NotFound("Variable %s is not found in scope.",
gather_var)); gather_var));
auto *gather = gather_var->GetMutable<LoDTensor>(); auto *gather = gather_var->GetMutable<phi::DenseTensor>();
gathers.emplace_back(gather); gathers.emplace_back(gather);
auto *out = local_scope->FindVar(out_var_handles[i]->name()) auto *out = local_scope->FindVar(out_var_handles[i]->name())
->GetMutable<LoDTensor>(); ->GetMutable<phi::DenseTensor>();
outs.emplace_back(out); outs.emplace_back(out);
if (k < 0) { if (k < 0) {
...@@ -268,7 +269,7 @@ int SparseAllReduceOpHandle::GetKValue(const std::string &grad_name) { ...@@ -268,7 +269,7 @@ int SparseAllReduceOpHandle::GetKValue(const std::string &grad_name) {
PADDLE_ENFORCE_NOT_NULL(var, PADDLE_ENFORCE_NOT_NULL(var,
platform::errors::NotFound( platform::errors::NotFound(
"Variable %s is not found in scope.", var_name)); "Variable %s is not found in scope.", var_name));
auto tensor = var->Get<LoDTensor>().data<float>(); auto tensor = var->Get<phi::DenseTensor>().data<float>();
return *tensor; return *tensor;
} }
...@@ -297,8 +298,8 @@ bool SparseAllReduceOpHandle::IsEncoded() { ...@@ -297,8 +298,8 @@ bool SparseAllReduceOpHandle::IsEncoded() {
platform::errors::NotFound( platform::errors::NotFound(
"Variable %s is not found in scope.", step_var)); "Variable %s is not found in scope.", step_var));
float count = *count_var->Get<LoDTensor>().data<float>(); float count = *count_var->Get<phi::DenseTensor>().data<float>();
float step = *step_var->Get<LoDTensor>().data<float>(); float step = *step_var->Get<phi::DenseTensor>().data<float>();
if (static_cast<int>(count) < static_cast<int>(step)) { if (static_cast<int>(count) < static_cast<int>(step)) {
VLOG(10) << "in all_reduce currentstep:" << count VLOG(10) << "in all_reduce currentstep:" << count
<< " < rampup_begin_step:" << step << " < rampup_begin_step:" << step
......
...@@ -32,8 +32,8 @@ namespace framework { ...@@ -32,8 +32,8 @@ namespace framework {
namespace details { namespace details {
template <typename Func> template <typename Func>
static void VisitVariable(Variable* var, Func* func) { static void VisitVariable(Variable* var, Func* func) {
if (var->IsType<LoDTensor>()) { if (var->IsType<phi::DenseTensor>()) {
(*func)(var->GetMutable<LoDTensor>()); (*func)(var->GetMutable<phi::DenseTensor>());
} else if (var->IsType<phi::SelectedRows>()) { } else if (var->IsType<phi::SelectedRows>()) {
(*func)(var->GetMutable<phi::SelectedRows>()); (*func)(var->GetMutable<phi::SelectedRows>());
} else { } else {
...@@ -45,8 +45,8 @@ static void VisitVariable(Variable* var, Func* func) { ...@@ -45,8 +45,8 @@ static void VisitVariable(Variable* var, Func* func) {
template <typename Func> template <typename Func>
static void VisitVariable(const Variable& var, Func* func) { static void VisitVariable(const Variable& var, Func* func) {
if (var.IsType<LoDTensor>()) { if (var.IsType<phi::DenseTensor>()) {
(*func)(var.Get<LoDTensor>()); (*func)(var.Get<phi::DenseTensor>());
} else if (var.IsType<phi::SelectedRows>()) { } else if (var.IsType<phi::SelectedRows>()) {
(*func)(var.Get<phi::SelectedRows>()); (*func)(var.Get<phi::SelectedRows>());
} else { } else {
...@@ -58,7 +58,7 @@ static void VisitVariable(const Variable& var, Func* func) { ...@@ -58,7 +58,7 @@ static void VisitVariable(const Variable& var, Func* func) {
struct TensorVisitor { struct TensorVisitor {
phi::DenseTensor* result_{nullptr}; phi::DenseTensor* result_{nullptr};
void operator()(LoDTensor* tensor) { result_ = tensor; } void operator()(phi::DenseTensor* tensor) { result_ = tensor; }
void operator()(phi::SelectedRows* selected_rows) { void operator()(phi::SelectedRows* selected_rows) {
result_ = selected_rows->mutable_value(); result_ = selected_rows->mutable_value();
...@@ -79,8 +79,8 @@ phi::DenseTensor& VariableVisitor::GetMutableTensor(Variable* var) { ...@@ -79,8 +79,8 @@ phi::DenseTensor& VariableVisitor::GetMutableTensor(Variable* var) {
struct ShareDimsAndLoDVisitor { struct ShareDimsAndLoDVisitor {
Variable* trg_; Variable* trg_;
void operator()(const LoDTensor& val) { void operator()(const phi::DenseTensor& val) {
auto* tensor = trg_->GetMutable<LoDTensor>(); auto* tensor = trg_->GetMutable<phi::DenseTensor>();
tensor->set_layout(val.layout()); tensor->set_layout(val.layout());
tensor->set_lod(val.lod()); tensor->set_lod(val.lod());
tensor->Resize(val.dims()); tensor->Resize(val.dims());
...@@ -108,8 +108,8 @@ void VariableVisitor::ShareDimsAndLoD(const Variable& src, Variable* trg) { ...@@ -108,8 +108,8 @@ void VariableVisitor::ShareDimsAndLoD(const Variable& src, Variable* trg) {
struct EnforceShapeAndDTypeEQVisitor { struct EnforceShapeAndDTypeEQVisitor {
const Variable* dst_; const Variable* dst_;
void operator()(const LoDTensor& src) { void operator()(const phi::DenseTensor& src) {
auto& tensor = dst_->Get<LoDTensor>(); auto& tensor = dst_->Get<phi::DenseTensor>();
PADDLE_ENFORCE_EQ( PADDLE_ENFORCE_EQ(
src.place().GetType(), src.place().GetType(),
tensor.place().GetType(), tensor.place().GetType(),
......
...@@ -205,7 +205,8 @@ void PrintLodTensor(phi::DenseTensor* tensor, ...@@ -205,7 +205,8 @@ void PrintLodTensor(phi::DenseTensor* tensor,
} }
} }
std::pair<int64_t, int64_t> GetTensorBound(LoDTensor* tensor, int index) { std::pair<int64_t, int64_t> GetTensorBound(phi::DenseTensor* tensor,
int index) {
auto& dims = tensor->dims(); auto& dims = tensor->dims();
if (tensor->lod().size() != 0) { if (tensor->lod().size() != 0) {
auto& lod = tensor->lod()[0]; auto& lod = tensor->lod()[0];
...@@ -215,7 +216,7 @@ std::pair<int64_t, int64_t> GetTensorBound(LoDTensor* tensor, int index) { ...@@ -215,7 +216,7 @@ std::pair<int64_t, int64_t> GetTensorBound(LoDTensor* tensor, int index) {
} }
} }
bool CheckValidOutput(LoDTensor* tensor, size_t batch_size) { bool CheckValidOutput(phi::DenseTensor* tensor, size_t batch_size) {
auto& dims = tensor->dims(); auto& dims = tensor->dims();
if (dims.size() != 2) return false; if (dims.size() != 2) return false;
if (tensor->lod().size() != 0) { if (tensor->lod().size() != 0) {
...@@ -239,7 +240,7 @@ void DeviceWorker::DumpParam(const Scope& scope, const int batch_id) { ...@@ -239,7 +240,7 @@ void DeviceWorker::DumpParam(const Scope& scope, const int batch_id) {
if (var == nullptr) { if (var == nullptr) {
continue; continue;
} }
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
phi::DenseTensor cpu_tensor; phi::DenseTensor cpu_tensor;
if (platform::is_gpu_place(tensor->place())) { if (platform::is_gpu_place(tensor->place())) {
TensorCopySync(*tensor, platform::CPUPlace(), &cpu_tensor); TensorCopySync(*tensor, platform::CPUPlace(), &cpu_tensor);
...@@ -292,7 +293,7 @@ void DeviceWorker::DumpField(const Scope& scope, ...@@ -292,7 +293,7 @@ void DeviceWorker::DumpField(const Scope& scope,
<< "] cannot be find in scope, so it was skipped."; << "] cannot be find in scope, so it was skipped.";
continue; continue;
} }
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
if (!tensor->IsInitialized()) { if (!tensor->IsInitialized()) {
VLOG(0) << "Note: field[" << field VLOG(0) << "Note: field[" << field
<< "] is not initialized, so it was skipped."; << "] is not initialized, so it was skipped.";
...@@ -315,8 +316,9 @@ void DeviceWorker::DumpField(const Scope& scope, ...@@ -315,8 +316,9 @@ void DeviceWorker::DumpField(const Scope& scope,
if (dump_fields_ == NULL || (*dump_fields_).size() == 0) { if (dump_fields_ == NULL || (*dump_fields_).size() == 0) {
return; return;
} }
auto set_output_str = [&, this]( auto set_output_str = [&, this](size_t begin,
size_t begin, size_t end, LoDTensor* tensor) { size_t end,
phi::DenseTensor* tensor) {
std::pair<int64_t, int64_t> bound; std::pair<int64_t, int64_t> bound;
auto& dims = tensor->dims(); auto& dims = tensor->dims();
for (size_t i = begin; i < end; ++i) { for (size_t i = begin; i < end; ++i) {
...@@ -339,7 +341,7 @@ void DeviceWorker::DumpField(const Scope& scope, ...@@ -339,7 +341,7 @@ void DeviceWorker::DumpField(const Scope& scope,
<< "] cannot be find in scope, so it was skipped."; << "] cannot be find in scope, so it was skipped.";
continue; continue;
} }
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
if (!tensor->IsInitialized()) { if (!tensor->IsInitialized()) {
VLOG(0) << "Note: field[" << field VLOG(0) << "Note: field[" << field
<< "] is not initialized, so it was skipped."; << "] is not initialized, so it was skipped.";
...@@ -422,7 +424,7 @@ void DeviceWorker::DumpField(const Scope& scope, ...@@ -422,7 +424,7 @@ void DeviceWorker::DumpField(const Scope& scope,
<< "] cannot be find in scope, so it was skipped."; << "] cannot be find in scope, so it was skipped.";
continue; continue;
} }
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
if (!tensor->IsInitialized()) { if (!tensor->IsInitialized()) {
VLOG(0) << "Note: field[" << field VLOG(0) << "Note: field[" << field
<< "] is not initialized, so it was skipped."; << "] is not initialized, so it was skipped.";
......
...@@ -70,8 +70,8 @@ void PrintLodTensor(phi::DenseTensor* tensor, ...@@ -70,8 +70,8 @@ void PrintLodTensor(phi::DenseTensor* tensor,
std::string& output_str, // NOLINT std::string& output_str, // NOLINT
char separator = ',', char separator = ',',
bool need_leading_separator = false); bool need_leading_separator = false);
std::pair<int64_t, int64_t> GetTensorBound(LoDTensor* tensor, int index); std::pair<int64_t, int64_t> GetTensorBound(phi::DenseTensor* tensor, int index);
bool CheckValidOutput(LoDTensor* tensor, size_t batch_size); bool CheckValidOutput(phi::DenseTensor* tensor, size_t batch_size);
class FleetWrapper; class FleetWrapper;
...@@ -274,7 +274,9 @@ class HogwildWorker : public CPUWorkerBase { ...@@ -274,7 +274,9 @@ class HogwildWorker : public CPUWorkerBase {
virtual void CreateDeviceResource(const ProgramDesc& main_prog); virtual void CreateDeviceResource(const ProgramDesc& main_prog);
virtual void BindingDataFeedMemory(); virtual void BindingDataFeedMemory();
template <typename T> template <typename T>
void SetZero(LoDTensor* tensor, LoDTensor* root_tensor, int tensor_dim); void SetZero(phi::DenseTensor* tensor,
phi::DenseTensor* root_tensor,
int tensor_dim);
protected: protected:
void CreateThreadOperators(const ProgramDesc& program); void CreateThreadOperators(const ProgramDesc& program);
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
namespace paddle { namespace paddle {
namespace framework { namespace framework {
TEST(LodTensor, PrintLodTensor) { TEST(LodTensor, PrintLodTensor) {
LoDTensor tensor1; phi::DenseTensor tensor1;
tensor1.Resize({2}); tensor1.Resize({2});
tensor1.mutable_data<float>(platform::CPUPlace()); tensor1.mutable_data<float>(platform::CPUPlace());
tensor1.data<float>()[0] = 0.2; tensor1.data<float>()[0] = 0.2;
...@@ -31,7 +31,7 @@ TEST(LodTensor, PrintLodTensor) { ...@@ -31,7 +31,7 @@ TEST(LodTensor, PrintLodTensor) {
res = PrintLodTensor(&tensor1, 0, 2); res = PrintLodTensor(&tensor1, 0, 2);
ASSERT_EQ(res, "0.2,0.5"); ASSERT_EQ(res, "0.2,0.5");
LoDTensor tensor2; phi::DenseTensor tensor2;
tensor2.Resize({2}); tensor2.Resize({2});
tensor2.mutable_data<int64_t>(platform::CPUPlace()); tensor2.mutable_data<int64_t>(platform::CPUPlace());
tensor2.data<int64_t>()[0] = 1; tensor2.data<int64_t>()[0] = 1;
...@@ -41,7 +41,7 @@ TEST(LodTensor, PrintLodTensor) { ...@@ -41,7 +41,7 @@ TEST(LodTensor, PrintLodTensor) {
res = PrintLodTensor(&tensor2, 0, 2); res = PrintLodTensor(&tensor2, 0, 2);
ASSERT_EQ(res, "1,2"); ASSERT_EQ(res, "1,2");
LoDTensor tensor3; phi::DenseTensor tensor3;
tensor3.Resize({2}); tensor3.Resize({2});
tensor3.mutable_data<double>(platform::CPUPlace()); tensor3.mutable_data<double>(platform::CPUPlace());
tensor3.data<double>()[0] = 0.1; tensor3.data<double>()[0] = 0.1;
...@@ -49,7 +49,7 @@ TEST(LodTensor, PrintLodTensor) { ...@@ -49,7 +49,7 @@ TEST(LodTensor, PrintLodTensor) {
res = PrintLodTensor(&tensor3, 0, 2); res = PrintLodTensor(&tensor3, 0, 2);
ASSERT_EQ(res, "0.1,0.2"); ASSERT_EQ(res, "0.1,0.2");
LoDTensor tensor4; phi::DenseTensor tensor4;
tensor4.Resize({2}); tensor4.Resize({2});
tensor4.mutable_data<double>(platform::CPUPlace()); tensor4.mutable_data<double>(platform::CPUPlace());
tensor4.data<double>()[0] = 0.1; tensor4.data<double>()[0] = 0.1;
...@@ -58,7 +58,7 @@ TEST(LodTensor, PrintLodTensor) { ...@@ -58,7 +58,7 @@ TEST(LodTensor, PrintLodTensor) {
PrintLodTensor(&tensor4, 0, 2, res); PrintLodTensor(&tensor4, 0, 2, res);
// ASSERT_EQ(res, "0.1,0.2"); // ASSERT_EQ(res, "0.1,0.2");
LoDTensor tensor5; phi::DenseTensor tensor5;
tensor5.Resize({2}); tensor5.Resize({2});
tensor5.mutable_data<int64_t>(platform::CPUPlace()); tensor5.mutable_data<int64_t>(platform::CPUPlace());
tensor5.data<int64_t>()[0] = 1; tensor5.data<int64_t>()[0] = 1;
...@@ -70,7 +70,7 @@ TEST(LodTensor, PrintLodTensor) { ...@@ -70,7 +70,7 @@ TEST(LodTensor, PrintLodTensor) {
PrintLodTensor(&tensor5, 0, 2, res); PrintLodTensor(&tensor5, 0, 2, res);
ASSERT_EQ(res, "1,2"); ASSERT_EQ(res, "1,2");
LoDTensor tensor6; phi::DenseTensor tensor6;
tensor6.Resize({2}); tensor6.Resize({2});
tensor6.mutable_data<float>(platform::CPUPlace()); tensor6.mutable_data<float>(platform::CPUPlace());
tensor6.data<float>()[0] = 0.2; tensor6.data<float>()[0] = 0.2;
...@@ -85,7 +85,7 @@ TEST(LodTensor, PrintLodTensor) { ...@@ -85,7 +85,7 @@ TEST(LodTensor, PrintLodTensor) {
TEST(LodTensor, GetTensorBound) { TEST(LodTensor, GetTensorBound) {
LoD lod{{0, 2}}; LoD lod{{0, 2}};
LoDTensor tensor; phi::DenseTensor tensor;
tensor.set_lod(lod); tensor.set_lod(lod);
tensor.Resize({2, 1}); tensor.Resize({2, 1});
tensor.mutable_data<float>(platform::CPUPlace()); tensor.mutable_data<float>(platform::CPUPlace());
...@@ -98,7 +98,7 @@ TEST(LodTensor, GetTensorBound) { ...@@ -98,7 +98,7 @@ TEST(LodTensor, GetTensorBound) {
TEST(LodTensor, CheckValidOutput) { TEST(LodTensor, CheckValidOutput) {
LoD lod{{0, 1, 2}}; LoD lod{{0, 1, 2}};
LoDTensor tensor; phi::DenseTensor tensor;
tensor.set_lod(lod); tensor.set_lod(lod);
tensor.Resize({2, 1}); tensor.Resize({2, 1});
tensor.mutable_data<float>(platform::CPUPlace()); tensor.mutable_data<float>(platform::CPUPlace());
......
...@@ -154,12 +154,13 @@ void DistMultiTrainer::Finalize() { ...@@ -154,12 +154,13 @@ void DistMultiTrainer::Finalize() {
if (root_var == nullptr) { if (root_var == nullptr) {
continue; continue;
} }
LoDTensor *root_tensor = root_var->GetMutable<LoDTensor>(); phi::DenseTensor *root_tensor = root_var->GetMutable<phi::DenseTensor>();
for (int j = 1; j < thread_num_; j++) { for (int j = 1; j < thread_num_; j++) {
Scope *cur_thread_scope = workers_[j]->GetThreadScope(); Scope *cur_thread_scope = workers_[j]->GetThreadScope();
Variable *thread_var = Variable *thread_var =
cur_thread_scope->FindVar(need_merge_var_names_[i]); cur_thread_scope->FindVar(need_merge_var_names_[i]);
LoDTensor *thread_tensor = thread_var->GetMutable<LoDTensor>(); phi::DenseTensor *thread_tensor =
thread_var->GetMutable<phi::DenseTensor>();
if (root_tensor->numel() != thread_tensor->numel()) { if (root_tensor->numel() != thread_tensor->numel()) {
continue; continue;
} }
...@@ -197,8 +198,8 @@ void DistMultiTrainer::Finalize() { ...@@ -197,8 +198,8 @@ void DistMultiTrainer::Finalize() {
} }
template <typename T> template <typename T>
void DistMultiTrainer::MergeToRootScope(LoDTensor *root_tensor, void DistMultiTrainer::MergeToRootScope(phi::DenseTensor *root_tensor,
LoDTensor *tensor) { phi::DenseTensor *tensor) {
T *root_data = root_tensor->data<T>(); T *root_data = root_tensor->data<T>();
T *data = tensor->data<T>(); T *data = tensor->data<T>();
for (int i = 0; i < tensor->numel(); i++) { for (int i = 0; i < tensor->numel(); i++) {
......
...@@ -204,14 +204,14 @@ void DownpourLiteWorker::CopyDenseVars() { ...@@ -204,14 +204,14 @@ void DownpourLiteWorker::CopyDenseVars() {
<< dest_var_name; << dest_var_name;
Variable* src_var = thread_scope_->FindVar(src_var_name); Variable* src_var = thread_scope_->FindVar(src_var_name);
CHECK(src_var != nullptr) << src_var_name << " not found"; // NOLINT CHECK(src_var != nullptr) << src_var_name << " not found"; // NOLINT
LoDTensor* src_tensor = src_var->GetMutable<LoDTensor>(); phi::DenseTensor* src_tensor = src_var->GetMutable<phi::DenseTensor>();
CHECK(src_tensor != nullptr) CHECK(src_tensor != nullptr)
<< src_var_name << " tensor is null"; // NOLINT << src_var_name << " tensor is null"; // NOLINT
float* src_data = src_tensor->data<float>(); float* src_data = src_tensor->data<float>();
Variable* dest_var = thread_scope_->FindVar(dest_var_name); Variable* dest_var = thread_scope_->FindVar(dest_var_name);
CHECK(dest_var != nullptr) << dest_var_name << " not found"; // NOLINT CHECK(dest_var != nullptr) << dest_var_name << " not found"; // NOLINT
LoDTensor* dest_tensor = dest_var->GetMutable<LoDTensor>(); phi::DenseTensor* dest_tensor = dest_var->GetMutable<phi::DenseTensor>();
CHECK(dest_tensor != nullptr) CHECK(dest_tensor != nullptr)
<< dest_var_name << " tensor is null"; // NOLINT << dest_var_name << " tensor is null"; // NOLINT
float* dest_data = dest_tensor->data<float>(); float* dest_data = dest_tensor->data<float>();
...@@ -307,7 +307,7 @@ void DownpourLiteWorker::TrainFilesWithProfiler() { ...@@ -307,7 +307,7 @@ void DownpourLiteWorker::TrainFilesWithProfiler() {
if (var == nullptr) { if (var == nullptr) {
continue; continue;
} }
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
if (tensor == nullptr) { if (tensor == nullptr) {
continue; continue;
} }
...@@ -490,7 +490,7 @@ void DownpourLiteWorker::TrainFiles() { ...@@ -490,7 +490,7 @@ void DownpourLiteWorker::TrainFiles() {
phi::DenseTensor* tensor = nullptr; phi::DenseTensor* tensor = nullptr;
int64_t len = 0; int64_t len = 0;
if (var->IsType<phi::DenseTensor>()) { if (var->IsType<phi::DenseTensor>()) {
tensor = var->GetMutable<LoDTensor>(); tensor = var->GetMutable<phi::DenseTensor>();
len = tensor->numel(); len = tensor->numel();
} else if (var->IsType<phi::SelectedRows>()) { } else if (var->IsType<phi::SelectedRows>()) {
auto selected_rows = var->GetMutable<phi::SelectedRows>(); auto selected_rows = var->GetMutable<phi::SelectedRows>();
...@@ -527,7 +527,7 @@ void DownpourLiteWorker::TrainFiles() { ...@@ -527,7 +527,7 @@ void DownpourLiteWorker::TrainFiles() {
if (var == nullptr) { if (var == nullptr) {
continue; continue;
} }
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
if (tensor == nullptr) { if (tensor == nullptr) {
continue; continue;
} }
......
...@@ -144,7 +144,7 @@ void DownpourWorker::CollectLabelInfo(size_t table_idx) { ...@@ -144,7 +144,7 @@ void DownpourWorker::CollectLabelInfo(size_t table_idx) {
auto& feature_label = feature_labels_[table_id]; auto& feature_label = feature_labels_[table_id];
feature_label.resize(feature.size()); feature_label.resize(feature.size());
Variable* var = thread_scope_->FindVar(label_var_name_[table_id]); Variable* var = thread_scope_->FindVar(label_var_name_[table_id]);
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
int64_t* label_ptr = tensor->data<int64_t>(); int64_t* label_ptr = tensor->data<int64_t>();
size_t global_index = 0; size_t global_index = 0;
...@@ -155,7 +155,7 @@ void DownpourWorker::CollectLabelInfo(size_t table_idx) { ...@@ -155,7 +155,7 @@ void DownpourWorker::CollectLabelInfo(size_t table_idx) {
if (fea_var == nullptr) { if (fea_var == nullptr) {
continue; continue;
} }
LoDTensor* tensor = fea_var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = fea_var->GetMutable<phi::DenseTensor>();
CHECK(tensor != nullptr) CHECK(tensor != nullptr)
<< "tensor of var " << sparse_key_names_[table_id][i] << " is null"; << "tensor of var " << sparse_key_names_[table_id][i] << " is null";
...@@ -207,7 +207,7 @@ void DownpourWorker::FillSparseValue(size_t table_idx) { ...@@ -207,7 +207,7 @@ void DownpourWorker::FillSparseValue(size_t table_idx) {
if (var == nullptr) { if (var == nullptr) {
continue; continue;
} }
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
CHECK(tensor != nullptr) << "tensor of var " << slot_name << " is null"; CHECK(tensor != nullptr) << "tensor of var " << slot_name << " is null";
int64_t* ids = tensor->data<int64_t>(); int64_t* ids = tensor->data<int64_t>();
int len = tensor->numel(); int len = tensor->numel();
...@@ -215,7 +215,7 @@ void DownpourWorker::FillSparseValue(size_t table_idx) { ...@@ -215,7 +215,7 @@ void DownpourWorker::FillSparseValue(size_t table_idx) {
if (var_emb == nullptr) { if (var_emb == nullptr) {
continue; continue;
} }
LoDTensor* tensor_emb = var_emb->GetMutable<LoDTensor>(); phi::DenseTensor* tensor_emb = var_emb->GetMutable<phi::DenseTensor>();
float* ptr = tensor_emb->mutable_data<float>({len, table.emb_dim()}, float* ptr = tensor_emb->mutable_data<float>({len, table.emb_dim()},
platform::CPUPlace()); platform::CPUPlace());
memset(ptr, 0, sizeof(float) * len * table.emb_dim()); memset(ptr, 0, sizeof(float) * len * table.emb_dim());
...@@ -290,7 +290,7 @@ void DownpourWorker::AdjustInsWeight() { ...@@ -290,7 +290,7 @@ void DownpourWorker::AdjustInsWeight() {
<< " is nullptr, skip adjust ins weight"; << " is nullptr, skip adjust ins weight";
return; return;
} }
LoDTensor* nid_tensor = nid_var->GetMutable<LoDTensor>(); phi::DenseTensor* nid_tensor = nid_var->GetMutable<phi::DenseTensor>();
if (nid_tensor == nullptr) { if (nid_tensor == nullptr) {
VLOG(0) << "tensor of nid slot var " << adjust_ins_weight_config_.nid_slot() VLOG(0) << "tensor of nid slot var " << adjust_ins_weight_config_.nid_slot()
<< " is nullptr, skip adjust ins weight"; << " is nullptr, skip adjust ins weight";
...@@ -303,7 +303,8 @@ void DownpourWorker::AdjustInsWeight() { ...@@ -303,7 +303,8 @@ void DownpourWorker::AdjustInsWeight() {
<< " is nullptr, skip adjust ins weight"; << " is nullptr, skip adjust ins weight";
return; return;
} }
LoDTensor* ins_weight_tensor = ins_weight_var->GetMutable<LoDTensor>(); phi::DenseTensor* ins_weight_tensor =
ins_weight_var->GetMutable<phi::DenseTensor>();
if (ins_weight_tensor == nullptr) { if (ins_weight_tensor == nullptr) {
VLOG(0) << "tensor of ins weight tensor " VLOG(0) << "tensor of ins weight tensor "
<< adjust_ins_weight_config_.ins_weight_slot() << adjust_ins_weight_config_.ins_weight_slot()
...@@ -428,14 +429,14 @@ void DownpourWorker::CopyDenseVars() { ...@@ -428,14 +429,14 @@ void DownpourWorker::CopyDenseVars() {
<< dest_var_name; << dest_var_name;
Variable* src_var = thread_scope_->FindVar(src_var_name); Variable* src_var = thread_scope_->FindVar(src_var_name);
CHECK(src_var != nullptr) << src_var_name << " not found"; // NOLINT CHECK(src_var != nullptr) << src_var_name << " not found"; // NOLINT
LoDTensor* src_tensor = src_var->GetMutable<LoDTensor>(); phi::DenseTensor* src_tensor = src_var->GetMutable<phi::DenseTensor>();
CHECK(src_tensor != nullptr) CHECK(src_tensor != nullptr)
<< src_var_name << " tensor is null"; // NOLINT << src_var_name << " tensor is null"; // NOLINT
float* src_data = src_tensor->data<float>(); float* src_data = src_tensor->data<float>();
Variable* dest_var = thread_scope_->FindVar(dest_var_name); Variable* dest_var = thread_scope_->FindVar(dest_var_name);
CHECK(dest_var != nullptr) << dest_var_name << " not found"; // NOLINT CHECK(dest_var != nullptr) << dest_var_name << " not found"; // NOLINT
LoDTensor* dest_tensor = dest_var->GetMutable<LoDTensor>(); phi::DenseTensor* dest_tensor = dest_var->GetMutable<phi::DenseTensor>();
CHECK(dest_tensor != nullptr) CHECK(dest_tensor != nullptr)
<< dest_var_name << " tensor is null"; // NOLINT << dest_var_name << " tensor is null"; // NOLINT
float* dest_data = dest_tensor->data<float>(); float* dest_data = dest_tensor->data<float>();
...@@ -577,7 +578,7 @@ void DownpourWorker::TrainFilesWithProfiler() { ...@@ -577,7 +578,7 @@ void DownpourWorker::TrainFilesWithProfiler() {
if (var == nullptr) { if (var == nullptr) {
continue; continue;
} }
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
if (tensor == nullptr) { if (tensor == nullptr) {
continue; continue;
} }
...@@ -875,7 +876,7 @@ void DownpourWorker::TrainFiles() { ...@@ -875,7 +876,7 @@ void DownpourWorker::TrainFiles() {
phi::DenseTensor* tensor = nullptr; phi::DenseTensor* tensor = nullptr;
int64_t len = 0; int64_t len = 0;
if (var->IsType<phi::DenseTensor>()) { if (var->IsType<phi::DenseTensor>()) {
tensor = var->GetMutable<LoDTensor>(); tensor = var->GetMutable<phi::DenseTensor>();
len = tensor->numel(); len = tensor->numel();
} else if (var->IsType<phi::SelectedRows>()) { } else if (var->IsType<phi::SelectedRows>()) {
auto selected_rows = var->GetMutable<phi::SelectedRows>(); auto selected_rows = var->GetMutable<phi::SelectedRows>();
...@@ -912,7 +913,7 @@ void DownpourWorker::TrainFiles() { ...@@ -912,7 +913,7 @@ void DownpourWorker::TrainFiles() {
if (var == nullptr) { if (var == nullptr) {
continue; continue;
} }
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
if (tensor == nullptr) { if (tensor == nullptr) {
continue; continue;
} }
...@@ -973,7 +974,7 @@ void DownpourWorker::TrainFiles() { ...@@ -973,7 +974,7 @@ void DownpourWorker::TrainFiles() {
if (need_to_push_dense_) { if (need_to_push_dense_) {
if (flag_partial_push_) { if (flag_partial_push_) {
Variable* var = (*thread_scope_).FindVar("cond_tag"); Variable* var = (*thread_scope_).FindVar("cond_tag");
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
// check type in python code // check type in python code
int64_t* cond_value_batch = tensor->data<int64_t>(); int64_t* cond_value_batch = tensor->data<int64_t>();
......
...@@ -433,7 +433,7 @@ void DownpourWorkerOpt::TrainFiles() { ...@@ -433,7 +433,7 @@ void DownpourWorkerOpt::TrainFiles() {
if (var == nullptr) { if (var == nullptr) {
continue; continue;
} }
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
if (tensor == nullptr) { if (tensor == nullptr) {
continue; continue;
} }
......
...@@ -205,7 +205,7 @@ void Executor::Run(const ProgramDesc& pdesc, ...@@ -205,7 +205,7 @@ void Executor::Run(const ProgramDesc& pdesc,
// Return true if the block has feed operators and holder of matching info. // Return true if the block has feed operators and holder of matching info.
static bool has_feed_operators( static bool has_feed_operators(
const BlockDesc& block, const BlockDesc& block,
const std::map<std::string, const LoDTensor*>& feed_targets, const std::map<std::string, const phi::DenseTensor*>& feed_targets,
const std::string& feed_holder_name) { const std::string& feed_holder_name) {
size_t feed_count = 0; size_t feed_count = 0;
for (auto* op : block.AllOps()) { for (auto* op : block.AllOps()) {
...@@ -324,7 +324,7 @@ static bool has_fetch_operators( ...@@ -324,7 +324,7 @@ static bool has_fetch_operators(
void Executor::Run(const ProgramDesc& program, void Executor::Run(const ProgramDesc& program,
Scope* scope, Scope* scope,
std::map<std::string, const LoDTensor*>* feed_targets, std::map<std::string, const phi::DenseTensor*>* feed_targets,
std::map<std::string, FetchType*>* fetch_targets, std::map<std::string, FetchType*>* fetch_targets,
bool create_local_scope, bool create_local_scope,
bool create_vars, bool create_vars,
...@@ -623,7 +623,7 @@ void Executor::RunPreparedContext(ExecutorPrepareContext* ctx, ...@@ -623,7 +623,7 @@ void Executor::RunPreparedContext(ExecutorPrepareContext* ctx,
void Executor::RunPreparedContext( void Executor::RunPreparedContext(
ExecutorPrepareContext* ctx, ExecutorPrepareContext* ctx,
Scope* scope, Scope* scope,
std::map<std::string, const LoDTensor*>* feed_targets, std::map<std::string, const phi::DenseTensor*>* feed_targets,
std::map<std::string, FetchType*>* fetch_targets, std::map<std::string, FetchType*>* fetch_targets,
bool create_local_scope, bool create_local_scope,
bool create_vars, bool create_vars,
......
...@@ -95,7 +95,7 @@ class Executor { ...@@ -95,7 +95,7 @@ class Executor {
// This API is very slow. // This API is very slow.
void Run(const ProgramDesc& program, void Run(const ProgramDesc& program,
Scope* scope, Scope* scope,
std::map<std::string, const LoDTensor*>* feed_targets, std::map<std::string, const phi::DenseTensor*>* feed_targets,
std::map<std::string, FetchType*>* fetch_targets, std::map<std::string, FetchType*>* fetch_targets,
bool create_local_scope = true, bool create_local_scope = true,
bool create_vars = true, bool create_vars = true,
...@@ -103,14 +103,15 @@ class Executor { ...@@ -103,14 +103,15 @@ class Executor {
const std::string& fetch_holder_name = "fetch"); const std::string& fetch_holder_name = "fetch");
// This API is very slow. // This API is very slow.
void RunPreparedContext(ExecutorPrepareContext* ctx, void RunPreparedContext(
Scope* scope, ExecutorPrepareContext* ctx,
std::map<std::string, const LoDTensor*>* feed_targets, Scope* scope,
std::map<std::string, FetchType*>* fetch_targets, std::map<std::string, const phi::DenseTensor*>* feed_targets,
bool create_local_scope = true, std::map<std::string, FetchType*>* fetch_targets,
bool create_vars = true, bool create_local_scope = true,
const std::string& feed_holder_name = "feed", bool create_vars = true,
const std::string& fetch_holder_name = "fetch"); const std::string& feed_holder_name = "feed",
const std::string& fetch_holder_name = "fetch");
static std::unique_ptr<ExecutorPrepareContext> Prepare( static std::unique_ptr<ExecutorPrepareContext> Prepare(
const ProgramDesc& program, const ProgramDesc& program,
......
...@@ -146,8 +146,9 @@ void DeleteUnusedTensors(const Scope &scope, ...@@ -146,8 +146,9 @@ void DeleteUnusedTensors(const Scope &scope,
} }
VLOG(2) << "Erase variable " << var_name; VLOG(2) << "Erase variable " << var_name;
if (var->IsType<LoDTensor>()) { if (var->IsType<phi::DenseTensor>()) {
garbages.emplace_back(var->GetMutable<LoDTensor>()->MoveMemoryHolder()); garbages.emplace_back(
var->GetMutable<phi::DenseTensor>()->MoveMemoryHolder());
} else if (var->IsType<phi::SelectedRows>()) { } else if (var->IsType<phi::SelectedRows>()) {
garbages.emplace_back(var->GetMutable<phi::SelectedRows>() garbages.emplace_back(var->GetMutable<phi::SelectedRows>()
->mutable_value() ->mutable_value()
......
...@@ -90,7 +90,7 @@ std::future<int32_t> DensePullThread::pull_dense(uint64_t table_id) { ...@@ -90,7 +90,7 @@ std::future<int32_t> DensePullThread::pull_dense(uint64_t table_id) {
for (auto i = 0u; i < variables.size(); ++i) { for (auto i = 0u; i < variables.size(); ++i) {
auto& t = variables[i]; auto& t = variables[i];
Variable* var = _root_scope->FindVar(t); Variable* var = _root_scope->FindVar(t);
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
float* w = tensor->data<float>(); float* w = tensor->data<float>();
paddle::ps::Region reg(w, tensor->numel()); paddle::ps::Region reg(w, tensor->numel());
...@@ -219,7 +219,8 @@ void ExecutorThreadWorker::SetDevice() { ...@@ -219,7 +219,8 @@ void ExecutorThreadWorker::SetDevice() {
} }
template <typename T> template <typename T>
void print_lod_tensor(std::string var_name, const LoDTensor& lod_tensor) { void print_lod_tensor(std::string var_name,
const phi::DenseTensor& lod_tensor) {
auto inspect = lod_tensor.data<T>(); auto inspect = lod_tensor.data<T>();
auto element_num = lod_tensor.numel(); auto element_num = lod_tensor.numel();
...@@ -235,7 +236,7 @@ void print_lod_tensor(std::string var_name, const LoDTensor& lod_tensor) { ...@@ -235,7 +236,7 @@ void print_lod_tensor(std::string var_name, const LoDTensor& lod_tensor) {
} }
static void print_fetch_var(Scope* scope, const std::string& var_name) { static void print_fetch_var(Scope* scope, const std::string& var_name) {
auto& tensor = scope->FindVar(var_name)->Get<LoDTensor>(); auto& tensor = scope->FindVar(var_name)->Get<phi::DenseTensor>();
#define PrintLoDTensorCallback(cpp_type, proto_type) \ #define PrintLoDTensorCallback(cpp_type, proto_type) \
do { \ do { \
...@@ -478,7 +479,7 @@ void AsyncExecutorThreadWorker::PushDense(int table_id) { ...@@ -478,7 +479,7 @@ void AsyncExecutorThreadWorker::PushDense(int table_id) {
for (auto& t : _param_config->dense_gradient_variable_name[table_id]) { for (auto& t : _param_config->dense_gradient_variable_name[table_id]) {
Variable* var = thread_scope_->FindVar(t); Variable* var = thread_scope_->FindVar(t);
CHECK(var != nullptr) << "var[" << t << "] not found"; CHECK(var != nullptr) << "var[" << t << "] not found";
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
int count = tensor->numel(); int count = tensor->numel();
float* g = tensor->data<float>(); float* g = tensor->data<float>();
paddle::ps::Region reg(g, count); paddle::ps::Region reg(g, count);
...@@ -502,7 +503,7 @@ void AsyncExecutorThreadWorker::PullSparse(int table_id) { ...@@ -502,7 +503,7 @@ void AsyncExecutorThreadWorker::PullSparse(int table_id) {
// slot_idx = 0 is label TODO // slot_idx = 0 is label TODO
for (auto slot_idx = 1u; slot_idx < feed_vec.size(); ++slot_idx) { for (auto slot_idx = 1u; slot_idx < feed_vec.size(); ++slot_idx) {
Variable* var = thread_scope_->FindVar(feed_vec[slot_idx]); Variable* var = thread_scope_->FindVar(feed_vec[slot_idx]);
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
int64_t* ids = tensor->data<int64_t>(); int64_t* ids = tensor->data<int64_t>();
int len = tensor->numel(); int len = tensor->numel();
for (auto i = 0u; i < len; ++i) { for (auto i = 0u; i < len; ++i) {
...@@ -546,12 +547,12 @@ void AsyncExecutorThreadWorker::FillSparse(int table_id) { ...@@ -546,12 +547,12 @@ void AsyncExecutorThreadWorker::FillSparse(int table_id) {
// slot_idx = 0 is label TODO // slot_idx = 0 is label TODO
for (auto slot_idx = 1u; slot_idx < feed_vec.size(); ++slot_idx) { for (auto slot_idx = 1u; slot_idx < feed_vec.size(); ++slot_idx) {
Variable* var = thread_scope_->FindVar(feed_vec[slot_idx]); Variable* var = thread_scope_->FindVar(feed_vec[slot_idx]);
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
int64_t* ids = tensor->data<int64_t>(); int64_t* ids = tensor->data<int64_t>();
int len = tensor->numel(); int len = tensor->numel();
Variable* var_emb = thread_scope_->FindVar( Variable* var_emb = thread_scope_->FindVar(
_param_config->slot_input_vec[table_id][slot_idx - 1]); _param_config->slot_input_vec[table_id][slot_idx - 1]);
LoDTensor* tensor_emb = var_emb->GetMutable<LoDTensor>(); phi::DenseTensor* tensor_emb = var_emb->GetMutable<phi::DenseTensor>();
float* ptr = float* ptr =
tensor_emb->mutable_data<float>({len, slot_dim}, platform::CPUPlace()); tensor_emb->mutable_data<float>({len, slot_dim}, platform::CPUPlace());
memset(ptr, 0, sizeof(float) * len * slot_dim); memset(ptr, 0, sizeof(float) * len * slot_dim);
...@@ -603,7 +604,7 @@ void AsyncExecutorThreadWorker::PushSparse(int table_id) { ...@@ -603,7 +604,7 @@ void AsyncExecutorThreadWorker::PushSparse(int table_id) {
CHECK(g_var != nullptr) CHECK(g_var != nullptr)
<< "var[" << _param_config->gradient_var[table_id][slot_idx - 1] << "var[" << _param_config->gradient_var[table_id][slot_idx - 1]
<< "] not found"; << "] not found";
LoDTensor* g_tensor = g_var->GetMutable<LoDTensor>(); phi::DenseTensor* g_tensor = g_var->GetMutable<phi::DenseTensor>();
if (g_tensor == NULL) { if (g_tensor == NULL) {
LOG(ERROR) << "var[" LOG(ERROR) << "var["
<< _param_config->gradient_var[table_id][slot_idx - 1] << _param_config->gradient_var[table_id][slot_idx - 1]
...@@ -614,7 +615,7 @@ void AsyncExecutorThreadWorker::PushSparse(int table_id) { ...@@ -614,7 +615,7 @@ void AsyncExecutorThreadWorker::PushSparse(int table_id) {
Variable* var = thread_scope_->FindVar(feed_vec[slot_idx]); Variable* var = thread_scope_->FindVar(feed_vec[slot_idx]);
CHECK(var != nullptr) << "var[" << feed_vec[slot_idx] << "] not found"; CHECK(var != nullptr) << "var[" << feed_vec[slot_idx] << "] not found";
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
if (tensor == NULL) { if (tensor == NULL) {
LOG(ERROR) << "var[" << feed_vec[slot_idx] << "] not found"; LOG(ERROR) << "var[" << feed_vec[slot_idx] << "] not found";
exit(-1); exit(-1);
...@@ -661,13 +662,13 @@ void AsyncExecutorThreadWorker::collect_feasign_info(int table_id) { ...@@ -661,13 +662,13 @@ void AsyncExecutorThreadWorker::collect_feasign_info(int table_id) {
fea_info.resize(feature.size()); fea_info.resize(feature.size());
const std::vector<std::string>& feed_vec = thread_reader_->GetUseSlotAlias(); const std::vector<std::string>& feed_vec = thread_reader_->GetUseSlotAlias();
Variable* var = thread_scope_->FindVar(feed_vec[0]); Variable* var = thread_scope_->FindVar(feed_vec[0]);
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
int64_t* label = tensor->data<int64_t>(); int64_t* label = tensor->data<int64_t>();
int global_index = 0; int global_index = 0;
for (auto slot_idx = 1u; slot_idx < feed_vec.size(); ++slot_idx) { for (auto slot_idx = 1u; slot_idx < feed_vec.size(); ++slot_idx) {
Variable* var = thread_scope_->FindVar(feed_vec[slot_idx]); Variable* var = thread_scope_->FindVar(feed_vec[slot_idx]);
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
int64_t* ids = tensor->data<int64_t>(); int64_t* ids = tensor->data<int64_t>();
int fea_idx = 0; int fea_idx = 0;
......
...@@ -28,7 +28,7 @@ namespace framework { ...@@ -28,7 +28,7 @@ namespace framework {
class Variable; class Variable;
void SetFeedVariable(Scope* scope, void SetFeedVariable(Scope* scope,
const LoDTensor& input, const phi::DenseTensor& input,
const std::string& var_name, const std::string& var_name,
size_t index) { size_t index) {
// If var_name Variable is not found in GlobalScope, a new variable will // If var_name Variable is not found in GlobalScope, a new variable will
...@@ -40,7 +40,7 @@ void SetFeedVariable(Scope* scope, ...@@ -40,7 +40,7 @@ void SetFeedVariable(Scope* scope,
feed_inputs.resize(index + 1); feed_inputs.resize(index + 1);
} }
// shared data with input tensor // shared data with input tensor
auto& val = PADDLE_GET(LoDTensor, feed_inputs[index]); auto& val = PADDLE_GET(phi::DenseTensor, feed_inputs[index]);
val.ShareDataWith(input); val.ShareDataWith(input);
// set lod // set lod
val.set_lod(input.lod()); val.set_lod(input.lod());
...@@ -86,16 +86,17 @@ FetchType& GetFetchVariable(const Scope& scope, ...@@ -86,16 +86,17 @@ FetchType& GetFetchVariable(const Scope& scope,
return tensor; return tensor;
} }
LoDTensor& GetVariableTensor(const Scope& scope, const std::string& var_name) { phi::DenseTensor& GetVariableTensor(const Scope& scope,
const std::string& var_name) {
Variable* var = scope.FindVar(var_name); Variable* var = scope.FindVar(var_name);
PADDLE_ENFORCE_NOT_NULL(var, PADDLE_ENFORCE_NOT_NULL(var,
platform::errors::NotFound( platform::errors::NotFound(
"Variable %s is not found in scope.", var_name)); "Variable %s is not found in scope.", var_name));
PADDLE_ENFORCE_EQ(var->IsType<LoDTensor>(), PADDLE_ENFORCE_EQ(var->IsType<phi::DenseTensor>(),
true, true,
platform::errors::InvalidArgument( platform::errors::InvalidArgument(
"Only support lod tensor in GetVariableTensor now.")); "Only support lod tensor in GetVariableTensor now."));
return *var->GetMutable<LoDTensor>(); return *var->GetMutable<phi::DenseTensor>();
} }
} // namespace framework } // namespace framework
......
...@@ -30,7 +30,7 @@ namespace framework { ...@@ -30,7 +30,7 @@ namespace framework {
class Scope; class Scope;
void SetFeedVariable(Scope* scope, void SetFeedVariable(Scope* scope,
const LoDTensor& input, const phi::DenseTensor& input,
const std::string& var_name, const std::string& var_name,
size_t index); size_t index);
...@@ -43,7 +43,8 @@ FetchType& GetFetchVariable(const Scope& scope, ...@@ -43,7 +43,8 @@ FetchType& GetFetchVariable(const Scope& scope,
const std::string& var_name, const std::string& var_name,
size_t index); size_t index);
LoDTensor& GetVariableTensor(const Scope& scope, const std::string& var_name); phi::DenseTensor& GetVariableTensor(const Scope& scope,
const std::string& var_name);
} // namespace framework } // namespace framework
} // namespace paddle } // namespace paddle
...@@ -22,18 +22,21 @@ limitations under the License. */ ...@@ -22,18 +22,21 @@ limitations under the License. */
namespace paddle { namespace paddle {
namespace framework { namespace framework {
using FeedType = paddle::variant<LoDTensor, Strings, phi::SparseCooTensor>; using FeedType =
paddle::variant<phi::DenseTensor, Strings, phi::SparseCooTensor>;
using FeedList = std::vector<FeedType>; using FeedList = std::vector<FeedType>;
using FetchType = paddle:: using FetchType = paddle::variant<phi::DenseTensor,
variant<LoDTensor, LoDTensorArray, framework::Vocab, phi::SparseCooTensor>; LoDTensorArray,
framework::Vocab,
phi::SparseCooTensor>;
using FetchList = std::vector<FetchType>; using FetchList = std::vector<FetchType>;
using FetchUnmergedList = std::vector<std::vector<FetchType>>; using FetchUnmergedList = std::vector<std::vector<FetchType>>;
using FetchResultType = paddle::variant<FetchList, FetchUnmergedList>; using FetchResultType = paddle::variant<FetchList, FetchUnmergedList>;
inline bool data_is_lod_tensor(const FetchType &data) { inline bool data_is_lod_tensor(const FetchType &data) {
if (data.type() == typeid(LoDTensor)) { if (data.type() == typeid(phi::DenseTensor)) {
return true; return true;
} }
return false; return false;
......
...@@ -589,7 +589,7 @@ class BoxWrapper { ...@@ -589,7 +589,7 @@ class BoxWrapper {
var, var,
platform::errors::NotFound("Error: var %s is not found in scope.", platform::errors::NotFound("Error: var %s is not found in scope.",
varname.c_str())); varname.c_str()));
auto& gpu_tensor = var->Get<LoDTensor>(); auto& gpu_tensor = var->Get<phi::DenseTensor>();
auto* gpu_data = gpu_tensor.data<T>(); auto* gpu_data = gpu_tensor.data<T>();
auto len = gpu_tensor.numel(); auto len = gpu_tensor.numel();
data->resize(len); data->resize(len);
...@@ -925,7 +925,7 @@ class BoxWrapper { ...@@ -925,7 +925,7 @@ class BoxWrapper {
std::map<std::string, MetricMsg*> metric_lists_; std::map<std::string, MetricMsg*> metric_lists_;
std::vector<std::string> metric_name_list_; std::vector<std::string> metric_name_list_;
std::vector<int> slot_vector_; std::vector<int> slot_vector_;
std::vector<LoDTensor> keys_tensor; // Cache for pull_sparse std::vector<phi::DenseTensor> keys_tensor; // Cache for pull_sparse
bool use_afs_api_ = false; bool use_afs_api_ = false;
public: public:
......
...@@ -47,7 +47,7 @@ void BoxWrapper::PullSparseCase(const paddle::platform::Place& place, ...@@ -47,7 +47,7 @@ void BoxWrapper::PullSparseCase(const paddle::platform::Place& place,
#if (defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)) && !defined(_WIN32) #if (defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)) && !defined(_WIN32)
VLOG(3) << "Begin copy keys, key_num[" << total_length << "]"; VLOG(3) << "Begin copy keys, key_num[" << total_length << "]";
int device_id = place.GetDeviceId(); int device_id = place.GetDeviceId();
LoDTensor& total_keys_tensor = keys_tensor[device_id]; phi::DenseTensor& total_keys_tensor = keys_tensor[device_id];
uint64_t* total_keys = reinterpret_cast<uint64_t*>( uint64_t* total_keys = reinterpret_cast<uint64_t*>(
total_keys_tensor.mutable_data<int64_t>({total_length, 1}, place)); total_keys_tensor.mutable_data<int64_t>({total_length, 1}, place));
...@@ -155,7 +155,7 @@ void BoxWrapper::PushSparseGradCase( ...@@ -155,7 +155,7 @@ void BoxWrapper::PushSparseGradCase(
} else if (platform::is_gpu_place(place)) { } else if (platform::is_gpu_place(place)) {
#if (defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)) && !defined(_WIN32) #if (defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)) && !defined(_WIN32)
int device_id = place.GetDeviceId(); int device_id = place.GetDeviceId();
LoDTensor& cached_total_keys_tensor = keys_tensor[device_id]; phi::DenseTensor& cached_total_keys_tensor = keys_tensor[device_id];
uint64_t* total_keys = uint64_t* total_keys =
reinterpret_cast<uint64_t*>(cached_total_keys_tensor.data<int64_t>()); reinterpret_cast<uint64_t*>(cached_total_keys_tensor.data<int64_t>());
VLOG(3) << "Begin copy grad tensor to boxps struct"; VLOG(3) << "Begin copy grad tensor to boxps struct";
......
...@@ -172,7 +172,7 @@ void FleetWrapper::HeterPullSparseVars( ...@@ -172,7 +172,7 @@ void FleetWrapper::HeterPullSparseVars(
if (var == nullptr) { if (var == nullptr) {
continue; continue;
} }
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
CHECK(tensor != nullptr) << "tensor of var " << name << " is null"; CHECK(tensor != nullptr) << "tensor of var " << name << " is null";
int64_t* ids = tensor->data<int64_t>(); int64_t* ids = tensor->data<int64_t>();
size_t len = tensor->numel(); size_t len = tensor->numel();
...@@ -269,7 +269,7 @@ void FleetWrapper::HeterPushSparseVars( ...@@ -269,7 +269,7 @@ void FleetWrapper::HeterPushSparseVars(
if (var == nullptr) { if (var == nullptr) {
continue; continue;
} }
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
if (tensor == nullptr) { if (tensor == nullptr) {
LOG(ERROR) << "tensor of var[" << sparse_key_names[i] << "] is null"; LOG(ERROR) << "tensor of var[" << sparse_key_names[i] << "] is null";
exit(-1); exit(-1);
...@@ -284,7 +284,7 @@ void FleetWrapper::HeterPushSparseVars( ...@@ -284,7 +284,7 @@ void FleetWrapper::HeterPushSparseVars(
if (g_var == nullptr) { if (g_var == nullptr) {
continue; continue;
} }
LoDTensor* g_tensor = g_var->GetMutable<LoDTensor>(); phi::DenseTensor* g_tensor = g_var->GetMutable<phi::DenseTensor>();
if (g_tensor == nullptr) { if (g_tensor == nullptr) {
LOG(ERROR) << "tensor of var[" << sparse_key_names[i] << "] is null"; LOG(ERROR) << "tensor of var[" << sparse_key_names[i] << "] is null";
exit(-1); exit(-1);
...@@ -334,7 +334,7 @@ void FleetWrapper::HeterPushSparseVars( ...@@ -334,7 +334,7 @@ void FleetWrapper::HeterPushSparseVars(
if (var == nullptr) { if (var == nullptr) {
continue; continue;
} }
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
if (tensor == nullptr) { if (tensor == nullptr) {
LOG(ERROR) << "tensor of var[" << sparse_key_names[i] << "] is null"; LOG(ERROR) << "tensor of var[" << sparse_key_names[i] << "] is null";
exit(-1); exit(-1);
...@@ -444,7 +444,7 @@ void FleetWrapper::PullSparseVarsFromLocal( ...@@ -444,7 +444,7 @@ void FleetWrapper::PullSparseVarsFromLocal(
if (var == nullptr) { if (var == nullptr) {
continue; continue;
} }
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
CHECK(tensor != nullptr) << "tensor of var " << name << " is null"; CHECK(tensor != nullptr) << "tensor of var " << name << " is null";
int64_t* ids = tensor->data<int64_t>(); int64_t* ids = tensor->data<int64_t>();
size_t len = tensor->numel(); size_t len = tensor->numel();
...@@ -508,7 +508,7 @@ std::future<int32_t> FleetWrapper::PullSparseVarsAsync( ...@@ -508,7 +508,7 @@ std::future<int32_t> FleetWrapper::PullSparseVarsAsync(
if (var == nullptr) { if (var == nullptr) {
continue; continue;
} }
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
CHECK(tensor != nullptr) << "tensor of var " << name << " is null"; CHECK(tensor != nullptr) << "tensor of var " << name << " is null";
int64_t* ids = tensor->data<int64_t>(); int64_t* ids = tensor->data<int64_t>();
size_t len = tensor->numel(); size_t len = tensor->numel();
...@@ -553,7 +553,7 @@ void FleetWrapper::PullSparseVarsSync( ...@@ -553,7 +553,7 @@ void FleetWrapper::PullSparseVarsSync(
if (var == nullptr) { if (var == nullptr) {
continue; continue;
} }
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
CHECK(tensor != nullptr) << "tensor of var " << name << " is null"; CHECK(tensor != nullptr) << "tensor of var " << name << " is null";
int64_t* ids = tensor->data<int64_t>(); int64_t* ids = tensor->data<int64_t>();
size_t len = tensor->numel(); size_t len = tensor->numel();
...@@ -615,12 +615,13 @@ void FleetWrapper::PullSparseVarsSync( ...@@ -615,12 +615,13 @@ void FleetWrapper::PullSparseVarsSync(
#endif #endif
} }
void FleetWrapper::PullSparseToTensorSync(const uint64_t table_id, void FleetWrapper::PullSparseToTensorSync(
int fea_dim, const uint64_t table_id,
uint64_t padding_id, int fea_dim,
platform::Place place, uint64_t padding_id,
std::vector<const LoDTensor*>* inputs, platform::Place place,
std::vector<LoDTensor*>* outputs) { std::vector<const phi::DenseTensor*>* inputs,
std::vector<phi::DenseTensor*>* outputs) {
#ifdef PADDLE_WITH_PSLIB #ifdef PADDLE_WITH_PSLIB
std::vector<uint64_t> fea_keys; std::vector<uint64_t> fea_keys;
std::vector<float*> pull_result_ptr; std::vector<float*> pull_result_ptr;
...@@ -695,7 +696,7 @@ void FleetWrapper::PullDenseVarsAsync( ...@@ -695,7 +696,7 @@ void FleetWrapper::PullDenseVarsAsync(
varname = var_names[i] + "pin"; varname = var_names[i] + "pin";
} }
Variable* var = scope.FindVar(varname); Variable* var = scope.FindVar(varname);
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
float* w = tensor->data<float>(); float* w = tensor->data<float>();
paddle::ps::Region reg(w, tensor->numel()); paddle::ps::Region reg(w, tensor->numel());
regions[i] = std::move(reg); regions[i] = std::move(reg);
...@@ -716,7 +717,7 @@ void FleetWrapper::PullDenseVarsSync( ...@@ -716,7 +717,7 @@ void FleetWrapper::PullDenseVarsSync(
regions.reserve(var_names.size()); regions.reserve(var_names.size());
for (auto& t : var_names) { for (auto& t : var_names) {
Variable* var = scope.FindVar(t); Variable* var = scope.FindVar(t);
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
float* w = tensor->data<float>(); float* w = tensor->data<float>();
paddle::ps::Region reg(w, tensor->numel()); paddle::ps::Region reg(w, tensor->numel());
regions.emplace_back(std::move(reg)); regions.emplace_back(std::move(reg));
...@@ -764,7 +765,7 @@ void FleetWrapper::PushDenseParamSync( ...@@ -764,7 +765,7 @@ void FleetWrapper::PushDenseParamSync(
for (auto& t : var_names) { for (auto& t : var_names) {
Variable* var = scope.FindVar(t); Variable* var = scope.FindVar(t);
CHECK(var != nullptr) << "var[" << t << "] not found"; CHECK(var != nullptr) << "var[" << t << "] not found";
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
float* g = tensor->mutable_data<float>(place); float* g = tensor->mutable_data<float>(place);
paddle::ps::Region reg(g, tensor->numel()); paddle::ps::Region reg(g, tensor->numel());
regions.emplace_back(std::move(reg)); regions.emplace_back(std::move(reg));
...@@ -797,12 +798,12 @@ void FleetWrapper::PushDenseVarsAsync( ...@@ -797,12 +798,12 @@ void FleetWrapper::PushDenseVarsAsync(
std::vector<paddle::ps::Region> regions; std::vector<paddle::ps::Region> regions;
for (auto& t : var_names) { for (auto& t : var_names) {
Variable* var = scope.FindVar(t); Variable* var = scope.FindVar(t);
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
int count = tensor->numel(); int count = tensor->numel();
float* g_data = tensor->data<float>(); float* g_data = tensor->data<float>();
Variable* pin_var = scope.FindVar(t + "pin"); Variable* pin_var = scope.FindVar(t + "pin");
LoDTensor* pin_tensor = pin_var->GetMutable<LoDTensor>(); phi::DenseTensor* pin_tensor = pin_var->GetMutable<phi::DenseTensor>();
float* pin_g = pin_tensor->mutable_data<float>(tensor->dims(), float* pin_g = pin_tensor->mutable_data<float>(tensor->dims(),
platform::CUDAPinnedPlace()); platform::CUDAPinnedPlace());
memory::Copy(platform::CUDAPinnedPlace(), memory::Copy(platform::CUDAPinnedPlace(),
...@@ -859,12 +860,12 @@ void FleetWrapper::PushDenseVarsAsync( ...@@ -859,12 +860,12 @@ void FleetWrapper::PushDenseVarsAsync(
std::vector<paddle::ps::Region> regions; std::vector<paddle::ps::Region> regions;
for (auto& t : var_names) { for (auto& t : var_names) {
Variable* var = scope.FindVar(t); Variable* var = scope.FindVar(t);
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
int count = tensor->numel(); int count = tensor->numel();
float* g_data = tensor->data<float>(); float* g_data = tensor->data<float>();
Variable* pin_var = scope.FindVar(t + "pin"); Variable* pin_var = scope.FindVar(t + "pin");
LoDTensor* pin_tensor = pin_var->GetMutable<LoDTensor>(); phi::DenseTensor* pin_tensor = pin_var->GetMutable<phi::DenseTensor>();
float* pin_g = float* pin_g =
pin_tensor->mutable_data<float>(tensor->dims(), platform::CPUPlace()); pin_tensor->mutable_data<float>(tensor->dims(), platform::CPUPlace());
memory::Copy( memory::Copy(
...@@ -908,7 +909,7 @@ void FleetWrapper::PushDenseVarsAsync( ...@@ -908,7 +909,7 @@ void FleetWrapper::PushDenseVarsAsync(
std::vector<paddle::ps::Region> regions; std::vector<paddle::ps::Region> regions;
for (auto& t : var_names) { for (auto& t : var_names) {
Variable* var = scope.FindVar(t); Variable* var = scope.FindVar(t);
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
int count = tensor->numel(); int count = tensor->numel();
float* g = tensor->data<float>(); float* g = tensor->data<float>();
if (scale_datanorm >= 0) { if (scale_datanorm >= 0) {
...@@ -988,7 +989,7 @@ void FleetWrapper::PushSparseVarsWithLabelAsync( ...@@ -988,7 +989,7 @@ void FleetWrapper::PushSparseVarsWithLabelAsync(
if (var == nullptr) { if (var == nullptr) {
continue; continue;
} }
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
if (tensor == nullptr) { if (tensor == nullptr) {
LOG(ERROR) << "tensor of var[" << sparse_key_names[i] << "] is null"; LOG(ERROR) << "tensor of var[" << sparse_key_names[i] << "] is null";
exit(-1); exit(-1);
...@@ -1015,7 +1016,7 @@ void FleetWrapper::PushSparseVarsWithLabelAsync( ...@@ -1015,7 +1016,7 @@ void FleetWrapper::PushSparseVarsWithLabelAsync(
if (g_var == nullptr) { if (g_var == nullptr) {
continue; continue;
} }
LoDTensor* g_tensor = g_var->GetMutable<LoDTensor>(); phi::DenseTensor* g_tensor = g_var->GetMutable<phi::DenseTensor>();
if (g_tensor == nullptr) { if (g_tensor == nullptr) {
LOG(ERROR) << "tensor of var[" << sparse_key_names[i] << "] is null"; LOG(ERROR) << "tensor of var[" << sparse_key_names[i] << "] is null";
exit(-1); exit(-1);
...@@ -1065,7 +1066,7 @@ void FleetWrapper::PushSparseVarsWithLabelAsync( ...@@ -1065,7 +1066,7 @@ void FleetWrapper::PushSparseVarsWithLabelAsync(
if (var == nullptr) { if (var == nullptr) {
continue; continue;
} }
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
if (tensor == nullptr) { if (tensor == nullptr) {
LOG(ERROR) << "tensor of var[" << sparse_key_names[i] << "] is null"; LOG(ERROR) << "tensor of var[" << sparse_key_names[i] << "] is null";
exit(-1); exit(-1);
...@@ -1109,8 +1110,8 @@ void FleetWrapper::PushSparseFromTensorWithLabelAsync( ...@@ -1109,8 +1110,8 @@ void FleetWrapper::PushSparseFromTensorWithLabelAsync(
const std::string& click_name, const std::string& click_name,
platform::Place place, platform::Place place,
const std::vector<std::string>& input_names, const std::vector<std::string>& input_names,
std::vector<const LoDTensor*>* inputs, std::vector<const phi::DenseTensor*>* inputs,
std::vector<const LoDTensor*>* outputs) { std::vector<const phi::DenseTensor*>* outputs) {
#ifdef PADDLE_WITH_PSLIB #ifdef PADDLE_WITH_PSLIB
int show_index = 0; int show_index = 0;
int click_index = 1; int click_index = 1;
...@@ -1302,12 +1303,12 @@ void FleetWrapper::LoadFromPaddleModel(Scope& scope, ...@@ -1302,12 +1303,12 @@ void FleetWrapper::LoadFromPaddleModel(Scope& scope,
for (auto& t : old_param_list) { for (auto& t : old_param_list) {
Variable* old_var = old_scope->Var(t); Variable* old_var = old_scope->Var(t);
// old model data, here we assume data type is float // old model data, here we assume data type is float
LoDTensor* old_tensor = old_var->GetMutable<LoDTensor>(); phi::DenseTensor* old_tensor = old_var->GetMutable<phi::DenseTensor>();
float* old_data = old_tensor->data<float>(); float* old_data = old_tensor->data<float>();
// new model data, here we assume data type is float // new model data, here we assume data type is float
Variable* var = scope.FindVar(t); Variable* var = scope.FindVar(t);
CHECK(var != nullptr) << "var[" << t << "] not found"; CHECK(var != nullptr) << "var[" << t << "] not found";
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
float* data = tensor->data<float>(); float* data = tensor->data<float>();
// copy from old data to new data // copy from old data to new data
if (old_tensor->numel() > tensor->numel()) { if (old_tensor->numel() > tensor->numel()) {
...@@ -1619,7 +1620,7 @@ void FleetWrapper::ShrinkDenseTable(int table_id, ...@@ -1619,7 +1620,7 @@ void FleetWrapper::ShrinkDenseTable(int table_id,
Variable* var = scope->FindVar(name); Variable* var = scope->FindVar(name);
CHECK(var != nullptr) << "var[" << name << "] not found"; CHECK(var != nullptr) << "var[" << name << "] not found";
VLOG(0) << "prepare shrink dense batch_sum"; VLOG(0) << "prepare shrink dense batch_sum";
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
float* g = tensor->data<float>(); float* g = tensor->data<float>();
// show_batch_sum += N * log(decay) // show_batch_sum += N * log(decay)
...@@ -1629,7 +1630,7 @@ void FleetWrapper::ShrinkDenseTable(int table_id, ...@@ -1629,7 +1630,7 @@ void FleetWrapper::ShrinkDenseTable(int table_id,
Variable* var_size = scope->FindVar(size_name); Variable* var_size = scope->FindVar(size_name);
CHECK(var_size != nullptr) << "var[" << size_name << "] not found"; CHECK(var_size != nullptr) << "var[" << size_name << "] not found";
VLOG(3) << "shrink dense batch_sum: " << name << ", " << size_name; VLOG(3) << "shrink dense batch_sum: " << name << ", " << size_name;
float* g_size = var_size->GetMutable<LoDTensor>()->data<float>(); float* g_size = var_size->GetMutable<phi::DenseTensor>()->data<float>();
for (int k = 0; k < tensor->numel(); k += emb_dim) { for (int k = 0; k < tensor->numel(); k += emb_dim) {
g[k] = g[k] + g_size[k] * log(decay); g[k] = g[k] + g_size[k] * log(decay);
...@@ -1639,7 +1640,7 @@ void FleetWrapper::ShrinkDenseTable(int table_id, ...@@ -1639,7 +1640,7 @@ void FleetWrapper::ShrinkDenseTable(int table_id,
} else { } else {
Variable* var = scope->FindVar(name); Variable* var = scope->FindVar(name);
CHECK(var != nullptr) << "var[" << name << "] not found"; CHECK(var != nullptr) << "var[" << name << "] not found";
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
float* g = tensor->data<float>(); float* g = tensor->data<float>();
paddle::ps::Region reg(g, tensor->numel()); paddle::ps::Region reg(g, tensor->numel());
regions.emplace_back(std::move(reg)); regions.emplace_back(std::move(reg));
......
...@@ -142,12 +142,13 @@ class FleetWrapper { ...@@ -142,12 +142,13 @@ class FleetWrapper {
// Pull sparse variables from server in sync mode // Pull sparse variables from server in sync mode
// pull immediately to tensors // pull immediately to tensors
void PullSparseToTensorSync(const uint64_t table_id, void PullSparseToTensorSync(
int fea_dim, const uint64_t table_id,
uint64_t padding_id, int fea_dim,
platform::Place place, uint64_t padding_id,
std::vector<const LoDTensor*>* inputs, // NOLINT platform::Place place,
std::vector<LoDTensor*>* outputs); // NOLINT std::vector<const phi::DenseTensor*>* inputs, // NOLINT
std::vector<phi::DenseTensor*>* outputs); // NOLINT
// pull dense variables from server in sync mod // pull dense variables from server in sync mod
// Param<in>: scope, table_id, var_names // Param<in>: scope, table_id, var_names
...@@ -256,8 +257,8 @@ class FleetWrapper { ...@@ -256,8 +257,8 @@ class FleetWrapper {
const std::string& click_name, const std::string& click_name,
platform::Place place, platform::Place place,
const std::vector<std::string>& input_names, const std::vector<std::string>& input_names,
std::vector<const LoDTensor*>* inputs, // NOLINT std::vector<const phi::DenseTensor*>* inputs, // NOLINT
std::vector<const LoDTensor*>* outputs); // NOLINT std::vector<const phi::DenseTensor*>* outputs); // NOLINT
// Push sparse variables to server in Async mode // Push sparse variables to server in Async mode
// Param<In>: scope, table_id, fea_keys, sparse_grad_names // Param<In>: scope, table_id, fea_keys, sparse_grad_names
...@@ -298,7 +299,7 @@ class FleetWrapper { ...@@ -298,7 +299,7 @@ class FleetWrapper {
// flush all push requests // flush all push requests
void ClientFlush(); void ClientFlush();
// load from paddle model // load from paddle model
void LoadFromPaddleModel(Scope& scope, void LoadFromPaddleModel(Scope& scope, // NOLINT
const uint64_t table_id, // NOLINT const uint64_t table_id, // NOLINT
std::vector<std::string> var_list, std::vector<std::string> var_list,
std::string model_path, std::string model_path,
......
...@@ -89,7 +89,7 @@ void HeterWrapper::SerializeToReq(const std::string& varname, ...@@ -89,7 +89,7 @@ void HeterWrapper::SerializeToReq(const std::string& varname,
if (var == nullptr) { if (var == nullptr) {
return; return;
} }
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
req_var->set_varname(varname); req_var->set_varname(varname);
req_var->set_type(LOD_TENSOR); req_var->set_type(LOD_TENSOR);
req_var->set_data_type(static_cast<VariableMessage::Type>( req_var->set_data_type(static_cast<VariableMessage::Type>(
...@@ -148,7 +148,7 @@ void HeterWrapper::DeSerializeToTensor(Scope* scope, ...@@ -148,7 +148,7 @@ void HeterWrapper::DeSerializeToTensor(Scope* scope,
gpuStream_t stream) { gpuStream_t stream) {
// const VariableMessage& req_var = request->vars(); // const VariableMessage& req_var = request->vars();
auto* var = scope->FindVar(req_var.varname()); auto* var = scope->FindVar(req_var.varname());
auto* tensor = var->GetMutable<LoDTensor>(); auto* tensor = var->GetMutable<phi::DenseTensor>();
std::vector<int> vec_dim; std::vector<int> vec_dim;
for (auto& x : req_var.dims()) { for (auto& x : req_var.dims()) {
...@@ -193,7 +193,7 @@ void HeterWrapper::DeSerializeToTensor(Scope* scope, ...@@ -193,7 +193,7 @@ void HeterWrapper::DeSerializeToTensor(Scope* scope,
platform::Place place) { platform::Place place) {
// const VariableMessage& req_var = request->vars(); // const VariableMessage& req_var = request->vars();
auto* var = scope->FindVar(req_var.varname()); auto* var = scope->FindVar(req_var.varname());
auto* tensor = var->GetMutable<LoDTensor>(); auto* tensor = var->GetMutable<phi::DenseTensor>();
std::vector<int> vec_dim; std::vector<int> vec_dim;
for (auto& x : req_var.dims()) { for (auto& x : req_var.dims()) {
......
...@@ -183,7 +183,7 @@ class Metric { ...@@ -183,7 +183,7 @@ class Metric {
var, var,
platform::errors::NotFound("Error: var %s is not found in scope.", platform::errors::NotFound("Error: var %s is not found in scope.",
varname.c_str())); varname.c_str()));
auto& cpu_tensor = var->Get<LoDTensor>(); auto& cpu_tensor = var->Get<phi::DenseTensor>();
*data = cpu_tensor.data<T>(); *data = cpu_tensor.data<T>();
*len = cpu_tensor.numel(); *len = cpu_tensor.numel();
} }
...@@ -197,7 +197,7 @@ class Metric { ...@@ -197,7 +197,7 @@ class Metric {
var, var,
platform::errors::NotFound("Error: var %s is not found in scope.", platform::errors::NotFound("Error: var %s is not found in scope.",
varname.c_str())); varname.c_str()));
auto& cpu_tensor = var->Get<LoDTensor>(); auto& cpu_tensor = var->Get<phi::DenseTensor>();
auto* cpu_data = cpu_tensor.data<T>(); auto* cpu_data = cpu_tensor.data<T>();
auto len = cpu_tensor.numel(); auto len = cpu_tensor.numel();
data->resize(len); data->resize(len);
......
...@@ -69,7 +69,7 @@ void NCCLWrapper::SyncVar(const int root_rank, ...@@ -69,7 +69,7 @@ void NCCLWrapper::SyncVar(const int root_rank,
#if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL) #if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL)
for (auto& name : var_names) { for (auto& name : var_names) {
auto var = scope.FindVar(name); auto var = scope.FindVar(name);
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
int32_t total_size = tensor->numel(); int32_t total_size = tensor->numel();
PADDLE_ENFORCE_GPU_SUCCESS(platform::dynload::ncclBcast( PADDLE_ENFORCE_GPU_SUCCESS(platform::dynload::ncclBcast(
reinterpret_cast<void*>(tensor->data<float>()), reinterpret_cast<void*>(tensor->data<float>()),
......
...@@ -140,7 +140,7 @@ void PSGPUWrapper::PreBuildTask(std::shared_ptr<HeterContext> gpu_task) { ...@@ -140,7 +140,7 @@ void PSGPUWrapper::PreBuildTask(std::shared_ptr<HeterContext> gpu_task) {
if (!gpu_graph_mode_) { if (!gpu_graph_mode_) {
if (data_set_name.find("SlotRecordDataset") != std::string::npos) { if (data_set_name.find("SlotRecordDataset") != std::string::npos) {
VLOG(0) << "ps_gpu_wrapper use SlotRecordDataset"; VLOG(0) << "ps_gpu_wrapper use SlotRecordDataset";
SlotRecordDataset* dataset = (SlotRecordDataset*)(dataset_); SlotRecordDataset* dataset = (SlotRecordDataset*)(dataset_); // NOLINT
auto input_channel = dataset->GetInputChannel(); auto input_channel = dataset->GetInputChannel();
VLOG(0) << "psgpu wrapperinputslotchannle size: " VLOG(0) << "psgpu wrapperinputslotchannle size: "
<< input_channel->Size(); << input_channel->Size();
...@@ -194,7 +194,7 @@ void PSGPUWrapper::PreBuildTask(std::shared_ptr<HeterContext> gpu_task) { ...@@ -194,7 +194,7 @@ void PSGPUWrapper::PreBuildTask(std::shared_ptr<HeterContext> gpu_task) {
} else { } else {
CHECK(data_set_name.find("MultiSlotDataset") != std::string::npos); CHECK(data_set_name.find("MultiSlotDataset") != std::string::npos);
VLOG(0) << "ps_gpu_wrapper use MultiSlotDataset"; VLOG(0) << "ps_gpu_wrapper use MultiSlotDataset";
MultiSlotDataset* dataset = (MultiSlotDataset*)(dataset_); MultiSlotDataset* dataset = (MultiSlotDataset*)(dataset_); // NOLINT
auto input_channel = dataset->GetInputChannel(); auto input_channel = dataset->GetInputChannel();
const std::deque<Record>& vec_data = input_channel->GetData(); const std::deque<Record>& vec_data = input_channel->GetData();
...@@ -235,7 +235,7 @@ void PSGPUWrapper::PreBuildTask(std::shared_ptr<HeterContext> gpu_task) { ...@@ -235,7 +235,7 @@ void PSGPUWrapper::PreBuildTask(std::shared_ptr<HeterContext> gpu_task) {
} }
} else { } else {
VLOG(0) << "PreBuild in GpuGraph mode"; VLOG(0) << "PreBuild in GpuGraph mode";
SlotRecordDataset* dataset = (SlotRecordDataset*)(dataset_); SlotRecordDataset* dataset = (SlotRecordDataset*)(dataset_); // NOLINT
const std::vector<uint64_t>& vec_data = dataset->GetGpuGraphTotalKeys(); const std::vector<uint64_t>& vec_data = dataset->GetGpuGraphTotalKeys();
total_len = vec_data.size(); total_len = vec_data.size();
...@@ -264,7 +264,7 @@ void PSGPUWrapper::PreBuildTask(std::shared_ptr<HeterContext> gpu_task) { ...@@ -264,7 +264,7 @@ void PSGPUWrapper::PreBuildTask(std::shared_ptr<HeterContext> gpu_task) {
iter++) { iter++) {
uint64_t cur_key = *iter; uint64_t cur_key = *iter;
int shard_id = cur_key % thread_keys_shard_num_; int shard_id = cur_key % thread_keys_shard_num_;
// TODO: feasign <-> slot <-> multi_dim // TODO(fengdanlei): feasign <-> slot <-> multi_dim
this->thread_dim_keys_[i][shard_id][0].insert(cur_key); this->thread_dim_keys_[i][shard_id][0].insert(cur_key);
} }
}; };
...@@ -786,9 +786,9 @@ void PSGPUWrapper::BuildGPUTask(std::shared_ptr<HeterContext> gpu_task) { ...@@ -786,9 +786,9 @@ void PSGPUWrapper::BuildGPUTask(std::shared_ptr<HeterContext> gpu_task) {
size_t left = 0, right = 0; size_t left = 0, right = 0;
size_t real_len = len_per_thread; size_t real_len = len_per_thread;
if ((size_t)z < remain) real_len++; if ((size_t)z < remain) real_len++; // NOLINT
if ((size_t)z < remain) { if ((size_t)z < remain) { // NOLINT
left = z * (len_per_thread + 1); left = z * (len_per_thread + 1);
right = left + real_len; right = left + real_len;
} else { } else {
...@@ -799,7 +799,7 @@ void PSGPUWrapper::BuildGPUTask(std::shared_ptr<HeterContext> gpu_task) { ...@@ -799,7 +799,7 @@ void PSGPUWrapper::BuildGPUTask(std::shared_ptr<HeterContext> gpu_task) {
for (size_t k = left; k < right; k++) { for (size_t k = left; k < right; k++) {
#ifdef PADDLE_WITH_PSLIB #ifdef PADDLE_WITH_PSLIB
float* val = (float*)(mem_pool->mem_address(k)); float* val = (float*)(mem_pool->mem_address(k)); // NOLINT
float* ptr_val = device_dim_ptrs[k]->data(); float* ptr_val = device_dim_ptrs[k]->data();
size_t dim = device_dim_ptrs[k]->size(); size_t dim = device_dim_ptrs[k]->size();
val->delta_score = val->delta_score =
...@@ -809,8 +809,8 @@ void PSGPUWrapper::BuildGPUTask(std::shared_ptr<HeterContext> gpu_task) { ...@@ -809,8 +809,8 @@ void PSGPUWrapper::BuildGPUTask(std::shared_ptr<HeterContext> gpu_task) {
DownpourCtrDymfFeatureValue::show_index()]; DownpourCtrDymfFeatureValue::show_index()];
val->clk = ptr_val[paddle::ps::DownpourCtrDymfAccessor:: val->clk = ptr_val[paddle::ps::DownpourCtrDymfAccessor::
DownpourCtrDymfFeatureValue::click_index()]; DownpourCtrDymfFeatureValue::click_index()];
val->slot = int(ptr_val[paddle::ps::DownpourCtrDymfAccessor:: val->slot = int(ptr_val[paddle::ps::DownpourCtrDymfAccessor:: // NOLINT
DownpourCtrDymfFeatureValue::slot_index()]); DownpourCtrDymfFeatureValue::slot_index()]);
val->lr = ptr_val[paddle::ps::DownpourCtrDymfAccessor:: val->lr = ptr_val[paddle::ps::DownpourCtrDymfAccessor::
DownpourCtrDymfFeatureValue::embed_w_index()]; DownpourCtrDymfFeatureValue::embed_w_index()];
val->lr_g2sum = val->lr_g2sum =
...@@ -818,7 +818,7 @@ void PSGPUWrapper::BuildGPUTask(std::shared_ptr<HeterContext> gpu_task) { ...@@ -818,7 +818,7 @@ void PSGPUWrapper::BuildGPUTask(std::shared_ptr<HeterContext> gpu_task) {
DownpourCtrDymfFeatureValue::embed_g2sum_index()]; DownpourCtrDymfFeatureValue::embed_g2sum_index()];
// TODO(xuefeng) set mf_dim while using DownpourCtrDymfAccessor // TODO(xuefeng) set mf_dim while using DownpourCtrDymfAccessor
ptr_val[paddle::ps::DownpourCtrDymfAccessor::DownpourCtrDymfFeatureValue:: ptr_val[paddle::ps::DownpourCtrDymfAccessor::DownpourCtrDymfFeatureValue::
mf_dim_index()] = float(mf_dim); mf_dim_index()] = float(mf_dim); // NOLINT
val->mf_dim = mf_dim; val->mf_dim = mf_dim;
if (dim > 8) { // CpuPS alreay expand as mf_dim if (dim > 8) { // CpuPS alreay expand as mf_dim
val->mf_size = mf_dim + 1; val->mf_size = mf_dim + 1;
...@@ -1025,7 +1025,8 @@ void PSGPUWrapper::EndPass() { ...@@ -1025,7 +1025,8 @@ void PSGPUWrapper::EndPass() {
VLOG(0) << "dump pool to cpu table: " << i << "with mf dim: " << mf_dim VLOG(0) << "dump pool to cpu table: " << i << "with mf dim: " << mf_dim
<< " key_len :" << len << " key_len :" << len
<< " feature_value_size:" << feature_value_size; << " feature_value_size:" << feature_value_size;
char* test_build_values = (char*)malloc(feature_value_size * real_len); char* test_build_values =
(char*)malloc(feature_value_size * real_len); // NOLINT
uint64_t offset = left * feature_value_size; uint64_t offset = left * feature_value_size;
cudaMemcpy(test_build_values, cudaMemcpy(test_build_values,
hbm_pool->mem() + offset, hbm_pool->mem() + offset,
...@@ -1038,9 +1039,9 @@ void PSGPUWrapper::EndPass() { ...@@ -1038,9 +1039,9 @@ void PSGPUWrapper::EndPass() {
continue; continue;
} }
size_t local_offset = (i - left) * feature_value_size; size_t local_offset = (i - left) * feature_value_size;
float* gpu_val = (float*)(test_build_values + local_offset); float* gpu_val = (float*)(test_build_values + local_offset); // NOLINT
#ifdef PADDLE_WITH_PSLIB #ifdef PADDLE_WITH_PSLIB
// TODO: PSLIB DumpFill // TODO(fengdanlei): PSLIB DumpFill
#endif #endif
#ifdef PADDLE_WITH_PSCORE #ifdef PADDLE_WITH_PSCORE
accessor_wrapper_ptr->DumpFill(gpu_val, cpu_table_accessor_, mf_dim); accessor_wrapper_ptr->DumpFill(gpu_val, cpu_table_accessor_, mf_dim);
...@@ -1239,7 +1240,7 @@ void PSGPUWrapper::PullSparse(const paddle::platform::Place& place, ...@@ -1239,7 +1240,7 @@ void PSGPUWrapper::PullSparse(const paddle::platform::Place& place,
auto buf = memory::Alloc(place, total_length * feature_value_size); auto buf = memory::Alloc(place, total_length * feature_value_size);
float* total_values_gpu = reinterpret_cast<float*>(buf->ptr()); float* total_values_gpu = reinterpret_cast<float*>(buf->ptr());
VLOG(3) << "Begin copy keys, key_num[" << total_length << "]"; VLOG(3) << "Begin copy keys, key_num[" << total_length << "]";
LoDTensor& total_keys_tensor = keys_tensor[devid_2_index]; phi::DenseTensor& total_keys_tensor = keys_tensor[devid_2_index];
uint64_t* total_keys = uint64_t* total_keys =
reinterpret_cast<uint64_t*>(total_keys_tensor.mutable_data<int64_t>( reinterpret_cast<uint64_t*>(total_keys_tensor.mutable_data<int64_t>(
{int64_t(total_length), 1}, place)); {int64_t(total_length), 1}, place));
...@@ -1309,7 +1310,7 @@ void PSGPUWrapper::PullSparse(const paddle::platform::Place& place, ...@@ -1309,7 +1310,7 @@ void PSGPUWrapper::PullSparse(const paddle::platform::Place& place,
VLOG(3) << "Begin copy keys, key_num[" << total_length << "]"; VLOG(3) << "Begin copy keys, key_num[" << total_length << "]";
int device_id = place.GetDeviceId(); int device_id = place.GetDeviceId();
int devid_2_index = HeterPs_->get_index_by_devid(device_id); int devid_2_index = HeterPs_->get_index_by_devid(device_id);
LoDTensor& total_keys_tensor = keys_tensor[devid_2_index]; phi::DenseTensor& total_keys_tensor = keys_tensor[devid_2_index];
uint64_t* total_keys = uint64_t* total_keys =
reinterpret_cast<uint64_t*>(total_keys_tensor.mutable_data<int64_t>( reinterpret_cast<uint64_t*>(total_keys_tensor.mutable_data<int64_t>(
{int64_t(total_length), 1}, place)); {int64_t(total_length), 1}, place));
...@@ -1489,7 +1490,7 @@ void PSGPUWrapper::PushSparseGrad(const paddle::platform::Place& place, ...@@ -1489,7 +1490,7 @@ void PSGPUWrapper::PushSparseGrad(const paddle::platform::Place& place,
<< "grad_value_size:" << grad_value_size; << "grad_value_size:" << grad_value_size;
float* total_grad_values_gpu = reinterpret_cast<float*>(buf->ptr()); float* total_grad_values_gpu = reinterpret_cast<float*>(buf->ptr());
LoDTensor& total_keys_tensor = keys_tensor[devid_2_index]; phi::DenseTensor& total_keys_tensor = keys_tensor[devid_2_index];
uint64_t* total_keys = uint64_t* total_keys =
reinterpret_cast<uint64_t*>(total_keys_tensor.data<int64_t>()); reinterpret_cast<uint64_t*>(total_keys_tensor.data<int64_t>());
VLOG(3) << "Begin copy grad tensor to gpups struct"; VLOG(3) << "Begin copy grad tensor to gpups struct";
...@@ -1526,7 +1527,7 @@ void PSGPUWrapper::PushSparseGrad(const paddle::platform::Place& place, ...@@ -1526,7 +1527,7 @@ void PSGPUWrapper::PushSparseGrad(const paddle::platform::Place& place,
VLOG(3) << "Push Sparse Max mf dimention: " << max_mf_dim_ VLOG(3) << "Push Sparse Max mf dimention: " << max_mf_dim_
<< "grad_value_size:" << grad_value_size; << "grad_value_size:" << grad_value_size;
float* total_grad_values_gpu = reinterpret_cast<float*>(buf->ptr()); float* total_grad_values_gpu = reinterpret_cast<float*>(buf->ptr());
LoDTensor& total_keys_tensor = keys_tensor[devid_2_index]; phi::DenseTensor& total_keys_tensor = keys_tensor[devid_2_index];
uint64_t* total_keys = uint64_t* total_keys =
reinterpret_cast<uint64_t*>(total_keys_tensor.data<int64_t>()); reinterpret_cast<uint64_t*>(total_keys_tensor.data<int64_t>());
VLOG(3) << "Begin copy grad tensor to xpups struct"; VLOG(3) << "Begin copy grad tensor to xpups struct";
......
...@@ -649,7 +649,7 @@ class PSGPUWrapper { ...@@ -649,7 +649,7 @@ class PSGPUWrapper {
std::vector<std::unordered_map<uint64_t, std::vector<float>>>> std::vector<std::unordered_map<uint64_t, std::vector<float>>>>
local_tables_; local_tables_;
HeterPsBase* HeterPs_; HeterPsBase* HeterPs_;
std::vector<LoDTensor> keys_tensor; // Cache for pull_sparse std::vector<phi::DenseTensor> keys_tensor; // Cache for pull_sparse
std::shared_ptr<HeterPsResource> resource_; std::shared_ptr<HeterPsResource> resource_;
int32_t sleep_seconds_before_fail_exit_; int32_t sleep_seconds_before_fail_exit_;
std::vector<int> slot_vector_; std::vector<int> slot_vector_;
......
...@@ -32,10 +32,11 @@ void SetMicroId(paddle::framework::Scope* scope, ...@@ -32,10 +32,11 @@ void SetMicroId(paddle::framework::Scope* scope,
auto* ptr = scope->Var("microbatch_id"); auto* ptr = scope->Var("microbatch_id");
InitializeVariable(ptr, proto::VarType::LOD_TENSOR); InitializeVariable(ptr, proto::VarType::LOD_TENSOR);
framework::Variable* var = scope->FindVar("microbatch_id"); framework::Variable* var = scope->FindVar("microbatch_id");
PADDLE_ENFORCE_EQ(var->IsType<phi::DenseTensor>(), PADDLE_ENFORCE_EQ(
1, var->IsType<phi::DenseTensor>(),
platform::errors::InvalidArgument( 1,
"the type of microbatch_id should be LoDTensor")); platform::errors::InvalidArgument(
"the type of microbatch_id should be phi::DenseTensor"));
auto* tensor = var->GetMutable<phi::DenseTensor>(); auto* tensor = var->GetMutable<phi::DenseTensor>();
std::vector<int> dims{1}; std::vector<int> dims{1};
tensor->Resize(phi::make_ddim(dims)); tensor->Resize(phi::make_ddim(dims));
......
...@@ -15,7 +15,7 @@ syntax = "proto2"; ...@@ -15,7 +15,7 @@ syntax = "proto2";
package paddle.framework; package paddle.framework;
option cc_generic_services = true; option cc_generic_services = true;
// It can be: LoDTensor、SelectedRows or NCCL_ID // It can be: phi::DenseTensor、SelectedRows or NCCL_ID
enum VarType { enum VarType {
LOD_TENSOR = 0; LOD_TENSOR = 0;
SELECTED_ROWS = 1; SELECTED_ROWS = 1;
......
...@@ -54,9 +54,10 @@ void HeterTask::PackTask(Scope* thread_scope, ...@@ -54,9 +54,10 @@ void HeterTask::PackTask(Scope* thread_scope,
auto& use_slots = reader->GetUseSlotAlias(); auto& use_slots = reader->GetUseSlotAlias();
for (size_t i = 0; i < use_slots.size(); ++i) { for (size_t i = 0; i < use_slots.size(); ++i) {
Variable* thread_var = thread_scope->FindVar(use_slots[i]); Variable* thread_var = thread_scope->FindVar(use_slots[i]);
LoDTensor* thread_tensor = thread_var->GetMutable<LoDTensor>(); phi::DenseTensor* thread_tensor =
thread_var->GetMutable<phi::DenseTensor>();
Variable* task_var = scope_->FindVar(use_slots[i]); Variable* task_var = scope_->FindVar(use_slots[i]);
LoDTensor* task_tensor = task_var->GetMutable<LoDTensor>(); phi::DenseTensor* task_tensor = task_var->GetMutable<phi::DenseTensor>();
TensorCopy(*thread_tensor, platform::CPUPlace(), task_tensor); TensorCopy(*thread_tensor, platform::CPUPlace(), task_tensor);
auto& tensor_lod = thread_tensor->lod()[0]; auto& tensor_lod = thread_tensor->lod()[0];
LoD thread_lod{tensor_lod}; LoD thread_lod{tensor_lod};
...@@ -198,7 +199,7 @@ void HeterCpuWorker::SetNeedDump(bool need_dump_field) { ...@@ -198,7 +199,7 @@ void HeterCpuWorker::SetNeedDump(bool need_dump_field) {
} }
// template <typename T> // template <typename T>
// std::string PrintLodTensorType(LoDTensor* tensor, // std::string PrintLodTensorType(phi::DenseTensor* tensor,
// int64_t start, int64_t end) { // int64_t start, int64_t end) {
// auto count = tensor->numel(); // auto count = tensor->numel();
// if (start < 0 || end > count) { // if (start < 0 || end > count) {
...@@ -212,7 +213,7 @@ void HeterCpuWorker::SetNeedDump(bool need_dump_field) { ...@@ -212,7 +213,7 @@ void HeterCpuWorker::SetNeedDump(bool need_dump_field) {
// return os.str(); // return os.str();
// } // }
// //
// std::string PrintLodTensorIntType(LoDTensor* tensor, int64_t start, // std::string PrintLodTensorIntType(phi::DenseTensor* tensor, int64_t start,
// int64_t end) { // int64_t end) {
// auto count = tensor->numel(); // auto count = tensor->numel();
// if (start < 0 || end > count) { // if (start < 0 || end > count) {
...@@ -226,7 +227,8 @@ void HeterCpuWorker::SetNeedDump(bool need_dump_field) { ...@@ -226,7 +227,8 @@ void HeterCpuWorker::SetNeedDump(bool need_dump_field) {
// return os.str(); // return os.str();
// } // }
// //
// std::string PrintLodTensor(LoDTensor* tensor, int64_t start, int64_t end) { // std::string PrintLodTensor(phi::DenseTensor* tensor, int64_t start, int64_t
// end) {
// std::string out_val; // std::string out_val;
// if (tensor->type() == proto::VarType::FP32) { // if (tensor->type() == proto::VarType::FP32) {
// out_val = PrintLodTensorType<float>(tensor, start, end); // out_val = PrintLodTensorType<float>(tensor, start, end);
...@@ -240,7 +242,8 @@ void HeterCpuWorker::SetNeedDump(bool need_dump_field) { ...@@ -240,7 +242,8 @@ void HeterCpuWorker::SetNeedDump(bool need_dump_field) {
// return out_val; // return out_val;
// } // }
// //
// std::pair<int64_t, int64_t> GetTensorBound(LoDTensor* tensor, int index) { // std::pair<int64_t, int64_t> GetTensorBound(phi::DenseTensor* tensor, int
// index) {
// auto& dims = tensor->dims(); // auto& dims = tensor->dims();
// if (tensor->lod().size() != 0) { // if (tensor->lod().size() != 0) {
// auto& lod = tensor->lod()[0]; // auto& lod = tensor->lod()[0];
...@@ -250,7 +253,7 @@ void HeterCpuWorker::SetNeedDump(bool need_dump_field) { ...@@ -250,7 +253,7 @@ void HeterCpuWorker::SetNeedDump(bool need_dump_field) {
// } // }
// } // }
// //
// bool CheckValidOutput(LoDTensor* tensor, size_t batch_size) { // bool CheckValidOutput(phi::DenseTensor* tensor, size_t batch_size) {
// auto& dims = tensor->dims(); // auto& dims = tensor->dims();
// if (dims.size() != 2) return false; // if (dims.size() != 2) return false;
// if (tensor->lod().size() != 0) { // if (tensor->lod().size() != 0) {
...@@ -275,7 +278,7 @@ void HeterCpuWorker::DumpParam() { ...@@ -275,7 +278,7 @@ void HeterCpuWorker::DumpParam() {
// if (var == nullptr) { // if (var == nullptr) {
// continue; // continue;
// } // }
// LoDTensor* tensor = var->GetMutable<LoDTensor>(); // phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
// int64_t len = tensor->numel(); // int64_t len = tensor->numel();
// os += PrintLodTensor(tensor, 0, len); // os += PrintLodTensor(tensor, 0, len);
// writer_ << os; // writer_ << os;
...@@ -302,7 +305,7 @@ void HeterCpuWorker::CollectLabelInfo(std::shared_ptr<HeterTask> task, ...@@ -302,7 +305,7 @@ void HeterCpuWorker::CollectLabelInfo(std::shared_ptr<HeterTask> task,
Scope* scope = task->scope_; Scope* scope = task->scope_;
feature_label.resize(feature.size()); feature_label.resize(feature.size());
Variable* var = scope->FindVar(label_var_name_[table_id]); Variable* var = scope->FindVar(label_var_name_[table_id]);
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
int64_t* label_ptr = tensor->data<int64_t>(); int64_t* label_ptr = tensor->data<int64_t>();
size_t global_index = 0; size_t global_index = 0;
...@@ -313,7 +316,7 @@ void HeterCpuWorker::CollectLabelInfo(std::shared_ptr<HeterTask> task, ...@@ -313,7 +316,7 @@ void HeterCpuWorker::CollectLabelInfo(std::shared_ptr<HeterTask> task,
if (fea_var == nullptr) { if (fea_var == nullptr) {
continue; continue;
} }
LoDTensor* tensor = fea_var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = fea_var->GetMutable<phi::DenseTensor>();
CHECK(tensor != nullptr) CHECK(tensor != nullptr)
<< "tensor of var " << sparse_key_names_[table_id][i] << " is null"; << "tensor of var " << sparse_key_names_[table_id][i] << " is null";
...@@ -365,7 +368,7 @@ void HeterCpuWorker::FillSparseValue(std::shared_ptr<HeterTask> task, ...@@ -365,7 +368,7 @@ void HeterCpuWorker::FillSparseValue(std::shared_ptr<HeterTask> task,
if (var == nullptr) { if (var == nullptr) {
continue; continue;
} }
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
CHECK(tensor != nullptr) << "tensor of var " << slot_name << " is null"; CHECK(tensor != nullptr) << "tensor of var " << slot_name << " is null";
int64_t* ids = tensor->data<int64_t>(); int64_t* ids = tensor->data<int64_t>();
int len = tensor->numel(); int len = tensor->numel();
...@@ -373,7 +376,7 @@ void HeterCpuWorker::FillSparseValue(std::shared_ptr<HeterTask> task, ...@@ -373,7 +376,7 @@ void HeterCpuWorker::FillSparseValue(std::shared_ptr<HeterTask> task,
if (var_emb == nullptr) { if (var_emb == nullptr) {
continue; continue;
} }
LoDTensor* tensor_emb = var_emb->GetMutable<LoDTensor>(); phi::DenseTensor* tensor_emb = var_emb->GetMutable<phi::DenseTensor>();
float* ptr = float* ptr =
tensor_emb->mutable_data<float>({len, table.emb_dim()}, place_); tensor_emb->mutable_data<float>({len, table.emb_dim()}, place_);
// memset(ptr, 0, sizeof(float) * len * table.emb_dim()); // memset(ptr, 0, sizeof(float) * len * table.emb_dim());
...@@ -448,7 +451,7 @@ void HeterCpuWorker::AdjustInsWeight(std::shared_ptr<HeterTask> task) { ...@@ -448,7 +451,7 @@ void HeterCpuWorker::AdjustInsWeight(std::shared_ptr<HeterTask> task) {
<< " is nullptr, skip adjust ins weight"; << " is nullptr, skip adjust ins weight";
return; return;
} }
LoDTensor* nid_tensor = nid_var->GetMutable<LoDTensor>(); phi::DenseTensor* nid_tensor = nid_var->GetMutable<phi::DenseTensor>();
if (nid_tensor == nullptr) { if (nid_tensor == nullptr) {
VLOG(0) << "tensor of nid slot var " << adjust_ins_weight_config_.nid_slot() VLOG(0) << "tensor of nid slot var " << adjust_ins_weight_config_.nid_slot()
<< " is nullptr, skip adjust ins weight"; << " is nullptr, skip adjust ins weight";
...@@ -461,7 +464,8 @@ void HeterCpuWorker::AdjustInsWeight(std::shared_ptr<HeterTask> task) { ...@@ -461,7 +464,8 @@ void HeterCpuWorker::AdjustInsWeight(std::shared_ptr<HeterTask> task) {
<< " is nullptr, skip adjust ins weight"; << " is nullptr, skip adjust ins weight";
return; return;
} }
LoDTensor* ins_weight_tensor = ins_weight_var->GetMutable<LoDTensor>(); phi::DenseTensor* ins_weight_tensor =
ins_weight_var->GetMutable<phi::DenseTensor>();
if (ins_weight_tensor == nullptr) { if (ins_weight_tensor == nullptr) {
VLOG(0) << "tensor of ins weight tensor " VLOG(0) << "tensor of ins weight tensor "
<< adjust_ins_weight_config_.ins_weight_slot() << adjust_ins_weight_config_.ins_weight_slot()
...@@ -584,14 +588,14 @@ void HeterCpuWorker::CopyDenseVars() { ...@@ -584,14 +588,14 @@ void HeterCpuWorker::CopyDenseVars() {
<< dest_var_name; << dest_var_name;
Variable* src_var = thread_scope_->FindVar(src_var_name); Variable* src_var = thread_scope_->FindVar(src_var_name);
CHECK(src_var != nullptr) << src_var_name << " not found"; // NOLINT CHECK(src_var != nullptr) << src_var_name << " not found"; // NOLINT
LoDTensor* src_tensor = src_var->GetMutable<LoDTensor>(); phi::DenseTensor* src_tensor = src_var->GetMutable<phi::DenseTensor>();
CHECK(src_tensor != nullptr) CHECK(src_tensor != nullptr)
<< src_var_name << " tensor is null"; // NOLINT << src_var_name << " tensor is null"; // NOLINT
float* src_data = src_tensor->data<float>(); float* src_data = src_tensor->data<float>();
Variable* dest_var = thread_scope_->FindVar(dest_var_name); Variable* dest_var = thread_scope_->FindVar(dest_var_name);
CHECK(dest_var != nullptr) << dest_var_name << " not found"; // NOLINT CHECK(dest_var != nullptr) << dest_var_name << " not found"; // NOLINT
LoDTensor* dest_tensor = dest_var->GetMutable<LoDTensor>(); phi::DenseTensor* dest_tensor = dest_var->GetMutable<phi::DenseTensor>();
CHECK(dest_tensor != nullptr) CHECK(dest_tensor != nullptr)
<< dest_var_name << " tensor is null"; // NOLINT << dest_var_name << " tensor is null"; // NOLINT
float* dest_data = dest_tensor->data<float>(); float* dest_data = dest_tensor->data<float>();
...@@ -797,7 +801,7 @@ void HeterCpuWorker::TrainFilesWithProfiler() { ...@@ -797,7 +801,7 @@ void HeterCpuWorker::TrainFilesWithProfiler() {
if (var == nullptr) { if (var == nullptr) {
continue; continue;
} }
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
if (tensor == nullptr) { if (tensor == nullptr) {
continue; continue;
} }
...@@ -1085,7 +1089,7 @@ void HeterCpuWorker::TrainFiles() { ...@@ -1085,7 +1089,7 @@ void HeterCpuWorker::TrainFiles() {
if (var == nullptr) { if (var == nullptr) {
continue; continue;
} }
LoDTensor* tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
if (tensor == nullptr) { if (tensor == nullptr) {
continue; continue;
} }
...@@ -1154,7 +1158,7 @@ void HeterCpuWorker::TrainFiles() { ...@@ -1154,7 +1158,7 @@ void HeterCpuWorker::TrainFiles() {
// if (var == nullptr) { // if (var == nullptr) {
// continue; // continue;
// } // }
// LoDTensor* tensor = var->GetMutable<LoDTensor>(); // phi::DenseTensor* tensor = var->GetMutable<phi::DenseTensor>();
// if (!CheckValidOutput(tensor, batch_size)) { // if (!CheckValidOutput(tensor, batch_size)) {
// continue; // continue;
// } // }
......
...@@ -133,10 +133,10 @@ void HeterXpuTrainer::CreateThreadParam(const ProgramDesc& program, int num) { ...@@ -133,10 +133,10 @@ void HeterXpuTrainer::CreateThreadParam(const ProgramDesc& program, int num) {
if (var->Persistable()) { if (var->Persistable()) {
auto name = var->Name(); auto name = var->Name();
Variable* root_var = root_scope_->FindVar(name); Variable* root_var = root_scope_->FindVar(name);
LoDTensor* root_tensor = root_var->GetMutable<LoDTensor>(); phi::DenseTensor* root_tensor = root_var->GetMutable<phi::DenseTensor>();
auto* ptr = scope->Var(name); auto* ptr = scope->Var(name);
InitializeVariable(ptr, proto::VarType::LOD_TENSOR); InitializeVariable(ptr, proto::VarType::LOD_TENSOR);
LoDTensor* thread_tensor = ptr->GetMutable<LoDTensor>(); phi::DenseTensor* thread_tensor = ptr->GetMutable<phi::DenseTensor>();
#define HeterMemcpyFunc(cpp_type, proto_type) \ #define HeterMemcpyFunc(cpp_type, proto_type) \
do { \ do { \
...@@ -167,8 +167,8 @@ void HeterXpuTrainer::CreateThreadParam(const ProgramDesc& program, int num) { ...@@ -167,8 +167,8 @@ void HeterXpuTrainer::CreateThreadParam(const ProgramDesc& program, int num) {
#ifdef PADDLE_WITH_CUDA #ifdef PADDLE_WITH_CUDA
template <typename T> template <typename T>
void HeterXpuTrainer::HeterMemCpy(LoDTensor* thread_tensor, void HeterXpuTrainer::HeterMemCpy(phi::DenseTensor* thread_tensor,
LoDTensor* root_tensor, phi::DenseTensor* root_tensor,
const paddle::platform::Place& thread_place, const paddle::platform::Place& thread_place,
cudaStream_t stream) { cudaStream_t stream) {
T* thread_ptr = T* thread_ptr =
...@@ -194,8 +194,8 @@ void HeterXpuTrainer::HeterMemCpy(LoDTensor* thread_tensor, ...@@ -194,8 +194,8 @@ void HeterXpuTrainer::HeterMemCpy(LoDTensor* thread_tensor,
#ifdef PADDLE_WITH_XPU #ifdef PADDLE_WITH_XPU
template <typename T> template <typename T>
void HeterXpuTrainer::HeterMemCpy(LoDTensor* thread_tensor, void HeterXpuTrainer::HeterMemCpy(phi::DenseTensor* thread_tensor,
LoDTensor* root_tensor, phi::DenseTensor* root_tensor,
const paddle::platform::Place& thread_place) { const paddle::platform::Place& thread_place) {
T* thread_ptr = T* thread_ptr =
thread_tensor->mutable_data<T>(root_tensor->dims(), thread_place); thread_tensor->mutable_data<T>(root_tensor->dims(), thread_place);
...@@ -319,7 +319,7 @@ int HeterXpuTrainer::EndPass(const HeterRequest* request, ...@@ -319,7 +319,7 @@ int HeterXpuTrainer::EndPass(const HeterRequest* request,
if (root_var == nullptr) { if (root_var == nullptr) {
continue; continue;
} }
LoDTensor* root_tensor = root_var->GetMutable<LoDTensor>(); phi::DenseTensor* root_tensor = root_var->GetMutable<phi::DenseTensor>();
for (size_t j = 0; j < place_scopes_.size(); j++) { for (size_t j = 0; j < place_scopes_.size(); j++) {
Scope* cur_thread_scope = place_scopes_[j]; Scope* cur_thread_scope = place_scopes_[j];
...@@ -328,7 +328,8 @@ int HeterXpuTrainer::EndPass(const HeterRequest* request, ...@@ -328,7 +328,8 @@ int HeterXpuTrainer::EndPass(const HeterRequest* request,
if (thread_var == nullptr) { if (thread_var == nullptr) {
continue; continue;
} }
LoDTensor* thread_tensor = thread_var->GetMutable<LoDTensor>(); phi::DenseTensor* thread_tensor =
thread_var->GetMutable<phi::DenseTensor>();
// if (root_tensor->numel() != thread_tensor->numel()) { // if (root_tensor->numel() != thread_tensor->numel()) {
// continue; // continue;
// } // }
...@@ -421,12 +422,12 @@ int HeterXpuTrainer::EndPass(const HeterRequest* request, ...@@ -421,12 +422,12 @@ int HeterXpuTrainer::EndPass(const HeterRequest* request,
} }
template <typename T> template <typename T>
void HeterXpuTrainer::MergeToRootScope(LoDTensor* root_tensor, void HeterXpuTrainer::MergeToRootScope(phi::DenseTensor* root_tensor,
LoDTensor* tensor) { phi::DenseTensor* tensor) {
LoDTensor tmp_root; phi::DenseTensor tmp_root;
TensorCopy(*root_tensor, platform::CPUPlace(), &tmp_root); TensorCopy(*root_tensor, platform::CPUPlace(), &tmp_root);
T* tmp_root_data = tmp_root.data<T>(); T* tmp_root_data = tmp_root.data<T>();
LoDTensor tmp_tensor; phi::DenseTensor tmp_tensor;
TensorCopy(*tensor, platform::CPUPlace(), &tmp_tensor); TensorCopy(*tensor, platform::CPUPlace(), &tmp_tensor);
T* data = tmp_tensor.data<T>(); T* data = tmp_tensor.data<T>();
for (int i = 0; i < tmp_tensor.numel(); i++) { for (int i = 0; i < tmp_tensor.numel(); i++) {
......
...@@ -74,13 +74,14 @@ void HogwildWorker::CreateThreadScope(const ProgramDesc &program) { ...@@ -74,13 +74,14 @@ void HogwildWorker::CreateThreadScope(const ProgramDesc &program) {
InitializeVariable(ptr, var->GetType()); InitializeVariable(ptr, var->GetType());
if (stat_var_name_map_.find(var->Name()) != stat_var_name_map_.end() && if (stat_var_name_map_.find(var->Name()) != stat_var_name_map_.end() &&
thread_id_ != 0) { thread_id_ != 0) {
int tensor_dim = int tensor_dim = root_scope_->FindVar(var->Name())
root_scope_->FindVar(var->Name())->GetMutable<LoDTensor>()->numel(); ->GetMutable<phi::DenseTensor>()
->numel();
auto *ptr1 = thread_scope_->Var(var->Name()); auto *ptr1 = thread_scope_->Var(var->Name());
InitializeVariable(ptr1, var->GetType()); InitializeVariable(ptr1, var->GetType());
LoDTensor *thread_tensor = ptr1->GetMutable<LoDTensor>(); phi::DenseTensor *thread_tensor = ptr1->GetMutable<phi::DenseTensor>();
LoDTensor *root_tensor = phi::DenseTensor *root_tensor =
root_scope_->FindVar(var->Name())->GetMutable<LoDTensor>(); root_scope_->FindVar(var->Name())->GetMutable<phi::DenseTensor>();
#define MemsetCallback(cpp_type, proto_type) \ #define MemsetCallback(cpp_type, proto_type) \
do { \ do { \
if (framework::TransToProtoVarType(root_tensor->dtype()) == proto_type) { \ if (framework::TransToProtoVarType(root_tensor->dtype()) == proto_type) { \
...@@ -97,8 +98,8 @@ void HogwildWorker::CreateThreadScope(const ProgramDesc &program) { ...@@ -97,8 +98,8 @@ void HogwildWorker::CreateThreadScope(const ProgramDesc &program) {
} }
template <typename T> template <typename T>
void HogwildWorker::SetZero(LoDTensor *tensor, void HogwildWorker::SetZero(phi::DenseTensor *tensor,
LoDTensor *root_tensor, phi::DenseTensor *root_tensor,
int tensor_dim) { int tensor_dim) {
T *ptr = tensor->mutable_data<T>(root_tensor->dims(), platform::CPUPlace()); T *ptr = tensor->mutable_data<T>(root_tensor->dims(), platform::CPUPlace());
memset(ptr, 0, sizeof(T) * tensor_dim); memset(ptr, 0, sizeof(T) * tensor_dim);
......
...@@ -379,12 +379,12 @@ void CompatMetaTensor::share_lod(const MetaTensor& meta_tensor) { ...@@ -379,12 +379,12 @@ void CompatMetaTensor::share_lod(const MetaTensor& meta_tensor) {
static_cast<const CompatMetaTensor&>(meta_tensor).GetRuntimeLoD(); static_cast<const CompatMetaTensor&>(meta_tensor).GetRuntimeLoD();
} else { } else {
// NOTE(chenweihang): do nothing // NOTE(chenweihang): do nothing
// only LoDTensor need to share lod // only phi::DenseTensor need to share lod
} }
} else { } else {
auto* var = PADDLE_GET(VarDesc*, var_); auto* var = PADDLE_GET(VarDesc*, var_);
if (!meta_tensor.is_dense() && !meta_tensor.is_tensor_array()) { if (!meta_tensor.is_dense() && !meta_tensor.is_tensor_array()) {
VLOG(3) << "input metatensor is not LoDTensor or LoDTensorArray."; VLOG(3) << "input metatensor is not phi::DenseTensor or LoDTensorArray.";
return; return;
} }
if (var) { if (var) {
...@@ -415,7 +415,7 @@ void CompatMetaTensor::share_meta(const MetaTensor& meta_tensor) { ...@@ -415,7 +415,7 @@ void CompatMetaTensor::share_meta(const MetaTensor& meta_tensor) {
share_dims(meta_tensor); share_dims(meta_tensor);
set_dtype(meta_tensor.dtype()); set_dtype(meta_tensor.dtype());
set_layout(meta_tensor.layout()); set_layout(meta_tensor.layout());
// special case: share lod of LoDTensor // special case: share lod of phi::DenseTensor
share_lod(meta_tensor); share_lod(meta_tensor);
} }
......
...@@ -72,7 +72,7 @@ class CompatMetaTensor : public phi::MetaTensor { ...@@ -72,7 +72,7 @@ class CompatMetaTensor : public phi::MetaTensor {
private: private:
const LoD& GetRuntimeLoD() const { const LoD& GetRuntimeLoD() const {
auto* var = PADDLE_GET_CONST(Variable*, var_); auto* var = PADDLE_GET_CONST(Variable*, var_);
return var->Get<LoDTensor>().lod(); return var->Get<phi::DenseTensor>().lod();
} }
int32_t GetCompileTimeLoD() const { int32_t GetCompileTimeLoD() const {
......
...@@ -183,21 +183,21 @@ void AttentionLSTMFusePass::FindWhileOp(Graph* graph) const { ...@@ -183,21 +183,21 @@ void AttentionLSTMFusePass::FindWhileOp(Graph* graph) const {
CHECK_P4(x0, x1, x2, x3); \ CHECK_P4(x0, x1, x2, x3); \
CHECK_P1(x4); CHECK_P1(x4);
void PrepareLSTMWeight(const LoDTensor& W_forget_w0, void PrepareLSTMWeight(const phi::DenseTensor& W_forget_w0,
const LoDTensor& W_forget_w1, const phi::DenseTensor& W_forget_w1,
const LoDTensor& W_input_w0, const phi::DenseTensor& W_input_w0,
const LoDTensor& W_input_w1, const phi::DenseTensor& W_input_w1,
const LoDTensor& W_output_w0, const phi::DenseTensor& W_output_w0,
const LoDTensor& W_output_w1, const phi::DenseTensor& W_output_w1,
const LoDTensor& W_cell_w0, const phi::DenseTensor& W_cell_w0,
const LoDTensor& W_cell_w1, const phi::DenseTensor& W_cell_w1,
LoDTensor* out); phi::DenseTensor* out);
void PrepareLSTMBias(const LoDTensor& B_forget, void PrepareLSTMBias(const phi::DenseTensor& B_forget,
const LoDTensor& B_input, const phi::DenseTensor& B_input,
const LoDTensor& B_output, const phi::DenseTensor& B_output,
const LoDTensor& B_cell, const phi::DenseTensor& B_cell,
LoDTensor* out); phi::DenseTensor* out);
void PrepareParameters(Graph* graph, const Param& param, ir::Node* lstm_op) { void PrepareParameters(Graph* graph, const Param& param, ir::Node* lstm_op) {
// Check parameters // Check parameters
...@@ -209,8 +209,8 @@ void PrepareParameters(Graph* graph, const Param& param, ir::Node* lstm_op) { ...@@ -209,8 +209,8 @@ void PrepareParameters(Graph* graph, const Param& param, ir::Node* lstm_op) {
// Create new parameters. // Create new parameters.
// AddInput // AddInput
scope.Var(param.LSTMWeight)->GetMutable<LoDTensor>(); scope.Var(param.LSTMWeight)->GetMutable<phi::DenseTensor>();
scope.Var(param.LSTMBias)->GetMutable<LoDTensor>(); scope.Var(param.LSTMBias)->GetMutable<phi::DenseTensor>();
// AddOutput // AddOutput
#define IR_NODE(x) \ #define IR_NODE(x) \
VarDesc key_##x(param.x); \ VarDesc key_##x(param.x); \
...@@ -226,20 +226,20 @@ void PrepareParameters(Graph* graph, const Param& param, ir::Node* lstm_op) { ...@@ -226,20 +226,20 @@ void PrepareParameters(Graph* graph, const Param& param, ir::Node* lstm_op) {
IR_NODE(LSTMOUT); IR_NODE(LSTMOUT);
#undef IR_NODE #undef IR_NODE
#define GATE_W(name__) \ #define GATE_W(name__) \
auto* W_##name__##_w0 = scope.FindVar(#name__ ".w_0"); \ auto* W_##name__##_w0 = scope.FindVar(#name__ ".w_0"); \
auto* W_##name__##_w1 = scope.FindVar(#name__ ".w_1"); \ auto* W_##name__##_w1 = scope.FindVar(#name__ ".w_1"); \
auto* W_##name__##_b0 = scope.FindVar(#name__ ".b_0"); \ auto* W_##name__##_b0 = scope.FindVar(#name__ ".b_0"); \
CHECK_P3(W_##name__##_w0, W_##name__##_w1, W_##name__##_b0); \ CHECK_P3(W_##name__##_w0, W_##name__##_w1, W_##name__##_b0); \
VLOG(4) << #name__ "_w0" \ VLOG(4) << #name__ "_w0" \
<< " shape: " << W_##name__##_w0->Get<LoDTensor>().dims(); \ << " shape: " << W_##name__##_w0->Get<phi::DenseTensor>().dims(); \
VLOG(4) << #name__ "_w1" \ VLOG(4) << #name__ "_w1" \
<< " shape: " << W_##name__##_w1->Get<LoDTensor>().dims(); \ << " shape: " << W_##name__##_w1->Get<phi::DenseTensor>().dims(); \
VLOG(4) << #name__ "_b0" \ VLOG(4) << #name__ "_b0" \
<< " shape: " << W_##name__##_b0->Get<LoDTensor>().dims(); \ << " shape: " << W_##name__##_b0->Get<phi::DenseTensor>().dims(); \
auto& W_##name__##_w0_t = W_##name__##_w0->Get<LoDTensor>(); \ auto& W_##name__##_w0_t = W_##name__##_w0->Get<phi::DenseTensor>(); \
auto& W_##name__##_w1_t = W_##name__##_w1->Get<LoDTensor>(); \ auto& W_##name__##_w1_t = W_##name__##_w1->Get<phi::DenseTensor>(); \
auto& W_##name__##_b0_t = W_##name__##_b0->Get<LoDTensor>(); auto& W_##name__##_b0_t = W_##name__##_b0->Get<phi::DenseTensor>();
GATE_W(forget); GATE_W(forget);
GATE_W(input); GATE_W(input);
...@@ -255,13 +255,13 @@ void PrepareParameters(Graph* graph, const Param& param, ir::Node* lstm_op) { ...@@ -255,13 +255,13 @@ void PrepareParameters(Graph* graph, const Param& param, ir::Node* lstm_op) {
attention_fc_w, attention_fc_b, attention_output_w, attention_output_b); attention_fc_w, attention_fc_b, attention_output_w, attention_output_b);
auto* lstm_weight = scope.Var(param.LSTMWeight); auto* lstm_weight = scope.Var(param.LSTMWeight);
auto* lstm_weight_t = lstm_weight->GetMutable<LoDTensor>(); auto* lstm_weight_t = lstm_weight->GetMutable<phi::DenseTensor>();
auto* lstm_bias = scope.Var(param.LSTMBias); auto* lstm_bias = scope.Var(param.LSTMBias);
auto* lstm_bias_t = lstm_bias->GetMutable<LoDTensor>(); auto* lstm_bias_t = lstm_bias->GetMutable<phi::DenseTensor>();
// reshape attention_bias // reshape attention_bias
auto* attention_bias_t = auto* attention_bias_t =
scope.FindVar(param.AttentionBias)->GetMutable<LoDTensor>(); scope.FindVar(param.AttentionBias)->GetMutable<phi::DenseTensor>();
PADDLE_ENFORCE_EQ( PADDLE_ENFORCE_EQ(
attention_bias_t->dims().size(), attention_bias_t->dims().size(),
1, 1,
...@@ -271,7 +271,7 @@ void PrepareParameters(Graph* graph, const Param& param, ir::Node* lstm_op) { ...@@ -271,7 +271,7 @@ void PrepareParameters(Graph* graph, const Param& param, ir::Node* lstm_op) {
attention_bias_t->Resize(phi::make_ddim({1, attention_bias_t->dims()[0]})); attention_bias_t->Resize(phi::make_ddim({1, attention_bias_t->dims()[0]}));
auto* attention_scalar_bias_t = auto* attention_scalar_bias_t =
scope.FindVar(param.AttentionScalarBias)->GetMutable<LoDTensor>(); scope.FindVar(param.AttentionScalarBias)->GetMutable<phi::DenseTensor>();
attention_scalar_bias_t->Resize( attention_scalar_bias_t->Resize(
phi::make_ddim({1, attention_scalar_bias_t->dims()[0]})); phi::make_ddim({1, attention_scalar_bias_t->dims()[0]}));
...@@ -289,15 +289,15 @@ void PrepareParameters(Graph* graph, const Param& param, ir::Node* lstm_op) { ...@@ -289,15 +289,15 @@ void PrepareParameters(Graph* graph, const Param& param, ir::Node* lstm_op) {
} }
// Prepare parameters // Prepare parameters
void PrepareLSTMWeight(const LoDTensor& W_forget_w0, void PrepareLSTMWeight(const phi::DenseTensor& W_forget_w0,
const LoDTensor& W_forget_w1, const phi::DenseTensor& W_forget_w1,
const LoDTensor& W_input_w0, const phi::DenseTensor& W_input_w0,
const LoDTensor& W_input_w1, const phi::DenseTensor& W_input_w1,
const LoDTensor& W_output_w0, const phi::DenseTensor& W_output_w0,
const LoDTensor& W_output_w1, const phi::DenseTensor& W_output_w1,
const LoDTensor& W_cell_w0, const phi::DenseTensor& W_cell_w0,
const LoDTensor& W_cell_w1, const phi::DenseTensor& W_cell_w1,
LoDTensor* out) { phi::DenseTensor* out) {
int D = W_forget_w0.dims()[0]; int D = W_forget_w0.dims()[0];
int M = W_forget_w1.dims()[0]; int M = W_forget_w1.dims()[0];
out->Resize(phi::make_ddim({D + M, 4 * D})); out->Resize(phi::make_ddim({D + M, 4 * D}));
...@@ -330,11 +330,11 @@ void PrepareLSTMWeight(const LoDTensor& W_forget_w0, ...@@ -330,11 +330,11 @@ void PrepareLSTMWeight(const LoDTensor& W_forget_w0,
} }
} }
void PrepareLSTMBias(const LoDTensor& B_forget, void PrepareLSTMBias(const phi::DenseTensor& B_forget,
const LoDTensor& B_input, const phi::DenseTensor& B_input,
const LoDTensor& B_output, const phi::DenseTensor& B_output,
const LoDTensor& B_cell, const phi::DenseTensor& B_cell,
LoDTensor* out) { phi::DenseTensor* out) {
std::array<const float*, 4> tensors{B_forget.data<float>(), std::array<const float*, 4> tensors{B_forget.data<float>(),
B_input.data<float>(), B_input.data<float>(),
B_output.data<float>(), B_output.data<float>(),
......
...@@ -175,10 +175,11 @@ class CoalesceGradTensorPass : public ir::Pass { ...@@ -175,10 +175,11 @@ class CoalesceGradTensorPass : public ir::Pass {
p_g.second)); p_g.second));
pinned_var_set->insert(it->Var()->Name()); pinned_var_set->insert(it->Var()->Name());
} }
PADDLE_ENFORCE_EQ(IsLoDTensorType(GetTypeOfVar(vars_info, p_g.second)), PADDLE_ENFORCE_EQ(
true, IsLoDTensorType(GetTypeOfVar(vars_info, p_g.second)),
platform::errors::InvalidArgument( true,
"Parameter@Grad %s is not LoDTensor.", p_g.second)); platform::errors::InvalidArgument(
"Parameter@Grad %s is not phi::DenseTensor.", p_g.second));
} }
} }
......
...@@ -107,15 +107,16 @@ void ConstantFoldingPass::ApplyImpl(ir::Graph *graph) const { ...@@ -107,15 +107,16 @@ void ConstantFoldingPass::ApplyImpl(ir::Graph *graph) const {
if (input_persis) { if (input_persis) {
for (auto in_node : op_node->inputs) { for (auto in_node : op_node->inputs) {
local_scope->Var(in_node->Var()->Name()); local_scope->Var(in_node->Var()->Name());
local_scope->FindVar(in_node->Var()->Name())->GetMutable<LoDTensor>(); local_scope->FindVar(in_node->Var()->Name())
->GetMutable<phi::DenseTensor>();
// This persistable input node is exclusive, and can be removed // This persistable input node is exclusive, and can be removed
if (in_node->outputs.size() == 1L) remove_nodes.emplace(in_node); if (in_node->outputs.size() == 1L) remove_nodes.emplace(in_node);
auto in_shape = in_node->Var()->GetShape(); auto in_shape = in_node->Var()->GetShape();
auto *global_persis_x_tensor = auto *global_persis_x_tensor =
scope->FindVar(in_node->Name())->GetMutable<LoDTensor>(); scope->FindVar(in_node->Name())->GetMutable<phi::DenseTensor>();
auto *local_x_tensor = auto *local_x_tensor = local_scope->FindVar(in_node->Name())
local_scope->FindVar(in_node->Name())->GetMutable<LoDTensor>(); ->GetMutable<phi::DenseTensor>();
local_x_tensor->Resize(global_persis_x_tensor->dims()); local_x_tensor->Resize(global_persis_x_tensor->dims());
*local_x_tensor = *global_persis_x_tensor; *local_x_tensor = *global_persis_x_tensor;
} }
...@@ -124,7 +125,8 @@ void ConstantFoldingPass::ApplyImpl(ir::Graph *graph) const { ...@@ -124,7 +125,8 @@ void ConstantFoldingPass::ApplyImpl(ir::Graph *graph) const {
remove_nodes.emplace(op_node); remove_nodes.emplace(op_node);
for (auto out_node : op_node->outputs) { for (auto out_node : op_node->outputs) {
local_scope->Var(out_node->Var()->Name()); local_scope->Var(out_node->Var()->Name());
local_scope->FindVar(out_node->Var()->Name())->GetMutable<LoDTensor>(); local_scope->FindVar(out_node->Var()->Name())
->GetMutable<phi::DenseTensor>();
// useless out_node can be removed, not need set it persistable ! // useless out_node can be removed, not need set it persistable !
if (out_node->outputs.size() == 0L) remove_nodes.emplace(out_node); if (out_node->outputs.size() == 0L) remove_nodes.emplace(out_node);
} }
...@@ -135,14 +137,15 @@ void ConstantFoldingPass::ApplyImpl(ir::Graph *graph) const { ...@@ -135,14 +137,15 @@ void ConstantFoldingPass::ApplyImpl(ir::Graph *graph) const {
auto out_desc = out_node->Var(); auto out_desc = out_node->Var();
auto out_name = out_desc->Name(); auto out_name = out_desc->Name();
auto *local_out_tensor = auto *local_out_tensor =
local_scope->FindVar(out_name)->GetMutable<LoDTensor>(); local_scope->FindVar(out_name)->GetMutable<phi::DenseTensor>();
std::vector<int64_t> out_shape; std::vector<int64_t> out_shape;
for (int64_t i = 0; i < local_out_tensor->dims().size(); i++) { for (int64_t i = 0; i < local_out_tensor->dims().size(); i++) {
out_shape.push_back(local_out_tensor->dims()[i]); out_shape.push_back(local_out_tensor->dims()[i]);
} }
out_desc->SetShape(out_shape); out_desc->SetShape(out_shape);
out_desc->SetPersistable(true); out_desc->SetPersistable(true);
auto *global_out_tensor = scope->Var(out_name)->GetMutable<LoDTensor>(); auto *global_out_tensor =
scope->Var(out_name)->GetMutable<phi::DenseTensor>();
*global_out_tensor = *local_out_tensor; *global_out_tensor = *local_out_tensor;
} }
GraphSafeRemoveNodes(graph, remove_nodes); GraphSafeRemoveNodes(graph, remove_nodes);
......
...@@ -77,12 +77,12 @@ namespace ir { ...@@ -77,12 +77,12 @@ namespace ir {
GET_IR_NODE_FROM_SUBGRAPH(bn_saved_variance, bn_saved_variance, pattern_name) GET_IR_NODE_FROM_SUBGRAPH(bn_saved_variance, bn_saved_variance, pattern_name)
void recompute_bias_and_weights(const Scope* scope, void recompute_bias_and_weights(const Scope* scope,
ir::Node* conv_weight, // ir::Node* conv_weight, //
const ir::Node& bn_scale, // const ir::Node& bn_scale, //
const LoDTensor& bn_bias_tensor, // const phi::DenseTensor& bn_bias_tensor, //
const ir::Node& bn_mean, // const ir::Node& bn_mean, //
const ir::Node& bn_variance, // const ir::Node& bn_variance, //
LoDTensor* eltwise_y_in_tensor, // phi::DenseTensor* eltwise_y_in_tensor, //
float epsilon, float epsilon,
const std::string& conv_type) { const std::string& conv_type) {
using EigenVectorArrayMap = using EigenVectorArrayMap =
...@@ -101,10 +101,12 @@ void recompute_bias_and_weights(const Scope* scope, ...@@ -101,10 +101,12 @@ void recompute_bias_and_weights(const Scope* scope,
eltwise_y_in_tensor->dims().size(), eltwise_y_in_tensor->dims().size(),
bn_bias_tensor.dims().size())); bn_bias_tensor.dims().size()));
auto* scale_tensor = scope->FindVar(bn_scale.Name())->GetMutable<LoDTensor>(); auto* scale_tensor =
scope->FindVar(bn_scale.Name())->GetMutable<phi::DenseTensor>();
auto* variance_tensor = auto* variance_tensor =
scope->FindVar(bn_variance.Name())->GetMutable<LoDTensor>(); scope->FindVar(bn_variance.Name())->GetMutable<phi::DenseTensor>();
auto* mean_tensor = scope->FindVar(bn_mean.Name())->GetMutable<LoDTensor>(); auto* mean_tensor =
scope->FindVar(bn_mean.Name())->GetMutable<phi::DenseTensor>();
ConstEigenVectorArrayMap scale_array( ConstEigenVectorArrayMap scale_array(
scale_tensor->data<float>(), scale_tensor->numel(), 1); scale_tensor->data<float>(), scale_tensor->numel(), 1);
...@@ -148,7 +150,8 @@ void recompute_bias_and_weights(const Scope* scope, ...@@ -148,7 +150,8 @@ void recompute_bias_and_weights(const Scope* scope,
} }
// Re-compute weight of conv2d from BN // Re-compute weight of conv2d from BN
auto* weights = scope->FindVar(conv_weight->Name())->GetMutable<LoDTensor>(); auto* weights =
scope->FindVar(conv_weight->Name())->GetMutable<phi::DenseTensor>();
auto weights_shape = weights->dims(); auto weights_shape = weights->dims();
auto weights_data = weights->mutable_data<float>(platform::CPUPlace()); auto weights_data = weights->mutable_data<float>(platform::CPUPlace());
...@@ -308,7 +311,7 @@ void ConvBNFusePass::ApplyImpl(ir::Graph* graph) const { ...@@ -308,7 +311,7 @@ void ConvBNFusePass::ApplyImpl(ir::Graph* graph) const {
// conv_weight fp32 --> fp16 // conv_weight fp32 --> fp16
auto* conv_weight_tensor = auto* conv_weight_tensor =
scope->FindVar(conv_weight->Name())->GetMutable<LoDTensor>(); scope->FindVar(conv_weight->Name())->GetMutable<phi::DenseTensor>();
auto tensor_type = conv_weight_tensor->dtype(); auto tensor_type = conv_weight_tensor->dtype();
if (tensor_type == paddle::experimental::DataType::FLOAT16) { if (tensor_type == paddle::experimental::DataType::FLOAT16) {
...@@ -317,7 +320,7 @@ void ConvBNFusePass::ApplyImpl(ir::Graph* graph) const { ...@@ -317,7 +320,7 @@ void ConvBNFusePass::ApplyImpl(ir::Graph* graph) const {
// Get batch norm bias // Get batch norm bias
auto* bn_bias_tensor = auto* bn_bias_tensor =
scope->FindVar(bn_bias->Name())->GetMutable<LoDTensor>(); scope->FindVar(bn_bias->Name())->GetMutable<phi::DenseTensor>();
// Create eltwise_y (conv bias) variable // Create eltwise_y (conv bias) variable
VarDesc eltwise_y_in_desc( VarDesc eltwise_y_in_desc(
...@@ -329,7 +332,7 @@ void ConvBNFusePass::ApplyImpl(ir::Graph* graph) const { ...@@ -329,7 +332,7 @@ void ConvBNFusePass::ApplyImpl(ir::Graph* graph) const {
eltwise_y_in_desc.SetPersistable(true); eltwise_y_in_desc.SetPersistable(true);
auto* eltwise_y_in_node = g->CreateVarNode(&eltwise_y_in_desc); auto* eltwise_y_in_node = g->CreateVarNode(&eltwise_y_in_desc);
auto* eltwise_y_in_tensor = auto* eltwise_y_in_tensor =
scope->Var(eltwise_y_in_node->Name())->GetMutable<LoDTensor>(); scope->Var(eltwise_y_in_node->Name())->GetMutable<phi::DenseTensor>();
// Initialize eltwise_y // Initialize eltwise_y
eltwise_y_in_tensor->Resize(bn_bias_tensor->dims()); eltwise_y_in_tensor->Resize(bn_bias_tensor->dims());
...@@ -370,7 +373,7 @@ void ConvBNFusePass::ApplyImpl(ir::Graph* graph) const { ...@@ -370,7 +373,7 @@ void ConvBNFusePass::ApplyImpl(ir::Graph* graph) const {
1UL, 1UL,
platform::errors::InvalidArgument("Find input var Bais error.")); platform::errors::InvalidArgument("Find input var Bais error."));
auto* conv_bias_var = scope->FindVar(conv_bias_names[0]); auto* conv_bias_var = scope->FindVar(conv_bias_names[0]);
auto* conv_bias_tensor = conv_bias_var->GetMutable<LoDTensor>(); auto* conv_bias_tensor = conv_bias_var->GetMutable<phi::DenseTensor>();
PADDLE_ENFORCE_EQ( PADDLE_ENFORCE_EQ(
conv_bias_tensor->dims(), conv_bias_tensor->dims(),
eltwise_y_in_tensor->dims(), eltwise_y_in_tensor->dims(),
...@@ -580,11 +583,11 @@ void ConvEltwiseAddBNFusePass::ApplyImpl(ir::Graph* graph) const { ...@@ -580,11 +583,11 @@ void ConvEltwiseAddBNFusePass::ApplyImpl(ir::Graph* graph) const {
// Get eltwise_y (conv bias) variable // Get eltwise_y (conv bias) variable
auto* eltwise_y_in_tensor = auto* eltwise_y_in_tensor =
scope->FindVar(eltwise_y_in->Name())->GetMutable<LoDTensor>(); scope->FindVar(eltwise_y_in->Name())->GetMutable<phi::DenseTensor>();
// Get batch norm bias // Get batch norm bias
auto* bn_bias_tensor = auto* bn_bias_tensor =
scope->FindVar(bn_bias->Name())->GetMutable<LoDTensor>(); scope->FindVar(bn_bias->Name())->GetMutable<phi::DenseTensor>();
// update weights and biases // update weights and biases
float epsilon = float epsilon =
...@@ -592,7 +595,7 @@ void ConvEltwiseAddBNFusePass::ApplyImpl(ir::Graph* graph) const { ...@@ -592,7 +595,7 @@ void ConvEltwiseAddBNFusePass::ApplyImpl(ir::Graph* graph) const {
// conv_weight fp16 --> fp32 // conv_weight fp16 --> fp32
auto* conv_weight_tensor = auto* conv_weight_tensor =
scope->FindVar(conv_weight->Name())->GetMutable<LoDTensor>(); scope->FindVar(conv_weight->Name())->GetMutable<phi::DenseTensor>();
auto tensor_type = conv_weight_tensor->dtype(); auto tensor_type = conv_weight_tensor->dtype();
if (tensor_type == paddle::experimental::DataType::FLOAT16) { if (tensor_type == paddle::experimental::DataType::FLOAT16) {
...@@ -614,7 +617,7 @@ void ConvEltwiseAddBNFusePass::ApplyImpl(ir::Graph* graph) const { ...@@ -614,7 +617,7 @@ void ConvEltwiseAddBNFusePass::ApplyImpl(ir::Graph* graph) const {
eltwise_y_in_desc.SetPersistable(true); eltwise_y_in_desc.SetPersistable(true);
auto* eltwise_y_in_node = g->CreateVarNode(&eltwise_y_in_desc); auto* eltwise_y_in_node = g->CreateVarNode(&eltwise_y_in_desc);
auto* eltwise_y_in_tensor_ex = auto* eltwise_y_in_tensor_ex =
scope->Var(eltwise_y_in_node->Name())->GetMutable<LoDTensor>(); scope->Var(eltwise_y_in_node->Name())->GetMutable<phi::DenseTensor>();
// Initialize eltwise_y // Initialize eltwise_y
TensorCopy( TensorCopy(
......
...@@ -30,7 +30,7 @@ namespace ir { ...@@ -30,7 +30,7 @@ namespace ir {
void AddVarToScope(Scope* param_scope, void AddVarToScope(Scope* param_scope,
const std::string& name, const std::string& name,
const DDim& dims) { const DDim& dims) {
auto* tensor = param_scope->Var(name)->GetMutable<LoDTensor>(); auto* tensor = param_scope->Var(name)->GetMutable<phi::DenseTensor>();
tensor->Resize(dims); tensor->Resize(dims);
tensor->mutable_data<float>(platform::CPUPlace()); tensor->mutable_data<float>(platform::CPUPlace());
} }
......
...@@ -49,7 +49,7 @@ class FakeTestOp : public OperatorBase { ...@@ -49,7 +49,7 @@ class FakeTestOp : public OperatorBase {
// Fake RunImpl, for test only // Fake RunImpl, for test only
Variable *var = scope.FindVar("X"); Variable *var = scope.FindVar("X");
if (var != nullptr) { if (var != nullptr) {
LoDTensor *tensor = var->GetMutable<LoDTensor>(); phi::DenseTensor *tensor = var->GetMutable<phi::DenseTensor>();
tensor->mutable_data<float>(place); tensor->mutable_data<float>(place);
} }
int count = 0; int count = 0;
......
...@@ -21,7 +21,7 @@ namespace framework { ...@@ -21,7 +21,7 @@ namespace framework {
namespace ir { namespace ir {
template <typename T> template <typename T>
void FillConstData(LoDTensor* out_t, T value) { void FillConstData(phi::DenseTensor* out_t, T value) {
auto output_data = out_t->mutable_data<T>(platform::CPUPlace()); auto output_data = out_t->mutable_data<T>(platform::CPUPlace());
for (int i = 0; i < out_t->numel(); i++) { for (int i = 0; i < out_t->numel(); i++) {
output_data[i] = value; output_data[i] = value;
...@@ -70,8 +70,8 @@ void DeleteFillConstantOpPass::ApplyImpl(ir::Graph* graph) const { ...@@ -70,8 +70,8 @@ void DeleteFillConstantOpPass::ApplyImpl(ir::Graph* graph) const {
auto fill_constant_out_desc = fill_constant_out_node->Var(); auto fill_constant_out_desc = fill_constant_out_node->Var();
fill_constant_out_desc->SetShape(shape); fill_constant_out_desc->SetShape(shape);
fill_constant_out_desc->SetPersistable(true); fill_constant_out_desc->SetPersistable(true);
auto* fill_constant_out_tensor = auto* fill_constant_out_tensor = scope->Var(fill_constant_out_desc->Name())
scope->Var(fill_constant_out_desc->Name())->GetMutable<LoDTensor>(); ->GetMutable<phi::DenseTensor>();
auto dtype = auto dtype =
framework::TransToPhiDataType(fill_constant_out_desc->GetDataType()); framework::TransToPhiDataType(fill_constant_out_desc->GetDataType());
fill_constant_out_tensor->Resize(phi::make_ddim(shape)); fill_constant_out_tensor->Resize(phi::make_ddim(shape));
......
...@@ -123,8 +123,8 @@ void DeleteQuantDequantFilterOpPass::ApplyImpl(ir::Graph* graph) const { ...@@ -123,8 +123,8 @@ void DeleteQuantDequantFilterOpPass::ApplyImpl(ir::Graph* graph) const {
auto dequant_type = quant_dequant_op->Op()->Type(); auto dequant_type = quant_dequant_op->Op()->Type();
// get weight tensor // get weight tensor
auto* weight_tensor = auto* weight_tensor = scope->GetVar(quant_dequant_op_x->Name())
scope->GetVar(quant_dequant_op_x->Name())->GetMutable<LoDTensor>(); ->GetMutable<phi::DenseTensor>();
auto w_dims = weight_tensor->dims(); auto w_dims = weight_tensor->dims();
float* quantized_weight_data = float* quantized_weight_data =
...@@ -148,8 +148,8 @@ void DeleteQuantDequantFilterOpPass::ApplyImpl(ir::Graph* graph) const { ...@@ -148,8 +148,8 @@ void DeleteQuantDequantFilterOpPass::ApplyImpl(ir::Graph* graph) const {
"Scales size in channel-wise quant dequantize op " "Scales size in channel-wise quant dequantize op "
"should be 1, got %d.", "should be 1, got %d.",
scales_name.size())); scales_name.size()));
const LoDTensor& channel_scale_tensor = const phi::DenseTensor& channel_scale_tensor =
scope->FindVar(scales_name[0])->Get<LoDTensor>(); scope->FindVar(scales_name[0])->Get<phi::DenseTensor>();
PADDLE_ENFORCE( PADDLE_ENFORCE(
paddle::platform::is_cpu_place(channel_scale_tensor.place()), paddle::platform::is_cpu_place(channel_scale_tensor.place()),
platform::errors::InvalidArgument( platform::errors::InvalidArgument(
......
...@@ -113,8 +113,9 @@ void DeleteQuantDequantLinearOpPass::ApplyImpl(ir::Graph* graph) const { ...@@ -113,8 +113,9 @@ void DeleteQuantDequantLinearOpPass::ApplyImpl(ir::Graph* graph) const {
std::unordered_set<const Node*> nodes2rm = {}; std::unordered_set<const Node*> nodes2rm = {};
// Get input scale from tensor // Get input scale from tensor
const LoDTensor& input_scale_tensor = const phi::DenseTensor& input_scale_tensor =
scope->GetVar(quantize_linear_op_scale->Name())->Get<LoDTensor>(); scope->GetVar(quantize_linear_op_scale->Name())
->Get<phi::DenseTensor>();
PADDLE_ENFORCE_EQ( PADDLE_ENFORCE_EQ(
paddle::platform::is_cpu_place(input_scale_tensor.place()), paddle::platform::is_cpu_place(input_scale_tensor.place()),
true, true,
......
...@@ -70,8 +70,8 @@ void DeleteQuantDequantOpPass::ApplyImpl(ir::Graph* graph) const { ...@@ -70,8 +70,8 @@ void DeleteQuantDequantOpPass::ApplyImpl(ir::Graph* graph) const {
scope, scope,
platform::errors::InvalidArgument( platform::errors::InvalidArgument(
"Scope in DeleteQuantDequantOpPass should not be null.")); "Scope in DeleteQuantDequantOpPass should not be null."));
const LoDTensor& input_scale_tensor = const phi::DenseTensor& input_scale_tensor =
scope->FindVar(input_scale_var_name)->Get<LoDTensor>(); scope->FindVar(input_scale_var_name)->Get<phi::DenseTensor>();
PADDLE_ENFORCE_EQ( PADDLE_ENFORCE_EQ(
paddle::platform::is_cpu_place(input_scale_tensor.place()), paddle::platform::is_cpu_place(input_scale_tensor.place()),
true, true,
......
...@@ -305,7 +305,7 @@ void DeleteWeightQuantDequantLinearOpPass::ApplyImpl(ir::Graph* graph) const { ...@@ -305,7 +305,7 @@ void DeleteWeightQuantDequantLinearOpPass::ApplyImpl(ir::Graph* graph) const {
// get weight tensor // get weight tensor
auto* weight_tensor = scope->GetVar(weight_dequantize_linear_op_x->Name()) auto* weight_tensor = scope->GetVar(weight_dequantize_linear_op_x->Name())
->GetMutable<LoDTensor>(); ->GetMutable<phi::DenseTensor>();
int8_t* quantized_weight_data = int8_t* quantized_weight_data =
weight_tensor->mutable_data<int8_t>(platform::CPUPlace()); weight_tensor->mutable_data<int8_t>(platform::CPUPlace());
auto w_dims = weight_tensor->dims(); auto w_dims = weight_tensor->dims();
...@@ -314,7 +314,7 @@ void DeleteWeightQuantDequantLinearOpPass::ApplyImpl(ir::Graph* graph) const { ...@@ -314,7 +314,7 @@ void DeleteWeightQuantDequantLinearOpPass::ApplyImpl(ir::Graph* graph) const {
std::vector<float> weight_scale; std::vector<float> weight_scale;
auto* weight_scale_tensor = auto* weight_scale_tensor =
scope->GetVar(weight_dequantize_linear_op_scale->Name()) scope->GetVar(weight_dequantize_linear_op_scale->Name())
->GetMutable<LoDTensor>(); ->GetMutable<phi::DenseTensor>();
float* weight_scale_data = float* weight_scale_data =
weight_scale_tensor->mutable_data<float>(platform::CPUPlace()); weight_scale_tensor->mutable_data<float>(platform::CPUPlace());
......
...@@ -25,7 +25,7 @@ namespace ir { ...@@ -25,7 +25,7 @@ namespace ir {
void AddVarToScope(Scope* param_scope, void AddVarToScope(Scope* param_scope,
const std::string& name, const std::string& name,
const DDim& dims) { const DDim& dims) {
auto* tensor = param_scope->Var(name)->GetMutable<LoDTensor>(); auto* tensor = param_scope->Var(name)->GetMutable<phi::DenseTensor>();
tensor->Resize(dims); tensor->Resize(dims);
tensor->mutable_data<float>(platform::CPUPlace()); tensor->mutable_data<float>(platform::CPUPlace());
} }
......
...@@ -23,7 +23,7 @@ namespace ir { ...@@ -23,7 +23,7 @@ namespace ir {
void AddVarToScope(Scope* param_scope, void AddVarToScope(Scope* param_scope,
const std::string& name, const std::string& name,
const DDim& dims) { const DDim& dims) {
auto* tensor = param_scope->Var(name)->GetMutable<LoDTensor>(); auto* tensor = param_scope->Var(name)->GetMutable<phi::DenseTensor>();
tensor->Resize(dims); tensor->Resize(dims);
tensor->mutable_data<float>(platform::CPUPlace()); tensor->mutable_data<float>(platform::CPUPlace());
} }
......
...@@ -195,7 +195,7 @@ int FCFusePass::ApplyFCPattern(Graph* graph, bool with_relu) const { ...@@ -195,7 +195,7 @@ int FCFusePass::ApplyFCPattern(Graph* graph, bool with_relu) const {
auto* w_node = g->CreateVarNode(&w_key); auto* w_node = g->CreateVarNode(&w_key);
if (!use_gpu && use_fc_padding) { if (!use_gpu && use_fc_padding) {
auto* scope = param_scope(); auto* scope = param_scope();
auto* weight = scope->FindVar(w->Name())->GetMutable<LoDTensor>(); auto* weight = scope->FindVar(w->Name())->GetMutable<phi::DenseTensor>();
auto* weight_data = weight->data<float>(); auto* weight_data = weight->data<float>();
auto weight_dims = weight->dims(); auto weight_dims = weight->dims();
int weight_num = product(weight_dims); int weight_num = product(weight_dims);
......
...@@ -24,7 +24,7 @@ namespace ir { ...@@ -24,7 +24,7 @@ namespace ir {
void AddVarToScope(Scope* param_scope, void AddVarToScope(Scope* param_scope,
const std::string& name, const std::string& name,
const DDim& dims) { const DDim& dims) {
auto* tensor = param_scope->Var(name)->GetMutable<LoDTensor>(); auto* tensor = param_scope->Var(name)->GetMutable<phi::DenseTensor>();
tensor->Resize(dims); tensor->Resize(dims);
tensor->mutable_data<float>(platform::CPUPlace()); tensor->mutable_data<float>(platform::CPUPlace());
} }
......
...@@ -228,8 +228,8 @@ int FCGRUFusePass::BuildFusion(Graph* graph, ...@@ -228,8 +228,8 @@ int FCGRUFusePass::BuildFusion(Graph* graph,
nullptr, nullptr,
platform::errors::NotFound("FC bias var has not been found.")); platform::errors::NotFound("FC bias var has not been found."));
auto* gru_bias_tensor = gru_bias_var->GetMutable<LoDTensor>(); auto* gru_bias_tensor = gru_bias_var->GetMutable<phi::DenseTensor>();
auto* fc_bias_tensor = fc_bias_var->GetMutable<LoDTensor>(); auto* fc_bias_tensor = fc_bias_var->GetMutable<phi::DenseTensor>();
PADDLE_ENFORCE_EQ( PADDLE_ENFORCE_EQ(
gru_bias_tensor->numel(), gru_bias_tensor->numel(),
fc_bias_tensor->numel(), fc_bias_tensor->numel(),
......
...@@ -26,7 +26,7 @@ namespace fc_gru_test { ...@@ -26,7 +26,7 @@ namespace fc_gru_test {
void AddVarToScope(Scope* param_scope, void AddVarToScope(Scope* param_scope,
const std::string& name, const std::string& name,
const DDim& dims) { const DDim& dims) {
auto* tensor = param_scope->Var(name)->GetMutable<LoDTensor>(); auto* tensor = param_scope->Var(name)->GetMutable<phi::DenseTensor>();
tensor->Resize(dims); tensor->Resize(dims);
tensor->mutable_data<float>(platform::CPUPlace()); tensor->mutable_data<float>(platform::CPUPlace());
} }
......
...@@ -28,7 +28,7 @@ namespace fc_lstm_test { ...@@ -28,7 +28,7 @@ namespace fc_lstm_test {
void AddVarToScope(Scope* param_scope, void AddVarToScope(Scope* param_scope,
const std::string& name, const std::string& name,
const DDim& dims) { const DDim& dims) {
auto* tensor = param_scope->Var(name)->GetMutable<LoDTensor>(); auto* tensor = param_scope->Var(name)->GetMutable<phi::DenseTensor>();
tensor->Resize(dims); tensor->Resize(dims);
tensor->mutable_data<float>(platform::CPUPlace()); tensor->mutable_data<float>(platform::CPUPlace());
} }
......
...@@ -392,13 +392,13 @@ void FuseOptimizerOpPass::FuseGradientsToContinuousSpace( ...@@ -392,13 +392,13 @@ void FuseOptimizerOpPass::FuseGradientsToContinuousSpace(
iter->second.front()->Var(), iter->second.front()->Var(),
platform::errors::InvalidArgument("The gradient var(%s) node is null.", platform::errors::InvalidArgument("The gradient var(%s) node is null.",
grad_var_name)); grad_var_name));
PADDLE_ENFORCE_EQ( PADDLE_ENFORCE_EQ(IsLoDTensorType(iter->second.front()->Var()->GetType()),
IsLoDTensorType(iter->second.front()->Var()->GetType()), true,
true, platform::errors::InvalidArgument(
platform::errors::InvalidArgument( "Currently the gradient(%s) type only should be "
"Currently the gradient(%s) type only should be LoDTensor when " "phi::DenseTensor when "
"fusing optimizer ops.", "fusing optimizer ops.",
grad_var_name)); grad_var_name));
for (auto var : iter->second) { for (auto var : iter->second) {
pinned_var_set.insert(var->Var()->Name()); pinned_var_set.insert(var->Var()->Name());
} }
......
...@@ -22,7 +22,7 @@ namespace ir { ...@@ -22,7 +22,7 @@ namespace ir {
void AddVarToScope(Scope* param_scope, void AddVarToScope(Scope* param_scope,
const std::string& name, const std::string& name,
const DDim& dims) { const DDim& dims) {
auto* tensor = param_scope->Var(name)->GetMutable<LoDTensor>(); auto* tensor = param_scope->Var(name)->GetMutable<phi::DenseTensor>();
tensor->Resize(dims); tensor->Resize(dims);
tensor->mutable_data<float>(platform::CPUPlace()); tensor->mutable_data<float>(platform::CPUPlace());
} }
......
...@@ -1100,12 +1100,12 @@ PDNode* MultiDevicesFusedMultiTransformerEncoderFuseQKVPattern::operator()() { ...@@ -1100,12 +1100,12 @@ PDNode* MultiDevicesFusedMultiTransformerEncoderFuseQKVPattern::operator()() {
} // namespace patterns } // namespace patterns
template <typename T> template <typename T>
inline void QKVWeightsProcess(framework::LoDTensor* wq_tensor, inline void QKVWeightsProcess(phi::DenseTensor* wq_tensor,
framework::LoDTensor* wk_tensor, phi::DenseTensor* wk_tensor,
framework::LoDTensor* wv_tensor, phi::DenseTensor* wv_tensor,
framework::LoDTensor* bq_tensor, phi::DenseTensor* bq_tensor,
framework::LoDTensor* bk_tensor, phi::DenseTensor* bk_tensor,
framework::LoDTensor* bv_tensor, phi::DenseTensor* bv_tensor,
const int num_head, const int num_head,
const int dim_head, const int dim_head,
const int dim_embed) { const int dim_embed) {
...@@ -1119,7 +1119,7 @@ inline void QKVWeightsProcess(framework::LoDTensor* wq_tensor, ...@@ -1119,7 +1119,7 @@ inline void QKVWeightsProcess(framework::LoDTensor* wq_tensor,
auto combined_w_dims = phi::make_ddim({3, num_head, dim_head, dim_embed}); auto combined_w_dims = phi::make_ddim({3, num_head, dim_head, dim_embed});
auto combined_bias_dims = phi::make_ddim({3, num_head, dim_head}); auto combined_bias_dims = phi::make_ddim({3, num_head, dim_head});
framework::LoDTensor tmp_combined_w_tensor; phi::DenseTensor tmp_combined_w_tensor;
tmp_combined_w_tensor.Resize(combined_w_dims); tmp_combined_w_tensor.Resize(combined_w_dims);
auto* tmp_combined_w_data = auto* tmp_combined_w_data =
tmp_combined_w_tensor.mutable_data<T>(platform::CPUPlace()); tmp_combined_w_tensor.mutable_data<T>(platform::CPUPlace());
...@@ -1144,7 +1144,7 @@ inline void QKVWeightsProcess(framework::LoDTensor* wq_tensor, ...@@ -1144,7 +1144,7 @@ inline void QKVWeightsProcess(framework::LoDTensor* wq_tensor,
memcpy( memcpy(
new_combined_w_data, tmp_combined_w_data, sizeof(T) * wq_tensor->numel()); new_combined_w_data, tmp_combined_w_data, sizeof(T) * wq_tensor->numel());
framework::LoDTensor tmp_combined_bias_tensor; phi::DenseTensor tmp_combined_bias_tensor;
tmp_combined_bias_tensor.Resize(combined_bias_dims); tmp_combined_bias_tensor.Resize(combined_bias_dims);
auto* tmp_combined_bias_data = auto* tmp_combined_bias_data =
tmp_combined_bias_tensor.mutable_data<T>(platform::CPUPlace()); tmp_combined_bias_tensor.mutable_data<T>(platform::CPUPlace());
...@@ -1164,15 +1164,15 @@ inline void QKVWeightsProcess(framework::LoDTensor* wq_tensor, ...@@ -1164,15 +1164,15 @@ inline void QKVWeightsProcess(framework::LoDTensor* wq_tensor,
} }
template <typename T> template <typename T>
inline void QKVWeightsProcessFuseQKV(framework::LoDTensor* qkv_w_tensor, inline void QKVWeightsProcessFuseQKV(phi::DenseTensor* qkv_w_tensor,
framework::LoDTensor* qkv_b_tensor, phi::DenseTensor* qkv_b_tensor,
const int num_head, const int num_head,
const int dim_head, const int dim_head,
const int dim_embed) { const int dim_embed) {
auto* qkv_w_data = qkv_w_tensor->mutable_data<T>(platform::CPUPlace()); auto* qkv_w_data = qkv_w_tensor->mutable_data<T>(platform::CPUPlace());
auto transpose_w_dims = phi::make_ddim({3, num_head, dim_head, dim_embed}); auto transpose_w_dims = phi::make_ddim({3, num_head, dim_head, dim_embed});
framework::LoDTensor tmp_transpose_w_tensor; phi::DenseTensor tmp_transpose_w_tensor;
tmp_transpose_w_tensor.Resize(transpose_w_dims); tmp_transpose_w_tensor.Resize(transpose_w_dims);
auto* tmp_transpose_w_data = auto* tmp_transpose_w_data =
tmp_transpose_w_tensor.mutable_data<T>(platform::CPUPlace()); tmp_transpose_w_tensor.mutable_data<T>(platform::CPUPlace());
...@@ -1202,7 +1202,7 @@ inline void QKVWeightsProcessFuseQKV(framework::LoDTensor* qkv_w_tensor, ...@@ -1202,7 +1202,7 @@ inline void QKVWeightsProcessFuseQKV(framework::LoDTensor* qkv_w_tensor,
auto* qkv_b_data = qkv_b_tensor->mutable_data<T>(platform::CPUPlace()); auto* qkv_b_data = qkv_b_tensor->mutable_data<T>(platform::CPUPlace());
auto transpose_b_dims = phi::make_ddim({3, num_head, dim_head}); auto transpose_b_dims = phi::make_ddim({3, num_head, dim_head});
framework::LoDTensor tmp_transpose_b_tensor; phi::DenseTensor tmp_transpose_b_tensor;
tmp_transpose_b_tensor.Resize(transpose_b_dims); tmp_transpose_b_tensor.Resize(transpose_b_dims);
auto* tmp_transpose_b_data = auto* tmp_transpose_b_data =
tmp_transpose_b_tensor.mutable_data<T>(platform::CPUPlace()); tmp_transpose_b_tensor.mutable_data<T>(platform::CPUPlace());
...@@ -1289,18 +1289,18 @@ int FusedMultiTransformerEncoderPass::BuildFusion(Graph* graph, ...@@ -1289,18 +1289,18 @@ int FusedMultiTransformerEncoderPass::BuildFusion(Graph* graph,
int layer_idx = atoi(ln_idx_str.c_str()) / 2; int layer_idx = atoi(ln_idx_str.c_str()) / 2;
auto* wq_tensor = auto* wq_tensor =
scope->FindVar(matmul0_w->Name())->GetMutable<LoDTensor>(); scope->FindVar(matmul0_w->Name())->GetMutable<phi::DenseTensor>();
auto* wk_tensor = auto* wk_tensor =
scope->FindVar(matmul1_w->Name())->GetMutable<LoDTensor>(); scope->FindVar(matmul1_w->Name())->GetMutable<phi::DenseTensor>();
auto* wv_tensor = auto* wv_tensor =
scope->FindVar(matmul2_w->Name())->GetMutable<LoDTensor>(); scope->FindVar(matmul2_w->Name())->GetMutable<phi::DenseTensor>();
auto* bq_tensor = auto* bq_tensor =
scope->FindVar(eltadd0_b->Name())->GetMutable<LoDTensor>(); scope->FindVar(eltadd0_b->Name())->GetMutable<phi::DenseTensor>();
auto* bk_tensor = auto* bk_tensor =
scope->FindVar(eltadd1_b->Name())->GetMutable<LoDTensor>(); scope->FindVar(eltadd1_b->Name())->GetMutable<phi::DenseTensor>();
auto* bv_tensor = auto* bv_tensor =
scope->FindVar(eltadd2_b->Name())->GetMutable<LoDTensor>(); scope->FindVar(eltadd2_b->Name())->GetMutable<phi::DenseTensor>();
if (wq_tensor->dtype() == phi::DataType::FLOAT32) { if (wq_tensor->dtype() == phi::DataType::FLOAT32) {
QKVWeightsProcess<float>(wq_tensor, QKVWeightsProcess<float>(wq_tensor,
...@@ -2053,9 +2053,9 @@ int FusedMultiTransformerEncoderFuseQKVPass::BuildFusion( ...@@ -2053,9 +2053,9 @@ int FusedMultiTransformerEncoderFuseQKVPass::BuildFusion(
int layer_idx = atoi(ln_idx_str.c_str()) / 2; int layer_idx = atoi(ln_idx_str.c_str()) / 2;
auto* qkv_w_tensor = auto* qkv_w_tensor =
scope->FindVar(matmul0_w->Name())->GetMutable<LoDTensor>(); scope->FindVar(matmul0_w->Name())->GetMutable<phi::DenseTensor>();
auto* qkv_b_tensor = auto* qkv_b_tensor =
scope->FindVar(eltadd0_b->Name())->GetMutable<LoDTensor>(); scope->FindVar(eltadd0_b->Name())->GetMutable<phi::DenseTensor>();
if (qkv_w_tensor->dtype() == phi::DataType::FLOAT32) { if (qkv_w_tensor->dtype() == phi::DataType::FLOAT32) {
QKVWeightsProcessFuseQKV<float>( QKVWeightsProcessFuseQKV<float>(
...@@ -2736,9 +2736,9 @@ int MultiDevicesFusedMultiTransformerEncoderFuseQKVPass::BuildFusion( ...@@ -2736,9 +2736,9 @@ int MultiDevicesFusedMultiTransformerEncoderFuseQKVPass::BuildFusion(
int layer_idx = atoi(ln_idx_str.c_str()) / 2; int layer_idx = atoi(ln_idx_str.c_str()) / 2;
auto* qkv_w_tensor = auto* qkv_w_tensor =
scope->FindVar(matmul0_w->Name())->GetMutable<LoDTensor>(); scope->FindVar(matmul0_w->Name())->GetMutable<phi::DenseTensor>();
auto* qkv_b_tensor = auto* qkv_b_tensor =
scope->FindVar(eltadd0_b->Name())->GetMutable<LoDTensor>(); scope->FindVar(eltadd0_b->Name())->GetMutable<phi::DenseTensor>();
int dim_embed = qkv_w_tensor->dims()[0]; int dim_embed = qkv_w_tensor->dims()[0];
......
...@@ -22,7 +22,7 @@ namespace ir { ...@@ -22,7 +22,7 @@ namespace ir {
void AddVarToScope(Scope* param_scope, void AddVarToScope(Scope* param_scope,
const std::string& name, const std::string& name,
const DDim& dims) { const DDim& dims) {
auto* tensor = param_scope->Var(name)->GetMutable<LoDTensor>(); auto* tensor = param_scope->Var(name)->GetMutable<phi::DenseTensor>();
tensor->Resize(dims); tensor->Resize(dims);
tensor->mutable_data<float>(platform::CPUPlace()); tensor->mutable_data<float>(platform::CPUPlace());
} }
......
...@@ -89,7 +89,7 @@ inline float elementwise_mul_grad_dy(float x, float y, float out, float dout) { ...@@ -89,7 +89,7 @@ inline float elementwise_mul_grad_dy(float x, float y, float out, float dout) {
} }
void CheckOutput(const std::vector<OperationExpression>& expressions, void CheckOutput(const std::vector<OperationExpression>& expressions,
const std::vector<LoDTensor> cpu_tensors, const std::vector<phi::DenseTensor> cpu_tensors,
const std::vector<int> input_ids_of_subgraph, const std::vector<int> input_ids_of_subgraph,
const std::vector<int> output_ids_of_subgraph, const std::vector<int> output_ids_of_subgraph,
int i, int i,
...@@ -152,7 +152,7 @@ void CheckOutput(const std::vector<OperationExpression>& expressions, ...@@ -152,7 +152,7 @@ void CheckOutput(const std::vector<OperationExpression>& expressions,
} }
template <typename T> template <typename T>
void SetupRandomCPUTensor(LoDTensor* tensor) { void SetupRandomCPUTensor(phi::DenseTensor* tensor) {
static unsigned int seed = 100; static unsigned int seed = 100;
std::mt19937 rng(seed++); std::mt19937 rng(seed++);
std::uniform_real_distribution<double> uniform_dist(0, 1); std::uniform_real_distribution<double> uniform_dist(0, 1);
......
...@@ -267,7 +267,8 @@ void LayerNormFusePass::ApplyImpl(Graph* graph) const { ...@@ -267,7 +267,8 @@ void LayerNormFusePass::ApplyImpl(Graph* graph) const {
GET_IR_NODE_FROM_SUBGRAPH(shift, shift, layer_norm_pattern); GET_IR_NODE_FROM_SUBGRAPH(shift, shift, layer_norm_pattern);
GET_IR_NODE_FROM_SUBGRAPH(shift_out, shift_out, layer_norm_pattern); GET_IR_NODE_FROM_SUBGRAPH(shift_out, shift_out, layer_norm_pattern);
auto* eps_tensor = scope->FindVar(eps->Name())->GetMutable<LoDTensor>(); auto* eps_tensor =
scope->FindVar(eps->Name())->GetMutable<phi::DenseTensor>();
const auto& x_shape = x->Var()->GetShape(); const auto& x_shape = x->Var()->GetShape();
// ------------------ subgraph node's validation --------------------------- // ------------------ subgraph node's validation ---------------------------
...@@ -336,7 +337,8 @@ void LayerNormFusePass::ApplyImpl(Graph* graph) const { ...@@ -336,7 +337,8 @@ void LayerNormFusePass::ApplyImpl(Graph* graph) const {
// gamma/beta must be a 1-dimensional tensor of size on layer_norm // gamma/beta must be a 1-dimensional tensor of size on layer_norm
auto layer_norm_x_mat_dims = auto layer_norm_x_mat_dims =
phi::flatten_to_2d(phi::make_ddim(x_shape), begin_norm_axis); phi::flatten_to_2d(phi::make_ddim(x_shape), begin_norm_axis);
auto* gamma_tensor = scope->FindVar(gamma->Name())->GetMutable<LoDTensor>(); auto* gamma_tensor =
scope->FindVar(gamma->Name())->GetMutable<phi::DenseTensor>();
VarDesc new_gamma_desc(patterns::PDNodeName("layer_norm_fuse", "Scale")); VarDesc new_gamma_desc(patterns::PDNodeName("layer_norm_fuse", "Scale"));
new_gamma_desc.SetShape({layer_norm_x_mat_dims[1]}); new_gamma_desc.SetShape({layer_norm_x_mat_dims[1]});
new_gamma_desc.SetDataType( new_gamma_desc.SetDataType(
...@@ -345,13 +347,14 @@ void LayerNormFusePass::ApplyImpl(Graph* graph) const { ...@@ -345,13 +347,14 @@ void LayerNormFusePass::ApplyImpl(Graph* graph) const {
new_gamma_desc.SetPersistable(true); new_gamma_desc.SetPersistable(true);
auto* new_gamma_node = g->CreateVarNode(&new_gamma_desc); auto* new_gamma_node = g->CreateVarNode(&new_gamma_desc);
auto* new_gamma_tensor = auto* new_gamma_tensor =
scope->Var(new_gamma_node->Name())->GetMutable<LoDTensor>(); scope->Var(new_gamma_node->Name())->GetMutable<phi::DenseTensor>();
new_gamma_tensor->Resize(phi::make_ddim({layer_norm_x_mat_dims[1]})); new_gamma_tensor->Resize(phi::make_ddim({layer_norm_x_mat_dims[1]}));
memcpy(new_gamma_tensor->mutable_data<float>(platform::CPUPlace()), memcpy(new_gamma_tensor->mutable_data<float>(platform::CPUPlace()),
gamma_tensor->mutable_data<float>(platform::CPUPlace()), gamma_tensor->mutable_data<float>(platform::CPUPlace()),
layer_norm_x_mat_dims[1] * sizeof(float)); layer_norm_x_mat_dims[1] * sizeof(float));
auto* beta_tensor = scope->FindVar(beta->Name())->GetMutable<LoDTensor>(); auto* beta_tensor =
scope->FindVar(beta->Name())->GetMutable<phi::DenseTensor>();
VarDesc new_beta_desc(patterns::PDNodeName("layer_norm_fuse", "Bias")); VarDesc new_beta_desc(patterns::PDNodeName("layer_norm_fuse", "Bias"));
new_beta_desc.SetShape({layer_norm_x_mat_dims[1]}); new_beta_desc.SetShape({layer_norm_x_mat_dims[1]});
new_beta_desc.SetDataType( new_beta_desc.SetDataType(
...@@ -360,7 +363,7 @@ void LayerNormFusePass::ApplyImpl(Graph* graph) const { ...@@ -360,7 +363,7 @@ void LayerNormFusePass::ApplyImpl(Graph* graph) const {
new_beta_desc.SetPersistable(true); new_beta_desc.SetPersistable(true);
auto* new_beta_node = g->CreateVarNode(&new_beta_desc); auto* new_beta_node = g->CreateVarNode(&new_beta_desc);
auto* new_beta_tensor = auto* new_beta_tensor =
scope->Var(new_beta_node->Name())->GetMutable<LoDTensor>(); scope->Var(new_beta_node->Name())->GetMutable<phi::DenseTensor>();
new_beta_tensor->Resize(phi::make_ddim({layer_norm_x_mat_dims[1]})); new_beta_tensor->Resize(phi::make_ddim({layer_norm_x_mat_dims[1]}));
memcpy(new_beta_tensor->mutable_data<float>(platform::CPUPlace()), memcpy(new_beta_tensor->mutable_data<float>(platform::CPUPlace()),
......
...@@ -149,7 +149,7 @@ void MatmulScaleFusePass::ApplyImpl(ir::Graph* graph) const { ...@@ -149,7 +149,7 @@ void MatmulScaleFusePass::ApplyImpl(ir::Graph* graph) const {
auto* scale_var = scope->FindVar(scale_var_name); auto* scale_var = scope->FindVar(scale_var_name);
// ScaleTensor must be weight // ScaleTensor must be weight
if (scale_var == nullptr) return; if (scale_var == nullptr) return;
auto* scale_tensor = scale_var->GetMutable<LoDTensor>(); auto* scale_tensor = scale_var->GetMutable<phi::DenseTensor>();
scale = *(scale_tensor->data<float>()); scale = *(scale_tensor->data<float>());
} }
...@@ -211,12 +211,12 @@ void MatmulV2ScaleFusePass::ApplyImpl(ir::Graph* graph) const { ...@@ -211,12 +211,12 @@ void MatmulV2ScaleFusePass::ApplyImpl(ir::Graph* graph) const {
auto* scale_var = scope->FindVar(scale_var_name); auto* scale_var = scope->FindVar(scale_var_name);
// ScaleTensor must be weight // ScaleTensor must be weight
if (scale_var == nullptr) return; if (scale_var == nullptr) return;
auto* scale_tensor = scale_var->GetMutable<LoDTensor>(); auto* scale_tensor = scale_var->GetMutable<phi::DenseTensor>();
scale = *(scale_tensor->data<float>()); scale = *(scale_tensor->data<float>());
} }
auto* matmul_y = auto* matmul_y =
scope->FindVar(matmul_v2_in_y->Name())->GetMutable<LoDTensor>(); scope->FindVar(matmul_v2_in_y->Name())->GetMutable<phi::DenseTensor>();
auto y_data = matmul_y->mutable_data<float>(platform::CPUPlace()); auto y_data = matmul_y->mutable_data<float>(platform::CPUPlace());
for (int i = 0; i < matmul_y->numel(); ++i) { for (int i = 0; i < matmul_y->numel(); ++i) {
y_data[i] *= scale; y_data[i] *= scale;
......
...@@ -47,12 +47,12 @@ static std::map<size_t, std::unordered_set<std::string>> VarsGroupByScopeIdx( ...@@ -47,12 +47,12 @@ static std::map<size_t, std::unordered_set<std::string>> VarsGroupByScopeIdx(
return result; return result;
} }
// Check whether the variable is LoDTensor based on static VarDesc info // Check whether the variable is phi::DenseTensor based on static VarDesc info
static bool IsLoDTensor(VarDesc *var) { static bool IsLoDTensor(VarDesc *var) {
return var->Proto()->type().type() == proto::VarType::LOD_TENSOR; return var->Proto()->type().type() == proto::VarType::LOD_TENSOR;
} }
// Get memory size of LoDTensor // Get memory size of phi::DenseTensor
static int64_t GetMemorySize( static int64_t GetMemorySize(
const std::unordered_map<std::string, std::vector<details::VarHandle *>> const std::unordered_map<std::string, std::vector<details::VarHandle *>>
&vars, &vars,
...@@ -64,7 +64,7 @@ static int64_t GetMemorySize( ...@@ -64,7 +64,7 @@ static int64_t GetMemorySize(
PADDLE_ENFORCE_EQ(IsLoDTensor(var_desc), PADDLE_ENFORCE_EQ(IsLoDTensor(var_desc),
true, true,
platform::errors::InvalidArgument( platform::errors::InvalidArgument(
"Var(%s) must be LoDTensor.", var_name)); "Var(%s) must be phi::DenseTensor.", var_name));
auto dims = var_desc->GetShape(); auto dims = var_desc->GetShape();
return SizeOfType(var_desc->GetDataType()) * return SizeOfType(var_desc->GetDataType()) *
std::accumulate(dims.begin(), std::accumulate(dims.begin(),
...@@ -73,10 +73,10 @@ static int64_t GetMemorySize( ...@@ -73,10 +73,10 @@ static int64_t GetMemorySize(
std::multiplies<int64_t>()); std::multiplies<int64_t>());
} }
// Split all variables in the graph into LoDTensor and Non-LoDTensor (e.g. // Split all variables in the graph into phi::DenseTensor and
// SelectedRows, LoDTensorArray) // Non-phi::DenseTensor (e.g. SelectedRows, LoDTensorArray) Since partial GC is
// Since partial GC is based on static analysis of memory size of each variable // based on static analysis of memory size of each variable So we should skip
// So we should skip SelectedRows and LoDTensorArray here // SelectedRows and LoDTensorArray here
static void SplitIntoLoDTensorAndNonLoDTensorVars( static void SplitIntoLoDTensorAndNonLoDTensorVars(
const OpToVarNameSetMap &m, const OpToVarNameSetMap &m,
const details::GraphVars &vars, const details::GraphVars &vars,
...@@ -128,7 +128,7 @@ static OpToVarNameSetMap ShrinkGCVars( ...@@ -128,7 +128,7 @@ static OpToVarNameSetMap ShrinkGCVars(
if (fraction_of_memory_size <= 0.0) return {}; if (fraction_of_memory_size <= 0.0) return {};
/** /**
* Step 1: Split all variables into LoDTensor and Non-LoDTensor. * Step 1: Split all variables into phi::DenseTensor and Non-phi::DenseTensor.
* We can only calculate memory size of LoDTensors * We can only calculate memory size of LoDTensors
*/ */
OpToVarNameSetMap lod_tensors, other_vars; OpToVarNameSetMap lod_tensors, other_vars;
......
...@@ -208,7 +208,7 @@ MemoryReusePass::InsertShareTensorBufferOpHandleToGraph( ...@@ -208,7 +208,7 @@ MemoryReusePass::InsertShareTensorBufferOpHandleToGraph(
* - it has not been reused. If an input var is reused twice or more, * - it has not been reused. If an input var is reused twice or more,
* the calculation result may be wrong. * the calculation result may be wrong.
* - it is not a persistable var. * - it is not a persistable var.
* - it is LoDTensor. We can support SelectedRows in the future. * - it is phi::DenseTensor. We can support SelectedRows in the future.
*/ */
bool MemoryReusePass::IsInVarReusable(const details::VarHandle &in_var) const { bool MemoryReusePass::IsInVarReusable(const details::VarHandle &in_var) const {
if (in_var.Name() == kEmptyVarName) { if (in_var.Name() == kEmptyVarName) {
...@@ -242,7 +242,7 @@ bool MemoryReusePass::IsInVarReusable(const details::VarHandle &in_var) const { ...@@ -242,7 +242,7 @@ bool MemoryReusePass::IsInVarReusable(const details::VarHandle &in_var) const {
* - it has not reused other var's memory. It is not necessary to do memory * - it has not reused other var's memory. It is not necessary to do memory
* reuse twice for the same var. * reuse twice for the same var.
* - it is not a persistable var. * - it is not a persistable var.
* - it is LoDTensor. We can support SelectedRows in the future. * - it is phi::DenseTensor. We can support SelectedRows in the future.
* - it does not occur in inputs of the generated op. It would happen when * - it does not occur in inputs of the generated op. It would happen when
* op has the same var as both input and output. * op has the same var as both input and output.
*/ */
......
...@@ -112,7 +112,7 @@ void ComputePropagateScalesMkldnnPass::ComputeVarScales( ...@@ -112,7 +112,7 @@ void ComputePropagateScalesMkldnnPass::ComputeVarScales(
"The input persistable var [%s] of [%s] op is not found.", "The input persistable var [%s] of [%s] op is not found.",
var_name, var_name,
op_desc->Type())); op_desc->Type()));
auto* weight_tensor = var->GetMutable<LoDTensor>(); auto* weight_tensor = var->GetMutable<phi::DenseTensor>();
const auto dims = weight_tensor->dims(); const auto dims = weight_tensor->dims();
int volume = 1; int volume = 1;
for (int i = 1; i < dims.size(); i++) { for (int i = 1; i < dims.size(); i++) {
...@@ -153,8 +153,8 @@ void ComputePropagateScalesMkldnnPass::ComputeSingleGruWeightScales( ...@@ -153,8 +153,8 @@ void ComputePropagateScalesMkldnnPass::ComputeSingleGruWeightScales(
platform::errors::NotFound("The input persistable var [%s] is not found.", platform::errors::NotFound("The input persistable var [%s] is not found.",
wh_var_name)); wh_var_name));
const auto* wx_tensor = wx_var->GetMutable<LoDTensor>(); const auto* wx_tensor = wx_var->GetMutable<phi::DenseTensor>();
const auto* wh_tensor = wh_var->GetMutable<LoDTensor>(); const auto* wh_tensor = wh_var->GetMutable<phi::DenseTensor>();
const int OC = wh_tensor->dims()[0]; const int OC = wh_tensor->dims()[0];
std::vector<float> scale_ur(2 * OC); std::vector<float> scale_ur(2 * OC);
std::vector<float> scale_o(OC); std::vector<float> scale_o(OC);
...@@ -252,8 +252,8 @@ void ComputePropagateScalesMkldnnPass::ComputeSingleLstmWeightScales( ...@@ -252,8 +252,8 @@ void ComputePropagateScalesMkldnnPass::ComputeSingleLstmWeightScales(
platform::errors::NotFound("The input persistable var [%s] is not found.", platform::errors::NotFound("The input persistable var [%s] is not found.",
wh_var_name)); wh_var_name));
const auto* wx_tensor = wx_var->GetMutable<LoDTensor>(); const auto* wx_tensor = wx_var->GetMutable<phi::DenseTensor>();
const auto* wh_tensor = wh_var->GetMutable<LoDTensor>(); const auto* wh_tensor = wh_var->GetMutable<phi::DenseTensor>();
std::vector<float> scale(wx_tensor->dims()[1]); std::vector<float> scale(wx_tensor->dims()[1]);
for (int row_id = 0; row_id < wx_tensor->dims()[0]; row_id++) { for (int row_id = 0; row_id < wx_tensor->dims()[0]; row_id++) {
......
...@@ -52,8 +52,8 @@ class Node; ...@@ -52,8 +52,8 @@ class Node;
void recompute_bias_and_weights(const Scope* scope, void recompute_bias_and_weights(const Scope* scope,
ir::Node* conv_weight, ir::Node* conv_weight,
const ir::Node& ac_scale, const ir::Node& ac_scale,
const LoDTensor& ac_bias_tensor, const phi::DenseTensor& ac_bias_tensor,
LoDTensor* eltwise_y_in_tensor) { phi::DenseTensor* eltwise_y_in_tensor) {
using EigenVectorArrayMap = using EigenVectorArrayMap =
Eigen::Map<Eigen::Array<float, Eigen::Dynamic, 1>>; Eigen::Map<Eigen::Array<float, Eigen::Dynamic, 1>>;
using ConstEigenVectorArrayMap = using ConstEigenVectorArrayMap =
...@@ -71,7 +71,8 @@ void recompute_bias_and_weights(const Scope* scope, ...@@ -71,7 +71,8 @@ void recompute_bias_and_weights(const Scope* scope,
eltwise_y_in_tensor->dims().size(), eltwise_y_in_tensor->dims().size(),
ac_bias_tensor.dims().size())); ac_bias_tensor.dims().size()));
auto* scale_tensor = scope->FindVar(ac_scale.Name())->GetMutable<LoDTensor>(); auto* scale_tensor =
scope->FindVar(ac_scale.Name())->GetMutable<phi::DenseTensor>();
ConstEigenVectorArrayMap scale_array( ConstEigenVectorArrayMap scale_array(
scale_tensor->data<float>(), scale_tensor->numel(), 1); scale_tensor->data<float>(), scale_tensor->numel(), 1);
...@@ -86,7 +87,8 @@ void recompute_bias_and_weights(const Scope* scope, ...@@ -86,7 +87,8 @@ void recompute_bias_and_weights(const Scope* scope,
eltwise_y_in_array = (eltwise_y_in_array * scale_array) + ac_bias_array; eltwise_y_in_array = (eltwise_y_in_array * scale_array) + ac_bias_array;
// Re-compute weight of conv2d from AffineChannel // Re-compute weight of conv2d from AffineChannel
auto* weights = scope->FindVar(conv_weight->Name())->GetMutable<LoDTensor>(); auto* weights =
scope->FindVar(conv_weight->Name())->GetMutable<phi::DenseTensor>();
auto weights_shape = weights->dims(); auto weights_shape = weights->dims();
auto weights_shape_2d = phi::flatten_to_2d(weights_shape, 1); auto weights_shape_2d = phi::flatten_to_2d(weights_shape, 1);
auto* weights_data = weights->mutable_data<float>(platform::CPUPlace()); auto* weights_data = weights->mutable_data<float>(platform::CPUPlace());
...@@ -214,7 +216,7 @@ void ConvAffineChannelFusePass::ApplyImpl(ir::Graph* graph) const { ...@@ -214,7 +216,7 @@ void ConvAffineChannelFusePass::ApplyImpl(ir::Graph* graph) const {
// Get affine_channel bias for resizing eltwise_y! // Get affine_channel bias for resizing eltwise_y!
auto* ac_bias_tensor = auto* ac_bias_tensor =
scope->FindVar(ac_bias->Name())->GetMutable<LoDTensor>(); scope->FindVar(ac_bias->Name())->GetMutable<phi::DenseTensor>();
// Create eltwise_y (conv bias) variable // Create eltwise_y (conv bias) variable
VarDesc eltwise_y_in_desc( VarDesc eltwise_y_in_desc(
...@@ -229,7 +231,7 @@ void ConvAffineChannelFusePass::ApplyImpl(ir::Graph* graph) const { ...@@ -229,7 +231,7 @@ void ConvAffineChannelFusePass::ApplyImpl(ir::Graph* graph) const {
// Initialize eltwise_y // Initialize eltwise_y
auto* eltwise_y_in_node = g->CreateVarNode(&eltwise_y_in_desc); auto* eltwise_y_in_node = g->CreateVarNode(&eltwise_y_in_desc);
auto* eltwise_y_in_tensor = auto* eltwise_y_in_tensor =
scope->Var(eltwise_y_in_node->Name())->GetMutable<LoDTensor>(); scope->Var(eltwise_y_in_node->Name())->GetMutable<phi::DenseTensor>();
eltwise_y_in_tensor->Resize(ac_bias_tensor->dims()); eltwise_y_in_tensor->Resize(ac_bias_tensor->dims());
std::fill_n(eltwise_y_in_tensor->mutable_data<float>(platform::CPUPlace()), std::fill_n(eltwise_y_in_tensor->mutable_data<float>(platform::CPUPlace()),
eltwise_y_in_tensor->numel(), eltwise_y_in_tensor->numel(),
......
...@@ -180,9 +180,9 @@ Conv3DBiasFusePass::Conv3DBiasFusePass() { ...@@ -180,9 +180,9 @@ Conv3DBiasFusePass::Conv3DBiasFusePass() {
} }
template <typename BinaryOperation> template <typename BinaryOperation>
LoDTensor tensor_apply_eltwise(const LoDTensor& vec_a, phi::DenseTensor tensor_apply_eltwise(const phi::DenseTensor& vec_a,
const LoDTensor& vec_b, const phi::DenseTensor& vec_b,
BinaryOperation f) { BinaryOperation f) {
PADDLE_ENFORCE_EQ(vec_a.dims(), PADDLE_ENFORCE_EQ(vec_a.dims(),
vec_b.dims(), vec_b.dims(),
platform::errors::InvalidArgument( platform::errors::InvalidArgument(
...@@ -190,7 +190,7 @@ LoDTensor tensor_apply_eltwise(const LoDTensor& vec_a, ...@@ -190,7 +190,7 @@ LoDTensor tensor_apply_eltwise(const LoDTensor& vec_a,
"different: %s, %s.", "different: %s, %s.",
vec_a.dims(), vec_a.dims(),
vec_b.dims())); vec_b.dims()));
LoDTensor vec_y; phi::DenseTensor vec_y;
vec_y.Resize(vec_a.dims()); vec_y.Resize(vec_a.dims());
const float* a = vec_a.data<float>(); const float* a = vec_a.data<float>();
const float* b = vec_b.data<float>(); const float* b = vec_b.data<float>();
...@@ -253,7 +253,7 @@ void ConvBiasFusePass::ApplyImpl(ir::Graph* graph) const { ...@@ -253,7 +253,7 @@ void ConvBiasFusePass::ApplyImpl(ir::Graph* graph) const {
} }
auto* eltwise_bias_tensor = auto* eltwise_bias_tensor =
scope->FindVar(eltwise_bias->Name())->GetMutable<LoDTensor>(); scope->FindVar(eltwise_bias->Name())->GetMutable<phi::DenseTensor>();
auto input_names = conv->Op()->InputNames(); auto input_names = conv->Op()->InputNames();
bool has_bias = std::find(input_names.begin(), input_names.end(), "Bias") != bool has_bias = std::find(input_names.begin(), input_names.end(), "Bias") !=
...@@ -266,7 +266,7 @@ void ConvBiasFusePass::ApplyImpl(ir::Graph* graph) const { ...@@ -266,7 +266,7 @@ void ConvBiasFusePass::ApplyImpl(ir::Graph* graph) const {
1, 1,
platform::errors::NotFound("Can not find var Bias.")); platform::errors::NotFound("Can not find var Bias."));
auto* conv_bias_var = scope->FindVar(conv_bias_names[0]); auto* conv_bias_var = scope->FindVar(conv_bias_names[0]);
auto* conv_bias_tensor = conv_bias_var->GetMutable<LoDTensor>(); auto* conv_bias_tensor = conv_bias_var->GetMutable<phi::DenseTensor>();
PADDLE_ENFORCE_EQ( PADDLE_ENFORCE_EQ(
conv_bias_tensor->dims(), conv_bias_tensor->dims(),
eltwise_bias_tensor->dims(), eltwise_bias_tensor->dims(),
......
...@@ -104,7 +104,7 @@ void InitTensorHolder(Scope* scope, ...@@ -104,7 +104,7 @@ void InitTensorHolder(Scope* scope,
const paddle::platform::Place& place, const paddle::platform::Place& place,
const char* var_name) { const char* var_name) {
auto x = scope->Var(var_name); auto x = scope->Var(var_name);
auto tensor = x->GetMutable<LoDTensor>(); auto tensor = x->GetMutable<phi::DenseTensor>();
tensor->mutable_data( tensor->mutable_data(
place, framework::TransToPhiDataType(proto::VarType::FP32), 1); place, framework::TransToPhiDataType(proto::VarType::FP32), 1);
} }
......
...@@ -289,7 +289,7 @@ bool CPUQuantizePass::AreScalesPresentForNodes( ...@@ -289,7 +289,7 @@ bool CPUQuantizePass::AreScalesPresentForNodes(
return present; return present;
} }
std::pair<bool, LoDTensor> CPUQuantizePass::GetScaleDataByName( std::pair<bool, phi::DenseTensor> CPUQuantizePass::GetScaleDataByName(
const std::string& name) const { const std::string& name) const {
if (var_quant_scales_->empty()) { if (var_quant_scales_->empty()) {
auto& scales = Get<VarQuantScale>("quant_var_scales"); auto& scales = Get<VarQuantScale>("quant_var_scales");
...@@ -298,16 +298,18 @@ std::pair<bool, LoDTensor> CPUQuantizePass::GetScaleDataByName( ...@@ -298,16 +298,18 @@ std::pair<bool, LoDTensor> CPUQuantizePass::GetScaleDataByName(
return var_quant_scales_->at(name); return var_quant_scales_->at(name);
} }
std::pair<bool, LoDTensor> CPUQuantizePass::GetScaleDataForNode( std::pair<bool, phi::DenseTensor> CPUQuantizePass::GetScaleDataForNode(
const Node* node) const { const Node* node) const {
return GetScaleDataByName(node->Name()); return GetScaleDataByName(node->Name());
} }
LoDTensor CPUQuantizePass::GetScaleTensorByName(const std::string& name) const { phi::DenseTensor CPUQuantizePass::GetScaleTensorByName(
const std::string& name) const {
return GetScaleDataByName(name).second; return GetScaleDataByName(name).second;
} }
LoDTensor CPUQuantizePass::GetScaleTensorForNode(const Node* node) const { phi::DenseTensor CPUQuantizePass::GetScaleTensorForNode(
const Node* node) const {
return GetScaleDataForNode(node).second; return GetScaleDataForNode(node).second;
} }
...@@ -1071,7 +1073,7 @@ void CPUQuantizePass::QuantizeMultiGru(Graph* graph) const { ...@@ -1071,7 +1073,7 @@ void CPUQuantizePass::QuantizeMultiGru(Graph* graph) const {
auto* w_scale_node = g->CreateVarNode(&scale_var_desc); auto* w_scale_node = g->CreateVarNode(&scale_var_desc);
auto* w_scale_tensor_dst = auto* w_scale_tensor_dst =
scope->Var(w_scale_node->Name())->GetMutable<LoDTensor>(); scope->Var(w_scale_node->Name())->GetMutable<phi::DenseTensor>();
w_scale_tensor_dst->Resize(scale_tensor_src.dims()); w_scale_tensor_dst->Resize(scale_tensor_src.dims());
auto* dst_data = auto* dst_data =
w_scale_tensor_dst->mutable_data<float>(platform::CPUPlace()); w_scale_tensor_dst->mutable_data<float>(platform::CPUPlace());
......
...@@ -37,7 +37,7 @@ class Graph; ...@@ -37,7 +37,7 @@ class Graph;
class Node; class Node;
using VarQuantScale = using VarQuantScale =
std::unordered_map<std::string, std::pair<bool, LoDTensor>>; std::unordered_map<std::string, std::pair<bool, phi::DenseTensor>>;
/* /*
* Quantize all supported operators. * Quantize all supported operators.
...@@ -93,10 +93,11 @@ class CPUQuantizePass : public FusePassBase { ...@@ -93,10 +93,11 @@ class CPUQuantizePass : public FusePassBase {
bool AreScalesPresentForVarNames(std::vector<std::string> names) const; bool AreScalesPresentForVarNames(std::vector<std::string> names) const;
bool AreScalesPresentForNodes(std::initializer_list<Node*> nodes) const; bool AreScalesPresentForNodes(std::initializer_list<Node*> nodes) const;
std::pair<bool, LoDTensor> GetScaleDataByName(const std::string& name) const; std::pair<bool, phi::DenseTensor> GetScaleDataByName(
std::pair<bool, LoDTensor> GetScaleDataForNode(const Node* node) const; const std::string& name) const;
LoDTensor GetScaleTensorByName(const std::string& name) const; std::pair<bool, phi::DenseTensor> GetScaleDataForNode(const Node* node) const;
LoDTensor GetScaleTensorForNode(const Node* node) const; phi::DenseTensor GetScaleTensorByName(const std::string& name) const;
phi::DenseTensor GetScaleTensorForNode(const Node* node) const;
double GetScaleValueByName(const std::string& name, double GetScaleValueByName(const std::string& name,
bool* is_unsigned = nullptr) const; bool* is_unsigned = nullptr) const;
double GetScaleValueForNode(const Node* node, double GetScaleValueForNode(const Node* node,
......
...@@ -131,7 +131,7 @@ void InitTensorHolder(Scope* scope, ...@@ -131,7 +131,7 @@ void InitTensorHolder(Scope* scope,
const paddle::platform::Place& place, const paddle::platform::Place& place,
const char* var_name) { const char* var_name) {
auto x = scope->Var(var_name); auto x = scope->Var(var_name);
auto tensor = x->GetMutable<LoDTensor>(); auto tensor = x->GetMutable<phi::DenseTensor>();
tensor->mutable_data( tensor->mutable_data(
place, framework::TransToPhiDataType(proto::VarType::FP32), 1); place, framework::TransToPhiDataType(proto::VarType::FP32), 1);
} }
...@@ -151,7 +151,7 @@ void PreparePass(std::unique_ptr<ir::Graph>* graph, ...@@ -151,7 +151,7 @@ void PreparePass(std::unique_ptr<ir::Graph>* graph,
for (auto& v : variable_names) { for (auto& v : variable_names) {
if (v.compare(var_without_scale) == 0) continue; if (v.compare(var_without_scale) == 0) continue;
InitTensorHolder(&scope, place, v.c_str()); InitTensorHolder(&scope, place, v.c_str());
LoDTensor tensor; phi::DenseTensor tensor;
tensor.Resize({1}); tensor.Resize({1});
auto* ptr = tensor.mutable_data<double>(place); auto* ptr = tensor.mutable_data<double>(place);
ptr[0] = SCALE; ptr[0] = SCALE;
......
...@@ -716,7 +716,7 @@ void InitTensorHolder(Scope* scope, ...@@ -716,7 +716,7 @@ void InitTensorHolder(Scope* scope,
const paddle::platform::Place& place, const paddle::platform::Place& place,
const char* var_name) { const char* var_name) {
auto x = scope->Var(var_name); auto x = scope->Var(var_name);
auto tensor = x->GetMutable<LoDTensor>(); auto tensor = x->GetMutable<phi::DenseTensor>();
tensor->mutable_data( tensor->mutable_data(
place, framework::TransToPhiDataType(proto::VarType::FP32), 1); place, framework::TransToPhiDataType(proto::VarType::FP32), 1);
} }
......
...@@ -25,7 +25,8 @@ namespace ir { ...@@ -25,7 +25,8 @@ namespace ir {
namespace { namespace {
template <typename T_out> template <typename T_out>
void QuantizeParams(LoDTensor* param_tensor, const std::vector<float>& scales) { void QuantizeParams(phi::DenseTensor* param_tensor,
const std::vector<float>& scales) {
std::vector<T_out> tmp_data; std::vector<T_out> tmp_data;
tmp_data.reserve(param_tensor->numel()); tmp_data.reserve(param_tensor->numel());
...@@ -59,7 +60,7 @@ void QuantizeConvInput(Scope* scope, ...@@ -59,7 +60,7 @@ void QuantizeConvInput(Scope* scope,
const std::string& input_name, const std::string& input_name,
const std::string& scales_attr_name) { const std::string& scales_attr_name) {
auto var = scope->GetVar(input_name); auto var = scope->GetVar(input_name);
if (var->Get<LoDTensor>().dtype() != phi::DataType::FLOAT32) { if (var->Get<phi::DenseTensor>().dtype() != phi::DataType::FLOAT32) {
VLOG(0) << "Skipping convolution filter: " << input_name VLOG(0) << "Skipping convolution filter: " << input_name
<< " because it is detected again."; << " because it is detected again.";
conv_op->Op()->SetAttr(scales_attr_name, std::vector<float>(1, 1)); conv_op->Op()->SetAttr(scales_attr_name, std::vector<float>(1, 1));
...@@ -67,7 +68,7 @@ void QuantizeConvInput(Scope* scope, ...@@ -67,7 +68,7 @@ void QuantizeConvInput(Scope* scope,
const auto scales = const auto scales =
conv_op->Op()->GetAttrIfExists<std::vector<float>>(scales_attr_name); conv_op->Op()->GetAttrIfExists<std::vector<float>>(scales_attr_name);
auto* tensor = scope->GetVar(input_name)->GetMutable<LoDTensor>(); auto* tensor = scope->GetVar(input_name)->GetMutable<phi::DenseTensor>();
QuantizeParams<T>(tensor, scales); QuantizeParams<T>(tensor, scales);
conv_op->Op()->SetAttr(scales_attr_name, std::vector<float>(1, 1)); conv_op->Op()->SetAttr(scales_attr_name, std::vector<float>(1, 1));
} }
......
...@@ -18,8 +18,6 @@ ...@@ -18,8 +18,6 @@
#include "paddle/fluid/imperative/type_defs.h" #include "paddle/fluid/imperative/type_defs.h"
#include "paddle/fluid/platform/place.h" #include "paddle/fluid/platform/place.h"
using LoDTensor = phi::DenseTensor;
namespace paddle { namespace paddle {
namespace framework { namespace framework {
namespace ir { namespace ir {
...@@ -48,15 +46,15 @@ struct Data { ...@@ -48,15 +46,15 @@ struct Data {
struct TestScope { struct TestScope {
void CreateTensor(const std::string& var_name, const Data& data) { void CreateTensor(const std::string& var_name, const Data& data) {
auto variable = scope.Var(var_name); auto variable = scope.Var(var_name);
auto tensor = variable->GetMutable<LoDTensor>(); auto tensor = variable->GetMutable<phi::DenseTensor>();
tensor->Resize(phi::make_ddim(data.getShape())); tensor->Resize(phi::make_ddim(data.getShape()));
auto dptr = tensor->mutable_data<float>(place); auto dptr = tensor->mutable_data<float>(place);
std::copy(data.getData().begin(), data.getData().end(), dptr); std::copy(data.getData().begin(), data.getData().end(), dptr);
} }
const LoDTensor& GetTensor(const std::string& input) const { const phi::DenseTensor& GetTensor(const std::string& input) const {
Variable* var = scope.FindVar(input); Variable* var = scope.FindVar(input);
return var->Get<LoDTensor>(); return var->Get<phi::DenseTensor>();
} }
framework::Scope* Scope() { return &scope; } framework::Scope* Scope() { return &scope; }
......
...@@ -84,7 +84,7 @@ void QuantDequantMkldnnPass::CollectInfoFromFake( ...@@ -84,7 +84,7 @@ void QuantDequantMkldnnPass::CollectInfoFromFake(
"The Scales variable [%s] of dequantize op is not found.", "The Scales variable [%s] of dequantize op is not found.",
var)); var));
auto* scale_tensor = var->GetMutable<LoDTensor>(); auto* scale_tensor = var->GetMutable<phi::DenseTensor>();
auto* scale_data = scale_tensor->data<float>(); auto* scale_data = scale_tensor->data<float>();
std::vector<float> thresholds{}; std::vector<float> thresholds{};
for (int i = 0; i < scale_tensor->numel(); i++) { for (int i = 0; i < scale_tensor->numel(); i++) {
...@@ -117,7 +117,7 @@ void QuantDequantMkldnnPass::CollectWeightScalesInfoFromONNXFormatDequantize( ...@@ -117,7 +117,7 @@ void QuantDequantMkldnnPass::CollectWeightScalesInfoFromONNXFormatDequantize(
platform::errors::NotFound( platform::errors::NotFound(
"The Scales variable [%s] of dequantize op is not found.", var)); "The Scales variable [%s] of dequantize op is not found.", var));
auto* scale_tensor = var->GetMutable<LoDTensor>(); auto* scale_tensor = var->GetMutable<phi::DenseTensor>();
auto* scale_data = scale_tensor->data<float>(); auto* scale_data = scale_tensor->data<float>();
auto x_var_name = op_desc->Input("X")[0]; auto x_var_name = op_desc->Input("X")[0];
...@@ -185,7 +185,7 @@ void QuantDequantMkldnnPass::CollectInputScalesFromQuantize( ...@@ -185,7 +185,7 @@ void QuantDequantMkldnnPass::CollectInputScalesFromQuantize(
platform::errors::NotFound( platform::errors::NotFound(
"The InScale variable [%s] of quantize op is not found.", var)); "The InScale variable [%s] of quantize op is not found.", var));
auto* scale_tensor = var->GetMutable<LoDTensor>(); auto* scale_tensor = var->GetMutable<phi::DenseTensor>();
auto* scale_data = scale_tensor->data<float>(); auto* scale_data = scale_tensor->data<float>();
float scale = 1.0 / scale_data[0]; float scale = 1.0 / scale_data[0];
if (std::isinf(scale) || std::isnan(scale)) { if (std::isinf(scale) || std::isnan(scale)) {
...@@ -458,7 +458,7 @@ bool QuantDequantMkldnnPass::IsInt8Weight( ...@@ -458,7 +458,7 @@ bool QuantDequantMkldnnPass::IsInt8Weight(
if (var == nullptr) { if (var == nullptr) {
return false; return false;
} }
auto* weight_tensor = var->GetMutable<LoDTensor>(); auto* weight_tensor = var->GetMutable<phi::DenseTensor>();
auto* weight_data = weight_tensor->data<float>(); auto* weight_data = weight_tensor->data<float>();
bool is_int8 = true; bool is_int8 = true;
for (int i = 0; i < weight_tensor->numel(); i++) { for (int i = 0; i < weight_tensor->numel(); i++) {
...@@ -581,7 +581,7 @@ void QuantDequantMkldnnPass::DequantizeOpWeights( ...@@ -581,7 +581,7 @@ void QuantDequantMkldnnPass::DequantizeOpWeights(
"The input persistable [%s] var of [%s] op is not found.", "The input persistable [%s] var of [%s] op is not found.",
weight_var_name, weight_var_name,
op_desc->Type())); op_desc->Type()));
auto* weight_tensor = var->GetMutable<LoDTensor>(); auto* weight_tensor = var->GetMutable<phi::DenseTensor>();
float* fp32_weight_data = float* fp32_weight_data =
weight_tensor->mutable_data<float>(platform::CPUPlace()); weight_tensor->mutable_data<float>(platform::CPUPlace());
ConvertFromINT8ToFP32( ConvertFromINT8ToFP32(
...@@ -626,7 +626,7 @@ void QuantDequantMkldnnPass::DequantizeOpWeightsFromONNXFormat( ...@@ -626,7 +626,7 @@ void QuantDequantMkldnnPass::DequantizeOpWeightsFromONNXFormat(
"The input persistable [%s] var of [%s] op is not found.", "The input persistable [%s] var of [%s] op is not found.",
weight_var_name, weight_var_name,
op_desc->Type())); op_desc->Type()));
auto* weight_tensor = var->GetMutable<LoDTensor>(); auto* weight_tensor = var->GetMutable<phi::DenseTensor>();
int8_t* int8_weight_data = int8_t* int8_weight_data =
weight_tensor->mutable_data<int8_t>(platform::CPUPlace()); weight_tensor->mutable_data<int8_t>(platform::CPUPlace());
......
...@@ -24,7 +24,7 @@ namespace ir { ...@@ -24,7 +24,7 @@ namespace ir {
void AddVarToScope(Scope* param_scope, void AddVarToScope(Scope* param_scope,
const std::string& name, const std::string& name,
const DDim& dims) { const DDim& dims) {
auto* tensor = param_scope->Var(name)->GetMutable<LoDTensor>(); auto* tensor = param_scope->Var(name)->GetMutable<phi::DenseTensor>();
tensor->Resize(dims); tensor->Resize(dims);
tensor->mutable_data<float>(platform::CPUPlace()); tensor->mutable_data<float>(platform::CPUPlace());
} }
......
...@@ -26,7 +26,7 @@ namespace ir { ...@@ -26,7 +26,7 @@ namespace ir {
void AddVarToScope(Scope* param_scope, void AddVarToScope(Scope* param_scope,
const std::string& name, const std::string& name,
const DDim& dims) { const DDim& dims) {
auto* tensor = param_scope->Var(name)->GetMutable<LoDTensor>(); auto* tensor = param_scope->Var(name)->GetMutable<phi::DenseTensor>();
tensor->Resize(dims); tensor->Resize(dims);
tensor->mutable_data<float>(platform::CPUPlace()); tensor->mutable_data<float>(platform::CPUPlace());
} }
......
...@@ -894,16 +894,19 @@ int MultiHeadMatmulV2FusePass::BuildFusionV2(Graph* graph, ...@@ -894,16 +894,19 @@ int MultiHeadMatmulV2FusePass::BuildFusionV2(Graph* graph,
// mul (B * S * Hidden) x (Hidden * 3 * N * H) = (B * S * 3 * N * H) // mul (B * S * Hidden) x (Hidden * 3 * N * H) = (B * S * 3 * N * H)
// bias (B * S * 3 * N * H) + bias (3 * N * H) // bias (B * S * 3 * N * H) + bias (3 * N * H)
// Transpose (B * S * 3 * N * H) -> (3 * B * N * S * H) // Transpose (B * S * 3 * N * H) -> (3 * B * N * S * H)
auto* wq_tensor = scope->FindVar(mul0_w->Name())->GetMutable<LoDTensor>(); auto* wq_tensor =
auto* wk_tensor = scope->FindVar(mul1_w->Name())->GetMutable<LoDTensor>(); scope->FindVar(mul0_w->Name())->GetMutable<phi::DenseTensor>();
auto* wv_tensor = scope->FindVar(mul2_w->Name())->GetMutable<LoDTensor>(); auto* wk_tensor =
scope->FindVar(mul1_w->Name())->GetMutable<phi::DenseTensor>();
auto* wv_tensor =
scope->FindVar(mul2_w->Name())->GetMutable<phi::DenseTensor>();
auto* bq_tensor = auto* bq_tensor =
scope->FindVar(eltadd0_b->Name())->GetMutable<LoDTensor>(); scope->FindVar(eltadd0_b->Name())->GetMutable<phi::DenseTensor>();
auto* bk_tensor = auto* bk_tensor =
scope->FindVar(eltadd1_b->Name())->GetMutable<LoDTensor>(); scope->FindVar(eltadd1_b->Name())->GetMutable<phi::DenseTensor>();
auto* bv_tensor = auto* bv_tensor =
scope->FindVar(eltadd2_b->Name())->GetMutable<LoDTensor>(); scope->FindVar(eltadd2_b->Name())->GetMutable<phi::DenseTensor>();
if (wq_tensor->dtype() == phi::DataType::FLOAT32) { if (wq_tensor->dtype() == phi::DataType::FLOAT32) {
QKVWeightsProcess<float>( QKVWeightsProcess<float>(
...@@ -1335,16 +1338,19 @@ int MultiHeadMatmulV3FusePass::BuildFusionV3(Graph* graph, ...@@ -1335,16 +1338,19 @@ int MultiHeadMatmulV3FusePass::BuildFusionV3(Graph* graph,
// mul (B * S * Hidden) x (Hidden * 3 * N * H) = (B * S * 3 * N * H) // mul (B * S * Hidden) x (Hidden * 3 * N * H) = (B * S * 3 * N * H)
// bias (B * S * 3 * N * H) + bias (3 * N * H) // bias (B * S * 3 * N * H) + bias (3 * N * H)
// Transpose (B * S * 3 * N * H) -> (3 * B * N * S * H) // Transpose (B * S * 3 * N * H) -> (3 * B * N * S * H)
auto* wq_tensor = scope->FindVar(mul0_w->Name())->GetMutable<LoDTensor>(); auto* wq_tensor =
auto* wk_tensor = scope->FindVar(mul1_w->Name())->GetMutable<LoDTensor>(); scope->FindVar(mul0_w->Name())->GetMutable<phi::DenseTensor>();
auto* wv_tensor = scope->FindVar(mul2_w->Name())->GetMutable<LoDTensor>(); auto* wk_tensor =
scope->FindVar(mul1_w->Name())->GetMutable<phi::DenseTensor>();
auto* wv_tensor =
scope->FindVar(mul2_w->Name())->GetMutable<phi::DenseTensor>();
auto* bq_tensor = auto* bq_tensor =
scope->FindVar(eltadd0_b->Name())->GetMutable<LoDTensor>(); scope->FindVar(eltadd0_b->Name())->GetMutable<phi::DenseTensor>();
auto* bk_tensor = auto* bk_tensor =
scope->FindVar(eltadd1_b->Name())->GetMutable<LoDTensor>(); scope->FindVar(eltadd1_b->Name())->GetMutable<phi::DenseTensor>();
auto* bv_tensor = auto* bv_tensor =
scope->FindVar(eltadd2_b->Name())->GetMutable<LoDTensor>(); scope->FindVar(eltadd2_b->Name())->GetMutable<phi::DenseTensor>();
auto* wq_data = wq_tensor->mutable_data<float>(platform::CPUPlace()); auto* wq_data = wq_tensor->mutable_data<float>(platform::CPUPlace());
auto* wk_data = wk_tensor->mutable_data<float>(platform::CPUPlace()); auto* wk_data = wk_tensor->mutable_data<float>(platform::CPUPlace());
......
...@@ -22,7 +22,7 @@ namespace ir { ...@@ -22,7 +22,7 @@ namespace ir {
void AddVarToScope(Scope* param_scope, void AddVarToScope(Scope* param_scope,
const std::string& name, const std::string& name,
const DDim& dims) { const DDim& dims) {
auto* tensor = param_scope->Var(name)->GetMutable<LoDTensor>(); auto* tensor = param_scope->Var(name)->GetMutable<phi::DenseTensor>();
tensor->Resize(dims); tensor->Resize(dims);
tensor->mutable_data<float>(platform::CPUPlace()); tensor->mutable_data<float>(platform::CPUPlace());
} }
......
...@@ -186,7 +186,7 @@ void InitLoDTensorHolder(const Scope& scope, ...@@ -186,7 +186,7 @@ void InitLoDTensorHolder(const Scope& scope,
const std::vector<int64_t>& dims, const std::vector<int64_t>& dims,
const T* data) { const T* data) {
auto var = scope.FindLocalVar(var_name); auto var = scope.FindLocalVar(var_name);
auto tensor = var->GetMutable<LoDTensor>(); auto tensor = var->GetMutable<phi::DenseTensor>();
auto* tensor_mem_ptr = tensor->mutable_data<T>(phi::make_ddim(dims), place); auto* tensor_mem_ptr = tensor->mutable_data<T>(phi::make_ddim(dims), place);
if (data != nullptr) { if (data != nullptr) {
std::memcpy(tensor_mem_ptr, data, tensor->memory_size()); std::memcpy(tensor_mem_ptr, data, tensor->memory_size());
......
...@@ -358,8 +358,8 @@ void QuantDequantFusePass::DeleteQuant(ir::Graph* graph, ...@@ -358,8 +358,8 @@ void QuantDequantFusePass::DeleteQuant(ir::Graph* graph,
scope, scope,
platform::errors::InvalidArgument( platform::errors::InvalidArgument(
"Scope in QuantDequantFuse pass should not be null.")); "Scope in QuantDequantFuse pass should not be null."));
const LoDTensor& input_scale_tensor = const phi::DenseTensor& input_scale_tensor =
scope->FindVar(input_scale_var_name)->Get<LoDTensor>(); scope->FindVar(input_scale_var_name)->Get<phi::DenseTensor>();
PADDLE_ENFORCE_EQ( PADDLE_ENFORCE_EQ(
paddle::platform::is_cpu_place(input_scale_tensor.place()), paddle::platform::is_cpu_place(input_scale_tensor.place()),
true, true,
...@@ -484,8 +484,8 @@ void QuantDequantFusePass::FuseDequant(ir::Graph* graph, ...@@ -484,8 +484,8 @@ void QuantDequantFusePass::FuseDequant(ir::Graph* graph,
platform::errors::InvalidArgument( platform::errors::InvalidArgument(
"Scales size in channel-wise dequantize op should be 2, got %d.", "Scales size in channel-wise dequantize op should be 2, got %d.",
scales_name.size())); scales_name.size()));
const LoDTensor& channel_scale_tensor = const phi::DenseTensor& channel_scale_tensor =
scope->FindVar(scales_name[0])->Get<LoDTensor>(); scope->FindVar(scales_name[0])->Get<phi::DenseTensor>();
PADDLE_ENFORCE_EQ( PADDLE_ENFORCE_EQ(
paddle::platform::is_cpu_place(channel_scale_tensor.place()), paddle::platform::is_cpu_place(channel_scale_tensor.place()),
true, true,
...@@ -503,8 +503,8 @@ void QuantDequantFusePass::FuseDequant(ir::Graph* graph, ...@@ -503,8 +503,8 @@ void QuantDequantFusePass::FuseDequant(ir::Graph* graph,
} }
// Convert weight to fp32 range // Convert weight to fp32 range
auto* weight_tensor = auto* weight_tensor = scope->Var(quantized_op_weight_node->Name())
scope->Var(quantized_op_weight_node->Name())->GetMutable<LoDTensor>(); ->GetMutable<phi::DenseTensor>();
const auto& w_dims = weight_tensor->dims(); const auto& w_dims = weight_tensor->dims();
float* quantized_weight_data = float* quantized_weight_data =
weight_tensor->mutable_data<float>(platform::CPUPlace()); weight_tensor->mutable_data<float>(platform::CPUPlace());
......
...@@ -209,7 +209,7 @@ void RemovePaddingRecoverPaddingPass::ApplyImpl(ir::Graph* graph) const { ...@@ -209,7 +209,7 @@ void RemovePaddingRecoverPaddingPass::ApplyImpl(ir::Graph* graph) const {
// create variable in scope // create variable in scope
scope->Var(remove_padding_out_name); scope->Var(remove_padding_out_name);
auto* remove_padding_out_tensor = auto* remove_padding_out_tensor =
scope->FindVar(remove_padding_out_name)->GetMutable<LoDTensor>(); scope->FindVar(remove_padding_out_name)->GetMutable<phi::DenseTensor>();
remove_padding_out_tensor->mutable_data<float>(platform::CUDAPlace()); remove_padding_out_tensor->mutable_data<float>(platform::CUDAPlace());
// rename // rename
...@@ -279,7 +279,8 @@ void RemovePaddingRecoverPaddingPass::ApplyImpl(ir::Graph* graph) const { ...@@ -279,7 +279,8 @@ void RemovePaddingRecoverPaddingPass::ApplyImpl(ir::Graph* graph) const {
// create variable in scope // create variable in scope
scope->Var(recover_padding_input_name); scope->Var(recover_padding_input_name);
auto* recover_padding_input_tensor = auto* recover_padding_input_tensor =
scope->FindVar(recover_padding_input_name)->GetMutable<LoDTensor>(); scope->FindVar(recover_padding_input_name)
->GetMutable<phi::DenseTensor>();
recover_padding_input_tensor->mutable_data<float>(platform::CUDAPlace()); recover_padding_input_tensor->mutable_data<float>(platform::CUDAPlace());
// rename // rename
......
...@@ -828,16 +828,19 @@ int TrtMultiHeadMatmulV2FusePass::BuildFusionV2(Graph* graph, ...@@ -828,16 +828,19 @@ int TrtMultiHeadMatmulV2FusePass::BuildFusionV2(Graph* graph,
// mul (B * S * Hidden) x (Hidden * 3 * N * H) = (B * S * 3 * N * H) // mul (B * S * Hidden) x (Hidden * 3 * N * H) = (B * S * 3 * N * H)
// bias (B * S * 3 * N * H) + bias (3 * N * H) // bias (B * S * 3 * N * H) + bias (3 * N * H)
// Transpose (B * S * 3 * N * H) -> (3 * B * N * S * H) // Transpose (B * S * 3 * N * H) -> (3 * B * N * S * H)
auto* wq_tensor = scope->FindVar(mul0_w->Name())->GetMutable<LoDTensor>(); auto* wq_tensor =
auto* wk_tensor = scope->FindVar(mul1_w->Name())->GetMutable<LoDTensor>(); scope->FindVar(mul0_w->Name())->GetMutable<phi::DenseTensor>();
auto* wv_tensor = scope->FindVar(mul2_w->Name())->GetMutable<LoDTensor>(); auto* wk_tensor =
scope->FindVar(mul1_w->Name())->GetMutable<phi::DenseTensor>();
auto* wv_tensor =
scope->FindVar(mul2_w->Name())->GetMutable<phi::DenseTensor>();
auto* bq_tensor = auto* bq_tensor =
scope->FindVar(eltadd0_b->Name())->GetMutable<LoDTensor>(); scope->FindVar(eltadd0_b->Name())->GetMutable<phi::DenseTensor>();
auto* bk_tensor = auto* bk_tensor =
scope->FindVar(eltadd1_b->Name())->GetMutable<LoDTensor>(); scope->FindVar(eltadd1_b->Name())->GetMutable<phi::DenseTensor>();
auto* bv_tensor = auto* bv_tensor =
scope->FindVar(eltadd2_b->Name())->GetMutable<LoDTensor>(); scope->FindVar(eltadd2_b->Name())->GetMutable<phi::DenseTensor>();
auto* wq_data = wq_tensor->mutable_data<float>(platform::CPUPlace()); auto* wq_data = wq_tensor->mutable_data<float>(platform::CPUPlace());
auto* wk_data = wk_tensor->mutable_data<float>(platform::CPUPlace()); auto* wk_data = wk_tensor->mutable_data<float>(platform::CPUPlace());
...@@ -1345,16 +1348,19 @@ int TrtMultiHeadMatmulV3FusePass::BuildFusionV3(Graph* graph, ...@@ -1345,16 +1348,19 @@ int TrtMultiHeadMatmulV3FusePass::BuildFusionV3(Graph* graph,
// mul (B * S * Hidden) x (Hidden * 3 * N * H) = (B * S * 3 * N * H) // mul (B * S * Hidden) x (Hidden * 3 * N * H) = (B * S * 3 * N * H)
// bias (B * S * 3 * N * H) + bias (3 * N * H) // bias (B * S * 3 * N * H) + bias (3 * N * H)
// Transpose (B * S * 3 * N * H) -> (3 * B * N * S * H) // Transpose (B * S * 3 * N * H) -> (3 * B * N * S * H)
auto* wq_tensor = scope->FindVar(mul0_w->Name())->GetMutable<LoDTensor>(); auto* wq_tensor =
auto* wk_tensor = scope->FindVar(mul1_w->Name())->GetMutable<LoDTensor>(); scope->FindVar(mul0_w->Name())->GetMutable<phi::DenseTensor>();
auto* wv_tensor = scope->FindVar(mul2_w->Name())->GetMutable<LoDTensor>(); auto* wk_tensor =
scope->FindVar(mul1_w->Name())->GetMutable<phi::DenseTensor>();
auto* wv_tensor =
scope->FindVar(mul2_w->Name())->GetMutable<phi::DenseTensor>();
auto* bq_tensor = auto* bq_tensor =
scope->FindVar(eltadd0_b->Name())->GetMutable<LoDTensor>(); scope->FindVar(eltadd0_b->Name())->GetMutable<phi::DenseTensor>();
auto* bk_tensor = auto* bk_tensor =
scope->FindVar(eltadd1_b->Name())->GetMutable<LoDTensor>(); scope->FindVar(eltadd1_b->Name())->GetMutable<phi::DenseTensor>();
auto* bv_tensor = auto* bv_tensor =
scope->FindVar(eltadd2_b->Name())->GetMutable<LoDTensor>(); scope->FindVar(eltadd2_b->Name())->GetMutable<phi::DenseTensor>();
auto* wq_data = wq_tensor->mutable_data<float>(platform::CPUPlace()); auto* wq_data = wq_tensor->mutable_data<float>(platform::CPUPlace());
auto* wk_data = wk_tensor->mutable_data<float>(platform::CPUPlace()); auto* wk_data = wk_tensor->mutable_data<float>(platform::CPUPlace());
......
...@@ -85,13 +85,13 @@ void VitAttentionFusePass::ApplyImpl(ir::Graph* graph) const { ...@@ -85,13 +85,13 @@ void VitAttentionFusePass::ApplyImpl(ir::Graph* graph) const {
} }
// refactor W and Bias // refactor W and Bias
auto* w_tensor = auto* w_tensor =
scope->FindVar(matmul0_in_y->Name())->GetMutable<LoDTensor>(); scope->FindVar(matmul0_in_y->Name())->GetMutable<phi::DenseTensor>();
auto w_dims = auto w_dims =
phi::make_ddim({w_tensor->dims()[0], 3, w_tensor->dims()[1] / 3}); phi::make_ddim({w_tensor->dims()[0], 3, w_tensor->dims()[1] / 3});
w_tensor->Resize(w_dims); w_tensor->Resize(w_dims);
auto* b_tensor = auto* b_tensor = scope->FindVar(elementwise0_in_y->Name())
scope->FindVar(elementwise0_in_y->Name())->GetMutable<LoDTensor>(); ->GetMutable<phi::DenseTensor>();
auto bias_dims = phi::make_ddim({3, b_tensor->dims()[0] / 3}); auto bias_dims = phi::make_ddim({3, b_tensor->dims()[0] / 3});
b_tensor->Resize(bias_dims); b_tensor->Resize(bias_dims);
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册