-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathasic_core.cpp
More file actions
4932 lines (4611 loc) · 187 KB
/
asic_core.cpp
File metadata and controls
4932 lines (4611 loc) · 187 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
#include "asic_core.hh"
asic_core::asic_core()
{
for (int i = 0; i < LANE_WIDTH; ++i)
{
_in_order_flag[i] = true;
_waiting_count[i] = 0;
}
for (int t = 0; t < NUM_TQ_PER_CORE; ++t)
{
_pending_task[t].vid = -1;
}
}
// The buffer from memory is a vector port; others are dfg port -- can be of variable length
bool asic_core::can_push_in_prefetch(int lane_id)
{
return (_pref_lsq[lane_id].size() < _agg_fifo_length);
}
bool asic_core::can_push_in_gcn_bank()
{
return ((_hit_gcn_updates.size() < _agg_fifo_length) && (_miss_gcn_updates.size() < _agg_fifo_length));
// return ((_hit_gcn_updates.size() < 0.5*FIFO_DEP_LEN) && (_miss_gcn_updates.size() < 1.5*FIFO_DEP_LEN));
}
bool asic_core::can_push_in_process(int lane_id)
{
return (_prefetch_process[lane_id].size() < _agg_fifo_length);
}
bool asic_core::can_push_in_reduce(int lane_id)
{
return (_process_reduce[lane_id].size() < _agg_fifo_length);
}
bool asic_core::can_push_to_cgra_event_queue()
{
bool flag = true;
int num_dfg = _fine_grain_throughput / _asic->_config->_process_thr;
for (int i = 0; i < num_dfg; ++i)
{
if (_cgra_event_queue[i].size() > _agg_fifo_length)
{
flag = false;
}
}
return flag; // (_cgra_event_queue.size() < FIFO_DEP_LEN);
}
// @vidushi: triangle counting: func(edge list of cur_tuple.dst_id and edge list of cur_tuple.src_id)
void asic_core::insert_vector_task(pref_tuple cur_tuple, bool spawn, int dfg_id)
{
if (_asic->_config->_tc && MAX_DFGS > 1)
{
assert(dfg_id > -1 && "we want to implement parallel dfgs");
_last_dfg_id = dfg_id;
}
// total finished edges should have been more right??
// cout << "Pushing a vector task for vid: " << cur_tuple.edge.dst_id << " at core: " << _core_id << " cycle: " << _asic->_cur_cycle << endl;
DTYPE prio = 0;
// int ready_cycle = _cur_free_cycle[_last_dfg_id] + DFG_LENGTH + bus_width/VEC_LEN; // cur_tuple.update_width/VEC_LEN;
int throughput = _asic->get_update_operation_throughput(cur_tuple.src_id, cur_tuple.edge.dst_id);
int latency = _asic->get_update_operation_latency();
int ready_cycle = _cur_free_cycle[_last_dfg_id] + latency + throughput;
int dst_id = cur_tuple.edge.dst_id;
if (_asic->_config->_pull_mode)
{
dst_id = cur_tuple.src_id;
}
gcn_update new_up(dst_id, spawn, cur_tuple, ready_cycle, prio);
new_up.second_buffer = cur_tuple.second_buffer;
if (_asic->_config->_algo == gcn)
{
assert(spawn == false && new_up.spawn == false);
}
if (_asic->_config->_tc && MAX_DFGS > 1)
{
new_up.thr = throughput;
_asic->_gcn_updates[dfg_id] += new_up.thr;
}
_cgra_event_queue[_last_dfg_id].push_back(new_up);
_cur_free_cycle[_last_dfg_id] = ready_cycle - latency; // pipelined issue
// cout << "Pushing a new event for gcn updates with dst_id: " << dst_id << " throughput " << throughput << " at core: " << _core_id << " cycle: " << _asic->_cur_cycle << " ready cycle: " << ready_cycle << " new free cycle: " << _cur_free_cycle << " and dfg id: " << _last_dfg_id << endl;
_asic->_stats->_stat_pushed_to_ps++;
if (!(_asic->_config->_tc && MAX_DFGS > 1))
{
_last_dfg_id = (_last_dfg_id + 1) % (_fine_grain_throughput / _asic->_config->_process_thr);
}
}
// TODO: add count for how many elements are added. (and check that only)
void asic_core::push_gcn_cache_miss(pref_tuple cur_tuple)
{
if (_asic->_config->_update_coalesce)
{
if (_asic->_task_ctrl->_present_in_miss_gcn_queue[cur_tuple.edge.dst_id] == 0)
{
_miss_gcn_updates.push_back(cur_tuple);
}
else
{ // here it should do compute-coalescing (push into cgra_event_queue)
insert_vector_task(cur_tuple, false);
++_asic->_mem_ctrl->_l2accesses;
++_asic->_mem_ctrl->_l2hits;
return;
}
++_asic->_task_ctrl->_present_in_miss_gcn_queue[cur_tuple.edge.dst_id];
}
else
{
_miss_gcn_updates.push_back(cur_tuple);
}
}
void asic_core::insert_prefetch_process(int lane_id, int priority, pref_tuple cur_tuple)
{
if (_asic->_config->_algo != gcn)
priority = 0;
// if(_asic->_cur_cycle<210) {
// cout << "In cycle: " << _asic->_cur_cycle << " core: " << _core_id << " pushed update from src_id: " << cur_tuple.src_id << " and dst: " << cur_tuple.edge.dst_id << endl;
// }
// assert(cur_tuple.src_id>=0 && cur_tuple.src_id<V);
auto it = _prefetch_process[lane_id].find(priority);
if (it == _prefetch_process[lane_id].end())
{
list<pref_tuple> x;
x.push_back(cur_tuple);
_prefetch_process[lane_id].insert(make_pair(priority, x));
}
else
{
it->second.push_back(cur_tuple);
}
}
void asic_core::pop_from_prefetch_process()
{
auto it = _prefetch_process[0].begin();
assert(it != _prefetch_process[0].end() && "should have entry while popping from it it");
(it->second).pop_front();
if ((it->second).empty())
{
_prefetch_process[0].erase(it->first);
}
}
void asic_core::push_gcn_cache_hit(pref_tuple cur_tuple)
{
_priority_hit_gcn_updates.push_back(cur_tuple);
++_asic->_mem_ctrl->_l2hits;
return;
// ++_asic->_mem_ctrl->_l2accesses;
// ++_asic->_mem_ctrl->_l2hits;
// _hit_gcn_updates.push_back(cur_tuple);
/*
if(_asic->_config->_update_coalesce) {
if (_asic->_task_ctrl->_present_in_miss_gcn_queue[cur_tuple.edge.dst_id]==0) {
_hit_gcn_updates.push_back(cur_tuple);
}
++_asic->_task_ctrl->_present_in_miss_gcn_queue[cur_tuple.edge.dst_id];
} else {
_hit_gcn_updates.push_back(cur_tuple);
}*/
// _hit_gcn_updates.push_back(cur_tuple);
}
// Step1: access the task queue to kill if this vid task is at the top of
// the queue (task queue prefetch rate should be slow for this case to be
// true)
// Step2: discard all the remaining updates (prevent computation somehow)
void asic_core::trigger_break_operations(int vid)
{
// search for vid at the priority=-1 to kill it
for (int tqid = 0; tqid < NUM_TQ_PER_CORE; ++tqid)
{
if (_pending_task[tqid].vid == vid)
{
_pending_task[tqid].vid = -1;
}
_asic->_task_ctrl->_present_in_local_queue[_core_id].reset(vid);
break;
/*if(_task_queue[tqid][0].empty()) continue;
auto it=_task_queue[tqid][0].begin();
task_entry cur_task = (it->second).front(); //_task_queue[t].front();
if(cur_task.vid==vid) { // pop the task
(it->second).pop_front();
if((it->second).empty()) {
_task_queue[tqid][0].erase(it->first);
}
_asic->_task_ctrl->_present_in_local_queue[_core_id].reset(vid);
_asic->_task_ctrl->_remaining_task_entries[_core_id][tqid]++;
break;
}*/
}
// discard the pending updates in the pipeline (skip it for now)
}
// What if the bank queue is full? then the reduce can pop the data. Push over
// the network, and at the net_out_buffer, when it cannot pop -- it will apply
// a backpressure in the network?
bool asic_core::can_push_in_local_bank_queue(int bank_id)
{
return (_local_bank_queues[bank_id].size() < FIFO_DEP_LEN);
}
// FIXME: not sure if required!!
void asic_core::set_dist_at_dequeue(task_entry &cur_task, pref_tuple &next_tuple)
{
if (_asic->_config->_domain == tree)
{
return;
}
if (_asic->_config->_algo == pr)
{
return;
}
if ((_asic->_config->is_async() || _asic->_switched_async) && !_asic->_switched_sync && !_asic->_config->is_vector())
{
cur_task.dist = _asic->_scratch[cur_task.vid];
}
/*if(_asic->_config->_algo==pr) {
// assert(cur_task.dist!=0 && "a task should not be created at src dist to be 0");
_asic->_scratch[cur_task.vid]=0;
if(_asic->_switched_async) {
next_tuple.src_dist = cur_task.dist; // _asic->_scratch[cur_task.vid];// it->first;
assert(next_tuple.src_dist>=0 && "correct src dist was assigned");
}
}*/
}
// FIXME: is it fixed again when data is returned from memory? (why is it set
// here?)
void asic_core::set_src_dist(task_entry cur_task, pref_tuple &next_tuple)
{
// TODO: vidushi: it should use the dist at creation, not dequeue
if (_asic->_config->_algo == pr)
{
// cout << "Vid: " << cur_task.vid << " dist of cur task: " << cur_task.dist << "\n";
next_tuple.src_dist = cur_task.dist;
return;
}
int src_id = next_tuple.src_id;
if (_asic->_config->is_sync() || _asic->_switched_sync)
{
if (_asic->_switched_async && _asic->_config->_domain != tree)
{
next_tuple.src_dist = _asic->_scratch[src_id];
}
else
{
next_tuple.src_dist = cur_task.dist; // it->first;
}
}
else if (_asic->_config->is_async())
{
next_tuple.src_dist = cur_task.dist; // it->first;
}
else if (_asic->_config->_exec_model == graphlab)
{
// if(_asic->_cur_cycle<_asic->_atomic_issue_cycle[src_id]+2) return;
next_tuple.src_dist = _asic->_scratch[src_id];
}
else if (_asic->_config->_exec_model == dijkstra)
{
next_tuple.src_dist = _asic->_scratch[src_id];
}
}
void asic_core::push_live_task(DTYPE priority_order, task_entry new_task)
{
_asic->_stats->_stat_online_tasks++;
if (_asic->_config->_prac == 0 || _asic->_config->_work_stealing == 0)
{
_asic->_task_ctrl->insert_new_task(0, 0, _asic->_scratch_ctrl->get_local_scratch_id(new_task.vid), priority_order, new_task);
return;
}
int check_index = _agg_push_index;
// then push into the queue
int tqid = check_index;
/*
int sample=check_index/2;
int one = sample*2;
int two = (sample*2) + 1;
tqid = one;
int p1=INF;
if(!_task_queue[one][0].empty()) {
p1 = _task_queue[one][0].begin()->first;
}
int p2=INF;
if(!_task_queue[two][0].empty()) {
p2 = _task_queue[two][0].begin()->first;
}
// push new task in a core with higher priority...but we should also
// try to balance the number of elements (that's done when elements are
// pulled from the FIFO queue)
if(p1<p2) tqid=two;
if(p2<p1) tqid=one;
if(_asic->_config->_num_tq_per_core==1) tqid=0;
check_index=tqid;
*/
_aggregation_buffer[check_index].push_back(make_pair((priority_order), new_task));
_agg_push_index = (check_index + 1) % _asic->_config->_num_tq_per_core;
}
void asic_core::create_async_task(DTYPE priority_order, task_entry new_task)
{
int dest_core_for_task = _asic->_scratch_ctrl->get_local_scratch_id(new_task.vid);
if (_asic->_config->_perfect_lb == 0 && _asic->_config->_net == mesh)
{
assert(dest_core_for_task == _core_id && "computation is near data");
}
if (_asic->_config->_domain == tree)
{
dest_core_for_task = 0;
}
// int degree = _asic->_offset[new_task.vid+1]-_asic->_offset[new_task.vid];
int slice_num = _asic->_scratch_ctrl->get_slice_num(new_task.vid);
// statistics
if (slice_num != _asic->_current_slice && !_asic->_switched_cache)
{
if (_asic->_config->_algo == pr)
{ // not sure why?
_asic->_stats->_stat_tot_num_copy_updates++;
}
}
else
{ // get stats for the percentage used in the current slice..
if (_asic->_task_ctrl->_check_vertex_done_this_phase.test(new_task.vid) != 1)
{
_asic->_stats->_stat_owned_tasks_this_phase++;
_asic->_task_ctrl->_check_vertex_done_this_phase.set(new_task.vid);
}
}
// No need to push in task queue if 1. belong to other slice 2. it is the
// finishing phase
if ((slice_num != _asic->_current_slice && !_asic->_switched_cache) || _asic->_async_finishing_phase)
{
_asic->_slice_fill_addr[slice_num]++; // FIXME: What is this?
if (_asic->_task_ctrl->_check_worklist_duplicate[slice_num].test(new_task.vid) != 1)
{
// cout << "Pushed a task to a different global task queue\n";
_asic->_task_ctrl->push_task_into_worklist(slice_num, priority_order, new_task);
_asic->_task_ctrl->_check_worklist_duplicate[slice_num].set(new_task.vid);
// _asic->_stats->_stat_remote_tasks_this_phase++;
}
else
{
if (slice_num != _asic->_current_slice)
{
_asic->_stats->_stat_num_dupl_copy_vertex_updates++;
}
}
}
else
{ // push into the task queue here...
_asic->_asic_cores[dest_core_for_task]->push_live_task(priority_order, new_task);
}
}
// I think this is for multicast: we would like to wait for all dst_id so that
// we can multicast?
int asic_core::access_all_edges(int line_addr, task_entry cur_task, pref_tuple next_tuple)
{
// TODO: this is the vectorized access of src vector, a different type of access
// this seems like accessing all edges for this source vector? shouldn't this
// be true for all edges?
// next_tuple.arob_entry = cur_task.start_offset;
int cur_task_start_offset = cur_task.start_offset;
// cout << "Setting edge arob entry to: " << next_tuple.arob_entry << endl;
int num_cache_lines_per_src = _asic->_offset[cur_task.vid + 1] - cur_task.start_offset;
num_cache_lines_per_src = ceil(num_cache_lines_per_src * message_size / (float)line_size);
assert(num_cache_lines_per_src != 0);
if (_asic->_config->_algo == gcn && _asic->_config->_ladies_gcn == 0)
{
num_cache_lines_per_src = min(SAMPLE_SIZE, num_cache_lines_per_src);
}
int edges_served = _asic->_compl_buf[_core_id]->_entries_remaining; // 1 entry for each..
assert(edges_served > 0 && "entries should be remaining in the completion buffer");
if (num_cache_lines_per_src <= edges_served)
{ // cool, good to go!
edges_served = _asic->_offset[cur_task.vid + 1] - cur_task.start_offset;
}
else
{ // serve only the edges that are left..
num_cache_lines_per_src = edges_served;
edges_served = edges_served * (line_size / message_size);
}
// num_cache_lines_per_src = ceil(num_cache_lines_per_src*4/(float)line_size);
// next_tuple.cb_entry = _asic->_compl_buf[_core_id]->allocate_cb_entry(num_cache_lines_per_src);
if ((_asic->_config->_exec_model == sync || _asic->_config->_exec_model == sync_slicing || _asic->_switched_sync) && cur_task.start_offset == _asic->_offset[cur_task.vid])
{
// assuming I just assidned it for src vertices...!!!
int cb_push = _asic->_compl_buf[_core_id]->_cur_cb_push_ptr;
cb_push = (cb_push - 1) % COMPLETION_BUFFER_SIZE;
if (cb_push < 0)
cb_push += COMPLETION_BUFFER_SIZE;
next_tuple.cb_entry = cb_push;
_asic->_compl_buf[_core_id]->_reorder_buf[cb_push].waiting_addr += num_cache_lines_per_src;
// cout << "Current waiting addr: " << _asic->_compl_buf[_core_id]->_reorder_buf[cb_push].waiting_addr << " at entry " << cb_push << endl;
}
else
{
next_tuple.cb_entry = _asic->_compl_buf[_core_id]->allocate_cb_entry(num_cache_lines_per_src);
}
// FIXME: is it sure that the updated entry will have this thing.. (if edge
// is served first?)
// next_tuple.entry_cycle = next_tuple.arob_entry + edges_served;
next_tuple.start_edge_served = cur_task_start_offset;
next_tuple.end_edge_served = cur_task_start_offset + edges_served;
next_tuple.core_type = fineMem;
// cout << "Sent memory request for start_edge: " << next_tuple.start_edge_served << " end edge: " << next_tuple.end_edge_served << endl;
next_tuple.req_core = _core_id;
// cout << "Sending edge src: " << next_tuple.src_id << " src_core: " << next_tuple.req_core << " cb_entry: " << next_tuple.cb_entry << " lines: " << num_cache_lines_per_src << " cycle: " << _asic->_cur_cycle << endl;
for (int i = 0; i < num_cache_lines_per_src; ++i)
{
_asic->_mem_ctrl->send_mem_request(false, line_addr, next_tuple, EDGE_SID);
line_addr += line_size;
}
// cout << "Sending edge access request for vid: " << next_tuple.src_id << " num cache lines: " << num_cache_lines_per_src << " core: " << _core_id << " cycle: " << _asic->_cur_cycle << endl;
return edges_served;
// int src_id = cur_task.vid;
// cur_task.start_offset = _asic->_offset[src_id+1];
}
void asic_core::access_src_vertex_prop(task_entry cur_task, pref_tuple next_tuple)
{
// return; // idea is that first edge should use the same entry
// uint64_t addr_offset=E*4/line_size;
// TODO: For GCN, it should send based on the current layer feature
// size and the number of cache lines involved
int num_cache_line_requests = 1;
uint64_t vid_addr = (_asic->_mem_ctrl->_vertex_offset + cur_task.vid * 4 / line_size) * line_size;
// FIXME: since it has more requests, some CB entries are not dropped and this is not the waiting_addr of the just the last element
/*
#if GCN==1 || CF==1
num_cache_line_requests = FEAT_LEN1*message_size/line_size;
vid_addr = _asic->_mem_ctrl->_vertex_offset + (_asic->_scratch_ctrl->_mapping[cur_task.vid]*num_cache_line_requests)*line_size;
#endif
*/
next_tuple.cb_entry = _asic->_compl_buf[_core_id]->allocate_cb_entry(num_cache_line_requests);
assert((_asic->_config->_heter_cores == 0 || _core_id == _asic->_scratch_ctrl->get_local_scratch_id(next_tuple.src_id)) && "fine task should have affinity to its core");
// cout << "Sending src_vertex_requests for entry: " << next_tuple.cb_entry << " req_core: " << _core_id << " for src: " << next_tuple.src_id << " lines: " << num_cache_line_requests << " cycle: " << _asic->_cur_cycle << endl;
next_tuple.req_core = _core_id;
// next_tuple.arob_entry = cur_task.start_offset;
next_tuple.end_edge_served = -1;
next_tuple.core_type = dummyCB;
// cout << "Setting arob entry to: " << cur_task.start_offset << endl;
for (int c = 0; c < num_cache_line_requests; ++c)
{
_asic->_mem_ctrl->send_mem_request(false, vid_addr, next_tuple, VERTEX_SID);
vid_addr += line_size;
}
}
int asic_core::access_edge(task_entry cur_task, int edge_id, pref_tuple next_tuple)
{
if ((_asic->_config->_exec_model == sync || _asic->_config->_exec_model == sync_slicing || _asic->_switched_sync) && cur_task.start_offset == _asic->_offset[cur_task.vid] && !_asic->_config->_pull_mode)
{
access_src_vertex_prop(cur_task, next_tuple);
}
if (_asic->_config->_exec_model == async || _asic->_config->_exec_model == sync_slicing)
{
// TODO: access scratchpad for reading original vertex ID and store the
// output in memory
}
// cout << "Remaining entries after serving source vertex prop: " << _asic->_compl_buf[_core_id]->_entries_remaining << endl;
// Creating the memory tuple it is waiting for!!
// Step 1: return entry (TODO: Why does it need extra entry if coalesced, any
// specific access?)
// int line_addr = _asic->_mem_ctrl->get_edge_addr(edge_id);
int line_addr = _asic->_mem_ctrl->get_edge_addr(edge_id, cur_task.vid);
next_tuple.req_core = _core_id;
// _asic->_stats->_stat_dist_tasks_dequed[_core_id]++;
_asic->_stats->_stat_dist_edges_dequed[_core_id]++;
// Step2: copy the data already
next_tuple.edge = _asic->_neighbor[edge_id];
int edges_served = 1;
// Step 1: access edges
// #if ALL_EDGE_ACCESS==0 // FIXME: I am not sure what is this doing...
if (_asic->_config->_all_edge_access == 0)
{
// this is for edge access -- this is for a single cache line???
next_tuple.cb_entry = _asic->_compl_buf[_core_id]->allocate_cb_entry(1);
next_tuple.core_type = fineMem;
// cout << "Sending memory request for src_id: " << next_tuple.src_id << " and dest: " << next_tuple.edge.dst_id << endl;
/*if(_asic->_config->_domain==tree) {
// TODO: just push to completion buffer directly (ideally I should do a scratch read)
// TODO: just want to load the location of the next memory location (that can be derived from vprop only)
_asic->_scratch_ctrl->send_scratch_request(_core_id, line_addr, next_tuple); // should be scratch_addr
} else {
_asic->_mem_ctrl->send_mem_request(false, line_addr, next_tuple, EDGE_SID);
}*/
_asic->_mem_ctrl->send_mem_request(false, line_addr, next_tuple, EDGE_SID);
// TODO: one by one? (so this function should be called by dispatch? why
// different for sgu_gcn_reorder? can't we vectorize without it?) -- 1 cb
// entry per edge (too small)
// Oh some issue here
/*if(next_tuple.src_id==38036) {
cout << "Sending edge access request1 for vid: " << next_tuple.src_id << " num cache lines: " << 1 << " core: " << _core_id << " cycle: " << _asic->_cur_cycle << " and cb entry: " << next_tuple.cb_entry << endl;
}*/
}
else
{
// TODO: why the above thing doesn't work for GCN?
edges_served = access_all_edges(line_addr, cur_task, next_tuple);
}
assert(edges_served > 0 && "we should serve positive number of edges for gcn");
return edges_served;
}
void asic_core::push_lsq_data(pref_tuple cur_tuple)
{
// assert(_pref_lsq[0].size() < FIFO_DEP_LEN && "cannot push more data in pref lsq core");
_pref_lsq[0].push(cur_tuple); // TODO: skipping lane id for now
}
void asic_core::send_scalar_packet(pref_tuple cur_tuple)
{
// TODO: FIX for this case as well...
int max_edges = _asic->_offset[cur_tuple.src_id + 1] - _asic->_offset[cur_tuple.src_id];
#if GCN == 1 && LADIES_GCN == 0
max_edges = min(SAMPLE_SIZE, max_edges);
#endif
int dst_core = -1;
int src_core = _asic->_scratch_ctrl->get_local_scratch_id(cur_tuple.src_id);
// src_id, dst_id, lane_id=0
net_packet multicast_net_packet[core_cnt]; // packet to each destination
bitset<core_cnt> _dest_done;
_dest_done.reset();
for (int i = _asic->_offset[cur_tuple.src_id]; i < (_asic->_offset[cur_tuple.src_id] + max_edges); ++i)
{
// cout << "Issuing packets for src: " << cur_tuple.src_id << " dst: " << _asic->_neighbor[i].dst_id << endl;
dst_core = _asic->_scratch_ctrl->get_local_scratch_id(_asic->_neighbor[i].dst_id);
// Here destinations may not equal to the number of dst_id, FIXME: NET: do
// they know this???
// multicast_net_packet[dst_core].multicast_dst.push_back(_asic->_neighbor[i].dst_id);
multicast_net_packet[dst_core].multicast_dst_wgt.push_back(make_pair(_asic->_neighbor[i].dst_id, _asic->_neighbor[i].wgt));
_dest_done.set(dst_core);
}
// now push those packets
for (int i = 0; i < core_cnt; ++i)
{
if (!_dest_done.test(i))
continue;
// if(net_packet[i].src_id==-1) continue;
// cout << "i: " << i << " dst_core: " << net_packet[i].dest_core_id << endl;
// assert(net_packet[i].dest_core_id==i);
if (i == src_core || _asic->_config->_perfect_net)
{ // push to the current core for all required entries
_asic->_network->_stat_local_updates++;
for (unsigned j = 0; j < multicast_net_packet[i].multicast_dst_wgt.size(); ++j)
{
pref_tuple return_to_arob;
return_to_arob.src_id = cur_tuple.src_id;
return_to_arob.second_buffer = cur_tuple.second_buffer;
return_to_arob.edge.dst_id = multicast_net_packet[i].multicast_dst_wgt[j].first;
return_to_arob.edge.wgt = multicast_net_packet[i].multicast_dst_wgt[j].second;
// return_to_arob.lane_id=0;
int dest_core = _asic->_scratch_ctrl->get_local_scratch_id(multicast_net_packet[i].multicast_dst_wgt[j].first);
// cout << "(Match) Src_id: " << cur_tuple.src_id << " and degree: " << _asic->get_degree(cur_tuple.src_id) << " and dst_id: " << return_to_arob.edge.dst_id << endl;
// _asic->_asic_cores[dest_core]->_prefetch_process[0].push_back(return_to_arob);
_asic->_asic_cores[dest_core]->insert_prefetch_process(0, 0, return_to_arob);
}
}
else
{ // push to the network which does the same thing
// in the real case, push N gcn packess for each combination and do the
// same thing at the destination
#if PERFECT_NET == 0
multicast_net_packet[i] = _asic->_network->create_vector_update_packet(cur_tuple.tid, cur_tuple.src_id, multicast_net_packet[i].multicast_dst_wgt, cur_tuple.vertex_data);
// net_packet[i].dest_core_id = i;
// net_packet[i].dst_id = -1; // _asic->_neighbor[i].dst_id;
// net_packet[i].src_id = cur_tuple.src_id;
// net_packet[i].packet_type=vectorized;
// net_packet[i].req_core_id=-1;
// for(int f=0; f<FEAT_LEN; ++f) multicast_net_packet[i].vertex_data[f] = cur_tuple.vertex_data[f];
for (int l = 0; l < num_packets; ++l)
{
_asic->_network->push_net_packet(_core_id, multicast_net_packet[i]);
}
#else
// this is also if perfect_net=1
// this should directly push to prefetch process queue
// cout << "At core i: " << i << " multicast dest: " << net_packet[i].multicast_dst.size() << endl;
// num_pops++;
for (unsigned j = 0; j < multicast_net_packet[i].multicast_dst_wgt.size(); ++j)
{
// this should be for number of packets right?
for (int l = 0; l < num_packets; ++l)
{
pref_tuple return_to_arob;
return_to_arob.src_id = cur_tuple.src_id;
return_to_arob.second_buffer = cur_tuple.second_buffer;
return_to_arob.edge.dst_id = multicast_net_packet[i].multicast_dst_wgt[j].first;
return_to_arob.edge.wgt = multicast_net_packet[i].multicast_dst_wgt[j].second;
// return_to_arob.lane_id=0;
return_to_arob.update_width = bus_width;
int dest_core = i;
for (int f = 0; f < FEAT_LEN; ++f)
return_to_arob.vertex_data[f] = cur_tuple.vertex_data[f];
#if GRAPHMAT_SLICING == 1 && REUSE > 1
if (_asic->_finishing_phase)
{ // this should actually be access to the cache
_asic->_asic_cores[dest_core]->insert_prefetch_process(0, 0, return_to_arob);
}
else
{
int dest_slice = _asic->get_slice_num(cur_tuple.edge.dst_id);
// cout << " current slice: " << _asic->_current_slice << " dest slice: " << dest_slice << endl;
if (_asic->_current_slice != dest_slice)
{
_asic->_delta_updates[_asic->_current_reuse].push_back(make_pair(cur_tuple.edge.dst_id, -1));
}
else
{
_asic->_asic_cores[dest_core]->insert_prefetch_process(0, 0, return_to_arob);
}
}
#else
// cout << "Src_id: " << cur_tuple.src_id << " and degree: " << _asic->get_degree(cur_tuple.src_id+1) << endl;
_asic->_asic_cores[dest_core]->insert_prefetch_process(0, 0, return_to_arob);
#endif
}
}
#endif
}
}
}
void asic_core::send_multicast_packet(pref_tuple cur_tuple, int start_offset, int end_offset)
{
net_packet net_tuple;
vector<iPair> mcast_dst_wgt;
/*for(int i=start_offset; i<end_offset; ++i) {
cout << "Sending edges from start: " << start_offset << " end: " << end_offset << " for src: " << cur_tuple.src_id << endl;
}*/
// there have been second buffer tasks as well (what if something happened
// over network?)
// cout << "Serving source id: " << cur_tuple.src_id << " start_offset: " << start_offset << " end_offset: " << end_offset << " buffer: " << cur_tuple.second_buffer << endl;
int src_core = _asic->_scratch_ctrl->get_local_scratch_id(cur_tuple.src_id);
int dst_core = -1;
int max_edges = end_offset - start_offset;
for (int i = start_offset; i < end_offset; ++i)
{
_asic->_edges_served++; // FIXME: here there are more than the things there.. (edges_served)
int slice_num = _asic->_scratch_ctrl->get_slice_num(_asic->_neighbor[i].dst_id);
// just stats calculation for the l2 hits
if (slice_num != _asic->_current_slice)
{
_asic->_mem_ctrl->_l2accesses++;
uint64_t paddr = _asic->_neighbor[i].dst_id * message_size * FEAT_LEN;
bool l2hit = _asic->_mem_ctrl->is_cache_hit(_core_id, paddr, ACCESS_LOAD, true, 0); // check cache statistics
if (l2hit)
_asic->_mem_ctrl->_l2hits++;
}
// cout << " src_id: " << cur_tuple.src_id << " src_core: " << src_core << " current core: " << _core_id << endl;
assert((_asic->_config->_heter_cores == 0 || _core_id == src_core) && "source vertex data should be ready at its data location");
dst_core = _asic->_scratch_ctrl->get_local_scratch_id(_asic->_neighbor[i].dst_id);
// Okay, correct till here...
if (src_core == dst_core)
_asic->_debug_local++;
else
_asic->_debug_remote++;
net_tuple.multicast_dst_wgt.push_back(make_pair(_asic->_neighbor[i].dst_id, _asic->_neighbor[i].wgt));
mcast_dst_wgt.push_back(make_pair(_asic->_neighbor[i].dst_id, _asic->_neighbor[i].wgt));
#if PERFECT_NET == 0
#if GRAPHMAT_SLICING == 1 && REUSE > 1 // multicast & network & sliced push
if (_asic->_finishing_phase)
{ // this should actually be access to the cache
net_tuple.multicast_dst_core_id.push_back(dst_core);
}
else
{
int dest_slice = _asic->_scratch_ctrl->get_slice_num(_asic->_neighbor[i].dst_id);
if (_asic->_current_slice != dest_slice)
{
_asic->_delta_updates[_asic->_current_reuse].push_back(make_pair(_asic->_neighbor[i].dst_id, -1));
}
else
{
net_tuple.multicast_dst_core_id.push_back(dst_core);
}
}
#else // multicast & network & normal push
net_tuple.multicast_dst_core_id.push_back(dst_core);
#endif
#else // for pefect_net==1
// TODO: push only if it belongs to the current core -- this is when
// perfect net=1
#if GRAPHMAT_SLICING == 1 && REUSE > 1
int dest_slice = _asic->get_slice_num(_asic->_neighbor[i].dst_id);
if (_asic->_finishing_phase || _asic->_current_slice == dest_slice)
{
net_tuple.multicast_dst_core_id.push_back(src_core);
}
else
{
_asic->_delta_updates[_asic->_current_reuse].push_back(make_pair(_asic->_neighbor[i].dst_id, -1));
}
#else
net_tuple.multicast_dst_core_id.push_back(src_core);
#endif
#endif
}
// TODO/FIXME: remove redundant calculations of dest core id
net_tuple = _asic->_network->create_vector_update_packet(cur_tuple.tid, cur_tuple.src_id, mcast_dst_wgt, cur_tuple.vertex_data);
net_tuple.second_buffer = cur_tuple.second_buffer;
if (net_tuple.multicast_dst_wgt.size() > 0)
{
/*for(int i=0; i<net_tuple.multicast_dst_core_id.size(); ++i) {
// okay dest here are only less
cout << "Dst size: " << net_tuple.multicast_dst.size() << " dst core: " << net_tuple.multicast_dst_core_id.size() << endl;
}*/
for (int k = 0; k < num_packets; ++k)
{
net_tuple.push_cycle = k;
// TODO: check how many pulled from multicast.. (till now I have not
// put barrier here)
_asic->_network->push_net_packet(_core_id, net_tuple);
}
}
}
void asic_core::access_cache_for_gcn_updates(pref_tuple cur_tuple, int start_offset, int end_offset)
{
bool l2hit = true;
int ratio = line_size / bus_width;
for (int i = start_offset; i < end_offset; ++i)
{
// TODO: put a condition when dst core is full, if not, then send the index
uint64_t base_addr = _asic->_mem_ctrl->_vertex_offset; // _asic->_neighbor[i].dst_id*message_size*FEAT_LEN;
for (int j = 0; j < num_packets; ++j)
{
pref_tuple update_tuple;
update_tuple.end_edge_served = j;
update_tuple.update_width = bus_width;
update_tuple.edge.dst_id = _asic->_neighbor[i].dst_id;
// if(_asic->_neighbor[i].dst_id==2404)
// cout << "src was: " << cur_tuple.src_id << endl;
// update_tuple.lane_id=0;
update_tuple.src_id = cur_tuple.src_id;
/*if(cur_tuple.second_buffer) {
cout << "A second buffer agg was identified in the memory request queue\n";
}*/
update_tuple.second_buffer = cur_tuple.second_buffer;
// so src_id makes it double, hence we can get 2x speedup..
uint64_t paddr = base_addr + (update_tuple.edge.dst_id * message_size * FEAT_LEN) + (j * bus_width);
// if(j%ratio==0)
int dst_core = _asic->_scratch_ctrl->get_local_scratch_id(update_tuple.edge.dst_id);
if (_asic->_config->_cache_hit_aware_sched)
{
update_tuple.src_dist = _asic->_cur_cycle;
int priority = _asic->_task_ctrl->get_cache_hit_aware_priority(_core_id, 0, -1, update_tuple.edge.dst_id, _asic->_local_coalescer[_core_id]->_batch_width, -1);
_asic->_asic_cores[dst_core]->insert_prefetch_process(0, priority, update_tuple);
continue;
}
bool l2hit = _asic->_mem_ctrl->is_cache_hit(_core_id, paddr, ACCESS_LOAD, true, 0);
// cout << "Access request at address: " << paddr << " and dst_id: " << cur_tuple.edge.dst_id << " hit? " << l2hit << endl;
// TODO: I could use the same algorithm to push in the task queue -- could even
// use the same function (just need to update the data-structure for
// prefetch_process)
if (!l2hit)
{
if (_asic->_config->_cache_hit_aware_sched)
{
// TODO: If same dst_id is available in the miss_gcn queue, merge it and increase the numbers of edges executed.
bool found = false;
/*for(auto it=_miss_gcn_updates.begin(); it!=_miss_gcn_updates.end(); ++it) {
if(it->edge.dst_id==update_tuple.edge.dst_id) {
found=true;
++_asic->_stats->_stat_tot_finished_edges;
++_asic->_mem_ctrl->_l2hits;
++_asic->_mem_ctrl->_l2accesses;
if(!update_tuple.second_buffer) {
--_asic->_correct_vertex_data[update_tuple.edge.dst_id];
} else {
--_asic->_correct_vertex_data_double_buffer[update_tuple.edge.dst_id];
}
// break;
}
}*/
if (!found)
{
update_tuple.src_dist = _asic->_cur_cycle;
push_gcn_cache_miss(update_tuple);
}
else
{
cout << "Merged an update from miss queue GCN for dst: " << update_tuple.edge.dst_id << "\n";
}
}
else
{
update_tuple.cb_entry = -1; // unordered packet
update_tuple.req_core = _core_id;
bool sent_request = _asic->_mem_ctrl->send_mem_request(false, paddr, update_tuple, VERTEX_SID);
// FIXME: even will all miss, this is the coalescing which is leading
// to so many hits..(So what is this condition??)
// if(j%ratio==0) {
if (!sent_request)
_asic->_mem_ctrl->_l2hits++;
// else cout << "Sent scratch request for vid: " << update_tuple.src_id << endl;
_asic->_mem_ctrl->_l2accesses++;
// }
_asic->_stats->_stat_pending_cache_misses++;
_asic->_mem_ctrl->_num_pending_cache_reqs++;
}
}
else
{
// cout << "Sending update for edge i: " << i << endl;
// if(j%ratio==0)
if (_asic->_config->_cache_hit_aware_sched)
{
update_tuple.src_dist = _asic->_cur_cycle;
// _asic->_asic_cores[dst_core]->_hit_gcn_updates.push_back(update_tuple);
push_gcn_cache_hit(update_tuple);
}
else
{
_asic->_mem_ctrl->_l2hits++;
_asic->_mem_ctrl->_l2accesses++;
// _asic->_asic_cores[dst_core]->_prefetch_process[0].push_back(update_tuple);
_asic->_asic_cores[dst_core]->insert_prefetch_process(0, 0, update_tuple);
}
}
// just push to delta updates as well, because we do not want to apply it
if (_asic->_config->_exec_model == sync_slicing && _asic->_config->_reuse > 1 && !_asic->_finishing_phase)
{
int dest_slice = _asic->_scratch_ctrl->get_slice_num(update_tuple.edge.dst_id);
if (_asic->_current_slice != dest_slice)
{
_asic->_delta_updates[_asic->_current_reuse].push_back(make_pair(update_tuple.edge.dst_id, -1));
}
}
}
}
}
void asic_core::generate_gcn_net_packet(pref_tuple cur_tuple, int start_offset, int end_offset)
{
int max_edges = end_offset - start_offset;
// TODO: for working cache, do as it would be for perfect network case or
// when src_id matches core_id (WE WOULD ALSO LIKE TO LIMIT BANDWIDTH)
if (_asic->_config->_working_cache)
{
// scan over dst id, find hits and push those in arob
// if not matching, send requests for misses (and this would be multiple
// cache lines, if half are available?)
// accumulate these in send_mem_request...no cmpl_buf -- but something to
// make sure accumulation is available...
access_cache_for_gcn_updates(cur_tuple, start_offset, end_offset);
return;
}
// Oh, it is creating packets for all its edges here
if (_asic->_config->_net_traffic == real_multicast || _asic->_config->_net_traffic == path_multicast)
{
send_multicast_packet(cur_tuple, start_offset, end_offset);
}
else
{
send_scalar_packet(cur_tuple);
}
}
void asic_core::consume_lsq_responses(int lane_id)
{
if ((_asic->_config->_net != crossbar && _asic->_config->_net == hrc_xbar) && _asic->_cur_cycle % _asic->_xbar_bw == 0)
return;
// TODO: Different kind of responses, based on how it was consumed
if (!_asic->_config->is_vector() || (_asic->_config->is_vector() && _asic->_config->_pull_mode == 1))
{
// these are responses corresponding to the edges
int elem_done = 0;
while (!_pref_lsq[lane_id].empty() && can_push_in_process(lane_id))
{
// cout << "Core: " << _core_id << " consuming a value from lsq cycle: " << _asic->_cur_cycle << endl;
++elem_done;
pref_tuple cur_tuple = _pref_lsq[lane_id].front();
if (_asic->_config->_pr == 0 && _asic->_config->_domain == graphs)
{ // could be src_dist for synchronous execution
if ((_asic->_config->_exec_model == sync || _asic->_config->_exec_model == sync_slicing || _asic->_switched_sync) && !_asic->_switched_async)
{
cur_tuple.src_dist = _asic->_vertex_data[cur_tuple.src_id];
}
else
{
cur_tuple.src_dist = _asic->_scratch[cur_tuple.src_id];
}
}
assert(cur_tuple.src_dist >= 0);
if (_asic->_config->_pull_mode)
{
cur_tuple.start_edge_served = _asic->_offset[cur_tuple.src_id];
_prefetch_scratch.push(cur_tuple);
}
else
{
insert_prefetch_process(lane_id, 0, cur_tuple);
}
_pref_lsq[lane_id].pop();
}
// cout << "In consume lsq responses, elem done: " << elem_done << " at cycle: " << _asic->_cur_cycle << endl;
}
else
{ // Step 2: do something different for vectorized values? (no computation, directly send reduce packet over the network)
// these are responses corresponding to the edges
// If perfect_net=1 for the purposes of crossbar, source should not be
// allowed to issue more than 8*8 requests more cycle (so 1)
int num_pops = 0;
int max_pops = 1;
// FIXME: @vidushi: Why more max_ops increase execution time? (does HOL come
// into picture?)
if (_asic->_config->_tc == 1 && MAX_DFGS > 1)
{
max_pops = MAX_DFGS;
}
// if(_asic->_config->_core_cnt==1) max_pops=16; // ideal
// FIXME: checking: remove
// max_pops=16; // ideal
/*if(!_asic->_network->can_push_in_network(_core_id)) {
cout << "Could not push in network\n";
}*/
while (!_pref_lsq[lane_id].empty() && num_pops < max_pops && _asic->_network->can_push_in_network(_core_id))
{
// cout << "Came in to send network packet for GCN\n";
#if WORKING_CACHE == 1
// FIXME: should this be proportional to the number of cache misses which
// might be sent in this case?
if (_asic->_mem_ctrl->_num_pending_cache_reqs >= MAX_CACHE_MISS_ALLOWED)
return;
#endif
// cout << "number of packets to send: " << num_packets << endl;
pref_tuple cur_tuple = _pref_lsq[lane_id].front();
// cout << "Reading from memory, src_id: " << cur_tuple.src_id << " and edge: " << cur_tuple.edge.dst_id << " end edge: " << cur_tuple.end_edge_served << endl;
int max_edges = _asic->_offset[cur_tuple.src_id + 1] - _asic->_offset[cur_tuple.src_id];
num_pops++;
// push this packet into the network
// Step1: allocate an entry into the atomic rob
int src_core = _asic->_scratch_ctrl->get_local_scratch_id(cur_tuple.src_id);
// combined tuple for a source vertex
int dst_core = -1; // _asic->get_local_scratch_id(cur_tuple.edge.dst_id);
#if PERFECT_NET == 1 // TODO: if ALL_EDGE_ACCESS
// TODO: if this is more than 1, maybe i need to run in loop and just change start_edge_served
cur_tuple.edge = _asic->_neighbor[cur_tuple.start_edge_served];
dst_core = _asic->_scratch_ctrl->get_local_scratch_id(cur_tuple.edge.dst_id);
// TODO: FIXME: this is the new part for the cache hit aware sched...