The Gaudi Framework  master (37c0b60a)
FiberManager Class Reference

#include </builds/gaudi/Gaudi/GaudiHive/src/FiberManager.h>

Collaboration diagram for FiberManager:

Public Member Functions

 FiberManager (int n_threads)
 FiberManager constructor. More...
 
 ~FiberManager ()
 
template<typename F >
void schedule (F &&func)
 Schedule work to run on the asynchronous pool. More...
 

Private Types

using SchedAlgo = boost::fibers::algo::shared_work
 

Private Attributes

boost::fibers::condition_variable m_shuttingDown_cv {}
 
boost::fibers::mutex m_shuttingDown_mtx {}
 
std::vector< std::threadm_threads {}
 
std::vector< SchedAlgo * > m_schedAlgoList {}
 

Detailed Description

The FiberManager manages a pool of threads used to run boost::fiber fibers.

These fibers can be suspended while waiting for GPU operations (with CUDA and HIP support built-in), remote I/O operations, and the like, providing a base for asynchronous algorithm support.

Author
Beojan Stanislaus
Version
1.0
Date
November 2023

Definition at line 34 of file FiberManager.h.

Member Typedef Documentation

◆ SchedAlgo

using FiberManager::SchedAlgo = boost::fibers::algo::shared_work
private

Definition at line 60 of file FiberManager.h.

Constructor & Destructor Documentation

◆ FiberManager()

FiberManager::FiberManager ( int  n_threads)

FiberManager constructor.

Parameters
n_threadsNumber of threads for CPU portion of asynchronous algorithms. These are in addition to the TBB worker threads used for CPU algorithms.

Definition at line 14 of file FiberManager.cpp.

14  {
16  auto* main_algo_ptr = new SchedAlgo( true );
17  m_schedAlgoList.at( n_threads ) = main_algo_ptr;
18 #if ( BOOST_VERSION >= 108400 )
19  boost::fibers::initialize_thread( main_algo_ptr,
20  boost::fibers::make_stack_allocator_wrapper<boost::fibers::default_stack>() );
21 #else
22  boost::fibers::context::active()->get_scheduler()->set_algo( main_algo_ptr );
23 #endif
24 
25  for ( int i = 0; i < n_threads; ++i ) {
27  auto* algo_ptr = new SchedAlgo( true );
28  m_schedAlgoList.at( i ) = algo_ptr;
29 #if ( BOOST_VERSION >= 108400 )
30  boost::fibers::initialize_thread( algo_ptr,
31  boost::fibers::make_stack_allocator_wrapper<boost::fibers::default_stack>() );
32 #else
33  boost::fibers::context::active()->get_scheduler()->set_algo( algo_ptr );
34 #endif
36  m_shuttingDown_cv.wait( lck );
37  } ) );
38  }
39 }

◆ ~FiberManager()

FiberManager::~FiberManager ( )

Definition at line 41 of file FiberManager.cpp.

41  {
42  m_shuttingDown_cv.notify_all();
43  for ( std::thread& t : m_threads ) { t.join(); }
44 }

Member Function Documentation

◆ schedule()

template<typename F >
void FiberManager::schedule ( F &&  func)
inline

Schedule work to run on the asynchronous pool.

AsynchronousAlgorithms should use a relatively small amount of CPU time, and should use boost::fiber functionality to yield while waiting for offloaded work to complete.

Parameters
funcThe AlgTask, when used in AvalancheSchedulerSvc

Definition at line 54 of file FiberManager.h.

54  {
55  boost::fibers::fiber( boost::fibers::launch::post, std::forward<F>( func ) ).detach();
56  for ( auto* p : m_schedAlgoList ) { p->notify(); }
57  }

Member Data Documentation

◆ m_schedAlgoList

std::vector<SchedAlgo*> FiberManager::m_schedAlgoList {}
private

Definition at line 64 of file FiberManager.h.

◆ m_shuttingDown_cv

boost::fibers::condition_variable FiberManager::m_shuttingDown_cv {}
private

Definition at line 61 of file FiberManager.h.

◆ m_shuttingDown_mtx

boost::fibers::mutex FiberManager::m_shuttingDown_mtx {}
private

Definition at line 62 of file FiberManager.h.

◆ m_threads

std::vector<std::thread> FiberManager::m_threads {}
private

Definition at line 63 of file FiberManager.h.


The documentation for this class was generated from the following files:
std::vector::resize
T resize(T... args)
FiberManager::m_threads
std::vector< std::thread > m_threads
Definition: FiberManager.h:63
prepareBenchmark.n_threads
n_threads
Definition: prepareBenchmark.py:40
FiberManager::m_schedAlgoList
std::vector< SchedAlgo * > m_schedAlgoList
Definition: FiberManager.h:64
bug_34121.t
t
Definition: bug_34121.py:31
FiberManager::SchedAlgo
boost::fibers::algo::shared_work SchedAlgo
Definition: FiberManager.h:60
std::thread
STL class.
std::vector::at
T at(T... args)
cpluginsvc.func
func
Definition: cpluginsvc.py:235
std::unique_lock
STL class.
FiberManager::m_shuttingDown_mtx
boost::fibers::mutex m_shuttingDown_mtx
Definition: FiberManager.h:62
std::vector::emplace_back
T emplace_back(T... args)
FiberManager::m_shuttingDown_cv
boost::fibers::condition_variable m_shuttingDown_cv
Definition: FiberManager.h:61