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 - creates __base_diagonals_sp_storage_t before the first real usage
  • Loading branch information
SergeyKopienko committed Jan 16, 2025
1 parent e24628f commit f82da46
Showing 1 changed file with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -604,14 +604,11 @@ struct __merge_sort_global_submitter<_IndexT, __internal::__optional_kernel_name
// std::log2 may be prone to rounding errors on some architectures
const std::int64_t __n_iter = sycl::ctz(__n_power2) - sycl::ctz(__leaf_size);

// Create storage to save split-points on each base diagonal + 1 (for the right base diagonal in the last work-group)
const std::size_t __max_base_diags_count = get_max_base_diags_count(__exec, __n_iter, __n, __n_sorted);
auto __p_base_diagonals_sp_global_storage =
new __base_diagonals_sp_storage_t(__exec, 0, __max_base_diags_count);
// Storage to save split-points on each base diagonal + 1 (for the right base diagonal in the last work-group)
__base_diagonals_sp_storage_t* __p_base_diagonals_sp_global_storage = nullptr;

// Save the raw pointer into a shared_ptr to return it in __future and extend the lifetime of the storage.
std::shared_ptr<__result_and_scratch_storage_base> __p_result_and_scratch_storage_base(
static_cast<__result_and_scratch_storage_base*>(__p_base_diagonals_sp_global_storage));
// shared_ptr instance to return it in __future and extend the lifetime of the storage.
std::shared_ptr<__result_and_scratch_storage_base> __p_result_and_scratch_storage_base;

for (std::int64_t __i = 0; __i < __n_iter; ++__i)
{
Expand All @@ -623,6 +620,19 @@ struct __merge_sort_global_submitter<_IndexT, __internal::__optional_kernel_name
}
else
{
if (__p_base_diagonals_sp_global_storage == nullptr)
{
// Create storage to save split-points on each base diagonal + 1 (for the right base diagonal in the last work-group)
const std::size_t __max_base_diags_count =
get_max_base_diags_count(__exec, __n_iter, __n, __n_sorted);
__p_base_diagonals_sp_global_storage =
new __base_diagonals_sp_storage_t(__exec, 0, __max_base_diags_count);

// Save the raw pointer into a shared_ptr to return it in __future and extend the lifetime of the storage.
__p_result_and_scratch_storage_base.reset(
static_cast<__result_and_scratch_storage_base*>(__p_base_diagonals_sp_global_storage));
}

const auto __portions = oneapi::dpl::__internal::__dpl_ceiling_div(__n, 2 * __n_sorted);
const nd_range_params __nd_range_params_this =
eval_nd_range_params(__exec, std::size_t(2 * __n_sorted), __portions);
Expand Down

0 comments on commit f82da46

Please sign in to comment.