1 /*========================== begin_copyright_notice ============================
2
3 Copyright (C) 2017-2021 Intel Corporation
4
5 SPDX-License-Identifier: MIT
6
7 ============================= end_copyright_notice ===========================*/
8
9 #include "IGC/common/StringMacros.hpp"
10 #include "visa_igc_common_header.h"
11 #include "common.h"
12 #include "G4_Opcode.h"
13 #include <cctype>
14
15 //for exception handling
16 //FIXME: potentially not thread safe, but should be ok since it's debugging code
17 std::stringstream errorMsgs;
18
19 static _THREAD TARGET_PLATFORM visaPlatform;
20
21 struct PlatformInfo {
22 TARGET_PLATFORM platform;
23 PlatformGen family;
24 int encoding;
25 const char *symbols[8];
26
PlatformInfoPlatformInfo27 constexpr PlatformInfo(
28 TARGET_PLATFORM p,
29 PlatformGen f,
30 int e,
31 const char *str0,
32 const char *str1 = nullptr,
33 const char *str2 = nullptr,
34 const char *str3 = nullptr,
35 const char *str4 = nullptr)
36 : platform(p), family(f), encoding(e), symbols{str0, str1, str2, str3, str4, nullptr}
37 {
38 }
39 }; // PlatformInfo
40
41 static const PlatformInfo ALL_PLATFORMS[] {
42 PlatformInfo(GENX_BDW, PlatformGen::GEN8, 3, "BDW", "GEN8"),
43 PlatformInfo(GENX_CHV, PlatformGen::GEN8, 4, "CHV", "GEN8LP"),
44 PlatformInfo(GENX_SKL, PlatformGen::GEN9, 5, "SKL", "GEN9", "KBL", "CFL"),
45 PlatformInfo(GENX_BXT, PlatformGen::GEN9, 6, "BXT", "GEN9LP"),
46 PlatformInfo(GENX_ICLLP, PlatformGen::GEN11, 10,
47 "ICLLP", "ICL", "GEN11", "GEN11LP"),
48 PlatformInfo(GENX_TGLLP, PlatformGen::XE, 12,
49 "TGLLP", "DG1", "GEN12LP"
50 ),
51 PlatformInfo(XeHP_SDV, PlatformGen::XE, 11,
52 "XeHP_SDV"),
53 PlatformInfo(GENX_DG2, PlatformGen::XE, 13,
54 "DG2"),
55 PlatformInfo(GENX_PVC, PlatformGen::XE, 14,
56 "PVC"),
57 PlatformInfo(GENX_PVCXT, PlatformGen::XE, 15,
58 "PVCXT"),
59 }; // ALL_PLATFORMS
60
LookupPlatformInfo(TARGET_PLATFORM p)61 static const PlatformInfo *LookupPlatformInfo(TARGET_PLATFORM p)
62 {
63 for (const auto &pi : ALL_PLATFORMS) {
64 if (pi.platform == p)
65 return π
66 }
67 return nullptr;
68 }
69
SetVisaPlatform(TARGET_PLATFORM vPlatform)70 int SetVisaPlatform(TARGET_PLATFORM vPlatform)
71 {
72 assert(vPlatform >= GENX_BDW && "unsupported platform");
73 visaPlatform = vPlatform;
74
75 return VISA_SUCCESS;
76 }
77
SetVisaPlatform(const char * str)78 int SetVisaPlatform(const char * str)
79 {
80 auto toUpperStr = [](const char *str) {
81 std::string upper;
82 while (*str)
83 upper += (char)toupper(*str++);
84 return upper;
85 };
86
87 std::string upperStr = toUpperStr(str);
88 auto platform = GENX_NONE;
89 for (const auto &pi : ALL_PLATFORMS) {
90 const char * const* syms = &pi.symbols[0];
91 while (*syms) {
92 if (upperStr == toUpperStr(*syms)) {
93 platform = pi.platform;
94 break;
95 }
96 syms++;
97 }
98 if (platform != GENX_NONE)
99 break;
100 }
101 visaPlatform = platform;
102 return platform != GENX_NONE ? VISA_SUCCESS : VISA_FAILURE;
103 }
104
getGenxPlatform()105 TARGET_PLATFORM getGenxPlatform()
106 {
107 return visaPlatform;
108 }
109
getPlatformGeneration(TARGET_PLATFORM platform)110 PlatformGen getPlatformGeneration(TARGET_PLATFORM platform)
111 {
112 if (const auto *pi = LookupPlatformInfo(platform)) {
113 return pi->family;
114 } else {
115 assert(false && "invalid platform");
116 return PlatformGen::GEN_UNKNOWN;
117 }
118 }
119
getGenxPlatformString(TARGET_PLATFORM platform)120 const char *getGenxPlatformString(TARGET_PLATFORM platform)
121 {
122 if (const auto *pi = LookupPlatformInfo(platform)) {
123 return pi->symbols[0] ? pi->symbols[0] : "???";
124 } else {
125 return "???";
126 }
127 }
128
129 // returns an array of all supported platforms
getGenxAllPlatforms(int * num)130 const TARGET_PLATFORM *getGenxAllPlatforms(int *num)
131 {
132 const static int N_PLATFORMS =
133 sizeof(ALL_PLATFORMS)/sizeof(ALL_PLATFORMS[0]);
134 static TARGET_PLATFORM s_platforms[N_PLATFORMS];
135 int i = 0;
136 for (const auto &pi : ALL_PLATFORMS) {
137 s_platforms[i++] = pi.platform;
138 }
139 *num = N_PLATFORMS;
140 return s_platforms;
141 }
142
143 // returns nullptr terminated string for a platform
getGenxPlatformStrings(TARGET_PLATFORM p)144 const char * const*getGenxPlatformStrings(TARGET_PLATFORM p)
145 {
146 if (const auto *pi = LookupPlatformInfo(p)) {
147 return pi->symbols;
148 } else {
149 assert(false && "invalid platform");
150 return nullptr;
151 }
152 }
153
getGRFSize()154 unsigned char getGRFSize()
155 {
156 unsigned int size = 32;
157
158 if (getGenxPlatform() >= GENX_PVC)
159 size = 64;
160
161 return size;
162 }
163
164 // The encoding of gen platform defined in vISA spec:
165 // 3 BDW
166 // 4 CHV
167 // 5 SKL
168 // 6 BXT
169 // 7 CNL
170 // 8 ICL
171 // 10 ICLLP
172 // 12 TGLLP
173 // 11 XeHP_SDV
174 // 13 DG2
175 // 14 PVC
176 // 15 PVC_XT
177 // Note that encoding is not linearized.
getGenxPlatformEncoding()178 int getGenxPlatformEncoding()
179 {
180 if (const auto *pi = LookupPlatformInfo(getGenxPlatform())) {
181 return pi->encoding;
182 } else {
183 assert(false && "invalid platform");
184 return -1;
185 }
186 }
187