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

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 365 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 367 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 369 of file flow_graph_opencl_node.h.

369 : my_callback_flag_ptr( std::make_shared< tbb::atomic<bool>>() ) {
370 my_callback_flag_ptr->store<tbb::relaxed>(false);
371 }
@ relaxed
No ordering.
Definition: atomic.h:61
std::shared_ptr< tbb::atomic< bool > > my_callback_flag_ptr

References tbb::relaxed.

◆ 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 373 of file flow_graph_opencl_node.h.

References tbb::relaxed.

◆ 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 377 of file flow_graph_opencl_node.h.

377 : my_data(data), my_event(event), my_is_event(true), my_callback_flag_ptr( std::make_shared<tbb::atomic<bool>>() ) {
378 my_callback_flag_ptr->store<tbb::relaxed>(false);
379 enforce_cl_retcode( clRetainEvent( my_event ), "Failed to retain an event" );
380 }
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_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
void enforce_cl_retcode(cl_int err, std::string msg)

References tbb::flow::interface11::enforce_cl_retcode(), 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::interface11::opencl_async_msg< T, Factory >::opencl_async_msg ( const opencl_async_msg< T, Factory > &  dmsg)
inline

Definition at line 400 of file flow_graph_opencl_node.h.

400 : async_msg<T>(dmsg),
401 my_data(dmsg.my_data), my_event(dmsg.my_event), my_is_event( dmsg.my_is_event ),
402 my_callback_flag_ptr(dmsg.my_callback_flag_ptr)
403 {
404 if ( my_is_event )
405 enforce_cl_retcode( clRetainEvent( my_event ), "Failed to retain an event" );
406 }

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

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 408 of file flow_graph_opencl_node.h.

408 : async_msg<T>(std::move(dmsg)),
409 my_data(std::move(dmsg.my_data)), my_event(dmsg.my_event), my_is_event(dmsg.my_is_event),
410 my_callback_flag_ptr( std::move(dmsg.my_callback_flag_ptr) )
411 {
412 dmsg.my_is_event = false;
413 }
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:319

◆ ~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 434 of file flow_graph_opencl_node.h.

434 {
435 if ( my_is_event )
436 enforce_cl_retcode( clReleaseEvent( my_event ), "Failed to release an event" );
437 }

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

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 452 of file flow_graph_opencl_node.h.

452 {
453 if ( my_is_event ) {
454 enforce_cl_retcode( clFlush( event_info<cl_command_queue>( my_event, CL_EVENT_COMMAND_QUEUE ) ), "Failed to flush an OpenCL command queue" );
455 enforce_cl_retcode( clReleaseEvent( my_event ), "Failed to release an event" );
456 }
457 my_is_event = false;
458 }

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().

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 382 of file flow_graph_opencl_node.h.

382 {
383 if ( my_is_event && wait ) {
384 enforce_cl_retcode( clWaitForEvents( 1, &my_event ), "Failed to wait for an event" );
385 enforce_cl_retcode( clReleaseEvent( my_event ), "Failed to release an event" );
386 my_is_event = false;
387 }
388 return my_data;
389 }

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

Referenced by tbb::flow::interface11::opencl_factory< DeviceFilter >::enqueue_map_buffer(), tbb::flow::interface11::key_from_message(), tbb::flow::interface11::opencl_factory< DeviceFilter >::process_one_arg(), 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().

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 391 of file flow_graph_opencl_node.h.

391 {
392 if ( my_is_event && wait ) {
393 enforce_cl_retcode( clWaitForEvents( 1, &my_event ), "Failed to wait for an event" );
394 enforce_cl_retcode( clReleaseEvent( my_event ), "Failed to release an event" );
395 my_is_event = false;
396 }
397 return my_data;
398 }

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

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
inlineprotected

Definition at line 472 of file flow_graph_opencl_node.h.

472 {
474 if (! my_callback_flag_ptr->fetch_and_store(true)) {
475 opencl_async_msg a(*this);
476 if (my_is_event) {
477 register_callback([a](const T& t) mutable {
478 a.set(t);
479 });
480 }
481 else {
482 a.set(my_data);
483 }
484 }
485 clear_event();
486 }
std::enable_if< is_memory_object_type< T >::value >::type receive_if_memory_object(const opencl_async_msg< T, Factory > &dmsg)

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

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 467 of file flow_graph_opencl_node.h.

467{ return data(); }

References 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 466 of file flow_graph_opencl_node.h.

466{ return data(); }

References 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 415 of file flow_graph_opencl_node.h.

415 {
416 async_msg<T>::operator =(dmsg);
417
418 // Release original event
419 if ( my_is_event )
420 enforce_cl_retcode( clReleaseEvent( my_event ), "Failed to retain an event" );
421
422 my_data = dmsg.my_data;
423 my_event = dmsg.my_event;
424 my_is_event = dmsg.my_is_event;
425
426 // Retain copied event
427 if ( my_is_event )
428 enforce_cl_retcode( clRetainEvent( my_event ), "Failed to retain an event" );
429
430 my_callback_flag_ptr = dmsg.my_callback_flag_ptr;
431 return *this;
432 }

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.

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 461 of file flow_graph_opencl_node.h.

461 {
462 __TBB_ASSERT( my_is_event, "The OpenCL event is not set" );
463 enforce_cl_retcode( clSetEventCallback( my_event, CL_COMPLETE, register_callback_func, new callback<Callback, T>( c, my_data ) ), "Failed to set an OpenCL callback" );
464 }
#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)

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

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 489 of file flow_graph_opencl_node.h.

489 {
490 tbb::internal::suppress_unused_warning( event_command_exec_status );
491 __TBB_ASSERT( event_command_exec_status == CL_COMPLETE, NULL );
492 __TBB_ASSERT( data, NULL );
493 callback_base *c = static_cast<callback_base*>(data);
494 c->call();
495 delete c;
496 }
void suppress_unused_warning(const T1 &)
Utility template function to prevent "unused" warnings by various compilers.
Definition: tbb_stddef.h:398

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

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 440 of file flow_graph_opencl_node.h.

440 {
441 if ( my_is_event ) {
442 cl_command_queue cq = event_info<cl_command_queue>( my_event, CL_EVENT_COMMAND_QUEUE );
443 if ( cq != event_info<cl_command_queue>( e, CL_EVENT_COMMAND_QUEUE ) )
444 enforce_cl_retcode( clFlush( cq ), "Failed to flush an OpenCL command queue" );
445 enforce_cl_retcode( clReleaseEvent( my_event ), "Failed to release an event" );
446 }
447 my_is_event = true;
448 my_event = e;
449 clRetainEvent( my_event );
450 }

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

Referenced by tbb::flow::interface11::opencl_factory< DeviceFilter >::enqueue_map_buffer(), tbb::flow::interface11::opencl_factory< DeviceFilter >::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< DeviceFilter >::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::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-2020 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.