-
Notifications
You must be signed in to change notification settings - Fork 546
/
Copy pathshader.cc
4470 lines (4096 loc) · 170 KB
/
shader.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
// Copyright (c) 2009-2011, Tor M. Aamodt, Wilson W.L. Fung, Ali Bakhoda,
// George L. Yuan, Andrew Turner, Inderpreet Singh
// The University of British Columbia
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. Neither the name of
// The University of British Columbia nor the names of its contributors may be
// used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#include "shader.h"
#include <float.h>
#include <limits.h>
#include <string.h>
#include "../../libcuda/gpgpu_context.h"
#include "../cuda-sim/cuda-sim.h"
#include "../cuda-sim/ptx-stats.h"
#include "../cuda-sim/ptx_sim.h"
#include "../statwrapper.h"
#include "addrdec.h"
#include "dram.h"
#include "gpu-misc.h"
#include "gpu-sim.h"
#include "icnt_wrapper.h"
#include "mem_fetch.h"
#include "mem_latency_stat.h"
#include "shader_trace.h"
#include "stat-tool.h"
#include "traffic_breakdown.h"
#include "visualizer.h"
#define PRIORITIZE_MSHR_OVER_WB 1
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
mem_fetch *shader_core_mem_fetch_allocator::alloc(
new_addr_type addr, mem_access_type type, unsigned size, bool wr,
unsigned long long cycle) const {
mem_access_t access(type, addr, size, wr, m_memory_config->gpgpu_ctx);
mem_fetch *mf =
new mem_fetch(access, NULL, wr ? WRITE_PACKET_SIZE : READ_PACKET_SIZE, -1,
m_core_id, m_cluster_id, m_memory_config, cycle);
return mf;
}
/////////////////////////////////////////////////////////////////////////////
std::list<unsigned> shader_core_ctx::get_regs_written(const inst_t &fvt) const {
std::list<unsigned> result;
for (unsigned op = 0; op < MAX_REG_OPERANDS; op++) {
int reg_num = fvt.arch_reg.dst[op]; // this math needs to match that used
// in function_info::ptx_decode_inst
if (reg_num >= 0) // valid register
result.push_back(reg_num);
}
return result;
}
void exec_shader_core_ctx::create_shd_warp() {
m_warp.resize(m_config->max_warps_per_shader);
for (unsigned k = 0; k < m_config->max_warps_per_shader; ++k) {
m_warp[k] = new shd_warp_t(this, m_config->warp_size);
}
}
void shader_core_ctx::create_front_pipeline() {
// pipeline_stages is the sum of normal pipeline stages and specialized_unit
// stages * 2 (for ID and EX)
unsigned total_pipeline_stages =
N_PIPELINE_STAGES + m_config->m_specialized_unit.size() * 2;
m_pipeline_reg.reserve(total_pipeline_stages);
for (int j = 0; j < N_PIPELINE_STAGES; j++) {
m_pipeline_reg.push_back(
register_set(m_config->pipe_widths[j], pipeline_stage_name_decode[j]));
}
for (int j = 0; j < m_config->m_specialized_unit.size(); j++) {
m_pipeline_reg.push_back(
register_set(m_config->m_specialized_unit[j].id_oc_spec_reg_width,
m_config->m_specialized_unit[j].name));
m_config->m_specialized_unit[j].ID_OC_SPEC_ID = m_pipeline_reg.size() - 1;
m_specilized_dispatch_reg.push_back(
&m_pipeline_reg[m_pipeline_reg.size() - 1]);
}
for (int j = 0; j < m_config->m_specialized_unit.size(); j++) {
m_pipeline_reg.push_back(
register_set(m_config->m_specialized_unit[j].oc_ex_spec_reg_width,
m_config->m_specialized_unit[j].name));
m_config->m_specialized_unit[j].OC_EX_SPEC_ID = m_pipeline_reg.size() - 1;
}
if (m_config->sub_core_model) {
// in subcore model, each scheduler should has its own issue register, so
// num scheduler = reg width
assert(m_config->gpgpu_num_sched_per_core ==
m_pipeline_reg[ID_OC_SP].get_size());
assert(m_config->gpgpu_num_sched_per_core ==
m_pipeline_reg[ID_OC_SFU].get_size());
assert(m_config->gpgpu_num_sched_per_core ==
m_pipeline_reg[ID_OC_MEM].get_size());
if (m_config->gpgpu_tensor_core_avail)
assert(m_config->gpgpu_num_sched_per_core ==
m_pipeline_reg[ID_OC_TENSOR_CORE].get_size());
if (m_config->gpgpu_num_dp_units > 0)
assert(m_config->gpgpu_num_sched_per_core ==
m_pipeline_reg[ID_OC_DP].get_size());
if (m_config->gpgpu_num_int_units > 0)
assert(m_config->gpgpu_num_sched_per_core ==
m_pipeline_reg[ID_OC_INT].get_size());
}
m_threadState = (thread_ctx_t *)calloc(sizeof(thread_ctx_t),
m_config->n_thread_per_shader);
m_not_completed = 0;
m_active_threads.reset();
m_n_active_cta = 0;
for (unsigned i = 0; i < MAX_CTA_PER_SHADER; i++) m_cta_status[i] = 0;
for (unsigned i = 0; i < m_config->n_thread_per_shader; i++) {
m_thread[i] = NULL;
m_threadState[i].m_cta_id = -1;
m_threadState[i].m_active = false;
}
// m_icnt = new shader_memory_interface(this,cluster);
if (m_config->gpgpu_perfect_mem) {
m_icnt = new perfect_memory_interface(this, m_cluster);
} else {
m_icnt = new shader_memory_interface(this, m_cluster);
}
m_mem_fetch_allocator =
new shader_core_mem_fetch_allocator(m_sid, m_tpc, m_memory_config);
// fetch
m_last_warp_fetched = 0;
#define STRSIZE 1024
char name[STRSIZE];
snprintf(name, STRSIZE, "L1I_%03d", m_sid);
m_L1I = new read_only_cache(name, m_config->m_L1I_config, m_sid,
get_shader_instruction_cache_id(), m_icnt,
IN_L1I_MISS_QUEUE);
}
void shader_core_ctx::create_schedulers() {
m_scoreboard = new Scoreboard(m_sid, m_config->max_warps_per_shader, m_gpu);
// scedulers
// must currently occur after all inputs have been initialized.
std::string sched_config = m_config->gpgpu_scheduler_string;
const concrete_scheduler scheduler =
sched_config.find("lrr") != std::string::npos
? CONCRETE_SCHEDULER_LRR
: sched_config.find("two_level_active") != std::string::npos
? CONCRETE_SCHEDULER_TWO_LEVEL_ACTIVE
: sched_config.find("gto") != std::string::npos
? CONCRETE_SCHEDULER_GTO
: sched_config.find("old") != std::string::npos
? CONCRETE_SCHEDULER_OLDEST_FIRST
: sched_config.find("warp_limiting") !=
std::string::npos
? CONCRETE_SCHEDULER_WARP_LIMITING
: NUM_CONCRETE_SCHEDULERS;
assert(scheduler != NUM_CONCRETE_SCHEDULERS);
for (unsigned i = 0; i < m_config->gpgpu_num_sched_per_core; i++) {
switch (scheduler) {
case CONCRETE_SCHEDULER_LRR:
schedulers.push_back(new lrr_scheduler(
m_stats, this, m_scoreboard, m_simt_stack, &m_warp,
&m_pipeline_reg[ID_OC_SP], &m_pipeline_reg[ID_OC_DP],
&m_pipeline_reg[ID_OC_SFU], &m_pipeline_reg[ID_OC_INT],
&m_pipeline_reg[ID_OC_TENSOR_CORE], m_specilized_dispatch_reg,
&m_pipeline_reg[ID_OC_MEM], i));
break;
case CONCRETE_SCHEDULER_TWO_LEVEL_ACTIVE:
schedulers.push_back(new two_level_active_scheduler(
m_stats, this, m_scoreboard, m_simt_stack, &m_warp,
&m_pipeline_reg[ID_OC_SP], &m_pipeline_reg[ID_OC_DP],
&m_pipeline_reg[ID_OC_SFU], &m_pipeline_reg[ID_OC_INT],
&m_pipeline_reg[ID_OC_TENSOR_CORE], m_specilized_dispatch_reg,
&m_pipeline_reg[ID_OC_MEM], i, m_config->gpgpu_scheduler_string));
break;
case CONCRETE_SCHEDULER_GTO:
schedulers.push_back(new gto_scheduler(
m_stats, this, m_scoreboard, m_simt_stack, &m_warp,
&m_pipeline_reg[ID_OC_SP], &m_pipeline_reg[ID_OC_DP],
&m_pipeline_reg[ID_OC_SFU], &m_pipeline_reg[ID_OC_INT],
&m_pipeline_reg[ID_OC_TENSOR_CORE], m_specilized_dispatch_reg,
&m_pipeline_reg[ID_OC_MEM], i));
break;
case CONCRETE_SCHEDULER_OLDEST_FIRST:
schedulers.push_back(new oldest_scheduler(
m_stats, this, m_scoreboard, m_simt_stack, &m_warp,
&m_pipeline_reg[ID_OC_SP], &m_pipeline_reg[ID_OC_DP],
&m_pipeline_reg[ID_OC_SFU], &m_pipeline_reg[ID_OC_INT],
&m_pipeline_reg[ID_OC_TENSOR_CORE], m_specilized_dispatch_reg,
&m_pipeline_reg[ID_OC_MEM], i));
break;
case CONCRETE_SCHEDULER_WARP_LIMITING:
schedulers.push_back(new swl_scheduler(
m_stats, this, m_scoreboard, m_simt_stack, &m_warp,
&m_pipeline_reg[ID_OC_SP], &m_pipeline_reg[ID_OC_DP],
&m_pipeline_reg[ID_OC_SFU], &m_pipeline_reg[ID_OC_INT],
&m_pipeline_reg[ID_OC_TENSOR_CORE], m_specilized_dispatch_reg,
&m_pipeline_reg[ID_OC_MEM], i, m_config->gpgpu_scheduler_string));
break;
default:
abort();
};
}
for (unsigned i = 0; i < m_warp.size(); i++) {
// distribute i's evenly though schedulers;
schedulers[i % m_config->gpgpu_num_sched_per_core]->add_supervised_warp_id(
i);
}
for (unsigned i = 0; i < m_config->gpgpu_num_sched_per_core; ++i) {
schedulers[i]->done_adding_supervised_warps();
}
}
void shader_core_ctx::create_exec_pipeline() {
// op collector configuration
enum { SP_CUS, DP_CUS, SFU_CUS, TENSOR_CORE_CUS, INT_CUS, MEM_CUS, GEN_CUS };
opndcoll_rfu_t::port_vector_t in_ports;
opndcoll_rfu_t::port_vector_t out_ports;
opndcoll_rfu_t::uint_vector_t cu_sets;
// configure generic collectors
m_operand_collector.add_cu_set(
GEN_CUS, m_config->gpgpu_operand_collector_num_units_gen,
m_config->gpgpu_operand_collector_num_out_ports_gen);
for (unsigned i = 0; i < m_config->gpgpu_operand_collector_num_in_ports_gen;
i++) {
in_ports.push_back(&m_pipeline_reg[ID_OC_SP]);
in_ports.push_back(&m_pipeline_reg[ID_OC_SFU]);
in_ports.push_back(&m_pipeline_reg[ID_OC_MEM]);
out_ports.push_back(&m_pipeline_reg[OC_EX_SP]);
out_ports.push_back(&m_pipeline_reg[OC_EX_SFU]);
out_ports.push_back(&m_pipeline_reg[OC_EX_MEM]);
if (m_config->gpgpu_tensor_core_avail) {
in_ports.push_back(&m_pipeline_reg[ID_OC_TENSOR_CORE]);
out_ports.push_back(&m_pipeline_reg[OC_EX_TENSOR_CORE]);
}
if (m_config->gpgpu_num_dp_units > 0) {
in_ports.push_back(&m_pipeline_reg[ID_OC_DP]);
out_ports.push_back(&m_pipeline_reg[OC_EX_DP]);
}
if (m_config->gpgpu_num_int_units > 0) {
in_ports.push_back(&m_pipeline_reg[ID_OC_INT]);
out_ports.push_back(&m_pipeline_reg[OC_EX_INT]);
}
if (m_config->m_specialized_unit.size() > 0) {
for (unsigned j = 0; j < m_config->m_specialized_unit.size(); ++j) {
in_ports.push_back(
&m_pipeline_reg[m_config->m_specialized_unit[j].ID_OC_SPEC_ID]);
out_ports.push_back(
&m_pipeline_reg[m_config->m_specialized_unit[j].OC_EX_SPEC_ID]);
}
}
cu_sets.push_back((unsigned)GEN_CUS);
m_operand_collector.add_port(in_ports, out_ports, cu_sets);
in_ports.clear(), out_ports.clear(), cu_sets.clear();
}
if (m_config->enable_specialized_operand_collector) {
m_operand_collector.add_cu_set(
SP_CUS, m_config->gpgpu_operand_collector_num_units_sp,
m_config->gpgpu_operand_collector_num_out_ports_sp);
m_operand_collector.add_cu_set(
DP_CUS, m_config->gpgpu_operand_collector_num_units_dp,
m_config->gpgpu_operand_collector_num_out_ports_dp);
m_operand_collector.add_cu_set(
TENSOR_CORE_CUS,
m_config->gpgpu_operand_collector_num_units_tensor_core,
m_config->gpgpu_operand_collector_num_out_ports_tensor_core);
m_operand_collector.add_cu_set(
SFU_CUS, m_config->gpgpu_operand_collector_num_units_sfu,
m_config->gpgpu_operand_collector_num_out_ports_sfu);
m_operand_collector.add_cu_set(
MEM_CUS, m_config->gpgpu_operand_collector_num_units_mem,
m_config->gpgpu_operand_collector_num_out_ports_mem);
m_operand_collector.add_cu_set(
INT_CUS, m_config->gpgpu_operand_collector_num_units_int,
m_config->gpgpu_operand_collector_num_out_ports_int);
for (unsigned i = 0; i < m_config->gpgpu_operand_collector_num_in_ports_sp;
i++) {
in_ports.push_back(&m_pipeline_reg[ID_OC_SP]);
out_ports.push_back(&m_pipeline_reg[OC_EX_SP]);
cu_sets.push_back((unsigned)SP_CUS);
cu_sets.push_back((unsigned)GEN_CUS);
m_operand_collector.add_port(in_ports, out_ports, cu_sets);
in_ports.clear(), out_ports.clear(), cu_sets.clear();
}
for (unsigned i = 0; i < m_config->gpgpu_operand_collector_num_in_ports_dp;
i++) {
in_ports.push_back(&m_pipeline_reg[ID_OC_DP]);
out_ports.push_back(&m_pipeline_reg[OC_EX_DP]);
cu_sets.push_back((unsigned)DP_CUS);
cu_sets.push_back((unsigned)GEN_CUS);
m_operand_collector.add_port(in_ports, out_ports, cu_sets);
in_ports.clear(), out_ports.clear(), cu_sets.clear();
}
for (unsigned i = 0; i < m_config->gpgpu_operand_collector_num_in_ports_sfu;
i++) {
in_ports.push_back(&m_pipeline_reg[ID_OC_SFU]);
out_ports.push_back(&m_pipeline_reg[OC_EX_SFU]);
cu_sets.push_back((unsigned)SFU_CUS);
cu_sets.push_back((unsigned)GEN_CUS);
m_operand_collector.add_port(in_ports, out_ports, cu_sets);
in_ports.clear(), out_ports.clear(), cu_sets.clear();
}
for (unsigned i = 0;
i < m_config->gpgpu_operand_collector_num_in_ports_tensor_core; i++) {
in_ports.push_back(&m_pipeline_reg[ID_OC_TENSOR_CORE]);
out_ports.push_back(&m_pipeline_reg[OC_EX_TENSOR_CORE]);
cu_sets.push_back((unsigned)TENSOR_CORE_CUS);
cu_sets.push_back((unsigned)GEN_CUS);
m_operand_collector.add_port(in_ports, out_ports, cu_sets);
in_ports.clear(), out_ports.clear(), cu_sets.clear();
}
for (unsigned i = 0; i < m_config->gpgpu_operand_collector_num_in_ports_mem;
i++) {
in_ports.push_back(&m_pipeline_reg[ID_OC_MEM]);
out_ports.push_back(&m_pipeline_reg[OC_EX_MEM]);
cu_sets.push_back((unsigned)MEM_CUS);
cu_sets.push_back((unsigned)GEN_CUS);
m_operand_collector.add_port(in_ports, out_ports, cu_sets);
in_ports.clear(), out_ports.clear(), cu_sets.clear();
}
for (unsigned i = 0; i < m_config->gpgpu_operand_collector_num_in_ports_int;
i++) {
in_ports.push_back(&m_pipeline_reg[ID_OC_INT]);
out_ports.push_back(&m_pipeline_reg[OC_EX_INT]);
cu_sets.push_back((unsigned)INT_CUS);
cu_sets.push_back((unsigned)GEN_CUS);
m_operand_collector.add_port(in_ports, out_ports, cu_sets);
in_ports.clear(), out_ports.clear(), cu_sets.clear();
}
}
m_operand_collector.init(m_config->gpgpu_num_reg_banks, this);
m_num_function_units =
m_config->gpgpu_num_sp_units + m_config->gpgpu_num_dp_units +
m_config->gpgpu_num_sfu_units + m_config->gpgpu_num_tensor_core_units +
m_config->gpgpu_num_int_units + m_config->m_specialized_unit_num +
1; // sp_unit, sfu, dp, tensor, int, ldst_unit
// m_dispatch_port = new enum pipeline_stage_name_t[ m_num_function_units ];
// m_issue_port = new enum pipeline_stage_name_t[ m_num_function_units ];
// m_fu = new simd_function_unit*[m_num_function_units];
for (int k = 0; k < m_config->gpgpu_num_sp_units; k++) {
m_fu.push_back(new sp_unit(&m_pipeline_reg[EX_WB], m_config, this));
m_dispatch_port.push_back(ID_OC_SP);
m_issue_port.push_back(OC_EX_SP);
}
for (int k = 0; k < m_config->gpgpu_num_dp_units; k++) {
m_fu.push_back(new dp_unit(&m_pipeline_reg[EX_WB], m_config, this));
m_dispatch_port.push_back(ID_OC_DP);
m_issue_port.push_back(OC_EX_DP);
}
for (int k = 0; k < m_config->gpgpu_num_int_units; k++) {
m_fu.push_back(new int_unit(&m_pipeline_reg[EX_WB], m_config, this));
m_dispatch_port.push_back(ID_OC_INT);
m_issue_port.push_back(OC_EX_INT);
}
for (int k = 0; k < m_config->gpgpu_num_sfu_units; k++) {
m_fu.push_back(new sfu(&m_pipeline_reg[EX_WB], m_config, this));
m_dispatch_port.push_back(ID_OC_SFU);
m_issue_port.push_back(OC_EX_SFU);
}
for (int k = 0; k < m_config->gpgpu_num_tensor_core_units; k++) {
m_fu.push_back(new tensor_core(&m_pipeline_reg[EX_WB], m_config, this));
m_dispatch_port.push_back(ID_OC_TENSOR_CORE);
m_issue_port.push_back(OC_EX_TENSOR_CORE);
}
for (int j = 0; j < m_config->m_specialized_unit.size(); j++) {
for (unsigned k = 0; k < m_config->m_specialized_unit[j].num_units; k++) {
m_fu.push_back(new specialized_unit(
&m_pipeline_reg[EX_WB], m_config, this, SPEC_UNIT_START_ID + j,
m_config->m_specialized_unit[j].name,
m_config->m_specialized_unit[j].latency));
m_dispatch_port.push_back(m_config->m_specialized_unit[j].ID_OC_SPEC_ID);
m_issue_port.push_back(m_config->m_specialized_unit[j].OC_EX_SPEC_ID);
}
}
m_ldst_unit = new ldst_unit(m_icnt, m_mem_fetch_allocator, this,
&m_operand_collector, m_scoreboard, m_config,
m_memory_config, m_stats, m_sid, m_tpc);
m_fu.push_back(m_ldst_unit);
m_dispatch_port.push_back(ID_OC_MEM);
m_issue_port.push_back(OC_EX_MEM);
assert(m_num_function_units == m_fu.size() and
m_fu.size() == m_dispatch_port.size() and
m_fu.size() == m_issue_port.size());
// there are as many result buses as the width of the EX_WB stage
num_result_bus = m_config->pipe_widths[EX_WB];
for (unsigned i = 0; i < num_result_bus; i++) {
this->m_result_bus.push_back(new std::bitset<MAX_ALU_LATENCY>());
}
}
shader_core_ctx::shader_core_ctx(class gpgpu_sim *gpu,
class simt_core_cluster *cluster,
unsigned shader_id, unsigned tpc_id,
const shader_core_config *config,
const memory_config *mem_config,
shader_core_stats *stats)
: core_t(gpu, NULL, config->warp_size, config->n_thread_per_shader),
m_barriers(this, config->max_warps_per_shader, config->max_cta_per_core,
config->max_barriers_per_cta, config->warp_size),
m_active_warps(0),
m_dynamic_warp_id(0) {
m_cluster = cluster;
m_config = config;
m_memory_config = mem_config;
m_stats = stats;
unsigned warp_size = config->warp_size;
Issue_Prio = 0;
m_sid = shader_id;
m_tpc = tpc_id;
m_last_inst_gpu_sim_cycle = 0;
m_last_inst_gpu_tot_sim_cycle = 0;
// Jin: for concurrent kernels on a SM
m_occupied_n_threads = 0;
m_occupied_shmem = 0;
m_occupied_regs = 0;
m_occupied_ctas = 0;
m_occupied_hwtid.reset();
m_occupied_cta_to_hwtid.clear();
}
void shader_core_ctx::reinit(unsigned start_thread, unsigned end_thread,
bool reset_not_completed) {
if (reset_not_completed) {
m_not_completed = 0;
m_active_threads.reset();
// Jin: for concurrent kernels on a SM
m_occupied_n_threads = 0;
m_occupied_shmem = 0;
m_occupied_regs = 0;
m_occupied_ctas = 0;
m_occupied_hwtid.reset();
m_occupied_cta_to_hwtid.clear();
m_active_warps = 0;
}
for (unsigned i = start_thread; i < end_thread; i++) {
m_threadState[i].n_insn = 0;
m_threadState[i].m_cta_id = -1;
}
for (unsigned i = start_thread / m_config->warp_size;
i < end_thread / m_config->warp_size; ++i) {
m_warp[i]->reset();
m_simt_stack[i]->reset();
}
}
void shader_core_ctx::init_warps(unsigned cta_id, unsigned start_thread,
unsigned end_thread, unsigned ctaid,
int cta_size, kernel_info_t &kernel) {
//
address_type start_pc = next_pc(start_thread);
unsigned kernel_id = kernel.get_uid();
if (m_config->model == POST_DOMINATOR) {
unsigned start_warp = start_thread / m_config->warp_size;
unsigned warp_per_cta = cta_size / m_config->warp_size;
unsigned end_warp = end_thread / m_config->warp_size +
((end_thread % m_config->warp_size) ? 1 : 0);
for (unsigned i = start_warp; i < end_warp; ++i) {
unsigned n_active = 0;
simt_mask_t active_threads;
for (unsigned t = 0; t < m_config->warp_size; t++) {
unsigned hwtid = i * m_config->warp_size + t;
if (hwtid < end_thread) {
n_active++;
assert(!m_active_threads.test(hwtid));
m_active_threads.set(hwtid);
active_threads.set(t);
}
}
m_simt_stack[i]->launch(start_pc, active_threads);
if (m_gpu->resume_option == 1 && kernel_id == m_gpu->resume_kernel &&
ctaid >= m_gpu->resume_CTA && ctaid < m_gpu->checkpoint_CTA_t) {
char fname[2048];
snprintf(fname, 2048, "checkpoint_files/warp_%d_%d_simt.txt",
i % warp_per_cta, ctaid);
unsigned pc, rpc;
m_simt_stack[i]->resume(fname);
m_simt_stack[i]->get_pdom_stack_top_info(&pc, &rpc);
for (unsigned t = 0; t < m_config->warp_size; t++) {
if (m_thread != NULL) {
m_thread[i * m_config->warp_size + t]->set_npc(pc);
m_thread[i * m_config->warp_size + t]->update_pc();
}
}
start_pc = pc;
}
m_warp[i]->init(start_pc, cta_id, i, active_threads, m_dynamic_warp_id);
++m_dynamic_warp_id;
m_not_completed += n_active;
++m_active_warps;
}
}
}
// return the next pc of a thread
address_type shader_core_ctx::next_pc(int tid) const {
if (tid == -1) return -1;
ptx_thread_info *the_thread = m_thread[tid];
if (the_thread == NULL) return -1;
return the_thread
->get_pc(); // PC should already be updatd to next PC at this point (was
// set in shader_decode() last time thread ran)
}
void gpgpu_sim::get_pdom_stack_top_info(unsigned sid, unsigned tid,
unsigned *pc, unsigned *rpc) {
unsigned cluster_id = m_shader_config->sid_to_cluster(sid);
m_cluster[cluster_id]->get_pdom_stack_top_info(sid, tid, pc, rpc);
}
void shader_core_ctx::get_pdom_stack_top_info(unsigned tid, unsigned *pc,
unsigned *rpc) const {
unsigned warp_id = tid / m_config->warp_size;
m_simt_stack[warp_id]->get_pdom_stack_top_info(pc, rpc);
}
float shader_core_ctx::get_current_occupancy(unsigned long long &active,
unsigned long long &total) const {
// To match the achieved_occupancy in nvprof, only SMs that are active are
// counted toward the occupancy.
if (m_active_warps > 0) {
total += m_warp.size();
active += m_active_warps;
return float(active) / float(total);
} else {
return 0;
}
}
void shader_core_stats::print(FILE *fout) const {
unsigned long long thread_icount_uarch = 0;
unsigned long long warp_icount_uarch = 0;
for (unsigned i = 0; i < m_config->num_shader(); i++) {
thread_icount_uarch += m_num_sim_insn[i];
warp_icount_uarch += m_num_sim_winsn[i];
}
fprintf(fout, "gpgpu_n_tot_thrd_icount = %lld\n", thread_icount_uarch);
fprintf(fout, "gpgpu_n_tot_w_icount = %lld\n", warp_icount_uarch);
fprintf(fout, "gpgpu_n_stall_shd_mem = %d\n", gpgpu_n_stall_shd_mem);
fprintf(fout, "gpgpu_n_mem_read_local = %d\n", gpgpu_n_mem_read_local);
fprintf(fout, "gpgpu_n_mem_write_local = %d\n", gpgpu_n_mem_write_local);
fprintf(fout, "gpgpu_n_mem_read_global = %d\n", gpgpu_n_mem_read_global);
fprintf(fout, "gpgpu_n_mem_write_global = %d\n", gpgpu_n_mem_write_global);
fprintf(fout, "gpgpu_n_mem_texture = %d\n", gpgpu_n_mem_texture);
fprintf(fout, "gpgpu_n_mem_const = %d\n", gpgpu_n_mem_const);
fprintf(fout, "gpgpu_n_load_insn = %d\n", gpgpu_n_load_insn);
fprintf(fout, "gpgpu_n_store_insn = %d\n", gpgpu_n_store_insn);
fprintf(fout, "gpgpu_n_shmem_insn = %d\n", gpgpu_n_shmem_insn);
fprintf(fout, "gpgpu_n_sstarr_insn = %d\n", gpgpu_n_sstarr_insn);
fprintf(fout, "gpgpu_n_tex_insn = %d\n", gpgpu_n_tex_insn);
fprintf(fout, "gpgpu_n_const_mem_insn = %d\n", gpgpu_n_const_insn);
fprintf(fout, "gpgpu_n_param_mem_insn = %d\n", gpgpu_n_param_insn);
fprintf(fout, "gpgpu_n_shmem_bkconflict = %d\n", gpgpu_n_shmem_bkconflict);
fprintf(fout, "gpgpu_n_cache_bkconflict = %d\n", gpgpu_n_cache_bkconflict);
fprintf(fout, "gpgpu_n_intrawarp_mshr_merge = %d\n",
gpgpu_n_intrawarp_mshr_merge);
fprintf(fout, "gpgpu_n_cmem_portconflict = %d\n", gpgpu_n_cmem_portconflict);
fprintf(fout, "gpgpu_stall_shd_mem[c_mem][resource_stall] = %d\n",
gpu_stall_shd_mem_breakdown[C_MEM][BK_CONF]);
// fprintf(fout, "gpgpu_stall_shd_mem[c_mem][mshr_rc] = %d\n",
// gpu_stall_shd_mem_breakdown[C_MEM][MSHR_RC_FAIL]); fprintf(fout,
// "gpgpu_stall_shd_mem[c_mem][icnt_rc] = %d\n",
// gpu_stall_shd_mem_breakdown[C_MEM][ICNT_RC_FAIL]); fprintf(fout,
// "gpgpu_stall_shd_mem[c_mem][data_port_stall] = %d\n",
// gpu_stall_shd_mem_breakdown[C_MEM][DATA_PORT_STALL]); fprintf(fout,
// "gpgpu_stall_shd_mem[t_mem][mshr_rc] = %d\n",
// gpu_stall_shd_mem_breakdown[T_MEM][MSHR_RC_FAIL]); fprintf(fout,
// "gpgpu_stall_shd_mem[t_mem][icnt_rc] = %d\n",
// gpu_stall_shd_mem_breakdown[T_MEM][ICNT_RC_FAIL]); fprintf(fout,
// "gpgpu_stall_shd_mem[t_mem][data_port_stall] = %d\n",
// gpu_stall_shd_mem_breakdown[T_MEM][DATA_PORT_STALL]);
fprintf(fout, "gpgpu_stall_shd_mem[s_mem][bk_conf] = %d\n",
gpu_stall_shd_mem_breakdown[S_MEM][BK_CONF]);
fprintf(
fout, "gpgpu_stall_shd_mem[gl_mem][resource_stall] = %d\n",
gpu_stall_shd_mem_breakdown[G_MEM_LD][BK_CONF] +
gpu_stall_shd_mem_breakdown[G_MEM_ST][BK_CONF] +
gpu_stall_shd_mem_breakdown[L_MEM_LD][BK_CONF] +
gpu_stall_shd_mem_breakdown[L_MEM_ST][BK_CONF]); // coalescing stall
// at data cache
fprintf(
fout, "gpgpu_stall_shd_mem[gl_mem][coal_stall] = %d\n",
gpu_stall_shd_mem_breakdown[G_MEM_LD][COAL_STALL] +
gpu_stall_shd_mem_breakdown[G_MEM_ST][COAL_STALL] +
gpu_stall_shd_mem_breakdown[L_MEM_LD][COAL_STALL] +
gpu_stall_shd_mem_breakdown[L_MEM_ST]
[COAL_STALL]); // coalescing stall + bank
// conflict at data cache
fprintf(fout, "gpgpu_stall_shd_mem[gl_mem][data_port_stall] = %d\n",
gpu_stall_shd_mem_breakdown[G_MEM_LD][DATA_PORT_STALL] +
gpu_stall_shd_mem_breakdown[G_MEM_ST][DATA_PORT_STALL] +
gpu_stall_shd_mem_breakdown[L_MEM_LD][DATA_PORT_STALL] +
gpu_stall_shd_mem_breakdown[L_MEM_ST]
[DATA_PORT_STALL]); // data port stall
// at data cache
// fprintf(fout, "gpgpu_stall_shd_mem[g_mem_ld][mshr_rc] = %d\n",
// gpu_stall_shd_mem_breakdown[G_MEM_LD][MSHR_RC_FAIL]); fprintf(fout,
// "gpgpu_stall_shd_mem[g_mem_ld][icnt_rc] = %d\n",
// gpu_stall_shd_mem_breakdown[G_MEM_LD][ICNT_RC_FAIL]); fprintf(fout,
// "gpgpu_stall_shd_mem[g_mem_ld][wb_icnt_rc] = %d\n",
// gpu_stall_shd_mem_breakdown[G_MEM_LD][WB_ICNT_RC_FAIL]); fprintf(fout,
// "gpgpu_stall_shd_mem[g_mem_ld][wb_rsrv_fail] = %d\n",
// gpu_stall_shd_mem_breakdown[G_MEM_LD][WB_CACHE_RSRV_FAIL]); fprintf(fout,
// "gpgpu_stall_shd_mem[g_mem_st][mshr_rc] = %d\n",
// gpu_stall_shd_mem_breakdown[G_MEM_ST][MSHR_RC_FAIL]); fprintf(fout,
// "gpgpu_stall_shd_mem[g_mem_st][icnt_rc] = %d\n",
// gpu_stall_shd_mem_breakdown[G_MEM_ST][ICNT_RC_FAIL]); fprintf(fout,
// "gpgpu_stall_shd_mem[g_mem_st][wb_icnt_rc] = %d\n",
// gpu_stall_shd_mem_breakdown[G_MEM_ST][WB_ICNT_RC_FAIL]); fprintf(fout,
// "gpgpu_stall_shd_mem[g_mem_st][wb_rsrv_fail] = %d\n",
// gpu_stall_shd_mem_breakdown[G_MEM_ST][WB_CACHE_RSRV_FAIL]); fprintf(fout,
// "gpgpu_stall_shd_mem[l_mem_ld][mshr_rc] = %d\n",
// gpu_stall_shd_mem_breakdown[L_MEM_LD][MSHR_RC_FAIL]); fprintf(fout,
// "gpgpu_stall_shd_mem[l_mem_ld][icnt_rc] = %d\n",
// gpu_stall_shd_mem_breakdown[L_MEM_LD][ICNT_RC_FAIL]); fprintf(fout,
// "gpgpu_stall_shd_mem[l_mem_ld][wb_icnt_rc] = %d\n",
// gpu_stall_shd_mem_breakdown[L_MEM_LD][WB_ICNT_RC_FAIL]); fprintf(fout,
// "gpgpu_stall_shd_mem[l_mem_ld][wb_rsrv_fail] = %d\n",
// gpu_stall_shd_mem_breakdown[L_MEM_LD][WB_CACHE_RSRV_FAIL]); fprintf(fout,
// "gpgpu_stall_shd_mem[l_mem_st][mshr_rc] = %d\n",
// gpu_stall_shd_mem_breakdown[L_MEM_ST][MSHR_RC_FAIL]); fprintf(fout,
// "gpgpu_stall_shd_mem[l_mem_st][icnt_rc] = %d\n",
// gpu_stall_shd_mem_breakdown[L_MEM_ST][ICNT_RC_FAIL]); fprintf(fout,
// "gpgpu_stall_shd_mem[l_mem_ld][wb_icnt_rc] = %d\n",
// gpu_stall_shd_mem_breakdown[L_MEM_ST][WB_ICNT_RC_FAIL]); fprintf(fout,
// "gpgpu_stall_shd_mem[l_mem_ld][wb_rsrv_fail] = %d\n",
// gpu_stall_shd_mem_breakdown[L_MEM_ST][WB_CACHE_RSRV_FAIL]);
fprintf(fout, "gpu_reg_bank_conflict_stalls = %d\n",
gpu_reg_bank_conflict_stalls);
fprintf(fout, "Warp Occupancy Distribution:\n");
fprintf(fout, "Stall:%d\t", shader_cycle_distro[2]);
fprintf(fout, "W0_Idle:%d\t", shader_cycle_distro[0]);
fprintf(fout, "W0_Scoreboard:%d", shader_cycle_distro[1]);
for (unsigned i = 3; i < m_config->warp_size + 3; i++)
fprintf(fout, "\tW%d:%d", i - 2, shader_cycle_distro[i]);
fprintf(fout, "\n");
fprintf(fout, "single_issue_nums: ");
for (unsigned i = 0; i < m_config->gpgpu_num_sched_per_core; i++)
fprintf(fout, "WS%d:%d\t", i, single_issue_nums[i]);
fprintf(fout, "\n");
fprintf(fout, "dual_issue_nums: ");
for (unsigned i = 0; i < m_config->gpgpu_num_sched_per_core; i++)
fprintf(fout, "WS%d:%d\t", i, dual_issue_nums[i]);
fprintf(fout, "\n");
m_outgoing_traffic_stats->print(fout);
m_incoming_traffic_stats->print(fout);
}
void shader_core_stats::event_warp_issued(unsigned s_id, unsigned warp_id,
unsigned num_issued,
unsigned dynamic_warp_id) {
assert(warp_id <= m_config->max_warps_per_shader);
for (unsigned i = 0; i < num_issued; ++i) {
if (m_shader_dynamic_warp_issue_distro[s_id].size() <= dynamic_warp_id) {
m_shader_dynamic_warp_issue_distro[s_id].resize(dynamic_warp_id + 1);
}
++m_shader_dynamic_warp_issue_distro[s_id][dynamic_warp_id];
if (m_shader_warp_slot_issue_distro[s_id].size() <= warp_id) {
m_shader_warp_slot_issue_distro[s_id].resize(warp_id + 1);
}
++m_shader_warp_slot_issue_distro[s_id][warp_id];
}
}
void shader_core_stats::visualizer_print(gzFile visualizer_file) {
// warp divergence breakdown
gzprintf(visualizer_file, "WarpDivergenceBreakdown:");
unsigned int total = 0;
unsigned int cf =
(m_config->gpgpu_warpdistro_shader == -1) ? m_config->num_shader() : 1;
gzprintf(visualizer_file, " %d",
(shader_cycle_distro[0] - last_shader_cycle_distro[0]) / cf);
gzprintf(visualizer_file, " %d",
(shader_cycle_distro[1] - last_shader_cycle_distro[1]) / cf);
gzprintf(visualizer_file, " %d",
(shader_cycle_distro[2] - last_shader_cycle_distro[2]) / cf);
for (unsigned i = 0; i < m_config->warp_size + 3; i++) {
if (i >= 3) {
total += (shader_cycle_distro[i] - last_shader_cycle_distro[i]);
if (((i - 3) % (m_config->warp_size / 8)) ==
((m_config->warp_size / 8) - 1)) {
gzprintf(visualizer_file, " %d", total / cf);
total = 0;
}
}
last_shader_cycle_distro[i] = shader_cycle_distro[i];
}
gzprintf(visualizer_file, "\n");
gzprintf(visualizer_file, "ctas_completed: %d\n", ctas_completed);
ctas_completed = 0;
// warp issue breakdown
unsigned sid = m_config->gpgpu_warp_issue_shader;
unsigned count = 0;
unsigned warp_id_issued_sum = 0;
gzprintf(visualizer_file, "WarpIssueSlotBreakdown:");
if (m_shader_warp_slot_issue_distro[sid].size() > 0) {
for (std::vector<unsigned>::const_iterator iter =
m_shader_warp_slot_issue_distro[sid].begin();
iter != m_shader_warp_slot_issue_distro[sid].end(); iter++, count++) {
unsigned diff = count < m_last_shader_warp_slot_issue_distro.size()
? *iter - m_last_shader_warp_slot_issue_distro[count]
: *iter;
gzprintf(visualizer_file, " %d", diff);
warp_id_issued_sum += diff;
}
m_last_shader_warp_slot_issue_distro = m_shader_warp_slot_issue_distro[sid];
} else {
gzprintf(visualizer_file, " 0");
}
gzprintf(visualizer_file, "\n");
#define DYNAMIC_WARP_PRINT_RESOLUTION 32
unsigned total_issued_this_resolution = 0;
unsigned dynamic_id_issued_sum = 0;
count = 0;
gzprintf(visualizer_file, "WarpIssueDynamicIdBreakdown:");
if (m_shader_dynamic_warp_issue_distro[sid].size() > 0) {
for (std::vector<unsigned>::const_iterator iter =
m_shader_dynamic_warp_issue_distro[sid].begin();
iter != m_shader_dynamic_warp_issue_distro[sid].end();
iter++, count++) {
unsigned diff =
count < m_last_shader_dynamic_warp_issue_distro.size()
? *iter - m_last_shader_dynamic_warp_issue_distro[count]
: *iter;
total_issued_this_resolution += diff;
if ((count + 1) % DYNAMIC_WARP_PRINT_RESOLUTION == 0) {
gzprintf(visualizer_file, " %d", total_issued_this_resolution);
dynamic_id_issued_sum += total_issued_this_resolution;
total_issued_this_resolution = 0;
}
}
if (count % DYNAMIC_WARP_PRINT_RESOLUTION != 0) {
gzprintf(visualizer_file, " %d", total_issued_this_resolution);
dynamic_id_issued_sum += total_issued_this_resolution;
}
m_last_shader_dynamic_warp_issue_distro =
m_shader_dynamic_warp_issue_distro[sid];
assert(warp_id_issued_sum == dynamic_id_issued_sum);
} else {
gzprintf(visualizer_file, " 0");
}
gzprintf(visualizer_file, "\n");
// overall cache miss rates
gzprintf(visualizer_file, "gpgpu_n_cache_bkconflict: %d\n",
gpgpu_n_cache_bkconflict);
gzprintf(visualizer_file, "gpgpu_n_shmem_bkconflict: %d\n",
gpgpu_n_shmem_bkconflict);
// instruction count per shader core
gzprintf(visualizer_file, "shaderinsncount: ");
for (unsigned i = 0; i < m_config->num_shader(); i++)
gzprintf(visualizer_file, "%u ", m_num_sim_insn[i]);
gzprintf(visualizer_file, "\n");
// warp instruction count per shader core
gzprintf(visualizer_file, "shaderwarpinsncount: ");
for (unsigned i = 0; i < m_config->num_shader(); i++)
gzprintf(visualizer_file, "%u ", m_num_sim_winsn[i]);
gzprintf(visualizer_file, "\n");
// warp divergence per shader core
gzprintf(visualizer_file, "shaderwarpdiv: ");
for (unsigned i = 0; i < m_config->num_shader(); i++)
gzprintf(visualizer_file, "%u ", m_n_diverge[i]);
gzprintf(visualizer_file, "\n");
}
#define PROGRAM_MEM_START \
0xF0000000 /* should be distinct from other memory spaces... \
check ptx_ir.h to verify this does not overlap \
other memory spaces */
const warp_inst_t *exec_shader_core_ctx::get_next_inst(unsigned warp_id,
address_type pc) {
// read the inst from the functional model
return m_gpu->gpgpu_ctx->ptx_fetch_inst(pc);
}
void exec_shader_core_ctx::get_pdom_stack_top_info(unsigned warp_id,
const warp_inst_t *pI,
unsigned *pc,
unsigned *rpc) {
m_simt_stack[warp_id]->get_pdom_stack_top_info(pc, rpc);
}
const active_mask_t &exec_shader_core_ctx::get_active_mask(
unsigned warp_id, const warp_inst_t *pI) {
return m_simt_stack[warp_id]->get_active_mask();
}
void shader_core_ctx::decode() {
if (m_inst_fetch_buffer.m_valid) {
// decode 1 or 2 instructions and place them into ibuffer
address_type pc = m_inst_fetch_buffer.m_pc;
const warp_inst_t *pI1 = get_next_inst(m_inst_fetch_buffer.m_warp_id, pc);
m_warp[m_inst_fetch_buffer.m_warp_id]->ibuffer_fill(0, pI1);
m_warp[m_inst_fetch_buffer.m_warp_id]->inc_inst_in_pipeline();
if (pI1) {
m_stats->m_num_decoded_insn[m_sid]++;
if (pI1->oprnd_type == INT_OP) {
m_stats->m_num_INTdecoded_insn[m_sid]++;
} else if (pI1->oprnd_type == FP_OP) {
m_stats->m_num_FPdecoded_insn[m_sid]++;
}
const warp_inst_t *pI2 =
get_next_inst(m_inst_fetch_buffer.m_warp_id, pc + pI1->isize);
if (pI2) {
m_warp[m_inst_fetch_buffer.m_warp_id]->ibuffer_fill(1, pI2);
m_warp[m_inst_fetch_buffer.m_warp_id]->inc_inst_in_pipeline();
m_stats->m_num_decoded_insn[m_sid]++;
if (pI2->oprnd_type == INT_OP) {
m_stats->m_num_INTdecoded_insn[m_sid]++;
} else if (pI2->oprnd_type == FP_OP) {
m_stats->m_num_FPdecoded_insn[m_sid]++;
}
}
}
m_inst_fetch_buffer.m_valid = false;
}
}
void shader_core_ctx::fetch() {
if (!m_inst_fetch_buffer.m_valid) {
if (m_L1I->access_ready()) {
mem_fetch *mf = m_L1I->next_access();
m_warp[mf->get_wid()]->clear_imiss_pending();
m_inst_fetch_buffer =
ifetch_buffer_t(m_warp[mf->get_wid()]->get_pc(),
mf->get_access_size(), mf->get_wid());
assert(m_warp[mf->get_wid()]->get_pc() ==
(mf->get_addr() -
PROGRAM_MEM_START)); // Verify that we got the instruction we
// were expecting.
m_inst_fetch_buffer.m_valid = true;
m_warp[mf->get_wid()]->set_last_fetch(m_gpu->gpu_sim_cycle);
delete mf;
} else {
// find an active warp with space in instruction buffer that is not
// already waiting on a cache miss and get next 1-2 instructions from
// i-cache...
for (unsigned i = 0; i < m_config->max_warps_per_shader; i++) {
unsigned warp_id =
(m_last_warp_fetched + 1 + i) % m_config->max_warps_per_shader;
// this code checks if this warp has finished executing and can be
// reclaimed
if (m_warp[warp_id]->hardware_done() &&
!m_scoreboard->pendingWrites(warp_id) &&
!m_warp[warp_id]->done_exit()) {
bool did_exit = false;
for (unsigned t = 0; t < m_config->warp_size; t++) {
unsigned tid = warp_id * m_config->warp_size + t;
if (m_threadState[tid].m_active == true) {
m_threadState[tid].m_active = false;
unsigned cta_id = m_warp[warp_id]->get_cta_id();
if (m_thread[tid] == NULL) {
register_cta_thread_exit(cta_id, m_kernel);
} else {
register_cta_thread_exit(cta_id,
&(m_thread[tid]->get_kernel()));
}
m_not_completed -= 1;
m_active_threads.reset(tid);
did_exit = true;
}
}
if (did_exit) m_warp[warp_id]->set_done_exit();
--m_active_warps;
assert(m_active_warps >= 0);
}
// this code fetches instructions from the i-cache or generates memory
if (!m_warp[warp_id]->functional_done() &&
!m_warp[warp_id]->imiss_pending() &&
m_warp[warp_id]->ibuffer_empty()) {
address_type pc;
pc = m_warp[warp_id]->get_pc();
address_type ppc = pc + PROGRAM_MEM_START;
unsigned nbytes = 16;
unsigned offset_in_block =
pc & (m_config->m_L1I_config.get_line_sz() - 1);
if ((offset_in_block + nbytes) > m_config->m_L1I_config.get_line_sz())
nbytes = (m_config->m_L1I_config.get_line_sz() - offset_in_block);
// TODO: replace with use of allocator
// mem_fetch *mf = m_mem_fetch_allocator->alloc()
mem_access_t acc(INST_ACC_R, ppc, nbytes, false, m_gpu->gpgpu_ctx);
mem_fetch *mf = new mem_fetch(
acc, NULL /*we don't have an instruction yet*/, READ_PACKET_SIZE,
warp_id, m_sid, m_tpc, m_memory_config,
m_gpu->gpu_tot_sim_cycle + m_gpu->gpu_sim_cycle);
std::list<cache_event> events;
enum cache_request_status status;
if (m_config->perfect_inst_const_cache)
status = HIT;
else
status = m_L1I->access(
(new_addr_type)ppc, mf,
m_gpu->gpu_sim_cycle + m_gpu->gpu_tot_sim_cycle, events);
if (status == MISS) {
m_last_warp_fetched = warp_id;
m_warp[warp_id]->set_imiss_pending();
m_warp[warp_id]->set_last_fetch(m_gpu->gpu_sim_cycle);
} else if (status == HIT) {
m_last_warp_fetched = warp_id;
m_inst_fetch_buffer = ifetch_buffer_t(pc, nbytes, warp_id);
m_warp[warp_id]->set_last_fetch(m_gpu->gpu_sim_cycle);
delete mf;
} else {
m_last_warp_fetched = warp_id;
assert(status == RESERVATION_FAIL);
delete mf;
}
break;
}
}
}
}
m_L1I->cycle();
}
void exec_shader_core_ctx::func_exec_inst(warp_inst_t &inst) {
execute_warp_inst_t(inst);
if (inst.is_load() || inst.is_store()) {
inst.generate_mem_accesses();
// inst.print_m_accessq();
}
}
void shader_core_ctx::issue_warp(register_set &pipe_reg_set,
const warp_inst_t *next_inst,
const active_mask_t &active_mask,
unsigned warp_id, unsigned sch_id) {
warp_inst_t **pipe_reg =
pipe_reg_set.get_free(m_config->sub_core_model, sch_id);
assert(pipe_reg);