Skip to content

Commit 94a5f93

Browse files
aus-intelsys_zuul
authored andcommitted
Rewrite CM adaptor library
Change library to header-only. Add wrapper class for interaction with raw dll calls. Move most of checks to new wrapper. Change-Id: I9f129474f4dcd7b75faaefa61a9b44ebe81d8223
1 parent 7d11ff4 commit 94a5f93

File tree

4 files changed

+222
-221
lines changed

4 files changed

+222
-221
lines changed

IGC/AdaptorOCL/ocl_igc_interface/impl/fcl_ocl_translation_ctx_impl.cpp

Lines changed: 54 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -126,60 +126,29 @@ std::vector<char> makeVcOptPayload(uint64_t IR_size,
126126
return VcPayload;
127127
}
128128

129-
void runFeInvocation(const InvocationInfo& Invocation,
130-
OclTranslationOutputBase& output) {
131-
132-
auto& outputInterface = *output.GetImpl();
133-
std::ifstream InputFile(Invocation.getInputFilename());
134-
if (!InputFile.is_open()) {
135-
outputInterface.SetError(TranslationErrorType::Internal,
136-
"CM frontend: could not read input file");
137-
return;
138-
}
139-
140-
std::string InputText{std::istreambuf_iterator<char>(InputFile),
141-
std::istreambuf_iterator<char>()};
142-
143-
if (Invocation.getOutputType() != InvocationInfo::OutputTypeT::SPIRV) {
144-
outputInterface.SetError(TranslationErrorType::Internal,
145-
"CM frontend: unsupported output request");
146-
return;
147-
}
148-
149-
IGC::AdaptorCM::Frontend::InputArgs InputArgs;
150-
InputArgs.InputText = InputText;
151-
InputArgs.CompilationOpts = Invocation.getFEArgs();
152-
153-
using FEOutput = IGC::AdaptorCM::Frontend::IOutputArgs;
154-
auto FeDeleter = [](FEOutput* out) { out->discard(); };
155-
std::unique_ptr<FEOutput, decltype(FeDeleter)> Res(
156-
IGC::AdaptorCM::Frontend::translate(InputArgs),
157-
FeDeleter);
158-
159-
if (!Res) {
160-
outputInterface.SetError(TranslationErrorType::Internal,
161-
"CM frontend null result errror");
162-
return;
163-
}
164-
165-
const auto& ErrLog = Res->getLog();
166-
167-
if (Res->getStatus() ==
168-
Intel::CM::ClangFE::IOutputArgs::ErrT::COMPILE_PROGRAM_FAILURE) {
169-
129+
void finalizeFEOutput(const IGC::AdaptorCM::Frontend::IOutputArgs& FEOutput,
130+
const InvocationInfo& Invocation,
131+
OclTranslationOutputBase& Output)
132+
{
133+
auto& OutputInterface = *Output.GetImpl();
134+
const auto& ErrLog = FEOutput.getLog();
135+
if (FEOutput.getStatus() ==
136+
Intel::CM::ClangFE::IOutputArgs::ErrT::COMPILE_PROGRAM_FAILURE)
137+
{
170138
if (ErrLog.empty())
171-
outputInterface.SetError(TranslationErrorType::Internal,
172-
"unknown error during cm source compilation");
139+
OutputInterface.SetError(
140+
TranslationErrorType::Internal,
141+
"unknown error during cm source compilation");
173142
else
174-
outputInterface.SetError(TranslationErrorType::UnhandledInput,
143+
OutputInterface.SetError(TranslationErrorType::UnhandledInput,
175144
ErrLog.c_str());
176145
return;
177146
}
178147

179148
if (!ErrLog.empty())
180-
outputInterface.AddWarning(ErrLog);
149+
OutputInterface.AddWarning(ErrLog);
181150

182-
const auto& IR = Res->getIR();
151+
const auto& IR = FEOutput.getIR();
183152
// This is where the tricky part starts
184153
// Right now we have no way to pass auxiliary options to vc-codegen backend
185154
// So we introduce a temporary hack to incorporate the options
@@ -195,9 +164,10 @@ void runFeInvocation(const InvocationInfo& Invocation,
195164
FinalOutput.insert(FinalOutput.end(), IR.begin(), IR.end());
196165
FinalOutput.insert(FinalOutput.end(), Payload.begin(), Payload.end());
197166

198-
if (!outputInterface.SetSuccessfulAndCloneOutput(FinalOutput.data(),
199-
FinalOutput.size())) {
200-
outputInterface.SetError(TranslationErrorType::Internal, "OOM (cm FE)");
167+
if (!OutputInterface.SetSuccessfulAndCloneOutput(FinalOutput.data(),
168+
FinalOutput.size()))
169+
{
170+
OutputInterface.SetError(TranslationErrorType::Internal, "OOM (cm FE)");
201171
return;
202172
}
203173
}
@@ -326,9 +296,9 @@ OclTranslationOutputBase* CIF_PIMPL(FclOclTranslationCtx)::TranslateCM(
326296
uint32_t tracingOptionsCount) {
327297

328298
// Output
329-
auto outputInterface = CIF::RAII::UPtr(
330-
CIF::InterfaceCreator<OclTranslationOutput>::CreateInterfaceVer(outVersion,
331-
outType));
299+
auto* outputInterface =
300+
CIF::InterfaceCreator<OclTranslationOutput>::CreateInterfaceVer(
301+
outVersion, outType);
332302
if (outputInterface == nullptr)
333303
return nullptr;
334304

@@ -343,44 +313,54 @@ OclTranslationOutputBase* CIF_PIMPL(FclOclTranslationCtx)::TranslateCM(
343313
(void)product;
344314
(void)stepping;
345315

346-
OclTranslationOutputBase& Out = *outputInterface.get();
316+
OclTranslationOutputBase& Out = *outputInterface;
347317

348318
#if !defined(WDDM_LINUX) && (!defined(IGC_VC_DISABLED) || !IGC_VC_DISABLED)
349-
IGC::AdaptorCM::Frontend::AbiCompatibilityInfo AbiInfo;
350-
if (!IGC::AdaptorCM::Frontend::validateABICompatibility(&AbiInfo)) {
351-
const auto &ErrMsg =
352-
llvm::StringRef("AdaptorCM: incompatible clangFEWrapper interface: ") +
353-
"expected = " + llvm::Twine(AbiInfo.RequestedVersion) +
354-
", loaded = " + llvm::Twine(AbiInfo.AvailableVersion);
355-
Out.GetImpl()->SetError(TranslationErrorType::Internal,
356-
ErrMsg.str().c_str());
357-
return outputInterface.release();
358-
}
319+
auto ErrFn = [&Out](const std::string& Err) {
320+
Out.GetImpl()->SetError(TranslationErrorType::Internal, Err.c_str());
321+
};
322+
auto MaybeFE = IGC::AdaptorCM::Frontend::makeFEWrapper(ErrFn);
323+
if (!MaybeFE)
324+
return outputInterface;
359325

360326
auto OptSrc = MakeTemporaryCMSource(src, Out);
361327
if (!OptSrc)
362-
return outputInterface.release(); // proper error message is already set
328+
return outputInterface; // proper error message is already set
363329

364330
llvm::BumpPtrAllocator A;
365331
llvm::StringSaver Saver(A);
366332
auto FeArgs = processFeOptions(OptSrc.getValue(), options, Saver);
367333

368-
using IGC::AdaptorCM::Frontend::getDriverInvocation;
334+
auto& FE = MaybeFE.getValue();
335+
auto Drv = FE.buildDriverInvocation(FeArgs);
336+
if (!Drv)
337+
{
338+
ErrFn("Null driver invocation in CMFE");
339+
return outputInterface;
340+
}
341+
if (Drv->getOutputType() != InvocationInfo::OutputTypeT::SPIRV)
342+
{
343+
ErrFn("CM frontend: unsupported output request");
344+
return outputInterface;
345+
}
346+
347+
IGC::AdaptorCM::Frontend::InputArgs InputArgs;
348+
InputArgs.CompilationOpts = Drv->getFEArgs();
349+
auto FEOutput = FE.translate(InputArgs);
350+
if (!FEOutput)
351+
{
352+
ErrFn("Null output in CMFE");
353+
return outputInterface;
354+
}
355+
356+
finalizeFEOutput(*FEOutput, *Drv, Out);
369357

370-
auto Deleter = [](InvocationInfo* p) { delete p; };
371-
using InvokeInfo = std::unique_ptr<InvocationInfo, decltype(Deleter)>;
372-
InvokeInfo invoker(getDriverInvocation(FeArgs.size(), FeArgs.data()), Deleter);
373-
if (invoker)
374-
runFeInvocation(*invoker, Out);
375-
else
376-
Out.GetImpl()->SetError(TranslationErrorType::Internal,
377-
"could not create CM fronend invocation");
378358
#else
379359
Out.GetImpl()->SetError(TranslationErrorType::Internal,
380360
"CM compilation is not supported in this configuration");
381361
#endif // !defined(WDDM_LINUX) && (!defined(IGC_VC_DISABLED) || !IGC_VC_DISABLED)
382362

383-
return outputInterface.release();
363+
return outputInterface;
384364
}
385365

386366
}

IGC/CMFE/AdaptorCM/CMakeLists.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ if(LLVM_ON_WIN32)
1717
add_compile_options(/wd4624)
1818
endif()
1919

20-
add_library(AdaptorCM STATIC
21-
Frontend.cpp
22-
)
20+
add_library(AdaptorCM INTERFACE)
2321

2422
vc_get_llvm_targets(LLVM_LIBS
2523
LLVMSupport
@@ -28,11 +26,12 @@ vc_get_llvm_targets(LLVM_LIBS
2826
message(STATUS "Linking CMFE with ${LLVM_LIBS}")
2927

3028
target_link_libraries(AdaptorCM
29+
INTERFACE
3130
${LLVM_LIBS}
3231
)
3332

34-
target_compile_definitions(AdaptorCM PRIVATE
33+
target_compile_definitions(AdaptorCM INTERFACE
3534
-DCMFE_WRAPPER_NAME=\"${INSTALL_CMFE_NAME}\")
3635

3736

38-
target_include_directories(AdaptorCM PUBLIC "$<BUILD_INTERFACE:${ADAPTOR_CM_INCLUDE_DIRS}>")
37+
target_include_directories(AdaptorCM INTERFACE "$<BUILD_INTERFACE:${ADAPTOR_CM_INCLUDE_DIRS}>")

IGC/CMFE/AdaptorCM/Frontend.cpp

Lines changed: 0 additions & 135 deletions
This file was deleted.

0 commit comments

Comments
 (0)