# Public API¶

## Data types¶

class DType(dtype)[source]

Data type object which indicates a low level type.

as_tensorflow()[source]
float32

The single precision floating point DType

float64

The double precision floating point DType

int8

The 8 bit signed integer DType

int16

The 16 bit signed integer DType

int32

The 32 bit signed integer DType

int64

The 64 bit signed integer DType

uint8

The 8 bit unsigned integer DType

uint16

The 16 bit unsigned integer DType

uint32

The 32 bit unsigned integer DType

uint64

The 64 bit unsigned integer DType

class TensorType(shape, dtype)[source]

A tensor is defined by its data type and its shape.

Parameters: shape – The tensor shape dtype – The data type A tensor type object
static like(other)[source]

Resolve the TensorType the argument

Parameters: other – The input object A TensorType like the input object

## Expressions¶

class Scalar(expr_code, dtype)[source]

An expression that refers to a single data value which has a data type

__add__(other)[source]
__div__(other)[source]
__eq__(other)[source]
__ge__(other)[source]
__gt__(other)[source]
__le__(other)[source]
__lt__(other)[source]
__mod__(other)[source]
__mul__(other)[source]
__ne__(other)[source]
__neg__()[source]
__rtruediv__(other)[source]
__sub__(other)[source]
__truediv__(other)[source]
class Variable(dtype, intial_const)[source]

A variable expression

__ilshift__(other)[source]
class InputTensor(tensor_type, io_index)[source]

__bool__()
__getitem__(item)
__nonzero__()
class OutputTensor(tensor_type, io_index)[source]

A write-only output expression

__bool__()
__nonzero__()
__setitem__(key, value)
class PositionTensor(workgroup_shape)[source]

The position expression which refers to the current position within the workgroup shape

__bool__()
__getitem__(item)
__nonzero__()
class LocalTensor(initial_value)[source]

Expression which references a worker-local tensor

__bool__()
__getitem__(item)
__nonzero__()
__setitem__(key, value)

## Tensor functions¶

position_in(workgroup_shape)[source]

Define the workgroup shape and retrieve a tensor expression that refers to the current position in that workgroup shape.

Parameters: workgroup_shape – An iterable of ints defining the shape of the workgroup a tensor expression which references the current workgroup position
output(*args)[source]

Define a new output

Parameters: args – args the define a TensorType, can be either a TensorType or a shape and a DType a tensor expression which refers to the newly defined output tensor

Create a new output tensor out based on the TensorType of input tensor in0

out = output(in0.tensor_type)


Create a new output tensor out based on the shape of input tensor in0 and the DType of input tensor in1:

out = output(in0.shape, in1.dtype)

output_like(other)[source]

Define a new output with the same TensorType as another tensor

Parameters: other – another tensor a tensor expression which refers to the newly defined output tensor
zeros(shape, dtype)[source]

Declare a new worker-local tensor with all elements initialized to zero.

Parameters: shape – the tensor shape dtype – the tensor data type the tensor expression
ones(shape, dtype)[source]

Declare a new worker-local tensor with all elements initialized to one.

Parameters: shape – the tensor shape dtype – the tensor data type the tensor expression

## Scalar functions¶

### Utility¶

variable(initial_value, dtype)[source]

Function for declaring a new variable

Parameters: initial_value – The initial value of the variable dtype – The DType of the variable The variable expression
cast(value, dtype)[source]

Cast a scalar expression as a new data type

Parameters: value – The scalar expression dtype – The new data type The casted scalar expression

### Numeric limits¶

min_value(dtype)[source]

Function for getting the minimum normalized positive value of floating point types

Parameters: dtype – The DType of the variable minimum value for dtype
max_value(dtype)[source]

Function for getting the maximum value of floating point types

Parameters: dtype – The DType of the variable maximum value for dtype
epsilon(dtype)[source]

Function for getting difference between 1.0 and the next representable value for floating point types

Parameters: dtype – The DType of the variable epsilon value for dtype

### Unary math¶

