-
Notifications
You must be signed in to change notification settings - Fork 12.7k
/
Copy pathomp-icv.cpp
1278 lines (1150 loc) · 42 KB
/
omp-icv.cpp
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* omp-icv.cpp -- OMPD Internal Control Variable handling
*/
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// clang-format off
/* clang-format expect kmp.h before omp.h which results in build break
* due to a few redeclarations.
*/
#include "omp-debug.h"
// NOLINTNEXTLINE "to avoid clang tidy warning for the same reason as above."
#include "omp.h"
#include "ompd-private.h"
#include "TargetValue.h"
#define OMPD_SKIP_HWLOC 1
#include "kmp.h"
#undef OMPD_SKIP_HWLOC
#include <cstring>
/* The ICVs ompd-final-var and ompd-implicit-var below are for backward
* compatibility with 5.0.
*/
#define FOREACH_OMPD_ICV(macro) \
macro(dyn_var, "dyn-var", ompd_scope_thread, 0) \
macro(run_sched_var, "run-sched-var", ompd_scope_task, 0) \
macro(stacksize_var, "stacksize-var", ompd_scope_address_space, 0) \
macro(cancel_var, "cancel-var", ompd_scope_address_space, 0) \
macro(max_task_priority_var, "max-task-priority-var", ompd_scope_address_space, 0)\
macro(debug_var, "debug-var", ompd_scope_address_space, 0) \
macro(nthreads_var, "nthreads-var", ompd_scope_thread, 0) \
macro(display_affinity_var, "display-affinity-var", ompd_scope_address_space, 0) \
macro(affinity_format_var, "affinity-format-var", ompd_scope_address_space, 0) \
macro(default_device_var, "default-device-var", ompd_scope_thread, 0) \
macro(tool_var, "tool-var", ompd_scope_address_space, 0) \
macro(tool_libraries_var, "tool-libraries-var", ompd_scope_address_space, 0) \
macro(tool_verbose_init_var, "tool-verbose-init-var", ompd_scope_address_space, 0)\
macro(levels_var, "levels-var", ompd_scope_parallel, 1) \
macro(active_levels_var, "active-levels-var", ompd_scope_parallel, 0) \
macro(thread_limit_var, "thread-limit-var", ompd_scope_task, 0) \
macro(max_active_levels_var, "max-active-levels-var", ompd_scope_task, 0) \
macro(bind_var, "bind-var", ompd_scope_task, 0) \
macro(num_procs_var, "num-procs-var", ompd_scope_address_space, 0) \
macro(ompd_num_procs_var, "ompd-num-procs-var", ompd_scope_address_space, 0) \
macro(thread_num_var, "thread-num-var", ompd_scope_thread, 1) \
macro(ompd_thread_num_var, "ompd-thread-num-var", ompd_scope_thread, 1) \
macro(final_var, "final-task-var", ompd_scope_task, 0) \
macro(ompd_final_var, "ompd-final-var", ompd_scope_task, 0) \
macro(ompd_final_task_var, "ompd-final-task-var", ompd_scope_task, 0) \
macro(implicit_var, "implicit-task-var", ompd_scope_task, 0) \
macro(ompd_implicit_var, "ompd-implicit-var", ompd_scope_task, 0) \
macro(ompd_implicit_task_var, "ompd-implicit-task-var", ompd_scope_task, 0) \
macro(team_size_var, "team-size-var", ompd_scope_parallel, 1) \
macro(ompd_team_size_var, "ompd-team-size-var", ompd_scope_parallel, 1)
void __ompd_init_icvs(const ompd_callbacks_t *table) { callbacks = table; }
enum ompd_icv {
ompd_icv_undefined_marker =
0, // ompd_icv_undefined is already defined in ompd.h
#define ompd_icv_macro(v, n, s, d) ompd_icv_##v,
FOREACH_OMPD_ICV(ompd_icv_macro)
#undef ompd_icv_macro
ompd_icv_after_last_icv
};
static const char *ompd_icv_string_values[] = {"undefined",
#define ompd_icv_macro(v, n, s, d) n,
FOREACH_OMPD_ICV(ompd_icv_macro)
#undef ompd_icv_macro
};
static const ompd_scope_t ompd_icv_scope_values[] = {
ompd_scope_global, // undefined marker
#define ompd_icv_macro(v, n, s, d) s,
FOREACH_OMPD_ICV(ompd_icv_macro)
#undef ompd_icv_macro
};
// clang-format on
ompd_rc_t ompd_enumerate_icvs(ompd_address_space_handle_t *handle,
ompd_icv_id_t current, ompd_icv_id_t *next_id,
const char **next_icv_name,
ompd_scope_t *next_scope, int *more) {
if (!handle) {
return ompd_rc_stale_handle;
}
if (!next_id || !next_icv_name || !next_scope || !more) {
return ompd_rc_bad_input;
}
if (current + 1 >= ompd_icv_after_last_icv) {
return ompd_rc_bad_input;
}
*next_id = current + 1;
char *icv_name = NULL;
ompd_rc_t ret = callbacks->alloc_memory(
std::strlen(ompd_icv_string_values[*next_id]) + 1, (void **)&icv_name);
*next_icv_name = icv_name;
if (ret != ompd_rc_ok) {
return ret;
}
std::strcpy(icv_name, ompd_icv_string_values[*next_id]);
*next_scope = ompd_icv_scope_values[*next_id];
if ((*next_id) + 1 >= ompd_icv_after_last_icv) {
*more = 0;
} else {
*more = 1;
}
return ompd_rc_ok;
}
static ompd_rc_t create_empty_string(const char **empty_string_ptr) {
char *empty_str;
ompd_rc_t ret;
if (!callbacks) {
return ompd_rc_callback_error;
}
ret = callbacks->alloc_memory(1, (void **)&empty_str);
if (ret != ompd_rc_ok) {
return ret;
}
empty_str[0] = '\0';
*empty_string_ptr = empty_str;
return ompd_rc_ok;
}
static ompd_rc_t ompd_get_dynamic(
ompd_thread_handle_t *thread_handle, /* IN: OpenMP thread handle */
ompd_word_t *dyn_val /* OUT: Dynamic adjustment of threads */
) {
if (!thread_handle)
return ompd_rc_stale_handle;
if (!thread_handle->ah)
return ompd_rc_stale_handle;
ompd_address_space_context_t *context = thread_handle->ah->context;
if (!context)
return ompd_rc_stale_handle;
if (!callbacks) {
return ompd_rc_callback_error;
}
int8_t dynamic;
ompd_rc_t ret =
TValue(context, thread_handle->th) /*__kmp_threads[t]->th*/
.cast("kmp_base_info_t")
.access("th_current_task") /*__kmp_threads[t]->th.th_current_task*/
.cast("kmp_taskdata_t", 1)
.access("td_icvs") /*__kmp_threads[t]->th.th_current_task->td_icvs*/
.cast("kmp_internal_control_t", 0)
.access(
"dynamic") /*__kmp_threads[t]->th.th_current_task->td_icvs.dynamic*/
.castBase()
.getValue(dynamic);
*dyn_val = dynamic;
return ret;
}
static ompd_rc_t
ompd_get_stacksize(ompd_address_space_handle_t
*addr_handle, /* IN: handle for the address space */
ompd_word_t *stacksize_val /* OUT: per thread stack size */
) {
ompd_address_space_context_t *context = addr_handle->context;
if (!context)
return ompd_rc_stale_handle;
ompd_rc_t ret;
if (!callbacks) {
return ompd_rc_callback_error;
}
size_t stacksize;
ret = TValue(context, "__kmp_stksize")
.castBase("__kmp_stksize")
.getValue(stacksize);
*stacksize_val = stacksize;
return ret;
}
static ompd_rc_t ompd_get_cancellation(
ompd_address_space_handle_t
*addr_handle, /* IN: handle for the address space */
ompd_word_t *cancellation_val /* OUT: cancellation value */
) {
ompd_address_space_context_t *context = addr_handle->context;
if (!context)
return ompd_rc_stale_handle;
if (!callbacks) {
return ompd_rc_callback_error;
}
ompd_rc_t ret;
int omp_cancellation;
ret = TValue(context, "__kmp_omp_cancellation")
.castBase("__kmp_omp_cancellation")
.getValue(omp_cancellation);
*cancellation_val = omp_cancellation;
return ret;
}
static ompd_rc_t ompd_get_max_task_priority(
ompd_address_space_handle_t
*addr_handle, /* IN: handle for the address space */
ompd_word_t *max_task_priority_val /* OUT: max task priority value */
) {
ompd_address_space_context_t *context = addr_handle->context;
if (!context)
return ompd_rc_stale_handle;
if (!callbacks) {
return ompd_rc_callback_error;
}
ompd_rc_t ret;
int max_task_priority;
ret = TValue(context, "__kmp_max_task_priority")
.castBase("__kmp_max_task_priority")
.getValue(max_task_priority);
*max_task_priority_val = max_task_priority;
return ret;
}
static ompd_rc_t
ompd_get_debug(ompd_address_space_handle_t
*addr_handle, /* IN: handle for the address space */
ompd_word_t *debug_val /* OUT: debug value */
) {
ompd_address_space_context_t *context = addr_handle->context;
if (!context)
return ompd_rc_stale_handle;
if (!callbacks) {
return ompd_rc_callback_error;
}
ompd_rc_t ret;
uint64_t ompd_state_val;
ret = TValue(context, "ompd_state")
.castBase("ompd_state")
.getValue(ompd_state_val);
if (ompd_state_val > 0) {
*debug_val = 1;
} else {
*debug_val = 0;
}
return ret;
}
/* Helper routine for the ompd_get_nthreads routines */
static ompd_rc_t ompd_get_nthreads_aux(ompd_thread_handle_t *thread_handle,
uint32_t *used,
uint32_t *current_nesting_level,
uint32_t *nproc) {
if (!thread_handle)
return ompd_rc_stale_handle;
if (!thread_handle->ah)
return ompd_rc_stale_handle;
ompd_address_space_context_t *context = thread_handle->ah->context;
if (!context)
return ompd_rc_stale_handle;
if (!callbacks) {
return ompd_rc_callback_error;
}
ompd_rc_t ret = TValue(context, "__kmp_nested_nth")
.cast("kmp_nested_nthreads_t")
.access("used")
.castBase(ompd_type_int)
.getValue(*used);
if (ret != ompd_rc_ok)
return ret;
TValue taskdata =
TValue(context, thread_handle->th) /*__kmp_threads[t]->th*/
.cast("kmp_base_info_t")
.access("th_current_task") /*__kmp_threads[t]->th.th_current_task*/
.cast("kmp_taskdata_t", 1);
ret = taskdata
.access("td_team") /*__kmp_threads[t]->th.th_current_task.td_team*/
.cast("kmp_team_p", 1)
.access("t") /*__kmp_threads[t]->th.th_current_task.td_team->t*/
.cast("kmp_base_team_t", 0) /*t*/
.access("t_level") /*t.t_level*/
.castBase(ompd_type_int)
.getValue(*current_nesting_level);
if (ret != ompd_rc_ok)
return ret;
ret = taskdata.cast("kmp_taskdata_t", 1)
.access("td_icvs") /*__kmp_threads[t]->th.th_current_task->td_icvs*/
.cast("kmp_internal_control_t", 0)
.access(
"nproc") /*__kmp_threads[t]->th.th_current_task->td_icvs.nproc*/
.castBase(ompd_type_int)
.getValue(*nproc);
if (ret != ompd_rc_ok)
return ret;
return ompd_rc_ok;
}
static ompd_rc_t ompd_get_nthreads(
ompd_thread_handle_t *thread_handle, /* IN: handle for the thread */
ompd_word_t *nthreads_var_val /* OUT: nthreads-var (of integer type)
value */
) {
uint32_t used;
uint32_t nproc;
uint32_t current_nesting_level;
ompd_rc_t ret;
ret = ompd_get_nthreads_aux(thread_handle, &used, ¤t_nesting_level,
&nproc);
if (ret != ompd_rc_ok)
return ret;
/*__kmp_threads[t]->th.th_current_task->td_icvs.nproc*/
*nthreads_var_val = nproc;
/* If the nthreads-var is a list with more than one element, then the value of
this ICV cannot be represented by an integer type. In this case,
ompd_rc_incomplete is returned. The tool can check the return value and
can choose to invoke ompd_get_icv_string_from_scope() if needed. */
if (current_nesting_level < used - 1) {
return ompd_rc_incomplete;
}
return ompd_rc_ok;
}
static ompd_rc_t ompd_get_nthreads(
ompd_thread_handle_t *thread_handle, /* IN: handle for the thread */
const char **nthreads_list_string /* OUT: string list of comma separated
nthreads values */
) {
uint32_t used;
uint32_t nproc;
uint32_t current_nesting_level;
ompd_rc_t ret;
ret = ompd_get_nthreads_aux(thread_handle, &used, ¤t_nesting_level,
&nproc);
if (ret != ompd_rc_ok)
return ret;
uint32_t num_list_elems;
if (used == 0 || current_nesting_level >= used) {
num_list_elems = 1;
} else {
num_list_elems = used - current_nesting_level;
}
size_t buffer_size = 16 /* digits per element including the comma separator */
* num_list_elems +
1; /* string terminator NULL */
char *nthreads_list_str;
ret = callbacks->alloc_memory(buffer_size, (void **)&nthreads_list_str);
if (ret != ompd_rc_ok)
return ret;
/* The nthreads-var list would be:
[__kmp_threads[t]->th.th_current_task->td_icvs.nproc,
__kmp_nested_nth.nth[current_nesting_level + 1],
__kmp_nested_nth.nth[current_nesting_level + 2],
…,
__kmp_nested_nth.nth[used - 1]]*/
sprintf(nthreads_list_str, "%d", nproc);
*nthreads_list_string = nthreads_list_str;
if (num_list_elems == 1) {
return ompd_rc_ok;
}
char temp_value[16];
uint32_t nth_value;
for (current_nesting_level++; /* the list element for this nesting
* level has already been accounted for
by nproc */
current_nesting_level < used; current_nesting_level++) {
ret = TValue(thread_handle->ah->context, "__kmp_nested_nth")
.cast("kmp_nested_nthreads_t")
.access("nth")
.cast("int", 1)
.getArrayElement(current_nesting_level)
.castBase(ompd_type_int)
.getValue(nth_value);
if (ret != ompd_rc_ok)
return ret;
sprintf(temp_value, ",%d", nth_value);
strcat(nthreads_list_str, temp_value);
}
return ompd_rc_ok;
}
static ompd_rc_t ompd_get_display_affinity(
ompd_address_space_handle_t
*addr_handle, /* IN: handle for the address space */
ompd_word_t *display_affinity_val /* OUT: display affinity value */
) {
ompd_address_space_context_t *context = addr_handle->context;
if (!context)
return ompd_rc_stale_handle;
ompd_rc_t ret;
if (!callbacks) {
return ompd_rc_callback_error;
}
ret = TValue(context, "__kmp_display_affinity")
.castBase("__kmp_display_affinity")
.getValue(*display_affinity_val);
return ret;
}
static ompd_rc_t ompd_get_affinity_format(
ompd_address_space_handle_t *addr_handle, /* IN: address space handle*/
const char **affinity_format_string /* OUT: affinity format string */
) {
ompd_address_space_context_t *context = addr_handle->context;
if (!context)
return ompd_rc_stale_handle;
if (!callbacks) {
return ompd_rc_callback_error;
}
ompd_rc_t ret;
ret = TValue(context, "__kmp_affinity_format")
.cast("char", 1)
.getString(affinity_format_string);
return ret;
}
static ompd_rc_t ompd_get_tool_libraries(
ompd_address_space_handle_t *addr_handle, /* IN: address space handle*/
const char **tool_libraries_string /* OUT: tool libraries string */
) {
if (!tool_libraries_string)
return ompd_rc_bad_input;
ompd_address_space_context_t *context = addr_handle->context;
if (!context)
return ompd_rc_stale_handle;
if (!callbacks) {
return ompd_rc_callback_error;
}
ompd_rc_t ret;
ret = TValue(context, "__kmp_tool_libraries")
.cast("char", 1)
.getString(tool_libraries_string);
if (ret == ompd_rc_unsupported) {
ret = create_empty_string(tool_libraries_string);
}
return ret;
}
static ompd_rc_t ompd_get_default_device(
ompd_thread_handle_t *thread_handle, /* IN: handle for the thread */
ompd_word_t *default_device_val /* OUT: default device value */
) {
if (!thread_handle)
return ompd_rc_stale_handle;
if (!thread_handle->ah)
return ompd_rc_stale_handle;
ompd_address_space_context_t *context = thread_handle->ah->context;
if (!context)
return ompd_rc_stale_handle;
if (!callbacks)
return ompd_rc_callback_error;
ompd_rc_t ret =
TValue(context, thread_handle->th) /*__kmp_threads[t]->th*/
.cast("kmp_base_info_t")
.access("th_current_task") /*__kmp_threads[t]->th.th_current_task*/
.cast("kmp_taskdata_t", 1)
.access("td_icvs") /*__kmp_threads[t]->th.th_current_task->td_icvs*/
.cast("kmp_internal_control_t", 0)
/*__kmp_threads[t]->th.th_current_task->td_icvs.default_device*/
.access("default_device")
.castBase()
.getValue(*default_device_val);
return ret;
}
static ompd_rc_t
ompd_get_tool(ompd_address_space_handle_t
*addr_handle, /* IN: handle for the address space */
ompd_word_t *tool_val /* OUT: tool value */
) {
ompd_address_space_context_t *context = addr_handle->context;
if (!context)
return ompd_rc_stale_handle;
if (!callbacks) {
return ompd_rc_callback_error;
}
ompd_rc_t ret;
ret =
TValue(context, "__kmp_tool").castBase("__kmp_tool").getValue(*tool_val);
return ret;
}
static ompd_rc_t ompd_get_tool_verbose_init(
ompd_address_space_handle_t *addr_handle, /* IN: address space handle*/
const char **tool_verbose_init_string /* OUT: tool verbose init string */
) {
ompd_address_space_context_t *context = addr_handle->context;
if (!context)
return ompd_rc_stale_handle;
if (!callbacks) {
return ompd_rc_callback_error;
}
ompd_rc_t ret;
ret = TValue(context, "__kmp_tool_verbose_init")
.cast("char", 1)
.getString(tool_verbose_init_string);
if (ret == ompd_rc_unsupported) {
ret = create_empty_string(tool_verbose_init_string);
}
return ret;
}
static ompd_rc_t ompd_get_level(
ompd_parallel_handle_t *parallel_handle, /* IN: OpenMP parallel handle */
ompd_word_t *val /* OUT: nesting level */
) {
if (!parallel_handle->ah)
return ompd_rc_stale_handle;
ompd_address_space_context_t *context = parallel_handle->ah->context;
if (!context)
return ompd_rc_stale_handle;
if (!callbacks) {
return ompd_rc_callback_error;
}
uint32_t res;
ompd_rc_t ret = TValue(context, parallel_handle->th)
.cast("kmp_base_team_t", 0) /*t*/
.access("t_level") /*t.t_level*/
.castBase()
.getValue(res);
*val = res;
return ret;
}
static ompd_rc_t ompd_get_active_level(
ompd_parallel_handle_t *parallel_handle, /* IN: OpenMP parallel handle */
ompd_word_t *val /* OUT: active nesting level */
) {
if (!parallel_handle->ah)
return ompd_rc_stale_handle;
ompd_address_space_context_t *context = parallel_handle->ah->context;
if (!context)
return ompd_rc_stale_handle;
if (!callbacks) {
return ompd_rc_callback_error;
}
uint32_t res;
ompd_rc_t ret = TValue(context, parallel_handle->th)
.cast("kmp_base_team_t", 0) /*t*/
.access("t_active_level") /*t.t_active_level*/
.castBase()
.getValue(res);
*val = res;
return ret;
}
static ompd_rc_t
ompd_get_num_procs(ompd_address_space_handle_t
*addr_handle, /* IN: handle for the address space */
ompd_word_t *val /* OUT: number of processes */
) {
ompd_address_space_context_t *context = addr_handle->context;
if (!context)
return ompd_rc_stale_handle;
if (!callbacks) {
return ompd_rc_callback_error;
}
if (!val)
return ompd_rc_bad_input;
ompd_rc_t ret;
int nth;
ret = TValue(context, "__kmp_avail_proc")
.castBase("__kmp_avail_proc")
.getValue(nth);
*val = nth;
return ret;
}
static ompd_rc_t ompd_get_thread_limit(
ompd_task_handle_t *task_handle, /* IN: OpenMP task handle*/
ompd_word_t *val /* OUT: max number of threads */
) {
if (!task_handle->ah)
return ompd_rc_stale_handle;
ompd_address_space_context_t *context = task_handle->ah->context;
if (!context)
return ompd_rc_stale_handle;
if (!callbacks) {
return ompd_rc_callback_error;
}
ompd_rc_t ret = TValue(context, task_handle->th)
.cast("kmp_taskdata_t") // td
.access("td_icvs") // td->td_icvs
.cast("kmp_internal_control_t", 0)
.access("thread_limit") // td->td_icvs.thread_limit
.castBase()
.getValue(*val);
return ret;
}
static ompd_rc_t ompd_get_thread_num(
ompd_thread_handle_t *thread_handle, /* IN: OpenMP thread handle*/
ompd_word_t *val /* OUT: number of the thread within the team */
) {
if (!thread_handle)
return ompd_rc_stale_handle;
if (!thread_handle->ah)
return ompd_rc_stale_handle;
ompd_address_space_context_t *context = thread_handle->ah->context;
if (!context)
return ompd_rc_stale_handle;
if (!callbacks) {
return ompd_rc_callback_error;
}
ompd_rc_t ret =
TValue(context, thread_handle->th) /*__kmp_threads[t]->th*/
.cast("kmp_base_info_t")
.access("th_info") /*__kmp_threads[t]->th.th_info*/
.cast("kmp_desc_t")
.access("ds") /*__kmp_threads[t]->th.th_info.ds*/
.cast("kmp_desc_base_t")
.access("ds_tid") /*__kmp_threads[t]->th.th_info.ds.ds_tid*/
.castBase()
.getValue(*val);
return ret;
}
static ompd_rc_t
ompd_in_final(ompd_task_handle_t *task_handle, /* IN: OpenMP task handle*/
ompd_word_t *val /* OUT: max number of threads */
) {
if (!task_handle->ah)
return ompd_rc_stale_handle;
ompd_address_space_context_t *context = task_handle->ah->context;
if (!context)
return ompd_rc_stale_handle;
if (!callbacks) {
return ompd_rc_callback_error;
}
ompd_rc_t ret = TValue(context, task_handle->th)
.cast("kmp_taskdata_t") // td
.access("td_flags") // td->td_flags
.cast("kmp_tasking_flags_t")
.check("final", val); // td->td_flags.tasktype
return ret;
}
static ompd_rc_t ompd_get_max_active_levels(
ompd_task_handle_t *task_handle, /* IN: OpenMP task handle*/
ompd_word_t *val /* OUT: max number of threads */
) {
if (!task_handle->ah)
return ompd_rc_stale_handle;
ompd_address_space_context_t *context = task_handle->ah->context;
if (!context)
return ompd_rc_stale_handle;
if (!callbacks) {
return ompd_rc_callback_error;
}
ompd_rc_t ret =
TValue(context, task_handle->th)
.cast("kmp_taskdata_t") // td
.access("td_icvs") // td->td_icvs
.cast("kmp_internal_control_t", 0)
.access("max_active_levels") // td->td_icvs.max_active_levels
.castBase()
.getValue(*val);
return ret;
}
static ompd_rc_t ompd_get_run_schedule(
ompd_task_handle_t *task_handle, /* IN: OpenMP task handle*/
const char **run_sched_string /* OUT: Run Schedule String
consisting of kind and modifier */
) {
if (!task_handle->ah)
return ompd_rc_stale_handle;
ompd_address_space_context_t *context = task_handle->ah->context;
if (!context)
return ompd_rc_stale_handle;
if (!callbacks) {
return ompd_rc_callback_error;
}
int kind;
TValue sched = TValue(context, task_handle->th)
.cast("kmp_taskdata_t") // td
.access("td_icvs") // td->td_icvs
.cast("kmp_internal_control_t", 0)
.access("sched") // td->td_icvs.sched
.cast("kmp_r_sched_t", 0);
ompd_rc_t ret = sched
.access("r_sched_type") // td->td_icvs.sched.r_sched_type
.castBase()
.getValue(kind);
if (ret != ompd_rc_ok) {
return ret;
}
int chunk = 0;
ret = sched
.access("chunk") // td->td_icvs.sched.chunk
.castBase()
.getValue(chunk);
if (ret != ompd_rc_ok) {
return ret;
}
char *run_sched_var_string;
ret = callbacks->alloc_memory(100, (void **)&run_sched_var_string);
if (ret != ompd_rc_ok) {
return ret;
}
run_sched_var_string[0] = '\0';
if (SCHEDULE_HAS_MONOTONIC(kind)) {
strcpy(run_sched_var_string, "monotonic:");
} else if (SCHEDULE_HAS_NONMONOTONIC(kind)) {
strcpy(run_sched_var_string, "nonmonotonic:");
}
bool static_unchunked = false;
switch (SCHEDULE_WITHOUT_MODIFIERS(kind)) {
case kmp_sch_static:
case kmp_sch_static_greedy:
case kmp_sch_static_balanced:
static_unchunked = true;
strcat(run_sched_var_string, "static");
break;
case kmp_sch_static_chunked:
strcat(run_sched_var_string, "static");
break;
case kmp_sch_dynamic_chunked:
strcat(run_sched_var_string, "dynamic");
break;
case kmp_sch_guided_chunked:
case kmp_sch_guided_iterative_chunked:
case kmp_sch_guided_analytical_chunked:
strcat(run_sched_var_string, "guided");
break;
case kmp_sch_auto:
strcat(run_sched_var_string, "auto");
break;
case kmp_sch_trapezoidal:
strcat(run_sched_var_string, "trapezoidal");
break;
case kmp_sch_static_steal:
strcat(run_sched_var_string, "static_steal");
break;
default:
ret = callbacks->free_memory((void *)(run_sched_var_string));
if (ret != ompd_rc_ok) {
return ret;
}
ret = create_empty_string(run_sched_string);
return ret;
}
if (static_unchunked == true) {
// To be in sync with what OMPT returns.
// Chunk was not set. Shown with a zero value.
chunk = 0;
}
char temp_str[16];
sprintf(temp_str, ",%d", chunk);
strcat(run_sched_var_string, temp_str);
*run_sched_string = run_sched_var_string;
return ret;
}
/* Helper routine for the ompd_get_proc_bind routines */
static ompd_rc_t ompd_get_proc_bind_aux(ompd_task_handle_t *task_handle,
uint32_t *used,
uint32_t *current_nesting_level,
uint32_t *proc_bind) {
if (!task_handle->ah)
return ompd_rc_stale_handle;
ompd_address_space_context_t *context = task_handle->ah->context;
if (!context)
return ompd_rc_stale_handle;
if (!callbacks) {
return ompd_rc_callback_error;
}
ompd_rc_t ret = TValue(context, "__kmp_nested_proc_bind")
.cast("kmp_nested_proc_bind_t")
.access("used")
.castBase(ompd_type_int)
.getValue(*used);
if (ret != ompd_rc_ok)
return ret;
TValue taskdata = TValue(context, task_handle->th) /* td */
.cast("kmp_taskdata_t");
ret = taskdata
.access("td_team") /* td->td_team*/
.cast("kmp_team_p", 1)
.access("t") /* td->td_team->t*/
.cast("kmp_base_team_t", 0) /*t*/
.access("t_level") /*t.t_level*/
.castBase(ompd_type_int)
.getValue(*current_nesting_level);
if (ret != ompd_rc_ok)
return ret;
ret = taskdata
.access("td_icvs") /* td->td_icvs */
.cast("kmp_internal_control_t", 0)
.access("proc_bind") /* td->td_icvs.proc_bind */
.castBase()
.getValue(*proc_bind);
return ret;
}
static ompd_rc_t
ompd_get_proc_bind(ompd_task_handle_t *task_handle, /* IN: OpenMP task handle */
ompd_word_t *bind /* OUT: Kind of proc-binding */
) {
uint32_t used;
uint32_t proc_bind;
uint32_t current_nesting_level;
ompd_rc_t ret;
ret = ompd_get_proc_bind_aux(task_handle, &used, ¤t_nesting_level,
&proc_bind);
if (ret != ompd_rc_ok)
return ret;
*bind = proc_bind;
/* If bind-var is a list with more than one element, then the value of
this ICV cannot be represented by an integer type. In this case,
ompd_rc_incomplete is returned. The tool can check the return value and
can choose to invoke ompd_get_icv_string_from_scope() if needed. */
if (current_nesting_level < used - 1) {
return ompd_rc_incomplete;
}
return ompd_rc_ok;
}
static ompd_rc_t ompd_get_proc_bind(
ompd_task_handle_t *task_handle, /* IN: OpenMP task handle */
const char **proc_bind_list_string /* OUT: string list of comma separated
bind-var values */
) {
uint32_t used;
uint32_t proc_bind;
uint32_t current_nesting_level;
ompd_rc_t ret;
ret = ompd_get_proc_bind_aux(task_handle, &used, ¤t_nesting_level,
&proc_bind);
if (ret != ompd_rc_ok)
return ret;
uint32_t num_list_elems;
if (used == 0 || current_nesting_level >= used) {
num_list_elems = 1;
} else {
num_list_elems = used - current_nesting_level;
}
size_t buffer_size = 16 /* digits per element including the comma separator */
* num_list_elems +
1; /* string terminator NULL */
char *proc_bind_list_str;
ret = callbacks->alloc_memory(buffer_size, (void **)&proc_bind_list_str);
if (ret != ompd_rc_ok)
return ret;
/* The bind-var list would be:
[td->td_icvs.proc_bind,
__kmp_nested_proc_bind.bind_types[current_nesting_level + 1],
__kmp_nested_proc_bind.bind_types[current_nesting_level + 2],
…,
__kmp_nested_proc_bind.bind_types[used - 1]]*/
sprintf(proc_bind_list_str, "%d", proc_bind);
*proc_bind_list_string = proc_bind_list_str;
if (num_list_elems == 1) {
return ompd_rc_ok;
}
char temp_value[16];
uint32_t bind_types_value;
for (current_nesting_level++; /* the list element for this nesting
level has already been accounted for
by proc_bind */
current_nesting_level < used; current_nesting_level++) {
ret = TValue(task_handle->ah->context, "__kmp_nested_proc_bind")
.cast("kmp_nested_proc_bind_t")
.access("bind_types")
.cast("int", 1)
.getArrayElement(current_nesting_level)
.castBase(ompd_type_int)
.getValue(bind_types_value);
if (ret != ompd_rc_ok)
return ret;
sprintf(temp_value, ",%d", bind_types_value);
strcat(proc_bind_list_str, temp_value);
}
return ompd_rc_ok;
}
static ompd_rc_t
ompd_is_implicit(ompd_task_handle_t *task_handle, /* IN: OpenMP task handle*/
ompd_word_t *val /* OUT: max number of threads */
) {
if (!task_handle)
return ompd_rc_stale_handle;
if (!task_handle->ah)
return ompd_rc_stale_handle;
ompd_address_space_context_t *context = task_handle->ah->context;
if (!context)
return ompd_rc_stale_handle;
if (!callbacks) {
return ompd_rc_callback_error;
}
ompd_rc_t ret = TValue(context, task_handle->th)
.cast("kmp_taskdata_t") // td
.access("td_flags") // td->td_flags
.cast("kmp_tasking_flags_t")
.check("tasktype", val); // td->td_flags.tasktype
*val ^= 1; // tasktype: explicit = 1, implicit = 0 => invert the value
return ret;
}
ompd_rc_t ompd_get_num_threads(
ompd_parallel_handle_t *parallel_handle, /* IN: OpenMP parallel handle */
ompd_word_t *val /* OUT: number of threads */
) {
if (!parallel_handle->ah)
return ompd_rc_stale_handle;
ompd_address_space_context_t *context = parallel_handle->ah->context;
if (!context)
return ompd_rc_stale_handle;
if (!callbacks) {
return ompd_rc_callback_error;
}
ompd_rc_t ret = ompd_rc_ok;
if (parallel_handle->lwt.address != 0) {
*val = 1;
} else {
uint32_t res;
ret = TValue(context, parallel_handle->th)
.cast("kmp_base_team_t", 0) /*t*/
.access("t_nproc") /*t.t_nproc*/
.castBase()
.getValue(res);
*val = res;
}
return ret;
}
ompd_rc_t ompd_get_icv_from_scope(void *handle, ompd_scope_t scope,
ompd_icv_id_t icv_id,
ompd_word_t *icv_value) {
if (!handle) {