HCC
HCC is a single-source, C/C++ compiler for heterogeneous computing. It's optimized with HSA (http://www.hsafoundation.com/).
Public Member Functions | Friends | List of all members
hc::completion_future Class Reference

This class is the return type of all asynchronous APIs and has an interface analogous to std::shared_future<void>. More...

#include <hc.hpp>

Collaboration diagram for hc::completion_future:
Collaboration graph

Public Member Functions

 completion_future ()
 Default constructor. More...
 
 completion_future (const completion_future &other)
 Copy constructor. More...
 
 completion_future (completion_future &&other)
 Move constructor. More...
 
completion_futureoperator= (const completion_future &_Other)
 Copy assignment. More...
 
completion_futureoperator= (completion_future &&_Other)
 Move assignment. More...
 
void get () const
 This method is functionally identical to std::shared_future<void>::get. More...
 
bool valid () const
 This method is functionally identical to std::shared_future<void>::valid. More...
 
 operator std::shared_future< void > () const
 Conversion operator to std::shared_future<void>. More...
 
template<typename functor >
void then (const functor &func)
 This method enables specification of a completion callback func which is executed upon completion of the asynchronous operation associated with this completion_future object. More...
 
void * get_native_handle () const
 Get the native handle for the asynchronous operation encapsulated in this completion_future object. More...
 
uint64_t get_begin_tick ()
 Get the tick number when the underlying asynchronous operation begins. More...
 
uint64_t get_end_tick ()
 Get the tick number when the underlying asynchronous operation ends. More...
 
uint64_t get_tick_frequency ()
 Get the frequency of ticks per second for the underlying asynchrnous operation. More...
 
bool is_ready ()
 Get if the async operations has been completed. More...
 
int get_use_count () const
 
void wait (hcWaitMode mode=hcWaitModeBlocked) const
 These methods are functionally identical to the corresponding std::shared_future<void> methods. More...
 
template<class _Rep , class _Period >
std::future_status wait_for (const std::chrono::duration< _Rep, _Period > &_Rel_time) const
 These methods are functionally identical to the corresponding std::shared_future<void> methods. More...
 
template<class _Clock , class _Duration >
std::future_status wait_until (const std::chrono::time_point< _Clock, _Duration > &_Abs_time) const
 These methods are functionally identical to the corresponding std::shared_future<void> methods. More...
 

Friends

class Kalmar::HSAQueue
 
template<typename T , int N>
class array_view
 
class accelerator_view
 
template<int N, typename Kernel >
completion_future parallel_for_each (const accelerator_view &, const extent< N > &, const Kernel &)
 
template<typename Kernel >
completion_future parallel_for_each (const accelerator_view &, const extent< 1 > &, const Kernel &)
 
template<typename Kernel >
completion_future parallel_for_each (const accelerator_view &, const extent< 2 > &, const Kernel &)
 
template<typename Kernel >
completion_future parallel_for_each (const accelerator_view &, const extent< 3 > &, const Kernel &)
 
template<typename Kernel >
completion_future parallel_for_each (const accelerator_view &, const tiled_extent< 3 > &, const Kernel &)
 
template<typename Kernel >
completion_future parallel_for_each (const accelerator_view &, const tiled_extent< 2 > &, const Kernel &)
 
template<typename Kernel >
completion_future parallel_for_each (const accelerator_view &, const tiled_extent< 1 > &, const Kernel &)
 
template<typename T , int N>
completion_future copy_async (const array_view< const T, N > &src, const array_view< T, N > &dest)
 The contents of "src" are copied into "dest". More...
 
template<typename T , int N>
completion_future copy_async (const array< T, N > &src, array< T, N > &dest)
 The contents of "src" are copied into "dest". More...
 
template<typename T , int N>
completion_future copy_async (const array< T, N > &src, const array_view< T, N > &dest)
 The contents of "src" are copied into "dest". More...
 
template<typename T , int N>
completion_future copy_async (const array_view< T, N > &src, const array_view< T, N > &dest)
 
template<typename T , int N>
completion_future copy_async (const array_view< const T, N > &src, array< T, N > &dest)
 The contents of "src" are copied into "dest". More...
 
template<typename InputIter , typename T , int N>
completion_future copy_async (InputIter srcBegin, InputIter srcEnd, array< T, N > &dest)
 The contents of a source container from the iterator range [srcBegin,srcEnd) are copied into "dest". More...
 
template<typename InputIter , typename T , int N>
completion_future copy_async (InputIter srcBegin, InputIter srcEnd, const array_view< T, N > &dest)
 The contents of a source container from the iterator range [srcBegin,srcEnd) are copied into "dest". More...
 
template<typename InputIter , typename T , int N>
completion_future copy_async (InputIter srcBegin, array< T, N > &dest)
 
template<typename InputIter , typename T , int N>
completion_future copy_async (InputIter srcBegin, const array_view< T, N > &dest)
 
template<typename OutputIter , typename T , int N>
completion_future copy_async (const array< T, N > &src, OutputIter destBegin)
 The contents of a source array are copied into "dest" starting with iterator destBegin. More...
 
