-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathinsert_function.c
More file actions
3506 lines (3123 loc) · 139 KB
/
insert_function.c
File metadata and controls
3506 lines (3123 loc) · 139 KB
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
/**
* Copyright (c) 2013-2024 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2023-2024 NVIDIA Corporation. All rights reserved.
*/
/* **************************************************************************** */
/**
* @file insert_function.c
*
*/
/* Define a group for Doxygen documentation */
/**
* @defgroup DTD_INTERFACE Dynamic Task Discovery interface for PaRSEC
* @ingroup parsec_public
*
* These functions are available from the PaRSEC library for the
* scheduling of kernel routines.
*/
/* Define a group for Doxygen documentation */
/**
* @defgroup DTD_INTERFACE_INTERNAL Dynamic Task Discovery functions for PaRSEC
* @ingroup parsec_internal
*
* These functions are not available from the PaRSEC library for the
* scheduling of kernel routines.
*/
#include <stdlib.h>
#include <sys/time.h>
#include "parsec/parsec_config.h"
#include "parsec/parsec_internal.h"
#include "parsec/scheduling.h"
#include "parsec/remote_dep.h"
#include "parsec/runtime.h"
#include "parsec/mca/device/device.h"
#if defined(PARSEC_HAVE_DEV_CUDA_SUPPORT)
#include "parsec/mca/device/cuda/device_cuda.h"
#endif /* defined(PARSEC_HAVE_DEV_CUDA_SUPPORT) */
#include "parsec/mca/mca_repository.h"
#include "parsec/constants.h"
#include "parsec/vpmap.h"
#include "parsec/utils/mca_param.h"
#include "parsec/mca/sched/sched.h"
#include "parsec/interfaces/interface.h"
#include "parsec/interfaces/dtd/insert_function.h"
#include "parsec/interfaces/dtd/insert_function_internal.h"
#include "parsec/parsec_binary_profile.h"
#include "parsec/utils/colors.h"
#include "parsec/mca/pins/pins.h"
#include "parsec/utils/debug.h"
#include "parsec/data_distribution.h"
#include "parsec/utils/backoff.h"
/* This allows DTD to have a separate stream for debug verbose output */
int parsec_dtd_debug_output;
static int parsec_dtd_debug_verbose = -1;
static int parsec_dtd_profile_verbose = 0;
static parsec_dc_key_t parsec_dtd_dc_id = 0;
int32_t __parsec_dtd_is_initialized = 0; /**< Indicates init of dtd environment is completed */
int parsec_dtd_window_size = 8000; /**< Default window size */
int parsec_dtd_threshold_size = 4000; /**< Default threshold size of tasks for master thread to wait on */
static int parsec_dtd_task_hash_table_size = 1<<16; /**< Default task hash table size */
static int parsec_dtd_tile_hash_table_size = 1<<16; /**< Default tile hash table size */
int parsec_dtd_dump_traversal_info = 60; /**< Level for printing traversal info */
int insert_task_trace_keyin = -1;
int insert_task_trace_keyout = -1;
int hashtable_trace_keyin = -1;
int hashtable_trace_keyout = -1;
extern parsec_sched_module_t *parsec_current_scheduler;
/* Global mempool for all tiles */
parsec_mempool_t *parsec_dtd_tile_mempool = NULL;
static parsec_hook_return_t parsec_dtd_cpu_task_submit(parsec_execution_stream_t *es, parsec_task_t *this_task);
static parsec_data_key_t parsec_dtd_tile_new_dc_data_key(parsec_data_collection_t *d, ...)
{
va_list ap;
uint64_t key;
va_start(ap, d);
key = va_arg(ap, uint64_t);
va_end(ap);
return (parsec_data_key_t)key;
}
static uint32_t parsec_dtd_tile_new_dc_rank_of_key(parsec_data_collection_t *d, parsec_data_key_t key)
{
parsec_dtd_tile_t *tile;
tile = parsec_hash_table_find(d->tile_h_table, key);
if(NULL == tile) {
assert(0);
return (uint32_t)-1;
}
return tile->rank;
}
static uint32_t parsec_dtd_tile_new_dc_rank_of(parsec_data_collection_t *d, ...)
{
va_list ap;
uint64_t key;
va_start(ap, d);
key = va_arg(ap, uint64_t);
va_end(ap);
return parsec_dtd_tile_new_dc_rank_of_key(d, key);
}
static parsec_data_t* parsec_dtd_tile_new_dc_data_of_key(parsec_data_collection_t *d, parsec_data_key_t key)
{
parsec_dtd_tile_t *tile;
tile = parsec_hash_table_find(d->tile_h_table, key);
if(NULL == tile) {
assert(0);
return NULL;
}
if(NULL == tile->data_copy) {
parsec_data_t *data = NULL;
data = parsec_data_create(&data, d, key, PARSEC_DATA_CREATE_ON_DEMAND, 0, PARSEC_DATA_FLAG_PARSEC_MANAGED);
if( !parsec_atomic_cas_ptr(&tile->data_copy, NULL, data->device_copies[0] ) ) {
assert(NULL != tile->data_copy);
parsec_data_destroy(data);
}
}
return tile->data_copy->original;
}
static parsec_data_t* parsec_dtd_tile_new_dc_data_of(parsec_data_collection_t *d, ...)
{
va_list ap;
uint64_t key;
va_start(ap, d);
key = va_arg(ap, uint64_t);
va_end(ap);
return parsec_dtd_tile_new_dc_data_of_key(d, key);
}
static int32_t parsec_dtd_tile_new_dc_vpid_of(parsec_data_collection_t *d, ...)
{
(void)d;
return 0;
}
static int32_t parsec_dtd_tile_new_dc_vpid_of_key(parsec_data_collection_t *d, parsec_data_key_t key)
{
(void)d;
(void)key;
return 0;
}
static int parsec_dtd_tile_new_dc_key_to_string(parsec_data_collection_t *d, parsec_data_key_t key, char * buffer,
uint32_t buffer_size)
{
return snprintf(buffer, buffer_size, "%s(%"PRIu64")", NULL == d->key_dim ? "" : d->key_dim, key);
}
/**
* All the static functions should be declared before being defined.
*/
static void
parsec_dtd_iterate_successors(parsec_execution_stream_t *es,
const parsec_task_t *this_task,
uint32_t action_mask,
parsec_ontask_function_t *ontask,
void *ontask_arg);
static int
parsec_dtd_release_deps(parsec_execution_stream_t *,
parsec_task_t *,
uint32_t, parsec_remote_deps_t *);
static parsec_hook_return_t
complete_hook_of_dtd(parsec_execution_stream_t *,
parsec_task_t *);
static parsec_key_fn_t DTD_key_fns = {
.key_equal = parsec_hash_table_generic_64bits_key_equal,
.key_print = parsec_hash_table_generic_64bits_key_print,
.key_hash = parsec_hash_table_generic_64bits_key_hash
};
void
parsec_dtd_insert_task_class(parsec_dtd_taskpool_t *tp,
parsec_dtd_task_class_t *value);
inline int parsec_dtd_task_is_local(parsec_dtd_task_t *task)
{
return task->rank == task->super.taskpool->context->my_rank;
}
inline int parsec_dtd_task_is_remote(parsec_dtd_task_t *task)
{ return !parsec_dtd_task_is_local(task); }
static int parsec_dtd_taskpool_enter_wait(parsec_taskpool_t* tp, void*_)
{
assert(tp != NULL);
assert(NULL != tp->tdm.module);
(void)_;
tp->tdm.module->taskpool_ready(tp);
return PARSEC_SUCCESS;
}
static int parsec_dtd_taskpool_leave_wait(parsec_taskpool_t* tp, void*_)
{
assert(tp != NULL);
assert(NULL != tp->tdm.module);
(void)_;
assert(tp->taskpool_type == PARSEC_TASKPOOL_TYPE_DTD);
/* Reset termination detector, so we can start adding tasks again */
tp->tdm.module->unmonitor_taskpool(tp);
parsec_termdet_open_module(tp, "local");
tp->tdm.module->monitor_taskpool(tp, parsec_taskpool_termination_detected);
tp->tdm.module->taskpool_set_nb_tasks(tp, 0);
tp->tdm.module->taskpool_set_runtime_actions(tp, 0);
/* We are re-attached to the context */
parsec_atomic_fetch_inc_int32(&tp->context->active_taskpools);
return PARSEC_SUCCESS;
}
int parsec_dtd_dequeue_taskpool(parsec_taskpool_t *tp)
{
return parsec_dtd_taskpool_enter_wait(tp, NULL);
}
/* enqueue wrapper for dtd */
int
parsec_dtd_enqueue_taskpool(parsec_taskpool_t *tp, void *data)
{
(void)data;
parsec_dtd_taskpool_t *dtd_tp = (parsec_dtd_taskpool_t *)tp;
parsec_dtd_param_t flush_param;
parsec_taskpool_enable(tp, NULL, NULL, NULL,
!!(tp->context->nb_nodes > 1));
/* The first taskclass of every taskpool is the flush taskclass */
parsec_dtd_task_class_t *data_flush_tc;
flush_param.op = PARSEC_AFFINITY | PARSEC_INOUT;
flush_param.size = PASSED_BY_REF;
data_flush_tc = parsec_dtd_create_task_classv("parsec_dtd_data_flush", 1, &flush_param);
__parsec_chore_t **incarnations = (__parsec_chore_t**)&data_flush_tc->super.incarnations;
(*incarnations)[0].type = PARSEC_DEV_CPU;
(*incarnations)[0].hook = parsec_dtd_data_flush_sndrcv;
data_flush_tc->cpu_func_ptr = parsec_dtd_data_flush_sndrcv;
(*incarnations)[1].type = PARSEC_DEV_NONE;
parsec_data_collection_init(&dtd_tp->new_tile_dc, dtd_tp->super.context->nb_nodes, dtd_tp->super.context->my_rank);
dtd_tp->new_tile_dc.data_key = parsec_dtd_tile_new_dc_data_key;
dtd_tp->new_tile_dc.data_of = parsec_dtd_tile_new_dc_data_of;
dtd_tp->new_tile_dc.data_of_key = parsec_dtd_tile_new_dc_data_of_key;
dtd_tp->new_tile_dc.key_to_string = parsec_dtd_tile_new_dc_key_to_string;
dtd_tp->new_tile_dc.rank_of = parsec_dtd_tile_new_dc_rank_of;
dtd_tp->new_tile_dc.rank_of_key = parsec_dtd_tile_new_dc_rank_of_key;
dtd_tp->new_tile_dc.vpid_of = parsec_dtd_tile_new_dc_vpid_of;
dtd_tp->new_tile_dc.vpid_of_key = parsec_dtd_tile_new_dc_vpid_of_key;
parsec_dtd_data_collection_init(&dtd_tp->new_tile_dc);
/* Bookkeeping of the task class */
uint64_t fkey = (uint64_t)(uintptr_t)parsec_dtd_data_flush_sndrcv + 1;
parsec_dtd_register_task_class(&dtd_tp->super, fkey, (parsec_task_class_t*)data_flush_tc);
parsec_dtd_insert_task_class(dtd_tp, (parsec_dtd_task_class_t*)data_flush_tc);
return PARSEC_SUCCESS;
}
/* To create object of class parsec_dtd_task_t that inherits parsec_task_t
* class
*/
PARSEC_OBJ_CLASS_INSTANCE(parsec_dtd_task_t, parsec_task_t,
NULL, NULL);
/* To create object of class dtd_tile_t that inherits parsec_list_item_t
* class
*/
PARSEC_OBJ_CLASS_INSTANCE(parsec_dtd_tile_t, parsec_list_item_t,
NULL, NULL);
/***************************************************************************//**
*
* Constructor of PaRSEC's DTD taskpool.
*
* @param[in,out] tp
* Pointer to taskpool which will be constructed
*
* @ingroup DTD_INTERFACE_INTERNAL
*
******************************************************************************/
void parsec_dtd_taskpool_constructor(parsec_dtd_taskpool_t *tp)
{
int nb;
tp->task_hash_table = PARSEC_OBJ_NEW(parsec_hash_table_t);
for( nb = 1; nb < 16 && (1 << nb) < parsec_dtd_task_hash_table_size; nb++ ) /* nothing */;
parsec_hash_table_init(tp->task_hash_table,
offsetof(dtd_hash_table_pointer_item_t, ht_item),
nb,
DTD_key_fns,
tp->task_hash_table);
tp->function_h_table = PARSEC_OBJ_NEW(parsec_hash_table_t);
for( nb = 1; nb < 16 && (1 << nb) < PARSEC_DTD_NB_TASK_CLASSES; nb++ ) /* nothing */;
parsec_hash_table_init(tp->function_h_table,
offsetof(dtd_hash_table_pointer_item_t, ht_item),
nb,
DTD_key_fns,
tp->function_h_table);
tp->super.startup_hook = parsec_dtd_startup;
tp->super.task_classes_array = (const parsec_task_class_t **)malloc(
PARSEC_DTD_NB_TASK_CLASSES * sizeof(parsec_task_class_t *));
for( int i = 0; i < PARSEC_DTD_NB_TASK_CLASSES; i++ ) {
tp->super.task_classes_array[i] = NULL;
}
tp->super.dependencies_array = calloc(PARSEC_DTD_NB_TASK_CLASSES, sizeof(parsec_dependencies_t *));
#if defined(PARSEC_PROF_TRACE)
tp->super.profiling_array = calloc(2 * PARSEC_DTD_NB_TASK_CLASSES, sizeof(int));
#endif /* defined(PARSEC_PROF_TRACE) */
/* Initializing hash_table_bucket mempool */
tp->hash_table_bucket_mempool = (parsec_mempool_t *)malloc(sizeof(parsec_mempool_t));
parsec_mempool_construct(tp->hash_table_bucket_mempool,
NULL, sizeof(dtd_hash_table_pointer_item_t),
offsetof(dtd_hash_table_pointer_item_t, mempool_owner),
1/* no. of threads*/ );
}
/***************************************************************************//**
*
* Destructor of PaRSEC's DTD taskpool.
*
* @param[in,out] tp
* Pointer to taskpool which will be destroyed
*
* @ingroup DTD_INTERFACE_INTERNAL
*
******************************************************************************/
void
parsec_dtd_taskpool_destructor(parsec_dtd_taskpool_t *tp)
{
uint32_t i;
if(NULL != tp->super.context) { /* Initialized only if taskpool startup hook ran */
/* The taskpool is just out of a wait and is ready to receive new tasks at this time, so it has a termination detector */
assert(NULL != tp->super.tdm.module);
/* The taskpool is NOT READY, because every time we leave wait(), we reinitialize the termination detector. */
assert( tp->super.tdm.module->taskpool_state(&tp->super) == PARSEC_TERM_TP_NOT_READY );
/* But there should be 0 event on this taskpool at this time */
assert( tp->super.nb_pending_actions == 0 && tp->super.nb_tasks == 0);
/* So, we can safely stop monitoring this taskpool, and trigger taskpool termination detection */
tp->super.tdm.module->unmonitor_taskpool(&tp->super);
parsec_taskpool_termination_detected(&tp->super);
parsec_dtd_data_collection_fini(&tp->new_tile_dc);
parsec_data_collection_destroy(&tp->new_tile_dc);
parsec_context_remove_taskpool(&tp->super);
/* Unregister the taskpool from the devices */
for( i = 0; i < parsec_nb_devices; i++ ) {
parsec_device_module_t *device = parsec_mca_device_get(i);
if( !(tp->super.devices_index_mask & (1 << device->device_index)))
continue;
tp->super.devices_index_mask &= ~(1 << device->device_index);
if((NULL == device) || (NULL == device->taskpool_unregister))
continue;
(void)device->taskpool_unregister(device, &tp->super);
}
assert(0 == tp->super.devices_index_mask);
/* taskpool_unregister will unmonitor this taskpool */
parsec_taskpool_unregister( (parsec_taskpool_t*)tp );
}
/* Destroy the data repositories for this object */
for (i = 0; i < PARSEC_DTD_NB_TASK_CLASSES; i++) {
parsec_task_class_t *tc = (parsec_task_class_t *) tp->super.task_classes_array[i];
/* Have we reached the end of known functions for this taskpool? */
if( NULL == tc ) {
continue;
}
parsec_dtd_task_class_release( (parsec_taskpool_t*)tp, tc );
parsec_destruct_dependencies(tp->super.dependencies_array[i]);
tp->super.dependencies_array[i] = NULL;
}
/* dtd_taskpool specific */
parsec_mempool_destruct(tp->hash_table_bucket_mempool);
free(tp->hash_table_bucket_mempool);
#if defined(PARSEC_PROF_TRACE)
free((void *)tp->super.profiling_array);
#endif /* defined(PARSEC_PROF_TRACE) */
if( NULL != tp->super.taskpool_name) {
free(tp->super.taskpool_name);
tp->super.taskpool_name = NULL;
}
free(tp->super.dependencies_array);
tp->super.dependencies_array = NULL;
free(tp->super.task_classes_array);
parsec_hash_table_fini(tp->task_hash_table);
PARSEC_OBJ_RELEASE(tp->task_hash_table);
parsec_hash_table_fini(tp->function_h_table);
PARSEC_OBJ_RELEASE(tp->function_h_table);
}
/* To create object of class parsec_dtd_taskpool_t that inherits parsec_taskpool_t
* class
*/
PARSEC_OBJ_CLASS_INSTANCE(parsec_dtd_taskpool_t, parsec_taskpool_t,
parsec_dtd_taskpool_constructor, parsec_dtd_taskpool_destructor);
/* **************************************************************************** */
/**
* Init function of Dynamic Task Discovery Interface. This function should never
* be called directly, it will be automatically called upon creation of the
* first taskpool. The corresponding finalization function (parsec_dtd_fini)
* will then be called once all references to the DTD will disappear.
*
* Here a global(per node/process) taskpool mempool for PaRSEC's DTD taskpool
* is constructed. The mca_params passed to the runtime are also scanned
* and set here.
* List of mca options available for DTD interface are:
* - dtd_traversal_info (default=0 off): This prints the DAG traversal
* info for each node in the DAG.
* - dtd_function_info (default=0 off): This prints the DOT compliant
* output to check the relationship
* between the master structure,
* which represent each task class.
* - dtd_tile_hash_size (default=104729): This sets the tile hash table
* size.
* - dtd_task_hash_size (default=11): This sets the size of task hash
* table.
* - parsec_dtd_window_size (default:2048): To set the window size for the
* execution.
* - parsec_dtd_threshold_size (default:2048): This sets the threshold task
* size up to which the master
* thread will wait before going
* back and inserting task into the
* engine.
* @ingroup DTD_INTERFACE
*/
static void
parsec_dtd_lazy_init(void)
{
(void)parsec_mca_param_reg_int_name("dtd", "debug_verbose",
"This param indicates the verbosity level of separate dtd output stream and "
"also determines if we will be using a separate output stream for DTD or not\n"
"Level 50 will print relationship between task class\n"
"Level 60 will print level 50 + traversal of the DAG",
false, false, parsec_dtd_debug_verbose,
&parsec_dtd_debug_verbose);
/* Registering mca param for tile hash table size */
(void)parsec_mca_param_reg_int_name("dtd", "tile_hash_size",
"Registers the supplied size overriding the default size of tile hash table",
false, false, parsec_dtd_tile_hash_table_size,
&parsec_dtd_tile_hash_table_size);
/* Registering mca param for task hash table size */
(void)parsec_mca_param_reg_int_name("dtd", "task_hash_size",
"Registers the supplied size overriding the default size of task hash table",
false, false, parsec_dtd_task_hash_table_size,
&parsec_dtd_task_hash_table_size);
/* Registering mca param for window size */
(void)parsec_mca_param_reg_int_name("dtd", "window_size",
"Registers the supplied size overriding the default size of window size",
false, false, parsec_dtd_window_size, &parsec_dtd_window_size);
/* Registering mca param for threshold size */
(void)parsec_mca_param_reg_int_name("dtd", "threshold_size",
"Registers the supplied size overriding the default size of threshold size",
false, false, parsec_dtd_threshold_size, &parsec_dtd_threshold_size);
/* Registering mca param for threshold size */
(void)parsec_mca_param_reg_int_name("dtd", "profile_verbose",
"This param turns events that profiles task insertion and other dtd overheads",
false, false, parsec_dtd_profile_verbose, &parsec_dtd_profile_verbose);
/* Register separate dtd_debug_output_stream */
if( -1 != parsec_dtd_debug_verbose ) {
/* By default we use parsec_debug_output,
* if it is indicated otherwise, we use a separate
* stream to output dtd verbose debug information
*/
parsec_dtd_debug_output = parsec_output_open(NULL);
/* We will have only two level of verbosity
* 1. For traversal info of the DAG - level 49
* 2. Level 1 + relationship between task classes - level 50
*/
parsec_output_set_verbosity(parsec_dtd_debug_output, parsec_dtd_debug_verbose);
} else {
/* Falling back to default output stream */
parsec_dtd_debug_output = parsec_debug_output;
}
/* Initializing the tile mempool and attaching it to the tp */
parsec_dtd_tile_mempool = (parsec_mempool_t*) malloc (sizeof(parsec_mempool_t));
parsec_mempool_construct( parsec_dtd_tile_mempool,
PARSEC_OBJ_CLASS(parsec_dtd_tile_t), sizeof(parsec_dtd_tile_t),
offsetof(parsec_dtd_tile_t, mempool_owner),
1/* no. of threads*/ );
}
/* **************************************************************************** */
/**
* Fini function of Dynamic Task Discovery Interface.
*
* The global mempool of dtd_tp is destroyed here.
*
* @ingroup DTD_INTERFACE
*/
void parsec_dtd_fini(void)
{
parsec_mempool_destruct( parsec_dtd_tile_mempool );
free( parsec_dtd_tile_mempool );
if( -1 != parsec_dtd_debug_verbose ) {
parsec_output_close(parsec_dtd_debug_output);
parsec_dtd_debug_output = parsec_debug_output;
}
}
extern int __parsec_task_progress(parsec_execution_stream_t *es,
parsec_task_t *task,
int distance);
/* **************************************************************************** */
/**
* Master thread calls this to join worker threads in executing tasks.
*
* Master thread, at the end of each window, calls this function to
* join the worker thread(s) in executing tasks and takes a break
* from inserting tasks. It(master thread) remains in this function
* till the total number of pending tasks in the engine reaches a
* threshold (see parsec_dtd_threshold_size). It goes back to inserting task
* once the number of pending tasks in the engine reaches the
* threshold size.
*
* @param[in] tp
* PaRSEC dtd taskpool
*
* @ingroup DTD_INTERFACE_INTERNAL
*/
void
parsec_execute_and_come_back(parsec_taskpool_t *tp,
int task_threshold_count)
{
uint64_t misses_in_a_row;
parsec_execution_stream_t *es = parsec_my_execution_stream();
parsec_task_t *task;
int rc, distance;
struct timespec rqtp;
rqtp.tv_sec = 0;
misses_in_a_row = 1;
/* Checking if the context has been started or not */
/* The master thread might not have to trigger the barrier if the other
* threads have been activated by a previous start.
*/
if( !(PARSEC_CONTEXT_FLAG_CONTEXT_ACTIVE & tp->context->flags)) {
(void)parsec_remote_dep_on(tp->context);
/* Mark the context so that we will skip the initial barrier during the _wait */
tp->context->flags |= PARSEC_CONTEXT_FLAG_CONTEXT_ACTIVE;
/* Wake up the other threads */
parsec_barrier_wait(&(tp->context->barrier));
}
/* we wait for all tasks inserted in the taskpool but not for the communication
* invoked by those tasks.
*/
while(tp->nb_tasks > task_threshold_count) {
if( misses_in_a_row > 1 ) {
rqtp.tv_nsec = parsec_exponential_backoff(es, misses_in_a_row);
nanosleep(&rqtp, NULL);
}
misses_in_a_row++; /* assume we fail to extract a task */
if( NULL == (task = es->next_task) ) {
task = parsec_current_scheduler->module.select(es, &distance);
} else {
es->next_task = NULL;
distance = 1;
}
if( task != NULL) {
misses_in_a_row = 0; /* reset the misses counter */
rc = __parsec_task_progress(es, task, distance);
(void)rc;
}
}
}
/* **************************************************************************** */
/**
* This function unpacks the parameters of a task
*
* Unpacks all parameters of a task, the variables (in which the actual
* values will be copied) are passed from the body (function that does what
* this_task is supposed to compute) of this task and the parameters of each
* task is copied back on the passed variables
*
* @param[in] this_task
* The task we are trying to unpack the parameters for
* @param[out] ...
* The variables where the parameters will be unpacked
*
* @ingroup DTD_INTERFACE
*/
void
parsec_dtd_unpack_args(parsec_task_t *this_task, ...)
{
parsec_dtd_task_t *current_task = (parsec_dtd_task_t *)this_task;
parsec_dtd_task_class_t* tc = (parsec_dtd_task_class_t*)current_task->super.task_class;
parsec_dtd_task_param_t *current_param = GET_HEAD_OF_PARAM_LIST(current_task);
int i, data_idx = 0;
void *tmp_val;
void **tmp_ref;
va_list arguments;
va_start(arguments, this_task);
for( i = 0; i < tc->count_of_params; i++ ) {
if((current_param->op_type & PARSEC_GET_OP_TYPE) == PARSEC_VALUE ) {
tmp_val = va_arg(arguments, void*);
memcpy(tmp_val, current_param->pointer_to_tile, current_param->arg_size);
} else if((current_param->op_type & PARSEC_GET_OP_TYPE) == PARSEC_SCRATCH ||
(current_param->op_type & PARSEC_GET_OP_TYPE) == PARSEC_REF ) {
tmp_ref = va_arg(arguments, void**);
*tmp_ref = current_param->pointer_to_tile;
} else if((current_param->op_type & PARSEC_GET_OP_TYPE) == PARSEC_INPUT ||
(current_param->op_type & PARSEC_GET_OP_TYPE) == PARSEC_INOUT ||
(current_param->op_type & PARSEC_GET_OP_TYPE) == PARSEC_OUTPUT ) {
tmp_ref = va_arg(arguments, void**);
*tmp_ref = PARSEC_DATA_COPY_GET_PTR(this_task->data[data_idx].data_in);
data_idx++;
} else {
parsec_warning("/!\\ Flag is not recognized in parsec_dtd_unpack_args /!\\.\n");
assert(0);
}
current_param = current_param + 1;
}
va_end(arguments);
}
#if defined(PARSEC_PROF_TRACE)
/* **************************************************************************** */
/**
* This function returns a unique color
*
* This function takes a index and a colorspace and queries unique_color()
* for a hex color code and prepends "fills:" to that color string.
*
* @param[in] index
* @param[in] colorspace
* @return
* String containing "fill:" followed by color code returned
* by unique_color()
*
* @ingroup DTD_INTERFACE_INTERNAL
*/
static inline char *
fill_color(int index, int colorspace)
{
char *str, *color;
str = (char *)calloc(12, sizeof(char));
color = parsec_unique_color(index, colorspace);
snprintf(str, 12, "fill:%s", color + 1); /* need to remove the prepended '#' */
free(color);
return str;
}
/* **************************************************************************** */
/**
* This function adds info about a task class into a global dictionary
* used for profiling.
*
* @param[in] __tp
* The pointer to the DTD taskpool
* @param[in] task_class_id
* Id of master structure representing a
* task class
* @param[in] name
* Name of the task class
* @param[in] flow_count
* Total number of flows of the task class
*
* @ingroup DTD_INTERFACE_INTERNAL
*/
void
parsec_dtd_add_profiling_info(parsec_taskpool_t *tp,
int task_class_id,
const char *name)
{
char *str = fill_color(task_class_id, PARSEC_DTD_NB_TASK_CLASSES);
parsec_profiling_add_dictionary_keyword(name, str,
sizeof(parsec_task_prof_info_t), PARSEC_TASK_PROF_INFO_CONVERTOR,
(int *)&tp->profiling_array[START_KEY(task_class_id)] /* start key */,
(int *)&tp->profiling_array[END_KEY(task_class_id)] /* end key */ );
free(str);
}
void
parsec_dtd_add_profiling_info_generic(parsec_taskpool_t *tp,
const char *name,
int *keyin, int *keyout)
{
(void)tp;
char *str = fill_color(*keyin, PARSEC_DTD_NB_TASK_CLASSES);
parsec_profiling_add_dictionary_keyword(name, str,
sizeof(parsec_task_prof_info_t), PARSEC_TASK_PROF_INFO_CONVERTOR,
keyin,
keyout);
free(str);
}
void *parsec_dtd_task_profile_info(void *dst, const void *task_, size_t size)
{
void *ptr;
const parsec_dtd_task_t *dtd_task = (const parsec_dtd_task_t *)task_;
const parsec_dtd_task_class_t *tc = (const parsec_dtd_task_class_t*)dtd_task->super.task_class;
parsec_dtd_task_param_t *param = GET_HEAD_OF_PARAM_LIST(dtd_task);
assert( dtd_task->super.task_class->task_class_type == PARSEC_TASK_CLASS_TYPE_DTD );
memcpy(dst, &dtd_task->super.prof_info, sizeof(parsec_task_prof_info_t));
ptr = dst + sizeof(parsec_task_prof_info_t);
for( int i = 0; i < tc->count_of_params; i++ ) {
if(param->op_type & PARSEC_PROFILE_INFO) {
assert( ptr-dst < (intptr_t)size ); (void)size;
memcpy(ptr, param->pointer_to_tile, param->arg_size);
ptr += param->arg_size;
}
param = param + 1;
}
return dst;
}
#endif /* defined(PARSEC_PROF_TRACE) */
/* **************************************************************************** */
static char* parsec_dtd_task_snprintf(char *buffer, size_t buffer_size, const parsec_task_t *task)
{
const parsec_dtd_task_t* dtd_task = (const parsec_dtd_task_t *)task;
const parsec_dtd_task_class_t *tc = (const parsec_dtd_task_class_t*)dtd_task->super.task_class;
char *b = buffer;
int ret, remaining = buffer_size;
ret = snprintf(b, remaining, "%s(", tc->super.name);
if(ret < 0) {
*b = '\0';
return buffer;
}
if(ret >= remaining)
return buffer;
remaining -= ret;
b += ret;
parsec_dtd_task_param_t *current_param = GET_HEAD_OF_PARAM_LIST(dtd_task);
bool first = true;
for( int i = 0; i < tc->count_of_params; i++ ) {
if(((current_param->op_type & PARSEC_GET_OP_TYPE) == PARSEC_VALUE) &&
(current_param->arg_size == sizeof(int))) {
ret = snprintf(b, remaining, "%s%d", first ? "" : ", ", *(int*)current_param->pointer_to_tile);
} else {
ret = snprintf(b, remaining, "%s_", first ? "" : ", ");
}
first = false;
if(ret < 0) {
*b = '\0';
return buffer;
}
if(ret >= remaining)
return buffer;
remaining -= ret;
b += ret;
current_param = current_param + 1;
}
ret = snprintf(b, remaining, ")");
if(ret < 0) {
*b = '\0';
return buffer;
}
if(ret >= remaining)
return buffer;
return buffer;
}
void
parsec_dtd_track_task(parsec_dtd_taskpool_t *tp,
uint64_t key,
void *value)
{
dtd_hash_table_pointer_item_t *item = (dtd_hash_table_pointer_item_t *)parsec_thread_mempool_allocate(
tp->hash_table_bucket_mempool->thread_mempools);
parsec_hash_table_t *hash_table = tp->task_hash_table;
item->ht_item.key = (parsec_key_t)key;
item->mempool_owner = tp->hash_table_bucket_mempool->thread_mempools;
item->value = (void *)value;
parsec_hash_table_nolock_insert(hash_table, &item->ht_item);
}
void *
parsec_dtd_find_task(parsec_dtd_taskpool_t *tp,
uint64_t key)
{
parsec_hash_table_t *hash_table = tp->task_hash_table;
dtd_hash_table_pointer_item_t *item = (dtd_hash_table_pointer_item_t *)parsec_hash_table_nolock_find(hash_table,
(parsec_key_t)key);
return (NULL == item) ? NULL : item->value;
}
void *
parsec_dtd_untrack_task(parsec_dtd_taskpool_t *tp,
uint64_t key)
{
parsec_hash_table_t *hash_table = tp->task_hash_table;
void *value;
dtd_hash_table_pointer_item_t *item = (dtd_hash_table_pointer_item_t *)parsec_hash_table_nolock_find(hash_table,
(parsec_key_t)key);
if( NULL == item ) return NULL;
parsec_hash_table_nolock_remove(hash_table, (parsec_key_t)key);
value = item->value;
parsec_mempool_free(tp->hash_table_bucket_mempool, item);
return value;
}
void
parsec_dtd_track_remote_dep(parsec_dtd_taskpool_t *tp,
uint64_t key,
void *value)
{
parsec_dtd_track_task(tp, key, value);
}
void *
parsec_dtd_find_remote_dep(parsec_dtd_taskpool_t *tp,
uint64_t key)
{
return parsec_dtd_find_task(tp, key);
}
void *
parsec_dtd_untrack_remote_dep(parsec_dtd_taskpool_t *tp,
uint64_t key)
{
return parsec_dtd_untrack_task(tp, key);
}
/* **************************************************************************** */
/**
* This function registers a task class into the taskpool hash table
*
* @param[in,out] tp
* Pointer to DTD taskpool, the hash table
* is attached to the taskpool
* @param[in] key
* The key to be used for the registration. A task class should not
* be registered multiple times under different keys.
* @param[in] tc
* The pointer to the task class to be registered
*
* @ingroup DTD_INTERFACE_INTERNAL
*/
void
parsec_dtd_register_task_class(parsec_taskpool_t *tp,
uint64_t key,
parsec_task_class_t *tc)
{
parsec_dtd_taskpool_t *dtd_tp = (parsec_dtd_taskpool_t *)tp;
parsec_hash_table_t *hash_table = dtd_tp->function_h_table;
parsec_key_handle_t kh;
parsec_hash_table_lock_bucket_handle(hash_table, key, &kh);
if( parsec_hash_table_nolock_find_handle(hash_table, &kh) != NULL ) {
parsec_hash_table_unlock_bucket_handle(hash_table, &kh);
return;
}
dtd_hash_table_pointer_item_t *item =(dtd_hash_table_pointer_item_t *)
parsec_thread_mempool_allocate(dtd_tp->hash_table_bucket_mempool->thread_mempools);
item->ht_item.key = (parsec_key_t)key;
item->mempool_owner = dtd_tp->hash_table_bucket_mempool->thread_mempools;
item->value = (void *)tc;
parsec_hash_table_nolock_insert_handle(hash_table, &kh, &item->ht_item);
parsec_hash_table_unlock_bucket_handle(hash_table, &kh);
}
/**
* This function inserts the task class in the task classes
* array.
*
* @param[in,out] tp
* Pointer to DTD taskpool, the hash table
* is attached to the taskpool
* @param[in] value
* The pointer to the master structure
*
* @ingroup DTD_INTERFACE_INTERNAL
*/
void
parsec_dtd_insert_task_class(parsec_dtd_taskpool_t *tp,
parsec_dtd_task_class_t *tc)
{
#if defined(PARSEC_PROF_TRACE)
char *info_str = NULL;
int info_size = 0;
#endif
if(tc->super.task_class_id != UINT8_MAX) {
parsec_warning("Task class %s (%p) has invalid or already defined task_class_id",
(void*)tc, tc->super.name);
return;
}
tc->super.task_class_id = tp->super.nb_task_classes++;
assert(NULL == tp->super.task_classes_array[tc->super.task_class_id]);
tp->super.task_classes_array[tc->super.task_class_id] = &tc->super;
#if defined(PARSEC_PROF_TRACE)
for(int i = 0; i < tc->count_of_params; i++) {
if( tc->params[i].size != PASSED_BY_REF ) {
if( tc->params[i].op & PARSEC_PROFILE_INFO ) {
char typename[64];
assert(NULL != tc->params[i].profile_info);
info_size += tc->params[i].size;
// Unfortunately, we don't have the type... And we can only work with
// a small subset of types at the conversion level. So we use a very
// simple heuristic for the most common types (no good solution to
// define signedness, so we always take the signed version), and fallback
// to an array of chars in the other cases.
switch(tc->params[i].size) {
case sizeof(int8_t):
snprintf(typename, 64, "int8_t");
break;
case sizeof(int16_t):
snprintf(typename, 64, "int16_t");
break;
case sizeof(int32_t):
snprintf(typename, 64, "int32_t");
break;
case sizeof(int64_t):
snprintf(typename, 64, "int64_t");
break;
#if defined(PARSEC_HAVE_INT128)
case sizeof(__int128_t):
snprintf(typename, 64, "int128_t");
break;
#endif
default:
snprintf(typename, 64, "char[%d]", (int)tc->params[i].size);
}
if(NULL == info_str) {
int rc = asprintf(&info_str, PARSEC_TASK_PROF_INFO_CONVERTOR";%s{%s}", tc->params[i].profile_info, typename);
if(-1 == rc) { info_str = ""; break; }
} else {
char *tmp = info_str;
int rc = asprintf(&info_str, "%s;%s{%s}", tmp, tc->params[i].profile_info, typename);
if(-1 == rc) { info_str = tmp; info_size -= tc->params[i].size; break; }
free(tmp);