ncarray
ncarray
Section titled “ncarray”Classes
Section titled “Classes”| Name | Description |
|---|---|
ArrayImpl |
The ArrayImpl provides the mean entry point for all array types. It is a templated class inheriting from Layout and Storage classes, allowing it to be customized to different kinds of array setups. E.g. suboffsets and NCArray style classes are both accessed via the ArrayImpl. |
index_error |
|
Stencil |
A Stencil for defining expressions over an array with determined offsets. |
type_error |
|
AllTraits |
Traits to find minima along axes. |
AnyTraits |
Traits to find minima along axes. |
ArgmaxTraits |
Traits to find the indices of maxima along axes. |
ArgminTraits |
Traits to find the indices of minima along axes. |
ArrayElementProxy |
The element proxy can be returned by arrays during indexing to provide reference based access to the underlying data. |
AxisDescr |
A description of an axis of an array. This struct can be used for creation of new views. |
BaseOpTraits |
Numeric traits for specifying types during arithmetic as well as providing operations for types that don’t have them, or overriding their default behaviour. |
concat |
A struct for concatenating type_lists together. |
concat< List > |
|
concat< type_list< Ts... >, type_list< Us... >, Rest... > |
|
DevDeleter |
|
DevOwnerPolicy |
|
DevRefPolicy |
|
DevTag |
|
DevViewPolicy |
|
Double2 |
A 2-double (double precision) vector data type. |
Double3 |
A 3-double (double precision) vector data type. |
Double4 |
A 4-double (double precision) vector data type. |
dtype_traits |
A small struct that maps a type to the DType enumerator via the value member. |
DynamicExprMVNode |
|
Ellipsis |
An empty struct indicating skipped axes when indexing an array. |
ExpressionTag |
|
ExprMVNode |
A multi-view array expression builder. |
ExprOpInterface |
|
FixedMetadata |
For simplifying CPU/GPU compatibility, STL containers are replaced with a fixed struct for expressing metadata surrounding arrays. E.g. shape and strides information. Currently, ncarray supports up to 10 dimensions in an array. |
Float2 |
A 2-float (single precision) vector data type. |
Float3 |
A 3-float (single precision) vector data type. |
Float4 |
A 4-float (single precision) vector data type. |
HostDeleter |
|
HostEngine |
The HostEngine is ultimately responsible for dispatching all operations involving arrays on the host/CPU. This includes binary operations, reductions, unary operations, copies, assignments, fills and so on. |
HostTag |
|
IndexItem |
A generic indexing argument with a tag indicating the type to be used. |
is_exprmv_node |
|
is_exprmv_node< ExprMVNode< MemTag > > |
|
is_in_list |
Struct for testing presence of a type in a type_list. |
is_in_list< T, type_list< Ts... > > |
|
is_layout_policy |
Type-trait style struct for the IsLayoutPolicy concept default falsey specialization. |
is_layout_policy< LayoutPolicy< D > > |
Type-trait style struct for the IsLayoutPolicy concept true specialization. |
is_ncoffsets_policy |
Type-trait style struct for whether NCOffsetsPolicy default false specialization. |
is_ncoffsets_policy< NCOffsetsPolicy > |
Type-trait style struct for whether NCOffsetsPolicy true specialization. |
is_soarray_policy |
Type-trait style struct for whether SOArrayPolicy default false specialization. |
is_soarray_policy< SOArrayPolicy > |
Type-trait style struct for whether SOArrayPolicy true specialization. |
KeyValPair |
A small struct for holding a key and value. |
LayoutPolicy |
The LayoutPolicy dictates the overall organization of an array object. E.g. if it has offsets or suboffsets. |
list_dispatcher |
A dispatch engine for matching a DType to the underlying type and running a function. |
list_dispatcher< type_list< T, Ts... > > |
|
list_dispatcher< type_list<> > |
|
MaxTraits |
Traits to find maxima along axes. |
MeanTraits |
|
MemTag |
|
MinTraits |
Traits to find minima along axes. |
NCOffsetsPolicy |
The NCOffsetsPolicy provides an additional offsets attribute and allows for a single pointer axis. |
op_traits |
|
op_traits< bool > |
|
op_traits< complex< T > > |
|
op_traits< Double2 > |
|
op_traits< Double3 > |
|
op_traits< Double4 > |
|
op_traits< Float2 > |
|
op_traits< Float3 > |
|
op_traits< Float4 > |
|
op_traits< int16_t > |
|
op_traits< int8_t > |
|
op_traits< uint16_t > |
|
op_traits< uint8_t > |
|
OwnerPolicy |
The OwnerPolicy dictates an array that manages its own buffer for the memory that backs the array. |
OwnerTag |
|
Reducer |
A wrapping class for reduction traits. |
ReductionParams |
A struct to define mapping requirements when performing axis-aware reductions. |
RefPolicy |
The RefPolicy dictates arrays which hold pointers to the individual components of the array. |
RefTag |
|
Slice |
A struct representing a slice for indexing by a step between a start and stop index. |
SOArrayPolicy |
The SOArrayPolicy implements PEP3118 compliance with the addition of a suboffsets field. |
StaticCoords |
A small struct with compile-time constant size for indexing arrays. |
StaticExprMVNode |
|
StdTraits |
Traits to find the standard deviation along axes. |
StoragePolicy |
The StoragePolicy specifies the storage class for the array in question. E.g., a view type array holds no memory, while an owning type does. |
StoragePolicyTraits |
|
StoragePolicyTraits< DevTag > |
|
StoragePolicyTraits< HostTag > |
|
SumTraits |
Traits for a summation along axes. |
type_list |
Basic type list. |
VarAccumulator |
An accumulator used for the calculation of variance and standard deviation. |
VarTraits |
Traits to find the variance along axes. |
ViewPolicy |
The ViewPolicy dictates arrays that have only a view of the data. |
ViewTag |
|
wrap_list |
A helper struct to wrap a templated class. |
wrap_list< Wrapper, type_list< Ts... > > |
Enumerations
Section titled “Enumerations”| Name | Description |
|---|---|
DType |
The main identifier for the ncarray type system. The DType determines array element type. |
IndexType |
A tag identifier for the type of indexing argument when constructing lists of args. |
OpCode |
OpCodes indicate types of operations or expressions. |
enum DTypeThe main identifier for the ncarray type system. The DType determines array element type.
| Value | Description |
|---|---|
bool_ |
Boolean type. |
char_ |
char type (signed 8-bit) |
uint8 |
8-bit unsigned integer |
uint16 |
16-bit unsigned integer |
uint32 |
32-bit unsigned integer |
uint64 |
64-bit unsigned integer |
int8 |
8-bit signed integer |
int16 |
16-bit signed integer |
int32 |
32-bit signed integer |
int64 |
64-bit signed integer |
float32 |
single precision float |
float64 |
double precision float |
float128 |
equivalent to long double |
complex64 |
complex |
complex128 |
complex |
complex256 |
complex |
vfloat2 |
2-float vector type (Float2) |
vfloat3 |
3-float vector type (Float3) |
vfloat4 |
4-float vector type (Float4) |
vdouble2 |
2-double vector type (Double2) |
vdouble3 |
3-double vector tyep (Double3) |
vdouble4 |
4-double vector type (Double4) |
IndexType
Section titled “IndexType”enum IndexTypeA tag identifier for the type of indexing argument when constructing lists of args.
| Value | Description |
|---|---|
Integer |
|
Slice |
|
Ellipsis |
OpCode
Section titled “OpCode”enum OpCodeOpCodes indicate types of operations or expressions.
When interfacing with Python these are used for the virtual machine. In normal C++ usage, they are used by the various BinaryExpr/UnaryExpr and so on.
All supported operations (add, subtract, etc.) are included here, in addition to the necessary codes to indicate loading/retrieval of the operands (arrays, or constant scalars)
| Value | Description |
|---|---|
NOOP |
Null op. |
IDX |
Index generator (Like APL) |
LOAD_NCARR |
Load an NCArray (VM only) |
LOAD_SOARR |
Load an SOArray (VM only) |
LOAD_CONST |
Load a constant (VM only) |
NEG |
Negative. |
INC |
Increment. |
DEC |
Decrement. |
SZOF |
Size of. |
ADDR |
Address of. |
INDR |
Indirection/dereference. |
CAST |
Cast. |
LNOT |
Logical not. |
BNOT |
Bitwise not. |
ADD |
Addition. |
SUB |
Subtraction. |
MUL |
Multiplication. |
DIV |
True division. |
MOD |
Modulo. |
FDIV |
Floor (integer) division. |
EQ |
Equal to. |
NE |
Not equal. |
LT |
Less than. |
LE |
Less than or equal. |
GT |
Greater than. |
GE |
Greater than or equal. |
LAND |
Logical and. |
LOR |
Logical or. |
BAND |
Bitwise and (&) |
BOR |
Bitwise or ( |
XOR |
Bitwise XOR (^) |
LSHFT |
Left shift (<<) |
RSHFT |
Right shift (>>) |
Typedefs
Section titled “Typedefs”| Return | Name | Description |
|---|---|---|
ArrayImpl< NCOffsetsPolicy, typename StoragePolicyTraits< MemType >::View > |
NCViewFor |
|
ArrayImpl< NCOffsetsPolicy, typename StoragePolicyTraits< MemType >::Ref > |
NCRefFor |
|
ArrayImpl< NCOffsetsPolicy, typename StoragePolicyTraits< MemType >::Owner > |
NCOwnerFor |
|
ArrayImpl< SOArrayPolicy, typename StoragePolicyTraits< MemType >::View > |
SOViewFor |
|
ArrayImpl< SOArrayPolicy, typename StoragePolicyTraits< MemType >::Ref > |
SORefFor |
|
ArrayImpl< SOArrayPolicy, typename StoragePolicyTraits< MemType >::Owner > |
SOOwnerFor |
|
std::variant< bool, char, uint8_t, uint16_t, uint32_t, uint64_t, int8_t, int16_t, int32_t, int64_t, float, double, long double, complex< float >, complex< double >, complex< long double >, Float2, Float3, Float4, Double2, Double3, Double4 > |
Scalar |
The set of scalar types used by ncarray - one for each DType. |
type_list< bool, char, uint8_t, uint16_t, uint32_t, uint64_t, int8_t, int16_t, int32_t, int64_t, float, double, long double, complex< float >, complex< double >, complex< long double >, Float2, Float3, Float4, Double2, Double3, Double4 > |
base_types |
All supported base datatypes in ncarray. |
typename concat< Lists... >::type |
concat_t |
The full type of a set of type_lists concatenated with concat. |
typename wrap_list< VarAccumulator, base_types >::type |
accumulator_types |
|
KeyValPair< ssize_t, T > |
IndexedKVP |
The KeyValPair type used for reductions in ncarray. |
typename wrap_list< IndexedKVP, base_types >::type |
keyval_types |
|
type_list< long, unsigned long, long long, unsigned long long > |
device_int_compat_types |
Provide supporting types for the ArrayElementProxy restricted conversion operators. |
concat_t< base_types, accumulator_types, keyval_types, device_int_compat_types > |
all_supported_types |
The set of all types in ncarray, including accumulators and the base dtypes. |
FixedMetadata< ssize_t > |
Metadata |
By default, Metadata will use ssize_t which is compatible with the conventions used in many places for a signed integer to describe shapes, strides, suboffsets and so on. |
ArrayImpl< NCOffsetsPolicy, ViewPolicy > |
NCArrayView |
|
ArrayImpl< NCOffsetsPolicy, RefPolicy > |
NCArrayRef |
|
ArrayImpl< NCOffsetsPolicy, OwnerPolicy > |
NCArray |
|
uint32_t |
Instruction |
Instructions for the virutal machine are stored in a packed format in 32 bit ints. |
ArrayImpl< SOArrayPolicy, ViewPolicy > |
SOArrayView |
|
ArrayImpl< SOArrayPolicy, RefPolicy > |
SOArrayRef |
|
ArrayImpl< SOArrayPolicy, OwnerPolicy > |
SOArray |
NCViewFor
Section titled “NCViewFor”using NCViewFor = ArrayImpl< NCOffsetsPolicy, typename StoragePolicyTraits< MemType >::View >NCRefFor
Section titled “NCRefFor”using NCRefFor = ArrayImpl< NCOffsetsPolicy, typename StoragePolicyTraits< MemType >::Ref >NCOwnerFor
Section titled “NCOwnerFor”using NCOwnerFor = ArrayImpl< NCOffsetsPolicy, typename StoragePolicyTraits< MemType >::Owner >SOViewFor
Section titled “SOViewFor”using SOViewFor = ArrayImpl< SOArrayPolicy, typename StoragePolicyTraits< MemType >::View >SORefFor
Section titled “SORefFor”using SORefFor = ArrayImpl< SOArrayPolicy, typename StoragePolicyTraits< MemType >::Ref >SOOwnerFor
Section titled “SOOwnerFor”using SOOwnerFor = ArrayImpl< SOArrayPolicy, typename StoragePolicyTraits< MemType >::Owner >Scalar
Section titled “Scalar”using Scalar = std::variant< bool, char, uint8_t, uint16_t, uint32_t, uint64_t, int8_t, int16_t, int32_t, int64_t, float, double, long double, complex< float >, complex< double >, complex< long double >, Float2, Float3, Float4, Double2, Double3, Double4 >The set of scalar types used by ncarray - one for each DType.
base_types
Section titled “base_types”using base_types = type_list< bool, char, uint8_t, uint16_t, uint32_t, uint64_t, int8_t, int16_t, int32_t, int64_t, float, double, long double, complex< float >, complex< double >, complex< long double >, Float2, Float3, Float4, Double2, Double3, Double4 >All supported base datatypes in ncarray.
This includes basic C++ types, complex numbers and vector types.
concat_t
Section titled “concat_t”using concat_t = typename concat< Lists... >::typeThe full type of a set of type_lists concatenated with concat.
accumulator_types
Section titled “accumulator_types”using accumulator_types = typename wrap_list< VarAccumulator, base_types >::typeIndexedKVP
Section titled “IndexedKVP”using IndexedKVP = KeyValPair< ssize_t, T >The KeyValPair type used for reductions in ncarray.
keyval_types
Section titled “keyval_types”using keyval_types = typename wrap_list< IndexedKVP, base_types >::typedevice_int_compat_types
Section titled “device_int_compat_types”using device_int_compat_types = type_list< long, unsigned long, long long, unsigned long long >Provide supporting types for the ArrayElementProxy restricted conversion operators.
Due to differences in definitions of fixed-width ints on host and device (std, vs cuda::std), the ArrayElementProxy concept on the operator T& may delete needed operators inside kernels. This type_list adds back the requisite types.
all_supported_types
Section titled “all_supported_types”using all_supported_types = concat_t< base_types, accumulator_types, keyval_types, device_int_compat_types >The set of all types in ncarray, including accumulators and the base dtypes.
Metadata
Section titled “Metadata”using Metadata = FixedMetadata< ssize_t >By default, Metadata will use ssize_t which is compatible with the conventions used in many places for a signed integer to describe shapes, strides, suboffsets and so on.
NCArrayView
Section titled “NCArrayView”using NCArrayView = ArrayImpl< NCOffsetsPolicy, ViewPolicy >NCArrayRef
Section titled “NCArrayRef”using NCArrayRef = ArrayImpl< NCOffsetsPolicy, RefPolicy >NCArray
Section titled “NCArray”using NCArray = ArrayImpl< NCOffsetsPolicy, OwnerPolicy >Instruction
Section titled “Instruction”using Instruction = uint32_tInstructions for the virutal machine are stored in a packed format in 32 bit ints.
The op code (e.g. ADD, LOAD_ARRAY etc) is stored in the lower 8 bits. The index of the operand in the VM’s stack is in the remaining bits.
SOArrayView
Section titled “SOArrayView”using SOArrayView = ArrayImpl< SOArrayPolicy, ViewPolicy >SOArrayRef
Section titled “SOArrayRef”using SOArrayRef = ArrayImpl< SOArrayPolicy, RefPolicy >SOArray
Section titled “SOArray”using SOArray = ArrayImpl< SOArrayPolicy, OwnerPolicy >Functions
Section titled “Functions”| Return | Name | Description |
|---|---|---|
std::vector< ssize_t > |
calculate_c_order_strides inline |
Calculate the strides for a standard C-order (row-major) contiguous array of given shape. |
std::vector< ssize_t > |
calculate_c_order_strides inline |
Calculate the strides for a standard C-order (row-major) contiguous array of given shape. |
NCA_HD void |
calculate_c_order_strides inline |
Calculate the strides for a standard C-order (row-major) contiguous array of given shape. |
auto |
promote_to_so |
Convert an NCOffsets array to an SOArray. |
NCA_HDArrayElementProxy |
static_index inline |
Given a linearized index and array, construct a StaticCoords object to index. |
ReductionParams |
build_reduction_params inline |
Setup a small struct with strides, offsets and masks for reducing axes. |
std::ostream & |
operator<< |
A formatting helper for printing vector datatypes. |
NCA_HD T |
nca_sqrt inline |
A helper for setting up square roots on various types. |
NCA_HD size_t |
itemsize inline |
Returns the size in bytes of the provided DType. |
std::string |
to_string inline |
Returns the string representation of the DType for printing. |
Scalar |
to_scalar |
Convert a pointer to an array element to a Scalar. |
NCA_HD auto |
dispatch_integers inline |
A restricted dispatcher for integer types. This is useful when using arrays to hold indices for other arrays. |
NCA_HD auto |
dispatch inline |
Dispatch a visitor/lambda based on DType. |
size_t |
bytes_for_dynamic_vm inline |
|
DynamicExprMVNode< MemTag > |
get_dynamic_mv_node inline |
|
DType |
promote_expr_types inline |
The enum DTypes are already ordered. For expressions’ working dtype, promote to the numerically larger. The final value is determined using op_traits. |
bool |
can_linearize |
|
std::string |
hash_to_hex |
|
std::string |
get_arch_opt |
|
fs::path |
get_cache_dir |
Get the cache directory for the system. |
std::string |
get_install_library_path |
Return the path to the currently loaded JIT shared library. |
std::string |
get_install_include_path |
Return the path to the include headers for ncarray relative to the shared library. |
std::string |
read_file |
Read a file at the provided path. The entire contents are returned in a string. |
void * |
read_bin_file_to_exec_mem |
Read a binary file at the provided path into executable memory. |
void |
write_file |
Write a file to the provided path. |
void |
write_file |
Write a binary object to the provided path. |
NCA_HDDType |
determine_dtype_for_op inline |
For a specific operation and input datatype determine the correct result dtype. |
NCA_HD uint32_t |
pack_instruction inline |
Pack an op code and an operand index into a single VM instruction. |
NCA_HDOpCode |
get_op inline |
From a packed instruction retrieve the op code. |
NCA_HD int |
get_index inline |
From a packed instruction retrieve the operand stack index. |
str |
get_include |
|
str |
get_lib_dir |
|
lazy_mode |
Context manager to delay immediate evaluation of results. |
calculate_c_order_strides
Section titled “calculate_c_order_strides”inline
inline std::vector< ssize_t > calculate_c_order_strides(const std::vector< ssize_t > & shape, const ssize_t itemsize)Calculate the strides for a standard C-order (row-major) contiguous array of given shape.
Parameters
Section titled “Parameters”-
shapeThe shape to calculate strides for. -
itemsizeThe size in bytes of a single element of the array.
Returns
Section titled “Returns”The C-order calculated strides.
calculate_c_order_strides
Section titled “calculate_c_order_strides”inline
inline std::vector< ssize_t > calculate_c_order_strides(const ssize_t ndim, const ssize_t * shape, const ssize_t itemsize)Calculate the strides for a standard C-order (row-major) contiguous array of given shape.
Parameters
Section titled “Parameters”-
Thenumber of dimensions in the array. -
shapeThe shape to calculate strides for (pointer to first element). -
itemsizeThe size in bytes of a single element of the array.
Returns
Section titled “Returns”The C-order calculated strides.
calculate_c_order_strides
Section titled “calculate_c_order_strides”inline
inline NCA_HD void calculate_c_order_strides(const ssize_t ndim, const ssize_t * shape, const ssize_t itemsize, ssize_t * new_strides)Calculate the strides for a standard C-order (row-major) contiguous array of given shape.
Parameters
Section titled “Parameters”-
Thenumber of dimensions in the array. -
shapeThe shape to calculate strides for (pointer to first element). -
itemsizeThe size in bytes of a single element of the array. -
stridesThe C-order calculated strides will be output in this pointer.
promote_to_so
Section titled “promote_to_so”template<typename MemTag> auto promote_to_so(const ArrayImpl< NCOffsetsPolicy, typename StoragePolicyTraits< MemTag >::View > & nc)Convert an NCOffsets array to an SOArray.
For convenience the function will consume all offsets in the NCOffsetsArray. All suboffsets should then be -1 or 0.
Parameters
Section titled “Parameters”[MemTag](api-ncarray-MemTag.md#memtag)The tag indicating whether array is host- or device-resident.
Parameters
Section titled “Parameters”ncThe NCArray* to be converted to SOArray*.
Returns
Section titled “Returns”The SOArray* equivalent to the input nc array.
static_index
Section titled “static_index”inline
template<class Array> inline NCA_HDArrayElementProxy static_index(Array arr, unsigned idx)Given a linearized index and array, construct a StaticCoords object to index.
Because the StaticCoords object has a constexpr size, using it for indexing as opposed to linearized indices can have major performance benefits, particularly for device code applications. E.g., the constexpr size generally allows loops to be fully unrolled, and stack spilling to be avoided in compiled kernels.
This routine simply converts the linearized ravel index to a StaticCoords object of the correct dimensionality of the array, using a switch dispatch.
Parameters
Section titled “Parameters”ArrayThe type of the input array.
Parameters
Section titled “Parameters”-
arrThe input array. -
idxThe linearized ravel index.
Returns
Section titled “Returns”The ArrayElementProxy to the requested data element.
build_reduction_params
Section titled “build_reduction_params”inline
inline ReductionParams build_reduction_params(const std::vector< ssize_t > & axes, ssize_t arr_ndim, const ssize_t * in_shape, const ssize_t * in_strides, ssize_t(&) new_shape, ssize_t & new_ndim, ssize_t itemsize, double ddof = 0.0)Setup a small struct with strides, offsets and masks for reducing axes.
Parameters
Section titled “Parameters”-
axesThe user-requested axes that willbe reduced. -
arr_ndimThe number of dimensions (axes) in the array currently. -
in_shapeThe shape of the axes in the array. -
in_stridesThe strides of the axes in the array in ELEMENTS (not bytes). -
new_shapeThe new shape for the array following reduction. -
new_ndimThe number of dimensions after reduction. -
itemsizeThe size in bytes of the array elements data type. -
ddofThe delta degrees of freedom – only passed through to var/std reductions.
Returns
Section titled “Returns”params The reduction parameter table.
operator<<
Section titled “operator<<”template<Vector2DType T> std::ostream & operator<<(std::ostream & oss, const T & vec)A formatting helper for printing vector datatypes.
Parameters
Section titled “Parameters”TThe input datatype, requires at least Vector2DType.
Parameters
Section titled “Parameters”-
ossThe stream to write the contents to. -
vecThe vector data type to print to the stream.
nca_sqrt
Section titled “nca_sqrt”inline
template<typename T> inline NCA_HD T nca_sqrt(const T & val)A helper for setting up square roots on various types.
Parameters
Section titled “Parameters”TThe datatype of the value to take the square root of.
Parameters
Section titled “Parameters”valThe value to take the square root of.
The square root overload for handling the elementwise square-root of vector types.
Parameters
Section titled “Parameters”TThe datatype of the value to take the square root of, requires at least Vector2DType.
Parameters
Section titled “Parameters”valThe vector value to take the elementwise square root of.
itemsize
Section titled “itemsize”inline
inline NCA_HD size_t itemsize(DType type)Returns the size in bytes of the provided DType.
Todo: Formally enforce these guarantees. This should be correct in all currently supported use cases – but its not guaranteed. The fixed sizes listed here need to be handled (via whatever types required) in the event they are not satisfied in a particular case/on a particular platform.
Parameters
Section titled “Parameters”typeThe input DType.
Returns
Section titled “Returns”The size in bytes.
to_string
Section titled “to_string”inline
inline std::string to_string(DType type)Returns the string representation of the DType for printing.
Parameters
Section titled “Parameters”typeThe input DType.
Returns
Section titled “Returns”The string representation of the data type.
to_scalar
Section titled “to_scalar”template<typename T> Scalar to_scalar(const void * ptr)Convert a pointer to an array element to a Scalar.
Parameters
Section titled “Parameters”TThe underlying type of the array element.
Parameters
Section titled “Parameters”ptrThe pointer to the array element.
Returns
Section titled “Returns”The Scalar wrapper.
dispatch_integers
Section titled “dispatch_integers”inline
template<typename Visitor> inline NCA_HD auto dispatch_integers(DType type, Visitor && visitor)A restricted dispatcher for integer types. This is useful when using arrays to hold indices for other arrays.
dispatch
Section titled “dispatch”inline
template<typename Visitor> inline NCA_HD auto dispatch(DType type, Visitor && visitor)Dispatch a visitor/lambda based on DType.
This function dispatches only on the base_types (this controls combinatorial explosion to some degree). In certain places, broader dispatching may be desired. In that case, using list_dispatcher directly with specialized type lists can be done instead.
Parameters
Section titled “Parameters”VisitorThe type of the visitor to be dispatched based on DType.
Parameters
Section titled “Parameters”-
typeThe DType to use for dispatching. -
visitorThe lambda visitor.
Returns
Section titled “Returns”Whatever is returned by the visitor.
bytes_for_dynamic_vm
Section titled “bytes_for_dynamic_vm”inline
template<typename MemTag> inline size_t bytes_for_dynamic_vm(const ExprMVNode< MemTag > & node, size_t alignment = 16)get_dynamic_mv_node
Section titled “get_dynamic_mv_node”inline
template<typename MemTag> inline DynamicExprMVNode< MemTag > get_dynamic_mv_node(const ExprMVNode< MemTag > & node, uint8_t * h_ptr, uint8_t * d_ptr = nullptr, size_t alignment = 16)promote_expr_types
Section titled “promote_expr_types”inline
inline DType promote_expr_types(DType a, DType b)The enum DTypes are already ordered. For expressions’ working dtype, promote to the numerically larger. The final value is determined using op_traits.
can_linearize
Section titled “can_linearize”template<class MemTag> bool can_linearize(const ExprMVNode< MemTag > & node)hash_to_hex
Section titled “hash_to_hex”std::string hash_to_hex(const std::string & input)get_arch_opt
Section titled “get_arch_opt”std::string get_arch_opt()get_cache_dir
Section titled “get_cache_dir”fs::path get_cache_dir()Get the cache directory for the system.
Uses XDG_CACHE_HOME on Linux if set, or LOCALPPDATA on Windows.
get_install_library_path
Section titled “get_install_library_path”std::string get_install_library_path()Return the path to the currently loaded JIT shared library.
get_install_include_path
Section titled “get_install_include_path”std::string get_install_include_path()Return the path to the include headers for ncarray relative to the shared library.
read_file
Section titled “read_file”std::string read_file(fs::path file_path)Read a file at the provided path. The entire contents are returned in a string.
Parameters
Section titled “Parameters”file_pathThe path to read.
Returns
Section titled “Returns”contents The file contents as a string. Empty if there was an error.
read_bin_file_to_exec_mem
Section titled “read_bin_file_to_exec_mem”void * read_bin_file_to_exec_mem(fs::path file_path)Read a binary file at the provided path into executable memory.
Parameters
Section titled “Parameters”file_pathThe path to read.
Returns
Section titled “Returns”contents The data loaded into executable memory.
write_file
Section titled “write_file”void write_file(fs::path file_path, const std::string & contents)Write a file to the provided path.
Parameters
Section titled “Parameters”-
file_pathThe path to write to. -
contentsThe file contents to write out.
write_file
Section titled “write_file”void write_file(fs::path file_path, std::size_t k_size, const std::uint8_t * k_data)Write a binary object to the provided path.
Parameters
Section titled “Parameters”-
file_pathThe path to write to. -
k_sizeNumber of bytes to write. -
k_dataPointer to the start of the data to write.
determine_dtype_for_op
Section titled “determine_dtype_for_op”inline
inline NCA_HDDType determine_dtype_for_op(OpCode code, DType left)For a specific operation and input datatype determine the correct result dtype.
[op_traits](api-ncarray-op_traits.md#op_traits) define certain semantics for type promotion or conversion depending on the operation being performed. E.g. to avoid frequent overflows very small integers (uint8, uint16) will be promoted to larger ones. The output datatype for an ADD operation for uint8 will then be uint64 (int8 -> int64).
Parameters
Section titled “Parameters”-
codeThe op code for this operation. -
leftThe datatype of the leftmost operand. -
res_dtypeThe appropriate output datatype for the operation.
pack_instruction
Section titled “pack_instruction”inline
inline NCA_HD uint32_t pack_instruction(OpCode op, int idx)Pack an op code and an operand index into a single VM instruction.
get_op
Section titled “get_op”inline
inline NCA_HDOpCode get_op(Instruction instr)From a packed instruction retrieve the op code.
get_index
Section titled “get_index”inline
inline NCA_HD int get_index(Instruction instr)From a packed instruction retrieve the operand stack index.
get_include
Section titled “get_include”str get_include()get_lib_dir
Section titled “get_lib_dir”str get_lib_dir()lazy_mode
Section titled “lazy_mode”lazy_mode()Context manager to delay immediate evaluation of results.
Variables
Section titled “Variables”| Return | Name | Description |
|---|---|---|
constexpr bool |
is_in_type_list_v constexpr |
Whether a requested type is in the specified type_list. |
constexpr bool |
is_exprmv_node_v constexpr |
|
constexpr bool |
is_layout_policy_v constexpr |
Underlying trait to check for layout policy descendence. |
constexpr bool |
is_ncoffsets_policy_v constexpr |
Underlying trait to check for if NCOffsetsPolicy. |
constexpr bool |
is_soarray_policy_v constexpr |
Underlying trait to check for if SOArrayPolicy. |
str |
lib_dir |
|
str |
core_dir |
|
bool |
has_driver |
|
str |
stub_path |
|
mode |
is_in_type_list_v
Section titled “is_in_type_list_v”constexpr
constexpr bool is_in_type_list_v = <T, List>::valueWhether a requested type is in the specified type_list.
Parameters
Section titled “Parameters”-
TThe object under test. -
ListThe list to check for the inclusion of T.
is_exprmv_node_v
Section titled “is_exprmv_node_v”constexpr
constexpr bool is_exprmv_node_v = <Expr>::valueis_layout_policy_v
Section titled “is_layout_policy_v”constexpr
constexpr bool is_layout_policy_v = <L>::valueUnderlying trait to check for layout policy descendence.
is_ncoffsets_policy_v
Section titled “is_ncoffsets_policy_v”constexpr
constexpr bool is_ncoffsets_policy_v = <L>::valueUnderlying trait to check for if NCOffsetsPolicy.
is_soarray_policy_v
Section titled “is_soarray_policy_v”constexpr
constexpr bool is_soarray_policy_v = <L>::valueUnderlying trait to check for if SOArrayPolicy.
lib_dir
Section titled “lib_dir”str lib_dir = ()core_dir
Section titled “core_dir”str core_dir = os.path.join(os.path.dirname(__file__), "core")has_driver
Section titled “has_driver”bool has_driver = ctypes.util.find_library("cuda") is not Nonestub_path
Section titled “stub_path”str stub_path = os.path.join( os.path.dirname(__file__), "core", "stubs", "libcuda.so" ) mode