Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb::flow::interface11::opencl_async_msg< T, Factory > Class Template Reference

#include <flow_graph_opencl_node.h>

Inheritance diagram for tbb::flow::interface11::opencl_async_msg< T, Factory >:
Collaboration diagram for tbb::flow::interface11::opencl_async_msg< T, Factory >:

Public Types

typedef T value_type
 
- Public Types inherited from tbb::flow::interface11::async_msg< T >
typedef T async_msg_data_type
 

Public Member Functions

 opencl_async_msg ()
 
 opencl_async_msg (const T &data)
 
 opencl_async_msg (const T &data, cl_event event)
 
T & data (bool wait=true)
 
const T & data (bool wait=true) const
 
 opencl_async_msg (const opencl_async_msg &dmsg)
 
 opencl_async_msg (opencl_async_msg &&dmsg)
 
opencl_async_msgoperator= (const opencl_async_msg &dmsg)
 
 ~opencl_async_msg ()
 
cl_event const * get_event () const
 
void set_event (cl_event e) const
 
void clear_event () const
 
template<typename Callback >
void register_callback (Callback c) const
 
 operator T & ()
 
 operator const T & () const
 
- Public Member Functions inherited from tbb::flow::interface11::async_msg< T >
 async_msg ()
 
 async_msg (const T &t)
 
 async_msg (T &&t)
 
virtual ~async_msg ()
 
void set (const T &t)
 
void set (T &&t)
 

Protected Member Functions

void finalize () const __TBB_override
 

Static Private Member Functions

static void CL_CALLBACK register_callback_func (cl_event, cl_int event_command_exec_status, void *data)
 

Private Attributes

my_data
 
cl_event my_event
 
bool my_is_event = false
 
std::shared_ptr< tbb::atomic< bool > > my_callback_flag_ptr
 

Detailed Description

template<typename T, typename Factory = opencl_info::default_opencl_factory>
class tbb::flow::interface11::opencl_async_msg< T, Factory >

Definition at line 354 of file flow_graph_opencl_node.h.

Member Typedef Documentation

◆ value_type

template<typename T, typename Factory = opencl_info::default_opencl_factory>
typedef T tbb::flow::interface11::opencl_async_msg< T, Factory >::value_type

Definition at line 356 of file flow_graph_opencl_node.h.

Constructor & Destructor Documentation

◆ opencl_async_msg() [1/5]

template<typename T, typename Factory = opencl_info::default_opencl_factory>
tbb::flow::interface11::opencl_async_msg< T, Factory >::opencl_async_msg ( )
inline

Definition at line 358 of file flow_graph_opencl_node.h.

References tbb::relaxed.

358  : my_callback_flag_ptr( std::make_shared< tbb::atomic<bool>>() ) {
359  my_callback_flag_ptr->store<tbb::relaxed>(false);
360  }
std::shared_ptr< tbb::atomic< bool > > my_callback_flag_ptr
No ordering.
Definition: atomic.h:61

◆ opencl_async_msg() [2/5]

template<typename T, typename Factory = opencl_info::default_opencl_factory>
tbb::flow::interface11::opencl_async_msg< T, Factory >::opencl_async_msg ( const T &  data)
inlineexplicit

Definition at line 362 of file flow_graph_opencl_node.h.

References tbb::relaxed.

362  : my_data(data), my_callback_flag_ptr( std::make_shared<tbb::atomic<bool>>() ) {
363  my_callback_flag_ptr->store<tbb::relaxed>(false);
364  }
std::shared_ptr< tbb::atomic< bool > > my_callback_flag_ptr
No ordering.
Definition: atomic.h:61

◆ opencl_async_msg() [3/5]

template<typename T, typename Factory = opencl_info::default_opencl_factory>
tbb::flow::interface11::opencl_async_msg< T, Factory >::opencl_async_msg ( const T &  data,
cl_event  event 
)
inline

Definition at line 366 of file flow_graph_opencl_node.h.

References tbb::flow::interface11::enforce_cl_retcode(), and tbb::relaxed.

