Higher level API to build and compile tvm functions.
Higher level API to build and compile tvm functions.
(bind-arguments arg-list bind-map build-config)
Given an arg-list and existing bind map, produce a new arg list and bind map with all arguments bound to input buffers with defined buffer layout. Bind map is a map of type NodeHandle->NodeHandle where the keys are tensors and the values are buffers. The default is to bind a compact, non-offset buffer so if you want a different buffer type than this then you need to bind it yourself.
Given an arg-list and existing bind map, produce a new arg list and bind map with all arguments bound to input buffers with defined buffer layout. Bind map is a map of type NodeHandle->NodeHandle where the keys are tensors and the values are buffers. The default is to bind a compact, non-offset buffer so if you want a different buffer type than this then you need to bind it yourself.
(call ret-dtype fn-name fn-args call-type function-ref value-index)
Call a 'function', which is basically executing a statement. For instance, getting a value from the tensor is calling a halide function with the tensor's generating-op and value index.
Call a 'function', which is basically executing a statement. For instance, getting a value from the tensor is calling a halide function with the tensor's generating-op and value index.
(call-intrin dtype func-name & args)
Build expression by calling an intrinsic function.
Intrinsics can be overloaded with multiple data types via the intrinsic translation rule.
dtype : str The data type of the result.
func_name: str The intrinsic function name.
args : list Positional arguments.
call : Expr The call expression.
Build expression by calling an intrinsic function. Intrinsics can be overloaded with multiple data types via the intrinsic translation rule. Parameters ---------- dtype : str The data type of the result. func_name: str The intrinsic function name. args : list Positional arguments. Returns ------- call : Expr The call expression.
(call-pure-intrin dtype func-name & args)
Build expression by calling a pure intrinsic function.
Intrinsics can be overloaded with multiple data types via the intrinsic translation rule.
dtype : str The data type of the result.
func_name: str The intrinsic function name.
args : list Positional arguments.
call : Expr The call expression.
Build expression by calling a pure intrinsic function. Intrinsics can be overloaded with multiple data types via the intrinsic translation rule. Parameters ---------- dtype : str The data type of the result. func_name: str The intrinsic function name. args : list Positional arguments. Returns ------- call : Expr The call expression.
Possible call types from Halide/IR.h
Possible call types from Halide/IR.h
(cast expr-node dtype)
See static cast redone to allow usage in ->
See static cast redone to allow usage in ->
(commutative-reduce reduce-op identity-val dtype expr-seq axis-seq)
1 left hand side, first var of reduce operation N right hand sides, rest of the variables of the reduce operation identity-val - initialization of left hand side.n expr-ary - one for each (const) right hand side. dtype - datatype of all inputs to reduction
1 left hand side, first var of reduce operation N right hand sides, rest of the variables of the reduce operation identity-val - initialization of left hand side.n expr-ary - one for each (const) right hand side. dtype - datatype of all inputs to reduction
(compute shape fcompute name & {:keys [tag attrs] :or {tag ""}})
Construct a new tensor by computing over the shape domain.
The compute rule is result[axis] = fcompute(axis)
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.
The created compute node
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
(const numeric-value & [dtype])
Convert an item to a const (immediate) value
Convert an item to a const (immediate) value
(declare-buffer
shape
&
{:keys [dtype name data strides elem-offset scope data-alignment]
:or {name "buffer" dtype "float32" scope "" data-alignment -1}})
Decleare a new symbolic buffer.
Normally buffer is created automatically during lower and build. This is only needed if user want to specify their own buffer layout.
See the note below for detailed discussion on usage of buffer.
shape : tuple of Expr The shape of the buffer.
dtype : str, optional The data type of the buffer.
name : str, optional The name of the buffer.
data : Var, optional The data pointer in the buffer.
strides: array of Expr The stride of the buffer.
elem_offset: Expr, optional The beginning offset of the array to data. In terms of number of elements of dtype.
scope: str, optional The storage scope of the buffer, if not global. If scope equals empty string, it means it is global memory.
data_alignment: int, optional The alignment of data pointer in bytes. If -1 is passed, the alignment will be set to TVM's internal default.
--CN - REMOVED - No one understands what this does. It is only referenced in the code in order to perform a check during argument binding. So the description below is accurate for what it is worth but it is hard to me to see how this is useful.
offset_factor: int, optional The factor of elem_offset field, when set, elem_offset is required to be multiple of offset_factor. If 0 is pssed, the alignment will be set to 1. if non-zero is passed, we will created a Var for elem_offset if elem_offset is not None.
--CN - END-REMOVED --
buffer : Buffer The created buffer
Buffer data structure reflects the DLTensor structure in dlpack. While DLTensor data structure is very general, it is usually helpful to create function that only handles specific case of data structure and make compiled function benefit from it.
If user pass strides and elem_offset is passed as None when constructing the function, then the function will be specialized for the DLTensor that is compact and aligned. If user pass a fully generic symbolic array to the strides, then the resulting function becomes fully generic.
Decleare a new symbolic buffer. Normally buffer is created automatically during lower and build. This is only needed if user want to specify their own buffer layout. See the note below for detailed discussion on usage of buffer. Parameters ---------- shape : tuple of Expr The shape of the buffer. dtype : str, optional The data type of the buffer. name : str, optional The name of the buffer. data : Var, optional The data pointer in the buffer. strides: array of Expr The stride of the buffer. elem_offset: Expr, optional The beginning offset of the array to data. In terms of number of elements of dtype. scope: str, optional The storage scope of the buffer, if not global. If scope equals empty string, it means it is global memory. data_alignment: int, optional The alignment of data pointer in bytes. If -1 is passed, the alignment will be set to TVM's internal default. --CN - REMOVED - No one understands what this does. It is only referenced in the code in order to perform a check during argument binding. So the description below is accurate for what it is worth but it is hard to me to see how this is useful. offset_factor: int, optional The factor of elem_offset field, when set, elem_offset is required to be multiple of offset_factor. If 0 is pssed, the alignment will be set to 1. if non-zero is passed, we will created a Var for elem_offset if elem_offset is not None. --CN - END-REMOVED -- Returns ------- buffer : Buffer The created buffer Note ---- Buffer data structure reflects the DLTensor structure in dlpack. While DLTensor data structure is very general, it is usually helpful to create function that only handles specific case of data structure and make compiled function benefit from it. If user pass strides and elem_offset is passed as None when constructing the function, then the function will be specialized for the DLTensor that is compact and aligned. If user pass a fully generic symbolic array to the strides, then the resulting function becomes fully generic.
(def-bin-op op-name make-name)
Define a binary operation
Define a binary operation
(def-op op-name make-name)
Define a binary operation
Define a binary operation
Comments from tvm/build_module.h
Comments from tvm/build_module.h
(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.
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.
Iteration variable types defined in tvm/include/Expr.h
Iteration variable types defined in tvm/include/Expr.h
(lowered-functions->module
lowered-function-seq
&
{:keys [build-config target-name target-host]
:or {target-name :llvm target-host :llvm build-config default-build-config}})
(name->thread-axis-iterator axis-name)
Create a thread iter-var from a thread axis name
Create a thread iter-var from a thread axis name
(placeholder shape name & {:keys [dtype] :or {dtype "float32"}})
Create a user-supplied tensor variable
Create a user-supplied tensor variable
(range start end)
Create a range with defined start inclusive and end exclusive
Create a range with defined start inclusive and end exclusive
(schedule->lowered-function schedule
args
name
&
{:keys [build-config bind-map simple-mode?]
:or {bind-map {}
build-config default-build-config}})
Lowering step before build into target.
schedule : tvm.Schedule The schedule to be builded
args : list of Buffer or Tensor or Var The argument lists to the function.
name : str, optional The name of result function.
bind-map: map of {:tensor :buffer}, optional mapping fuction or hash-map that maps the Tensor to Buffer which specified the data layout requirement of the function. By default, a new compact buffer is created for each tensor in the argument list.
simple-mode? : bool, optional (not currently implemented) Whether only output simple and compact statement, this will skip LoopPartition, api wrapper generation and Unrolling.
f : LoweredFunc or Stmt The result function, if with_api_wrapper=False Then the Stmt before make api is returned.
Lowering step before build into target. Parameters ---------- schedule : tvm.Schedule The schedule to be builded args : list of Buffer or Tensor or Var The argument lists to the function. name : str, optional The name of result function. bind-map: map of {:tensor :buffer}, optional mapping fuction or hash-map that maps the Tensor to Buffer which specified the data layout requirement of the function. By default, a new compact buffer is created for each tensor in the argument list. simple-mode? : bool, optional (not currently implemented) Whether only output simple and compact statement, this will skip LoopPartition, api wrapper generation and Unrolling. Returns ------- f : LoweredFunc or Stmt The result function, if with_api_wrapper=False Then the Stmt before make api is returned.
(schedule-cache-write schedule tensor cache-type)
Returns a new tensor
Returns a new tensor
(schedules->fns
sched-data-seq
&
{:keys [build-config target-name target-host]
:or {build-config default-build-config target-name :llvm target-host :llvm}})
Given a sequence of schedule-data, return a map of name to clojure callable function. A module is created and added to the resource context transparently. Schedule data: {:name :fn-name :arglist arguments :schedule schedule :bind-map (optional) bind-map } returns: {:module module :fn-map map of name->IFn (clojure callable function.)
Given a sequence of schedule-data, return a map of name to clojure callable function. A module is created and added to the resource context transparently. Schedule data: {:name :fn-name :arglist arguments :schedule schedule :bind-map (optional) bind-map } returns: {:module module :fn-map map of name->IFn (clojure callable function.)
(select bool-stmt true-stmt false-stmt)
Select between two expressions based on a condition. Thus works similar to the clojure 'if' statement.
Select between two expressions based on a condition. Thus works similar to the clojure 'if' statement.
(stage-bind stage iter-var thread-ivar)
Bind an iter-var to a stage variable
Bind an iter-var to a stage variable
(stage-bind-gpu stage block-axis-seq thread-axis-seq)
Bind the gpu-defined axis to the tvm axis. GPU (cuda, opencl) define a roughly level stage breakdown of axis: block and thread. Threads run on the same block and can share a special kind of memory (called shared memory). There can be up to 3 tvm axis per block or thread and these are labeled (outer iterator to inner iterator): [z y x]
Bind the gpu-defined axis to the tvm axis. GPU (cuda, opencl) define a roughly level stage breakdown of axis: block and thread. Threads run on the same block and can share a special kind of memory (called shared memory). There can be up to 3 tvm axis per block or thread and these are labeled (outer iterator to inner iterator): [z y x]
(stage-compute-at src-stage dst-stage dst-axis)
Compute src stage at dst stage dst axis
Compute src stage at dst stage dst axis
(stage-fuse stage axis-args)
Fuse n-axis together, returns single new axis
Fuse n-axis together, returns single new axis
(stage-gpu-injective stage
op
&
{:keys [thread-count axis] :or {thread-count 16}})
(stage-parallel stage axis)
Indicate that this axis has complete parallelism
Indicate that this axis has complete parallelism
(static-cast dtype expr-node)
Cast an item from one datatype to another
Cast an item from one datatype to another
(tvm-fn arg-vec & body)
Like (fn) but retains the arglists. Lambda in clojure unfortunately does not.
Like (fn) but retains the arglists. Lambda in clojure unfortunately does not.
(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!!
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 name & {:keys [dtype] :or {dtype "int32"}})
Create a scalar variable. Returns a node handle
Create a scalar variable. Returns a node handle
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close