File: tool_available_search.c

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (127 lines) | stat: -rw-r--r-- 4,360 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// RUN: %clang %flags -shared -fPIC %s -o %T/first_tool.so
// RUN: %clang %flags -DTOOL -DSECOND_TOOL -shared -fPIC %s -o %T/second_tool.so
// RUN: %clang %flags -DTOOL -DTHIRD_TOOL -shared -fPIC %s -o %T/third_tool.so
// RUN: %libomp-compile -DCODE
// RUN: env OMP_TOOL_LIBRARIES=%T/non_existing_file.so:%T/first_tool.so:%T/second_tool.so:%T/third_tool.so \
// RUN: OMP_TOOL_VERBOSE_INIT=stdout %libomp-run | FileCheck %s -DPARENTPATH=%T

// REQUIRES: ompt

/*
 *  This file contains code for three OMPT shared library tool to be 
 *  loaded and the code for the OpenMP executable. 
 *  No option enables code for the first shared library 
 *  (without an implementation of ompt_start_tool) during compilation
 *  -DTOOL -DSECOND_TOOL enables the code for the second tool during compilation
 *  -DTOOL -DTHIRD_TOOL enables the code for the third tool during compilation
 *  -DCODE enables the code for the executable during compilation
 */

// CHECK: ----- START LOGGING OF TOOL REGISTRATION -----
// CHECK-NEXT: Search for OMP tool in current address space... Failed.
// CHECK-NEXT: Searching tool libraries...
// CHECK-NEXT: OMP_TOOL_LIBRARIES = [[PARENTPATH]]/non_existing_file.so
// CHECK-SAME: [[PARENTPATH]]/first_tool.so
// CHECK-SAME: [[PARENTPATH]]/second_tool.so
// CHECK-SAME: [[PARENTPATH]]/third_tool.so
// CHECK-NEXT: Opening [[PARENTPATH]]/non_existing_file.so... Failed:
// CHECK-SAME: [[PARENTPATH]]/non_existing_file.so: cannot open shared object
// CHECK-SAME: file: No such file or directory
// CHECK-NEXT: Opening [[PARENTPATH]]/first_tool.so... Success.
// CHECK-NEXT: Searching for ompt_start_tool in
// CHECK-SAME: [[PARENTPATH]]/first_tool.so... Failed:
// CHECK-SAME: [[PARENTPATH]]/first_tool.so: undefined symbol: ompt_start_tool
// CHECK-NEXT: Opening [[PARENTPATH]]/second_tool.so... Success.
// CHECK-NEXT: Searching for ompt_start_tool in
// CHECK-SAME: [[PARENTPATH]]/second_tool.so... 0: Do not initialize tool
// CHECK-NEXT: Found but not using the OMPT interface.
// CHECK-NEXT: Continuing search...
// CHECK-NEXT: Opening [[PARENTPATH]]/third_tool.so... Success.
// CHECK-NEXT: Searching for ompt_start_tool in
// CHECK-SAME: [[PARENTPATH]]/third_tool.so... 0: Do initialize tool
// CHECK-NEXT: Success.
// CHECK-NEXT: Tool was started and is using the OMPT interface.
// CHECK-NEXT: ----- END LOGGING OF TOOL REGISTRATION -----

// Check if libomp supports the callbacks for this test.

// CHECK-NOT: {{^}}0: Could not register callback 
// CHECK: {{^}}0: Tool initialized
// CHECK: {{^}}0: ompt_event_thread_begin
// CHECK-DAG: {{^}}0: ompt_event_thread_begin
// CHECK-DAG: {{^}}0: control_tool()=-1
// CHECK: {{^}}0: Tool finalized


#ifdef CODE
#include "stdio.h"
#include "omp.h"
#include "omp-tools.h"

int main()
{
  #pragma omp parallel num_threads(2)
  {
    #pragma omp master
    {
      int result = omp_control_tool(omp_control_tool_start, 0, NULL);
      printf("0: control_tool()=%d\n", result);
    }
  }


  return 0;
}

#endif /* CODE */

#ifdef TOOL

#include <omp-tools.h>
#include "stdio.h"

#ifdef SECOND_TOOL
// The second tool has an implementation of ompt_start_tool that returns NULL
ompt_start_tool_result_t* ompt_start_tool(
  unsigned int omp_version,
  const char *runtime_version)
{
  printf("0: Do not initialize tool\n");
  return NULL;
}
#elif defined(THIRD_TOOL)
// The third tool has an implementation of ompt_start_tool that returns a 
// pointer to a valid instance of ompt_start_tool_result_t

static void
on_ompt_callback_thread_begin(
  ompt_thread_t thread_type,
  ompt_data_t *thread_data)
{
  printf("0: ompt_event_thread_begin\n");
}

int ompt_initialize(ompt_function_lookup_t lookup, int initial_device_num,
                    ompt_data_t *tool_data) {
  ompt_set_callback_t ompt_set_callback = (ompt_set_callback_t) lookup("ompt_set_callback");
  ompt_set_callback(ompt_callback_thread_begin, (ompt_callback_t)on_ompt_callback_thread_begin);
  printf("0: Tool initialized\n");
  return 1;
}

void ompt_finalize(ompt_data_t *tool_data)
{
  printf("0: Tool finalized\n");
}

ompt_start_tool_result_t* ompt_start_tool(
  unsigned int omp_version,
  const char *runtime_version)
{
  printf("0: Do initialize tool\n");
  static ompt_start_tool_result_t ompt_start_tool_result = {&ompt_initialize,&ompt_finalize, 0};
  return &ompt_start_tool_result;
}
#endif

#endif /* TOOL */