Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb::flow::interface10::opencl_memory< Factory > Class Template Referenceabstract

#include <flow_graph_opencl_node.h>

Inheritance diagram for tbb::flow::interface10::opencl_memory< Factory >:
Collaboration diagram for tbb::flow::interface10::opencl_memory< Factory >:

Public Member Functions

 opencl_memory ()
 
 opencl_memory (Factory &f)
 
 ~opencl_memory ()
 
cl_mem get_cl_mem () const
 
voidget_host_ptr ()
 
Factory * factory () const
 
opencl_async_msg< void *, Factory > receive (const cl_event *e)
 
opencl_async_msg< void *, Factory > send (opencl_device device, const cl_event *e)
 
virtual void map_memory (opencl_device, opencl_async_msg< void *, Factory > &)=0
 

Protected Attributes

cl_mem my_cl_mem
 
tbb::atomic< opencl_device::device_id_typemy_curr_device_id
 
voidmy_host_ptr
 
Factory * my_factory
 
tbb::spin_mutex my_sending_lock
 
bool my_sending_event_present
 
cl_event my_sending_event
 

Detailed Description

template<typename Factory>
class tbb::flow::interface10::opencl_memory< Factory >

Definition at line 500 of file flow_graph_opencl_node.h.

Constructor & Destructor Documentation

◆ opencl_memory() [1/2]

template<typename Factory>
tbb::flow::interface10::opencl_memory< Factory >::opencl_memory ( )
inline

Definition at line 502 of file flow_graph_opencl_node.h.

502 {}

◆ opencl_memory() [2/2]

template<typename Factory>
tbb::flow::interface10::opencl_memory< Factory >::opencl_memory ( Factory &  f)
inline

Definition at line 503 of file flow_graph_opencl_node.h.

503  : my_host_ptr( NULL ), my_factory( &f ), my_sending_event_present( false ) {
504  my_curr_device_id = my_factory->devices().begin()->my_device_id;
505  }
tbb::atomic< opencl_device::device_id_type > my_curr_device_id

◆ ~opencl_memory()

template<typename Factory>
tbb::flow::interface10::opencl_memory< Factory >::~opencl_memory ( )
inline

Definition at line 507 of file flow_graph_opencl_node.h.

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

507  {
508  if ( my_sending_event_present ) enforce_cl_retcode( clReleaseEvent( my_sending_event ), "Failed to release an event for the OpenCL buffer" );
509  enforce_cl_retcode( clReleaseMemObject( my_cl_mem ), "Failed to release an memory object" );
510  }
void enforce_cl_retcode(cl_int err, std::string msg)
Here is the call graph for this function:

Member Function Documentation

◆ factory()

template<typename Factory>
Factory* tbb::flow::interface10::opencl_memory< Factory >::factory ( ) const
inline

Definition at line 525 of file flow_graph_opencl_node.h.

◆ get_cl_mem()

template<typename Factory>
cl_mem tbb::flow::interface10::opencl_memory< Factory >::get_cl_mem ( ) const
inline

◆ get_host_ptr()

template<typename Factory>
void* tbb::flow::interface10::opencl_memory< Factory >::get_host_ptr ( )
inline

Definition at line 516 of file flow_graph_opencl_node.h.

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

Referenced by tbb::flow::interface10::opencl_factory< default_device_filter >::enqueue_unmap_buffer().

516  {
517  if ( !my_host_ptr ) {
518  opencl_async_msg<void*, Factory> d = receive( NULL );
519  d.data();
520  __TBB_ASSERT( d.data() == my_host_ptr, NULL );
521  }
522  return my_host_ptr;
523  }
opencl_async_msg< void *, Factory > receive(const cl_event *e)
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ map_memory()

template<typename Factory>
virtual void tbb::flow::interface10::opencl_memory< Factory >::map_memory ( opencl_device  ,
opencl_async_msg< void *, Factory > &   
)
pure virtual

◆ receive()

template<typename Factory>
opencl_async_msg<void*, Factory> tbb::flow::interface10::opencl_memory< Factory >::receive ( const cl_event *  e)
inline

Definition at line 527 of file flow_graph_opencl_node.h.

References d, tbb::flow::interface10::opencl_async_msg< T, Factory >::data(), tbb::flow::interface10::enforce_cl_retcode(), tbb::flow::interface10::opencl_device::host, and tbb::relaxed.

