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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
|
// Copyright (c) 2009-2021, Tor M. Aamodt, Inderpreet Singh, Vijay Kandiah,
// Nikos Hardavellas, Mahmoud Khairy, Junrui Pan, Timothy G. Rogers The
// University of British Columbia, Northwestern University, Purdue University
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this
// list of conditions and the following disclaimer;
// 2. 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;
// 3. Neither the names of The University of British Columbia, Northwestern
// University nor the names of their 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.
#ifndef ABSTRACT_HARDWARE_MODEL_INCLUDED
#define ABSTRACT_HARDWARE_MODEL_INCLUDED
// Forward declarations
class gpgpu_sim;
class kernel_info_t;
class gpgpu_context;
class shader_core_ctx;
class shader_core_config;
struct memory_config;
class simt_tables;
// Set a hard limit of 32 CTAs per shader [cuda only has 8]
#define MAX_CTA_PER_SHADER 32
#define MAX_BARRIERS_PER_CTA 16
// After expanding the vector input and output operands
#define MAX_INPUT_VALUES 24
#define MAX_OUTPUT_VALUES 8
enum _memory_space_t {
undefined_space = 0,
reg_space,
local_space,
shared_space,
sstarr_space,
param_space_unclassified,
param_space_kernel, /* global to all threads in a kernel : read-only */
param_space_local, /* local to a thread : read-writable */
const_space,
tex_space,
surf_space,
global_space,
generic_space,
instruction_space
};
#ifndef COEFF_STRUCT
#define COEFF_STRUCT
struct PowerscalingCoefficients {
double int_coeff;
double int_mul_coeff;
double int_mul24_coeff;
double int_mul32_coeff;
double int_div_coeff;
double fp_coeff;
double dp_coeff;
double fp_mul_coeff;
double fp_div_coeff;
double dp_mul_coeff;
double dp_div_coeff;
double sqrt_coeff;
double log_coeff;
double sin_coeff;
double exp_coeff;
double tensor_coeff;
double tex_coeff;
};
#endif
enum FuncCache {
FuncCachePreferNone = 0,
FuncCachePreferShared = 1,
FuncCachePreferL1 = 2
};
enum AdaptiveCache { FIXED = 0, ADAPTIVE_CACHE = 1 };
#ifdef __cplusplus
#include <stack>
#include <stdio.h>
#include <string.h>
#include <set>
typedef unsigned long long new_addr_type;
typedef unsigned long long cudaTextureObject_t;
typedef unsigned long long address_type;
typedef unsigned long long addr_t;
// the following are operations the timing model can see
#define SPECIALIZED_UNIT_NUM 8
#define SPEC_UNIT_START_ID 100
enum uarch_op_t {
NO_OP = -1,
ALU_OP = 1,
SFU_OP,
TENSOR_CORE_OP,
DP_OP,
SP_OP,
INTP_OP,
ALU_SFU_OP,
LOAD_OP,
TENSOR_CORE_LOAD_OP,
TENSOR_CORE_STORE_OP,
STORE_OP,
BRANCH_OP,
BARRIER_OP,
MEMORY_BARRIER_OP,
CALL_OPS,
RET_OPS,
EXIT_OPS,
SPECIALIZED_UNIT_1_OP = SPEC_UNIT_START_ID,
SPECIALIZED_UNIT_2_OP,
SPECIALIZED_UNIT_3_OP,
SPECIALIZED_UNIT_4_OP,
SPECIALIZED_UNIT_5_OP,
SPECIALIZED_UNIT_6_OP,
SPECIALIZED_UNIT_7_OP,
SPECIALIZED_UNIT_8_OP
};
typedef enum uarch_op_t op_type;
enum uarch_bar_t { NOT_BAR = -1, SYNC = 1, ARRIVE, RED };
typedef enum uarch_bar_t barrier_type;
enum uarch_red_t { NOT_RED = -1, POPC_RED = 1, AND_RED, OR_RED };
typedef enum uarch_red_t reduction_type;
enum uarch_operand_type_t { UN_OP = -1, INT_OP, FP_OP };
typedef enum uarch_operand_type_t types_of_operands;
enum special_operations_t {
OTHER_OP,
INT__OP,
INT_MUL24_OP,
INT_MUL32_OP,
INT_MUL_OP,
INT_DIV_OP,
FP_MUL_OP,
FP_DIV_OP,
FP__OP,
FP_SQRT_OP,
FP_LG_OP,
FP_SIN_OP,
FP_EXP_OP,
DP_MUL_OP,
DP_DIV_OP,
DP___OP,
TENSOR__OP,
TEX__OP
};
typedef enum special_operations_t
special_ops; // Required to identify for the power model
enum operation_pipeline_t {
UNKOWN_OP,
SP__OP,
DP__OP,
INTP__OP,
SFU__OP,
TENSOR_CORE__OP,
MEM__OP,
SPECIALIZED__OP,
};
typedef enum operation_pipeline_t operation_pipeline;
enum mem_operation_t { NOT_TEX, TEX };
typedef enum mem_operation_t mem_operation;
enum _memory_op_t {
no_memory_op = 0,
bru_st_fill_request,
bru_st_spill_request,
bru_rt_fill_request,
bru_rt_spill_request,
memory_load,
memory_store
};
#include <assert.h>
#include <stdlib.h>
#include <algorithm>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <vector>
#if !defined(__VECTOR_TYPES_H__)
#include "vector_types.h"
#endif
struct dim3comp {
bool operator()(const dim3 &a, const dim3 &b) const {
if (a.z < b.z)
return true;
else if (a.y < b.y)
return true;
else if (a.x < b.x)
return true;
else
return false;
}
};
void increment_x_then_y_then_z(dim3 &i, const dim3 &bound);
// Jin: child kernel information for CDP
#include "stream_manager.h"
class stream_manager;
struct CUstream_st;
// extern stream_manager * g_stream_manager;
// support for pinned memories added
extern std::map<void *, void **> pinned_memory;
extern std::map<void *, size_t> pinned_memory_size;
class kernel_info_t {
public:
// kernel_info_t()
// {
// m_valid=false;
// m_kernel_entry=NULL;
// m_uid=0;
// m_num_cores_running=0;
// m_param_mem=NULL;
// }
kernel_info_t(dim3 gridDim, dim3 blockDim, class function_info *entry,
unsigned long long streamID);
kernel_info_t(
dim3 gridDim, dim3 blockDim, class function_info *entry,
std::map<std::string, const struct cudaArray *> nameToCudaArray,
std::map<std::string, const struct textureInfo *> nameToTextureInfo);
~kernel_info_t();
void inc_running() { m_num_cores_running++; }
void dec_running() {
assert(m_num_cores_running > 0);
m_num_cores_running--;
}
bool running() const { return m_num_cores_running > 0; }
bool done() const { return no_more_ctas_to_run() && !running(); }
class function_info *entry() {
return m_kernel_entry;
}
const class function_info *entry() const { return m_kernel_entry; }
size_t num_blocks() const {
return m_grid_dim.x * m_grid_dim.y * m_grid_dim.z;
}
size_t threads_per_cta() const {
return m_block_dim.x * m_block_dim.y * m_block_dim.z;
}
dim3 get_grid_dim() const { return m_grid_dim; }
dim3 get_cta_dim() const { return m_block_dim; }
void increment_cta_id() {
increment_x_then_y_then_z(m_next_cta, m_grid_dim);
m_next_tid.x = 0;
m_next_tid.y = 0;
m_next_tid.z = 0;
}
dim3 get_next_cta_id() const { return m_next_cta; }
unsigned get_next_cta_id_single() const {
return m_next_cta.x + m_grid_dim.x * m_next_cta.y +
m_grid_dim.x * m_grid_dim.y * m_next_cta.z;
}
bool no_more_ctas_to_run() const {
return (m_next_cta.x >= m_grid_dim.x || m_next_cta.y >= m_grid_dim.y ||
m_next_cta.z >= m_grid_dim.z);
}
void increment_thread_id() {
increment_x_then_y_then_z(m_next_tid, m_block_dim);
}
dim3 get_next_thread_id_3d() const { return m_next_tid; }
unsigned get_next_thread_id() const {
return m_next_tid.x + m_block_dim.x * m_next_tid.y +
m_block_dim.x * m_block_dim.y * m_next_tid.z;
}
bool more_threads_in_cta() const {
return m_next_tid.z < m_block_dim.z && m_next_tid.y < m_block_dim.y &&
m_next_tid.x < m_block_dim.x;
}
unsigned get_uid() const { return m_uid; }
unsigned long long get_streamID() const { return m_streamID; }
std::string get_name() const { return name(); }
std::string name() const;
std::list<class ptx_thread_info *> &active_threads() {
return m_active_threads;
}
class memory_space *get_param_memory() {
return m_param_mem;
}
// The following functions access texture bindings present at the kernel's
// launch
const struct cudaArray *get_texarray(const std::string &texname) const {
std::map<std::string, const struct cudaArray *>::const_iterator t =
m_NameToCudaArray.find(texname);
assert(t != m_NameToCudaArray.end());
return t->second;
}
const struct textureInfo *get_texinfo(const std::string &texname) const {
std::map<std::string, const struct textureInfo *>::const_iterator t =
m_NameToTextureInfo.find(texname);
assert(t != m_NameToTextureInfo.end());
return t->second;
}
private:
kernel_info_t(const kernel_info_t &); // disable copy constructor
void operator=(const kernel_info_t &); // disable copy operator
class function_info *m_kernel_entry;
unsigned m_uid; // Kernel ID
unsigned long long m_streamID;
// These maps contain the snapshot of the texture mappings at kernel launch
std::map<std::string, const struct cudaArray *> m_NameToCudaArray;
std::map<std::string, const struct textureInfo *> m_NameToTextureInfo;
dim3 m_grid_dim;
dim3 m_block_dim;
dim3 m_next_cta;
dim3 m_next_tid;
unsigned m_num_cores_running;
std::list<class ptx_thread_info *> m_active_threads;
class memory_space *m_param_mem;
public:
// Jin: parent and child kernel management for CDP
void set_parent(kernel_info_t *parent, dim3 parent_ctaid, dim3 parent_tid);
void set_child(kernel_info_t *child);
void remove_child(kernel_info_t *child);
bool is_finished();
bool children_all_finished();
void notify_parent_finished();
CUstream_st *create_stream_cta(dim3 ctaid);
CUstream_st *get_default_stream_cta(dim3 ctaid);
bool cta_has_stream(dim3 ctaid, CUstream_st *stream);
void destroy_cta_streams();
void print_parent_info();
kernel_info_t *get_parent() { return m_parent_kernel; }
private:
kernel_info_t *m_parent_kernel;
dim3 m_parent_ctaid;
dim3 m_parent_tid;
std::list<kernel_info_t *> m_child_kernels; // child kernel launched
std::map<dim3, std::list<CUstream_st *>, dim3comp>
m_cta_streams; // streams created in each CTA
// Jin: kernel timing
public:
unsigned long long launch_cycle;
unsigned long long start_cycle;
unsigned long long end_cycle;
unsigned m_launch_latency;
mutable bool cache_config_set;
unsigned m_kernel_TB_latency; // this used for any CPU-GPU kernel latency and
// counted in the gpu_cycle
};
class core_config {
public:
core_config(gpgpu_context *ctx) {
gpgpu_ctx = ctx;
m_valid = false;
num_shmem_bank = 16;
shmem_limited_broadcast = false;
gpgpu_shmem_sizeDefault = (unsigned)-1;
gpgpu_shmem_sizePrefL1 = (unsigned)-1;
gpgpu_shmem_sizePrefShared = (unsigned)-1;
}
virtual void init() = 0;
bool m_valid;
unsigned warp_size;
// backward pointer
class gpgpu_context *gpgpu_ctx;
// off-chip memory request architecture parameters
int gpgpu_coalesce_arch;
// shared memory bank conflict checking parameters
bool shmem_limited_broadcast;
static const address_type WORD_SIZE = 4;
unsigned num_shmem_bank;
unsigned shmem_bank_func(address_type addr) const {
return ((addr / WORD_SIZE) % num_shmem_bank);
}
unsigned mem_warp_parts;
mutable unsigned gpgpu_shmem_size;
char *gpgpu_shmem_option;
std::vector<unsigned> shmem_opt_list;
unsigned gpgpu_shmem_sizeDefault;
unsigned gpgpu_shmem_sizePrefL1;
unsigned gpgpu_shmem_sizePrefShared;
unsigned mem_unit_ports;
// texture and constant cache line sizes (used to determine number of memory
// accesses)
unsigned gpgpu_cache_texl1_linesize;
unsigned gpgpu_cache_constl1_linesize;
unsigned gpgpu_max_insn_issue_per_warp;
bool gmem_skip_L1D; // on = global memory access always skip the L1 cache
bool adaptive_cache_config;
};
// bounded stack that implements simt reconvergence using pdom mechanism from
// MICRO'07 paper
const unsigned MAX_WARP_SIZE = 32;
typedef std::bitset<MAX_WARP_SIZE> active_mask_t;
#define MAX_WARP_SIZE_SIMT_STACK MAX_WARP_SIZE
typedef std::bitset<MAX_WARP_SIZE_SIMT_STACK> simt_mask_t;
typedef std::vector<address_type> addr_vector_t;
class simt_stack {
public:
simt_stack(unsigned wid, unsigned warpSize, class gpgpu_sim *gpu);
void reset();
void launch(address_type start_pc, const simt_mask_t &active_mask);
void update(simt_mask_t &thread_done, addr_vector_t &next_pc,
address_type recvg_pc, op_type next_inst_op,
unsigned next_inst_size, address_type next_inst_pc);
const simt_mask_t &get_active_mask() const;
void get_pdom_stack_top_info(unsigned *pc, unsigned *rpc) const;
unsigned get_rp() const;
void print(FILE *fp) const;
void resume(char *fname);
void print_checkpoint(FILE *fout) const;
protected:
unsigned m_warp_id;
unsigned m_warp_size;
enum stack_entry_type { STACK_ENTRY_TYPE_NORMAL = 0, STACK_ENTRY_TYPE_CALL };
struct simt_stack_entry {
address_type m_pc;
unsigned int m_calldepth;
simt_mask_t m_active_mask;
address_type m_recvg_pc;
unsigned long long m_branch_div_cycle;
stack_entry_type m_type;
simt_stack_entry()
: m_pc(-1),
m_calldepth(0),
m_active_mask(),
m_recvg_pc(-1),
m_branch_div_cycle(0),
m_type(STACK_ENTRY_TYPE_NORMAL){};
};
std::deque<simt_stack_entry> m_stack;
class gpgpu_sim *m_gpu;
};
// Let's just upgrade to C++11 so we can use constexpr here...
// start allocating from this address (lower values used for allocating globals
// in .ptx file)
const unsigned long long GLOBAL_HEAP_START = 0xC0000000;
// Volta max shmem size is 96kB
const unsigned long long SHARED_MEM_SIZE_MAX = 96 * (1 << 10);
// Volta max local mem is 16kB
const unsigned long long LOCAL_MEM_SIZE_MAX = 1 << 14;
// Volta Titan V has 80 SMs
const unsigned MAX_STREAMING_MULTIPROCESSORS = 80;
// Max 2048 threads / SM
const unsigned MAX_THREAD_PER_SM = 1 << 11;
// MAX 64 warps / SM
const unsigned MAX_WARP_PER_SM = 1 << 6;
const unsigned long long TOTAL_LOCAL_MEM_PER_SM =
MAX_THREAD_PER_SM * LOCAL_MEM_SIZE_MAX;
const unsigned long long TOTAL_SHARED_MEM =
MAX_STREAMING_MULTIPROCESSORS * SHARED_MEM_SIZE_MAX;
const unsigned long long TOTAL_LOCAL_MEM =
MAX_STREAMING_MULTIPROCESSORS * MAX_THREAD_PER_SM * LOCAL_MEM_SIZE_MAX;
// BRU virtualization memory region (carved out between global heap and shared mem)
const unsigned MAX_BRU_VIR_PER_SPLIT = (16 * 2);
const unsigned long long TOTAL_BRU_VIR =
(MAX_STREAMING_MULTIPROCESSORS * MAX_THREAD_PER_SM * MAX_BRU_VIR_PER_SPLIT);
const unsigned long long BRU_VIR_START = (GLOBAL_HEAP_START - TOTAL_BRU_VIR);
const unsigned long long SHARED_GENERIC_START = (BRU_VIR_START - TOTAL_SHARED_MEM);
const unsigned long long LOCAL_GENERIC_START =
SHARED_GENERIC_START - TOTAL_LOCAL_MEM;
const unsigned long long STATIC_ALLOC_LIMIT =
GLOBAL_HEAP_START - (TOTAL_LOCAL_MEM + TOTAL_SHARED_MEM + TOTAL_BRU_VIR);
#if !defined(__CUDA_RUNTIME_API_H__)
#include "builtin_types.h"
struct cudaArray {
void *devPtr;
int devPtr32;
struct cudaChannelFormatDesc desc;
int width;
int height;
int size; // in bytes
unsigned dimensions;
};
#endif
// Struct that record other attributes in the textureReference declaration
// - These attributes are passed thru __cudaRegisterTexture()
struct textureReferenceAttr {
const struct textureReference *m_texref;
int m_dim;
enum cudaTextureReadMode m_readmode;
int m_ext;
textureReferenceAttr(const struct textureReference *texref, int dim,
enum cudaTextureReadMode readmode, int ext)
: m_texref(texref), m_dim(dim), m_readmode(readmode), m_ext(ext) {}
};
class gpgpu_functional_sim_config {
public:
void reg_options(class OptionParser *opp);
void ptx_set_tex_cache_linesize(unsigned linesize);
unsigned get_forced_max_capability() const {
return m_ptx_force_max_capability;
}
bool convert_to_ptxplus() const { return m_ptx_convert_to_ptxplus; }
bool use_cuobjdump() const { return m_ptx_use_cuobjdump; }
bool experimental_lib_support() const { return m_experimental_lib_support; }
int get_ptx_inst_debug_to_file() const { return g_ptx_inst_debug_to_file; }
const char *get_ptx_inst_debug_file() const { return g_ptx_inst_debug_file; }
int get_ptx_inst_debug_thread_uid() const {
return g_ptx_inst_debug_thread_uid;
}
unsigned get_texcache_linesize() const { return m_texcache_linesize; }
int get_checkpoint_option() const { return checkpoint_option; }
int get_checkpoint_kernel() const { return checkpoint_kernel; }
int get_checkpoint_CTA() const { return checkpoint_CTA; }
int get_resume_option() const { return resume_option; }
int get_resume_kernel() const { return resume_kernel; }
int get_resume_CTA() const { return resume_CTA; }
int get_checkpoint_CTA_t() const { return checkpoint_CTA_t; }
int get_checkpoint_insn_Y() const { return checkpoint_insn_Y; }
private:
// PTX options
int m_ptx_convert_to_ptxplus;
int m_ptx_use_cuobjdump;
int m_experimental_lib_support;
unsigned m_ptx_force_max_capability;
int checkpoint_option;
int checkpoint_kernel;
int checkpoint_CTA;
unsigned resume_option;
unsigned resume_kernel;
unsigned resume_CTA;
unsigned checkpoint_CTA_t;
int checkpoint_insn_Y;
int g_ptx_inst_debug_to_file;
char *g_ptx_inst_debug_file;
int g_ptx_inst_debug_thread_uid;
unsigned m_texcache_linesize;
};
class gpgpu_t {
public:
gpgpu_t(const gpgpu_functional_sim_config &config, gpgpu_context *ctx);
// backward pointer
class gpgpu_context *gpgpu_ctx;
int checkpoint_option;
int checkpoint_kernel;
int checkpoint_CTA;
unsigned resume_option;
unsigned resume_kernel;
unsigned resume_CTA;
unsigned checkpoint_CTA_t;
int checkpoint_insn_Y;
// Move some cycle core stats here instead of being global
unsigned long long gpu_sim_cycle;
unsigned long long gpu_tot_sim_cycle;
void *gpu_malloc(size_t size);
void *gpu_mallocarray(size_t count);
void gpu_memset(size_t dst_start_addr, int c, size_t count);
void memcpy_to_gpu(size_t dst_start_addr, const void *src, size_t count);
void memcpy_from_gpu(void *dst, size_t src_start_addr, size_t count);
void memcpy_gpu_to_gpu(size_t dst, size_t src, size_t count);
class memory_space *get_global_memory() {
return m_global_mem;
}
class memory_space *get_tex_memory() {
return m_tex_mem;
}
class memory_space *get_surf_memory() {
return m_surf_mem;
}
void gpgpu_ptx_sim_bindTextureToArray(const struct textureReference *texref,
const struct cudaArray *array);
void gpgpu_ptx_sim_bindNameToTexture(const char *name,
const struct textureReference *texref,
int dim, int readmode, int ext);
void gpgpu_ptx_sim_unbindTexture(const struct textureReference *texref);
const char *gpgpu_ptx_sim_findNamefromTexture(
const struct textureReference *texref);
const struct textureReference *get_texref(const std::string &texname) const {
std::map<std::string,
std::set<const struct textureReference *> >::const_iterator t =
m_NameToTextureRef.find(texname);
assert(t != m_NameToTextureRef.end());
return *(t->second.begin());
}
const struct cudaArray *get_texarray(const std::string &texname) const {
std::map<std::string, const struct cudaArray *>::const_iterator t =
m_NameToCudaArray.find(texname);
assert(t != m_NameToCudaArray.end());
return t->second;
}
const struct textureInfo *get_texinfo(const std::string &texname) const {
std::map<std::string, const struct textureInfo *>::const_iterator t =
m_NameToTextureInfo.find(texname);
assert(t != m_NameToTextureInfo.end());
return t->second;
}
const struct textureReferenceAttr *get_texattr(
const std::string &texname) const {
std::map<std::string, const struct textureReferenceAttr *>::const_iterator
t = m_NameToAttribute.find(texname);
assert(t != m_NameToAttribute.end());
return t->second;
}
const gpgpu_functional_sim_config &get_config() const {
return m_function_model_config;
}
FILE *get_ptx_inst_debug_file() { return ptx_inst_debug_file; }
// These maps return the current texture mappings for the GPU at any given
// time.
std::map<std::string, const struct cudaArray *> getNameArrayMapping() {
return m_NameToCudaArray;
}
std::map<std::string, const struct textureInfo *> getNameInfoMapping() {
return m_NameToTextureInfo;
}
virtual ~gpgpu_t() {}
protected:
const gpgpu_functional_sim_config &m_function_model_config;
FILE *ptx_inst_debug_file;
class memory_space *m_global_mem;
class memory_space *m_tex_mem;
class memory_space *m_surf_mem;
unsigned long long m_dev_malloc;
// These maps contain the current texture mappings for the GPU at any given
// time.
std::map<std::string, std::set<const struct textureReference *> >
m_NameToTextureRef;
std::map<const struct textureReference *, std::string> m_TextureRefToName;
std::map<std::string, const struct cudaArray *> m_NameToCudaArray;
std::map<std::string, const struct textureInfo *> m_NameToTextureInfo;
std::map<std::string, const struct textureReferenceAttr *> m_NameToAttribute;
};
struct gpgpu_ptx_sim_info {
// Holds properties of the kernel (Kernel's resource use).
// These will be set to zero if a ptxinfo file is not present.
int lmem;
int smem;
int cmem;
int gmem;
int regs;
int barriers;
unsigned maxthreads;
unsigned ptx_version;
unsigned sm_target;
};
struct gpgpu_ptx_sim_arg {
gpgpu_ptx_sim_arg() { m_start = NULL; }
gpgpu_ptx_sim_arg(const void *arg, size_t size, size_t offset) {
m_start = arg;
m_nbytes = size;
m_offset = offset;
}
const void *m_start;
size_t m_nbytes;
size_t m_offset;
};
typedef std::list<gpgpu_ptx_sim_arg> gpgpu_ptx_sim_arg_list_t;
class memory_space_t {
public:
memory_space_t() {
m_type = undefined_space;
m_bank = 0;
}
memory_space_t(const enum _memory_space_t &from) {
m_type = from;
m_bank = 0;
}
bool operator==(const memory_space_t &x) const {
return (m_bank == x.m_bank) && (m_type == x.m_type);
}
bool operator!=(const memory_space_t &x) const { return !(*this == x); }
bool operator<(const memory_space_t &x) const {
if (m_type < x.m_type)
return true;
else if (m_type > x.m_type)
return false;
else if (m_bank < x.m_bank)
return true;
return false;
}
enum _memory_space_t get_type() const { return m_type; }
void set_type(enum _memory_space_t t) { m_type = t; }
unsigned get_bank() const { return m_bank; }
void set_bank(unsigned b) { m_bank = b; }
bool is_const() const {
return (m_type == const_space) || (m_type == param_space_kernel);
}
bool is_local() const {
return (m_type == local_space) || (m_type == param_space_local);
}
bool is_global() const { return (m_type == global_space); }
private:
enum _memory_space_t m_type;
unsigned m_bank; // n in ".const[n]"; note .const == .const[0] (see PTX 2.1
// manual, sec. 5.1.3)
};
const unsigned MAX_MEMORY_ACCESS_SIZE = 128;
typedef std::bitset<MAX_MEMORY_ACCESS_SIZE> mem_access_byte_mask_t;
const unsigned SECTOR_CHUNCK_SIZE = 4; // four sectors
const unsigned SECTOR_SIZE = 32; // sector is 32 bytes width
typedef std::bitset<SECTOR_CHUNCK_SIZE> mem_access_sector_mask_t;
#define NO_PARTIAL_WRITE (mem_access_byte_mask_t())
#define MEM_ACCESS_TYPE_TUP_DEF \
MA_TUP_BEGIN(mem_access_type) \
MA_TUP(GLOBAL_ACC_R), MA_TUP(LOCAL_ACC_R), MA_TUP(CONST_ACC_R), \
MA_TUP(TEXTURE_ACC_R), MA_TUP(GLOBAL_ACC_W), MA_TUP(BRU_ST_SPILL), \
MA_TUP(BRU_ST_FILL), MA_TUP(BRU_RT_SPILL), MA_TUP(BRU_RT_FILL), \
MA_TUP(LOCAL_ACC_W), MA_TUP(L1_WRBK_ACC), MA_TUP(L2_WRBK_ACC), \
MA_TUP(INST_ACC_R), MA_TUP(L1_WR_ALLOC_R), MA_TUP(L2_WR_ALLOC_R), \
MA_TUP(NUM_MEM_ACCESS_TYPE) MA_TUP_END(mem_access_type)
#define MA_TUP_BEGIN(X) enum X {
#define MA_TUP(X) X
#define MA_TUP_END(X) \
} \
;
MEM_ACCESS_TYPE_TUP_DEF
#undef MA_TUP_BEGIN
#undef MA_TUP
#undef MA_TUP_END
const char *mem_access_type_str(enum mem_access_type access_type);
enum cache_operator_type {
CACHE_UNDEFINED,
// loads
CACHE_ALL, // .ca
CACHE_LAST_USE, // .lu
CACHE_VOLATILE, // .cv
CACHE_L1, // .nc
// loads and stores
CACHE_STREAMING, // .cs
CACHE_GLOBAL, // .cg
// stores
CACHE_WRITE_BACK, // .wb
CACHE_WRITE_THROUGH // .wt
};
class mem_access_t {
public:
mem_access_t(gpgpu_context *ctx) { init(ctx); }
mem_access_t(mem_access_type type, new_addr_type address, unsigned size,
bool wr, gpgpu_context *ctx) {
init(ctx);
m_type = type;
m_addr = address;
m_req_size = size;
m_write = wr;
}
mem_access_t(mem_access_type type, new_addr_type address, unsigned size,
bool wr, const active_mask_t &active_mask,
const mem_access_byte_mask_t &byte_mask,
const mem_access_sector_mask_t §or_mask, gpgpu_context *ctx)
: m_warp_mask(active_mask),
m_byte_mask(byte_mask),
m_sector_mask(sector_mask) {
init(ctx);
m_type = type;
m_addr = address;
m_req_size = size;
m_write = wr;
}
new_addr_type get_addr() const { return m_addr; }
void set_addr(new_addr_type addr) { m_addr = addr; }
unsigned get_size() const { return m_req_size; }
const active_mask_t &get_warp_mask() const { return m_warp_mask; }
bool is_write() const { return m_write; }
enum mem_access_type get_type() const { return m_type; }
mem_access_byte_mask_t get_byte_mask() const { return m_byte_mask; }
mem_access_sector_mask_t get_sector_mask() const { return m_sector_mask; }
void print(FILE *fp) const {
fprintf(fp, "addr=0x%llx, %s, size=%u, ", m_addr,
m_write ? "store" : "load ", m_req_size);
switch (m_type) {
case GLOBAL_ACC_R:
fprintf(fp, "GLOBAL_R");
break;
case LOCAL_ACC_R:
fprintf(fp, "LOCAL_R ");
break;
case CONST_ACC_R:
fprintf(fp, "CONST ");
break;
case TEXTURE_ACC_R:
fprintf(fp, "TEXTURE ");
break;
case GLOBAL_ACC_W:
fprintf(fp, "GLOBAL_W");
break;
case LOCAL_ACC_W:
fprintf(fp, "LOCAL_W ");
break;
case L2_WRBK_ACC:
fprintf(fp, "L2_WRBK ");
break;
case INST_ACC_R:
fprintf(fp, "INST ");
break;
case L1_WRBK_ACC:
fprintf(fp, "L1_WRBK ");
break;
default:
fprintf(fp, "unknown ");
break;
}
}
gpgpu_context *gpgpu_ctx;
private:
void init(gpgpu_context *ctx);
unsigned m_uid;
new_addr_type m_addr; // request address
bool m_write;
unsigned m_req_size; // bytes
mem_access_type m_type;
active_mask_t m_warp_mask;
mem_access_byte_mask_t m_byte_mask;
mem_access_sector_mask_t m_sector_mask;
};
class mem_fetch;
class mem_fetch_interface {
public:
virtual bool full(unsigned size, bool write) const = 0;
virtual void push(mem_fetch *mf) = 0;
};
class mem_fetch_allocator {
public:
virtual mem_fetch *alloc(new_addr_type addr, mem_access_type type,
unsigned size, bool wr, unsigned long long cycle,
unsigned long long streamID) const = 0;
virtual mem_fetch *alloc(const class warp_inst_t &inst,
const mem_access_t &access,
unsigned long long cycle) const = 0;
virtual mem_fetch *alloc(new_addr_type addr, mem_access_type type,
const active_mask_t &active_mask,
const mem_access_byte_mask_t &byte_mask,
const mem_access_sector_mask_t §or_mask,
unsigned size, bool wr, unsigned long long cycle,
unsigned wid, unsigned sid, unsigned tpc,
mem_fetch *original_mf,
unsigned long long streamID) const = 0;
};
// the maximum number of destination, source, or address uarch operands in a
// instruction
#define MAX_REG_OPERANDS 32
struct dram_callback_t {
dram_callback_t() {
function = NULL;
instruction = NULL;
thread = NULL;
}
void (*function)(const class inst_t *, class ptx_thread_info *);
const class inst_t *instruction;
class ptx_thread_info *thread;
};
class inst_t {
public:
inst_t() {
m_decoded = false;
pc = (address_type)-1;
reconvergence_pc = (address_type)-1;
op = NO_OP;
bar_type = NOT_BAR;
red_type = NOT_RED;
bar_id = (unsigned)-1;
bar_count = (unsigned)-1;
oprnd_type = UN_OP;
sp_op = OTHER_OP;
op_pipe = UNKOWN_OP;
mem_op = NOT_TEX;
const_cache_operand = 0;
num_operands = 0;
num_regs = 0;
memset(out, 0, sizeof(unsigned));
memset(in, 0, sizeof(unsigned));
is_vectorin = 0;
is_vectorout = 0;
space = memory_space_t();
cache_op = CACHE_UNDEFINED;
latency = 1;
initiation_interval = 1;
for (unsigned i = 0; i < MAX_REG_OPERANDS; i++) {
arch_reg.src[i] = -1;
arch_reg.dst[i] = -1;
}
isize = 0;
}
bool valid() const { return m_decoded; }
virtual void print_insn(FILE *fp) const {
fprintf(fp, " [inst @ pc=0x%04llx] ", pc);
}
bool is_bru_st_fill_request() const {
return (op == LOAD_OP && memory_op == bru_st_fill_request);
}
bool is_bru_rt_fill_request() const {
return (op == LOAD_OP && memory_op == bru_rt_fill_request);
}
bool is_bru_st_spill_request() const {
return (op == STORE_OP && memory_op == bru_st_spill_request);
}
bool is_bru_rt_spill_request() const {
return (op == STORE_OP && memory_op == bru_rt_spill_request);
}
bool is_load() const {
return (op == LOAD_OP || op == TENSOR_CORE_LOAD_OP ||
memory_op == memory_load) &&
(memory_op != bru_st_fill_request &&
memory_op != bru_rt_fill_request);
}
bool is_store() const {
return (op == STORE_OP || op == TENSOR_CORE_STORE_OP ||
memory_op == memory_store) &&
(memory_op != bru_st_spill_request &&
memory_op != bru_rt_spill_request);
}
bool is_fp() const { return ((sp_op == FP__OP)); } // VIJAY
bool is_fpdiv() const { return ((sp_op == FP_DIV_OP)); }
bool is_fpmul() const { return ((sp_op == FP_MUL_OP)); }
bool is_dp() const { return ((sp_op == DP___OP)); }
bool is_dpdiv() const { return ((sp_op == DP_DIV_OP)); }
bool is_dpmul() const { return ((sp_op == DP_MUL_OP)); }
bool is_imul() const { return ((sp_op == INT_MUL_OP)); }
bool is_imul24() const { return ((sp_op == INT_MUL24_OP)); }
bool is_imul32() const { return ((sp_op == INT_MUL32_OP)); }
bool is_idiv() const { return ((sp_op == INT_DIV_OP)); }
bool is_sfu() const {
return ((sp_op == FP_SQRT_OP) || (sp_op == FP_LG_OP) ||
(sp_op == FP_SIN_OP) || (sp_op == FP_EXP_OP) ||
(sp_op == TENSOR__OP));
}
bool is_alu() const { return (sp_op == INT__OP); }
unsigned get_num_operands() const { return num_operands; }
unsigned get_num_regs() const { return num_regs; }
void set_num_regs(unsigned num) { num_regs = num; }
void set_num_operands(unsigned num) { num_operands = num; }
void set_bar_id(unsigned id) { bar_id = id; }
void set_bar_count(unsigned count) { bar_count = count; }
address_type pc; // program counter address of instruction
unsigned isize; // size of instruction in bytes
op_type op; // opcode (uarch visible)
barrier_type bar_type;
reduction_type red_type;
unsigned bar_id;
unsigned bar_count;
types_of_operands oprnd_type; // code (uarch visible) identify if the
// operation is an interger or a floating point
special_ops
sp_op; // code (uarch visible) identify if int_alu, fp_alu, int_mul ....
operation_pipeline op_pipe; // code (uarch visible) identify the pipeline of
// the operation (SP, SFU or MEM)
mem_operation mem_op; // code (uarch visible) identify memory type
bool const_cache_operand; // has a load from constant memory as an operand
_memory_op_t memory_op; // memory_op used by ptxplus
unsigned num_operands;
unsigned num_regs; // count vector operand as one register operand
address_type reconvergence_pc; // -1 => not a branch, -2 => use function
// return address
unsigned out[8];
unsigned outcount;
unsigned in[24];
unsigned incount;
unsigned char is_vectorin;
unsigned char is_vectorout;
int pred; // predicate register number
int ar1, ar2;
// register number for bank conflict evaluation
struct {
int dst[MAX_REG_OPERANDS];
int src[MAX_REG_OPERANDS];
} arch_reg;
// int arch_reg[MAX_REG_OPERANDS]; // register number for bank conflict
// evaluation
unsigned latency; // operation latency
unsigned initiation_interval;
unsigned data_size; // what is the size of the word being operated on?
memory_space_t space;
cache_operator_type cache_op;
protected:
bool m_decoded;
virtual void pre_decode() {}
};
enum splits_replacement_policy_t {
FIFO_BACK = 1,
NUM_ST_REPLACEMENT_POLICIES
};
enum reconvergence_replacement_policy_t {
REC_LRU = 1,
NUM_REC_REPLACEMENT_POLICIES
};
enum divergence_support_t {
POST_DOMINATOR = 1,
AWARE_RECONVERGENCE = 2,
NUM_SIMD_MODEL
};
const unsigned MAX_ACCESSES_PER_INSN_PER_THREAD = 8;
// SIMD lane partitioning: per-set execution data
struct simd_set_info {
unsigned set_id; // Set index (0 to num_sets-1)
unsigned warp_id; // Owning warp
simt_mask_t set_active_mask; // Active lanes within this set (lower set_width bits)
active_mask_t active_mask_in_warp; // Active mask in original 32-bit warp thread domain
unsigned thread_ids[MAX_WARP_SIZE]; // Original thread IDs for each lane (max set_width used)
unsigned num_active_threads; // popcount of set_active_mask
bool valid; // Whether this set has any active threads
const inst_t *source_inst; // Pointer to static decoded instruction (for MIMD)
simd_set_info()
: set_id(0), warp_id(0), num_active_threads(0), valid(false),
source_inst(NULL) {
set_active_mask.reset();
active_mask_in_warp.reset();
for (unsigned i = 0; i < MAX_WARP_SIZE; i++) thread_ids[i] = 0;
}
};
class warp_inst_t : public inst_t {
public:
// constructors
warp_inst_t() {
m_uid = 0;
m_streamID = (unsigned long long)-1;
m_empty = true;
m_config = NULL;
// Ni:
m_is_ldgsts = false;
m_is_ldgdepbar = false;
m_is_depbar = false;
m_depbar_group_no = 0;
}
warp_inst_t(const core_config *config) {
m_uid = 0;
m_streamID = (unsigned long long)-1;
assert(config->warp_size <= MAX_WARP_SIZE);
m_config = config;
m_empty = true;
m_isatomic = false;
m_per_scalar_thread_valid = false;
m_mem_accesses_created = false;
m_cache_hit = false;
m_is_printf = false;
m_is_cdp = 0;
should_do_atomic = true;
// Ni:
m_is_ldgsts = false;
m_is_ldgdepbar = false;
m_is_depbar = false;
m_depbar_group_no = 0;
}
virtual ~warp_inst_t() {}
// modifiers
void broadcast_barrier_reduction(const active_mask_t &access_mask);
void do_atomic(bool forceDo = false);
void do_atomic(const active_mask_t &access_mask, bool forceDo = false);
void clear() {
m_empty = true;
m_simd_sets.clear();
}
void issue(const active_mask_t &mask, unsigned warp_id,
unsigned long long cycle, int dynamic_warp_id, int sch_id,
unsigned long long streamID);
// SIMD lane partitioning
void compute_simd_sets(unsigned num_sets, unsigned set_width);
const std::vector<simd_set_info> &get_simd_sets() const {
return m_simd_sets;
}
unsigned num_active_simd_sets() const;
bool has_simd_sets() const { return !m_simd_sets.empty(); }
void merge_simd_sets(const std::vector<simd_set_info> &other_sets);
void set_source_inst_on_sets(const inst_t *src);
static bool simd_sets_overlap(const std::vector<simd_set_info> &a,
const std::vector<simd_set_info> &b);
const active_mask_t &get_active_mask() const { return m_warp_active_mask; }
void completed(unsigned long long cycle)
const; // stat collection: called when the instruction is completed
void set_addr(unsigned n, new_addr_type addr) {
if (!m_per_scalar_thread_valid) {
m_per_scalar_thread.resize(m_config->warp_size);
m_per_scalar_thread_valid = true;
}
m_per_scalar_thread[n].memreqaddr[0] = addr;
}
void set_addr(unsigned n, new_addr_type *addr, unsigned num_addrs) {
if (!m_per_scalar_thread_valid) {
m_per_scalar_thread.resize(m_config->warp_size);
m_per_scalar_thread_valid = true;
}
assert(num_addrs <= MAX_ACCESSES_PER_INSN_PER_THREAD);
for (unsigned i = 0; i < num_addrs; i++)
m_per_scalar_thread[n].memreqaddr[i] = addr[i];
}
void print_m_accessq() {
if (accessq_empty())
return;
else {
printf("Printing mem access generated\n");
std::list<mem_access_t>::iterator it;
for (it = m_accessq.begin(); it != m_accessq.end(); ++it) {
printf("MEM_TXN_GEN:%s:%llx, Size:%d \n",
mem_access_type_str(it->get_type()), it->get_addr(),
it->get_size());
}
}
}
struct transaction_info {
std::bitset<4> chunks; // bitmask: 32-byte chunks accessed
mem_access_byte_mask_t bytes;
active_mask_t active; // threads in this transaction
bool test_bytes(unsigned start_bit, unsigned end_bit) {
for (unsigned i = start_bit; i <= end_bit; i++)
if (bytes.test(i)) return true;
return false;
}
};
void generate_mem_accesses();
void memory_coalescing_arch(bool is_write, mem_access_type access_type);
void memory_coalescing_arch_atomic(bool is_write,
mem_access_type access_type);
void memory_coalescing_arch_reduce_and_send(bool is_write,
mem_access_type access_type,
const transaction_info &info,
new_addr_type addr,
unsigned segment_size);
void add_callback(unsigned lane_id,
void (*function)(const class inst_t *,
class ptx_thread_info *),
const inst_t *inst, class ptx_thread_info *thread,
bool atomic) {
if (!m_per_scalar_thread_valid) {
m_per_scalar_thread.resize(m_config->warp_size);
m_per_scalar_thread_valid = true;
if (atomic) m_isatomic = true;
}
m_per_scalar_thread[lane_id].callback.function = function;
m_per_scalar_thread[lane_id].callback.instruction = inst;
m_per_scalar_thread[lane_id].callback.thread = thread;
}
void set_active(const active_mask_t &active);
void set_active(unsigned lane_id) { m_warp_active_mask.set(lane_id); }
void clear_active(const active_mask_t &inactive);
void set_not_active(unsigned lane_id);
void clear_pending_mem_requests() { m_accessq.clear(); }
void inject_mem_acccesses(mem_access_t acc) { m_accessq.push_back(acc); }
// accessors
virtual void print_insn(FILE *fp) const {
fprintf(fp, " [inst @ pc=0x%04llx] ", pc);
for (int i = (int)m_config->warp_size - 1; i >= 0; i--)
fprintf(fp, "%c", ((m_warp_active_mask[i]) ? '1' : '0'));
}
bool active(unsigned thread) const { return m_warp_active_mask.test(thread); }
unsigned active_count() const { return m_warp_active_mask.count(); }
unsigned issued_count() const {
assert(m_empty == false);
return m_warp_issued_mask.count();
} // for instruction counting
bool empty() const { return m_empty; }
void occupy() { m_empty = false; }
unsigned get_warp_id() const { return m_warp_id; }
void set_warp_id(unsigned warp_id) { m_warp_id = warp_id; }
unsigned warp_id() const {
assert(!m_empty);
return m_warp_id;
}
unsigned warp_id_func() const // to be used in functional simulations only
{
return m_warp_id;
}
unsigned dynamic_warp_id() const {
assert(!m_empty);
return m_dynamic_warp_id;
}
bool has_callback(unsigned n) const {
return m_warp_active_mask[n] && m_per_scalar_thread_valid &&
(m_per_scalar_thread[n].callback.function != NULL);
}
new_addr_type get_addr(unsigned n) const {
assert(m_per_scalar_thread_valid);
return m_per_scalar_thread[n].memreqaddr[0];
}
bool isatomic() const { return m_isatomic; }
unsigned warp_size() const { return m_config->warp_size; }
bool accessq_empty() const { return m_accessq.empty(); }
unsigned accessq_count() const { return m_accessq.size(); }
const mem_access_t &accessq_back() { return m_accessq.back(); }
void accessq_pop_back() { m_accessq.pop_back(); }
bool dispatch_delay() {
if (cycles > 0) cycles--;
return cycles > 0;
}
bool has_dispatch_delay() { return cycles > 0; }
void print(FILE *fout) const;
unsigned get_uid() const { return m_uid; }
unsigned long long get_streamID() const { return m_streamID; }
unsigned get_schd_id() const { return m_scheduler_id; }
active_mask_t get_warp_active_mask() const { return m_warp_active_mask; }
protected:
unsigned m_uid;
unsigned long long m_streamID;
bool m_empty;
bool m_cache_hit;
unsigned long long issue_cycle;
unsigned cycles; // used for implementing initiation interval delay
bool m_isatomic;
bool should_do_atomic;
bool m_is_printf;
unsigned m_warp_id;
unsigned m_dynamic_warp_id;
const core_config *m_config;
active_mask_t m_warp_active_mask; // dynamic active mask for timing model
// (after predication)
active_mask_t
m_warp_issued_mask; // active mask at issue (prior to predication test)
// -- for instruction counting
struct per_thread_info {
per_thread_info() {
for (unsigned i = 0; i < MAX_ACCESSES_PER_INSN_PER_THREAD; i++)
memreqaddr[i] = 0;
}
dram_callback_t callback;
new_addr_type
memreqaddr[MAX_ACCESSES_PER_INSN_PER_THREAD]; // effective address,
// upto 8 different
// requests (to support
// 32B access in 8 chunks
// of 4B each)
};
bool m_per_scalar_thread_valid;
std::vector<per_thread_info> m_per_scalar_thread;
bool m_mem_accesses_created;
std::list<mem_access_t> m_accessq;
unsigned m_scheduler_id; // the scheduler that issues this inst
// SIMD lane partitioning data
std::vector<simd_set_info> m_simd_sets;
// Jin: cdp support
public:
int m_is_cdp;
// Ni: add boolean to indicate whether the instruction is ldgsts
bool m_is_ldgsts;
bool m_is_ldgdepbar;
bool m_is_depbar;
unsigned int m_depbar_group_no;
};
void move_warp(warp_inst_t *&dst, warp_inst_t *&src);
size_t get_kernel_code_size(class function_info *entry);
class checkpoint {
public:
checkpoint();
~checkpoint() { printf("clasfsfss destructed\n"); }
void load_global_mem(class memory_space *temp_mem, char *f1name);
void store_global_mem(class memory_space *mem, char *fname, char *format);
unsigned radnom;
};
// Debug print macro for ITS (disabled by default)
#define AWARE_DEBUG_PRINT 1
#define AWARE_DPRINTF(...) \
if (AWARE_DEBUG_PRINT) { \
printf(__VA_ARGS__); \
fflush(stdout); \
}
// ── ITS (AWARE Reconvergence) data structures ──────────────────────────────
#define MAX_ST_SIZE 33
#define MAX_RT_SIZE 32
enum splits_table_entry_type {
SPLITS_TABLE_ENTRY_TYPE_NORMAL = 0,
SPLITS_TABLE_TYPE_CALL
};
struct simt_splits_table_entry {
bool m_valid;
bool m_blocked;
bool m_virtual;
bool m_transient;
bool m_suspended;
address_type m_pc;
unsigned int m_calldepth;
simt_mask_t m_active_mask;
address_type m_recvg_pc;
unsigned int m_recvg_entry;
unsigned long long m_branch_div_cycle;
splits_table_entry_type m_type;
simt_splits_table_entry()
: m_valid(false), m_blocked(false), m_virtual(false),
m_transient(false), m_suspended(false), m_pc(-1), m_calldepth(0),
m_active_mask(), m_recvg_pc(-1), m_branch_div_cycle(0),
m_type(SPLITS_TABLE_ENTRY_TYPE_NORMAL) {}
};
struct fifo_entry {
bool m_blocked;
unsigned m_st_entry;
unsigned long long m_insertion_cycle;
unsigned m_insertion_distance;
fifo_entry() : m_blocked(false), m_st_entry(-1) {}
fifo_entry(unsigned num, unsigned long long cycle, unsigned dist)
: m_blocked(false), m_st_entry(num), m_insertion_cycle(cycle),
m_insertion_distance(dist) {}
void update_insertion_cycle(unsigned long long cycle, unsigned dist) {
m_insertion_cycle = cycle;
m_insertion_distance = dist;
}
};
struct simt_reconvergence_table_entry {
bool m_valid;
bool m_virtual;
bool m_transient;
address_type m_pc;
unsigned int m_calldepth;
simt_mask_t m_active_mask;
simt_mask_t m_pending_mask;
address_type m_recvg_pc;
unsigned int m_recvg_entry;
unsigned long long m_branch_rec_cycle;
splits_table_entry_type m_type;
simt_reconvergence_table_entry()
: m_valid(false), m_virtual(false), m_transient(false), m_pc(-1),
m_calldepth(0), m_active_mask(), m_recvg_pc(-1),
m_branch_rec_cycle(0), m_type(SPLITS_TABLE_ENTRY_TYPE_NORMAL) {}
};
class simt_splits_table {
public:
simt_splits_table(unsigned wid, unsigned warpSize,
const shader_core_config *config,
const struct memory_config *mem_config,
simt_tables *simt_table);
void reset();
void launch(address_type start_pc, const simt_mask_t &active_mask);
unsigned insert_new_entry(address_type pc, address_type rpc,
unsigned rpc_entry,
const simt_mask_t &tmp_active_mask,
splits_table_entry_type type, bool recvged = false);
unsigned insert_new_entry(address_type pc, address_type rpc,
unsigned rpc_entry,
const simt_mask_t &tmp_active_mask,
splits_table_entry_type type, bool call_ret,
bool recvged);
unsigned insert_new_entry(simt_splits_table_entry entry, bool recvged = false);
bool fill_st_entry(unsigned entry);
bool spill_st_entry();
void get_pdom_splits_entry_info(unsigned num, unsigned *pc, unsigned *rpc);
void get_pdom_active_split_info(unsigned *pc, unsigned *rpc);
const simt_mask_t &get_active_mask(unsigned num);
const simt_mask_t &get_active_mask();
unsigned get_rpc();
unsigned get_pc();
unsigned get_rpc_entry();
splits_table_entry_type get_type();
bool valid();
unsigned get_rpc(unsigned num);
void invalidate();
void update_active_entry();
void update_pc(address_type new_pc);
void set_to_blocked();
void unset_blocked();
void unset_blocked(unsigned entry);
void release_blocked();
bool is_blocked();
bool is_virtual();
bool is_blocked_or_virtual();
bool split_reaches_barrier(address_type pc);
void push_back();
void push_back_once();
unsigned check_simt_splits_table();
unsigned num_entries() { return m_num_entries; }
unsigned getInsertionDist() { return m_fifo_queue.front().m_insertion_distance; }
unsigned long long getInsertionCycle() { return m_fifo_queue.front().m_insertion_cycle; }
void print(FILE *fp);
void cycle();
bool branch_unit_avail() { return m_spill_st_entry.empty(); }
unsigned get_replacement_candidate();
void set_shader(shader_core_ctx *shader);
bool push_to_st_response_fifo(unsigned entry);
bool is_virtualized();
bool is_pending_reconvergence() { return m_pending_recvg_entry.m_valid; }
bool st_space_available() { return m_num_physical_entries < m_max_st_size; }
bool blocked();
unsigned address_to_entry(warp_inst_t inst);
protected:
unsigned m_warp_size;
unsigned m_warp_id;
unsigned m_max_st_size;
unsigned m_num_entries;
unsigned m_num_physical_entries;
unsigned m_num_transient_entries;
std::map<unsigned, simt_splits_table_entry> m_splits_table;
std::deque<fifo_entry> m_fifo_queue;
std::stack<int> m_invalid_entries;
std::stack<int> m_available_v_id;
unsigned m_active_split;
warp_inst_t m_spill_st_entry;
warp_inst_t m_fill_st_entry;
int m_response_st_entry;
shader_core_ctx *m_shader;
const shader_core_config *m_config;
const struct memory_config *m_mem_config;
simt_tables *m_simt_tables;
simt_splits_table_entry m_pending_recvg_entry;
};
class simt_reconvergence_table {
public:
simt_reconvergence_table(unsigned wid, unsigned warpSize,
const shader_core_config *config,
const struct memory_config *mem_config,
simt_tables *simt_table);
void reset();
const simt_mask_t &get_active_mask();
const simt_mask_t &get_active_mask(unsigned num);
void get_recvg_entry_info(unsigned num, unsigned *pc, unsigned *rpc);
void get_active_recvg_info(unsigned *pc, unsigned *rpc);
unsigned get_rpc(unsigned num);
unsigned get_rpc();
unsigned get_rpc_entry(unsigned num);
splits_table_entry_type get_type(unsigned num);
splits_table_entry_type get_type();
unsigned get_rpc_entry();
unsigned get_pc(unsigned num);
unsigned get_pc();
void invalidate();
void invalidate(unsigned num);
bool update_pending_mask(unsigned top_recvg_entry, address_type top_recvg_pc,
const simt_mask_t &tmp_active_mask, bool &suspended);
unsigned insert_new_entry(address_type pc, address_type rpc,
unsigned rpc_entry,
const simt_mask_t &tmp_active_mask,
splits_table_entry_type type);
void update_masks_upon_time_out(unsigned k,
const simt_mask_t &reconverged_mask);
void set_rec_cycle(unsigned rec_entry, unsigned long long time);
unsigned check_simt_reconvergence_table();
simt_reconvergence_table_entry get_recvg_entry(unsigned num);
unsigned num_entries() { return m_num_entries; }
void print(FILE *fout);
void cycle();
bool branch_unit_avail() { return m_spill_rec_entry.empty(); }
void set_shader(shader_core_ctx *shader) { m_shader = shader; }
bool spill_rec_entry();
bool fill_rec_entry(unsigned entry);
bool is_pending_update() { return m_pending_update_entry.m_valid; }
bool push_to_rt_response_fifo(unsigned entry);
unsigned get_replacement_candidate();
unsigned address_to_entry(warp_inst_t inst);
protected:
unsigned m_warp_id;
unsigned m_warp_size;
unsigned m_num_entries;
unsigned m_num_physical_entries;
unsigned m_num_transient_entries;
unsigned m_max_rec_size;
std::map<int, simt_reconvergence_table_entry> m_recvg_table;
std::stack<int> m_invalid_entries;
unsigned m_active_reconvergence;
const shader_core_config *m_config;
shader_core_ctx *m_shader;
simt_tables *m_simt_tables;
warp_inst_t m_spill_rec_entry;
warp_inst_t m_fill_rec_entry;
int m_response_rec_entry;
simt_reconvergence_table_entry m_pending_update_entry;
const struct memory_config *m_mem_config;
};
class simt_tables {
public:
simt_tables(unsigned wid, unsigned warpSize,
const shader_core_config *config,
const memory_config *mem_config);
void reset();
void launch(address_type start_pc, const simt_mask_t &active_mask);
void update(simt_mask_t &thread_done, addr_vector_t &next_pc,
address_type recvg_pc, op_type next_inst_op,
unsigned next_inst_size, address_type next_inst_pc,
bool predicated);
const simt_mask_t &get_active_mask();
void get_pdom_active_split_info(unsigned *pc, unsigned *rpc);
unsigned get_rp();
void check_simt_tables();
void check_time_out();
void release_barrier();
bool split_reaches_barrier(address_type pc);
void print(FILE *fp);
unsigned getSTsize() { return m_simt_splits_table->num_entries(); }
unsigned getInsertionDist() { return m_simt_splits_table->getInsertionDist(); }
unsigned long long getInsertionCycle() { return m_simt_splits_table->getInsertionCycle(); }
unsigned getRTsize() { return m_simt_recvg_table->num_entries(); }
bool branch_unit_avail() {
return m_simt_splits_table->branch_unit_avail() &&
m_simt_recvg_table->branch_unit_avail();
}
bool push_to_st_response_fifo(unsigned entry);
bool push_to_rt_response_fifo(unsigned entry);
void cycle() {
m_simt_splits_table->cycle();
m_simt_recvg_table->cycle();
}
void set_shader(shader_core_ctx *shader);
void push_back();
bool is_virtualized();
bool is_pending_reconvergence();
bool st_space_available();
bool blocked();
bool valid();
bool is_blocked();
bool fill_rec_entry(unsigned entry) {
return m_simt_recvg_table->fill_rec_entry(entry);
}
bool insert_st_entry(address_type pc, address_type rpc, unsigned rpc_entry,
const simt_mask_t &tmp_active_mask,
splits_table_entry_type type, bool recvged = false) {
return m_simt_splits_table->insert_new_entry(pc, rpc, rpc_entry,
tmp_active_mask, type, recvged);
}
private:
unsigned m_warp_id;
unsigned m_warp_size;
simt_splits_table *m_simt_splits_table;
simt_reconvergence_table *m_simt_recvg_table;
const shader_core_config *m_config;
const struct memory_config *m_mem_config;
shader_core_ctx *m_shader;
};
// ── End ITS data structures ─────────────────────────────────────────────────
/*
* This abstract class used as a base for functional and performance and
* simulation, it has basic functional simulation data structures and
* procedures.
*/
class core_t {
public:
core_t(gpgpu_sim *gpu, kernel_info_t *kernel, unsigned warp_size,
unsigned threads_per_shader)
: m_gpu(gpu),
m_kernel(kernel),
m_simt_stack(NULL),
m_simt_tables(NULL),
m_thread(NULL),
m_warp_size(warp_size) {
m_warp_count = threads_per_shader / m_warp_size;
// Handle the case where the number of threads is not a
// multiple of the warp size
if (threads_per_shader % m_warp_size != 0) {
m_warp_count += 1;
}
assert(m_warp_count * m_warp_size > 0);
m_thread = (ptx_thread_info **)calloc(m_warp_count * m_warp_size,
sizeof(ptx_thread_info *));
initilizeSIMTDivergenceStructures(m_warp_count, m_warp_size);
for (unsigned i = 0; i < MAX_CTA_PER_SHADER; i++) {
for (unsigned j = 0; j < MAX_BARRIERS_PER_CTA; j++) {
reduction_storage[i][j] = 0;
}
}
}
virtual ~core_t() { free(m_thread); }
virtual void warp_exit(unsigned warp_id) = 0;
virtual bool warp_waiting_at_barrier(unsigned warp_id) const = 0;
virtual void checkExecutionStatusAndUpdate(warp_inst_t &inst, unsigned t,
unsigned tid) = 0;
class gpgpu_sim *get_gpu() {
return m_gpu;
}
void execute_warp_inst_t(warp_inst_t &inst, unsigned warpId = (unsigned)-1);
bool ptx_thread_done(unsigned hw_thread_id) const;
virtual void updateSIMTStack(unsigned warpId, warp_inst_t *inst);
virtual void updateSIMTDivergenceStructures(unsigned warpId, warp_inst_t *inst);
void initilizeSIMTStack(unsigned warp_count, unsigned warps_size);
void deleteSIMTStack();
void initilizeSIMTDivergenceStructures(unsigned warp_count, unsigned warp_size);
void deleteSIMTDivergenceStructures();
warp_inst_t getExecuteWarp(unsigned warpId);
void get_pdom_stack_top_info(unsigned warpId, unsigned *pc,
unsigned *rpc) const;
kernel_info_t *get_kernel_info() { return m_kernel; }
class ptx_thread_info **get_thread_info() {
return m_thread;
}
unsigned get_warp_size() const { return m_warp_size; }
void and_reduction(unsigned ctaid, unsigned barid, bool value) {
reduction_storage[ctaid][barid] &= value;
}
void or_reduction(unsigned ctaid, unsigned barid, bool value) {
reduction_storage[ctaid][barid] |= value;
}
void popc_reduction(unsigned ctaid, unsigned barid, bool value) {
reduction_storage[ctaid][barid] += value;
}
unsigned get_reduction_value(unsigned ctaid, unsigned barid) {
return reduction_storage[ctaid][barid];
}
protected:
class gpgpu_sim *m_gpu;
kernel_info_t *m_kernel;
simt_stack **m_simt_stack; // pdom based reconvergence context for each warp
simt_tables **m_simt_tables; // ITS (AWARE) reconvergence tables per warp
class ptx_thread_info **m_thread;
unsigned m_warp_size;
unsigned m_warp_count;
unsigned reduction_storage[MAX_CTA_PER_SHADER][MAX_BARRIERS_PER_CTA];
};
// register that can hold multiple instructions.
class register_set {
public:
register_set(unsigned num, const char *name) {
for (unsigned i = 0; i < num; i++) {
regs.push_back(new warp_inst_t());
}
m_name = name;
}
const char *get_name() { return m_name; }
bool has_free() {
for (unsigned i = 0; i < regs.size(); i++) {
if (regs[i]->empty()) {
return true;
}
}
return false;
}
bool has_free(bool sub_core_model, unsigned reg_id) {
// in subcore model, each sched has a one specific reg to use (based on
// sched id)
if (!sub_core_model) return has_free();
assert(reg_id < regs.size());
return regs[reg_id]->empty();
}
bool has_ready() {
for (unsigned i = 0; i < regs.size(); i++) {
if (not regs[i]->empty()) {
return true;
}
}
return false;
}
bool has_ready(bool sub_core_model, unsigned reg_id) {
if (!sub_core_model) return has_ready();
assert(reg_id < regs.size());
return (not regs[reg_id]->empty());
}
unsigned get_ready_reg_id() {
// for sub core model we need to figure which reg_id has the ready warp
// this function should only be called if has_ready() was true
assert(has_ready());
warp_inst_t **ready;
ready = NULL;
unsigned reg_id = 0;
for (unsigned i = 0; i < regs.size(); i++) {
if (not regs[i]->empty()) {
if (ready and (*ready)->get_uid() < regs[i]->get_uid()) {
// ready is oldest
} else {
ready = ®s[i];
reg_id = i;
}
}
}
return reg_id;
}
unsigned get_schd_id(unsigned reg_id) {
assert(not regs[reg_id]->empty());
return regs[reg_id]->get_schd_id();
}
void move_in(warp_inst_t *&src) {
warp_inst_t **free = get_free();
move_warp(*free, src);
}
// void copy_in( warp_inst_t* src ){
// src->copy_contents_to(*get_free());
//}
void move_in(bool sub_core_model, unsigned reg_id, warp_inst_t *&src) {
warp_inst_t **free;
if (!sub_core_model) {
free = get_free();
} else {
assert(reg_id < regs.size());
free = get_free(sub_core_model, reg_id);
}
move_warp(*free, src);
}
void move_out_to(warp_inst_t *&dest) {
warp_inst_t **ready = get_ready();
move_warp(dest, *ready);
}
void move_out_to(bool sub_core_model, unsigned reg_id, warp_inst_t *&dest) {
if (!sub_core_model) {
return move_out_to(dest);
}
warp_inst_t **ready = get_ready(sub_core_model, reg_id);
assert(ready != NULL);
move_warp(dest, *ready);
}
warp_inst_t **get_ready() {
warp_inst_t **ready;
ready = NULL;
for (unsigned i = 0; i < regs.size(); i++) {
if (not regs[i]->empty()) {
if (ready and (*ready)->get_uid() < regs[i]->get_uid()) {
// ready is oldest
} else {
ready = ®s[i];
}
}
}
return ready;
}
warp_inst_t **get_ready(bool sub_core_model, unsigned reg_id) {
if (!sub_core_model) return get_ready();
warp_inst_t **ready;
ready = NULL;
assert(reg_id < regs.size());
if (not regs[reg_id]->empty()) ready = ®s[reg_id];
return ready;
}
void print(FILE *fp) const {
fprintf(fp, "%s : @%p\n", m_name, this);
for (unsigned i = 0; i < regs.size(); i++) {
fprintf(fp, " ");
regs[i]->print(fp);
fprintf(fp, "\n");
}
}
warp_inst_t **get_free() {
for (unsigned i = 0; i < regs.size(); i++) {
if (regs[i]->empty()) {
return ®s[i];
}
}
assert(0 && "No free registers found");
return NULL;
}
warp_inst_t **get_free(bool sub_core_model, unsigned reg_id) {
// in subcore model, each sched has a one specific reg to use (based on
// sched id)
if (!sub_core_model) return get_free();
assert(reg_id < regs.size());
if (regs[reg_id]->empty()) {
return ®s[reg_id];
}
assert(0 && "No free register found");
return NULL;
}
unsigned get_size() { return regs.size(); }
private:
std::vector<warp_inst_t *> regs;
const char *m_name;
};
#endif // #ifdef __cplusplus
#endif // #ifndef ABSTRACT_HARDWARE_MODEL_INCLUDED
|