tvm-clj.ast
TVM’s algorithms are first described using an AST tailored towards ND-array programming.
commutative-reduce
(commutative-reduce comm-reducer reduce-axis read-exprs condition)(commutative-reduce comm-reducer reduce-axis read-exprs)Create a reduce node.
comm-reducer- A commutative reducer produced via eithercommutative-reducerortvm-fn->commutative-reducer.reduce-axis- A list of either maps of {:domain :name} oriteration-variable’s of type:communicative-reduce. If a list element is a map?, it will be interpreted as a map of {:domain :name} in the corresponding iteration variable will be created for you.-
read-exprs- Eitherfn?’s or a list of expressions that must equal the number of inputs tocommutative-reducerand that must be based off of the variables defined inreduce-axis. If read-exprs are clojure ’fn?’s they will be called with the reduction variables created from reduce-axis.
commutative-reducer
(commutative-reducer reduce-fn-args reduction-ast-fns)Create a commutative reducer. Reducers are used in as the part of the commutative reduction pathway.
reduce-fn-args- sequence of maps of {:name :datatype :argument-type :identity-value} tell you the name of the argument, the datatype, and when the argument is and:accumulatingarg or an:incomingarg. If the argument is an accumulator argument then an:identity-valuemust be provided.incoming-names- Argument names of the incoming values.reduction-ast-fn- fn taking ‘(+ (count accum-args) (count incoming-args))’ arguments and returning an AST that performs the reduction.
Returns a commutative reducer you can use in Reduce.
compute
macro
(compute shape name options idx-varnames body)(compute shape name idx-varnames body)(compute shape idx-varnames body)Compute a new tensor over this shape.
compute-op
(compute-op shape name {:keys [tag attrs], :or {tag ""}} fcompute)(compute-op shape name fcompute)(compute-op shape fcompute)Construct a new tensor by computing over the shape domain.
The compute rule is result[axis] = fcompute(axis)
Parameters
shape: Array of Expr The shape of the tensor
fcompute: lambda function of indices-> value Specifies the input source expression
name: str, optional The name hint of the tensor
tag: str, optional Additonal tag information about the compute.
attrs: dict, optional The additional auxiliary attributes about the compute.
Returns
The created compute node
iteration-variable
(iteration-variable domain name iteration-type & {:keys [thread-tag], :or {thread-tag ""}})Create a variable that controls iteration through the data. The iteration type affects the class of optimizations that the compiler is able to apply to the affected expressions,
Parameters
----------
dom : Range
The domain of iteration.
name : str
The name of iteration variable.
iteration-type : keyword
The type of iteration.
thread-tag : str
The thread tag of the iteration variable.
name->thread-axis-iterator
(name->thread-axis-iterator axis-name)Create a thread iter-var from a thread axis name
placeholder
(placeholder shape name & {:keys [dtype], :or {dtype "float32"}})Create a user-supplied tensor variable
scan
(scan init-op update-op scan-state args & [{:keys [op-name tag attrs], :or {op-name "scan", tag ""}}])Create a recursive scan operation
tvm-fn
macro
(tvm-fn arg-vec & body)Like (fn) but retains the arglists. Lambda in clojure unfortunately does not.
tvm-fn->args
(tvm-fn->args tvm-fn)Get the vector of tvm-safe string argument names to a tvm function.
tvm-fn->commutative-reducer
(tvm-fn->commutative-reducer tvm-fn identity-values datatypes)(tvm-fn->commutative-reducer tvm-fn identity-values)Make a reducer out of a tvm function assuming all arguments are the same datatype.
Accumulation arguments are considered the first N arguments where N is the number of initial values. The rest of the arguments are considered incoming arguments. There must be at least one each of accumulation and incoming arguments.
tvm-fn- a function with proper metadata such that:arglistscan be found.identity-values- list of identity values. This implicitly indicates the number of accumulation arguments as there must be one identity value per accumulation arguments.datatype- Option datatype. If not provided will be inferred from the datatypes of identity-values.
tvm-let
macro
(tvm-let expr-pairs body)Lets in tvm must be nested. This leads to an exciting macro. Pairs must be of the form var val-expr. Body is not an implicit do!!
variable
(variable name & {:keys [dtype], :or {dtype "int32"}})Create a scalar variable. Returns a node handle