Skip to content

Commit

Permalink
going back to serial specific impl
Browse files Browse the repository at this point in the history
move back into __detail namespace

Signed-off-by: Dan Hoeflinger <[email protected]>
  • Loading branch information
danhoeflinger committed Feb 5, 2025
1 parent e716655 commit 798f1ff
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 25 deletions.
24 changes: 15 additions & 9 deletions include/oneapi/dpl/pstl/omp/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
#ifndef _ONEDPL_INTERNAL_OMP_UTIL_H
#define _ONEDPL_INTERNAL_OMP_UTIL_H

#include <iterator> //std::iterator_traits, std::distance
#include <cstddef> //std::size_t
#include <memory> //std::allocator
#include <iterator> //std::iterator_traits, std::distance
#include <cstddef> //std::size_t
#include <memory> //std::allocator
#include <type_traits> // std::decay, is_integral_v, enable_if_t
#include <utility> // std::forward
#include <utility> // std::forward
#include <omp.h>

#include "../parallel_backend_utils.h"
Expand Down Expand Up @@ -150,6 +150,8 @@ __process_chunk(const __chunk_metrics& __metrics, _Iterator __base, _Index __chu
__f(__first, __last);
}

namespace __detail
{
struct __get_num_threads
{
std::size_t
Expand All @@ -167,15 +169,19 @@ struct __get_thread_num
return omp_get_thread_num();
}
};

} // namespace __detail

// enumerable thread local storage should only be created from make function
template <typename _ValueType, typename... Args>
oneapi::dpl::__utils::__enumerable_thread_local_storage<_ValueType, oneapi::dpl::__omp_backend::__get_num_threads,
oneapi::dpl::__omp_backend::__get_thread_num, Args...>
oneapi::dpl::__utils::__detail::__enumerable_thread_local_storage<
_ValueType, oneapi::dpl::__omp_backend::__detail::__get_num_threads,
oneapi::dpl::__omp_backend::__detail::__get_thread_num, Args...>
__make_enumerable_tls(Args&&... __args)
{
return oneapi::dpl::__utils::__enumerable_thread_local_storage<
_ValueType, oneapi::dpl::__omp_backend::__get_num_threads, oneapi::dpl::__omp_backend::__get_thread_num,
Args...>(std::forward<Args>(__args)...);
return oneapi::dpl::__utils::__detail::__enumerable_thread_local_storage<
_ValueType, oneapi::dpl::__omp_backend::__detail::__get_num_threads,
oneapi::dpl::__omp_backend::__detail::__get_thread_num, Args...>(std::forward<Args>(__args)...);
}
} // namespace __omp_backend
} // namespace dpl
Expand Down
53 changes: 42 additions & 11 deletions include/oneapi/dpl/pstl/parallel_backend_serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,48 @@ namespace dpl
namespace __serial_backend
{

namespace __detail
{

template <typename _ValueType>
struct __enumerable_thread_local_storage
{
template <typename... _LocalArgs>
__enumerable_thread_local_storage(_LocalArgs&&... __args) : __storage(std::forward<_LocalArgs>(__args)...)
{
}

std::size_t
size() const
{
return std::size_t{1};
}

_ValueType&
get_for_current_thread()
{
return __storage;
}

_ValueType&
get_with_id(std::size_t /*__i*/)
{
return get_for_current_thread();
}

_ValueType __storage;
};

} //namespace __detail

// enumerable thread local storage should only be created from make function
template <typename _ValueType, typename... Args>
__detail::__enumerable_thread_local_storage<_ValueType>
__make_enumerable_tls(Args&&... __args)
{
return __detail::__enumerable_thread_local_storage<_ValueType>(std::forward<Args>(__args)...);
}

template <typename _ExecutionPolicy, typename _Tp>
using __buffer = oneapi::dpl::__utils::__buffer_impl<std::decay_t<_ExecutionPolicy>, _Tp, std::allocator>;

Expand Down Expand Up @@ -147,17 +189,6 @@ struct __get_thread_num
}
};

// enumerable thread local storage should only be created from make function
template <typename _ValueType, typename... Args>
oneapi::dpl::__utils::__enumerable_thread_local_storage<_ValueType, oneapi::dpl::__serial_backend::__get_num_threads,
oneapi::dpl::__serial_backend::__get_thread_num, Args...>
__make_enumerable_tls(Args&&... __args)
{
return oneapi::dpl::__utils::__enumerable_thread_local_storage<
_ValueType, oneapi::dpl::__serial_backend::__get_num_threads, oneapi::dpl::__serial_backend::__get_thread_num,
Args...>(std::forward<Args>(__args)...);
}

} // namespace __serial_backend
} // namespace dpl
} // namespace oneapi
Expand Down
14 changes: 9 additions & 5 deletions include/oneapi/dpl/pstl/parallel_backend_tbb.h
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,8 @@ __parallel_for_each(oneapi::dpl::__internal::__tbb_backend_tag, _ExecutionPolicy
tbb::this_task_arena::isolate([&]() { tbb::parallel_for_each(__begin, __end, __f); });
}

namespace __detail
{
struct __get_num_threads
{
std::size_t
Expand All @@ -1323,16 +1325,18 @@ struct __get_thread_num
return tbb::this_task_arena::current_thread_index();
}
};
} //namespace __detail

// enumerable thread local storage should only be created from make function
template <typename _ValueType, typename... Args>
oneapi::dpl::__utils::__enumerable_thread_local_storage<_ValueType, oneapi::dpl::__tbb_backend::__get_num_threads,
oneapi::dpl::__tbb_backend::__get_thread_num, Args...>
oneapi::dpl::__utils::__detail::__enumerable_thread_local_storage<
_ValueType, oneapi::dpl::__tbb_backend::__detail::__get_num_threads,
oneapi::dpl::__tbb_backend::__detail::__get_thread_num, Args...>
__make_enumerable_tls(Args&&... __args)
{
return oneapi::dpl::__utils::__enumerable_thread_local_storage<
_ValueType, oneapi::dpl::__tbb_backend::__get_num_threads, oneapi::dpl::__tbb_backend::__get_thread_num,
Args...>(std::forward<Args>(__args)...);
return oneapi::dpl::__utils::__detail::__enumerable_thread_local_storage<
_ValueType, oneapi::dpl::__tbb_backend::__detail::__get_num_threads,
oneapi::dpl::__tbb_backend::__detail::__get_thread_num, Args...>(std::forward<Args>(__args)...);
}

} // namespace __tbb_backend
Expand Down
4 changes: 4 additions & 0 deletions include/oneapi/dpl/pstl/parallel_backend_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ __set_symmetric_difference_construct(_ForwardIterator1 __first1, _ForwardIterato
return __cc_range(__first2, __last2, __result);
}

namespace __detail
{

template <typename _ValueType, typename _GetNumThreads, typename _GetThreadNum, typename... _Args>
struct __enumerable_thread_local_storage
{
Expand Down Expand Up @@ -372,6 +375,7 @@ struct __enumerable_thread_local_storage
std::tuple<_Args...> __args;
};

} // namespace __detail
} // namespace __utils
} // namespace dpl
} // namespace oneapi
Expand Down

0 comments on commit 798f1ff

Please sign in to comment.