compute

The contents of this module can be included with the header hpx/modules/compute.hpp. These headers may be used by user-code but are not guaranteed stable (neither header location nor contents). You are using these at your own risk. If you wish to use non-public functionality from a module we strongly suggest only including the module header hpx/modules/compute.hpp, not the particular header in which the functionality you would like to use is defined. See Public API for a list of names that are part of the public HPX API.

namespace hpx
namespace compute

Functions

template<typename T, typename Allocator>
void swap(vector<T, Allocator> &x, vector<T, Allocator> &y)

Effects: x.swap(y);.

template<typename T, typename Allocator = std::allocator<T>>
class vector

Public Types

typedef T value_type

Member types (FIXME: add reference to std.

typedef Allocator allocator_type
typedef alloc_traits::access_target access_target
typedef std::size_t size_type
typedef std::ptrdiff_t difference_type
typedef alloc_traits::reference reference
typedef alloc_traits::const_reference const_reference
typedef alloc_traits::pointer pointer
typedef alloc_traits::const_pointer const_pointer
typedef detail::iterator<T, Allocator> iterator
typedef detail::iterator<T const, Allocator> const_iterator
typedef detail::reverse_iterator<T, Allocator> reverse_iterator
typedef detail::const_reverse_iterator<T, Allocator> const_reverse_iterator

Public Functions

vector(Allocator const &alloc = Allocator())
vector(size_type count, T const &value, Allocator const &alloc = Allocator())
vector(size_type count, Allocator const &alloc = Allocator())
template<typename InIter, typename Enable = typename std::enable_if<hpx::traits::is_input_iterator<InIter>::value>::type>
vector(InIter first, InIter last, Allocator const &alloc)
vector(vector const &other)
vector(vector const &other, Allocator const &alloc)
vector(vector &&other)
vector(vector &&other, Allocator const &alloc)
vector(std::initializer_list<T> init, Allocator const &alloc)
~vector()
vector &operator=(vector const &other)
vector &operator=(vector &&other)
allocator_type get_allocator() const

Returns the allocator associated with the container.

reference operator[](size_type pos)
const_reference operator[](size_type pos) const
pointer data()

Returns pointer to the underlying array serving as element storage. The pointer is such that range [data(); data() + size()) is always a valid range, even if the container is empty (data() is not dereferenceable in that case).

const_pointer data() const

Returns pointer to the underlying array serving as element storage. The pointer is such that range [data(); data() + size()) is always a valid range, even if the container is empty (data() is not dereferenceable in that case).

T *device_data() const

Returns a raw pointer corresponding to the address of the data allocated on the device.

std::size_t size() const
std::size_t capacity() const
bool empty() const

Returns: size() == 0.

void resize(size_type)

Effects: If size <= size(), equivalent to calling pop_back() size() - size times. If size() < size, appends size - size() default-inserted elements to the sequence.

Requires: T shall be MoveInsertable and DefaultInsertable into *this.

Remarks: If an exception is thrown other than by the move constructor of a non-CopyInsertable T there are no effects.

void resize(size_type, T const&)

Effects: If size <= size(), equivalent to calling pop_back() size() - size times. If size() < size, appends size - size() copies of val to the sequence.

Requires: T shall be CopyInsertable into *this.

Remarks: If an exception is thrown there are no effects.

iterator begin()
iterator end()
const_iterator cbegin() const
const_iterator cend() const
const_iterator begin() const
const_iterator end() const
void swap(vector &other)

Effects: Exchanges the contents and capacity() of *this with that of x.

Complexity: Constant time.

void clear()

Effects: Erases all elements in the range [begin(),end()). Destroys all elements in a. Invalidates all references, pointers, and iterators referring to the elements of a and may invalidate the past-the-end iterator.

Post: a.empty() returns true.

Complexity: Linear.

Private Types

typedef traits::allocator_traits<Allocator> alloc_traits

Private Members

size_type size_
size_type capacity_
allocator_type alloc_
pointer data_
namespace hpx
namespace compute
namespace host
template<typename T, typename Executor = hpx::parallel::execution::restricted_thread_pool_executor>
struct block_allocator : public hpx::compute::host::detail::policy_allocator<T, hpx::execution::parallel_policy_shim<block_executor<hpx::parallel::execution::restricted_thread_pool_executor>, block_executor<hpx::parallel::execution::restricted_thread_pool_executor>::executor_parameters_type>>
#include <block_allocator.hpp>

The block_allocator allocates blocks of memory evenly divided onto the passed vector of targets. This is done by using first touch memory placement.

This allocator can be used to write NUMA aware algorithms:

using allocator_type = hpx::compute::host::block_allocator<int>; using vector_type = hpx::compute::vector<int, allocator_type>;

auto numa_nodes = hpx::compute::host::numa_domains(); std::size_t N = 2048; vector_type v(N, allocator_type(numa_nodes));

Public Types

template<>
using executor_type = block_executor<Executor>
template<>
using executor_parameters_type = typename executor_type::executor_parameters_type
template<>
using policy_type = hpx::execution::parallel_policy_shim<executor_type, executor_parameters_type>
template<>
using base_type = detail::policy_allocator<T, policy_type>
template<>
using target_type = std::vector<host::target>

Public Functions

block_allocator()
block_allocator(target_type const &targets)
block_allocator(target_type &&targets)
target_type const &target() const
template<typename Executor>
struct executor_execution_category<compute::host::block_executor<Executor>>

Public Types

typedef hpx::execution::parallel_execution_tag type
namespace hpx
namespace compute
namespace host
template<typename Executor = hpx::parallel::execution::restricted_thread_pool_executor>
struct block_executor
#include <block_executor.hpp>

The block executor can be used to build NUMA aware programs. It will distribute work evenly across the passed targets

Template Parameters
  • Executor: The underlying executor to use

Public Types

template<>
using executor_parameters_type = hpx::execution::static_chunk_size

Public Functions

block_executor(std::vector<host::target> const &targets, threads::thread_priority priority = threads::thread_priority::high, threads::thread_stacksize stacksize = threads::thread_stacksize::default_, threads::thread_schedule_hint schedulehint = {})
block_executor(std::vector<host::target> &&targets)
block_executor(block_executor const &other)
block_executor(block_executor &&other)
block_executor &operator=(block_executor const &other)
block_executor &operator=(block_executor &&other)
template<typename F, typename ...Ts>
void post(F &&f, Ts&&... ts)
template<typename F, typename ...Ts>
hpx::future<typename hpx::util::detail::invoke_deferred_result<F, Ts...>::type> async_execute(F &&f, Ts&&... ts)
template<typename F, typename ...Ts>
hpx::util::detail::invoke_deferred_result<F, Ts...>::type sync_execute(F &&f, Ts&&... ts)
template<typename F, typename Shape, typename ...Ts>
std::vector<hpx::future<typename parallel::execution::detail::bulk_function_result<F, Shape, Ts...>::type>> bulk_async_execute(F &&f, Shape const &shape, Ts&&... ts)
template<typename F, typename Shape, typename ...Ts>
parallel::execution::detail::bulk_execute_result<F, Shape, Ts...>::type bulk_sync_execute(F &&f, Shape const &shape, Ts&&... ts)
std::vector<host::target> const &targets() const

Private Functions

void init_executors()

Private Members

std::vector<host::target> targets_
std::atomic<std::size_t> current_
std::vector<Executor> executors_
threads::thread_priority priority_ = threads::thread_priority::high
threads::thread_stacksize stacksize_ = threads::thread_stacksize::default_
threads::thread_schedule_hint schedulehint_ = {}
namespace parallel
namespace execution
template<typename Executor>
struct executor_execution_category<compute::host::block_executor<Executor>>

Public Types

typedef hpx::execution::parallel_execution_tag type
namespace hpx
namespace compute
namespace host

Functions

std::vector<target> get_local_targets()
namespace hpx
namespace parallel
namespace util
template<typename T, typename Executors>
class numa_allocator

Public Types

typedef T value_type
typedef value_type *pointer
typedef value_type const *const_pointer
typedef value_type &reference
typedef value_type const &const_reference
typedef std::size_t size_type
typedef std::ptrdiff_t difference_type

Public Functions

numa_allocator(Executors const &executors, hpx::threads::topology &topo)
numa_allocator(numa_allocator const &rhs)
template<typename U>
numa_allocator(numa_allocator<U, Executors> const &rhs)
pointer address(reference r)
const_pointer address(const_reference r)
pointer allocate(size_type cnt, const void* = nullptr)
void deallocate(pointer p, size_type cnt)
size_type max_size() const
void construct(pointer p, const T &t)
void destroy(pointer p)

Private Types

typedef Executors::value_type executor_type

Private Members

Executors const &executors_
hpx::threads::topology &topo_

Friends

friend hpx::parallel::util::numa_allocator
bool operator==(numa_allocator const&, numa_allocator const&)
bool operator!=(numa_allocator const &l, numa_allocator const &r)
template<typename U>
struct rebind

Public Types

template<>
typedef numa_allocator<U, Executors> other

Defines

NUMA_BINDING_ALLOCATOR_DEBUG
namespace hpx

Functions

static hpx::debug::enable_print<NUMA_BINDING_ALLOCATOR_DEBUG> hpx::nba_deb("NUM_B_A")
namespace compute
namespace host

Typedefs

template<typename T>
using numa_binding_helper_ptr = std::shared_ptr<numa_binding_helper<T>>
template<typename T>
struct numa_binding_allocator
#include <numa_binding_allocator.hpp>

The numa_binding_allocator allocates memory using a policy based on hwloc flags for memory binding. This allocator can be used to request data that is bound to one or more numa domains via the bitmap mask supplied

Public Types

typedef T value_type
typedef T *pointer
typedef T &reference
typedef T const &const_reference
typedef std::size_t size_type
typedef std::ptrdiff_t difference_type
template<>
using numa_binding_helper_ptr = std::shared_ptr<numa_binding_helper<T>>

Public Functions

numa_binding_allocator()
numa_binding_allocator(threads::hpx_hwloc_membind_policy policy, unsigned int flags)
numa_binding_allocator(numa_binding_helper_ptr bind_func, threads::hpx_hwloc_membind_policy policy, unsigned int flags)
numa_binding_allocator(numa_binding_allocator const &rhs)
template<typename U>
numa_binding_allocator(numa_binding_allocator<U> const &rhs)
numa_binding_allocator(numa_binding_allocator &&rhs)
numa_binding_allocator &operator=(numa_binding_allocator const &rhs)
numa_binding_allocator &operator=(numa_binding_allocator &&rhs)
pointer address(reference x) const
const_pointer address(const_reference x) const
pointer allocate(size_type n)
void deallocate(pointer p, size_type n)
size_type max_size() const
template<class U, class ...A>
void construct(U *const p, A&&... args)
template<class U>
void destroy(U *const p)
int get_numa_domain(void *page)
std::string get_page_numa_domains(void *addr, std::size_t len) const
void initialize_pages(pointer p, size_t n) const
std::string display_binding(pointer p, numa_binding_helper_ptr helper)
template<typename Binder>
std::shared_ptr<Binder> get_binding_helper_cast() const

Public Members

const typedef T* hpx::compute::host::numa_binding_allocator::const_pointer
std::shared_ptr<numa_binding_helper<T>> binding_helper_
threads::hpx_hwloc_membind_policy policy_
unsigned int flags_

Protected Functions

std::vector<threads::hwloc_bitmap_ptr> create_nodesets(threads::hwloc_bitmap_ptr bitmap) const
void touch_pages(pointer p, size_t n, numa_binding_helper_ptr helper, size_type numa_domain, std::vector<threads::hwloc_bitmap_ptr> const &nodesets) const
void bind_pages(pointer p, size_t n, numa_binding_helper_ptr helper, size_type numa_domain, std::vector<threads::hwloc_bitmap_ptr> const &nodesets) const

Private Members

std::mutex init_mutex
template<typename U>
struct rebind

Public Types

template<>
typedef numa_binding_allocator<U> other
template<typename T>
struct numa_binding_helper

Public Functions

virtual std::size_t operator()(const T*const, const T*const, std::size_t const, std::size_t const) const
virtual ~numa_binding_helper()
virtual const std::string &pool_name() const
virtual std::size_t memory_bytes() const
virtual std::size_t array_rank() const
virtual std::size_t array_size(std::size_t) const
virtual std::size_t memory_step(std::size_t) const
virtual std::size_t display_step(std::size_t) const
virtual std::string description() const

Public Members

std::string pool_name_ = "default"
namespace parallel
namespace execution
template<>
struct pool_numa_hint<numa_binding_allocator_tag>

Public Functions

int operator()(int const &domain) const
namespace hpx
namespace compute
namespace host

Functions

std::vector<target> numa_domains()
namespace hpx
namespace compute
namespace host
struct target

Public Functions

target()
target(hpx::threads::mask_type mask)
native_handle_type &native_handle()
native_handle_type const &native_handle() const
std::pair<std::size_t, std::size_t> num_pus() const
void synchronize() const
hpx::future<void> get_future() const

Public Static Functions

static std::vector<target> get_local_targets()

Private Functions

void serialize(serialization::input_archive &ar, const unsigned int)
void serialize(serialization::output_archive &ar, const unsigned int)

Private Members

native_handle_type handle_

Friends

friend hpx::compute::host::hpx::serialization::access
bool operator==(target const &lhs, target const &rhs)
struct native_handle_type

Public Functions

native_handle_type()
native_handle_type(hpx::threads::mask_type mask)
hpx::threads::mask_type &get_device()
hpx::threads::mask_type const &get_device() const

Private Members

hpx::threads::mask_type mask_

Friends

friend hpx::compute::host::target
template<>
struct access_target<host::target>

Public Types

typedef host::target target_type

Public Static Functions

template<typename T>
static T const &read(target_type const&, T const *t)
template<typename T>
static void write(target_type const&, T *dst, T const *src)
template<>
struct access_target<std::vector<host::target>>

Public Types

typedef std::vector<host::target> target_type

Public Static Functions

template<typename T>
static T const &read(target_type const&, T const *t)
template<typename T>
static void write(target_type const&, T *dst, T const *src)
namespace hpx
namespace compute
namespace traits
template<>
struct access_target<host::target>

Public Types

typedef host::target target_type

Public Static Functions

template<typename T>
static T const &read(target_type const&, T const *t)
template<typename T>
static void write(target_type const&, T *dst, T const *src)
template<>
struct access_target<std::vector<host::target>>

Public Types

typedef std::vector<host::target> target_type

Public Static Functions

template<typename T>
static T const &read(target_type const&, T const *t)
template<typename T>
static void write(target_type const&, T *dst, T const *src)
namespace hpx
namespace serialization

Functions

template<typename T, typename Allocator>
void serialize(input_archive &ar, compute::vector<T, Allocator> &v, unsigned)
template<typename T, typename Allocator>
void serialize(output_archive &ar, compute::vector<T, Allocator> const &v, unsigned)
namespace hpx
namespace compute
namespace traits
template<typename Allocator>
struct allocator_traits

Public Types

template<>
using reference = typename detail::get_reference_type<Allocator>::type
template<>
using const_reference = typename detail::get_const_reference_type<Allocator>::type
template<>
using access_target = typename detail::get_target_traits<Allocator>::type
template<>
using target_type = typename access_target::target_type

Public Static Functions

static auto target(Allocator const &alloc)
template<typename ...Ts>
static void bulk_construct(Allocator &alloc, pointer p, size_type count, Ts&&... vs)
static void bulk_destroy(Allocator &alloc, pointer p, size_type count)

Private Types

template<>
using base_type = std::allocator_traits<Allocator>