forked from AnonymousRepo123/AlphaSparse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exe_graph.cc
executable file
·3947 lines (3165 loc) · 170 KB
/
exe_graph.cc
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
#include "exe_graph.hpp"
#include "user_pruning_strategy.hpp"
set<template_type> supported_template_of_sub_matrix(sparse_struct_t *matrix, unsigned long dense_block_id)
{
assert(matrix != NULL);
assert(matrix->block_coor_table.item_arr.size() > 0 && dense_block_id < matrix->block_coor_table.item_arr.size());
set<template_type> return_template_type_set;
// 子矩阵的表格项
dense_block_table_item_t *sub_matrix = matrix->block_coor_table.item_arr[dense_block_id];
assert(sub_matrix != NULL);
assert(sub_matrix->compressed_block_ptr != NULL);
assert(sub_matrix->compressed_block_ptr->read_index.size() == 7);
// 所有的检查,压缩的版本可以覆盖不压缩的版本
bool is_supported = false;
is_supported = is_supported_by_unaligned_warp_reduce_same_TLB_size_template(matrix, dense_block_id) && is_supported_by_unaligned_warp_reduce_same_TLB_size_template_with_user_strategy(matrix, dense_block_id);
if (is_supported == true)
{
// 一般来说,UNALIGNED_WARP_REDUCE_SAME_TLB_SIZE_TEMPLATE和UNALIGNED_WARP_REDUCE_SAME_TLB_SIZE_TEMPLATE_WITH_WARP_REDUCE的支持条件是一样的
// cout << "UNALIGNED_WARP_REDUCE_SAME_TLB_SIZE_TEMPLATE" << endl;
return_template_type_set.insert(UNALIGNED_WARP_REDUCE_SAME_TLB_SIZE_TEMPLATE);
}
// UNALIGNED_WARP_REDUCE_SAME_TLB_SIZE_TEMPLATE_WITH_WARP_REDUCE多了一个tblock数量的限制,因为UNALIGNED_WARP_REDUCE_SAME_TLB_SIZE_TEMPLATE_WITH_WARP_REDUCE要求
// 在thread in block的数量一定的前提下,为了让总线程的数量将将多于TLB的数量,需要做一个检查
is_supported = is_supported_by_unaligned_warp_reduce_same_TLB_size_template_with_warp_reduce(matrix, dense_block_id) && is_supported_be_unaligned_warp_reduce_same_TLB_size_template_with_warp_reduce_with_user_strategy(matrix, dense_block_id);
if (is_supported == true)
{
return_template_type_set.insert(UNALIGNED_WARP_REDUCE_SAME_TLB_SIZE_TEMPLATE_WITH_WARP_REDUCE);
}
// 极度压缩,首先是warp和block的压缩
is_supported = is_supported_by_direct_atom_template_warp_block_compress(matrix, dense_block_id) && is_supported_by_direct_atom_template_warp_block_compress_with_user_strategy(matrix, dense_block_id);
// 小的不行检查大的
if (is_supported == false)
{
is_supported = is_supported_by_direct_atom_template_warp_compress(matrix, dense_block_id) && is_supported_by_direct_atom_template_warp_compress_with_user_strategy(matrix, dense_block_id);
if (is_supported == false)
{
is_supported = is_supported_by_direct_atom_template(matrix, dense_block_id) && is_supported_by_direct_atom_template_with_user_strategy(matrix, dense_block_id);
if (is_supported == false)
{
cout << "cannot pass check in direct_atom_template" << endl;
}
else
{
return_template_type_set.insert(DIRECT_ATOM_TEMPLATE);
}
}
else
{
// 通过了检查,将对应的模板类型记录下来
return_template_type_set.insert(DIRECT_ATOM_TEMPLATE_WARP_COMPRESS);
}
}
else
{
return_template_type_set.insert(DIRECT_ATOM_TEMPLATE_WARP_BLOCK_COMPRESS);
}
// shared memory的压缩
is_supported = is_supported_by_shared_memory_template_warp_compress(matrix, dense_block_id) && is_supported_by_shared_memory_template_warp_compress_with_user_strategy(matrix, dense_block_id);
if (is_supported == false)
{
is_supported = is_supported_by_shared_memory_template(matrix, dense_block_id) && is_supported_by_shared_memory_template_with_user_strategy(matrix, dense_block_id);
if (is_supported == true)
{
return_template_type_set.insert(SHARED_MEMORY_TEMPLATE);
}
}
else
{
return_template_type_set.insert(SHARED_MEMORY_TEMPLATE_WARP_COMPRESS);
}
// 带上warp归约的原子加
is_supported = is_supported_by_direct_atom_total_warp_reduce_template(matrix, dense_block_id) && is_supported_by_direct_atom_total_warp_reduce_template_with_user_strategy(matrix, dense_block_id);
if (is_supported == true)
{
return_template_type_set.insert(DIRECT_ATOM_TOTAL_WARP_REDUCE_TEMPLATE);
}
// 所有的归约层次全部使用
is_supported = is_supported_by_shared_memory_long_row_template(matrix, dense_block_id) && is_supported_by_shared_memory_long_row_template_with_user_strategy(matrix, dense_block_id);
if (is_supported == true)
{
return_template_type_set.insert(SHARED_MEMORY_LONG_ROW_TEMPLATE);
}
// warp不跨行
is_supported = is_supported_by_shared_memory_total_warp_reduce_template(matrix, dense_block_id) && is_supported_by_shared_memory_total_warp_reduce_template_with_user_strategy(matrix, dense_block_id);
if (is_supported == true)
{
return_template_type_set.insert(SHARED_MEMORY_TOTAL_WARP_REDUCE_TEMPLATE);
}
if (return_template_type_set.size() == 0)
{
cout << "this matrix can not be supported by all existing template" << endl;
}
else
{
return_template_type_set = filter_from_existing_template_set(return_template_type_set);
}
return return_template_type_set;
}
exe_begin_memory_cache_input_file_param_t get_exe_begin_memory_cache_input_file_param_from_coo_file(string file_name, data_type type)
{
assert(type == DOUBLE || type == FLOAT);
vector<float> float_val_vec;
vector<double> double_val_vec;
unsigned long max_col_index;
unsigned long max_row_index;
vector<unsigned long> col_index_vec;
vector<unsigned long> row_index_vec;
get_matrix_index_and_val_from_file(file_name, row_index_vec, col_index_vec, float_val_vec, double_val_vec, type, max_row_index, max_col_index);
exe_begin_memory_cache_input_file_param_t param;
param.col_index_cache = col_index_vec;
param.row_index_cache = row_index_vec;
param.float_val_cache = float_val_vec;
param.double_val_cache = double_val_vec;
param.col_index_max = max_col_index;
param.row_index_max = max_row_index;
param.val_data_type = type;
// 将结果直接返回
return param;
}
bool dependence_of_exe_begin_artificial_input_node(exe_graph_t *graph, exe_sub_graph_type graph_type, exe_begin_artificial_input_param_t param, int sub_graph, int input_index)
{
// 只判断输入的合法性
assert(graph != NULL && (input_index == GRAPH_END || input_index <= graph->dense_sub_graph.exe_node_vec.size()));
if (graph_type != EXE_DENSE_SUB_GRAPH)
{
return false;
}
if (sub_graph != 0)
{
return false;
}
if (graph_type == EXE_DENSE_SUB_GRAPH)
{
assert(sub_graph == 0);
}
// 全场只能有一个输入节点
for (int dense_node_id = 0; dense_node_id < graph->dense_sub_graph.exe_node_vec.size(); dense_node_id++)
{
exe_node_t node = graph->dense_sub_graph.exe_node_vec[dense_node_id];
assert(node.param != NULL);
if (node.type == BEGIN_ARTIFICIAL_INPUT || node.type == BEGIN_INPUT_FILE || node.type == BEGIN_MEMORY_CACHE_INPUT_FILE)
{
return false;
}
}
// 检查一下依赖,只能放在开头,或者在啥都没有的时候放在末尾
if (input_index == 0)
{
}
else if (input_index == GRAPH_END && graph->dense_sub_graph.exe_node_vec.size() == 0)
{
}
else
{
return false;
}
return true;
}
bool dependence_of_exe_compress_node(exe_graph_t *graph, exe_sub_graph_type graph_type, exe_compress_param_t param, int sub_graph, int input_index)
{
assert(graph != NULL && (input_index == GRAPH_END || input_index <= graph->dense_sub_graph.exe_node_vec.size()));
// compress的插入位置是稠密视图
if (graph_type != EXE_DENSE_SUB_GRAPH)
{
return false;
}
if (sub_graph != 0)
{
return false;
}
// 节点的位置和当前图的状态都会影响依赖,在加入这个节点的时候,已经加入了输入,插入的位置是稠密矩阵的最后一个位置
if (graph->dense_sub_graph.exe_node_vec.size() == 0)
{
return false;
}
// 第一个位置已经有输入节点
if (graph->dense_sub_graph.exe_node_vec[0].type != BEGIN_INPUT_FILE && graph->dense_sub_graph.exe_node_vec[0].type != BEGIN_ARTIFICIAL_INPUT && graph->dense_sub_graph.exe_node_vec[0].type != BEGIN_MEMORY_CACHE_INPUT_FILE)
{
return false;
}
// 插入在稠密矩阵视图的最后
if (input_index != graph->dense_sub_graph.exe_node_vec.size() && input_index != GRAPH_END)
{
return false;
}
// 实际上压缩视图是空的
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec.size() != 0)
{
return false;
}
// 在之前不能出现compress
for (int dense_node_id = 0; dense_node_id < graph->dense_sub_graph.exe_node_vec.size(); dense_node_id++)
{
exe_node_t node = graph->dense_sub_graph.exe_node_vec[dense_node_id];
assert(node.param != NULL);
if (node.type == COMPRESS)
{
return false;
}
}
return true;
}
// 从内存中初始化一个矩阵的节点
bool dependence_of_exe_begin_memory_cache_input_file_node(exe_graph_t *graph, exe_sub_graph_type graph_type, exe_begin_memory_cache_input_file_param_t param, int sub_graph, int input_index)
{
assert(graph != NULL && (input_index == GRAPH_END || input_index <= graph->dense_sub_graph.exe_node_vec.size()));
if (graph_type != EXE_DENSE_SUB_GRAPH)
{
return false;
}
if (sub_graph != 0)
{
return false;
}
if (graph_type == EXE_DENSE_SUB_GRAPH)
{
assert(sub_graph == 0);
}
// 全场只能有一个输入节点
for (int dense_node_id = 0; dense_node_id < graph->dense_sub_graph.exe_node_vec.size(); dense_node_id++)
{
exe_node_t node = graph->dense_sub_graph.exe_node_vec[dense_node_id];
assert(node.param != NULL);
if (node.type == BEGIN_ARTIFICIAL_INPUT || node.type == BEGIN_INPUT_FILE || node.type == BEGIN_MEMORY_CACHE_INPUT_FILE)
{
return false;
}
}
// 检查一下依赖,只能放在开头,或者在啥都没有的时候放在末尾
//
if (input_index == 0)
{
}
else if (input_index == GRAPH_END && graph->dense_sub_graph.exe_node_vec.size() == 0)
{
}
else
{
return false;
}
return true;
}
// 依赖和人工输入节点差不多
bool dependence_of_exe_begin_input_file_node(exe_graph_t *graph, exe_sub_graph_type graph_type, exe_begin_input_file_param_t param, int sub_graph, int input_index)
{
// 只判断输入的合法性
assert(graph != NULL && (input_index == GRAPH_END || input_index <= graph->dense_sub_graph.exe_node_vec.size()));
if (graph_type != EXE_DENSE_SUB_GRAPH)
{
return false;
}
if (sub_graph != 0)
{
return false;
}
if (graph_type == EXE_DENSE_SUB_GRAPH)
{
assert(sub_graph == 0);
}
// 全场只能有一个输入节点
for (int dense_node_id = 0; dense_node_id < graph->dense_sub_graph.exe_node_vec.size(); dense_node_id++)
{
exe_node_t node = graph->dense_sub_graph.exe_node_vec[dense_node_id];
assert(node.param != NULL);
if (node.type == BEGIN_ARTIFICIAL_INPUT || node.type == BEGIN_INPUT_FILE || node.type == BEGIN_MEMORY_CACHE_INPUT_FILE)
{
return false;
}
}
// 检查一下依赖,只能放在开头,或者在啥都没有的时候放在末尾
if (input_index == 0)
{
}
else if (input_index == GRAPH_END && graph->dense_sub_graph.exe_node_vec.size() == 0)
{
}
else
{
return false;
}
return true;
}
bool dependence_of_exe_dense_row_div_node(exe_graph_t *graph, exe_sub_graph_type graph_type, exe_dense_row_div_param_t param, int sub_graph, int input_index)
{
// 判断行分块是不是是不是可以被枚举。行分块只能添加到操作序列的尾部。
assert(graph != NULL && (input_index == GRAPH_END || input_index == graph->dense_sub_graph.exe_node_vec.size()));
assert(param.row_div_position.size() > 0);
if (graph_type != EXE_DENSE_SUB_GRAPH)
{
return false;
}
if (sub_graph != 0)
{
return false;
}
// 并且保证之前出现了输入节点
if (graph->dense_sub_graph.exe_node_vec.size() > 0)
{
if (graph->dense_sub_graph.exe_node_vec[0].type != BEGIN_INPUT_FILE && graph->dense_sub_graph.exe_node_vec[0].type != BEGIN_ARTIFICIAL_INPUT && graph->dense_sub_graph.exe_node_vec[0].type != BEGIN_MEMORY_CACHE_INPUT_FILE)
{
return false;
}
}
else
{
return false;
}
// 依赖通过
return true;
}
bool dependence_of_exe_dense_fixed_col_div_node(exe_graph_t *graph, exe_sub_graph_type graph_type, exe_dense_fixed_col_div_param_t param, int sub_graph, int input_index)
{
assert(graph != NULL && (input_index == GRAPH_END || input_index == graph->dense_sub_graph.exe_node_vec.size()));
assert(param.fixed_col_block_size > 0);
if (graph_type != EXE_DENSE_SUB_GRAPH)
{
return false;
}
if (sub_graph != 0)
{
return false;
}
// 并且保证之前出现了输入节点
if (graph->dense_sub_graph.exe_node_vec.size() > 0)
{
if (graph->dense_sub_graph.exe_node_vec[0].type != BEGIN_INPUT_FILE && graph->dense_sub_graph.exe_node_vec[0].type != BEGIN_ARTIFICIAL_INPUT && graph->dense_sub_graph.exe_node_vec[0].type != BEGIN_MEMORY_CACHE_INPUT_FILE)
{
return false;
}
}
else
{
return false;
}
// 保证之前没有出现compress
if (graph->dense_sub_graph.preorder_node_set.count(COMPRESS) != 0)
{
return false;
}
return true;
}
bool dependence_of_exe_dense_row_coarse_sort_node(exe_graph_t *graph, exe_sub_graph_type graph_type, exe_dense_row_coarse_sort_param_t param, int sub_graph, int input_index)
{
// 只能加到尾部
assert(graph != NULL && (input_index == GRAPH_END || input_index == graph->dense_sub_graph.exe_node_vec.size()));
assert(param.bin_row_nnz_low_bound.size() > 0);
assert(param.bin_row_nnz_low_bound[0] == 0);
// 之前必须有输入节点
if (graph->dense_sub_graph.preorder_node_set.count(BEGIN_ARTIFICIAL_INPUT) == 0 && graph->dense_sub_graph.preorder_node_set.count(BEGIN_INPUT_FILE) == 0 && graph->dense_sub_graph.preorder_node_set.count(BEGIN_MEMORY_CACHE_INPUT_FILE) == 0)
{
// 没有出现输入节点,不能通过
return false;
}
// 之前不能有分块节点,主要是因为还没实现
if (graph->dense_sub_graph.preorder_node_set.count(DENSE_FIXED_COL_DIV) != 0)
{
return false;
}
if (graph->dense_sub_graph.preorder_node_set.count(DENSE_ROW_DIV) != 0)
{
return false;
}
// 排序不能排两次
if (graph->dense_sub_graph.preorder_node_set.count(DENSE_ROW_COARSE_SORT) != 0)
{
return false;
}
if (graph->dense_sub_graph.preorder_node_set.count(DENSE_FINE_SORT) != 0)
{
return false;
}
if (graph->dense_sub_graph.preorder_node_set.count(DENSE_BLOCK_SORT) != 0)
{
return false;
}
// 之前不能出现compress
if (graph->dense_sub_graph.preorder_node_set.count(COMPRESS) != 0)
{
return false;
}
return true;
}
bool dependence_of_exe_compress_BLB_row_div_node(exe_graph_t *graph, exe_sub_graph_type graph_type, exe_compress_tblock_level_row_div_param_t param, int sub_graph, int input_index)
{
// 必须在执行完稠密子图的部分之后再执行
assert(graph != NULL && graph->op_manager->matrix != NULL);
// 子块的大小和子图的数量是一致的
assert(graph->total_compressed_sub_graph.compressed_sub_graph_vec.size() == graph->op_manager->matrix->block_coor_table.item_arr.size());
// 子图的编号小于子块的数量
assert(sub_graph < graph->total_compressed_sub_graph.compressed_sub_graph_vec.size());
// 节点添加的位置只能加到尾部
assert(input_index == GRAPH_END || input_index == graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].exe_node_vec.size());
// 保证所有所有线程块粒度的行号加起来正好是对应压缩子块的行数量
assert(graph->op_manager->matrix->block_coor_table.item_arr[sub_graph]->max_dense_row_index >= graph->op_manager->matrix->block_coor_table.item_arr[sub_graph]->min_dense_row_index);
unsigned long row_num_of_sub_matrix = graph->op_manager->matrix->block_coor_table.item_arr[sub_graph]->max_dense_row_index - graph->op_manager->matrix->block_coor_table.item_arr[sub_graph]->min_dense_row_index + 1;
unsigned long sum_tmp = 0;
for (auto item : param.row_num_of_each_BLB)
{
sum_tmp = sum_tmp + item;
}
assert(sum_tmp == row_num_of_sub_matrix);
// 在之前不能出现其他任何类型的分块
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_TBLOCK_LEVEL_ROW_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_TBLOCK_LEVEL_COL_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_WARP_LEVEL_ROW_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_WARP_LEVEL_COL_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_THREAD_LEVEL_ROW_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_THREAD_LEVEL_COL_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_THREAD_LEVEL_NNZ_DIV) != 0)
{
return false;
}
return true;
}
bool dependence_of_exe_compress_BLB_col_div_node(exe_graph_t *graph, exe_sub_graph_type graph_type, exe_compress_tblock_level_col_div_param_t param, int sub_graph, int input_index)
{
// 必须在执行完稠密子图的部分之后再执行
assert(graph != NULL && graph->op_manager->matrix != NULL);
// 子块的大小和子图的数量是一致的
assert(graph->total_compressed_sub_graph.compressed_sub_graph_vec.size() == graph->op_manager->matrix->block_coor_table.item_arr.size());
// 子图的编号小于子块的数量
assert(sub_graph < graph->total_compressed_sub_graph.compressed_sub_graph_vec.size());
// 节点添加的位置只能加到尾部
assert(input_index == GRAPH_END || input_index == graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].exe_node_vec.size());
// 保证所有所有线程块粒度的行号加起来正好是对应压缩子块的行数量
assert(graph->op_manager->matrix->block_coor_table.item_arr[sub_graph]->max_dense_row_index >= graph->op_manager->matrix->block_coor_table.item_arr[sub_graph]->min_dense_row_index);
// 列块数组的大小肯定大于0的
assert(param.col_block_nnz_num_of_each_BLB.size() > 0 && param.col_block_nnz_num_of_each_BLB[0].size() > 0);
// 在之前不能出现其他任何类型的分块
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_TBLOCK_LEVEL_ROW_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_TBLOCK_LEVEL_COL_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_WARP_LEVEL_ROW_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_WARP_LEVEL_COL_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_THREAD_LEVEL_ROW_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_THREAD_LEVEL_COL_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_THREAD_LEVEL_NNZ_DIV) != 0)
{
return false;
}
return true;
}
bool dependence_of_exe_compress_WLB_row_div_node(exe_graph_t *graph, exe_sub_graph_type graph_type, exe_compress_warp_level_row_div_param_t param, int sub_graph, int input_index)
{
// 必须在执行完稠密子图的部分之后再执行
assert(graph != NULL && graph->op_manager->matrix != NULL);
// 子块的大小和子图的数量是一致的
assert(graph->total_compressed_sub_graph.compressed_sub_graph_vec.size() == graph->op_manager->matrix->block_coor_table.item_arr.size());
// 子图的编号小于子块的数量
assert(sub_graph < graph->total_compressed_sub_graph.compressed_sub_graph_vec.size());
// 节点添加的位置只能加到尾部
assert(input_index == GRAPH_END || input_index == graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].exe_node_vec.size());
// 保证所有所有线程块粒度的行号加起来正好是对应压缩子块的行数量
assert(graph->op_manager->matrix->block_coor_table.item_arr[sub_graph]->max_dense_row_index >= graph->op_manager->matrix->block_coor_table.item_arr[sub_graph]->min_dense_row_index);
// 列块数组的大小肯定大于0的
assert(param.row_num_of_each_WLB_in_BLB.size() > 0 && param.row_num_of_each_WLB_in_BLB[0].size() > 0);
// 在之前不能出现warp级别和thread级别的所有分块
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_WARP_LEVEL_ROW_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_WARP_LEVEL_COL_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_THREAD_LEVEL_ROW_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_THREAD_LEVEL_COL_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_THREAD_LEVEL_NNZ_DIV) != 0)
{
return false;
}
return true;
}
bool dependence_of_exe_compress_WLB_col_div_node(exe_graph_t *graph, exe_sub_graph_type graph_type, exe_compress_warp_level_col_div_param_t param, int sub_graph, int input_index)
{
// 必须在执行完稠密子图的部分之后再执行
assert(graph != NULL && graph->op_manager->matrix != NULL);
// 子块的大小和子图的数量是一致的
assert(graph->total_compressed_sub_graph.compressed_sub_graph_vec.size() == graph->op_manager->matrix->block_coor_table.item_arr.size());
// 子图的编号小于子块的数量
assert(sub_graph < graph->total_compressed_sub_graph.compressed_sub_graph_vec.size());
// 节点添加的位置只能加到尾部
assert(input_index == GRAPH_END || input_index == graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].exe_node_vec.size());
// 保证所有所有线程块粒度的行号加起来正好是对应压缩子块的行数量
assert(graph->op_manager->matrix->block_coor_table.item_arr[sub_graph]->max_dense_row_index >= graph->op_manager->matrix->block_coor_table.item_arr[sub_graph]->min_dense_row_index);
// 列块数组的大小肯定大于0的
assert(param.col_num_of_WLB_in_each_parent_row_block_or_BLB.size() > 0 && param.col_num_of_WLB_in_each_parent_row_block_or_BLB[0].size() > 0);
// 列切分块的大小是32的倍数
for (unsigned long i = 0; i < param.col_num_of_WLB_in_each_parent_row_block_or_BLB.size(); i++)
{
for (unsigned long j = 0; j < param.col_num_of_WLB_in_each_parent_row_block_or_BLB[i].size(); j++)
{
if (param.col_num_of_WLB_in_each_parent_row_block_or_BLB[i][j] % 32 != 0)
{
cout << "nnz of WLB must be multiples of 32" << endl;
assert(false);
}
}
}
// 在之前不能出现warp级别和thread级别的所有分块
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_WARP_LEVEL_ROW_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_WARP_LEVEL_COL_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_THREAD_LEVEL_ROW_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_THREAD_LEVEL_COL_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_THREAD_LEVEL_NNZ_DIV) != 0)
{
return false;
}
return true;
}
bool dependence_of_exe_compress_TLB_row_div_node(exe_graph_t *graph, exe_sub_graph_type graph_type, exe_compress_thread_level_row_div_param_t param, int sub_graph, int input_index)
{
// 必须在执行完稠密子图的部分之后再执行
assert(graph != NULL && graph->op_manager->matrix != NULL);
// 子块的大小和子图的数量是一致的
assert(graph->total_compressed_sub_graph.compressed_sub_graph_vec.size() == graph->op_manager->matrix->block_coor_table.item_arr.size());
// 子图的编号小于子块的数量
assert(sub_graph < graph->total_compressed_sub_graph.compressed_sub_graph_vec.size());
// 节点添加的位置只能加到尾部
assert(input_index == GRAPH_END || input_index == graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].exe_node_vec.size());
assert(graph->op_manager->matrix->block_coor_table.item_arr[sub_graph]->max_dense_row_index >= graph->op_manager->matrix->block_coor_table.item_arr[sub_graph]->min_dense_row_index);
// 之前不能出现所有thread级别的排序方式
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_THREAD_LEVEL_ROW_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_THREAD_LEVEL_COL_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_THREAD_LEVEL_NNZ_DIV) != 0)
{
return false;
}
return true;
}
bool dependence_of_exe_compress_TLB_col_div_node(exe_graph_t *graph, exe_sub_graph_type graph_type, exe_compress_thread_level_col_div_param_t param, int sub_graph, int input_index)
{
// 必须在执行完稠密子图的部分之后再执行
assert(graph != NULL && graph->op_manager->matrix != NULL);
// 子块的大小和子图的数量是一致的
assert(graph->total_compressed_sub_graph.compressed_sub_graph_vec.size() == graph->op_manager->matrix->block_coor_table.item_arr.size());
// 子图的编号小于子块的数量
assert(sub_graph < graph->total_compressed_sub_graph.compressed_sub_graph_vec.size());
// 节点添加的位置只能加到尾部
assert(input_index == GRAPH_END || input_index == graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].exe_node_vec.size());
assert(graph->op_manager->matrix->block_coor_table.item_arr[sub_graph]->max_dense_row_index >= graph->op_manager->matrix->block_coor_table.item_arr[sub_graph]->min_dense_row_index);
// 之前不能出现所有thread级别的排序方式
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_THREAD_LEVEL_ROW_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_THREAD_LEVEL_COL_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_THREAD_LEVEL_NNZ_DIV) != 0)
{
return false;
}
return true;
}
bool dependence_of_exe_compress_thread_level_nnz_div_node(exe_graph_t *graph, exe_sub_graph_type graph_type, exe_compress_thread_level_nnz_div_param_t param, int sub_graph, int input_index)
{
// 必须在执行完稠密子图的部分之后再执行
assert(graph != NULL && graph->op_manager->matrix != NULL);
// 子块的大小和子图的数量是一致的
assert(graph->total_compressed_sub_graph.compressed_sub_graph_vec.size() == graph->op_manager->matrix->block_coor_table.item_arr.size());
// 子图的编号小于子块的数量
assert(sub_graph < graph->total_compressed_sub_graph.compressed_sub_graph_vec.size());
// 之前不能出现任何种类的分块
// 在之前不能出现其他任何类型的分块
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_TBLOCK_LEVEL_ROW_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_TBLOCK_LEVEL_COL_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_WARP_LEVEL_ROW_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_WARP_LEVEL_COL_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_THREAD_LEVEL_ROW_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_THREAD_LEVEL_COL_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_THREAD_LEVEL_NNZ_DIV) != 0)
{
return false;
}
// 之前不能出现压缩视图下的padding
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_ROW_PADDING) != 0)
{
return false;
}
return true;
}
bool dependence_of_exe_compress_row_padding_node(exe_graph_t *graph, exe_sub_graph_type graph_type, exe_compress_row_padding_param_t param, int sub_graph, int input_index)
{
// 必须在执行完稠密子图的部分之后再执行
assert(graph != NULL && graph->op_manager->matrix != NULL);
// 子块的大小和子图的数量是一致的
assert(graph->total_compressed_sub_graph.compressed_sub_graph_vec.size() == graph->op_manager->matrix->block_coor_table.item_arr.size());
// 子图的编号小于子块的数量
assert(sub_graph < graph->total_compressed_sub_graph.compressed_sub_graph_vec.size());
// 在之前不能出现其他任何类型的分块
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_TBLOCK_LEVEL_ROW_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_TBLOCK_LEVEL_COL_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_WARP_LEVEL_ROW_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_WARP_LEVEL_COL_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_THREAD_LEVEL_ROW_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_THREAD_LEVEL_COL_DIV) != 0)
{
return false;
}
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_THREAD_LEVEL_NNZ_DIV) != 0)
{
return false;
}
// 之前不能出现row padding
if (graph->total_compressed_sub_graph.compressed_sub_graph_vec[sub_graph].preorder_node_set.count(COMPRESSED_ROW_PADDING) != 0)
{
return false;
}
return true;
}
void reset_param_of_all_sub_compressed_graph(exe_compressed_sub_graph_t* sub_compressed_graph)
{
assert(sub_compressed_graph != NULL);
assert(sub_compressed_graph->exe_node_vec.size() > 0 && sub_compressed_graph->preorder_node_set.size() > 0);
for (unsigned long i = 0; i < sub_compressed_graph->exe_node_vec.size(); i++)
{
// 当前节点的大小
if (sub_compressed_graph->exe_node_vec[i].type == COMPRESSED_ROW_PADDING)
{
assert(sub_compressed_graph->exe_node_vec[i].param != NULL);
delete (exe_compress_row_padding_param_t *)sub_compressed_graph->exe_node_vec[i].param;
sub_compressed_graph->exe_node_vec[i].param = new exe_compress_row_padding_param_t();
}
else if (sub_compressed_graph->exe_node_vec[i].type == COMPRESSED_TBLOCK_LEVEL_ROW_DIV)
{
assert(sub_compressed_graph->exe_node_vec[i].param != NULL);
delete (exe_compress_tblock_level_row_div_param_t *)sub_compressed_graph->exe_node_vec[i].param;
sub_compressed_graph->exe_node_vec[i].param = new exe_compress_tblock_level_row_div_param_t();
}
else if (sub_compressed_graph->exe_node_vec[i].type == COMPRESSED_TBLOCK_LEVEL_COL_DIV)
{
assert(sub_compressed_graph->exe_node_vec[i].param != NULL);
delete (exe_compress_tblock_level_col_div_param_t *)sub_compressed_graph->exe_node_vec[i].param;
sub_compressed_graph->exe_node_vec[i].param = new exe_compress_tblock_level_col_div_param_t();
}
else if (sub_compressed_graph->exe_node_vec[i].type == COMPRESSED_WARP_LEVEL_ROW_DIV)
{
assert(sub_compressed_graph->exe_node_vec[i].param != NULL);
delete (exe_compress_warp_level_row_div_param_t *)sub_compressed_graph->exe_node_vec[i].param;
sub_compressed_graph->exe_node_vec[i].param = new exe_compress_warp_level_row_div_param_t();
}
else if (sub_compressed_graph->exe_node_vec[i].type == COMPRESSED_WARP_LEVEL_COL_DIV)
{
assert(sub_compressed_graph->exe_node_vec[i].param != NULL);
delete (exe_compress_warp_level_col_div_param_t *)sub_compressed_graph->exe_node_vec[i].param;
sub_compressed_graph->exe_node_vec[i].param = new exe_compress_warp_level_col_div_param_t();
}
else if (sub_compressed_graph->exe_node_vec[i].type == COMPRESSED_THREAD_LEVEL_ROW_DIV)
{
assert(sub_compressed_graph->exe_node_vec[i].param != NULL);
delete (exe_compress_thread_level_row_div_param_t *)sub_compressed_graph->exe_node_vec[i].param;
sub_compressed_graph->exe_node_vec[i].param = new exe_compress_thread_level_row_div_param_t();
}
else if (sub_compressed_graph->exe_node_vec[i].type == COMPRESSED_THREAD_LEVEL_COL_DIV)
{
assert(sub_compressed_graph->exe_node_vec[i].param != NULL);
delete (exe_compress_thread_level_col_div_param_t *)sub_compressed_graph->exe_node_vec[i].param;
sub_compressed_graph->exe_node_vec[i].param = new exe_compress_thread_level_col_div_param_t();
}
else if (sub_compressed_graph->exe_node_vec[i].type == COMPRESSED_THREAD_LEVEL_NNZ_DIV)
{
assert(sub_compressed_graph->exe_node_vec[i].param != NULL);
delete (exe_compress_thread_level_nnz_div_param_t *)sub_compressed_graph->exe_node_vec[i].param;
sub_compressed_graph->exe_node_vec[i].param = new exe_compress_thread_level_nnz_div_param_t();
}
else
{
cout << "reset_param_of_all_sub_compressed_graph: exe node type is not supported" << endl;
assert(false);
}
}
}
void reset_param_of_all_sub_dense_graph(exe_dense_sub_graph* sub_dense_graph)
{
assert(sub_dense_graph != NULL);
assert(sub_dense_graph->exe_node_vec.size() > 0 && sub_dense_graph->preorder_node_set.size() > 0);
for (unsigned long i = 0; i < sub_dense_graph->exe_node_vec.size(); i++)
{
// 根据当前节点的类型来重置其参数
if (sub_dense_graph->exe_node_vec[i].type == BEGIN_MEMORY_CACHE_INPUT_FILE)
{
assert(sub_dense_graph->exe_node_vec[i].param != NULL);
delete (exe_begin_memory_cache_input_file_param_t *)sub_dense_graph->exe_node_vec[i].param;
sub_dense_graph->exe_node_vec[i].param = new exe_begin_memory_cache_input_file_param_t();
}
else if (sub_dense_graph->exe_node_vec[i].type == DENSE_ROW_COARSE_SORT)
{
assert(sub_dense_graph->exe_node_vec[i].param != NULL);
delete (exe_dense_row_coarse_sort_param_t *)sub_dense_graph->exe_node_vec[i].param;
sub_dense_graph->exe_node_vec[i].param = new exe_dense_row_coarse_sort_param_t();
}
else if (sub_dense_graph->exe_node_vec[i].type == DENSE_ROW_DIV)
{
assert(sub_dense_graph->exe_node_vec[i].param != NULL);
delete (exe_dense_row_div_param_t *)sub_dense_graph->exe_node_vec[i].param;
sub_dense_graph->exe_node_vec[i].param = new exe_dense_row_div_param_t();
}
else if (sub_dense_graph->exe_node_vec[i].type == COMPRESS)
{
assert(sub_dense_graph->exe_node_vec[i].param != NULL);
delete (exe_compress_param_t *)sub_dense_graph->exe_node_vec[i].param;
sub_dense_graph->exe_node_vec[i].param = new exe_compress_param_t();
}
else
{
cout << "reset_param_of_all_sub_dense_graph: exe node type is not supported" << endl;
assert(false);
}
}
}
void malloc_param_of_all_sub_compressed_graph(exe_compressed_sub_graph_t* sub_compressed_graph)
{
assert(sub_compressed_graph != NULL);
assert(sub_compressed_graph->exe_node_vec.size() > 0 && sub_compressed_graph->preorder_node_set.size() > 0);
for (unsigned long i = 0; i < sub_compressed_graph->exe_node_vec.size(); i++)
{
// 当前节点的大小
if (sub_compressed_graph->exe_node_vec[i].type == COMPRESSED_ROW_PADDING)
{
assert(sub_compressed_graph->exe_node_vec[i].param != NULL);
sub_compressed_graph->exe_node_vec[i].param = new exe_compress_row_padding_param_t();
}
else if (sub_compressed_graph->exe_node_vec[i].type == COMPRESSED_TBLOCK_LEVEL_ROW_DIV)
{
assert(sub_compressed_graph->exe_node_vec[i].param != NULL);
sub_compressed_graph->exe_node_vec[i].param = new exe_compress_tblock_level_row_div_param_t();
}
else if (sub_compressed_graph->exe_node_vec[i].type == COMPRESSED_TBLOCK_LEVEL_COL_DIV)
{
assert(sub_compressed_graph->exe_node_vec[i].param != NULL);
sub_compressed_graph->exe_node_vec[i].param = new exe_compress_tblock_level_col_div_param_t();