Skip to content

Commit

Permalink
set device_id in eager_gen
Browse files Browse the repository at this point in the history
  • Loading branch information
pangyoki committed Apr 6, 2022
1 parent a0835a1 commit 3537f12
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,16 @@ class {} : public egr::GradNodeBase {{
// Get Input AutoGradMeta
{}
// Set Device Id
auto place = egr::Controller::Instance().GetExpectedPlace();
if (paddle::platform::is_gpu_place(place)) {{
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
phi::backends::gpu::SetDeviceId(place.device);
#else
PADDLE_THROW(paddle::platform::errors::PreconditionNotMet(
"PaddlePaddle should compile with GPU if use CUDAPlace."));
#endif
}}
// Forward API Call
{}
// Get Outputs
Expand Down Expand Up @@ -285,6 +295,7 @@ class {} : public egr::GradNodeBase {{
#include "paddle/fluid/platform/profiler/event_tracing.h"
#include "paddle/fluid/eager/amp_utils.h"
#include "paddle/fluid/eager/eager_amp_auto_cast.h"
#include "paddle/phi/backends/gpu/gpu_info.h"
{}
{}
Expand Down
10 changes: 0 additions & 10 deletions paddle/fluid/imperative/tracer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -385,16 +385,6 @@ void Tracer::TraceOp(const std::string& type, const NameTensorMap& ins,

void Tracer::SetExpectedPlace(platform::Place place) {
expected_place_ = place;
if (platform::is_gpu_place(place)) {
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
if (place.device) {
platform::SetDeviceId(place.device);
}
#else
PADDLE_THROW(platform::errors::PreconditionNotMet(
"PaddlePaddle should compile with GPU if use CUDAPlace."));
#endif
}
}

bool Tracer::ComputeRequiredGrad(const NameVarBaseMap& ins,
Expand Down

1 comment on commit 3537f12

@paddle-bot-old
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congratulation! Your pull request passed all required CI. You could ask reviewer(s) to approve and merge. 🎉

Please sign in to comment.