Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ ConvertToMixedPrecisionPass::ConvertToMixedPrecisionPass(
}

void ConvertToMixedPrecisionPass::LoadModel() {
framework::Executor exe{phi::CPUPlace{}};
framework::Executor exe{CPUPlace{}};
// If we did not find the provided weight path,
// we assume that the model to be converted only has a model file and no
// params file, we believe this situation is reasonable. In this case, weight
Expand Down Expand Up @@ -177,7 +177,7 @@ void ConvertToMixedPrecisionPass::SaveMixedModel() {
op->SetAttr("file_path", save_params_path);
op->CheckAttrs();

framework::Executor exe(phi::CPUPlace{});
framework::Executor exe(CPUPlace{});
exe.Run(save_program, &scope_, 0, true, true);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void IrGraphBuildPass::RunImpl(Argument *argument) {
// so that the parameters will on the same device, or they will keep copying
// between difference devices.
phi::Place place;
place = phi::CPUPlace();
place = CPUPlace();

if (argument->model_dir_valid()) {
auto program =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void IrParamsSyncAmongDevicesPass::CopyParamsToGpu(Argument *argument) {
true,
common::errors::PreconditionNotMet(
"The gpu_device_id field should be valid"));
phi::Place place = phi::GPUPlace(argument->gpu_device_id());
phi::Place place = GPUPlace(argument->gpu_device_id());
auto *scope = argument->scope_ptr();
std::vector<std::string> all_vars = scope->LocalVarNames();

Expand Down Expand Up @@ -130,7 +130,7 @@ void IrParamsSyncAmongDevicesPass::CopyParamsToGpu(Argument *argument) {
dst_ptr = dev_ctx->Alloc(t, t->dtype());
phi::memory_utils::Copy(place,
dst_ptr,
phi::CPUPlace(),
CPUPlace(),
src_ptr,
t->numel() * phi::SizeOf(t->dtype()),
stream);
Expand Down Expand Up @@ -269,7 +269,7 @@ void IrParamsSyncAmongDevicesPass::RunImpl(Argument *argument) {
CopyParamsToXpu(argument);
}
#endif
paddle::memory::Release(phi::CPUPlace());
paddle::memory::Release(CPUPlace());
}

std::string IrParamsSyncAmongDevicesPass::repr() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void SaveOptimizedModelPass::SaveOptimizedModel(Argument* argument) {
op->SetAttr("file_path", save_params_path);
op->CheckAttrs();

framework::Executor exe(phi::CPUPlace{});
framework::Executor exe(CPUPlace{});
exe.Run(save_program, &scope, 0, true, true);
};
// TODO(shentanyue01): Setting hardware and version identification for
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/inference/io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ void SaveVars(const framework::Scope& scope,
op->SetAttr("file_path", dirname + "/param");
op->CheckAttrs();

phi::CPUPlace place;
CPUPlace place;
framework::Executor exe(place);
exe.Run(prog, const_cast<framework::Scope*>(&scope), 0, true, true);
}
Expand Down
14 changes: 7 additions & 7 deletions paddle/fluid/inference/tensorrt/convert/batch_norm_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,18 @@ class BatchNormOpConverter : public OpConverter {
scale_tensor.Resize(Scale_t->dims());
variance_tensor.Resize(Variance_t->dims());

phi::CPUPlace cpu_place;
CPUPlace cpu_place;
// copy data from gpu to cpu
paddle::framework::TensorCopySync((*Bias_t), cpu_place, &bias_tensor);
paddle::framework::TensorCopySync((*Mean_t), cpu_place, &mean_tensor);
paddle::framework::TensorCopySync((*Scale_t), cpu_place, &scale_tensor);
paddle::framework::TensorCopySync(
(*Variance_t), cpu_place, &variance_tensor);

auto* bias_data = bias_tensor.mutable_data<float>(phi::CPUPlace());
auto* mean_data = mean_tensor.mutable_data<float>(phi::CPUPlace());
auto* scale_data = scale_tensor.mutable_data<float>(phi::CPUPlace());
auto* variance_data = variance_tensor.mutable_data<float>(phi::CPUPlace());
auto* bias_data = bias_tensor.mutable_data<float>(CPUPlace());
auto* mean_data = mean_tensor.mutable_data<float>(CPUPlace());
auto* scale_data = scale_tensor.mutable_data<float>(CPUPlace());
auto* variance_data = variance_tensor.mutable_data<float>(CPUPlace());

std::unique_ptr<phi::DenseTensor> combine_scale_tensor(
new phi::DenseTensor());
Expand All @@ -92,9 +92,9 @@ class BatchNormOpConverter : public OpConverter {
combine_bias_tensor->Resize(bias_tensor.dims());

auto* combine_scale_data =
combine_scale_tensor->mutable_data<float>(phi::CPUPlace());
combine_scale_tensor->mutable_data<float>(CPUPlace());
auto* combine_bias_data =
combine_bias_tensor->mutable_data<float>(phi::CPUPlace());
combine_bias_tensor->mutable_data<float>(CPUPlace());

size_t ele_num = combine_scale_tensor->memory_size() / sizeof(float);

Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/inference/tensorrt/convert/dropout_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ class DropoutOpConverter : public OpConverter {
return;
}

phi::CPUPlace cpu_place;
CPUPlace cpu_place;
std::unique_ptr<phi::DenseTensor> weight_tensor(new phi::DenseTensor());
weight_tensor->Resize(common::make_ddim({1}));
auto* weight_data = weight_tensor->mutable_data<float>(phi::CPUPlace());
auto* weight_data = weight_tensor->mutable_data<float>(CPUPlace());
weight_data[0] = 1 - dropout_prob;

TensorRTEngine::Weight scale_weights{
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/inference/tensorrt/convert/fill_constant_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ class FillConstantOpConverter : public OpConverter {
void* trt_data = nullptr;
size_t trt_num;
if (dtype == 2 || dtype == 3) { // int,int64
auto* tmp_ptr = out_tensor->mutable_data<int>(phi::CPUPlace());
auto* tmp_ptr = out_tensor->mutable_data<int>(CPUPlace());
for (int64_t i = 0; i < out_tensor->numel(); i++)
tmp_ptr[i] = std::stoi(str_value);
trt_dtype = nvinfer1::DataType::kINT32;
trt_data = static_cast<void*>(tmp_ptr);
} else if (dtype == 5) { // float
auto* tmp_ptr = out_tensor->mutable_data<float>(phi::CPUPlace());
auto* tmp_ptr = out_tensor->mutable_data<float>(CPUPlace());
for (int64_t i = 0; i < out_tensor->numel(); i++)
tmp_ptr[i] = std::stof(str_value);
trt_data = static_cast<void*>(tmp_ptr);
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/inference/tensorrt/convert/gelu_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class GeluOpConverter : public OpConverter {
auto create_weights = [&](float data, std::string type) -> float* {
std::unique_ptr<phi::DenseTensor> tmp_tensor(new phi::DenseTensor());
tmp_tensor->Resize({1});
auto* tmp_data = tmp_tensor->mutable_data<float>(phi::CPUPlace());
auto* tmp_data = tmp_tensor->mutable_data<float>(CPUPlace());
tmp_data[0] = data;
engine_->SetWeights(out_name + "_gelu_op_" + type,
std::move(tmp_tensor));
Expand Down Expand Up @@ -146,7 +146,7 @@ class GeluOpConverter : public OpConverter {
auto create_weights = [&](float data, std::string type) -> float* {
std::unique_ptr<phi::DenseTensor> tmp_tensor(new phi::DenseTensor());
tmp_tensor->Resize({1});
auto* tmp_data = tmp_tensor->mutable_data<float>(phi::CPUPlace());
auto* tmp_data = tmp_tensor->mutable_data<float>(CPUPlace());
tmp_data[0] = data;
engine_->SetWeights(out_name + "_gelu_op_" + type,
std::move(tmp_tensor));
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/inference/tensorrt/convert/leaky_relu_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class LeakyReluOpConverter : public OpConverter {
engine_->SetTensorDynamicRange(input, in_scale);
}
#else
phi::CPUPlace place;
CPUPlace place;
std::unique_ptr<phi::DenseTensor> alpha_tensor(new phi::DenseTensor());
alpha_tensor->Resize(common::make_ddim({2}));
float* alpha_data = alpha_tensor->mutable_data<float>(place);
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/inference/tensorrt/convert/op_converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ class OpConverter {
shape.d, shape.d + shape.nbDims, 1, std::multiplies<int>());
std::unique_ptr<phi::DenseTensor> tmp_tensor(new phi::DenseTensor());
tmp_tensor->Resize({data_size});
auto* tmp_data = tmp_tensor->mutable_data<T>(phi::CPUPlace());
auto* tmp_data = tmp_tensor->mutable_data<T>(CPUPlace());
for (int i = 0; i < data_size; i++) {
tmp_data[i] = data[i];
}
Expand Down Expand Up @@ -740,7 +740,7 @@ class OpConverter {
std::unique_ptr<phi::DenseTensor> tmp_tensor(new phi::DenseTensor());
int data_size = data.size();
tmp_tensor->Resize({data_size});
auto* tmp_data = tmp_tensor->mutable_data<T>(phi::CPUPlace());
auto* tmp_data = tmp_tensor->mutable_data<T>(CPUPlace());
for (int i = 0; i < data_size; i++) {
tmp_data[i] = data[i];
}
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/inference/tensorrt/convert/test_io_converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ void IOConverterTester(const phi::DeviceContext& ctx) {
}

TEST(EngineIOConverterTester, DefaultCPU) {
phi::CPUPlace place;
CPUPlace place;
phi::CPUContext ctx(place);
IOConverterTester(ctx);
}

TEST(EngineIOConverterTester, DefaultGPU) {
phi::GPUPlace place;
GPUPlace place;
phi::GPUContext ctx(place);
IOConverterTester(ctx);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ TEST(OpConverter, ConvertBlock) {
auto* x = scope.Var("conv2d-Y");
auto* x_tensor = x->GetMutable<phi::DenseTensor>();
x_tensor->Resize(common::make_ddim(dim_vec));
x_tensor->mutable_data<float>(phi::GPUPlace(0));
x_tensor->mutable_data<float>(GPUPlace(0));

OpTeller::Global().SetOpConverterType(conv2d_op, OpConverterType::Default);
OpConverter converter;
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/inference/tensorrt/convert/ut_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void RandomizeTensor(phi::DenseTensor* tensor,
common::errors::PermissionDenied("RandomizeTensor only can be used for "
"tensor which dims is not zero."));

phi::CPUPlace cpu_place;
CPUPlace cpu_place;
phi::DenseTensor temp_tensor;
temp_tensor.Resize(dims);
auto* temp_data = temp_tensor.mutable_data<float>(cpu_place);
Expand Down Expand Up @@ -250,7 +250,7 @@ class TRTConvertValidation {
framework::Scope& scope() { return scope_; }

private:
phi::GPUPlace place_;
GPUPlace place_;
std::unique_ptr<TensorRTEngine> engine_;
cudaStream_t stream_;
std::unique_ptr<framework::OperatorBase> op_;
Expand Down
64 changes: 28 additions & 36 deletions paddle/fluid/inference/tensorrt/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void TensorRTEngine::Execute(int batch_size,
inference::Singleton<inference::tensorrt::TRTEngineManager>::Global()
.GetContextMemory(
predictor_id_per_thread,
phi::GPUPlace(device_id()),
GPUPlace(device_id()),
phi::Stream(reinterpret_cast<phi::StreamId>(stream)));
infer_context->setDeviceMemory(context_memory);
}
Expand Down Expand Up @@ -669,7 +669,7 @@ TensorRTEngine::Weight TensorRTEngine::GetFp16TrtWeight(
std::string name_suffix = std::to_string(name_suffix_counter);
std::string splitter = "__";
std::string name_with_suffix = name + splitter + name_suffix;
phi::CPUPlace cpu_place;
CPUPlace cpu_place;
PADDLE_ENFORCE_EQ(weight_map.count(name_with_suffix),
0,
common::errors::AlreadyExists(
Expand All @@ -686,12 +686,11 @@ TensorRTEngine::Weight TensorRTEngine::GetFp16TrtWeight(
if (weight_tensor.dtype() == phi::DataType::BFLOAT16) {
phi::DenseTensor bf16_tensor;
bf16_tensor.clear();
paddle::framework::TensorCopySync(
weight_tensor, phi::CPUPlace(), &bf16_tensor);
paddle::framework::TensorCopySync(weight_tensor, CPUPlace(), &bf16_tensor);
weight_map[name_with_suffix]->set_type(phi::DataType::FLOAT16);
auto *fp16_data =
weight_map[name_with_suffix]->mutable_data<float16>(phi::CPUPlace());
auto *bf16_data = bf16_tensor.mutable_data<bfloat16>(phi::CPUPlace());
weight_map[name_with_suffix]->mutable_data<float16>(CPUPlace());
auto *bf16_data = bf16_tensor.mutable_data<bfloat16>(CPUPlace());
for (int i = 0; i < weight_tensor.numel(); i++) {
fp16_data[i] = static_cast<float16>(bf16_data[i]);
}
Expand All @@ -700,12 +699,11 @@ TensorRTEngine::Weight TensorRTEngine::GetFp16TrtWeight(
} else if (weight_tensor.dtype() == phi::DataType::FLOAT32) {
phi::DenseTensor fp32_tensor;
fp32_tensor.clear();
paddle::framework::TensorCopySync(
weight_tensor, phi::CPUPlace(), &fp32_tensor);
paddle::framework::TensorCopySync(weight_tensor, CPUPlace(), &fp32_tensor);
weight_map[name_with_suffix]->set_type(phi::DataType::FLOAT16);
auto *fp16_data =
weight_map[name_with_suffix]->mutable_data<float16>(phi::CPUPlace());
auto *fp32_data = fp32_tensor.mutable_data<float>(phi::CPUPlace());
weight_map[name_with_suffix]->mutable_data<float16>(CPUPlace());
auto *fp32_data = fp32_tensor.mutable_data<float>(CPUPlace());
for (int i = 0; i < weight_tensor.numel(); i++) {
fp16_data[i] = static_cast<float16>(fp32_data[i]);
}
Expand All @@ -714,12 +712,11 @@ TensorRTEngine::Weight TensorRTEngine::GetFp16TrtWeight(
} else if (weight_tensor.dtype() == phi::DataType::INT64) {
phi::DenseTensor int64_tensor;
int64_tensor.clear();
paddle::framework::TensorCopySync(
weight_tensor, phi::CPUPlace(), &int64_tensor);
paddle::framework::TensorCopySync(weight_tensor, CPUPlace(), &int64_tensor);
weight_map[name_with_suffix]->set_type(phi::DataType::INT32);
auto *int32_data =
weight_map[name_with_suffix]->mutable_data<int32_t>(phi::CPUPlace());
auto *int64_data = int64_tensor.mutable_data<int64_t>(phi::CPUPlace());
weight_map[name_with_suffix]->mutable_data<int32_t>(CPUPlace());
auto *int64_data = int64_tensor.mutable_data<int64_t>(CPUPlace());
for (int i = 0; i < weight_tensor.numel(); i++) {
int32_data[i] = int64_data[i];
}
Expand All @@ -742,7 +739,7 @@ TensorRTEngine::Weight TensorRTEngine::GetFp32TrtWeight(
std::string name_suffix = std::to_string(name_suffix_counter);
std::string splitter = "__";
std::string name_with_suffix = name + splitter + name_suffix;
phi::CPUPlace cpu_place;
CPUPlace cpu_place;
PADDLE_ENFORCE_EQ(weight_map.count(name_with_suffix),
0,
common::errors::AlreadyExists(
Expand All @@ -759,12 +756,11 @@ TensorRTEngine::Weight TensorRTEngine::GetFp32TrtWeight(
if (weight_tensor.dtype() == phi::DataType::BFLOAT16) {
phi::DenseTensor bf16_tensor;
bf16_tensor.clear();
paddle::framework::TensorCopySync(
weight_tensor, phi::CPUPlace(), &bf16_tensor);
paddle::framework::TensorCopySync(weight_tensor, CPUPlace(), &bf16_tensor);
weight_map[name_with_suffix]->set_type(phi::DataType::FLOAT32);
auto *fp32_data =
weight_map[name_with_suffix]->mutable_data<float>(phi::CPUPlace());
auto *bf16_data = bf16_tensor.mutable_data<bfloat16>(phi::CPUPlace());
weight_map[name_with_suffix]->mutable_data<float>(CPUPlace());
auto *bf16_data = bf16_tensor.mutable_data<bfloat16>(CPUPlace());
for (int i = 0; i < weight_tensor.numel(); i++) {
fp32_data[i] = static_cast<float>(bf16_data[i]);
}
Expand All @@ -773,12 +769,11 @@ TensorRTEngine::Weight TensorRTEngine::GetFp32TrtWeight(
} else if (weight_tensor.dtype() == phi::DataType::FLOAT16) {
phi::DenseTensor fp16_tensor;
fp16_tensor.clear();
paddle::framework::TensorCopySync(
weight_tensor, phi::CPUPlace(), &fp16_tensor);
paddle::framework::TensorCopySync(weight_tensor, CPUPlace(), &fp16_tensor);
weight_map[name_with_suffix]->set_type(phi::DataType::FLOAT32);
auto *fp32_data =
weight_map[name_with_suffix]->mutable_data<float>(phi::CPUPlace());
auto *fp16_data = fp16_tensor.mutable_data<float16>(phi::CPUPlace());
weight_map[name_with_suffix]->mutable_data<float>(CPUPlace());
auto *fp16_data = fp16_tensor.mutable_data<float16>(CPUPlace());
for (int i = 0; i < weight_tensor.numel(); i++) {
fp32_data[i] = static_cast<float>(fp16_data[i]);
}
Expand All @@ -787,12 +782,11 @@ TensorRTEngine::Weight TensorRTEngine::GetFp32TrtWeight(
} else if (weight_tensor.dtype() == phi::DataType::INT64) {
phi::DenseTensor int64_tensor;
int64_tensor.clear();
paddle::framework::TensorCopySync(
weight_tensor, phi::CPUPlace(), &int64_tensor);
paddle::framework::TensorCopySync(weight_tensor, CPUPlace(), &int64_tensor);
weight_map[name_with_suffix]->set_type(phi::DataType::INT32);
auto *int32_data =
weight_map[name_with_suffix]->mutable_data<int32_t>(phi::CPUPlace());
auto *int64_data = int64_tensor.mutable_data<int64_t>(phi::CPUPlace());
weight_map[name_with_suffix]->mutable_data<int32_t>(CPUPlace());
auto *int64_data = int64_tensor.mutable_data<int64_t>(CPUPlace());
for (int i = 0; i < weight_tensor.numel(); i++) {
int32_data[i] = int64_data[i];
}
Expand All @@ -814,7 +808,7 @@ TensorRTEngine::Weight TensorRTEngine::GetTrtWeight(
std::string name_suffix = std::to_string(name_suffix_counter);
std::string splitter = "__";
std::string name_with_suffix = name + splitter + name_suffix;
phi::CPUPlace cpu_place;
CPUPlace cpu_place;
PADDLE_ENFORCE_EQ(weight_map.count(name_with_suffix),
0,
common::errors::AlreadyExists(
Expand All @@ -835,12 +829,11 @@ TensorRTEngine::Weight TensorRTEngine::GetTrtWeight(
if (weight_tensor.dtype() == phi::DataType::BFLOAT16) {
phi::DenseTensor bf16_tensor;
bf16_tensor.clear();
paddle::framework::TensorCopySync(
weight_tensor, phi::CPUPlace(), &bf16_tensor);
paddle::framework::TensorCopySync(weight_tensor, CPUPlace(), &bf16_tensor);
weight_map[name_with_suffix]->set_type(phi::DataType::FLOAT32);
auto *fp32_data =
weight_map[name_with_suffix]->mutable_data<float>(phi::CPUPlace());
auto *bf16_data = bf16_tensor.mutable_data<bfloat16>(phi::CPUPlace());
weight_map[name_with_suffix]->mutable_data<float>(CPUPlace());
auto *bf16_data = bf16_tensor.mutable_data<bfloat16>(CPUPlace());
for (int i = 0; i < weight_tensor.numel(); i++) {
fp32_data[i] = static_cast<float>(bf16_data[i]);
}
Expand All @@ -849,12 +842,11 @@ TensorRTEngine::Weight TensorRTEngine::GetTrtWeight(
} else if (weight_tensor.dtype() == phi::DataType::INT64) {
phi::DenseTensor int64_tensor;
int64_tensor.clear();
paddle::framework::TensorCopySync(
weight_tensor, phi::CPUPlace(), &int64_tensor);
paddle::framework::TensorCopySync(weight_tensor, CPUPlace(), &int64_tensor);
weight_map[name_with_suffix]->set_type(phi::DataType::INT32);
auto *int32_data =
weight_map[name_with_suffix]->mutable_data<int32_t>(phi::CPUPlace());
auto *int64_data = int64_tensor.mutable_data<int64_t>(phi::CPUPlace());
weight_map[name_with_suffix]->mutable_data<int32_t>(CPUPlace());
auto *int64_data = int64_tensor.mutable_data<int64_t>(CPUPlace());
for (int i = 0; i < weight_tensor.numel(); i++) {
int32_data[i] = int64_data[i];
}
Expand Down
Loading
Loading