Tensor and Arrow Headers¶
The SDK has two interchange headers: caliper/tensor.h for tensors and caliper/arrow_c.h for tables.
Tensor Header¶
CaliperTensor is a type, not a service. It is a plain struct that describes a block of memory with a dtype, a shape, strides in elements, a device, and an optional stream. The layout follows DLPack, so a torch, numpy, or mlx tensor is a cast away and not a copy. The layout is frozen, and thus GPU-resident tensors cross the ABI with no CPU staging.
An applet passes a CaliperTensor into a service. No service returns one. These services take it:
caliper.metrics.v1:image()accepts a CPU-resident, contiguous, HWCu8tensor.caliper.tensor_bridge.v1and its revisionsv1_1andv1_2: they turn a tensor on any supported device into a texture.
Types¶
CaliperDType¶
The element type of a tensor.
| Constant | Value | Description |
|---|---|---|
CALIPER_DT_F32 |
0 |
A 32-bit float. |
CALIPER_DT_F16 |
1 |
A 16-bit half float. |
CALIPER_DT_BF16 |
2 |
A 16-bit brain float. |
CALIPER_DT_I64 |
3 |
A 64-bit signed integer. |
CALIPER_DT_I32 |
4 |
A 32-bit signed integer. |
CALIPER_DT_U8 |
5 |
An 8-bit unsigned integer. |
CaliperTensor¶
A block of memory with a dtype, a shape, strides, a device and an optional stream.
The layout follows DLPack, so a torch, numpy or mlx tensor is a cast away. An applet passes a tensor into a service. The struct does not own the memory, and no service returns one.
| Field | Type | Description |
|---|---|---|
struct_size |
uint32_t |
The value of sizeof(CaliperTensor) as the caller built it. |
data |
void* |
The pointer to the first element, in device memory or in host memory. |
dtype |
CaliperDType |
The element type. |
ndim |
int32_t |
The number of dimensions, at most 8. |
shape |
int64_t[8] |
The size of each dimension in elements. Only the first ndim values are used. |
strides |
int64_t[8] |
The distance between two neighbors in each dimension, in elements and not in bytes. |
device |
CaliperDeviceKind |
The memory domain that holds the data. |
device_index |
int32_t |
The index of the device within its kind. |
stream |
void* |
The cudaStream_t or MTLCommandQueue* that orders access to the data, or NULL for none. |
Arrow Header¶
caliper.data.v1 returns tabular results as structures of the Arrow C Data Interface. The interface is a specification and not a library, so no Arrow library type crosses the ABI.
Overview¶
The Arrow C Data Interface is a small, stable ABI that passes columnar data between components with no shared library. It has three plain C structs:
ArrowSchema: the column types.ArrowArray: one batch of column buffers.ArrowArrayStream: an iterator that yields batches.
Each struct carries a release callback. The producer fills a struct and sets release. The consumer drains the struct and must call release(self) exactly once, which sets the callback to NULL. A struct whose release is NULL is empty. A stream signals its end the same way.
Tabular Boundary¶
The Caliper ABI is a frozen C ABI. No third-party type can appear in a service header, because the applet and the host would then need to agree on the version and layout of that library. Thus no DuckDB or Arrow C++ type crosses the boundary. Both sides compile their own copy of the same frozen structs and interoperate by layout alone. DuckDB exports its results as these structs, so a SQL result reaches an applet through data.v1 with no conversion.
Vendored Header¶
The definitions in caliper/arrow_c.h are a verbatim copy of the specification. The doc comments are Caliper's. The header is the only header that data_v1.h can include, because the frozen data.v1 struct references ArrowArrayStream*.
The include guards are the ARROW_C_DATA_INTERFACE and ARROW_C_STREAM_INTERFACE guards of the specification, and not #pragma once. Thus another vendored copy of these definitions, for example inside DuckDB or torch, can share a translation unit with this header. The first copy that the compiler includes wins, and the other copies compile to nothing.
Types¶
Most applets never use these structs directly. The drain_numeric helper of the caliper::Data sugar walks the stream and releases it. Use the raw interface only for non-numeric columns or for control of the stream.
ArrowSchema¶
The type description of one array, which can have child types.
The producer fills the struct and sets release. The consumer calls release exactly once when it no longer needs the struct. A struct whose release is NULL is released, and the consumer must not use it.
| Field | Type | Description |
|---|---|---|
format |
const char* |
The format string of the type, as a null-terminated UTF-8 string. |
name |
const char* |
The name of the field, as a null-terminated UTF-8 string, or NULL if the type has no name. |
metadata |
const char* |
The binary-encoded key-value metadata of the field, or NULL if there is none. |
flags |
int64_t |
The bit flags of the field, a combination of the ARROW_FLAG_* values. |
n_children |
int64_t |
The number of child types in children. |
children |
struct ArrowSchema** |
The array of n_children pointers to the child types, or NULL if n_children is 0. |
dictionary |
struct ArrowSchema* |
The type of the dictionary values for a dictionary-encoded type, or NULL otherwise. |
release |
void (*)(struct ArrowSchema*) |
Release the resources of the struct, including the children and the dictionary, and set release to NULL. The consumer calls it exactly once. |
private_data |
void* |
Opaque data that belongs to the producer. The consumer must not read or change it. |
ArrowArray¶
The data of one array, which can have child arrays.
The producer fills the struct and sets release. The consumer calls release exactly once when it no longer needs the struct. A struct whose release is NULL is released, and the consumer must not use it.
| Field | Type | Description |
|---|---|---|
length |
int64_t |
The number of logical elements in the array. |
null_count |
int64_t |
The number of null elements, or -1 if the producer did not compute the count. |
offset |
int64_t |
The logical offset of the first element into the buffers, in elements. It is 0 for most arrays. |
n_buffers |
int64_t |
The number of physical buffers in buffers. It depends on the type of the array. |
n_children |
int64_t |
The number of child arrays in children. |
buffers |
const void** |
The array of n_buffers pointers to the buffers. A pointer can be NULL when the spec allows it. |
children |
struct ArrowArray** |
The array of n_children pointers to the child arrays, or NULL if n_children is 0. |
dictionary |
struct ArrowArray* |
The dictionary values for a dictionary-encoded array, or NULL otherwise. |
release |
void (*)(struct ArrowArray*) |
Release the buffers, the children and the dictionary, and set release to NULL. The consumer calls it exactly once. |
private_data |
void* |
Opaque data that belongs to the producer. The consumer must not read or change it. |
ArrowArrayStream¶
A stream of arrays that all have the same type, which the consumer pulls one array at a time.
The consumer calls release exactly once when it no longer needs the stream. The arrays that get_next returns are independent of the stream, and the consumer must release each one.
| Field | Type | Description |
|---|---|---|
get_schema |
int (*)(struct ArrowArrayStream*, struct ArrowSchema* out) |
Write the type of the stream to out, which is the same for all arrays in the stream. Return 0 on success, or an errno-compatible error code otherwise. |
get_next |
int (*)(struct ArrowArrayStream*, struct ArrowArray* out) |
Write the next array to out. If the call succeeds and the array in out is released, the stream has ended. Return 0 on success, or an errno-compatible error code otherwise. |
get_last_error |
const char* (*)(struct ArrowArrayStream*) |
Return a null-terminated description of the last error, or NULL if no description is available. Call it only after a stream operation failed with a return code that is not 0. |
release |
void (*)(struct ArrowArrayStream*) |
Release the resources of the stream itself and set release to NULL. The arrays that get_next returned are not affected, and the consumer must release each one. |
private_data |
void* |
Opaque data that belongs to the producer. The consumer must not read or change it. |
Flags¶
| Name | Value | Description |
|---|---|---|
ARROW_FLAG_DICTIONARY_ORDERED |
1 |
Bit flag of ArrowSchema.flags. The values of the dictionary are ordered. |
ARROW_FLAG_NULLABLE |
2 |
Bit flag of ArrowSchema.flags. The field can hold null values. |
ARROW_FLAG_MAP_KEYS_SORTED |
4 |
Bit flag of ArrowSchema.flags. The keys of a map type are sorted. |