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
2 changes: 1 addition & 1 deletion paddle/fluid/inference/api/analysis_predictor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
10 changes: 9 additions & 1 deletion paddle/fluid/inference/api/infer_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions paddle/fluid/inference/api/infer_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#pragma once

#include "paddle/phi/backends/all_context.h"
#include "paddle/phi/common/place.h"

namespace paddle {

Expand All @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions paddle/phi/backends/gpu/gpu_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,6 @@ struct GPUContext::Impl {
InitDnnWorkspace();
}

Impl() : place_(GPUPlace()) {}

explicit Impl(const GPUPlace& place) : place_(place) {}

~Impl() {
Expand Down Expand Up @@ -784,8 +782,6 @@ struct GPUContext::Impl {
std::unique_ptr<internal::EigenGpuStreamDevice> eigen_stream_{nullptr};
};

GPUContext::GPUContext() : DeviceContext(), impl_(std::make_unique<Impl>()) {}

GPUContext::GPUContext(GPUContext&&) = default;

GPUContext& GPUContext::operator=(GPUContext&&) = default;
Expand Down
1 change: 0 additions & 1 deletion paddle/phi/backends/gpu/gpu_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ class DnnWorkspaceHandle {

class PADDLE_API GPUContext : public DeviceContext {
public:
GPUContext();
explicit GPUContext(const GPUPlace& place, bool init = true);

GPUContext(GPUContext&&);
Expand Down
5 changes: 3 additions & 2 deletions paddle/phi/tests/common/test_scalar.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion paddle/phi/tests/kernels/test_sparse_conv3d_dev_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void TestConv3dBase(const std::vector<IntT>& 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()
Expand Down
2 changes: 1 addition & 1 deletion paddle/phi/tests/kernels/test_sparse_pool_dev_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void TestMaxPoolBase(const std::vector<IntT>& 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()
Expand Down
12 changes: 6 additions & 6 deletions paddle/phi/tests/kernels/test_sparse_utils_dev_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -505,7 +505,7 @@ void TestCooToCsr(const DDim& dense_dims,
const auto cuda_alloc =
std::make_shared<paddle::experimental::DefaultAllocator>(
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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -741,7 +741,7 @@ void TestSparseCooToDense(const DDim& dense_dims,
const auto cuda_alloc =
std::make_shared<paddle::experimental::DefaultAllocator>(
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()
Expand Down Expand Up @@ -889,7 +889,7 @@ void TestSparseCsrToDense(const DDim& dense_dims,
const auto cuda_alloc =
std::make_shared<paddle::experimental::DefaultAllocator>(
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()
Expand Down