Public API¶
Data types¶
-
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
Expressions¶
-
class
Scalar
(expr_code, dtype)[source]¶ An expression that refers to a single data value which has a data type
-
class
InputTensor
(tensor_type, io_index)[source]¶ A read-only input tensor expression
-
__bool__
()¶
-
__getitem__
(item)¶
-
__nonzero__
()¶
-
-
class
OutputTensor
(tensor_type, io_index)[source]¶ A write-only output expression
-
__bool__
()¶
-
__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 Returns: 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 Returns: a tensor expression which refers to the newly defined output tensor Example: Create a new output tensor
out
based on theTensorType
of input tensorin0
out = output(in0.tensor_type)
Example: Create a new output tensor
out
based on theshape
of input tensorin0
and theDType
of input tensorin1
: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 Returns: a tensor expression which refers to the newly defined output tensor
Scalar functions¶
Utility¶
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 Returns: minimum value for dtype
Unary math¶
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
Returns: None
Example: 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
blockParameters: condition – The condition under which to execute the body of the with block Example: 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 Example: 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 Returns: 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.Example: 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¶
-
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.
Returns: 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
Returns: 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
Returns: A TensorFlow operator.