366  : my_data(data), my_event(event), my_is_event(true), my_callback_flag_ptr( std::make_shared<tbb::atomic<bool>>() ) {
367  my_callback_flag_ptr->store<tbb::relaxed>(false);
368  enforce_cl_retcode( clRetainEvent( my_event ), "Failed to retain an event" );
369  }
std::shared_ptr< tbb::atomic< bool > > my_callback_flag_ptr
void enforce_cl_retcode(cl_int err, std::string msg)
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type size_t void ITT_FORMAT p const __itt_domain __itt_id __itt_string_handle const wchar_t size_t ITT_FORMAT lu const __itt_domain __itt_id __itt_relation __itt_id ITT_FORMAT p const wchar_t int ITT_FORMAT __itt_group_mark d __itt_event event
No ordering.
Definition: atomic.h:61
Here is the call graph for this function:

◆ opencl_async_msg() [4/5]

template<typename T, typename Factory = opencl_info::default_opencl_factory>
tbb::flow::interface11::opencl_async_msg< T, Factory >::opencl_async_msg ( const opencl_async_msg< T, Factory > &  dmsg)
inline

Definition at line 389 of file flow_graph_opencl_node.h.

References tbb::flow::interface11::enforce_cl_retcode().

389  : async_msg<T>(dmsg),
390  my_data(dmsg.my_data), my_event(dmsg.my_event), my_is_event( dmsg.my_is_event ),
391  my_callback_flag_ptr(dmsg.my_callback_flag_ptr)
392  {
393  if ( my_is_event )
394  enforce_cl_retcode( clRetainEvent( my_event ), "Failed to retain an event" );
395  }
std::shared_ptr< tbb::atomic< bool > > my_callback_flag_ptr
void enforce_cl_retcode(cl_int err, std::string msg)
Here is the call graph for this function:

◆ opencl_async_msg() [5/5]

template<typename T, typename Factory = opencl_info::default_opencl_factory>
tbb::flow::interface11::opencl_async_msg< T, Factory >::opencl_async_msg ( opencl_async_msg< T, Factory > &&  dmsg)
inline

Definition at line 397 of file flow_graph_opencl_node.h.

397  : async_msg<T>(std::move(dmsg)),
398  my_data(std::move(dmsg.my_data)), my_event(dmsg.my_event), my_is_event(dmsg.my_is_event),
399  my_callback_flag_ptr( std::move(dmsg.my_callback_flag_ptr) )
400  {
401  dmsg.my_is_event = false;
402  }
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:319
std::shared_ptr< tbb::atomic< bool > > my_callback_flag_ptr

◆ ~opencl_async_msg()

template<typename T, typename Factory = opencl_info::default_opencl_factory>
tbb::flow::interface11::opencl_async_msg< T, Factory >::~opencl_async_msg ( )
inline

Definition at line 423 of file flow_graph_opencl_node.h.

References tbb::flow::interface11::enforce_cl_retcode().

423  {
424  if ( my_is_event )
425  enforce_cl_retcode( clReleaseEvent( my_event ), "Failed to release an event" );
426  }
void enforce_cl_retcode(cl_int err, std::string msg)
Here is the call graph for this function:

Member Function Documentation

◆ clear_event()

template<typename T, typename Factory = opencl_info::default_opencl_factory>
void tbb::flow::interface11::opencl_async_msg< T, Factory >::clear_event ( ) const
inline

Definition at line 441 of file flow_graph_opencl_node.h.

References tbb::flow::interface11::enforce_cl_retcode().

Referenced by tbb::flow::interface11::opencl_buffer< T, Factory >::receive(), and tbb::flow::interface11::opencl_buffer< T, Factory >::send().

441  {
442  if ( my_is_event ) {
443  enforce_cl_retcode( clFlush( event_info<cl_command_queue>( my_event, CL_EVENT_COMMAND_QUEUE ) ), "Failed to flush an OpenCL command queue" );
444  enforce_cl_retcode( clReleaseEvent( my_event ), "Failed to release an event" );
445  }
446  my_is_event = false;
447  }
void enforce_cl_retcode(cl_int err, std::string msg)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ data() [1/2]

template<typename T, typename Factory = opencl_info::default_opencl_factory>
T& tbb::flow::interface11::opencl_async_msg< T, Factory >::data ( bool  wait = true)
inline

Definition at line 371 of file flow_graph_opencl_node.h.

References tbb::flow::interface11::enforce_cl_retcode().

Referenced by tbb::flow::interface11::opencl_factory< default_device_filter >::enqueue_map_buffer(), tbb::flow::interface11::opencl_memory< Factory >::get_host_ptr(), tbb::flow::interface11::key_from_message(), tbb::flow::interface11::opencl_factory< default_device_filter >::process_one_arg(), tbb::flow::interface11::opencl_memory< Factory >::receive(), tbb::flow::interface11::opencl_buffer< T, Factory >::receive(), tbb::flow::interface11::receive_if_memory_object(), tbb::flow::interface11::opencl_buffer< T, Factory >::send(), and tbb::flow::interface11::send_if_memory_object().

