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

#include <flow_graph_opencl_node.h>

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

Public Types

typedef T value_type
 
- Public Types inherited from tbb::flow::interface10::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::interface10::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::interface10::opencl_async_msg< T, Factory >

Definition at line 351 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::interface10::opencl_async_msg< T, Factory >::value_type

Definition at line 353 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::interface10::opencl_async_msg< T, Factory >::opencl_async_msg ( )
inline

Definition at line 355 of file flow_graph_opencl_node.h.

355  : my_callback_flag_ptr( std::make_shared< tbb::atomic<bool>>() ) {
356  my_callback_flag_ptr->store<tbb::relaxed>(false);
357  }
std::shared_ptr< tbb::atomic< bool > > my_callback_flag_ptr
No ordering.
Definition: atomic.h:47

References tbb::flow::interface10::opencl_async_msg< T, Factory >::my_callback_flag_ptr, and tbb::relaxed.

◆ opencl_async_msg() [2/5]

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

◆ opencl_async_msg() [3/5]

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

Definition at line 363 of file flow_graph_opencl_node.h.

363  : my_data(data), my_event(event), my_is_event(true), my_callback_flag_ptr( std::make_shared<tbb::atomic<bool>>() ) {
364  my_callback_flag_ptr->store<tbb::relaxed>(false);
365  enforce_cl_retcode( clRetainEvent( my_event ), "Failed to retain an event" );
366  }
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
std::shared_ptr< tbb::atomic< bool > > my_callback_flag_ptr
No ordering.
Definition: atomic.h:47
void enforce_cl_retcode(cl_int err, std::string msg)

References tbb::flow::interface10::enforce_cl_retcode(), tbb::flow::interface10::opencl_async_msg< T, Factory >::my_callback_flag_ptr, tbb::flow::interface10::opencl_async_msg< T, Factory >::my_event, and tbb::relaxed.

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::interface10::opencl_async_msg< T, Factory >::opencl_async_msg ( const opencl_async_msg< T, Factory > &  dmsg)
inline

Definition at line 386 of file flow_graph_opencl_node.h.

386  : async_msg<T>(dmsg),
387  my_data(dmsg.my_data), my_event(dmsg.my_event), my_is_event( dmsg.my_is_event ),
388  my_callback_flag_ptr(dmsg.my_callback_flag_ptr)
389  {
390  if ( my_is_event )
391  enforce_cl_retcode( clRetainEvent( my_event ), "Failed to retain an event" );
392  }
std::shared_ptr< tbb::atomic< bool > > my_callback_flag_ptr
void enforce_cl_retcode(cl_int err, std::string msg)

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

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::interface10::opencl_async_msg< T, Factory >::opencl_async_msg ( opencl_async_msg< T, Factory > &&  dmsg)
inline

Definition at line 394 of file flow_graph_opencl_node.h.

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

◆ ~opencl_async_msg()

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

Definition at line 420 of file flow_graph_opencl_node.h.

420  {
421  if ( my_is_event )
422  enforce_cl_retcode( clReleaseEvent( my_event ), "Failed to release an event" );
423  }
void enforce_cl_retcode(cl_int err, std::string msg)

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

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::interface10::opencl_async_msg< T, Factory >::clear_event ( ) const
inline

Definition at line 438 of file flow_graph_opencl_node.h.

438  {
439  if ( my_is_event ) {
440  enforce_cl_retcode( clFlush( event_info<cl_command_queue>( my_event, CL_EVENT_COMMAND_QUEUE ) ), "Failed to flush an OpenCL command queue" );
441  enforce_cl_retcode( clReleaseEvent( my_event ), "Failed to release an event" );
442  }
443  my_is_event = false;
444  }
void enforce_cl_retcode(cl_int err, std::string msg)

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

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

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::interface10::opencl_async_msg< T, Factory >::data ( bool  wait = true)
inline

Definition at line 368 of file flow_graph_opencl_node.h.

368  {
369  if ( my_is_event && wait ) {
370  enforce_cl_retcode( clWaitForEvents( 1, &my_event ), "Failed to wait for an event" );
371  enforce_cl_retcode( clReleaseEvent( my_event ), "Failed to release an event" );
372  my_is_event = false;
373  }
374  return my_data;
375  }
void enforce_cl_retcode(cl_int err, std::string msg)

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

