Device#
- class ivy.data_classes.container.device._ContainerWithDevice(dict_in=None, queues=None, queue_load_sizes=None, container_combine_method='list_join', queue_timeout=None, print_limit=10, key_length_limit=None, print_indent=4, print_line_spacing=0, ivyh=None, default_key_color='green', keyword_color_dict=None, rebuild_child_containers=False, types_to_iteratively_nest=None, alphabetical_keys=True, dynamic_backend=None, build_callable=False, **kwargs)[source]#
Bases:
ContainerBase
- _abc_impl = <_abc._abc_data object>#
- static _static_dev(x, /, *, as_native=False)[source]#
ivy.Container static method variant of ivy.dev. This method simply wraps the function, and so the docstring for ivy.dev also applies to this method with minimal changes.
- Return type:
Container
Examples
>>> x = ivy.Container(a=ivy.array([[2, 3], [3, 5]]), ... b=ivy.native_array([1, 2, 4, 5, 7])) >>> as_native = ivy.Container(a=True, b=False) >>> y = ivy.Container.static_dev(x, as_native=as_native) >>> print(y) { a: device(type=cpu), b: cpu }
- static _static_to_device(x, device, /, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, stream=None, out=None)[source]#
ivy.Container instance method variant of ivy.to_device. This method simply wraps the function, and so the docstring for ivy.to_device also applies to this method with minimal changes.
- Parameters:
x (
Union
[Container
,Array
,NativeArray
]) – input array to be moved to the desired devicedevice (
Union
[Device
,NativeDevice
,Container
]) – device to move the input array x tokey_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.stream (
Optional
[Union
[int
,Any
,Container
]], default:None
) – stream object to use during copy. In addition to the types supported in array.__dlpack__(), implementations may choose to support any library-specific stream object with the caveat that any code using such an object would not be portable.out (
Optional
[Container
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – input array x placed on the desired device
Examples
>>> x = ivy.Container(a=ivy.array([[2, 3, 1], [3, 5, 3]]), ... b=ivy.native_array([[1, 2], [4, 5]])) >>> y = ivy.Container.static_to_device(x, 'cpu') >>> print(y.a.device, y.b.device) cpu cpu
- dev(as_native=False)[source]#
ivy.Container instance method variant of ivy.dev. This method simply wraps the function, and so the docstring for ivy.dev also applies to this method with minimal changes.
- Parameters:
self (
Container
) – contaioner of arrays for which to get the device handle.as_native (
Union
[bool
,Container
], default:False
) – Whether or not to return the dev in native format. Default isFalse
.
- Return type:
Container
Examples
>>> x = ivy.Container(a=ivy.array([[2, 3, 1], [3, 5, 3]]), ... b=ivy.native_array([[1, 2], [4, 5]])) >>> as_native = ivy.Container(a=False, b=True) >>> y = x.dev(as_native=as_native) >>> print(y) { a:cpu, b:cpu }
- to_device(device, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, stream=None, out=None)[source]#
ivy.Container instance method variant of ivy.to_device. This method simply wraps the function, and so the docstring for ivy.to_device also applies to this method with minimal changes.
- Parameters:
x – input array to be moved to the desired device
device (
Union
[Device
,NativeDevice
,Container
]) – device to move the input array x tokey_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.stream (
Optional
[Union
[int
,Any
,Container
]], default:None
) – stream object to use during copy. In addition to the types supported in array.__dlpack__(), implementations may choose to support any library-specific stream object with the caveat that any code using such an object would not be portable.out (
Optional
[Container
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – input array x placed on the desired device
Examples
>>> x = ivy.Container(a=ivy.array([[2, 3, 1], [3, 5, 3]]), ... b=ivy.native_array([[1, 2], [4, 5]])) >>> y = x.to_device('cpu') >>> print(y.a.device, y.b.device) cpu cpu
This should have hopefully given you an overview of the device submodule, if you have any questions, please feel free to reach out on our discord!