def check_all_same_device(glist, name):
    """Check all the graphs have the same device."""
    if len(glist) == 0:
        return
    device = glist[0].device
    for i, g in enumerate(glist):
        if g.device != device:
            raise DGLError(
                "Expect {}[{}] to be on device {}, but got {}.".format(
                    name, i, device, g.device
                )
            )
Check all the graphs have the same device.
python/dgl/utils/checks.py