Skip to content

Commit addc538

Browse files
ForFisheswentaoyu
authored andcommitted
part-4 cherry from: [BugFix]Fix bug in paddle.device.cdua.synchronize() (PaddlePaddle#56451)
* fix bug in synchronize * fix bug in synchronize
1 parent c273534 commit addc538

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

python/paddle/device/cuda/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,21 @@ def synchronize(device=None):
107107
>>> paddle.device.cuda.synchronize(paddle.CUDAPlace(0))
108108
109109
'''
110-
111-
device_id = -1
112-
113110
if device is not None:
114111
if isinstance(device, int):
115112
device_id = device
116113
elif isinstance(device, core.CUDAPlace):
117114
device_id = device.get_device_id()
118115
else:
119116
raise ValueError("device type must be int or paddle.CUDAPlace")
120-
117+
else:
118+
place = paddle.framework._current_expected_place()
119+
if paddle.is_compiled_with_cuda() and isinstance(
120+
place, paddle.CUDAPlace
121+
):
122+
device_id = place.get_device_id()
123+
else:
124+
device_id = -1
121125
return core._device_synchronize(device_id)
122126

123127

0 commit comments

Comments
 (0)