NPUData¶
Represents a model input or output tensor that can reside either on the host (CPU) or on the NPU.
An NPUData object is obtained from a model via Model::acquireInputNPUData or Model::acquireOutputNPUData. It owns its host buffer, holds NPU memory that belongs to the Accelerator while the data is on the NPU, and lets the user move the data between CPU and NPU.
An NPU-resident NPUData may be passed to any model that expects a tensor of the same shape and element type on the same accelerator, so several models can share one NPU-resident tensor without copying it back to the host in between.
Warning
This API is in beta: it may still contain bugs, and its behavior may change in a future release.
Warning
NPUData objects are not fully thread-safe; the client must serialize access to an NPUData from different threads. In particular, launch() and cpu() change where the data resides and must not run concurrently with each other.
Note
These APIs are intended for advanced use rather than typical usage.
Note
An NPUData is not owned by the Model it came from and may safely outlive it: destroying the model leaves the data intact and usable. NPU memory instead belongs to the Accelerator the data resides on. If that accelerator is destroyed while the data is still on the NPU, the NPU memory is reclaimed and the NPUData becomes invalid: cpu(), launch(), copyFrom() and data() fail, and devNo() returns -1. A CPU-resident NPUData holds no accelerator resource and is unaffected by the accelerator's destruction.
Member functions¶
| Member | Description |
|---|---|
NPUData ×2 |
|
operator= ×2 |
|
launch |
Uploads the data to the NPU memory associated with the given accelerator. |
cpu |
Brings the data back to host (CPU) memory. |
copyFrom |
Copies the data from another NPUData. |
data |
Returns a typed pointer to the host (CPU) data. |
shape |
Returns the shape of the data. |
dataType |
Returns the element data type of the data. |
devNo |
Returns the device number of the accelerator the data resides on. |
deviceName |
Returns the hardware name (device type) of the accelerator the data resides on. |
NPUData¶
operator=¶
launch¶
Uploads the data to the NPU memory associated with the given accelerator.
Warning
Not thread-safe: see the class-level note.
Parameters
acc[in] — The accelerator on which to place the data.
Returns
A status code indicating success or the specific error condition.
cpu¶
Brings the data back to host (CPU) memory.
Warning
Not thread-safe: see the class-level note.
Returns
A status code indicating success or the specific error condition.
copyFrom¶
Copies the data from another NPUData.
Both tensors must have the same shape and element type; the source may reside on either side (a CPU-to-NPU or NPU-to-CPU copy is staged through the host).
Parameters
src[in] — The sourceNPUDatato copy from.
Returns
A status code indicating success or the specific error condition.
data¶
Returns a typed pointer to the host (CPU) data.
Note
The data must reside on the CPU (see NPUData::cpu). Otherwise, sc is set to an error and nullptr is returned.
Template parameters
T— The element type to reinterpret the data as.
Parameters
sc[out] — A reference to a status code that will be updated to indicate success or the specific error condition.
Returns
A pointer to the host data, or nullptr on error.
shape¶
Returns the shape of the data.
Returns
A reference to the shape vector.
dataType¶
Returns the element data type of the data.
Returns
The DataType of the elements.
devNo¶
Returns the device number of the accelerator the data resides on.
Returns
The device number of the connected accelerator when the data is on the NPU, or -1 when the data is on the host (CPU) or has been invalidated (see the class-level note on accelerator destruction).
deviceName¶
Returns the hardware name (device type) of the accelerator the data resides on.
Device numbers are assigned per hardware type (e.g. an "aries-rb" and a "regulus-ra" can both be device #0), so devNo() alone does not identify a physical device; pair it with this name to distinguish devices.
Returns
The hardware name (e.g. "aries-rb") when the data is on the NPU, or an empty string when the data is on the host (CPU) or has been invalidated (see the class-level note on accelerator destruction).