@@ -74,21 +74,24 @@ namespace VLD {
74
74
using namespace TC ;
75
75
76
76
77
- // Translates SPIR-V module that consists of SPMD code that invokes ESIMD code.
77
+ // Translates ESIMD and SPMD code in the module.
78
+ // 3 cases are handled:
79
+ // 1. only SPMD code is present
80
+ // 2. only ESIMD code is present
81
+ // 3. ESIMD code is invoked from SPMD code
82
+ //
78
83
// The general flow is:
79
84
// 1. Split input SPIR-V module into SPMD and ESIMD parts
80
85
// 2. Invoke SPMD and ESIMD backends with appropriate SPIR-V modules
81
- // 3. Extract .visaasm from the output zeBinary
86
+ // 3. If SPMD code invokes ESIMD code, extract .visaasm from the each output zeBinary
82
87
// TODO: 4. Link .visaasm files via vISA interfaces
83
88
//
84
89
// The function signature corresponds to TC::TranslateBuild interface, so that
85
90
// it is easy to pass same arguments to SPMD and VC backends.
86
91
//
87
92
// Assumptions:
88
- // 1. ZEBinary output format is used.
93
+ // 1. ZEBinary output format is used in SPMD+ESIMD case .
89
94
// TODO: error out if patch token output format is used.
90
- // 2. Input is in SPIR-V format
91
- // TODO: error out if other input format is used.
92
95
bool TranslateBuildSPMDAndESIMD (const TC::STB_TranslateInputArgs *pInputArgs,
93
96
TC::STB_TranslateOutputArgs *pOutputArgs,
94
97
TC::TB_DATA_FORMAT inputDataFormatTemp,
@@ -97,19 +100,54 @@ bool TranslateBuildSPMDAndESIMD(const TC::STB_TranslateInputArgs *pInputArgs,
97
100
const ShaderHash &inputShHash,
98
101
std::string& errorMessage) {
99
102
103
+ IGC_ASSERT (inputDataFormatTemp == TB_DATA_FORMAT_SPIR_V);
104
+
100
105
// Split ESIMD and SPMD code.
101
106
auto spmd_esimd_programs_or_err = VLD::SplitSPMDAndESIMD (
102
107
pInputArgs->pInput , pInputArgs->InputSize );
103
108
104
109
if (!spmd_esimd_programs_or_err) {
105
- // Caller releases the error string, so we need to make a copy of the error message here.
106
- // TODO: pOutputArgs contains field for error string so we can copy it there.
107
- // Not done now, as it would require copy-paste code that is avaiable in dllinterfacecompute. Needs to be refactored.
108
- errorMessage = " Error while splitting ESIMD and SPMD code: " +
109
- llvm::toString (spmd_esimd_programs_or_err.takeError ());
110
- return false ;
110
+ // Workaround: try to compile on SPMD path if splitting failed.
111
+ // This is because not all VC opcodes are merged to SPIR-V Tools.
112
+ return TranslateBuildSPMD (pInputArgs, pOutputArgs, inputDataFormatTemp,
113
+ IGCPlatform, profilingTimerResolution,
114
+ inputShHash);
115
+
116
+ // TODO: uncomment once above workaround is removed.
117
+ // Caller releases the error string, so we need to make a copy of the error message here.
118
+ // TODO: pOutputArgs contains field for error string so we can copy it there.
119
+ // Not done now, as it would require copy-paste code that is avaiable in dllinterfacecompute. Needs to be refactored.
120
+ // errorMessage = llvm::toString(spmd_esimd_programs_or_err.takeError());
121
+ // return false;
111
122
}
112
123
124
+ std::string newOptions{pInputArgs->pOptions ? pInputArgs->pOptions : " " };
125
+ std::string esimdOptions{ newOptions };
126
+ esimdOptions += " -vc-codegen" ;
127
+
128
+ IGC_ASSERT (!spmd_esimd_programs_or_err->first .empty () || !spmd_esimd_programs_or_err->second .empty ());
129
+ if (spmd_esimd_programs_or_err->first .empty ()) {
130
+ #if defined(IGC_VC_ENABLED)
131
+ // Only ESIMD code detected.
132
+ STB_TranslateInputArgs newArgs = *pInputArgs;
133
+ newArgs.pOptions = esimdOptions.data ();
134
+ newArgs.OptionsSize = esimdOptions.size ();
135
+ return TranslateBuildESIMD (&newArgs, pOutputArgs, inputDataFormatTemp,
136
+ IGCPlatform, profilingTimerResolution,
137
+ inputShHash);
138
+ #else // defined(IGC_VC_ENABLED)
139
+ errorMessage = " ESIMD code detected, but VC not enabled in this build." ;
140
+ return false ;
141
+ #endif // defined(IGC_VC_ENABLED)
142
+ } else if (spmd_esimd_programs_or_err->second .empty ()) {
143
+ // Only SPMD code detected.
144
+ return TranslateBuildSPMD (pInputArgs, pOutputArgs, inputDataFormatTemp,
145
+ IGCPlatform, profilingTimerResolution,
146
+ inputShHash);
147
+ }
148
+
149
+ // SPMD+ESIMD code detected.
150
+
113
151
if (IGC_IS_FLAG_ENABLED (ShaderDumpEnable)) {
114
152
const char * pOutputFolder = IGC::Debug::GetShaderOutputFolder ();
115
153
@@ -134,27 +172,24 @@ bool TranslateBuildSPMDAndESIMD(const TC::STB_TranslateInputArgs *pInputArgs,
134
172
dump ((*spmd_esimd_programs_or_err).second , " .esimd_split.spv" );
135
173
}
136
174
137
- std::string newOptions{pInputArgs->pOptions };
138
- IGC_ASSERT (newOptions.find (VLD_compilation_enable_option) !=
139
- std::string::npos);
140
- newOptions.erase (newOptions.find (VLD_compilation_enable_option),
141
- strnlen (VLD_compilation_enable_option, sizeof (VLD_compilation_enable_option)));
142
-
143
175
auto translateToVISA =
144
176
[&](VLD::ProgramStreamType& program,
145
- const char *newOptions) -> decltype (GetVISAAsmFromZEBinary (0 ,0 )) {
177
+ const std::string& newOptions,
178
+ decltype (TranslateBuildSPMD) TranslateFunction
179
+ ) -> decltype (GetVISAAsmFromZEBinary (0 ,0 )) {
146
180
STB_TranslateInputArgs newArgs = *pInputArgs;
147
181
148
182
TC::STB_TranslateOutputArgs outputArgs;
149
183
CIF::SafeZeroOut (outputArgs);
150
184
151
185
newArgs.pInput = reinterpret_cast <char *>(program.data ());
152
186
newArgs.InputSize = program.size () * sizeof (*program.begin ());;
153
- newArgs.pOptions = newOptions;
187
+ newArgs.pOptions = newOptions.data ();
188
+ newArgs.OptionsSize = newOptions.size ();
154
189
155
190
const bool success =
156
- TranslateBuild (&newArgs, &outputArgs, inputDataFormatTemp,
157
- IGCPlatform, profilingTimerResolution);
191
+ TranslateFunction (&newArgs, &outputArgs, inputDataFormatTemp,
192
+ IGCPlatform, profilingTimerResolution, inputShHash );
158
193
159
194
auto outputData = std::unique_ptr<char []>(outputArgs.pOutput );
160
195
auto errorString = std::unique_ptr<char []>(outputArgs.pErrorString );
@@ -170,20 +205,22 @@ bool TranslateBuildSPMDAndESIMD(const TC::STB_TranslateInputArgs *pInputArgs,
170
205
return spmdVISAAsmVector;
171
206
};
172
207
173
- std::string esimdOptions{ newOptions };
174
- esimdOptions += " -vc-codegen" ;
175
-
208
+ #if defined(IGC_VC_ENABLED)
176
209
auto esimdVISA =
177
- translateToVISA (spmd_esimd_programs_or_err->second , esimdOptions. data () );
210
+ translateToVISA (spmd_esimd_programs_or_err->second , esimdOptions, TranslateBuildESIMD );
178
211
179
212
if (!esimdVISA) {
180
213
errorMessage = " VLD: Failed to compile ESIMD part with following error: \n " +
181
214
llvm::toString (esimdVISA.takeError ());
182
215
return false ;
183
216
}
217
+ #else // defined(IGC_VC_ENABLED)
218
+ errorMessage = " Could not compile ESIMD part of SPIR-V module, as VC is not included in this build." ;
219
+ return false ;
220
+ #endif // defined(IGC_VC_ENABLED)
184
221
185
222
auto spmdVISA =
186
- translateToVISA (spmd_esimd_programs_or_err->first , newOptions.data ());
223
+ translateToVISA (spmd_esimd_programs_or_err->first , newOptions.data (), TranslateBuildSPMD );
187
224
188
225
if (!spmdVISA) {
189
226
errorMessage = " VLD: Failed to compile SPMD part with following error: \n " +
0 commit comments