arccos(x)[source]
arcsin(x)[source]
arctan(x)[source]
cos(x)[source]
cosh(x)[source]
sin(x)[source]
sinh(x)[source]
tan(x)[source]
tanh(x)[source]
exp(x)[source]
log(x)[source]
log10(x)[source]
sqrt(x)[source]
ceil(x)[source]
absolute(x)[source]
floor(x)[source]
logical_not(x)[source]
isinf(x)[source]
isfinite(x)[source]
isnan(x)[source]

### Binary math¶

minimum(x, y)[source]
maximum(x, y)[source]
power(x, y)[source]
arctan2(x, y)[source]
logical_and(x, y)[source]
logical_or(x, y)[source]

## Control flow¶

arange(start, stop=None, step=None)[source]

Create an iterator to iterate over a range

Parameters: start – The starting point in the iterator stop – The stopping point in the iterator step – The iterator step size None

usage for accumulating a variable to 10:

accum = variable(0, uint64)
for i in arange(10):
accum <<= accum + 1

if_(condition)[source]

conditional execution, must be used as part of a with block

Parameters: condition – The condition under which to execute the body of the with block

Clip input_tensor to a maximum value of 1:

y = variable(0, input_tensor.dtype)
y = input_tensor[some_index]
with if_(y > 1):
y <<= 1
output_tensor[some_index] = y

elif_(condition)[source]

else if conditional execution, must be used as part of a with block and must come directly after another if or else if block.

Parameters: condition – The condition under which to execute the body of the with block

Clip input_tensor to a maximum value of 1 and a minimum value of -1:

y = variable(0, input_tensor.dtype)
y = input_tensor[some_index]
with if_(y > 1):
y <<= 1
with elif_(y <-1):
y <<= -1
output_tensor[some_index] = y

Parameters: condition – The condition under which to execute the body of the with block None
else_()[source]

else conditional execution, must be used as part of a with block and must come directly after another if or else if block.

Clip input_tensor to a maximum value of 1 and a minimum value of -1, and zero it out if it is within that range:

y = variable(0, input_tensor.dtype)
with if_(y > 1):
y <<= 1
with elif_(y <-1):
y <<= -1
with else_():
y <<= 0
output_tensor[some_index] = y


## Operator functions¶

operator(forbid_none_valued_constants=True, name=None)[source]
gradient(op_function)[source]
evaluate(output_list, target_language='cpp', opt_level=3)[source]

Evaluate a collection of OVL operator, mainly used for testing. This function uses a test operator function for running the generated generic version of the operator so it does not depend on an external execution runtime. This also means that this function only works for operators whose inputs are numpy arrays.

Parameters: output_list – The outputs to evaluate target_language – ‘cpp’ or ‘cuda’ opt_level – Optimization level. A list of numpy arrays for each operator output in output_list
profile(output_list, target_language, profiling_iterations, opt_level)[source]

Evaluate a collection of OVL operator, mainly used for testing. This function uses a test operator function for running the generated generic version of the operator so it does not depend on an external execution runtime. This also means that this function only works for operators whose inputs are numpy arrays.

Parameters: output_list – The outputs to evaluate target_language – ‘cpp’ or ‘cuda’ profiling_iterations – Number of times to run this operator for profiling purposes. Must be a positive int. opt_level – optimization level A tuple containing a list of numpy arrays for each operator output in output_list, and a dictionary of numpy arrays containing the execution times for each operator in the operator DAG.
as_tensorflow(tensor_list, opt_level=3)[source]

Create a DAG of TensorFlow operators based on a DAG of OVL operators and register it with the current TensorFlow Graph. The inputs to the DAG must be numpy arrays or TensorFlow tensors.

Parameters: tensor_list – operator outputs to convert to TensorFlow tensors opt_level – optimization level to use A TensorFlow operator.

## Local runtime environment functions¶

version

Version string for current version

logger

The opveclib logger

cuda_enabled

Flag which indicates whether or not CUDA operators are enabled

cache_directory

Directory where cached operators are stored

clear_op_cache()[source]

Delete all cached operators in the current cache directory. Generally used to make sure there are no stale operators in the cache when testing and debugging.