38#define ompt_get_callback_success 1
39#define ompt_get_callback_failure 0
41#define no_tool_present 0
43#define OMPT_API_ROUTINE static
46#define OMPT_STR_MATCH(haystack, needle) (!strcasecmp(haystack, needle))
53#define OMPT_VERBOSE_INIT_PRINT(...) \
55 fprintf(verbose_file, __VA_ARGS__)
56#define OMPT_VERBOSE_INIT_CONTINUED_PRINT(...) \
58 fprintf(verbose_file, __VA_ARGS__)
64#define OMPT_GETENV secure_getenv
66#define OMPT_GETENV getenv
97#define ompt_state_macro(state, code) {#state, state},
99#undef ompt_state_macro
103#define kmp_mutex_impl_macro(name, id) {#name, name},
105#undef kmp_mutex_impl_macro
115#define OMPT_DLCLOSE(Lib) FreeLibrary(Lib)
119#define OMPT_DLCLOSE(Lib) dlclose(Lib)
152 const char *runtime_version) {
158 ret = start_tool(omp_version, runtime_version);
163#elif OMPT_HAVE_WEAK_ATTRIBUTE
170ompt_start_tool(
unsigned int omp_version,
const char *runtime_version) {
179 ret = next_tool(omp_version, runtime_version);
192#pragma comment(lib, "psapi.lib")
195#define NUM_MODULES 128
198ompt_tool_windows(
unsigned int omp_version,
const char *runtime_version) {
202 HANDLE process = GetCurrentProcess();
203 modules = (HMODULE *)malloc(NUM_MODULES *
sizeof(HMODULE));
207 printf(
"ompt_tool_windows(): looking for ompt_start_tool\n");
209 if (!EnumProcessModules(process, modules, NUM_MODULES *
sizeof(HMODULE),
216 new_size = needed /
sizeof(HMODULE);
219 printf(
"ompt_tool_windows(): resize buffer to %d bytes\n", needed);
221 modules = (HMODULE *)realloc(modules, needed);
223 if (!EnumProcessModules(process, modules, needed, &needed)) {
229 (FARPROC &)ompt_tool_p = GetProcAddress(modules[
i],
"ompt_start_tool");
232 TCHAR modName[MAX_PATH];
233 if (GetModuleFileName(modules[
i], modName, MAX_PATH))
234 printf(
"ompt_tool_windows(): ompt_start_tool found in module %s\n",
238 return (*ompt_tool_p)(omp_version, runtime_version);
242 TCHAR modName[MAX_PATH];
243 if (GetModuleFileName(modules[
i], modName, MAX_PATH))
244 printf(
"ompt_tool_windows(): ompt_start_tool not found in module %s\n",
253#error Activation of OMPT is not supported on this platform.
262 const char *sep =
";";
264 const char *sep =
":";
272 ret = ompt_tool_darwin(omp_version, runtime_version);
273#elif OMPT_HAVE_WEAK_ATTRIBUTE
276 ret = ompt_tool_windows(omp_version, runtime_version);
278#error Activation of OMPT is not supported on this platform.
283 "Tool was started and is using the OMPT interface.\n");
290 const char *tool_libs =
OMPT_GETENV(
"OMP_TOOL_LIBRARIES");
303 void *
h = dlopen(fname, RTLD_LAZY);
313 char *error = dlerror();
318 "ompt_start_tool = NULL");
323 HMODULE
h = LoadLibrary(fname);
326 (
unsigned)GetLastError());
334 (
unsigned)GetLastError());
337#error Activation of OMPT is not supported on this platform.
340 ret = (*start_tool)(omp_version, runtime_version);
344 "Tool was started and is using the OMPT interface.\n");
349 "Found but not using the OMPT interface.\n");
369 const char *fname =
"libarcher.so";
371 "...searching tool libraries failed. Using archer tool.\n");
373 void *
h = dlopen(fname, RTLD_LAZY);
379 ret = (*start_tool)(omp_version, runtime_version);
383 "Tool was started and is using the OMPT interface.\n");
385 "----- END LOGGING OF TOOL REGISTRATION -----\n");
390 "Found but not using the OMPT interface.\n");
407 static int ompt_pre_initialized = 0;
409 if (ompt_pre_initialized)
412 ompt_pre_initialized = 1;
417 const char *ompt_env_var = getenv(
"OMP_TOOL");
420 if (!ompt_env_var || !strcmp(ompt_env_var,
""))
427 const char *ompt_env_verbose_init = getenv(
"OMP_TOOL_VERBOSE_INIT");
430 if (ompt_env_verbose_init && strcmp(ompt_env_verbose_init,
"") &&
443 printf(
"ompt_pre_init(): tool_setting = %d\n", tool_setting);
445 switch (tool_setting) {
464 "Warning: OMP_TOOL has invalid value \"%s\".\n"
465 " legal values are (NULL,\"\",\"disabled\","
473 printf(
"ompt_pre_init(): ompt_enabled = %d\n",
ompt_enabled.enabled);
477#define omp_initial_device -1
483 static int ompt_post_initialized = 0;
485 if (ompt_post_initialized)
488 ompt_post_initialized = 1;
506 ompt_set_thread_state(root_thread, ompt_state_overhead);
507 __ompt_task_init(root_thread->th.th_current_task, 0);
513 ompt_data_t *task_data =
nullptr;
514 ompt_data_t *parallel_data =
nullptr;
519 ompt_scope_begin, parallel_data, task_data, 1, 1, ompt_task_initial);
522 ompt_set_thread_state(root_thread, ompt_state_work_serial);
552 const char **next_state_name) {
556 for (
i = 0;
i < len - 1;
i++) {
569 const char **next_impl_name) {
570 const static int len =
573 for (
i = 0;
i < len - 1;
i++) {
588 ompt_callback_t callback) {
591#define ompt_event_macro(event_name, callback_type, event_id) \
593 ompt_callbacks.ompt_callback(event_name) = (callback_type)callback; \
594 ompt_enabled.event_name = (callback != 0); \
596 return ompt_event_implementation_status(event_name); \
598 return ompt_set_always;
602#undef ompt_event_macro
605 return ompt_set_error;
610 ompt_callback_t *callback) {
616#define ompt_event_macro(event_name, callback_type, event_id) \
618 ompt_callback_t mycb = \
619 (ompt_callback_t)ompt_callbacks.ompt_callback(event_name); \
620 if (ompt_enabled.event_name && mycb) { \
622 return ompt_get_callback_success; \
624 return ompt_get_callback_failure; \
629#undef ompt_event_macro
641 ompt_data_t **parallel_data,
651 return ompt_state_work_serial;
654 if (thread_state == ompt_state_undefined) {
655 thread_state = ompt_state_work_serial;
672 ompt_data_t **task_data,
673 ompt_frame_t **task_frame,
674 ompt_data_t **parallel_data,
679 task_frame, parallel_data, thread_num);
703#if !KMP_AFFINITY_SUPPORTED
706 if (!KMP_AFFINITY_CAPABLE())
708 return __kmp_affinity.num_masks;
715#if !KMP_AFFINITY_SUPPORTED
720 for (
int j = 0;
j < ids_size;
j++)
722 if (!KMP_AFFINITY_CAPABLE())
724 if (place_num < 0 || place_num >= (
int)__kmp_affinity.num_masks)
728 kmp_affin_mask_t *
mask = KMP_CPU_INDEX(__kmp_affinity.masks, place_num);
730 KMP_CPU_SET_ITERATE(
i,
mask) {
731 if ((!KMP_CPU_ISSET(
i, __kmp_affin_fullMask)) ||
732 (!KMP_CPU_ISSET(
i,
mask))) {
735 if (
count < ids_size)
739 if (ids_size >=
count) {
750#if !KMP_AFFINITY_SUPPORTED
758 if (!KMP_AFFINITY_CAPABLE())
762 if (thread == NULL || thread->th.th_current_place < 0)
764 return thread->th.th_current_place;
771#if !KMP_AFFINITY_SUPPORTED
777 int i, gtid, place_num, first_place, last_place, start,
end;
779 if (!KMP_AFFINITY_CAPABLE())
785 first_place = thread->th.th_first_place;
786 last_place = thread->th.th_last_place;
787 if (first_place < 0 || last_place < 0)
789 if (first_place <= last_place) {
796 if (
end - start <= place_nums_size)
797 for (
i = 0, place_num = start; place_num <=
end; ++place_num, ++
i) {
798 place_nums[
i] = place_num;
800 return end - start + 1;
811#if KMP_HAVE_SCHED_GETCPU
812 return sched_getcpu();
815 GetCurrentProcessorNumberEx(&pn);
816 return 64 * pn.Group + pn.Number;
868 ompt_id_t *target_id,
869 ompt_id_t *host_op_id) {
885#define ompt_interface_fn(fn) \
886 fn##_t fn##_f = fn; \
887 if (strcmp(s, #fn) == 0) \
888 return (ompt_interface_fn_t)fn##_f;
892#undef ompt_interface_fn
905#define provide_fn(fn) \
906 if (strcmp(s, #fn) == 0) \
907 return (ompt_interface_fn_t)fn;
914#define ompt_interface_fn(fn, type, code) \
915 if (strcmp(s, #fn) == 0) \
916 return (ompt_interface_fn_t)ompt_callbacks.ompt_callback(fn);
921#undef ompt_interface_fn
923 return (ompt_interface_fn_t)0;
static ompt_get_task_info_t ompt_get_task_info
static ompt_enumerate_states_t ompt_enumerate_states
static ompt_get_callback_t ompt_get_callback
static ompt_get_place_proc_ids_t ompt_get_place_proc_ids
static ompt_set_callback_t ompt_set_callback
static ompt_get_partition_place_nums_t ompt_get_partition_place_nums
static ompt_get_task_memory_t ompt_get_task_memory
static ompt_get_state_t ompt_get_state
static ompt_get_parallel_info_t ompt_get_parallel_info
static ompt_enumerate_mutex_impls_t ompt_enumerate_mutex_impls
A simple pure header implementation of VLA that aims to replace uses of actual VLA,...
void const char const char int ITT_FORMAT __itt_group_sync s
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 ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t new_size
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 mask
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 ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp end
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 ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t count
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 size
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 ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type size_t void ITT_FORMAT p const __itt_domain __itt_id __itt_string_handle const wchar_t size_t ITT_FORMAT lu const __itt_domain __itt_id __itt_relation __itt_id ITT_FORMAT p const wchar_t int ITT_FORMAT __itt_group_mark d int
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 ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function h
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 ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type type
void __kmp_internal_end_atexit(void)
#define __kmp_entry_gtid()
static kmp_info_t * __kmp_thread_from_gtid(int gtid)
union KMP_ALIGN_CACHE kmp_info kmp_info_t
char * __kmp_str_format(char const *format,...)
char * __kmp_str_token(char *str, char const *delim, char **buf)
void __kmp_str_free(char **str)
struct ompt_start_tool_result_t ompt_start_tool_result_t
int const __kmp_openmp_version
static FILE * verbose_file
_OMP_EXTERN void ompt_libomp_connect(ompt_start_tool_result_t *result)
This function is called by the libomptarget connector to assign callbacks already registered with lib...
kmp_mutex_impl_info_t kmp_mutex_impl_info[]
ompt_callbacks_active_t ompt_enabled
#define OMPT_VERBOSE_INIT_CONTINUED_PRINT(...)
#define ompt_interface_fn(fn)
#define kmp_mutex_impl_macro(name, id)
#define ompt_state_macro(state, code)
static ompt_start_tool_result_t * ompt_try_start_tool(unsigned int omp_version, const char *runtime_version)
#define OMPT_STR_MATCH(haystack, needle)
static ompt_data_t * ompt_get_target_task_data()
OMPT_API_ROUTINE int ompt_get_num_devices(void)
static void * ompt_tool_module
#define OMPT_VERBOSE_INIT_PRINT(...)
static void * ompt_archer_module
ompt_state_info_t ompt_state_info[]
#define omp_initial_device
OMPT_API_ROUTINE int ompt_get_proc_id(void)
int __kmp_control_tool(uint64_t command, uint64_t modifier, void *arg)
static ompt_interface_fn_t ompt_fn_lookup(const char *s)
#define OMPT_DLCLOSE(Lib)
static ompt_start_tool_result_t * libomptarget_ompt_result
Used to track the initializer and the finalizer provided by libomptarget.
OMPT_API_ROUTINE int ompt_get_num_places(void)
static ompt_interface_fn_t ompt_libomp_target_fn_lookup(const char *s)
Lookup function to query libomp callbacks registered by the tool.
#define ompt_get_callback_failure
static ompt_data_t * ompt_get_task_data()
OMPT_API_ROUTINE void ompt_finalize_tool(void)
OMPT_API_ROUTINE ompt_data_t * ompt_get_thread_data(void)
static ompt_start_tool_result_t * ompt_start_tool_result
int omp_get_num_devices(void)
#define ompt_event_macro(event_name, callback_type, event_id)
ompt_start_tool_result_t *(* ompt_start_tool_t)(unsigned int, const char *)
OMPT_API_ROUTINE uint64_t ompt_get_unique_id(void)
OMPT_API_ROUTINE int ompt_get_target_info(uint64_t *device_num, ompt_id_t *target_id, ompt_id_t *host_op_id)
ompt_callbacks_internal_t ompt_callbacks
OMPT_API_ROUTINE int ompt_get_num_procs(void)
OMPT_API_ROUTINE int ompt_get_place_num(void)
struct ompt_callbacks_internal_s ompt_callbacks_internal_t
struct ompt_callbacks_active_s ompt_callbacks_active_t
#define OMPT_WEAK_ATTRIBUTE
int __ompt_get_task_memory_internal(void **addr, size_t *size, int blocknum)
int __ompt_get_state_internal(ompt_wait_id_t *omp_wait_id)
ompt_data_t * __ompt_get_target_task_data()
int __ompt_get_task_info_internal(int ancestor_level, int *type, ompt_data_t **task_data, ompt_frame_t **task_frame, ompt_data_t **parallel_data, int *thread_num)
ompt_data_t * __ompt_get_task_data()
static uint64_t __ompt_get_unique_id_internal()
void __ompt_force_initialization()
ompt_data_t * __ompt_get_thread_data_internal()
int __ompt_get_parallel_info_internal(int ancestor_level, ompt_data_t **parallel_data, int *team_size)