未验证 提交 74e46a93 编写于 作者: W Wilber 提交者: GitHub

infer context fix place error. (#44726)

* infer context fix place error.

* update

* update
上级 71f74f5c
...@@ -393,7 +393,7 @@ void AnalysisPredictor::InitDeviceContexts() { ...@@ -393,7 +393,7 @@ void AnalysisPredictor::InitDeviceContexts() {
place_, std::async(std::launch::deferred, [=] { place_, std::async(std::launch::deferred, [=] {
auto *gpu_resource = auto *gpu_resource =
ResourceManager::Instance().GetGPUResource(predictor_stream_); ResourceManager::Instance().GetGPUResource(predictor_stream_);
auto *gpu_context = new InferGPUContext(); auto *gpu_context = new InferGPUContext(place_);
gpu_context->SetAllocator( gpu_context->SetAllocator(
memory::allocation::AllocatorFacade::Instance() memory::allocation::AllocatorFacade::Instance()
.GetAllocator(place_, gpu_resource->GetStream()) .GetAllocator(place_, gpu_resource->GetStream())
......
...@@ -13,5 +13,13 @@ ...@@ -13,5 +13,13 @@
// limitations under the License. // limitations under the License.
#include "paddle/fluid/inference/api/infer_context.h" #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
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#pragma once #pragma once
#include "paddle/phi/backends/all_context.h" #include "paddle/phi/backends/all_context.h"
#include "paddle/phi/common/place.h"
namespace paddle { namespace paddle {
...@@ -25,6 +26,7 @@ class InferCPUContext : public phi::CPUContext { ...@@ -25,6 +26,7 @@ class InferCPUContext : public phi::CPUContext {
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
class InferGPUContext : public phi::GPUContext { class InferGPUContext : public phi::GPUContext {
public: public:
explicit InferGPUContext(const phi::Place& place);
using phi::GPUContext::SetBlasHandle; using phi::GPUContext::SetBlasHandle;
using phi::GPUContext::SetBlasTensorCoreHandle; using phi::GPUContext::SetBlasTensorCoreHandle;
using phi::GPUContext::SetBlasTF32Handle; using phi::GPUContext::SetBlasTF32Handle;
......
...@@ -240,8 +240,6 @@ struct GPUContext::Impl { ...@@ -240,8 +240,6 @@ struct GPUContext::Impl {
InitDnnWorkspace(); InitDnnWorkspace();
} }
Impl() : place_(GPUPlace()) {}
explicit Impl(const GPUPlace& place) : place_(place) {} explicit Impl(const GPUPlace& place) : place_(place) {}
~Impl() { ~Impl() {
...@@ -784,8 +782,6 @@ struct GPUContext::Impl { ...@@ -784,8 +782,6 @@ struct GPUContext::Impl {
std::unique_ptr<internal::EigenGpuStreamDevice> eigen_stream_{nullptr}; std::unique_ptr<internal::EigenGpuStreamDevice> eigen_stream_{nullptr};
}; };
GPUContext::GPUContext() : DeviceContext(), impl_(std::make_unique<Impl>()) {}
GPUContext::GPUContext(GPUContext&&) = default; GPUContext::GPUContext(GPUContext&&) = default;
GPUContext& GPUContext::operator=(GPUContext&&) = default; GPUContext& GPUContext::operator=(GPUContext&&) = default;
......
...@@ -79,7 +79,6 @@ class DnnWorkspaceHandle { ...@@ -79,7 +79,6 @@ class DnnWorkspaceHandle {
class PADDLE_API GPUContext : public DeviceContext { class PADDLE_API GPUContext : public DeviceContext {
public: public:
GPUContext();
explicit GPUContext(const GPUPlace& place, bool init = true); explicit GPUContext(const GPUPlace& place, bool init = true);
GPUContext(GPUContext&&); GPUContext(GPUContext&&);
......
...@@ -21,6 +21,7 @@ limitations under the License. */ ...@@ -21,6 +21,7 @@ limitations under the License. */
#include "paddle/phi/backends/gpu/gpu_context.h" #include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/common/complex.h" #include "paddle/phi/common/complex.h"
#include "paddle/phi/common/float16.h" #include "paddle/phi/common/float16.h"
#include "paddle/phi/common/place.h"
#include "paddle/phi/common/scalar.h" #include "paddle/phi/common/scalar.h"
#include "paddle/phi/core/dense_tensor.h" #include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/core/kernel_registry.h" #include "paddle/phi/core/kernel_registry.h"
...@@ -159,7 +160,7 @@ TEST(Scalar, ConstructFromDenseTensor7) { ...@@ -159,7 +160,7 @@ TEST(Scalar, ConstructFromDenseTensor7) {
alloc.get(), alloc.get(),
phi::DenseTensorMeta( phi::DenseTensorMeta(
phi::DataType::FLOAT32, phi::make_ddim({1}), phi::DataLayout::NCHW)); 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() dev_ctx.SetAllocator(paddle::memory::allocation::AllocatorFacade::Instance()
.GetAllocator(phi::GPUPlace()) .GetAllocator(phi::GPUPlace())
.get()); .get());
...@@ -181,7 +182,7 @@ TEST(Scalar, ConstructFromTensor) { ...@@ -181,7 +182,7 @@ TEST(Scalar, ConstructFromTensor) {
phi::DenseTensorMeta( phi::DenseTensorMeta(
phi::DataType::FLOAT32, phi::make_ddim({1}), phi::DataLayout::NCHW)); 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() dev_ctx.SetAllocator(paddle::memory::allocation::AllocatorFacade::Instance()
.GetAllocator(phi::GPUPlace()) .GetAllocator(phi::GPUPlace())
.get()); .get());
......
...@@ -160,7 +160,7 @@ void TestConv3dBase(const std::vector<IntT>& indices, ...@@ -160,7 +160,7 @@ void TestConv3dBase(const std::vector<IntT>& indices,
// test gpu // test gpu
#if defined(PADDLE_WITH_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.PartialInitWithoutAllocator();
dev_ctx_gpu.SetAllocator( dev_ctx_gpu.SetAllocator(
paddle::memory::allocation::AllocatorFacade::Instance() paddle::memory::allocation::AllocatorFacade::Instance()
......
...@@ -122,7 +122,7 @@ void TestMaxPoolBase(const std::vector<IntT>& indices, ...@@ -122,7 +122,7 @@ void TestMaxPoolBase(const std::vector<IntT>& indices,
// test gpu // test gpu
#if defined(PADDLE_WITH_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.PartialInitWithoutAllocator();
dev_ctx_gpu.SetAllocator( dev_ctx_gpu.SetAllocator(
paddle::memory::allocation::AllocatorFacade::Instance() paddle::memory::allocation::AllocatorFacade::Instance()
......
...@@ -105,7 +105,7 @@ void TestDenseToSparseCoo(const DenseTensor& dense_x, ...@@ -105,7 +105,7 @@ void TestDenseToSparseCoo(const DenseTensor& dense_x,
// 2. test cuda // 2. test cuda
#if defined(PADDLE_WITH_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.PartialInitWithoutAllocator();
dev_ctx_gpu.SetAllocator( dev_ctx_gpu.SetAllocator(
paddle::memory::allocation::AllocatorFacade::Instance() paddle::memory::allocation::AllocatorFacade::Instance()
...@@ -319,7 +319,7 @@ void TestSparseCsrToCoo(const DDim& dense_dims, ...@@ -319,7 +319,7 @@ void TestSparseCsrToCoo(const DDim& dense_dims,
alloc); alloc);
// 2. test cuda // 2. test cuda
#if defined(PADDLE_WITH_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.PartialInitWithoutAllocator();
dev_ctx_gpu.SetAllocator( dev_ctx_gpu.SetAllocator(
paddle::memory::allocation::AllocatorFacade::Instance() paddle::memory::allocation::AllocatorFacade::Instance()
...@@ -505,7 +505,7 @@ void TestCooToCsr(const DDim& dense_dims, ...@@ -505,7 +505,7 @@ void TestCooToCsr(const DDim& dense_dims,
const auto cuda_alloc = const auto cuda_alloc =
std::make_shared<paddle::experimental::DefaultAllocator>( std::make_shared<paddle::experimental::DefaultAllocator>(
paddle::platform::CUDAPlace()); paddle::platform::CUDAPlace());
phi::GPUContext dev_ctx_gpu; phi::GPUContext dev_ctx_gpu{phi::GPUPlace()};
dev_ctx_gpu.PartialInitWithoutAllocator(); dev_ctx_gpu.PartialInitWithoutAllocator();
dev_ctx_gpu.SetAllocator( dev_ctx_gpu.SetAllocator(
paddle::memory::allocation::AllocatorFacade::Instance() paddle::memory::allocation::AllocatorFacade::Instance()
...@@ -608,7 +608,7 @@ void TestDenseToSparseCsr(const DenseTensor& dense_x, ...@@ -608,7 +608,7 @@ void TestDenseToSparseCsr(const DenseTensor& dense_x,
cuda_alloc.get(), cuda_alloc.get(),
DenseTensorMeta(dense_x.dtype(), dense_x.dims(), dense_x.layout())); 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.PartialInitWithoutAllocator();
dev_ctx_gpu.SetAllocator( dev_ctx_gpu.SetAllocator(
paddle::memory::allocation::AllocatorFacade::Instance() paddle::memory::allocation::AllocatorFacade::Instance()
...@@ -741,7 +741,7 @@ void TestSparseCooToDense(const DDim& dense_dims, ...@@ -741,7 +741,7 @@ void TestSparseCooToDense(const DDim& dense_dims,
const auto cuda_alloc = const auto cuda_alloc =
std::make_shared<paddle::experimental::DefaultAllocator>( std::make_shared<paddle::experimental::DefaultAllocator>(
paddle::platform::CUDAPlace()); paddle::platform::CUDAPlace());
phi::GPUContext dev_ctx_gpu; phi::GPUContext dev_ctx_gpu{phi::GPUPlace()};
dev_ctx_gpu.PartialInitWithoutAllocator(); dev_ctx_gpu.PartialInitWithoutAllocator();
dev_ctx_gpu.SetAllocator( dev_ctx_gpu.SetAllocator(
paddle::memory::allocation::AllocatorFacade::Instance() paddle::memory::allocation::AllocatorFacade::Instance()
...@@ -889,7 +889,7 @@ void TestSparseCsrToDense(const DDim& dense_dims, ...@@ -889,7 +889,7 @@ void TestSparseCsrToDense(const DDim& dense_dims,
const auto cuda_alloc = const auto cuda_alloc =
std::make_shared<paddle::experimental::DefaultAllocator>( std::make_shared<paddle::experimental::DefaultAllocator>(
paddle::platform::CUDAPlace()); paddle::platform::CUDAPlace());
phi::GPUContext dev_ctx_gpu; phi::GPUContext dev_ctx_gpu{phi::GPUPlace()};
dev_ctx_gpu.PartialInitWithoutAllocator(); dev_ctx_gpu.PartialInitWithoutAllocator();
dev_ctx_gpu.SetAllocator( dev_ctx_gpu.SetAllocator(
paddle::memory::allocation::AllocatorFacade::Instance() paddle::memory::allocation::AllocatorFacade::Instance()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册