Skip to content

Commit 827f97e

Browse files
authored
[REFACTOR][TIR] Remove obsolete TIRx builtins (#20463)
## Summary - Remove 14 obsolete TIRx builtins and their dependent lowering, codegen, and Python interfaces. - Use native `Break` and `Continue` statements for loop control; retain `thread_return` for GPU thread exits while function `Return` carries a value. - Keep independent runtime DMA APIs and live synchronization paths. Reject unsupported global storage synchronization explicitly.
1 parent c584f23 commit 827f97e

49 files changed

Lines changed: 214 additions & 2131 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎cmake/modules/Hexagon.cmake‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -298,14 +298,10 @@ if(USE_HEXAGON_RPC)
298298
# TODO(masahi): Remove rpc_local_session.cc after verifying that things work without it
299299
"${TVM_CORE_RUNTIME_SOURCE_DIR}/rpc/rpc_local_session.cc"
300300
)
301-
set(HEXAGON_PROFILER_DIR "${TVMRT_SOURCE_DIR}/profiler")
302301
# Add the hardware-specific RPC code into the skel library.
303-
set_property(SOURCE ${HEXAGON_PROFILER_DIR}/lwp_handler.S PROPERTY LANGUAGE C)
304302
add_library(hexagon_rpc_skel SHARED
305303
"${TVMRT_SOURCE_DIR}/rpc/hexagon/rpc_server.cc"
306304
"${TVMRT_SOURCE_DIR}/rpc/hexagon_rpc_skel.c"
307-
"${HEXAGON_PROFILER_DIR}/prof_utils.cc"
308-
"${HEXAGON_PROFILER_DIR}/lwp_handler.S"
309305
)
310306
target_include_directories(hexagon_rpc_skel
311307
SYSTEM PRIVATE "${TVMRT_SOURCE_DIR}/rpc"
@@ -314,8 +310,6 @@ if(USE_HEXAGON_RPC)
314310
# executed via run_main_on_sim.
315311
add_library(hexagon_rpc_sim SHARED
316312
"${TVMRT_SOURCE_DIR}/rpc/simulator/rpc_server.cc"
317-
"${HEXAGON_PROFILER_DIR}/prof_utils.cc"
318-
"${HEXAGON_PROFILER_DIR}/lwp_handler.S"
319313
)
320314
target_link_libraries(hexagon_rpc_sim
321315
-Wl,--whole-archive tvm_runtime -Wl,--no-whole-archive

‎include/tvm/runtime/device_api.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,6 @@ TVM_RUNTIME_DLL bool RuntimeEnabled(const ffi::String& target);
417417

418418
/*! \brief namespace for constant symbols */
419419
namespace symbol {
420-
constexpr const char* tvm_global_barrier_state = "__tvm_global_barrier_state";
421420
/*! \brief global function to set device */
422421
constexpr const char* tvm_set_device = "__tvm_set_device";
423422
} // namespace symbol

‎include/tvm/s_tir/stmt.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,9 @@ constexpr const char* manifest_shared_memory_local_stage =
336336

337337
/*!
338338
* \brief Mark alignment of buffer dimension
339-
* stmt.node is Tensor
340-
* stmt.value is tvm_tuple(dim, align, offset)
341-
* This gives hint to require stride of dim to be k * align + offset.
339+
* The annotation value is an array of explicit tuples
340+
* (buffer_index, axis, factor, offset).
341+
* This requires the stride of an axis to be k * factor + offset.
342342
*/
343343
constexpr const char* buffer_dim_align = "buffer_dim_align";
344344

‎include/tvm/s_tir/transform.h‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,6 @@ TVM_DLL Pass InstrumentBoundCheckers();
295295
*/
296296
TVM_DLL Pass InjectPTXLDG32(bool enable_inject = true);
297297

298-
/*!
299-
* \brief Insert intrinsic calls to instrument function and loop level profiling.
300-
* \return The pass.
301-
*/
302-
TVM_DLL Pass InstrumentProfileIntrinsics();
303-
304298
/*!
305299
* \brief Lower VTCM allocations.
306300
* \return The pass.
@@ -326,12 +320,6 @@ TVM_DLL Pass InferFragment();
326320
*/
327321
TVM_DLL Pass LowerThreadAllreduce();
328322

329-
/*!
330-
* \brief Lower Async TIR primitives to DMA copy and wait builtins.
331-
* \return The pass.
332-
*/
333-
TVM_DLL Pass LowerAsyncDMA();
334-
335323
/*!
336324
* \brief Rewrite global to shared memory copy on CUDA with asynchronous copy.
337325
* \return The pass.

‎include/tvm/tirx/builtin.h‎

Lines changed: 1 addition & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,9 @@ namespace tirx {
4242
/*! \brief Collection of builtin intrinsics as ops */
4343
namespace builtin {
4444
/*!
45-
* \brief Return from a GPU thread.
45+
* \brief Return from a GPU thread without returning a function value.
4646
*/
4747
TVM_DLL const Op& thread_return();
48-
/*!
49-
* \brief Loop continue.
50-
*/
51-
TVM_DLL const Op& continue_loop();
52-
/*!
53-
* \brief Loop break.
54-
*/
55-
TVM_DLL const Op& break_loop();
5648
/*!
5749
* \brief Reinterpret the value using the target type.
5850
*/
@@ -230,21 +222,6 @@ TVM_DLL const Op& ptr_byte_offset();
230222
*/
231223
TVM_DLL const Op& tvm_static_handle();
232224

233-
/*!
234-
* \brief Return a unique context id, used for hint of workspace separation.
235-
* Different context id ganrantees not having overlapping workspace.
236-
*/
237-
TVM_DLL const Op& tvm_context_id();
238-
239-
/*!
240-
* \brief tvm_tuple is not an actual function and cannot codegen.
241-
* It is used to represent tuple structure in value field of AttrStmt,
242-
* for the sake of giving hint to optimization.
243-
*
244-
* void tvm_tuple(value0, value1, ..., value_n);
245-
*/
246-
TVM_DLL const Op& tvm_tuple();
247-
248225
/*!
249226
* \brief See pesudo code
250227
*
@@ -274,14 +251,6 @@ TVM_DLL const Op& tvm_struct_get();
274251
*/
275252
TVM_DLL const Op& tvm_struct_set();
276253

277-
/*!
278-
* \brief See pseudo code
279-
* Type lookup_param(ffi::String param_name) {
280-
* return __tvm_param__param_name;
281-
* }
282-
*/
283-
TVM_DLL const Op& lookup_param();
284-
285254
/*!
286255
* \brief See pesudo code
287256
*
@@ -378,19 +347,6 @@ TVM_DLL const Op& tensormap_encode_tiled();
378347
*/
379348
TVM_DLL const Op& tvm_call_cpacked();
380349

381-
/*!
382-
* \brief See pesudo code
383-
*
384-
* return_type tvm_call_trace_packed(name, TVMFFIAny* args) {
385-
* ModuleNode* env = GetCurrentEnv();
386-
* const ffi::Function* f = env->GetFuncFromEnv(name);
387-
* (*f)(args, args, len(args));
388-
* // return type can be int, float, handle.
389-
* return cast(return_type, result);
390-
* }
391-
*/
392-
TVM_DLL const Op& tvm_call_trace_packed();
393-
394350
/*!
395351
* \brief Mark a condition to be thread invariant.
396352
* This means the condition must be the same for all threads.
@@ -430,25 +386,6 @@ TVM_DLL const Op& tvm_call_packed_lowered();
430386
*/
431387
TVM_DLL const Op& tvm_call_cpacked_lowered();
432388

433-
/*!
434-
* \brief Lowered version of trace intrinsic, the space of value and
435-
* type codes are explicitly allocated. The return value is the
436-
* (end - 1) value on the stack.
437-
*
438-
* return_type tvm_call_trace_packed_lowered(name,
439-
* TVMFFIAny* args_stack,
440-
* int begin,
441-
* int end) {
442-
* ModuleNode* env = GetCurrentEnv();
443-
* const ffi::Function* f = env->GetFuncFromEnv(name);
444-
* f->CallPacked(ffi::PackedArgs(args_stack[begin:end]),
445-
* ffi::Any(args_stack + end));
446-
* // return type can be int, float, handle.
447-
* return cast(return_type, load_return_from(args_stack + end))
448-
* }
449-
*/
450-
TVM_DLL const Op& tvm_call_trace_packed_lowered();
451-
452389
/*!
453390
* \brief See pseudo code
454391
*
@@ -501,12 +438,6 @@ TVM_DLL const Op& tvm_warp_shuffle_down();
501438
TVM_DLL const Op& tvm_warp_shuffle_xor();
502439
TVM_DLL const Op& tvm_warp_activemask();
503440

504-
/*!
505-
* \brief Initialize the global barrier.
506-
* Call this at beginning of kernel that need global barrier.
507-
*/
508-
TVM_DLL const Op& tvm_global_barrier_kinit();
509-
510441
/*!
511442
* \brief See pesudo code
512443
*
@@ -604,51 +535,6 @@ TVM_DLL const Op& texture2d_store();
604535
*/
605536
TVM_DLL const Op& texture2d_load();
606537

607-
/*!
608-
* \brief Initiate a non-blocking DMA copy from source to destination
609-
*
610-
* The copy is launched immediately.
611-
*
612-
* If a `dma_start_group()` call is active, the copy will be added
613-
* to the current group for tracking of in-flight group counts.
614-
*
615-
* If no `dma_start_group()` call is active, the copy will be tracked
616-
* individually i.e. as a group with size 1.
617-
*/
618-
TVM_DLL const Op& dma_copy();
619-
620-
/*!
621-
* \brief Wait until the number of DMA groups in flight is less than
622-
* or equal to some maximum
623-
*
624-
* Calling `dma_wait()` while a group is active is unsupported.
625-
*/
626-
TVM_DLL const Op& dma_wait();
627-
628-
/*!
629-
* \brief Start a group of DMA copies
630-
*
631-
* Any call to `dma_copy()` that occurs after `dma_start_group()` will
632-
* be added to the current group for tracking of in-flight group counts.
633-
*
634-
* Only one DMA group may be active at a given time. Calling
635-
* `dma_start_group()` while a group is active is unsupported.
636-
*/
637-
TVM_DLL const Op& dma_start_group();
638-
639-
/*!
640-
* \brief End a group of DMA copies
641-
*
642-
* Track all calls to `dma_copy()` that occurred since the preceding
643-
* `dma_start_group()` as a single group in-flight.
644-
*
645-
* Calling `dma_end_group()` without an active group is unsupported.
646-
*
647-
* Note: A group of DMA calls may be empty, and will still contribute
648-
* to the count of in-flight groups used by `dma_wait()`.
649-
*/
650-
TVM_DLL const Op& dma_end_group();
651-
652538
/*!
653539
* \brief Provide a true statement that can be used for simplifications
654540
*
@@ -666,16 +552,6 @@ TVM_DLL const Op& assume();
666552
*/
667553
TVM_DLL const Op& undef();
668554

669-
/*!
670-
* \brief Profiling intrinsic
671-
*/
672-
TVM_DLL const Op& start_profile_intrinsic();
673-
674-
/*!
675-
* \brief Profiling intrinsic
676-
*/
677-
TVM_DLL const Op& end_profile_intrinsic();
678-
679555
/*!
680556
* \brief Get a item from any list and return it.
681557
*

‎include/tvm/tirx/op.h‎

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,27 +77,13 @@ TVM_DLL Type GetType(const PrimExpr& expr);
7777
TVM_DLL Type GetTypeFromRuntimeDataType(DLDataType dtype);
7878

7979
/*!
80-
* \brief Return from a thread.
80+
* \brief Return from a GPU thread without returning a function value.
8181
*
8282
* \param span The location of this operation in the source.
83-
* \return The return expression.
83+
* \return The thread return expression.
8484
*/
8585
TVM_DLL PrimExpr thread_return(Span span = Span());
8686

87-
/*!
88-
* \brief Continue current loop.
89-
* \param span The location of this operation in the source.
90-
* \return The continue loop expression.
91-
*/
92-
TVM_DLL PrimExpr continue_loop(Span span = Span());
93-
94-
/*!
95-
* \brief Break current loop.
96-
* \param span The location of this operation in the source.
97-
* \return The break loop expression.
98-
*/
99-
TVM_DLL PrimExpr break_loop(Span span = Span());
100-
10187
/*!
10288
* Get the value of infinity.
10389
* \param dtype The primitive type.

‎include/tvm/tirx/script/ir_builder/ir.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,15 @@ tvm::tirx::Stmt Return(Expr value);
274274

275275
/*!
276276
* \brief Create a break statement.
277+
* \return The same statement that was added to the parent frame.
277278
*/
278-
void Break();
279+
tvm::tirx::Stmt Break();
279280

280281
/*!
281282
* \brief Create a continue statement.
283+
* \return The same statement that was added to the parent frame.
282284
*/
283-
void Continue();
285+
tvm::tirx::Stmt Continue();
284286

285287
/*!
286288
* \brief Create an if statement.

‎python/tvm/s_tir/backend/adreno/pipeline.py‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ def _pipeline(mod: tvm.ir.IRModule, _ctx: tvm.transform.PassContext) -> tvm.ir.I
6161
]
6262
if not bool(config.get("tirx.disable_storage_rewrite", False)):
6363
passes.append(tirx.transform.StorageRewrite())
64-
if config.get("tirx.use_async_copy", False):
65-
passes.append(s_tir.transform.LowerAsyncDMA())
6664
passes.extend(
6765
[
6866
s_tir.transform.HoistIfThenElse(),
@@ -80,8 +78,6 @@ def _pipeline(mod: tvm.ir.IRModule, _ctx: tvm.transform.PassContext) -> tvm.ir.I
8078
passes.append(s_tir.transform.InjectPTXLDG32(True))
8179
if not bool(config.get("tirx.disable_cse_tir", False)):
8280
passes.append(tirx.transform.CommonSubexprElim())
83-
if bool(config.get("tirx.instrument_lwp", False)):
84-
passes.append(s_tir.transform.InstrumentProfileIntrinsics())
8581
passes.extend(
8682
[
8783
# Bind the target first so that target-specific attributes are available.

‎python/tvm/s_tir/pipeline.py‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ def _pipeline(mod: tvm.ir.IRModule, _ctx: tvm.transform.PassContext) -> tvm.ir.I
6161
]
6262
if not bool(config.get("tirx.disable_storage_rewrite", False)):
6363
passes.append(tirx.transform.StorageRewrite())
64-
if config.get("tirx.use_async_copy", False):
65-
passes.append(s_tir.transform.LowerAsyncDMA())
6664
passes.extend(
6765
[
6866
s_tir.transform.HoistIfThenElse(),
@@ -80,8 +78,6 @@ def _pipeline(mod: tvm.ir.IRModule, _ctx: tvm.transform.PassContext) -> tvm.ir.I
8078
passes.append(s_tir.transform.InjectPTXLDG32(True))
8179
if not bool(config.get("tirx.disable_cse_tir", False)):
8280
passes.append(tirx.transform.CommonSubexprElim())
83-
if bool(config.get("tirx.instrument_lwp", False)):
84-
passes.append(s_tir.transform.InstrumentProfileIntrinsics())
8581
passes.extend(
8682
[
8783
# Bind the target first so that target-specific attributes are available.

‎python/tvm/s_tir/transform/transform.py‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -342,17 +342,6 @@ def InjectPTXLDG32(enable_inject_ptx_intrin=True):
342342
return _ffi_api.InjectPTXLDG32(enable_inject_ptx_intrin) # type: ignore
343343

344344

345-
def InstrumentProfileIntrinsics():
346-
"""Insert intrinsic calls to instrument function and loop level profiling.
347-
348-
Returns
349-
-------
350-
fpass : tvm.transform.Pass
351-
The result pass
352-
"""
353-
return _ffi_api.InstrumentProfileIntrinsics() # type: ignore
354-
355-
356345
def VerifyVTCMLimit(default_target=None):
357346
"""Verify if the size of the allocated vtcm memory satisfies the limit.
358347
@@ -420,17 +409,6 @@ def LowerThreadAllreduce():
420409
return _ffi_api.LowerThreadAllreduce() # type: ignore
421410

422411

423-
def LowerAsyncDMA():
424-
"""Lower async DMA to DMA.
425-
426-
Returns
427-
-------
428-
fpass : tvm.transform.Pass
429-
The result pass
430-
"""
431-
return _ffi_api.LowerAsyncDMA() # type: ignore
432-
433-
434412
def InjectPTXAsyncCopy():
435413
"""Rewrite global to shared memory copy on CUDA with asynchronous copy.
436414

0 commit comments

Comments
 (0)