Skip to content

Commit 484e05a

Browse files
aparshin-inteligcbot
authored andcommitted
implement proper error reporting for the case when VC platform selector could not determine target platform
1 parent f3d682f commit 484e05a

File tree

7 files changed

+120
-37
lines changed

7 files changed

+120
-37
lines changed

IGC/AdaptorOCL/ocl_igc_interface/impl/fcl_ocl_translation_ctx_impl.cpp

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ static std::vector<const char*>
179179
const std::string& inputFile,
180180
CIF::Builtins::BufferSimple* options,
181181
llvm::StringSaver& stringSaver,
182-
const char *platform,
182+
const std::string& platform,
183183
unsigned stepping) {
184184

185185
llvm::SmallVector<const char*, 20> userArgs;
@@ -216,11 +216,12 @@ static std::vector<const char*>
216216
return S.startswith("-march=") || S.startswith("-mcpu=");
217217
});
218218
if (!CmArchPresent) {
219-
// Pass the runtime-specified architecture if user hasn't specified one
220-
if (platform)
221-
result.push_back(stringSaver.save("-march=" + std::string(platform)).data());
222-
else
219+
// Prefer user-specified architecture. If none specified -
220+
// pass the runtime-selected architecture.
221+
if (platform.empty())
223222
result.push_back(stringSaver.save("-march=" + cmfeDefaultArch).data());
223+
else
224+
result.push_back(stringSaver.save("-march=" + platform).data());
224225
}
225226

226227
result.insert(result.end(), userArgs.begin(), userArgs.end());
@@ -303,15 +304,15 @@ static std::string getCMFEWrapperDir() {
303304
#endif
304305
}
305306

