diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/gpgpusim_entrypoint.cc | 26 | ||||
| -rw-r--r-- | src/stream_manager.cc | 52 | ||||
| -rw-r--r-- | src/stream_manager.h | 6 |
3 files changed, 56 insertions, 28 deletions
diff --git a/src/gpgpusim_entrypoint.cc b/src/gpgpusim_entrypoint.cc index 6271f79..3aabb02 100644 --- a/src/gpgpusim_entrypoint.cc +++ b/src/gpgpusim_entrypoint.cc @@ -89,13 +89,12 @@ bool g_sim_done = true; void *gpgpu_sim_thread_concurrent(void*) { // concurrent kernel execution simulation thread - do { if(g_debug_execution >= 3) { printf("GPGPU-Sim: *** simulation thread starting and spinning waiting for work ***\n"); fflush(stdout); } - while( g_stream_manager->empty() && !g_sim_done ) + while( g_stream_manager->empty_protected() && !g_sim_done ) ; if(g_debug_execution >= 3) { printf("GPGPU-Sim: ** START simulation thread (detected work) **\n"); @@ -110,23 +109,14 @@ void *gpgpu_sim_thread_concurrent(void*) g_the_gpu->init(); do { // check if a kernel has completed - unsigned grid_uid = g_the_gpu->finished_kernel(); - if( grid_uid ){ - g_stream_manager->register_finished_kernel(grid_uid); - g_the_gpu->print_stats(); - } - // launch operation on device if one is pending and can be run - stream_operation op = g_stream_manager->front(); - op.do_operation(g_the_gpu); - - // simulate a clock cycle on the GPU - if( g_the_gpu->active() ) { - g_the_gpu->cycle(); - sim_cycles = true; - g_the_gpu->deadlock_check(); - } - active = g_the_gpu->active() || !g_stream_manager->empty(); + g_stream_manager->operation(&sim_cycles); + if( g_the_gpu->active() ) { + g_the_gpu->cycle(); + sim_cycles = true; + g_the_gpu->deadlock_check(); + } + active=g_the_gpu->active() || !g_stream_manager->empty_protected(); } while( active ); if(g_debug_execution >= 3) { printf("GPGPU-Sim: ** STOP simulation thread (no work) **\n"); diff --git a/src/stream_manager.cc b/src/stream_manager.cc index 85778c9..06fa13e 100644 --- a/src/stream_manager.cc +++ b/src/stream_manager.cc @@ -110,6 +110,7 @@ void CUstream_st::print(FILE *fp) pthread_mutex_unlock(&m_lock); } + void stream_operation::do_operation( gpgpu_sim *gpu ) { if( is_noop() ) @@ -195,24 +196,50 @@ stream_manager::stream_manager( gpgpu_sim *gpu, bool cuda_launch_blocking ) pthread_mutex_init(&m_lock,NULL); } -void stream_manager::register_finished_kernel( unsigned grid_uid ) +void stream_manager::operation( bool * sim) +{ + bool active=false; + pthread_mutex_lock(&m_lock); + bool check=check_finished_kernel(); + if(check) m_gpu->print_stats(); + stream_operation op =front(); + op.do_operation( m_gpu ); + pthread_mutex_unlock(&m_lock); + //pthread_mutex_lock(&m_lock); + // simulate a clock cycle on the GPU + +} + +bool stream_manager::check_finished_kernel() +{ + + unsigned grid_uid = m_gpu->finished_kernel(); + bool check=register_finished_kernel(grid_uid); + return check; + +} + +bool stream_manager::register_finished_kernel(unsigned grid_uid) { // called by gpu simulation thread - pthread_mutex_lock(&m_lock); + if(grid_uid > 0){ CUstream_st *stream = m_grid_id_to_stream[grid_uid]; kernel_info_t *kernel = stream->front().get_kernel(); assert( grid_uid == kernel->get_uid() ); stream->record_next_done(); m_grid_id_to_stream.erase(grid_uid); delete kernel; - pthread_mutex_unlock(&m_lock); + return true; + }else{ + return false; + } + return false; } stream_operation stream_manager::front() { // called by gpu simulation thread stream_operation result; - pthread_mutex_lock(&m_lock); if( concurrent_streams_empty() ) m_service_stream_zero = true; if( m_service_stream_zero ) { @@ -241,7 +268,6 @@ stream_operation stream_manager::front() } } } - pthread_mutex_unlock(&m_lock); return result; } @@ -285,25 +311,35 @@ bool stream_manager::concurrent_streams_empty() return result; } -bool stream_manager::empty() +bool stream_manager::empty_protected() { bool result = true; pthread_mutex_lock(&m_lock); + if( !concurrent_streams_empty() ) + result = false; + if( !m_stream_zero.empty() ) + result = false; + pthread_mutex_unlock(&m_lock); + return result; +} + +bool stream_manager::empty() +{ + bool result = true; if( !concurrent_streams_empty() ) result = false; if( !m_stream_zero.empty() ) result = false; - pthread_mutex_unlock(&m_lock); return result; } + void stream_manager::print( FILE *fp) { pthread_mutex_lock(&m_lock); print_impl(fp); pthread_mutex_unlock(&m_lock); } - void stream_manager::print_impl( FILE *fp) { fprintf(fp,"GPGPU-Sim API: Stream Manager State\n"); diff --git a/src/stream_manager.h b/src/stream_manager.h index 23867f1..a30e21b 100644 --- a/src/stream_manager.h +++ b/src/stream_manager.h @@ -235,15 +235,17 @@ private: class stream_manager { public: stream_manager( gpgpu_sim *gpu, bool cuda_launch_blocking ); - void register_finished_kernel( unsigned grid_uid ); + bool register_finished_kernel(unsigned grid_uid ); + bool check_finished_kernel( ); stream_operation front(); void add_stream( CUstream_st *stream ); void destroy_stream( CUstream_st *stream ); bool concurrent_streams_empty(); + bool empty_protected(); bool empty(); void print( FILE *fp); void push( stream_operation op ); - + void operation(bool * sim); private: void print_impl( FILE *fp); |
