The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
FiberManager Class Reference

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

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

Collaboration diagram for FiberManager:

Public Member Functions

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

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::thread > m_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 {
15 m_schedAlgoList.resize( n_threads + 1 );
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 ) {
26 m_threads.emplace_back( std::thread( [this, 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
35 std::unique_lock lck{ m_shuttingDown_mtx };
36 m_shuttingDown_cv.wait( lck );
37 } ) );
38 }
39}
boost::fibers::condition_variable m_shuttingDown_cv
boost::fibers::algo::shared_work SchedAlgo
std::vector< SchedAlgo * > m_schedAlgoList
boost::fibers::mutex m_shuttingDown_mtx
std::vector< std::thread > m_threads

◆ ~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.

64{};

◆ m_shuttingDown_cv

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

Definition at line 61 of file FiberManager.h.

61{};

◆ m_shuttingDown_mtx

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

Definition at line 62 of file FiberManager.h.

62{};

◆ m_threads

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

Definition at line 63 of file FiberManager.h.

63{};

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