Referenced by tbb::flow::interface10::opencl_factory< default_device_filter >::enqueue_map_buffer(), tbb::flow::interface10::key_from_message(), tbb::flow::interface10::opencl_async_msg< T, Factory >::operator const T &(), tbb::flow::interface10::opencl_async_msg< T, Factory >::operator T&(), tbb::flow::interface10::opencl_factory< default_device_filter >::process_one_arg(), tbb::flow::interface10::opencl_buffer< T, Factory >::receive(), tbb::flow::interface10::receive_if_memory_object(), tbb::flow::interface10::opencl_async_msg< T, Factory >::register_callback_func(), tbb::flow::interface10::opencl_buffer< T, Factory >::send(), and tbb::flow::interface10::send_if_memory_object().

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::interface10::opencl_async_msg< T, Factory >::data ( bool  wait = true) const
inline

Definition at line 377 of file flow_graph_opencl_node.h.

377  {
378  if ( my_is_event && wait ) {
379  enforce_cl_retcode( clWaitForEvents( 1, &my_event ), "Failed to wait for an event" );
380  enforce_cl_retcode( clReleaseEvent( my_event ), "Failed to release an event" );
381  my_is_event = false;
382  }
383  return my_data;
384  }
void enforce_cl_retcode(cl_int err, std::string msg)

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

Here is the call graph for this function:

◆ finalize()

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

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

Definition at line 458 of file flow_graph_opencl_node.h.

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

References tbb::flow::interface10::opencl_async_msg< T, Factory >::clear_event(), tbb::flow::interface10::opencl_async_msg< T, Factory >::my_callback_flag_ptr, tbb::flow::interface10::opencl_async_msg< T, Factory >::my_data, tbb::flow::interface10::opencl_async_msg< T, Factory >::my_is_event, tbb::flow::interface10::receive_if_memory_object(), tbb::flow::interface10::opencl_async_msg< T, Factory >::register_callback(), and tbb::flow::interface10::async_msg< T >::set().

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::interface10::opencl_async_msg< T, Factory >::operator const T & ( ) const
inline

Definition at line 453 of file flow_graph_opencl_node.h.

453 { return data(); }

References tbb::flow::interface10::opencl_async_msg< T, Factory >::data().

Here is the call graph for this function:

◆ operator T&()

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

Definition at line 452 of file flow_graph_opencl_node.h.

452 { return data(); }

References tbb::flow::interface10::opencl_async_msg< T, Factory >::data().

Here is the call graph for this function:

◆ operator=()

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

Definition at line 401 of file flow_graph_opencl_node.h.

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

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

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::interface10::opencl_async_msg< T, Factory >::register_callback ( Callback  c) const
inline

Definition at line 447 of file flow_graph_opencl_node.h.

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

References __TBB_ASSERT, tbb::flow::interface10::enforce_cl_retcode(), tbb::flow::interface10::opencl_async_msg< T, Factory >::my_data, tbb::flow::interface10::opencl_async_msg< T, Factory >::my_event, tbb::flow::interface10::opencl_async_msg< T, Factory >::my_is_event, and tbb::flow::interface10::opencl_async_msg< T, Factory >::register_callback_func().

Referenced by tbb::flow::interface10::opencl_async_msg< T, Factory >::finalize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_callback_func()

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

Definition at line 475 of file flow_graph_opencl_node.h.

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

References __TBB_ASSERT, tbb::flow::interface10::callback_base::call(), tbb::flow::interface10::opencl_async_msg< T, Factory >::data(), and tbb::internal::suppress_unused_warning().

Referenced by tbb::flow::interface10::opencl_async_msg< T, Factory >::register_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_event()

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

Definition at line 426 of file flow_graph_opencl_node.h.

426  {
427  if ( my_is_event ) {
428  cl_command_queue cq = event_info<cl_command_queue>( my_event, CL_EVENT_COMMAND_QUEUE );
429  if ( cq != event_info<cl_command_queue>( e, CL_EVENT_COMMAND_QUEUE ) )
430  enforce_cl_retcode( clFlush( cq ), "Failed to flush an OpenCL command queue" );
431  enforce_cl_retcode( clReleaseEvent( my_event ), "Failed to release an event" );
432  }
433  my_is_event = true;
434  my_event = e;
435  clRetainEvent( my_event );
436  }
void enforce_cl_retcode(cl_int err, std::string msg)

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

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

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::interface10::opencl_async_msg< T, Factory >::my_callback_flag_ptr
private

◆ my_data

◆ my_event

◆ my_is_event


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.