def is_device_memory(obj):
 return getattr(obj, '__cuda_memory__', False)

def is_device_memory ( obj ) : return getattr ( obj , '__cuda_memory__' , False )
all cuda memory object is recognized as an instance with the attribute "__cuda_memory__" defined and its value evaluated to true .