![]() |
Q.ANT Native Computing Toolkit 2.4.0
All you need for photonic computing
|
#include <stddef.h>#include <stdint.h>#include <dlpack/dlpack.h>

Go to the source code of this file.
Typedefs | |
| typedef struct QantMemoryHandle | QantMemoryHandle |
| Opaque handle to a block of device memory sized to hold a matrix. | |
| typedef enum QantDataRole | QantDataRole |
| Role of a block of device memory. | |
Enumerations | |
| enum | QantDataRole { Weights , Features } |
| Role of a block of device memory. More... | |
Functions | |
| int | init_npu (const uint32_t id) |
| Initialises the Native Processing Unit. | |
| int | release_npu (const uint32_t id) |
| Releases an NPU and frees associated memory. | |
| QantMemoryHandle * | npu_allocate (const uint32_t npu_id, const size_t rows, const size_t cols, const QantDataRole data_role) |
| Allocates a block of device memory sized to hold a (rows, cols) matrix. | |
| int | npu_free (QantMemoryHandle *handle) |
| Frees a previously allocated block of device memory. | |
| QantMemoryHandle * | npu_upload (const uint32_t npu_id, DLManagedTensorVersioned const *data, const QantDataRole data_role) |
| Allocates a block of device memory and uploads a matrix to it. | |
| int | npu_upload_into (QantMemoryHandle const *handle, DLManagedTensorVersioned const *data) |
| Uploads a matrix to a previously allocated block of device memory. | |
| DLManagedTensorVersioned * | npu_download (QantMemoryHandle const *handle) |
| Downloads the matrix currently stored in a block of device memory. | |
| typedef enum QantDataRole QantDataRole |
Role of a block of device memory.
| typedef struct QantMemoryHandle QantMemoryHandle |
Opaque handle to a block of device memory sized to hold a matrix.
Instances are created by npu_allocate() and must be released exactly once with npu_free(). Using a handle after it has been freed is undefined behavior.
| enum QantDataRole |
| int init_npu | ( | const uint32_t | id | ) |
Initialises the Native Processing Unit.
Optional, not necessary for computation.
NPUs are automatically initialised on the first operation that uses the specific device. Within one process, concurrent operation calls on a single NPU are possible, this creates a first-come first-serve queue. A process has an exclusive lock on each NPU it initialised, NPUs can be released explicitly to free devices for use by a different process, see release_npu.
| id | The identifier of the NPU to be initialised. |
| QantMemoryHandle * npu_allocate | ( | const uint32_t | npu_id, |
| const size_t | rows, | ||
| const size_t | cols, | ||
| const QantDataRole | data_role ) |
Allocates a block of device memory sized to hold a (rows, cols) matrix.
| npu_id | The identifier of the NPU on which the memory is allocated. |
| rows | Number of rows of the matrix the memory is sized for. |
| cols | Number of columns of the matrix the memory is sized for. |
| data_role | Role of the memory block (Weights or Features). |
| DLManagedTensorVersioned * npu_download | ( | QantMemoryHandle const * | handle | ) |
Downloads the matrix currently stored in a block of device memory.
| handle | The handle to download from, as returned by npu_allocate(). |
| int npu_free | ( | QantMemoryHandle * | handle | ) |
Frees a previously allocated block of device memory.
| handle | The handle to free, as returned by npu_allocate(). Must not be used again after this call. |
| QantMemoryHandle * npu_upload | ( | const uint32_t | npu_id, |
| DLManagedTensorVersioned const * | data, | ||
| const QantDataRole | data_role ) |
Allocates a block of device memory and uploads a matrix to it.
| npu_id | The identifier of the NPU on which the memory is allocated. |
| data | A 2D tensor with shape (rows, cols) and data type bfloat16. |
| data_role | Role of the memory block (Weights or Features). |
| int npu_upload_into | ( | QantMemoryHandle const * | handle, |
| DLManagedTensorVersioned const * | data ) |
Uploads a matrix to a previously allocated block of device memory.
| handle | The handle to upload to, as returned by npu_allocate() or npu_upload(). |
| data | A 2D tensor with shape (rows, cols) matching the handle. Must be data type bfloat16. |
| int release_npu | ( | const uint32_t | id | ) |
Releases an NPU and frees associated memory.
Only relevant if multiple processes want to access the same device.
| id | The identifier of the NPU to be released. |