template<typename OutputIter , typename T , int N>
completion_future copy_async (const array_view< T, N > &src, OutputIter destBegin)
 The contents of a source array are copied into "dest" starting with iterator destBegin. More...
 

Detailed Description

This class is the return type of all asynchronous APIs and has an interface analogous to std::shared_future<void>.

Similar to std::shared_future, this type provides member methods such as wait and get to wait for asynchronous operations to finish, and the type additionally provides a member method then(), to specify a completion callback functor to be executed upon completion of an asynchronous operation.

Constructor & Destructor Documentation

hc::completion_future::completion_future ( )
inline

Default constructor.

Constructs an empty uninitialized completion_future object which does not refer to any asynchronous operation. Default constructed completion_future objects have valid() == false

hc::completion_future::completion_future ( const completion_future other)
inline

Copy constructor.

Constructs a new completion_future object that referes to the same asynchronous operation as the other completion_future object.

Parameters
[in]otherAn object of type completion_future from which to initialize this.
hc::completion_future::completion_future ( completion_future &&  other)
inline

Move constructor.

Move constructs a new completion_future object that referes to the same asynchronous operation as originally refered by the other completion_future object. After this constructor returns, other.valid() == false

Parameters
[in]otherAn object of type completion_future which the new completion_future

Member Function Documentation

void hc::completion_future::get ( ) const
inline

This method is functionally identical to std::shared_future<void>::get.

This method waits for the associated asynchronous operation to finish and returns only upon the completion of the asynchronous operation. If an exception was encountered during the execution of the asynchronous operation, this method throws that stored exception.

uint64_t hc::completion_future::get_begin_tick ( )
inline

Get the tick number when the underlying asynchronous operation begins.

Returns
An implementation-defined tick number in case the instance is created by a kernel dispatch or a barrier packet. 0 otherwise.
uint64_t hc::completion_future::get_end_tick ( )
inline

Get the tick number when the underlying asynchronous operation ends.

Returns
An implementation-defined tick number in case the instance is created by a kernel dispatch or a barrier packet. 0 otherwise.
void* hc::completion_future::get_native_handle ( ) const
inline

Get the native handle for the asynchronous operation encapsulated in this completion_future object.

The method is mostly used for debugging purpose. Applications should retain the parent completion_future to ensure the native handle is not deallocated by the HCC runtime. The completion_future pointer to the native handle is reference counted, so a copy of the completion_future is sufficient to retain the native_handle.

uint64_t hc::completion_future::get_tick_frequency ( )
inline

Get the frequency of ticks per second for the underlying asynchrnous operation.

Returns
An implementation-defined frequency in Hz in case the instance is created by a kernel dispatch or a barrier packet. 0 otherwise.
int hc::completion_future::get_use_count ( ) const
inline
Returns
reference count for the completion future. Primarily used for debug purposes.
bool hc::completion_future::is_ready ( )
inline

Get if the async operations has been completed.

Returns
True if the async operation has been completed, false if not.
hc::completion_future::operator std::shared_future< void > ( ) const
inline

Conversion operator to std::shared_future<void>.

This method returns a shared_future<void> object corresponding to this completion_future object and refers to the same asynchronous operation.

completion_future& hc::completion_future::operator= ( const completion_future _Other)
inline

Copy assignment.

Copy assigns the contents of other to this. This method causes this to stop referring its current asynchronous operation and start referring the same asynchronous operation as other.

Parameters
[in]otherAn object of type completion_future which is copy assigned to this.
completion_future& hc::completion_future::operator= ( completion_future &&  _Other)
inline

Move assignment.

Move assigns the contents of other to this. This method causes this to stop referring its current asynchronous operation and start referring the same asynchronous operation as other. After this method returns, other.valid() == false

Parameters
[in]otherAn object of type completion_future which is move assigned to this.
template<typename functor >
void hc::completion_future::then ( const functor &  func)
inline

This method enables specification of a completion callback func which is executed upon completion of the asynchronous operation associated with this completion_future object.

The completion callback func should have an operator() that is valid when invoked with non arguments, i.e., "func()".

bool hc::completion_future::valid ( ) const
inline

This method is functionally identical to std::shared_future<void>::valid.

This returns true if this completion_future is associated with an asynchronous operation.

void hc::completion_future::wait ( hcWaitMode  mode = hcWaitModeBlocked) const
inline

These methods are functionally identical to the corresponding std::shared_future<void> methods.

The wait method waits for the associated asynchronous operation to finish and returns only upon completion of the associated asynchronous operation or if an exception was encountered when executing the asynchronous operation.

The other variants are functionally identical to the std::shared_future<void> member methods with same names.

Parameters
waitMode[in]An optional parameter to specify the wait mode. By default it would be hcWaitModeBlocked. hcWaitModeActive would be used to reduce latency with the expense of using one CPU core for active waiting.
template<class _Rep , class _Period >
std::future_status hc::completion_future::wait_for ( const std::chrono::duration< _Rep, _Period > &  _Rel_time) const
inline

These methods are functionally identical to the corresponding std::shared_future<void> methods.

