2121
2222from tvm import tir
2323from tvm .target import Target
24- from ..base import analysis
24+ from .. import analysis
2525from .base import AdrenoScheduleRule
26- from .utils import get_texture_storage
26+
27+
28+ def _assert_gpu_target (target : Target ):
29+ if "gpu" not in target .keys :
30+ raise ValueError (f"Expect a GPU target, but got { target } " )
31+
32+
33+ def get_max_threads_per_block (target : Target ) -> int :
34+ _assert_gpu_target (target )
35+ max_threads_per_block = None
36+ for name in ["max_threads_per_block" , "max_num_threads" ]:
37+ if max_threads_per_block is None :
38+ max_threads_per_block = target .attrs .get (name , None )
39+ if max_threads_per_block is None :
40+ max_threads_per_block = 64
41+ return int (max_threads_per_block )
2742
2843
2944# pylint: disable=invalid-name,missing-function-docstring,unused-variable,unused-import
@@ -45,13 +60,13 @@ def schedule_inline_blocks(
4560 remaining_blocks = []
4661 for blk in blocks :
4762 block_info = analysis .get_block_info (sch , blk )
48- if block_info .is_injective () and not block_info .is_data_pad ():
49- if len (block_info . consumers ) == 1 :
63+ if block_info .is_injective () and not block_info .is_data_pad (sch ):
64+ if len (sch . get_consumers ( blk ) ) == 1 :
5065 try :
5166 sch .compute_inline (blk )
5267 except Exception : # pylint: disable=broad-exception-caught
5368 remaining_blocks .append (blk )
54- elif len (block_info . producers ) == 1 :
69+ elif len (sch . get_producers ( blk ) ) == 1 :
5570 inlined_once = False
5671 try :
5772 # Would cause an issue inlining to producer with multiple consumers
@@ -71,34 +86,20 @@ def schedule_inline_blocks(
7186 remaining_blocks .append (blk )
7287 return remaining_blocks
7388
74- @staticmethod
75- def schedule_annotate_storage (sch : tir .Schedule , func = get_texture_storage ):
76- """Annotates intermediate buffers to textures whenever it's possible to do so"""
77- return
78- # pylint: disable=unreachable
79- root_blk = analysis .get_root_block (sch )
80- blocks = sch .get_child_blocks (root_blk )
81-
82- for blk in blocks :
83- block_info = analysis .get_block_info (sch , blk )
84- scope = func (block_info )
85- if scope is not None and len (sch .get_consumers (blk )) > 0 :
86- sch .set_scope (blk , 0 , scope )
87-
8889 @staticmethod
8990 def schedule_default (sch : tir .Schedule , blk : tir .schedule .BlockRV ):
9091 block_info = analysis .get_block_info (sch , blk )
9192
9293 s_loops , r_loops , o_loops = [], [], []
93- v_loop = block_info .write_bufs [0 ].assoc_lps [- 1 ]
94+ v_loop = block_info .write_bufs ( sch ) [0 ].assoc_lps [- 1 ]
9495
9596 for iter_info in block_info .iters :
9697 if sch .get (iter_info .loop_rv ) == sch .get (v_loop ):
9798 continue
9899 {"S" : s_loops , "R" : r_loops , "O" : o_loops }.get (iter_info .kind ).append (iter_info .loop_rv )
99100
100101 iter_vars = analysis .collect_block_iter_vars_used_in_access_region (
101- block_info . block_stmt , block_info .write_bufs [0 ].buf_region .region
102+ sch . get ( blk ) , block_info .write_bufs ( sch ) [0 ].buf_region .region
102103 )
103104 o_outer = [lp for lp in o_loops if sch .get (lp ).var in iter_vars ]
104105 o_inner = [lp for lp in o_loops if sch .get (lp ).var not in iter_vars ]
@@ -114,7 +115,7 @@ def schedule_default(sch: tir.Schedule, blk: tir.schedule.BlockRV):
114115 tgt = Target .current (allow_none = True )
115116
116117 b = sch .fuse (* s_loops )
117- tx_extent = analysis . get_max_threads_per_block (tgt ) if tgt is not None else 256
118+ tx_extent = get_max_threads_per_block (tgt ) if tgt is not None else 256
118119 bx , tx = sch .split (b , [None , tx_extent ])
119120 sch .bind (bx , "blockIdx.x" )
120121 sch .bind (tx , "threadIdx.x" )
@@ -139,7 +140,7 @@ def schedule_fallback(sch):
139140 blk
140141 for blk in blocks
141142 if analysis .get_block_info (sch , blk ).is_reduction ()
142- or analysis .get_block_info (sch , blk ).is_data_pad ()
143+ or analysis .get_block_info (sch , blk ).is_data_pad (sch )
143144 ]
144145 remaining_blocks = [blk for blk in blocks if blk not in schedule_blocks ]
145146
@@ -149,7 +150,6 @@ def schedule_fallback(sch):
149150 # TODO: Analyze unscheduled blocks to schedule instead of relying on remaining
150151 for blk in remaining_blocks :
151152 Fallback .schedule_default (sch , blk )
152- Fallback .schedule_annotate_storage (sch , schedule_blocks + remaining_blocks )
153153
154154 def apply ( # pylint: disable=too-many-locals
155155 self ,
@@ -170,7 +170,7 @@ def apply( # pylint: disable=too-many-locals
170170 return None
171171
172172 block_infos = [analysis .get_block_info (sch , block ) for block in blocks ]
173- if not any ("texture" in block .write_bufs [0 ].get_scope () for block in block_infos ):
173+ if not any ("texture" in block .write_bufs ( sch ) [0 ].get_scope () for block in block_infos ):
174174 return None
175175
176176 Fallback .schedule_fallback (sch )
0 commit comments