371  {
372  if ( my_is_event && wait ) {
373  enforce_cl_retcode( clWaitForEvents( 1, &my_event ), "Failed to wait for an event" );
374  enforce_cl_retcode( clReleaseEvent( my_event ), "Failed to release an event" );
375  my_is_event = false;
376  }
377  return my_data;
378  }
void enforce_cl_retcode(cl_int err, std::string msg)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ data() [2/2]

template<typename T, typename Factory = opencl_info::default_opencl_factory>
const T& tbb::flow::interface11::opencl_async_msg< T, Factory >::data ( bool  wait = true) const
inline

Definition at line 380 of file flow_graph_opencl_node.h.

References tbb::flow::interface11::enforce_cl_retcode().

380  {
381  if ( my_is_event && wait ) {
382  enforce_cl_retcode( clWaitForEvents( 1, &my_event ), "Failed to wait for an event" );
383  enforce_cl_retcode( clReleaseEvent( my_event ), "Failed to release an event" );
384  my_is_event = false;
385  }
386  return my_data;
387  }
void enforce_cl_retcode(cl_int err, std::string msg)
Here is the call graph for this function:

◆ finalize()

template<typename T, typename Factory = opencl_info::default_opencl_factory>
void tbb::flow::interface11::opencl_async_msg< T, Factory >::finalize ( ) const
inlineprotectedvirtual

Reimplemented from tbb::flow::interface11::async_msg< T >.

Definition at line 461 of file flow_graph_opencl_node.h.

References tbb::flow::interface11::receive_if_memory_object(), and tbb::flow::interface11::async_msg< T >::set().

461  {
463  if (! my_callback_flag_ptr->fetch_and_store(true)) {
464  opencl_async_msg a(*this);
465  if (my_is_event) {
466  register_callback([a](const T& t) mutable {
467  a.set(t);
468  });
469  }
470  else {
471  a.set(my_data);
472  }
473  }
474  clear_event();
475  }
std::enable_if< is_memory_object_type< T >::value >::type receive_if_memory_object(const opencl_async_msg< T, Factory > &dmsg)
std::shared_ptr< tbb::atomic< bool > > my_callback_flag_ptr
Here is the call graph for this function:

◆ get_event()

◆ operator const T &()

template<typename T, typename Factory = opencl_info::default_opencl_factory>
tbb::flow::interface11::opencl_async_msg< T, Factory >::operator const T & ( ) const
inline

Definition at line 456 of file flow_graph_opencl_node.h.

References data.

456 { return data(); }

◆ operator T &()

template<typename T, typename Factory = opencl_info::default_opencl_factory>
tbb::flow::interface11::opencl_async_msg< T, Factory >::operator T& ( )
inline

Definition at line 455 of file flow_graph_opencl_node.h.

References data.

455 { return data(); }

◆ operator=()

template<typename T, typename Factory = opencl_info::default_opencl_factory>
opencl_async_msg& tbb::flow::interface11::opencl_async_msg< T, Factory >::operator= ( const opencl_async_msg< T, Factory > &  dmsg)
inline

Definition at line 404 of file flow_graph_opencl_node.h.

References tbb::flow::interface11::enforce_cl_retcode(), tbb::flow::interface11::opencl_async_msg< T, Factory >::my_callback_flag_ptr, tbb::flow::interface11::opencl_async_msg< T, Factory >::my_data, tbb::flow::interface11::opencl_async_msg< T, Factory >::my_event, and tbb::flow::interface11::opencl_async_msg< T, Factory >::my_is_event.

404  {
406 
407  // Release original event
408  if ( my_is_event )
409  enforce_cl_retcode( clReleaseEvent( my_event ), "Failed to retain an event" );
410 
411  my_data = dmsg.my_data;
412  my_event = dmsg.my_event;
413  my_is_event = dmsg.my_is_event;
414 
415  // Retain copied event
416  if ( my_is_event )
417  enforce_cl_retcode( clRetainEvent( my_event ), "Failed to retain an event" );
418 
419  my_callback_flag_ptr = dmsg.my_callback_flag_ptr;
420  return *this;
421  }
std::shared_ptr< tbb::atomic< bool > > my_callback_flag_ptr
void enforce_cl_retcode(cl_int err, std::string msg)
Here is the call graph for this function:

