MCPcopy Create free account
hub / github.com/apache/tvm / _odd_even_sort

Function _odd_even_sort

python/tvm/topi/gpu/sort.py:85–180  ·  view source on GitHub ↗
(
    size,
    axis_mul_before,
    axis_mul_after,
    is_ascend,
    keys,
    keys_swap,
    values=None,
    values_swap=None,
)

Source from the content-addressed store, hash-verified

83
84
85def _odd_even_sort(
86 size,
87 axis_mul_before,
88 axis_mul_after,
89 is_ascend,
90 keys,
91 keys_swap,
92 values=None,
93 values_swap=None,
94):
95 nthread_tx = block_size // 2
96 nthread_bx = ceil_div(size, block_size)
97 nthread_by = axis_mul_before * axis_mul_after
98
99 tx, bx, by, ntx, nbx, nby = _get_threads(nthread_tx, nthread_bx, nthread_by)
100 with T.frame_scope(
101 [
102 T.attr(tvm.tirx.const(0), "hand_threaded", 0),
103 T.attr(tx, "thread_extent", ntx),
104 T.attr(bx, "thread_extent", nbx),
105 T.attr(by, "thread_extent", nby),
106 ]
107 ):
108 by_val = by % axis_mul_before
109 bz = by // axis_mul_before
110 tid = 2 * tx
111 start = bx * block_size
112
113 # Buffer declarations (DeclBuffer generates both Allocate + DeclBuffer nodes)
114 tmp_keys_swap = T.decl_buffer([block_size], keys_swap.dtype, scope="shared")
115 temp_keys = T.decl_buffer([1], keys_swap.dtype, scope="local")
116 temp_cond1 = T.decl_buffer([1], keys_swap.dtype, scope="local")
117 temp_cond2 = T.decl_buffer([1], keys_swap.dtype, scope="local")
118 if values_swap is not None:
119 tmp_values_swap = T.decl_buffer([block_size], values_swap.dtype, scope="shared")
120 temp_values = T.decl_buffer([1], values_swap.dtype, scope="local")
121
122 # Copy data to scratch space
123 base_idx = by_val * size * axis_mul_after + bz
124 with T.serial(0, 2) as n:
125 with T.If((tid + n + start) < size):
126 with T.Then():
127 T.buffer_store(
128 tmp_keys_swap,
129 keys[base_idx + (tid + n + start) * axis_mul_after],
130 [tid + n],
131 )
132 if values_swap is not None:
133 T.buffer_store(
134 tmp_values_swap,
135 values[base_idx + (tid + n + start) * axis_mul_after],
136 [tid + n],
137 )
138
139 T.evaluate(tvm.tirx.Call(None, "tirx.tvm_storage_sync", tvm.runtime.convert(["shared"])))
140
141 idxm = tvm.tirx.indexmod
142 # OddEvenTransposeSort

Callers 1

_sort_commonFunction · 0.85

Calls 6

ceil_divFunction · 0.85
_get_threadsFunction · 0.85
attrMethod · 0.80
minMethod · 0.80
evaluateMethod · 0.45
convertMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…