def auto_device(obj, context, stream=None, copy=True): """ Create a DeviceArray like obj and optionally copy data from host to device. If obj already represents device memory, it is returned and no copy is made. """ if _driver.is_device_memory(obj): # it's already on the dGPU return obj, False else: # needs to be copied to the dGPU sentry_contiguous(obj) devobj = from_array_like(obj) if copy: devobj.copy_to_device(obj, stream=stream, context=context) return devobj, True