Bump version to 19.1.0-rc3
[llvm-project.git] / offload / test / ompt / callbacks.h
blob95437d9cdcfb1f9bbf96903b6ca8e4690724111c
1 #include <assert.h>
2 #include <stdio.h>
3 #include <stdlib.h>
5 // Tool related code below
6 #include <omp-tools.h>
8 // For EMI callbacks
9 ompt_id_t next_op_id = 0x8000000000000001;
11 // OMPT callbacks
13 // Synchronous callbacks
14 static void on_ompt_callback_device_initialize(int device_num, const char *type,
15 ompt_device_t *device,
16 ompt_function_lookup_t lookup,
17 const char *documentation) {
18 printf("Callback Init: device_num=%d type=%s device=%p lookup=%p doc=%p\n",
19 device_num, type, device, lookup, documentation);
22 static void on_ompt_callback_device_finalize(int device_num) {
23 printf("Callback Fini: device_num=%d\n", device_num);
26 static void on_ompt_callback_device_load(int device_num, const char *filename,
27 int64_t offset_in_file,
28 void *vma_in_file, size_t bytes,
29 void *host_addr, void *device_addr,
30 uint64_t module_id) {
31 printf("Callback Load: device_num:%d module_id:%lu filename:%s host_adddr:%p "
32 "device_addr:%p bytes:%lu\n",
33 device_num, module_id, filename, host_addr, device_addr, bytes);
36 static void on_ompt_callback_target_data_op(
37 ompt_id_t target_id, ompt_id_t host_op_id, ompt_target_data_op_t optype,
38 void *src_addr, int src_device_num, void *dest_addr, int dest_device_num,
39 size_t bytes, const void *codeptr_ra) {
40 assert(codeptr_ra != 0 && "Unexpected null codeptr");
41 printf(" Callback DataOp: target_id=%lu host_op_id=%lu optype=%d src=%p "
42 "src_device_num=%d "
43 "dest=%p dest_device_num=%d bytes=%lu code=%p\n",
44 target_id, host_op_id, optype, src_addr, src_device_num, dest_addr,
45 dest_device_num, bytes, codeptr_ra);
48 static void on_ompt_callback_target(ompt_target_t kind,
49 ompt_scope_endpoint_t endpoint,
50 int device_num, ompt_data_t *task_data,
51 ompt_id_t target_id,
52 const void *codeptr_ra) {
53 assert(codeptr_ra != 0 && "Unexpected null codeptr");
54 printf("Callback Target: target_id=%lu kind=%d endpoint=%d device_num=%d "
55 "code=%p\n",
56 target_id, kind, endpoint, device_num, codeptr_ra);
59 static void on_ompt_callback_target_submit(ompt_id_t target_id,
60 ompt_id_t host_op_id,
61 unsigned int requested_num_teams) {
62 printf(" Callback Submit: target_id=%lu host_op_id=%lu req_num_teams=%d\n",
63 target_id, host_op_id, requested_num_teams);
66 static void on_ompt_callback_target_map(ompt_id_t target_id,
67 unsigned int nitems, void **host_addr,
68 void **device_addr, size_t *bytes,
69 unsigned int *mapping_flags,
70 const void *codeptr_ra) {
71 printf("Target map callback is unimplemented\n");
72 abort();
75 static void on_ompt_callback_target_data_op_emi(
76 ompt_scope_endpoint_t endpoint, ompt_data_t *target_task_data,
77 ompt_data_t *target_data, ompt_id_t *host_op_id,
78 ompt_target_data_op_t optype, void *src_addr, int src_device_num,
79 void *dest_addr, int dest_device_num, size_t bytes,
80 const void *codeptr_ra) {
81 assert(codeptr_ra != 0 && "Unexpected null codeptr");
82 if (endpoint == ompt_scope_begin)
83 *host_op_id = next_op_id++;
84 // target_task_data may be null, avoid dereferencing it
85 uint64_t target_task_data_value =
86 (target_task_data) ? target_task_data->value : 0;
87 printf(" Callback DataOp EMI: endpoint=%d optype=%d target_task_data=%p "
88 "(0x%lx) target_data=%p (0x%lx) host_op_id=%p (0x%lx) src=%p "
89 "src_device_num=%d "
90 "dest=%p dest_device_num=%d bytes=%lu code=%p\n",
91 endpoint, optype, target_task_data, target_task_data_value,
92 target_data, target_data->value, host_op_id, *host_op_id, src_addr,
93 src_device_num, dest_addr, dest_device_num, bytes, codeptr_ra);
96 static void on_ompt_callback_target_emi(ompt_target_t kind,
97 ompt_scope_endpoint_t endpoint,
98 int device_num, ompt_data_t *task_data,
99 ompt_data_t *target_task_data,
100 ompt_data_t *target_data,
101 const void *codeptr_ra) {
102 assert(codeptr_ra != 0 && "Unexpected null codeptr");
103 if (endpoint == ompt_scope_begin)
104 target_data->value = next_op_id++;
105 printf("Callback Target EMI: kind=%d endpoint=%d device_num=%d task_data=%p "
106 "(0x%lx) target_task_data=%p (0x%lx) target_data=%p (0x%lx) code=%p\n",
107 kind, endpoint, device_num, task_data, task_data->value,
108 target_task_data, target_task_data->value, target_data,
109 target_data->value, codeptr_ra);
112 static void on_ompt_callback_target_submit_emi(
113 ompt_scope_endpoint_t endpoint, ompt_data_t *target_data,
114 ompt_id_t *host_op_id, unsigned int requested_num_teams) {
115 printf(" Callback Submit EMI: endpoint=%d req_num_teams=%d target_data=%p "
116 "(0x%lx) host_op_id=%p (0x%lx)\n",
117 endpoint, requested_num_teams, target_data, target_data->value,
118 host_op_id, *host_op_id);
121 static void on_ompt_callback_target_map_emi(ompt_data_t *target_data,
122 unsigned int nitems,
123 void **host_addr,
124 void **device_addr, size_t *bytes,
125 unsigned int *mapping_flags,
126 const void *codeptr_ra) {
127 printf("Target map emi callback is unimplemented\n");
128 abort();