oneDPL
oneDPL copied to clipboard
Remove duplicated host buffer implementations from oneDPL code
Now we have only one class __buffer_impl
in oneDPL code and it's renamed to class __buffer_impl_host
:
template <typename _ExecutionPolicy, typename _Tp, typename _TAllocator>
class __buffer_impl_host
{
// ...
};
Also now we can specify which allocator we will use in this buffer through template param _TAllocator
:
- for
serial
andomp
backends it's::std::allocator
; - for
tbb
backend it'stbb::tbb_allocator
.
For support tag dispatching and use different allocators the the host buffer now we use functions __get_buffer_allocator
:
template <typename _T>
constexpr decltype(auto) __get_buffer_allocator(oneapi::dpl::__internal::__serial_backend_tag)
{
return ::std::allocator<_T>{};
}
template <typename _T>
constexpr decltype(auto) __get_buffer_allocator(oneapi::dpl::__internal::__omp_backend_tag)
{
return ::std::allocator<_T>{};
}
template <typename _T>
constexpr decltype(auto) __get_buffer_allocator(oneapi::dpl::__internal::__tbb_backend_tag)
{
return tbb::tbb_allocator<_T>{};
}
This functions also has overload for resolve dispatching tags into buffer allocators:
template <typename _T, typename _IsVector>
constexpr decltype(auto) __get_buffer_allocator(oneapi::dpl::__internal::__serial_tag<_IsVector>)
{
return oneapi::dpl::__internal::__get_buffer_allocator<_T>(oneapi::dpl::__internal::__serial_backend_tag{});
}
template <typename _T, typename _IsVector>
constexpr decltype(auto) __get_buffer_allocator(oneapi::dpl::__internal::__parallel_tag<_IsVector>)
{
using __backend_tag = typename oneapi::dpl::__internal::__parallel_tag<_IsVector>::__backend_tag;
return oneapi::dpl::__internal::__get_buffer_allocator<_T>(__backend_tag{});
}
template <typename _T>
constexpr decltype(auto) __get_buffer_allocator(oneapi::dpl::__internal::__parallel_forward_tag)
{
using __backend_tag = typename oneapi::dpl::__internal::__parallel_forward_tag::__backend_tag;
return oneapi::dpl::__internal::__get_buffer_allocator<_T>(__backend_tag{});
}
As result now we able too use right host buffer allocator depends on backend tag or dispatch tag:
template <typename _BackendOrDispatchTag, typename _ExecutionPolicy, typename _Tp,
typename _TAllocator =
decltype(oneapi::dpl::__internal::__get_buffer_allocator<_Tp>(::std::declval<_BackendOrDispatchTag>()))>
using __buffer = oneapi::dpl::__utils::__buffer_impl_host<::std::decay_t<_ExecutionPolicy>, _Tp, _TAllocator>;