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