masahi commented on a change in pull request #8672:
URL: https://github.com/apache/tvm/pull/8672#discussion_r684107862



##########
File path: src/runtime/contrib/sort/sort.cc
##########
@@ -153,27 +174,29 @@ void sort_impl(DLTensor* input, DLTensor* output, int32_t 
axis, bool is_ascend,
       } else {
         std::stable_sort(sorter.begin(), sorter.end(), 
CompareDescend<DataType>);
       }
-      if (is_argsort) {
-        for (int64_t k = 0; k < input->shape[axis]; ++k) {
-          out_ptr[base_idx + k * axis_mul_after] = 
static_cast<OutType>(sorter[k].first);
-        }
-      } else {
-        for (int64_t k = 0; k < input->shape[axis]; ++k) {
-          out_ptr[base_idx + k * axis_mul_after] = 
static_cast<OutType>(sorter[k].second);
-        }
+      for (int64_t k = 0; k < input->shape[axis]; ++k) {
+        epilogue(out_ptr, base_idx + k * axis_mul_after, sorter[k]);

Review comment:
       This change is add so that there is no need to instantiate 
`static_cast<OutType>(sorter[k].first)` for `sort`, where `is_argsort = false`, 
`OutType = DataType = float16`. Without this change, the compiler requires the 
cast from `int64_t` to `float16` be implemented for `is_argsort = true` path, 
even though this path never hits for normal `sort`. Alternatively, when c++ 17 
becomes available, `if constexpr (is_argsort)` can also be used.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to