diff --git a/paddle/fluid/inference/api/analysis_predictor.cc b/paddle/fluid/inference/api/analysis_predictor.cc index 39c83d24a1522c1fafdc6036b9273981c9dc7c02..8971448071f1d2d7521889ca2f30ad9e211d1bcc 100644 --- a/paddle/fluid/inference/api/analysis_predictor.cc +++ b/paddle/fluid/inference/api/analysis_predictor.cc @@ -393,7 +393,7 @@ void AnalysisPredictor::InitDeviceContexts() { place_, std::async(std::launch::deferred, [=] { auto *gpu_resource = ResourceManager::Instance().GetGPUResource(predictor_stream_); - auto *gpu_context = new InferGPUContext(); + auto *gpu_context = new InferGPUContext(place_); gpu_context->SetAllocator( memory::allocation::AllocatorFacade::Instance() .GetAllocator(place_, gpu_resource->GetStream()) diff --git a/paddle/fluid/inference/api/infer_context.cc b/paddle/fluid/inference/api/infer_context.cc index 7706f2d0824e305534ed2275f6be282f6cab4454..9a76528a48edb50bef279f70c63cab539416ffa2 100644 --- a/paddle/fluid/inference/api/infer_context.cc +++ b/paddle/fluid/inference/api/infer_context.cc @@ -13,5 +13,13 @@ // limitations under the License. #include "paddle/fluid/inference/api/infer_context.h" +#include "paddle/phi/backends/gpu/gpu_context.h" -namespace paddle {} // namespace paddle +namespace paddle { + +#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) +InferGPUContext::InferGPUContext(const phi::Place& place) + : phi::GPUContext(place, false) {} +#endif + +} // namespace paddle diff --git a/paddle/fluid/inference/api/infer_context.h b/paddle/fluid/inference/api/infer_context.h index c2a23a7ca2ce5d027093b68e4d25892255fa9046..5dbcf355a6e279712c45a3e6296c51b478e37efb 100644 --- a/paddle/fluid/inference/api/infer_context.h +++ b/paddle/fluid/inference/api/infer_context.h @@ -14,6 +14,7 @@ #pragma once #include "paddle/phi/backends/all_context.h" +#include "paddle/phi/common/place.h" namespace paddle { @@ -25,6 +26,7 @@ class InferCPUContext : public phi::CPUContext { #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) class InferGPUContext : public phi::GPUContext { public: + explicit InferGPUContext(const phi::Place& place); using phi::GPUContext::SetBlasHandle; using phi::GPUContext::SetBlasTensorCoreHandle; using phi::GPUContext::SetBlasTF32Handle; diff --git a/paddle/phi/backends/gpu/gpu_context.cc b/paddle/phi/backends/gpu/gpu_context.cc index a7d79738142a3c2fbaca1ef558c598b1fe09232b..87d779f9194dba6840aab833ba637a4d222604dd 100644 --- a/paddle/phi/backends/gpu/gpu_context.cc +++ b/paddle/phi/backends/gpu/gpu_context.cc @@ -240,8 +240,6 @@ struct GPUContext::Impl { InitDnnWorkspace(); } - Impl() : place_(GPUPlace()) {} - explicit Impl(const GPUPlace& place) : place_(place) {} ~Impl() { @@ -784,8 +782,6 @@ struct GPUContext::Impl { std::unique_ptr eigen_stream_{nullptr}; }; -GPUContext::GPUContext() : DeviceContext(), impl_(std::make_unique()) {} - GPUContext::GPUContext(GPUContext&&) = default; GPUContext& GPUContext::operator=(GPUContext&&) = default; diff --git a/paddle/phi/backends/gpu/gpu_context.h b/paddle/phi/backends/gpu/gpu_context.h index 376d9e47f492ccd544d96148bda6823630061dc8..989bbbcbbf5f8c63ebb9b2e815ca2346189275c0 100644 --- a/paddle/phi/backends/gpu/gpu_context.h +++ b/paddle/phi/backends/gpu/gpu_context.h @@ -79,7 +79,6 @@ class DnnWorkspaceHandle { class PADDLE_API GPUContext : public DeviceContext { public: - GPUContext(); explicit GPUContext(const GPUPlace& place, bool init = true); GPUContext(GPUContext&&); diff --git a/paddle/phi/tests/common/test_scalar.cu b/paddle/phi/tests/common/test_scalar.cu index e985f1c417de3d7d792e08c3a55e63b948a6bd4b..ad41201b9302fe494618c67ddd6ee0730ac185ad 100644 --- a/paddle/phi/tests/common/test_scalar.cu +++ b/paddle/phi/tests/common/test_scalar.cu @@ -21,6 +21,7 @@ limitations under the License. */ #include "paddle/phi/backends/gpu/gpu_context.h" #include "paddle/phi/common/complex.h" #include "paddle/phi/common/float16.h" +#include "paddle/phi/common/place.h" #include "paddle/phi/common/scalar.h" #include "paddle/phi/core/dense_tensor.h" #include "paddle/phi/core/kernel_registry.h" @@ -159,7 +160,7 @@ TEST(Scalar, ConstructFromDenseTensor7) { alloc.get(), phi::DenseTensorMeta( phi::DataType::FLOAT32, phi::make_ddim({1}), phi::DataLayout::NCHW)); - phi::GPUContext dev_ctx; + phi::GPUContext dev_ctx{phi::GPUPlace()}; dev_ctx.SetAllocator(paddle::memory::allocation::AllocatorFacade::Instance() .GetAllocator(phi::GPUPlace()) .get()); @@ -181,7 +182,7 @@ TEST(Scalar, ConstructFromTensor) { phi::DenseTensorMeta( phi::DataType::FLOAT32, phi::make_ddim({1}), phi::DataLayout::NCHW)); - phi::GPUContext dev_ctx; + phi::GPUContext dev_ctx{phi::GPUPlace()}; dev_ctx.SetAllocator(paddle::memory::allocation::AllocatorFacade::Instance() .GetAllocator(phi::GPUPlace()) .get()); diff --git a/paddle/phi/tests/kernels/test_sparse_conv3d_dev_api.cc b/paddle/phi/tests/kernels/test_sparse_conv3d_dev_api.cc index f7c7b7e9486ee85b4ff28305b8bc5409211208f4..f9c41d1826ab75dc6e69bc02d1216ed2cfcf8651 100644 --- a/paddle/phi/tests/kernels/test_sparse_conv3d_dev_api.cc +++ b/paddle/phi/tests/kernels/test_sparse_conv3d_dev_api.cc @@ -160,7 +160,7 @@ void TestConv3dBase(const std::vector& indices, // test gpu #if defined(PADDLE_WITH_CUDA) - phi::GPUContext dev_ctx_gpu; + phi::GPUContext dev_ctx_gpu{phi::GPUPlace()}; dev_ctx_gpu.PartialInitWithoutAllocator(); dev_ctx_gpu.SetAllocator( paddle::memory::allocation::AllocatorFacade::Instance() diff --git a/paddle/phi/tests/kernels/test_sparse_pool_dev_api.cc b/paddle/phi/tests/kernels/test_sparse_pool_dev_api.cc index ffc2604e6b8daad773831a780d3abd67941271b6..b4e1def372fbb90691ab06ff90eff1ae961fbf7a 100644 --- a/paddle/phi/tests/kernels/test_sparse_pool_dev_api.cc +++ b/paddle/phi/tests/kernels/test_sparse_pool_dev_api.cc @@ -122,7 +122,7 @@ void TestMaxPoolBase(const std::vector& indices, // test gpu #if defined(PADDLE_WITH_CUDA) - phi::GPUContext dev_ctx_gpu; + phi::GPUContext dev_ctx_gpu{phi::GPUPlace()}; dev_ctx_gpu.PartialInitWithoutAllocator(); dev_ctx_gpu.SetAllocator( paddle::memory::allocation::AllocatorFacade::Instance() diff --git a/paddle/phi/tests/kernels/test_sparse_utils_dev_api.cc b/paddle/phi/tests/kernels/test_sparse_utils_dev_api.cc index 70c9f4cfc611d77dd7a895adb28f0c3d78c6ed50..29300d8f58adf7632f217e605c71c8924db80be1 100644 --- a/paddle/phi/tests/kernels/test_sparse_utils_dev_api.cc +++ b/paddle/phi/tests/kernels/test_sparse_utils_dev_api.cc @@ -105,7 +105,7 @@ void TestDenseToSparseCoo(const DenseTensor& dense_x, // 2. test cuda #if defined(PADDLE_WITH_CUDA) - phi::GPUContext dev_ctx_gpu; + phi::GPUContext dev_ctx_gpu{phi::GPUPlace()}; dev_ctx_gpu.PartialInitWithoutAllocator(); dev_ctx_gpu.SetAllocator( paddle::memory::allocation::AllocatorFacade::Instance() @@ -319,7 +319,7 @@ void TestSparseCsrToCoo(const DDim& dense_dims, alloc); // 2. test cuda #if defined(PADDLE_WITH_CUDA) - phi::GPUContext dev_ctx_gpu; + phi::GPUContext dev_ctx_gpu{phi::GPUPlace()}; dev_ctx_gpu.PartialInitWithoutAllocator(); dev_ctx_gpu.SetAllocator( paddle::memory::allocation::AllocatorFacade::Instance() @@ -505,7 +505,7 @@ void TestCooToCsr(const DDim& dense_dims, const auto cuda_alloc = std::make_shared( paddle::platform::CUDAPlace()); - phi::GPUContext dev_ctx_gpu; + phi::GPUContext dev_ctx_gpu{phi::GPUPlace()}; dev_ctx_gpu.PartialInitWithoutAllocator(); dev_ctx_gpu.SetAllocator( paddle::memory::allocation::AllocatorFacade::Instance() @@ -608,7 +608,7 @@ void TestDenseToSparseCsr(const DenseTensor& dense_x, cuda_alloc.get(), DenseTensorMeta(dense_x.dtype(), dense_x.dims(), dense_x.layout())); - phi::GPUContext dev_ctx_gpu; + phi::GPUContext dev_ctx_gpu{phi::GPUPlace()}; dev_ctx_gpu.PartialInitWithoutAllocator(); dev_ctx_gpu.SetAllocator( paddle::memory::allocation::AllocatorFacade::Instance() @@ -741,7 +741,7 @@ void TestSparseCooToDense(const DDim& dense_dims, const auto cuda_alloc = std::make_shared( paddle::platform::CUDAPlace()); - phi::GPUContext dev_ctx_gpu; + phi::GPUContext dev_ctx_gpu{phi::GPUPlace()}; dev_ctx_gpu.PartialInitWithoutAllocator(); dev_ctx_gpu.SetAllocator( paddle::memory::allocation::AllocatorFacade::Instance() @@ -889,7 +889,7 @@ void TestSparseCsrToDense(const DDim& dense_dims, const auto cuda_alloc = std::make_shared( paddle::platform::CUDAPlace()); - phi::GPUContext dev_ctx_gpu; + phi::GPUContext dev_ctx_gpu{phi::GPUPlace()}; dev_ctx_gpu.PartialInitWithoutAllocator(); dev_ctx_gpu.SetAllocator( paddle::memory::allocation::AllocatorFacade::Instance()