40 #ifndef DISTRIBUTIONS_H_
41 #define DISTRIBUTIONS_H_
45 #include "detail/Distribution.h"
46 #include "detail/BlockDistribution.h"
47 #include "detail/OLDistribution.h"
48 #include "detail/CopyDistribution.h"
49 #include "detail/SingleDistribution.h"
55 namespace detail {
class Device; }
64 namespace distribution {
92 template <
template <
typename>
class C,
typename T>
93 std::unique_ptr<skelcl::detail::Distribution<C<T>>>
97 return std::unique_ptr<skelcl::detail::Distribution<C<T>>>(
98 new skelcl::detail::BlockDistribution<C<T>>() );
113 template <
template <
typename>
class C,
typename T>
116 c.setDistribution( std::unique_ptr<skelcl::detail::Distribution<C<T>>>(
117 new skelcl::detail::BlockDistribution<C<T>>() ) );
136 template <
template <
typename>
class C,
typename T>
137 std::unique_ptr<skelcl::detail::Distribution<C<T>>>
141 return std::unique_ptr<skelcl::detail::Distribution<C<T>>>(
142 new skelcl::detail::OLDistribution<C<T>>() );
157 template <
template <
typename>
class C,
typename T>
160 c.setDistribution( std::unique_ptr<skelcl::detail::Distribution<C<T>>>(
161 new skelcl::detail::OLDistribution<C<T>>() ) );
184 template <
template <
typename>
class C,
typename T>
185 std::unique_ptr<skelcl::detail::Distribution<C<T>>>
187 typename identity<std::function<T(
const T&,
const T&)>>::type
188 combineFunc =
nullptr )
191 return std::unique_ptr<skelcl::detail::Distribution<C<T>>>(
192 new skelcl::detail::CopyDistribution<C<T>>(
193 detail::globalDeviceList, combineFunc ) );
212 template <
template <
typename>
class C,
typename T>
214 std::function<T(
const T&,
const T&)> combineFunc =
nullptr)
216 c.setDistribution( std::unique_ptr<skelcl::detail::Distribution<C<T>>>(
217 new skelcl::detail::CopyDistribution<C<T>>(
218 detail::globalDeviceList, combineFunc ) ) );
237 template <
template <
typename>
class C,
typename T>
238 std::unique_ptr<skelcl::detail::Distribution<C<T>>>
242 return std::unique_ptr<skelcl::detail::Distribution<C<T>>>(
243 new skelcl::detail::SingleDistribution<C<T>>() );
263 template <
template <
typename>
class C,
typename T>
264 std::unique_ptr<skelcl::detail::Distribution<C<T>>>
266 const std::shared_ptr<skelcl::detail::Device>&
device )
269 return std::unique_ptr<skelcl::detail::Distribution<C<T>>>(
270 new skelcl::detail::SingleDistribution<C<T>>(
device) );
285 template <
template <
typename>
class C,
typename T>
288 c.setDistribution( std::unique_ptr<skelcl::detail::Distribution<C<T>>>(
289 new skelcl::detail::SingleDistribution<C<T>>() ) );
305 template <
template <
typename>
class C,
typename T>
307 const std::shared_ptr<skelcl::detail::Device>&
device )
309 c.setDistribution( std::unique_ptr<skelcl::detail::Distribution<C<T>>>(
310 new skelcl::detail::SingleDistribution<C<T>>(device) ) );
326 template <
typename T,
typename U,
template <
typename>
class C>
327 std::unique_ptr<Distribution<C<T>>>
328 cloneAndConvert(
const Distribution<C<U>>& dist)
331 auto block =
dynamic_cast<const BlockDistribution<C<U>
>*>(&dist);
332 if (block !=
nullptr) {
333 return std::unique_ptr<Distribution<C<T>>>(
334 new BlockDistribution<C<T>>(*block) );
338 auto copy =
dynamic_cast<const CopyDistribution<C<U>
>*>(&dist);
339 if (copy !=
nullptr) {
340 return std::unique_ptr<Distribution<C<T>>>(
341 new CopyDistribution<C<T>>(*copy) );
345 auto single =
dynamic_cast<const SingleDistribution<C<U>
>*>(&dist);
346 if (single !=
nullptr) {
347 return std::unique_ptr<Distribution<C<T>>>(
348 new SingleDistribution<C<T>>(*single) );
352 auto ol =
dynamic_cast<const OLDistribution<C<U>
>*>(&dist);
354 return std::unique_ptr<Distribution<C<T>>>(
355 new OLDistribution<C<T>>(*ol) );
359 return std::unique_ptr<Distribution<C<T>>>(
360 new Distribution<C<T>>(dist) );
365 template <
typename OutT,
typename InT>
366 std::unique_ptr<Distribution<OutT>>
367 cloneAndConvert(
const Distribution<InT>& dist)
370 auto block =
dynamic_cast<const BlockDistribution<InT>*
>(&dist);
371 if (block !=
nullptr) {
372 return std::unique_ptr<Distribution<OutT>>(
373 new BlockDistribution<OutT>(*block));
377 auto copy =
dynamic_cast<const CopyDistribution<InT>*
>(&dist);
378 if (copy !=
nullptr) {
379 return std::unique_ptr<Distribution<OutT>>(
380 new CopyDistribution<OutT>(*copy));
384 auto single =
dynamic_cast<const SingleDistribution<InT>*
>(&dist);
385 if (single !=
nullptr) {
386 return std::unique_ptr<Distribution<OutT>>(
387 new SingleDistribution<OutT>(*single));
391 auto ol =
dynamic_cast<const OLDistribution<InT>*
>(&dist);
393 return std::unique_ptr<Distribution<OutT>>(
394 new OLDistribution<OutT>(*ol));
398 return std::unique_ptr<Distribution<OutT>>(
399 new Distribution<OutT>(dist));
408 #endif // DISTRIBUTIONS_H_
void setSingle(const C< T > &c)
This function sets the distribution of the given container to the SingleDistribution using the defaul...
std::unique_ptr< skelcl::detail::Distribution< C< T > > > OL(const C< T > &c)
Factory function to create an OverlapDistribution with the types of the given container.
void setOL(const C< T > &c)
This function sets the distribution of the given container to the OverlapDistribution.
SKELCL_DLL detail::DeviceID device(size_t dID)
Creates an OpenCL device ID to be used as parameter of the init(detail::PlatformID, detail::DeviceID) function.
std::unique_ptr< skelcl::detail::Distribution< C< T > > > Block(const C< T > &c)
Factory function to create a BlockDistribution with the types of the given container.
void setBlock(const C< T > &c)
This function sets the distribution of the given container to the BlockDistribution.
std::unique_ptr< skelcl::detail::Distribution< C< T > > > Copy(const C< T > &c, typename identity< std::function< T(const T &, const T &)>>::type combineFunc=nullptr)
Factory function to create a CopyDistribution with the types of the given container.
void setCopy(const C< T > &c, std::function< T(const T &, const T &)> combineFunc=nullptr)
This function sets the distribution of the given container to the CopyDistribution.
std::unique_ptr< skelcl::detail::Distribution< C< T > > > Single(const C< T > &c)
Factory function to create a SingleDistribution with the types of the given container and for the def...