tvm
builtin.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
33 #ifndef TVM_TIR_BUILTIN_H_
34 #define TVM_TIR_BUILTIN_H_
35 
36 #include <tvm/ir/op.h>
37 #include <tvm/tirx/expr.h>
38 
39 namespace tvm {
40 namespace tirx {
41 
43 namespace builtin {
47 TVM_DLL const Op& ret();
51 TVM_DLL const Op& thread_return();
55 TVM_DLL const Op& continue_loop();
59 TVM_DLL const Op& break_loop();
63 TVM_DLL const Op& reinterpret();
64 
68 TVM_DLL const Op& likely();
69 
77 TVM_DLL const Op& filter();
78 
87 TVM_DLL const Op& selector();
88 
92 TVM_DLL const Op& bitwise_and();
93 
97 TVM_DLL const Op& bitwise_or();
98 
102 TVM_DLL const Op& bitwise_xor();
103 
107 TVM_DLL const Op& bitwise_not();
108 
112 TVM_DLL const Op& shift_left();
113 
117 TVM_DLL const Op& shift_right();
118 
128 TVM_DLL const Op& large_uint_imm();
129 
136 TVM_DLL const Op& q_multiply_shift();
137 TVM_DLL const Op& q_multiply_shift_per_axis();
138 
151 TVM_DLL const Op& address_of();
152 
160 TVM_DLL const Op& if_then_else();
161 
169 TVM_DLL const Op& isnullptr();
170 
174 TVM_DLL const Op& isnan();
175 
179 TVM_DLL const Op& popcount();
180 
188 TVM_DLL const Op& fma();
189 
202 TVM_DLL const Op& call_extern();
203 
216 TVM_DLL const Op& call_pure_extern();
217 
228 TVM_DLL const Op& call_llvm_intrin();
229 
240 TVM_DLL const Op& call_llvm_pure_intrin();
241 
251 TVM_DLL const Op& call_spirv_pure_glsl450();
252 
253 // TODO(tvm-team) revisit the builtins below
254 // some of them can simply become ops with special codegen attr.
258 TVM_DLL const Op& prefetch();
259 
275 TVM_DLL const Op& tvm_access_ptr();
276 
284 TVM_DLL const Op& ptr_byte_offset();
285 
290 TVM_DLL const Op& tvm_static_handle();
291 
296 TVM_DLL const Op& tvm_context_id();
297 
305 TVM_DLL const Op& tvm_tuple();
306 
314 TVM_DLL const Op& handle_add_byte_offset();
315 
324 TVM_DLL const Op& tvm_struct_get();
325 
334 TVM_DLL const Op& tvm_struct_set();
335 
342 TVM_DLL const Op& lookup_param();
343 
351 TVM_DLL const Op& tvm_throw_last_error();
352 
362 TVM_DLL const Op& tvm_stack_alloca();
363 
374 TVM_DLL const Op& tvm_stack_make_shape();
375 
395 TVM_DLL const Op& tvm_stack_make_array();
396 
409 TVM_DLL const Op& tvm_call_packed();
410 
420 TVM_DLL const Op& tvm_call_cpacked();
421 
433 TVM_DLL const Op& tvm_call_trace_packed();
434 
439 TVM_DLL const Op& tvm_thread_invariant();
440 
457 TVM_DLL const Op& tvm_call_packed_lowered();
458 
472 TVM_DLL const Op& tvm_call_cpacked_lowered();
473 
492 
501 TVM_DLL const Op& tvm_storage_sync();
502 
506 TVM_DLL const Op& tvm_kernel_replace_point();
507 
539 TVM_DLL const Op& tvm_warp_shuffle();
540 TVM_DLL const Op& tvm_warp_shuffle_up();
541 TVM_DLL const Op& tvm_warp_shuffle_down();
542 TVM_DLL const Op& tvm_warp_shuffle_xor();
543 TVM_DLL const Op& tvm_warp_activemask();
544 
549 TVM_DLL const Op& tvm_global_barrier_kinit();
550 
562 TVM_DLL const Op& tvm_thread_allreduce();
563 // Metal cooperative_tensor intrinsics (MetalPerformancePrimitives / Metal 4)
564 
571 TVM_DLL const Op& cooperative_tensor_fill();
572 
583 TVM_DLL const Op& cooperative_tensor_load();
584 
595 TVM_DLL const Op& cooperative_tensor_store();
596 
607 
608 // TODO(tvm-team) replace the usage of the vector operations by Shuffle.
612 TVM_DLL const Op& vectorhigh();
613 
617 TVM_DLL const Op& vectorlow();
618 
622 TVM_DLL const Op& vectorcombine();
623 
627 TVM_DLL const Op& dp4a();
628 
632 TVM_DLL const Op& atomic_add();
636 TVM_DLL const Op& nd_mem_alloc_with_scope();
637 
641 TVM_DLL const Op& texture2d_store();
642 
646 TVM_DLL const Op& texture2d_load();
647 
659 TVM_DLL const Op& dma_copy();
660 
667 TVM_DLL const Op& dma_wait();
668 
678 TVM_DLL const Op& dma_start_group();
679 
691 TVM_DLL const Op& dma_end_group();
692 
700 TVM_DLL const Op& assume();
701 
708 TVM_DLL const Op& undef();
709 
713 TVM_DLL const Op& start_profile_intrinsic();
714 
718 TVM_DLL const Op& end_profile_intrinsic();
719 
731 TVM_DLL const Op& anylist_getitem();
732 
744 TVM_DLL const Op& anylist_resetitem();
745 
758 
763 
768 TVM_DLL const Op& vscale();
769 
776 TVM_DLL const Op& get_active_lane_mask();
777 
779 TVM_DLL const Op& ignore_loop_partition();
785 TVM_DLL const Op& buffer_offset();
786 
788 enum TVMStructFieldKind : int {
789  // DLTensor fields
802  // TVMValue field
808  // Generic int64 array element access: ((int64_t*)buf)[index]
810 };
811 
815 TVM_DLL const Op& print_buffer();
816 } // namespace builtin
817 } // namespace tirx
818 } // namespace tvm
819 #endif // TVM_TIR_BUILTIN_H_
Managed reference class to OpNode.
Definition: op.h:163
Primitive operators(builtin intrinsics) and registry for them.
const Op & q_multiply_shift()
Execute a multiplication between two Q-numbers x and y followed by a right shift s The default roundi...
const Op & tvm_warp_shuffle_up()
const Op & dma_end_group()
End a group of DMA copies.
const Op & tvm_stack_make_array()
Allocate a Tensor(DLTensor) on stack, return the handle.
const Op & vscale()
Get the target's vscale value. It will be lowered to llvm.vscale intrinsic (https://llvm....
const Op & tvm_call_cpacked_lowered()
Lowered version of call c-packed, the space of value and type codes are explicitly allocated.
const Op & tvm_access_ptr()
Get head access address with memory access pattern info.
const Op & dp4a()
Dot product of two int8x4 vectors and add an optional accumulator.
const Op & bitwise_xor()
Bitwise xor operator.
const Op & tvm_thread_allreduce()
See pesudo code.
const Op & buffer_offset()
Get the element offset of a buffer given logical indices.
const Op & tvm_call_packed_lowered()
Lowered version of call packed, the space of value and type codes are explicitly allocated.
const Op & address_of()
Returns the address of an element in the buffer (see pseudocode below).
const Op & undef()
Returns an initialized but arbitrary value.
const Op & tvm_call_trace_packed()
See pesudo code.
const Op & tvm_call_cpacked()
See pesudo code.
const Op & tvm_context_id()
Return a unique context id, used for hint of workspace separation. Different context id ganrantees no...
const Op & texture2d_store()
Store to texture 2d memory.
const Op & anylist_setitem_call_cpacked()
Same as anylist_setitem_call_packed but use C calling convention.
const Op & tvm_call_trace_packed_lowered()
Lowered version of trace intrinsic, the space of value and type codes are explicitly allocated....
const Op & cooperative_tensor_multiply_accumulate()
Multiply and accumulate two matrices using cooperative_tensor (MetalPerformancePrimitives matmul2d).
const Op & tvm_tuple()
tvm_tuple is not an actual function and cannot codegen. It is used to represent tuple structure in va...
const Op & cooperative_tensor_store()
Store data from a cooperative_tensor to device or threadgroup memory.
const Op & ptr_byte_offset()
Cast a handle to a typed pointer after adding a byte offset.
const Op & call_extern()
Call an extern C function with given name and signature from the types of args in the runtime environ...
const Op & tvm_kernel_replace_point()
Marker where a transform should replace generated kernel initialization.
const Op & texture2d_load()
Load from texture 2d memory.
const Op & tvm_warp_activemask()
const Op & tvm_call_packed()
See pesudo code.
const Op & lookup_param()
See pseudo code Type lookup_param(ffi::String param_name) { return __tvm_param__param_name; }.
const Op & continue_loop()
Loop continue.
const Op & prefetch()
same signature as llvm.prefetch
const Op & tvm_struct_set()
See pesudo code.
const Op & selector()
Analysis-only active-thread selector.
const Op & thread_return()
Return from a GPU thread.
const Op & get_active_lane_mask()
Calculate a predicate mask given an upper bound (limit) and a current value (base).
const Op & if_then_else()
Same as select, used for unsafe memory access.
const Op & ret()
Return value.
const Op & end_profile_intrinsic()
Profiling intrinsic.
const Op & call_spirv_pure_glsl450()
Call an SPIRV pure GLSL450 intrinsic.
const Op & bitwise_not()
Bitwise not operator.
const Op & cooperative_tensor_load()
Load data from device or threadgroup memory into a cooperative_tensor.
const Op & tvm_stack_alloca()
See pesudo code.
const Op & break_loop()
Loop break.
const Op & bitwise_and()
Bitwise and operator.
const Op & print_buffer()
Print the content of a buffer during runtime.
const Op & assume()
Provide a true statement that can be used for simplifications.
const Op & large_uint_imm()
See pesudo code.
const Op & tvm_thread_invariant()
Mark a condition to be thread invariant. This means the condition must be the same for all threads.
const Op & start_profile_intrinsic()
Profiling intrinsic.
const Op & handle_add_byte_offset()
See pesudo code.
const Op & call_llvm_pure_intrin()
Call an LLVM pure intrinsic with a given intrinsic id and signature from the types of args in the run...
const Op & filter()
Thread-set filter predicate. Used as the condition of an IfThenElse to narrow the active thread set A...
const Op & tvm_global_barrier_kinit()
Initialize the global barrier. Call this at beginning of kernel that need global barrier.
const Op & fma()
Fused multiply add.
const Op & call_pure_extern()
Call an pure extern C function with given name and signature from the types of args in the runtime en...
const Op & tvm_throw_last_error()
See pesudo code.
const Op & shift_left()
Left shift.
const Op & tvm_warp_shuffle_down()
const Op & dma_start_group()
Start a group of DMA copies.
const Op & dma_copy()
Initiate a non-blocking DMA copy from source to destination.
const Op & tvm_storage_sync()
See pseudo code.
const Op & call_llvm_intrin()
Call an LLVM intrinsic with a given intrinsic id and signature from the types of args in the runtime ...
const Op & likely()
Marks a condition is likely going to happen.
const Op & ignore_loop_partition()
Annotate a predicate not be considered as target condition of loop partition.
const Op & vectorhigh()
Get the high level half of the vector.
const Op & anylist_setitem_call_packed()
Set an item into any list by running packed function call.
const Op & shift_right()
Right shift.
const Op & anylist_getitem()
Get a item from any list and return it.
const Op & cooperative_tensor_fill()
Fill a cooperative_tensor with a given value.
const Op & q_multiply_shift_per_axis()
const Op & tvm_static_handle()
Create a function local static handle that iniitalizes to nullptr. can be used to cache function loca...
const Op & vectorcombine()
Concat two vectors.
const Op & tvm_warp_shuffle_xor()
TVMStructFieldKind
The kind of structure field info used in intrinsic.
Definition: builtin.h:788
@ kDLTensorNDim
Definition: builtin.h:794
@ kTVMFFIAnyUnionValue
Definition: builtin.h:806
@ kTVMFFIAnyTypeIndex
Definition: builtin.h:804
@ kDLTensorDeviceId
Definition: builtin.h:799
@ kDLTensorKindBound_
Definition: builtin.h:801
@ kDLTensorTypeLanes
Definition: builtin.h:797
@ kTVMValueKindBound_
Definition: builtin.h:807
@ kTVMValueContent
Definition: builtin.h:803
@ kDLTensorStrides
Definition: builtin.h:793
@ kDLTensorTypeCode
Definition: builtin.h:795
@ kDLTensorAddr
Definition: builtin.h:790
@ kDLTensorByteOffset
Definition: builtin.h:798
@ kDLTensorShape
Definition: builtin.h:792
@ kInt64ArrayElem
Definition: builtin.h:809
@ kDLTensorDeviceType
Definition: builtin.h:800
@ kTVMFFIAnyZeroPadding
Definition: builtin.h:805
@ kDLTensorData
Definition: builtin.h:791
@ kDLTensorTypeBits
Definition: builtin.h:796
const Op & tvm_stack_make_shape()
Allocate a shape tuple on stack, return the handle.
const Op & isnullptr()
See pesudo code.
const Op & dma_wait()
Wait until the number of DMA groups in flight is less than or equal to some maximum.
const Op & atomic_add()
atomic add instruction, corresponding e.g. to atomicAdd in CUDA
const Op & tvm_struct_get()
See pesudo code.
const Op & reinterpret()
Reinterpret the value using the target type.
const Op & isnan()
Check if value is nan.
const Op & vectorlow()
Get the low-level half of the vector.
const Op & tvm_warp_shuffle()
See pseudo code.
const Op & anylist_resetitem()
Reset and clear a item in any list.
const Op & popcount()
Popcount.
const Op & nd_mem_alloc_with_scope()
Create an Nd memory allocation with storage scope.
const Op & bitwise_or()
Bitwise or operator.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition: analyzer.h:40
TIR expressions.