306-
#endif // defined(IGC_VC_ENABLED)
307-
308307
// This essentialy duplicates existing DumpShaderFile in dllInterfaceCompute
309308
// but now I see no way to reuse it. To be converged later
310-
static void DumpInputs(PLATFORM *Platform, const char *Selected,
309+
static void DumpInputs(const PLATFORM *Platform,
310+
const std::string& SelectedPlatform,
311311
int Stepping, CIF::Builtins::BufferSimple* src,
312312
CIF::Builtins::BufferSimple* options,
313313
CIF::Builtins::BufferSimple* internalOptions,
314-
CIF::Builtins::BufferSimple* tracingOptions) {
314+
CIF::Builtins::BufferSimple* tracingOptions)
315+
{
315316
#if defined( _DEBUG ) || defined( _INTERNAL )
316317
// check for shader dumps enabled
317318
if (!FCL_IGC_IS_FLAG_ENABLED(ShaderDumpEnable))
@@ -335,7 +336,7 @@ static void DumpInputs(PLATFORM *Platform, const char *Selected,
335336
Os << "NEO passed: DisplayCore = " << Core
336337
<< ", RenderCore = " << RenderCore << ", Product = " << Product
337338
<< ", Revision = " << RevId << "\n";
338-
Os << "IGC translated into: " << Selected << ", " << Stepping << "\n";
339+
Os << "IGC translated into: <" << SelectedPlatform << ">, " << Stepping << "\n";
339340
} else {
340341
Os << "Nothing came from NEO\n";
341342
}
@@ -378,6 +379,40 @@ static void DumpInputs(PLATFORM *Platform, const char *Selected,
378379
#endif // defined( _DEBUG ) || defined( _INTERNAL )
379380
}
380381

382+
struct CMFEPlatform {
383+
std::string PlatformStr;
384+
unsigned Stepping;
385+
};
386+
387+
template <typename T>
388+
static llvm::Optional<CMFEPlatform> describeCMFEPlatform(
389+
const T *platformImpl,
390+
CIF::Builtins::BufferSimple* src,
391+
CIF::Builtins::BufferSimple* options,
392+
CIF::Builtins::BufferSimple* internalOptions,
393+
CIF::Builtins::BufferSimple* tracingOptions)
394+
{
395+
bool Error = false;
396+
const PLATFORM *platformDescr = nullptr;
397+
unsigned stepping = 0;
398+
std::string platformStr;
399+
400+
if (platformImpl)
401+
{
402+
platformDescr = &platformImpl->p;
403+
stepping = platformDescr->usRevId;
404+
platformStr = cmc::getPlatformStr(*platformDescr, /* inout */ stepping);
405+
Error = platformStr.empty();
406+
}
407+
DumpInputs(platformDescr, platformStr, stepping,
408+
src, options, internalOptions, tracingOptions);
409+
410+
if (Error)
411+
return {};
412+
return CMFEPlatform { platformStr, stepping };
413+
}
414+
#endif // defined(IGC_VC_ENABLED)
415+
381416
OclTranslationOutputBase* CIF_PIMPL(FclOclTranslationCtx)::TranslateCM(
382417
CIF::Version_t outVersion,
383418
CIF::Builtins::BufferSimple* src,
@@ -393,27 +428,22 @@ OclTranslationOutputBase* CIF_PIMPL(FclOclTranslationCtx)::TranslateCM(
393428
if (outputInterface == nullptr)
394429
return nullptr;
395430

396-
PLATFORM *platformDescr = nullptr;
397-
const char *platformStr = nullptr;
398-
unsigned stepping = 0U;
399-
400-
if(globalState.GetPlatformImpl()){
401-
// NEO supports platform interface
402-
auto *PlatformImpl = globalState.GetPlatformImpl();
403-
platformDescr = &PlatformImpl->p;
404-
stepping = PlatformImpl->p.usRevId;
405-
platformStr = cmc::getPlatformStr(PlatformImpl->p, /* inout */ stepping);
406-
}
407-
408-
DumpInputs(platformDescr, platformStr, stepping,
409-
src, options, internalOptions, tracingOptions);
410-
411431
OclTranslationOutputBase& Out = *outputInterface;
412432

413433
#if defined(IGC_VC_ENABLED)
414434
auto ErrFn = [&Out](const std::string& Err) {
415435
Out.GetImpl()->SetError(TranslationErrorType::Internal, Err.c_str());
416436
};
437+
438+
auto MaybePlatform = describeCMFEPlatform(globalState.GetPlatformImpl(),
439+
src, options, internalOptions,
440+
tracingOptions);
441+
if (!MaybePlatform)
442+
{
443+
ErrFn("could not derive platform string and stepping");
444+
return outputInterface;
445+
}
446+
417447
auto MaybeFE =
418448
IGC::AdaptorCM::Frontend::makeFEWrapper(ErrFn, getCMFEWrapperDir());
419449
if (!MaybeFE)
@@ -426,8 +456,8 @@ OclTranslationOutputBase* CIF_PIMPL(FclOclTranslationCtx)::TranslateCM(
426456
llvm::BumpPtrAllocator A;
427457
llvm::StringSaver Saver(A);
428458
auto& FE = MaybeFE.getValue();
429-
auto FeArgs = processFeOptions(FE.LibInfo(), OptSrc.getValue(),
430-
options, Saver, platformStr, stepping);
459+
auto FeArgs = processFeOptions(FE.LibInfo(), OptSrc.getValue(), options, Saver,
460+
MaybePlatform->PlatformStr, MaybePlatform->Stepping);
431461

432462
auto Drv = FE.buildDriverInvocation(FeArgs.size(), FeArgs.data());
433463
if (!Drv)

IGC/VectorCompiler/igcdeps/src/TranslationInterface.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,16 @@ class BuildDiag {
5050
void addWarning(const std::string &Str) {
5151
BuildLog << "warning: " << Str << "\n";
5252
}
53+
void addError(const std::string &Str) {
54+
BuildLog << "error: " << Str << "\n";
55+
HasError = true;
56+
}
5357
std::string getLog() const { return BuildLog.str(); }
58+
bool hasError() const { return HasError; }
5459

5560
private:
56-
// for now, we don't differentiate between warnings and errors
57-
// the expectation is that a marker indicating an error shall be
58-
// reported by other means
5961
std::ostringstream BuildLog;
62+
bool HasError = false;
6063
};
6164

6265
} // namespace
@@ -128,12 +131,14 @@ std::unique_ptr<llvm::MemoryBuffer> getVCModuleBuffer() {
128131
}
129132

130133
static void adjustPlatform(const IGC::CPlatform &IGCPlatform,
131-
vc::CompileOptions &Opts) {
134+
vc::CompileOptions &Opts, BuildDiag &Diag) {
132135
auto &PlatformInfo = IGCPlatform.getPlatformInfo();
133136
unsigned RevId = PlatformInfo.usRevId;
134137
Opts.CPUStr = cmc::getPlatformStr(PlatformInfo, /* inout */ RevId);
135138
Opts.RevId = RevId;
136139
Opts.WATable = &IGCPlatform.getWATable();
140+
if (Opts.CPUStr.empty())
141+
Diag.addError("could not determine target Platform");
137142
}
138143

139144
static void adjustFileType(TC::TB_DATA_FORMAT DataFormat,
@@ -205,7 +210,7 @@ static void adjustDumpOptions(vc::CompileOptions &Opts) {
205210
static void adjustOptions(const IGC::CPlatform &IGCPlatform,
206211
TC::TB_DATA_FORMAT DataFormat,
207212
vc::CompileOptions &Opts, BuildDiag &Diag) {
208-
adjustPlatform(IGCPlatform, Opts);
213+
adjustPlatform(IGCPlatform, Opts, Diag);
209214
adjustFileType(DataFormat, Opts);
210215
adjustOptLevel(Opts);
211216
adjustBinaryFormat(Opts.Binary);
@@ -425,8 +430,15 @@ std::error_code vc::translateBuild(const TC::STB_TranslateInputArgs *InputArgs,
425430

426431
// here we have Opts set and can dump what we got from runtime and how
427432
// we understood it
433+
// we intentionally query Diag object after Platform dumps
428434
dumpPlatform(Opts, IGCPlatform.getPlatformInfo(), *Dumper);
429435

436+
// Note: we intentionally query Diag object after Platform dumps
437+
if (Diag.hasError())
438+
return getError(
439+
llvm::make_error<vc::CompilationAbortedError>(Diag.getLog()),
440+
OutputArgs);
441+
430442
if (IGC_IS_FLAG_ENABLED(ShaderOverride))
431443
Opts.ShaderOverrider =
432444
vc::createVC_IGCShaderOverrider(Hash, IGCPlatform.getPlatformInfo());

IGC/VectorCompiler/include/vc/Support/Status.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,23 @@ class OptionError final : public llvm::ErrorInfo<OptionError> {
135135
}
136136
};
137137

138+
class CompilationAbortedError final
139+
: public llvm::ErrorInfo<CompilationAbortedError> {
140+
public:
141+
static char ID;
142+
143+
private:
144+
std::string Message;
145+
146+
public:
147+
CompilationAbortedError(llvm::StringRef Msg) : Message(Msg.str()) {}
148+
149+
void log(llvm::raw_ostream &OS) const override;
150+
std::error_code convertToErrorCode() const override {
151+
return make_error_code(errc::compilation_aborted);
152+
}
153+
};
154+
138155
} // namespace vc
139156

140157
#endif

IGC/VectorCompiler/include/vc/Support/StatusCode.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ enum class errc {
4141
// Bad option in internal options.
4242
invalid_internal_option,
4343

44-
// loading OCL BiF module failed
44+
// Loading of OCL BiF module failed.
4545
bif_load_fail,
46+
47+
// Compilation was aborted.
48+
compilation_aborted
4649
};
4750

4851
const std::error_category &err_category() noexcept;

IGC/VectorCompiler/include/vc/Support/StatusTraits.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ template <> struct ErrorTraits<errc::bif_load_fail> {
6868
}
6969
};
7070

71+
template <> struct ErrorTraits<errc::compilation_aborted> {
72+
static llvm::StringRef getMessage() { return "compilation aborted"; }
73+
};
74+
7175
} // namespace vc
7276

7377
#endif

IGC/VectorCompiler/lib/Support/Status.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ std::string vc_error_category::message(int condition) const {
4949
return std::string(ErrorTraits<errc::invalid_internal_option>::getMessage());
5050
case errc::bif_load_fail:
5151
return std::string(ErrorTraits<errc::bif_load_fail>::getMessage());
52+
case errc::compilation_aborted:
53+
return std::string(ErrorTraits<errc::compilation_aborted>::getMessage());
5254
}
5355
IGC_ASSERT_EXIT_MESSAGE(0, "Unknown error code");
5456
}
@@ -128,4 +130,12 @@ void OptionError::log(llvm::raw_ostream &OS) const {
128130
}
129131
// }}
130132

133+
// CompilationAbortedError {{
134+
char CompilationAbortedError::ID = 0;
135+
136+
void CompilationAbortedError::log(llvm::raw_ostream &OS) const {
137+
OS << ErrorTraits<errc::compilation_aborted>::getMessage() << ": " << Message;
138+
}
139+
// }}
140+
131141
} // namespace vc

IGC/common/VCPlatformSelector.hpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@ SPDX-License-Identifier: MIT
2121

2222
namespace cmc {
2323

24-
inline const char *getPlatformStr(PLATFORM Platform, unsigned &RevId) {
24+
// getPlatformStr:
25+
// given a PLATFORM data structure and "revision ID" returns
26+
// "Platform String" - the string identifier for the targeted platform.
27+
// Note: the interpretation of RevId ("revision ID") depends on the target
28+
// platform. RevID is considered an input/output parameter and may be
29+
// changed during the invocation.
30+
// If the target platform can not be derived - an empty string is returned,
31+
// in this case the client code is expected to report an error.
32+
inline std::string getPlatformStr(const PLATFORM &Platform, unsigned &RevId) {
2533
// after some consultations with Wndows KMD folks,
2634
// only render core shall be used in all cases
2735
auto Core = Platform.eRenderCoreFamily;
@@ -44,10 +52,9 @@ inline const char *getPlatformStr(PLATFORM Platform, unsigned &RevId) {
4452
if (Product == IGFX_DG1)
4553
return "DG1";
4654
default:
47-
IGC_ASSERT_MESSAGE(0, "unsupported platform");
48-
break;
55+
// Return an empty platform string to indicate an error.
56+
return "";
4957
}
50-
return IGC_MANGLE("SKL");
5158
}
5259

5360
} // namespace cmc

0 commit comments

Comments
 (0)