◆ register_callback()

template<typename T, typename Factory = opencl_info::default_opencl_factory>
template<typename Callback >
void tbb::flow::interface11::opencl_async_msg< T, Factory >::register_callback ( Callback  c) const
inline

Definition at line 450 of file flow_graph_opencl_node.h.

References __TBB_ASSERT, and tbb::flow::interface11::enforce_cl_retcode().

450  {
451  __TBB_ASSERT( my_is_event, "The OpenCL event is not set" );
452  enforce_cl_retcode( clSetEventCallback( my_event, CL_COMPLETE, register_callback_func, new callback<Callback, T>( c, my_data ) ), "Failed to set an OpenCL callback" );
453  }
void enforce_cl_retcode(cl_int err, std::string msg)
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
static void CL_CALLBACK register_callback_func(cl_event, cl_int event_command_exec_status, void *data)
Here is the call graph for this function:

◆ register_callback_func()

template<typename T, typename Factory = opencl_info::default_opencl_factory>
static void CL_CALLBACK tbb::flow::interface11::opencl_async_msg< T, Factory >::register_callback_func ( cl_event  ,
cl_int  event_command_exec_status,
void data 
)
inlinestaticprivate

Definition at line 478 of file flow_graph_opencl_node.h.

References __TBB_ASSERT, tbb::flow::interface11::callback_base::call(), data, and tbb::internal::suppress_unused_warning().

478  {
479  tbb::internal::suppress_unused_warning( event_command_exec_status );
480  __TBB_ASSERT( event_command_exec_status == CL_COMPLETE, NULL );
481  __TBB_ASSERT( data, NULL );
482  callback_base *c = static_cast<callback_base*>(data);
483  c->call();
484  delete c;
485  }
void suppress_unused_warning(const T1 &)
Utility template function to prevent "unused" warnings by various compilers.
Definition: tbb_stddef.h:398
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
Here is the call graph for this function:

◆ set_event()

template<typename T, typename Factory = opencl_info::default_opencl_factory>
void tbb::flow::interface11::opencl_async_msg< T, Factory >::set_event ( cl_event  e) const
inline

Definition at line 429 of file flow_graph_opencl_node.h.

References tbb::flow::interface11::enforce_cl_retcode().

Referenced by tbb::flow::interface11::opencl_factory< default_device_filter >::enqueue_map_buffer(), tbb::flow::interface11::opencl_factory< default_device_filter >::enqueue_unmap_buffer(), tbb::flow::interface11::opencl_buffer< T, Factory >::receive(), tbb::flow::interface11::receive_if_memory_object(), tbb::flow::interface11::opencl_buffer< T, Factory >::send(), tbb::flow::interface11::send_if_memory_object(), and tbb::flow::interface11::opencl_factory< default_device_filter >::update_one_arg().

429  {
430  if ( my_is_event ) {
431  cl_command_queue cq = event_info<cl_command_queue>( my_event, CL_EVENT_COMMAND_QUEUE );
432  if ( cq != event_info<cl_command_queue>( e, CL_EVENT_COMMAND_QUEUE ) )
433  enforce_cl_retcode( clFlush( cq ), "Failed to flush an OpenCL command queue" );
434  enforce_cl_retcode( clReleaseEvent( my_event ), "Failed to release an event" );
435  }
436  my_is_event = true;
437  my_event = e;
438  clRetainEvent( my_event );
439  }
void enforce_cl_retcode(cl_int err, std::string msg)
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ my_callback_flag_ptr

template<typename T, typename Factory = opencl_info::default_opencl_factory>
std::shared_ptr< tbb::atomic<bool> > tbb::flow::interface11::opencl_async_msg< T, Factory >::my_callback_flag_ptr
private

◆ my_data

template<typename T, typename Factory = opencl_info::default_opencl_factory>
T tbb::flow::interface11::opencl_async_msg< T, Factory >::my_data
private

◆ my_event

template<typename T, typename Factory = opencl_info::default_opencl_factory>
cl_event tbb::flow::interface11::opencl_async_msg< T, Factory >::my_event
mutableprivate

◆ my_is_event

template<typename T, typename Factory = opencl_info::default_opencl_factory>
bool tbb::flow::interface11::opencl_async_msg< T, Factory >::my_is_event = false
mutableprivate

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

Copyright © 2005-2019 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.