diff --git a/cmake/OMPTChecks.cmake b/cmake/OMPTChecks.cmake index aba8368..efd29c9 100644 --- a/cmake/OMPTChecks.cmake +++ b/cmake/OMPTChecks.cmake @@ -34,12 +34,13 @@ include( CheckIncludeFile ) include( CheckTypeSize ) +include( CheckCXXSourceCompiles ) function( OMPT_HEADER_CHECK ) check_include_file( "omp-tools.h" HAVE_OMP_TOOLS_HEADER ) if( HAVE_OMP_TOOLS_HEADER ) - set( CMAKE_EXTRA_INCLUDE_FILES "omp-tools.h" ) + set( CMAKE_EXTRA_INCLUDE_FILES "omp-tools.h" ) # OpenMP 5.1 checks # Check for added callback values check_type_size( ompt_callback_target_emi OMPT_CALLBACK_TARGET_EMI LANGUAGE C ) @@ -47,6 +48,7 @@ function( OMPT_HEADER_CHECK ) check_type_size( ompt_callback_target_submit_emi OMPT_CALLBACK_TARGET_SUBMIT_EMI LANGUAGE C ) check_type_size( ompt_callback_target_map_emi OMPT_CALLBACK_TARGET_MAP_EMI LANGUAGE C ) check_type_size( ompt_callback_masked OMPT_CALLBACK_MASKED LANGUAGE C ) + check_type_size( ompt_callback_error OMPT_CALLBACK_ERROR LANGUAGE C ) # Check for new enum values # New fields in ompt_scope_endpoint_t check_type_size( ompt_scope_beginend OMPT_SCOPE_BEGINEND LANGUAGE C ) @@ -130,11 +132,29 @@ function( OMPT_HEADER_CHECK ) check_type_size( ompt_record_target_data_op_t OMPT_RECORD_TARGET_DATA_OP LANGUAGE C ) check_type_size( ompt_record_target_map_t OMPT_RECORD_TARGET_MAP LANGUAGE C ) check_type_size( ompt_record_target_kernel_t OMPT_RECORD_TARGET_KERNEL LANGUAGE C ) + + # Check for more niche cases + + # ompt_record_work_t uses wstype in OpenMP v5.0, work_type in OpenMP v5.1 and newer. + check_cxx_source_compiles( [[ + #include + int main( int argc, char** argv ) + { + ompt_record_work_t work; + return work.wstype; + } + ]] HAVE_OMPT_RECORD_WORK_WSTYPE ) + if( NOT HAVE_OMPT_RECORD_WORK_WSTYPE ) + set( HAVE_OMPT_RECORD_WORK_WSTYPE FALSE PARENT_SCOPE ) + else() + set( HAVE_OMPT_RECORD_WORK_WSTYPE TRUE PARENT_SCOPE ) + endif() set( CMAKE_EXTRA_INCLUDE_FILES ) endif() endfunction() + set( COMPILER_TOOLCHAIN GCC CACHE STRING "Set compiler toolchain. Will overwrite native CMake commands" ) function( OMPT_ADDITIONAL_CFLAGS ) diff --git a/src/tool-definitions.h.in b/src/tool-definitions.h.in index c3b6c6e..093ff48 100644 --- a/src/tool-definitions.h.in +++ b/src/tool-definitions.h.in @@ -37,7 +37,7 @@ #define FALSE 0 #define TRUE 1 -#define HAVE( X ) defined( HAVE_ ##X ) && HAVE_ ##X == TRUE +#define HAVE( X ) defined( HAVE_ ##X ) && ( HAVE_ ##X == TRUE ) /* OpenMP 5.1 */ #define HAVE_OMPT_CALLBACK_TARGET_EMI @HAVE_OMPT_CALLBACK_TARGET_EMI@ @@ -108,4 +108,6 @@ #define HAVE_OMPT_RECORD_TARGET_MAP @HAVE_OMPT_RECORD_TARGET_MAP@ #define HAVE_OMPT_RECORD_TARGET_KERNEL @HAVE_OMPT_RECORD_TARGET_KERNEL@ +#define HAVE_OMPT_RECORD_WORK_WSTYPE @HAVE_OMPT_RECORD_WORK_WSTYPE@ + #endif /* PRINTF_TOOL_DEFINITIONS_H */ diff --git a/src/tool.cpp b/src/tool.cpp index 1a75c5b..197d2cd 100644 --- a/src/tool.cpp +++ b/src/tool.cpp @@ -1575,6 +1575,422 @@ callback_buffer_request( int device_num, ompt_buffer_t** buffer, } } +static void +device_tracing_thread_begin( const char* invoker, const ompt_record_ompt_t* record ) +{ + atomic_printf( + "[%s] type = thread_begin | time = %lu | thread_id = %lu | target_id = %lu | thread_type = %s\n", + invoker, + record->time, + record->thread_id, + record->target_id, + thread2string( record->record.thread_begin.thread_type ).c_str() + ); +} + +static void +device_tracing_parallel_begin( const char* invoker, const ompt_record_ompt_t* record ) +{ + atomic_printf( + "[%s] type = parallel_begin | time = %lu | thread_id = %lu | target_id = %lu | " + "encountering_task_id = %lu | parallel_id = %lu | " + "requested_parallelism = %lu | flags = %s | codeptr_ra = %p\n", + invoker, + record->time, + record->thread_id, + record->target_id, + record->record.parallel_begin.encountering_task_id, + record->record.parallel_begin.parallel_id, + record->record.parallel_begin.requested_parallelism, + parallel_flag2string( record->record.parallel_begin.flags ).c_str(), + record->record.parallel_begin.codeptr_ra + ); +} + +static void +device_tracing_parallel_end( const char* invoker, const ompt_record_ompt_t* record ) +{ + atomic_printf( + "[%s] type = parallel_end | time = %lu | thread_id = %lu | target_id = %lu | " + "encountering_task_id = %lu | parallel_id = %lu | flags = %s | codeptr_ra = %p\n", + invoker, + record->time, + record->thread_id, + record->target_id, + record->record.parallel_end.encountering_task_id, + record->record.parallel_end.parallel_id, + parallel_flag2string( record->record.parallel_end.flags ).c_str(), + record->record.parallel_end.codeptr_ra + ); +} + +static void +device_tracing_work( const char* invoker, const ompt_record_ompt_t* record ) +{ + atomic_printf( + "[%s] type = work | time = %lu | thread_id = %lu | target_id = %lu | " + "work_type = %s | endpoint = %s | parallel_id = %lu | task_id = %lu | count = %lu | " + "codeptr_ra = %p\n", + invoker, + record->time, + record->thread_id, + record->target_id, +#if HAVE( OMPT_RECORD_WORK_WSTYPE ) + work2string( record->record.work.wstype ).c_str(), +#else + work2string( record->record.work.work_type ).c_str(), +#endif + endpoint2string( record->record.work.endpoint ).c_str(), + record->record.work.parallel_id, + record->record.work.task_id, + record->record.work.count, + record->record.work.codeptr_ra + ); +} + +static void +device_tracing_dispatch( const char* invoker, const ompt_record_ompt_t* record ) +{ + atomic_printf( + "[%s] type = dispatch | time = %lu | thread_id = %lu | target_id = %lu | " + "parallel_id = %lu | task_id = %lu | kind = %s | instance = %lu\n", + invoker, + record->time, + record->thread_id, + record->target_id, + record->record.dispatch.parallel_id, + record->record.dispatch.task_id, + dispatch2string( record->record.dispatch.kind ).c_str(), + record->record.dispatch.instance.value + ); +} + +static void +device_tracing_task_create( const char* invoker, const ompt_record_ompt_t* record ) +{ + atomic_printf( + "[%s] type = task_create | time = %lu | thread_id = %lu | target_id = %lu | " + "encountering_task_id = %lu | new_task_id = %lu | flags = %s | has_dependences = %d | codeptr = %p\n", + invoker, + record->time, + record->thread_id, + record->target_id, + record->record.task_create.encountering_task_id, + record->record.task_create.new_task_id, + task_flag2string( record->record.task_create.flags ).c_str(), + record->record.task_create.has_dependences, + record->record.task_create.codeptr_ra + ); +} + +static void +device_tracing_dependences( const char* invoker, const ompt_record_ompt_t* record ) +{ + atomic_printf( + "[%s] type = dependences | time = %lu | thread_id = %lu | target_id = %lu | " + "task_id = %lu | dep.variable.value = %lu | dep.dependence_type = %s | ndeps = %lu\n", + invoker, + record->time, + record->thread_id, + record->target_id, + record->record.dependences.task_id, + record->record.dependences.dep.variable.value, + dependence_type2string( record->record.dependences.dep.dependence_type ).c_str(), + record->record.dependences.ndeps + ); +} + +static void +device_tracing_task_schedule( const char* invoker, const ompt_record_ompt_t* record ) +{ + atomic_printf( + "[%s] type = task_schedule | time = %lu | thread_id = %lu | target_id = %lu | " + "prior_task_id = %lu | prior_task_status = %s | next_task_id = %lu\n", + invoker, + record->time, + record->thread_id, + record->target_id, + record->record.task_schedule.prior_task_id, + task_status2string( record->record.task_schedule.prior_task_status ).c_str(), + record->record.task_schedule.next_task_id + ); +} + +static void +device_tracing_implicit_task( const char* invoker, const ompt_record_ompt_t* record ) +{ + atomic_printf( + "[%s] type = implicit_task | time = %lu | thread_id = %lu | target_id = %lu | " + "endpoint = %s | parallel_id = %lu | task_id = %lu | actual_parallelism = %u | index = %u | flags = %s\n", + invoker, + record->time, + record->thread_id, + record->target_id, + endpoint2string( record->record.implicit_task.endpoint ).c_str(), + record->record.implicit_task.parallel_id, + record->record.implicit_task.task_id, + record->record.implicit_task.actual_parallelism, + record->record.implicit_task.index, + task_flag2string( record->record.implicit_task.flags ).c_str() + ); +} + +#if HAVE( OMPT_CALLBACK_MASKED ) +static void +device_tracing_masked( const char* invoker, const ompt_record_ompt_t* record ) +{ + atomic_printf( + "[%s] type = masked | time = %lu | thread_id = %lu | target_id = %lu | " + "endpoint = %s | parallel_id = %lu | task_id = %lu | codeptr_ra = %p\n", + invoker, + record->time, + record->thread_id, + record->target_id, + endpoint2string( record->record.masked.endpoint ).c_str(), + record->record.masked.parallel_id, + record->record.masked.task_id, + record->record.masked.codeptr_ra + ); +} +#endif + +static void +device_tracing_sync_region( const char* invoker, const ompt_record_ompt_t* record ) +{ + atomic_printf( + "[%s] type = sync_region | time = %lu | thread_id = %lu | target_id = %lu | " + "kind = %s | endpoint = %s | parallel_id = %lu | task_id = %lu | codeptr_ra = %p\n", + invoker, + record->time, + record->thread_id, + record->target_id, + sync2string( record->record.sync_region.kind ).c_str(), + endpoint2string( record->record.sync_region.endpoint ).c_str(), + record->record.sync_region.parallel_id, + record->record.sync_region.task_id, + record->record.sync_region.codeptr_ra + ); +} + +static void +device_tracing_mutex_acquire( const char* invoker, const ompt_record_ompt_t* record ) +{ + atomic_printf( + "[%s] type = mutex_acquire | time = %lu | thread_id = %lu | target_id = %lu | " + "kind = %s | hint = %u | impl = %u | wait_id = %lu | codeptr_ra = %p\n", + invoker, + record->time, + record->thread_id, + record->target_id, + mutex2string( record->record.mutex_acquire.kind ).c_str(), + record->record.mutex_acquire.hint, + record->record.mutex_acquire.impl, + record->record.mutex_acquire.wait_id, + record->record.mutex_acquire.codeptr_ra + ); +} + +static void +device_tracing_mutex_acquired( const char* invoker, const ompt_record_ompt_t* record ) +{ + atomic_printf( + "[%s] type = mutex_acquired | time = %lu | thread_id = %lu | target_id = %lu | " + "kind = %s | wait_id = %lu | codeptr_ra = %p\n", + invoker, + record->time, + record->thread_id, + record->target_id, + record->record.mutex.kind, + record->record.mutex.wait_id, + record->record.mutex.codeptr_ra + ); +} + +static void +device_tracing_mutex_released( const char* invoker, const ompt_record_ompt_t* record ) +{ + atomic_printf( + "[%s] type = mutex_released | time = %lu | thread_id = %lu | target_id = %lu | ", + "kind = %s | wait_id = %lu | codeptr_ra = %p\n", + invoker, + record->time, + record->thread_id, + record->target_id, + record->record.mutex.kind, + record->record.mutex.wait_id, + record->record.mutex.codeptr_ra + ); +} + +static void +device_tracing_nest_lock( const char* invoker, const ompt_record_ompt_t* record ) +{ + atomic_printf( + "[%s] type = nest_lock | time = %lu | thread_id = %lu | target_id = %lu | " + "endpoint = %s | wait_id = %lu | codeptr_ra = %p\n", + invoker, + record->time, + record->thread_id, + record->target_id, + endpoint2string( record->record.nest_lock.endpoint ).c_str(), + record->record.nest_lock.wait_id, + record->record.nest_lock.codeptr_ra + ); +} + +static void +device_tracing_flush( const char* invoker, const ompt_record_ompt_t* record ) +{ + atomic_printf( + "[%s] type = flush | time = %lu | thread_id = %lu | target_id = %lu | codeptr_ra = %p\n", + invoker, + record->time, + record->thread_id, + record->target_id, + record->record.flush.codeptr_ra + ); +} + +static void +device_tracing_cancel( const char* invoker, const ompt_record_ompt_t* record ) +{ + atomic_printf( + "[%s] type = cancel | time = %lu | thread_id = %lu | target_id = %lu | " + "task_id = %lu | flags = %s | codeptr_ra = %p\n", + invoker, + record->time, + record->thread_id, + record->target_id, + record->record.cancel.task_id, + cancel2string( record->record.cancel.flags ).c_str(), + record->record.cancel.codeptr_ra + ); +} + +static void +device_tracing_control_tool( const char* invoker, const ompt_record_ompt_t* record ) +{ + atomic_printf( + "[%s] type = control_tool | time = %lu | thread_id = %lu | target_id = %lu | " + "command = %lu | modifier = %lu | codeptr_ra = %p\n", + invoker, + record->time, + record->thread_id, + record->target_id, + record->record.control_tool.command, + record->record.control_tool.modifier, + record->record.control_tool.codeptr_ra + ); +} + +static void +device_tracing_error( const char* invoker, const ompt_record_ompt_t* record ) +{ + // Not implemented by some runtimes, e.g. LLVM 20.1.8. Since it's hard to check + // for, ignore until implemented by some runtimes. +} + +void +device_tracing_target( const char* invoker, const ompt_record_ompt_t* record ) +{ +#if HAVE( OMPT_RECORD_TARGET_EMI ) + ompt_record_target_emi_t target = record->record.target_emi; +#elif HAVE( OMPT_RECORD_TARGET ) + ompt_record_target_t target = record->record.target; +#endif + atomic_printf( "[%s] type = target | time = %lu | thread_id = %lu | target_id = %lu | kind = %s | " + "endpoint = %s | device_num = %d | task_id = %lu | target_id = %lu | codeptr_ra = %p\n", + invoker, + record->time, + record->thread_id, + record->target_id, + target2string( target.kind ).c_str(), + endpoint2string( target.endpoint ).c_str(), + target.device_num, + target.task_id, + target.target_id, + target.codeptr_ra ); +} + +static void +device_tracing_target_data_op( const char* invoker, const ompt_record_ompt_t* record ) +{ +#if HAVE( OMPT_RECORD_TARGET_DATA_OP_EMI ) + ompt_record_target_data_op_emi_t data_op = record->record.target_data_op_emi; +#elif HAVE( OMPT_RECORD_TARGET_DATA_OP ) + ompt_record_target_data_op_t data_op = record->record.target_data_op; +#endif + atomic_printf( "[%s] type = target_data_op | time = %lu | thread_id = %lu | target_id = %lu | host_op_id = %lu | " + "optype = %s | src_addr = %p | src_device_num = %d | dest_addr = %p | " + "dest_device_num = %d | bytes = %lu | end_time = %lu | codeptr_ra = %p\n", + invoker, + record->time, + record->thread_id, + record->target_id, + data_op.host_op_id, + data_op2string( data_op.optype ).c_str(), + data_op.src_addr, + data_op.src_device_num, + data_op.dest_addr, + data_op.dest_device_num, + data_op.bytes, + data_op.end_time, + data_op.codeptr_ra ); +} + +void +device_tracing_target_map( const char* invoker, const ompt_record_ompt_t* record ) +{ +#if HAVE( OMPT_RECORD_TARGET_MAP_EMI ) + ompt_record_target_map_emi_t map = record->record.target_map_emi; +#elif HAVE( OMPT_RECORD_TARGET_MAP ) + ompt_record_target_map_t map = record->record.target_map; +#endif + atomic_printf( "[%s] type = target_map | time = %lu | thread_id = %lu | target_id = %lu | target_id = %lu | " + "nitems = %u | codeptr_ra = %p\n", + invoker, + record->time, + record->thread_id, + record->target_id, + map.target_id, + map.nitems, + map.codeptr_ra ); + for ( unsigned int i = 0; i < map.nitems; ++i ) + { + atomic_printf( + "[%s] type = target_map | host_addr[%d] = %p | device_addr[%d] = %p | bytes[%d] = %lu | mapping_flags[%d] = %s\n", + invoker, + i, + map.host_addr[ i ], + i, + map.device_addr[ i ], + i, + map.bytes[ i ], + i, + map_flag2string( record->record.target_map.mapping_flags[ i ] ).c_str() ); + } +} + +static void +device_tracing_target_submit( const char* invoker, const ompt_record_ompt_t* record ) +{ +#if HAVE( OMPT_RECORD_TARGET_SUBMIT_EMI ) + ompt_record_target_submit_emi_t kernel = record->record.target_submit_emi; +#elif HAVE( OMPT_RECORD_TARGET_KERNEL ) + ompt_record_target_kernel_t kernel = record->record.target_kernel; +#endif + atomic_printf( "[%s] type = target_submit | time = %lu | thread_id = %lu | target_id = %lu | host_op_id = %lu | " + "requested_num_teams = %u | granted_num_teams = %u | end_time = %lu\n", + invoker, + record->time, + record->thread_id, + record->target_id, + kernel.host_op_id, + kernel.requested_num_teams, + kernel.granted_num_teams, + kernel.end_time ); +} + template void callback_buffer_complete( int device_num, @@ -1586,6 +2002,7 @@ callback_buffer_complete( int device_num, if constexpr ( mode == printf_mode::callback ) { print_function_name( __FUNCTION__ ); + return; } else if constexpr ( mode == printf_mode::callback_include_args ) { @@ -1596,6 +2013,7 @@ callback_buffer_complete( int device_num, bytes, begin, buffer_owned ); + return; } /* AMD implementation might return buffer complete callback to indicate buffer @@ -1624,123 +2042,99 @@ callback_buffer_complete( int device_num, ompt_id_t target_id; */ switch ( record->type ) { + case ompt_callback_thread_begin: + device_tracing_thread_begin( __FUNCTION__, record ); + break; + case ompt_callback_parallel_begin: + device_tracing_parallel_begin( __FUNCTION__, record ); + break; + case ompt_callback_parallel_end: + device_tracing_parallel_end( __FUNCTION__, record ); + break; + case ompt_callback_work: + device_tracing_work( __FUNCTION__, record ); + break; + case ompt_callback_dispatch: + device_tracing_dispatch( __FUNCTION__, record ); + break; + case ompt_callback_task_create: + device_tracing_task_create( __FUNCTION__, record ); + break; + case ompt_callback_dependences: + device_tracing_dependences( __FUNCTION__, record ); + break; + case ompt_callback_task_schedule: + device_tracing_task_schedule( __FUNCTION__, record ); + break; + case ompt_callback_implicit_task: + device_tracing_implicit_task( __FUNCTION__, record ); + break; +#if HAVE( OMPT_CALLBACK_MASKED ) + case ompt_callback_masked: + device_tracing_masked( __FUNCTION__, record ); + break; +#endif + case ompt_callback_sync_region: + device_tracing_sync_region( __FUNCTION__, record ); + break; + case ompt_callback_mutex_acquire: + device_tracing_mutex_acquire( __FUNCTION__, record ); + break; + case ompt_callback_mutex_acquired: + device_tracing_mutex_acquired( __FUNCTION__, record ); + break; + case ompt_callback_mutex_released: + device_tracing_mutex_released( __FUNCTION__, record ); + break; + case ompt_callback_nest_lock: + device_tracing_nest_lock( __FUNCTION__, record ); + break; + case ompt_callback_flush: + device_tracing_flush( __FUNCTION__, record ); + break; + case ompt_callback_cancel: + device_tracing_cancel( __FUNCTION__, record ); + break; + case ompt_callback_control_tool: + device_tracing_control_tool( __FUNCTION__, record ); + break; +#if HAVE( OMPT_CALLBACK_ERROR ) + case ompt_callback_error: + device_tracing_error( __FUNCTION__, record ); + break; +#endif #if HAVE( OMPT_CALLBACK_TARGET ) case ompt_callback_target: #endif #if HAVE( OMPT_CALLBACK_TARGET_EMI ) case ompt_callback_target_emi: #endif - { -#if HAVE( OMPT_RECORD_TARGET_EMI ) - ompt_record_target_emi_t target = record->record.target_emi; -#elif HAVE( OMPT_RECORD_TARGET ) - ompt_record_target_t target = record->record.target; -#endif - atomic_printf( "[%s] time = %lu | thread_id = %lu | target_id = %lu | kind = %s | " - "endpoint = %s | device_num = %d | task_id = %lu | target_id = %lu | codeptr_ra = %p\n", - __FUNCTION__, - record->time, - record->thread_id, - record->target_id, - target2string( target.kind ).c_str(), - endpoint2string( target.endpoint ).c_str(), - target.device_num, - target.task_id, - target.target_id, - target.codeptr_ra ); + device_tracing_target( __FUNCTION__, record ); break; - } #if HAVE( OMPT_CALLBACK_TARGET_DATA_OP ) case ompt_callback_target_data_op: #endif #if HAVE( OMPT_CALLBACK_TARGET_DATA_OP_EMI ) case ompt_callback_target_data_op_emi: #endif - { -#if HAVE( OMPT_RECORD_TARGET_DATA_OP_EMI ) - ompt_record_target_data_op_emi_t data_op = record->record.target_data_op_emi; -#elif HAVE( OMPT_RECORD_TARGET_DATA_OP ) - ompt_record_target_data_op_t data_op = record->record.target_data_op; -#endif - atomic_printf( "[%s] time = %lu | thread_id = %lu | target_id = %lu | host_op_id = %lu | " - "optype = %s | src_addr = %p | src_device_num = %d | dest_addr = %p | " - "dest_device_num = %d | bytes = %lu | end_time = %lu | codeptr_ra = %p\n", - __FUNCTION__, - record->time, - record->thread_id, - record->target_id, - data_op.host_op_id, - data_op2string( data_op.optype ).c_str(), - data_op.src_addr, - data_op.src_device_num, - data_op.dest_addr, - data_op.dest_device_num, - data_op.bytes, - data_op.end_time, - data_op.codeptr_ra ); + device_tracing_target_data_op( __FUNCTION__, record ); break; - } #if HAVE( OMPT_CALLBACK_TARGET_MAP ) case ompt_callback_target_map: #endif #if HAVE( OMPT_CALLBACK_TARGET_MAP_EMI ) case ompt_callback_target_map_emi: #endif - { -#if HAVE( OMPT_RECORD_TARGET_MAP_EMI ) - ompt_record_target_map_emi_t map = record->record.target_map_emi; -#elif HAVE( OMPT_RECORD_TARGET_MAP ) - ompt_record_target_map_t map = record->record.target_map; -#endif - atomic_printf( "[%s] time = %lu | thread_id = %lu | target_id = %lu | target_id = %lu | " - "nitems = %u | codeptr_ra = %p\n", - __FUNCTION__, - record->time, - record->thread_id, - record->target_id, - map.target_id, - map.nitems, - map.codeptr_ra ); - for ( unsigned int i = 0; i < map.nitems; ++i ) - { - atomic_printf( - "[%s] host_addr[%d] = %p | device_addr[%d] = %p | bytes[%d] = %lu | mapping_flags[%d] = %s\n", - __FUNCTION__, - i, - map.host_addr[ i ], - i, - map.device_addr[ i ], - i, - map.bytes[ i ], - i, - map_flag2string( record->record.target_map.mapping_flags[ i ] ).c_str() ); - } + device_tracing_target_map( __FUNCTION__, record ); break; - } #if HAVE( OMPT_CALLBACK_TARGET_SUBMIT ) case ompt_callback_target_submit: #endif #if HAVE( OMPT_CALLBACK_TARGET_SUBMIT_EMI ) case ompt_callback_target_submit_emi: #endif - { -#if HAVE( OMPT_RECORD_TARGET_SUBMIT_EMI ) - ompt_record_target_submit_emi_t kernel = record->record.target_submit_emi; -#elif HAVE( OMPT_RECORD_TARGET_KERNEL ) - ompt_record_target_kernel_t kernel = record->record.target_kernel; -#endif - atomic_printf( "[%s] time = %lu | thread_id = %lu | target_id = %lu | host_op_id = %lu | " - "requested_num_teams = %u | granted_num_teams = %u | end_time = %lu\n", - __FUNCTION__, - record->time, - record->thread_id, - record->target_id, - kernel.host_op_id, - kernel.requested_num_teams, - kernel.granted_num_teams, - kernel.end_time ); + device_tracing_target_submit( __FUNCTION__, record ); break; - } default: assert( false && "Unexpected ompt_record_ompt_t type" ); } @@ -1822,114 +2216,100 @@ callback_device_initialize( int device_num, /* Register buffer events */ ompt_set_result_t result; - bool registration_success = false; + bool registration_success; + +#define ENABLE_DEVICE_TRACING_CALLBACK( CALLBACK_NAME, NEEDS_REGISTRATION_RESULT ) \ + do { \ + result = new_device->device_functions.set_trace_ompt( new_device->address, true, CALLBACK_NAME ); \ + if constexpr ( NEEDS_REGISTRATION_RESULT ) \ + { \ + registration_success = result == ompt_set_always; \ + } \ + if constexpr ( mode > printf_mode::disable_output ) \ + { \ + atomic_printf( "[%s] device_num = %d | %s = %s\n", \ + __FUNCTION__, \ + device_num, \ + #CALLBACK_NAME, \ + set_result2string( result ).c_str() ); \ + } \ + } while ( 0 ) /* ompt_callback_target[_emi] */ + registration_success = false; #if HAVE( OMPT_CALLBACK_TARGET_EMI ) - result = new_device->device_functions.set_trace_ompt( new_device->address, true, ompt_callback_target_emi ); - registration_success = result == ompt_set_always; - if constexpr ( mode > printf_mode::disable_output ) - { - atomic_printf( "[%s] device_num = %d | ompt_callback_target_emi = %s\n", - __FUNCTION__, - device_num, - set_result2string( result ).c_str() ); - } + ENABLE_DEVICE_TRACING_CALLBACK( ompt_callback_target_emi, true ); #endif #if HAVE( OMPT_CALLBACK_TARGET ) if ( !registration_success ) { - result = new_device->device_functions.set_trace_ompt( new_device->address, true, ompt_callback_target ); - if constexpr ( mode > printf_mode::disable_output ) { - atomic_printf( "[%s] device_num = %d | ompt_callback_target = %s\n", - __FUNCTION__, - device_num, - set_result2string( result ).c_str() ); - } + ENABLE_DEVICE_TRACING_CALLBACK( ompt_callback_target, false ); } #endif /* ompt_callback_target_data_op[_emi] */ registration_success = false; #if HAVE( OMPT_CALLBACK_TARGET_DATA_OP_EMI ) - result = new_device->device_functions.set_trace_ompt( new_device->address, true, ompt_callback_target_data_op_emi ); - registration_success = result == ompt_set_always; - if constexpr ( mode > printf_mode::disable_output ) - { - atomic_printf( "[%s] device_num = %d | ompt_callback_target_data_op_emi = %s\n", - __FUNCTION__, - device_num, - set_result2string( result ).c_str() ); - } + ENABLE_DEVICE_TRACING_CALLBACK( ompt_callback_target_data_op_emi, true ); #endif #if HAVE( OMPT_CALLBACK_TARGET_DATA_OP ) if ( !registration_success ) { - result = new_device->device_functions.set_trace_ompt( new_device->address, true, ompt_callback_target_data_op ); - if constexpr ( mode > printf_mode::disable_output ) { - if ( result != ompt_set_error ) - { - atomic_printf( "[%s] device_num = %d | ompt_callback_target_data_op = %s\n", - __FUNCTION__, - device_num, - set_result2string( result ).c_str() ); - } - } + ENABLE_DEVICE_TRACING_CALLBACK( ompt_callback_target_data_op, false ); } #endif /* ompt_callback_target_map[_emi] */ registration_success = false; #if HAVE( OMPT_CALLBACK_TARGET_MAP_EMI ) - result = new_device->device_functions.set_trace_ompt( new_device->address, true, ompt_callback_target_map_emi ); - registration_success = result == ompt_set_always; - if constexpr ( mode > printf_mode::disable_output ) - { - atomic_printf( "[%s] device_num = %d | ompt_callback_target_map_emi = %s\n", - __FUNCTION__, - device_num, - set_result2string( result ).c_str() ); - } + ENABLE_DEVICE_TRACING_CALLBACK( ompt_callback_target_map_emi, true ); #endif #if HAVE( OMPT_CALLBACK_TARGET_MAP ) if ( !registration_success ) { - result = new_device->device_functions.set_trace_ompt( new_device->address, true, ompt_callback_target_map ); - if constexpr ( mode > printf_mode::disable_output ) { - atomic_printf( "[%s] device_num = %d | ompt_callback_target_map = %s\n", - __FUNCTION__, - device_num, - set_result2string( result ).c_str() ); - } + ENABLE_DEVICE_TRACING_CALLBACK( ompt_callback_target_map, false ); } #endif /* ompt_callback_target_submit[_emi] */ registration_success = false; #if HAVE( OMPT_CALLBACK_TARGET_SUBMIT_EMI ) - result = new_device->device_functions.set_trace_ompt( new_device->address, true, ompt_callback_target_submit_emi ); - registration_success = result == ompt_set_always; - if constexpr ( mode > printf_mode::disable_output ) - { - atomic_printf( "[%s] device_num = %d | ompt_callback_target_submit_emi = %s\n", - __FUNCTION__, - device_num, - set_result2string( result ).c_str() ); - } + ENABLE_DEVICE_TRACING_CALLBACK( ompt_callback_target_submit_emi, true ); #endif #if HAVE( OMPT_CALLBACK_TARGET_SUBMIT ) if ( !registration_success ) { - result = new_device->device_functions.set_trace_ompt( new_device->address, true, - ompt_callback_target_submit ); - if constexpr ( mode > printf_mode::disable_output ) { - atomic_printf( "[%s] device_num = %d | ompt_callback_target_submit = %s\n", - __FUNCTION__, - device_num, - set_result2string( result ).c_str() ); - } + ENABLE_DEVICE_TRACING_CALLBACK( ompt_callback_target_submit, false ); } #endif + /* Host side callbacks */ + ENABLE_DEVICE_TRACING_CALLBACK( ompt_callback_thread_begin, false ); + /* OpenMP 6.0, p.728, l.16: If type is ompt_callback_thread_end then the value of record is undefined. */ + // ENABLE_DEVICE_TRACING_CALLBACK( ompt_callback_thread_end, false ); + ENABLE_DEVICE_TRACING_CALLBACK( ompt_callback_parallel_begin, false ); + ENABLE_DEVICE_TRACING_CALLBACK( ompt_callback_parallel_end, false ); + ENABLE_DEVICE_TRACING_CALLBACK( ompt_callback_work, false ); + ENABLE_DEVICE_TRACING_CALLBACK( ompt_callback_dispatch, false ); + ENABLE_DEVICE_TRACING_CALLBACK( ompt_callback_task_create, false ); + ENABLE_DEVICE_TRACING_CALLBACK( ompt_callback_dependences, false ); + ENABLE_DEVICE_TRACING_CALLBACK( ompt_callback_task_schedule, false ); + ENABLE_DEVICE_TRACING_CALLBACK( ompt_callback_implicit_task, false ); +#if HAVE( OMPT_CALLBACK_MASKED ) + ENABLE_DEVICE_TRACING_CALLBACK( ompt_callback_masked, false ); +#endif + ENABLE_DEVICE_TRACING_CALLBACK( ompt_callback_sync_region, false ); + ENABLE_DEVICE_TRACING_CALLBACK( ompt_callback_mutex_acquire, false ); + ENABLE_DEVICE_TRACING_CALLBACK( ompt_callback_mutex_acquired, false ); + ENABLE_DEVICE_TRACING_CALLBACK( ompt_callback_mutex_released, false ); + ENABLE_DEVICE_TRACING_CALLBACK( ompt_callback_nest_lock, false ); + ENABLE_DEVICE_TRACING_CALLBACK( ompt_callback_flush, false ); + ENABLE_DEVICE_TRACING_CALLBACK( ompt_callback_cancel, false ); + ENABLE_DEVICE_TRACING_CALLBACK( ompt_callback_control_tool, false ); +#if HAVE( OMPT_CALLBACK_ERROR ) + ENABLE_DEVICE_TRACING_CALLBACK( ompt_callback_error, false ); +#endif + +#undef ENABLE_DEVICE_TRACING_CALLBACK if ( !new_device->device_functions.start_trace( new_device->address, &callback_buffer_request, &callback_buffer_complete ) ) { return; @@ -2516,7 +2896,7 @@ tool_initialize( ompt_function_lookup_t lookup, * ompt_callback_target_data_op_emi = 34, ADDED_51 * ompt_callback_target_submit_emi = 35, ADDED_51 * ompt_callback_target_map_emi = 36, ADDED_51 - * ompt_callback_error = 37 + * ompt_callback_error = 37, ADDED_51 * } ompt_callbacks_t; */ /* Register callbacks for the host side */