527  {
528  opencl_async_msg<void*, Factory> d;
529  if (e) {
530  d = opencl_async_msg<void*, Factory>(my_host_ptr, *e);
531  } else {
532  d = opencl_async_msg<void*, Factory>(my_host_ptr);
533  }
534 
535  // Concurrent receives are prohibited so we do not worry about synchronization.
537  map_memory(*my_factory->devices().begin(), d);
539  my_host_ptr = d.data(false);
540  }
541  // Release the sending event
543  enforce_cl_retcode(clReleaseEvent(my_sending_event), "Failed to release an event");
544  my_sending_event_present = false;
545  }
546  return d;
547  }
value_type load() const
Definition: atomic.h:302
void store(value_type value)
Definition: atomic.h:313
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
No ordering.
Definition: atomic.h:47
void enforce_cl_retcode(cl_int err, std::string msg)
tbb::atomic< opencl_device::device_id_type > my_curr_device_id
virtual void map_memory(opencl_device, opencl_async_msg< void *, Factory > &)=0
Here is the call graph for this function:

◆ send()

template<typename Factory>
opencl_async_msg<void*, Factory> tbb::flow::interface10::opencl_memory< Factory >::send ( opencl_device  device,
const cl_event *  e 
)
inline

Definition at line 549 of file flow_graph_opencl_node.h.

References __TBB_ASSERT, tbb::acquire, d, tbb::flow::interface10::enforce_cl_retcode(), tbb::flow::interface10::opencl_async_msg< T, Factory >::get_event(), lock, tbb::flow::interface10::opencl_device::my_device_id, tbb::relaxed, and tbb::release.

549  {
550  opencl_device::device_id_type device_id = device.my_device_id;
551  if (!my_factory->is_same_context(my_curr_device_id.load<tbb::acquire>(), device_id)) {
552  {
554  if (!my_factory->is_same_context(my_curr_device_id.load<tbb::relaxed>(), device_id)) {
555  __TBB_ASSERT(my_host_ptr, "The buffer has not been mapped");
556  opencl_async_msg<void*, Factory> d(my_host_ptr);
557  my_factory->enqueue_unmap_buffer(device, *this, d);
558  my_sending_event = *d.get_event();
560  enforce_cl_retcode(clRetainEvent(my_sending_event), "Failed to retain an event");
561  my_host_ptr = NULL;
563  }
564  }
566  }
567 
568  // !e means that buffer has come from the host
570 
571  __TBB_ASSERT(!my_host_ptr, "The buffer has not been unmapped");
572  return e ? opencl_async_msg<void*, Factory>(NULL, *e) : opencl_async_msg<void*, Factory>(NULL);
573  }
value_type load() const
Definition: atomic.h:302
void store(value_type value)
Definition: atomic.h:313
Release.
Definition: atomic.h:45
Represents acquisition of a mutex.
Definition: spin_mutex.h:50
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
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 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 * lock
No ordering.
Definition: atomic.h:47
void enforce_cl_retcode(cl_int err, std::string msg)
Acquire.
Definition: atomic.h:43
tbb::atomic< opencl_device::device_id_type > my_curr_device_id
Here is the call graph for this function:

Member Data Documentation

◆ my_cl_mem

template<typename Factory>
cl_mem tbb::flow::interface10::opencl_memory< Factory >::my_cl_mem
protected

Definition at line 577 of file flow_graph_opencl_node.h.

◆ my_curr_device_id

template<typename Factory>
tbb::atomic<opencl_device::device_id_type> tbb::flow::interface10::opencl_memory< Factory >::my_curr_device_id
protected

Definition at line 578 of file flow_graph_opencl_node.h.

◆ my_factory

template<typename Factory>
Factory* tbb::flow::interface10::opencl_memory< Factory >::my_factory
protected

Definition at line 580 of file flow_graph_opencl_node.h.

◆ my_host_ptr

template<typename Factory>
void* tbb::flow::interface10::opencl_memory< Factory >::my_host_ptr
protected

Definition at line 579 of file flow_graph_opencl_node.h.

◆ my_sending_event

template<typename Factory>
cl_event tbb::flow::interface10::opencl_memory< Factory >::my_sending_event
protected

Definition at line 584 of file flow_graph_opencl_node.h.

◆ my_sending_event_present

template<typename Factory>
bool tbb::flow::interface10::opencl_memory< Factory >::my_sending_event_present
protected

Definition at line 583 of file flow_graph_opencl_node.h.

◆ my_sending_lock

template<typename Factory>
tbb::spin_mutex tbb::flow::interface10::opencl_memory< Factory >::my_sending_lock
protected

Definition at line 582 of file flow_graph_opencl_node.h.


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.