The wait method waits for the associated asynchronous operation to finish and returns only upon completion of the associated asynchronous operation or if an exception was encountered when executing the asynchronous operation.

The other variants are functionally identical to the std::shared_future<void> member methods with same names.

Parameters
waitMode[in]An optional parameter to specify the wait mode. By default it would be hcWaitModeBlocked. hcWaitModeActive would be used to reduce latency with the expense of using one CPU core for active waiting.
template<class _Clock , class _Duration >
std::future_status hc::completion_future::wait_until ( const std::chrono::time_point< _Clock, _Duration > &  _Abs_time) const
inline

These methods are functionally identical to the corresponding std::shared_future<void> methods.

The wait method waits for the associated asynchronous operation to finish and returns only upon completion of the associated asynchronous operation or if an exception was encountered when executing the asynchronous operation.

The other variants are functionally identical to the std::shared_future<void> member methods with same names.

Parameters
waitMode[in]An optional parameter to specify the wait mode. By default it would be hcWaitModeBlocked. hcWaitModeActive would be used to reduce latency with the expense of using one CPU core for active waiting.

Friends And Related Function Documentation

template<typename T , int N>
completion_future copy_async ( const array_view< const T, N > &  src,
const array_view< T, N > &  dest 
)
friend

The contents of "src" are copied into "dest".

If the extents of "src" and "dest" don't match, a runtime exception is thrown.

Parameters
[in]srcAn object of type array_view<T,N> (or array_view<const T, N>) to be copied from.
[out]destAn object of type array_view<T,N> to be copied to.
template<typename T , int N>
completion_future copy_async ( const array< T, N > &  src,
array< T, N > &  dest 
)
friend

The contents of "src" are copied into "dest".

The source and destination may reside on different accelerators. If the extents of "src" and "dest" don't match, a runtime exception is thrown.

Parameters
[in]srcAn object of type array<T,N> to be copied from.
[out]destAn object of type array<T,N> to be copied to.
template<typename T , int N>
completion_future copy_async ( const array< T, N > &  src,
const array_view< T, N > &  dest 
)
friend

The contents of "src" are copied into "dest".

If the extents of "src" and "dest" don't match, a runtime exception is thrown.

Parameters
[in]srcAn object of type array<T,N> to be copied from.
[out]destAn object of type array_view<T,N> to be copied to.
template<typename T , int N>
completion_future copy_async ( const array_view< const T, N > &  src,
array< T, N > &  dest 
)
friend

The contents of "src" are copied into "dest".

If the extents of "src" and "dest" don't match, a runtime exception is thrown.

Parameters
[in]srcAn object of type array_view<T,N> (or array_view<const T, N>) to be copied from.
[out]destAn object of type array<T,N> to be copied to.
template<typename InputIter , typename T , int N>
completion_future copy_async ( InputIter  srcBegin,
InputIter  srcEnd,
array< T, N > &  dest 
)
friend

The contents of a source container from the iterator range [srcBegin,srcEnd) are copied into "dest".

If the number of elements in the iterator range is not equal to "dest.extent.size()", an exception is thrown.

In the overloads which don't take an end-iterator it is assumed that the source iterator is able to provide at least dest.extent.size() elements, but no checking is performed (nor possible).

Parameters
[in]srcBeginAn iterator to the first element of a source container.
[in]srcEndAn interator to the end of a source container.
[out]destAn object of type array<T,N> to be copied to.
template<typename InputIter , typename T , int N>
completion_future copy_async ( InputIter  srcBegin,
InputIter  srcEnd,
const array_view< T, N > &  dest 
)
friend

The contents of a source container from the iterator range [srcBegin,srcEnd) are copied into "dest".

If the number of elements in the iterator range is not equal to "dest.extent.size()", an exception is thrown.

In the overloads which don't take an end-iterator it is assumed that the source iterator is able to provide at least dest.extent.size() elements, but no checking is performed (nor possible).

Parameters
[in]srcBeginAn iterator to the first element of a source container.
[in]srcEndAn interator to the end of a source container.
[out]destAn object of type array_view<T,N> to be copied to.
template<typename OutputIter , typename T , int N>
completion_future copy_async ( const array< T, N > &  src,
OutputIter  destBegin 
)
friend

The contents of a source array are copied into "dest" starting with iterator destBegin.

If the number of elements in the range starting destBegin in the destination container is smaller than "src.extent.size()", the behavior is undefined.

Parameters
[in]srcAn object of type array<T,N> to be copied from.
[out]destBeginAn output iterator addressing the position of the first element in the destination container.
template<typename OutputIter , typename T , int N>
completion_future copy_async ( const array_view< T, N > &  src,
OutputIter  destBegin 
)
friend

The contents of a source array are copied into "dest" starting with iterator destBegin.

If the number of elements in the range starting destBegin in the destination container is smaller than "src.extent.size()", the behavior is undefined.

Parameters
[in]srcAn object of type array_view<T,N> to be copied from.
[out]destBeginAn output iterator addressing the position of the first element in the destination container.

The documentation for this class was generated from the following file: