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.

Header hpx/compute/host.hpp

Header hpx/compute/host/block_allocator.hpp

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::parallel::execution::parallel_policy_shim<block_executor<Executor>, block_executor<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::parallel::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

Header hpx/compute/host/block_executor.hpp

template<typename Executor>
struct executor_execution_category<compute::host::block_executor<Executor>>
#include <block_executor.hpp>

Public Types

typedef parallel::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

typedef hpx::parallel::execution::static_chunk_size executor_parameters_type

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>>
#include <block_executor.hpp>

Public Types

typedef parallel::execution::parallel_execution_tag type

Header hpx/compute/host/get_targets.hpp

namespace hpx
namespace compute
namespace host

Functions

std::vector<target> get_local_targets()
hpx::future<std::vector<target>> get_targets(hpx::id_type const &locality)

Header hpx/compute/host/numa_allocator.hpp

namespace hpx
namespace parallel
namespace util
template<typename T, typename Executors>
class numa_allocator
#include <numa_allocator.hpp>

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, typename std::allocator<void>::const_pointer = 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
#include <numa_allocator.hpp>

Public Types

template<>
typedef numa_allocator<U, Executors> other

Header hpx/compute/host/numa_binding_allocator.hpp

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

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 const T *const_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

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
#include <numa_binding_allocator.hpp>

Public Types

template<>
typedef numa_binding_allocator<U> other
template<typename T>
struct numa_binding_helper
#include <numa_binding_allocator.hpp>

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 axis) const
virtual std::size_t memory_step(std::size_t axis) const
virtual std::size_t display_step(std::size_t axis) 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>
#include <numa_binding_allocator.hpp>

Public Functions

int operator()(int const &domain) const

Header hpx/compute/host/numa_domains.hpp

namespace hpx
namespace compute
namespace host

Functions

std::vector<target> numa_domains()

Header hpx/compute/host/target.hpp

namespace hpx
namespace compute
namespace host
struct target
#include <target.hpp>

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()
static hpx::future<std::vector<target>> get_targets(hpx::id_type const &locality)

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
#include <target.hpp>

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

Header hpx/compute/host/target_distribution_policy.hpp

Header hpx/compute/host/traits/access_target.hpp

template<>
struct access_target<host::target>
#include <access_target.hpp>

Public Types

typedef host::target target_type

Public Static Functions

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

Public Types

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

Public Static Functions

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

Public Types

typedef host::target target_type

Public Static Functions

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

Public Types

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

Public Static Functions

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

Header hpx/compute/serialization/vector.hpp

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)

Header hpx/compute/traits.hpp

Header hpx/compute/traits/access_target.hpp

Header hpx/compute/traits/allocator_traits.hpp

namespace hpx
namespace compute
namespace traits
template<typename Allocator>
struct allocator_traits : public std::allocator_traits<Allocator>
#include <allocator_traits.hpp>

Public Types

typedef detail::get_reference_type<Allocator>::type reference
typedef detail::get_const_reference_type<Allocator>::type const_reference
typedef detail::get_target_traits<Allocator>::type access_target
typedef access_target::target_type 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

typedef std::allocator_traits<Allocator> base_type

Header hpx/compute/vector.hpp

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
#include <vector.hpp>

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 size)

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 size, T const &val)

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_