(sorted_sequence_buf, values_buf, indices_buf)
| 1120 | ) |
| 1121 | |
| 1122 | def ir(sorted_sequence_buf, values_buf, indices_buf): |
| 1123 | with IRBuilder() as ib: |
| 1124 | sorted_sequence_shape = sorted_sequence_buf.shape |
| 1125 | values_shape = values_buf.shape |
| 1126 | num_search = prod(values_shape) |
| 1127 | search_range = sorted_sequence_shape[-1] |
| 1128 | |
| 1129 | sorted_sequence_ptr = T.buffer_proxy(sorted_sequence_buf) |
| 1130 | values_ptr = T.buffer_proxy(values_buf) |
| 1131 | indices_ptr = T.buffer_proxy(indices_buf) |
| 1132 | |
| 1133 | max_threads = int(tvm.target.Target.current(allow_none=False).attrs["max_num_threads"]) |
| 1134 | nthread_tx = max_threads |
| 1135 | nthread_bx = ceil_div(num_search, nthread_tx) |
| 1136 | tx = te.thread_axis("threadIdx.x") |
| 1137 | bx = te.thread_axis("blockIdx.x") |
| 1138 | with T.frame_scope( |
| 1139 | [ |
| 1140 | T.attr(tx, "thread_extent", nthread_tx), |
| 1141 | T.attr(bx, "thread_extent", nthread_bx), |
| 1142 | ] |
| 1143 | ): |
| 1144 | tid = bx * nthread_tx + tx |
| 1145 | |
| 1146 | with T.If(tid < num_search): |
| 1147 | with T.Then(): |
| 1148 | if len(sorted_sequence_shape) == 1: |
| 1149 | sequence_offset = 0 |
| 1150 | else: |
| 1151 | sequence_id = tid // values_shape[-1] |
| 1152 | sequence_offset = sequence_id * search_range |
| 1153 | |
| 1154 | indices_ptr[tid] = binary_search( |
| 1155 | sequence_offset, |
| 1156 | search_range, |
| 1157 | sorted_sequence_ptr, |
| 1158 | values_ptr[tid], |
| 1159 | right, |
| 1160 | out_dtype, |
| 1161 | ) |
| 1162 | |
| 1163 | return ib.get() |
| 1164 | |
| 1165 | return te.extern( |
| 1166 | values.shape, |
no test coverage detected