Device¶
-
class Device¶
Compute backend a Tensor’s storage lives on.
One instance per physical device (CPU, or a specific CUDA or HIP GPU); obtained through
cpu_device(),cuda_device()orhip_device()rather than constructed directly. Every device-dependent tensor operation (allocation, copy, the elementary kernels used to train the network globals) is dispatched through this interface.Public Functions
-
virtual ~Device() = default¶
-
virtual std::pair<void*, Tensor> allocate(std::size_t size, AllocHint hint) const = 0¶
Allocate
sizebytes forhint; the returned Tensor, if not empty, is the pool allocation this storage was carved out of.
-
inline virtual void free_on_stream(void *ptr, void *stream) const¶
Free a pointer returned by allocate after the work queued on
stream.
-
inline virtual void *default_free_stream() const¶
Stream to free stream-ordered storage on if it has no known stream.
-
inline virtual void order_streams(void *from, void *to) const¶
Make work queued on
tofrom now on wait for the work queued onfrom.
-
virtual void memcpy(void *to, void *from, std::size_t size) const = 0¶
Copy
sizebytes fromfromtoto, both on this device.
-
virtual void tensor_copy(const Tensor &source, Tensor &target) const = 0¶
Copy the elements of
sourceintotarget.
-
virtual void tensor_add(const Tensor &source, Tensor &target) const = 0¶
Add
sourceintotargetelement-wise.
-
virtual void tensor_cpu(const Tensor &source, Tensor &target) const = 0¶
Copy
sourceintotarget, which lives on the CPU.
-
virtual const Device *device_ptr() const = 0¶
This device, as the pointer type used elsewhere in the API.
-
inline virtual void sync_barrier() const¶
Block until every operation queued on this device has completed.
-
virtual DeviceType device_type() const = 0¶
The kind of device this is.
-
inline virtual int device_index() const¶
Index of the device among those of its type, 0 for the CPU.
-
virtual void activate() const = 0¶
Make this device current for the calling thread.
Public Static Attributes
-
static constexpr bool stream_ordered_alloc¶
-
virtual ~Device() = default¶