17
from .log import logger
20
def get_device_and_mapping():
22
Return device type and name-bool mapping implifying which type is supported.
24
suppoted_device_map = {
25
"gpu": paddle.is_compiled_with_cuda(),
26
"xpu": paddle.is_compiled_with_xpu(),
27
"rocm": paddle.is_compiled_with_rocm(),
28
"npu": paddle.is_compiled_with_custom_device("npu"),
31
for d, v in suppoted_device_map.items():
33
return d, suppoted_device_map
38
Return the device with which the paddle is compiled, including 'gpu'(for rocm and gpu), 'npu', 'xpu', 'cpu'.
40
d, _ = get_device_and_mapping()
46
Synchronize device, return True if succeeded, otherwise return False
48
device = paddle.get_device().split(":")[0]
49
if device in ["gpu", "rocm"]:
50
paddle.device.cuda.synchronize()
53
paddle.device.xpu.synchronize()
55
elif device in paddle.device.get_all_custom_device_type():
56
paddle.device.synchronize()
59
logger.warning("The synchronization is only supported on cuda and xpu now.")