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
10 changes: 10 additions & 0 deletions paddle/phi/common/place.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ limitations under the License. */
#include "glog/logging.h"
#include "paddle/common/exception.h"
#include "paddle/phi/backends/gpu/gpu_info.h"
#include "paddle/phi/backends/xpu/xpu_info.h"

namespace phi {

Expand Down Expand Up @@ -274,4 +275,13 @@ GPUPlace DefaultGPUPlace() {
#endif
}

phi::XPUPlace DefaultXPUPlace() {
return phi::XPUPlace(
#ifdef PADDLE_WITH_XPU
phi::backends::xpu::GetXPUCurrentDeviceId());
#else
0);
#endif
}

} // namespace paddle
2 changes: 2 additions & 0 deletions paddle/phi/common/place.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,6 @@ PADDLE_API bool operator==(PlaceType place_type, const Place& place);

PADDLE_API GPUPlace DefaultGPUPlace();

PADDLE_API phi::XPUPlace DefaultXPUPlace();

} // namespace paddle
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ Place GetDefaultPlace() {
if (phi::backends::gpu::GetGPUDeviceCount() >= 0) {
return paddle::DefaultGPUPlace();
}
#elif defined(PADDLE_WITH_XPU)
if (phi::backends::xpu::GetXPUDeviceCount() >= 0) {
return paddle::DefaultXPUPlace();
}
#endif
return paddle::CPUPlace();
}
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/nn/clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ def async_add_n(var_list):
global_norm_var = async_add_n(global_norm_var)
global_norm_var = paddle.sqrt(global_norm_var)
max_global_norm = paddle.full(
shape=[], dtype=sum_dtype, fill_value=self.clip_norm
shape=[1], dtype=sum_dtype, fill_value=self.clip_norm
)

need_clip = False
Expand Down
Loading