Skip to content

Commit

Permalink
include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl_merge_sort…
Browse files Browse the repository at this point in the history
….h - avoid if statement inside Kernel's code

Signed-off-by: Sergey Kopienko <[email protected]>
  • Loading branch information
SergeyKopienko committed Dec 23, 2024
1 parent c58325a commit cb89d6e
Showing 1 changed file with 22 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,13 @@ struct __subgroup_bubble_sorter
void
sort(const _StorageAcc& __storage_acc, _Compare __comp, std::uint32_t __start, std::uint32_t __end) const
{
using std::swap;

for (std::uint32_t i = __start; i < __end; ++i)
{
for (std::uint32_t j = __start + 1; j < __start + __end - i; ++j)
{
if (__comp(__storage_acc[j], __storage_acc[j - 1]))
{
using std::swap;
swap(__storage_acc[j - 1], __storage_acc[j]);
}
__comp(__storage_acc[j], __storage_acc[j - 1]) ? swap(__storage_acc[j - 1], __storage_acc[j]) : void();
}
}
}
Expand Down Expand Up @@ -485,23 +483,12 @@ struct __merge_sort_global_submitter<_IndexT, __internal::__optional_kernel_name
const std::size_t __linear_id = __item_id.get_linear_id();

const WorkDataArea __data_area(__n, __n_sorted, __linear_id, __nd_range_params.chunk);
if (__data_area.is_i_elem_local_inside_merge_matrix())
{
if (__data_in_temp)
{
DropViews __views(__dst, __data_area);

const auto __sp = __find_start_point_w(__data_area, __views, __comp);
__serial_merge_w(__nd_range_params, __data_area, __views, __rng, __sp, __comp);
}
else
{
DropViews __views(__rng, __data_area);

const auto __sp = __find_start_point_w(__data_area, __views, __comp);
__serial_merge_w(__nd_range_params, __data_area, __views, __dst, __sp, __comp);
}
}

__data_area.is_i_elem_local_inside_merge_matrix()
? (__data_in_temp
? __serial_merge_w(__nd_range_params, __data_area, DropViews(__dst, __data_area), __rng, __find_start_point_w(__data_area, DropViews(__dst, __data_area), __comp), __comp)
: __serial_merge_w(__nd_range_params, __data_area, DropViews(__rng, __data_area), __dst, __find_start_point_w(__data_area, DropViews(__rng, __data_area), __comp), __comp))
: void();
});
});
}
Expand Down Expand Up @@ -535,27 +522,19 @@ struct __merge_sort_global_submitter<_IndexT, __internal::__optional_kernel_name

const WorkDataArea __data_area(__n, __n_sorted, __linear_id, __nd_range_params.chunk);

if (__data_area.is_i_elem_local_inside_merge_matrix())
{
if (__data_in_temp)
{
DropViews __views(__dst, __data_area);

const auto __sp =
__lookup_sp(__linear_id /* __linear_id_in_steps_range */, __nd_range_params,
__data_area, __views, __comp, __base_diagonals_sp_global_ptr);
__serial_merge_w(__nd_range_params, __data_area, __views, __rng, __sp, __comp);
}
else
{
DropViews __views(__rng, __data_area);

const auto __sp =
__lookup_sp(__linear_id /* __linear_id_in_steps_range */, __nd_range_params,
__data_area, __views, __comp, __base_diagonals_sp_global_ptr);
__serial_merge_w(__nd_range_params, __data_area, __views, __dst, __sp, __comp);
}
}
__data_area.is_i_elem_local_inside_merge_matrix()
? (__data_in_temp
? __serial_merge_w(__nd_range_params, __data_area, DropViews(__dst, __data_area), __rng,
__lookup_sp(__linear_id, __nd_range_params, __data_area,
DropViews(__dst, __data_area), __comp,
__base_diagonals_sp_global_ptr),
__comp)
: __serial_merge_w(__nd_range_params, __data_area, DropViews(__rng, __data_area), __dst,
__lookup_sp(__linear_id, __nd_range_params, __data_area,
DropViews(__rng, __data_area), __comp,
__base_diagonals_sp_global_ptr),
__comp))
: void();
});
});
}
Expand Down

0 comments on commit cb89d6e

Please sign in to comment.