Skip to content

Commit 835e550

Browse files
aparshin-inteligcbot
authored andcommitted
fcl options string *must* start with "-cmc" to invoke CM frontend
1 parent 0879fa6 commit 835e550

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

IGC/AdaptorOCL/ocl_igc_interface/impl/fcl_ocl_translation_ctx_impl.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,15 @@ static std::vector<const char*>
292292
else
293293
llvm::cl::TokenizeGNUCommandLine(userArgsStr, stringSaver, userArgs);
294294

295-
auto toErase = std::remove_if(userArgs.begin(), userArgs.end(),
296-
[](const auto& Item) { return std::strcmp(Item, "-cmc") == 0; });
297-
userArgs.erase(toErase, userArgs.end());
295+
if (std::getenv(UseLegacyCMCPrefixEnv)) {
296+
// TODO: remove this branch once all clients fixed their tests
297+
auto toErase = std::remove_if(userArgs.begin(), userArgs.end(),
298+
[](const auto& Item) { return std::strcmp(Item, "-cmc") == 0; });
299+
userArgs.erase(toErase, userArgs.end());
300+
} else {
301+
IGC_ASSERT(!userArgs.empty() && strcmp(userArgs[0], "-cmc") == 0);
302+
userArgs.erase(userArgs.begin());
303+
}
298304

299305
// this was old hack before FE can pass platform, now we prefer to use argument
300306
// but if it is null, it may be still useful, so let it be for a while

IGC/AdaptorOCL/ocl_igc_interface/impl/fcl_ocl_translation_ctx_impl.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ IN THE SOFTWARE.
2929
#include <map>
3030
#include <memory>
3131
#include <mutex>
32+
#include <regex>
3233
#include <utility>
34+
#include <cstdlib>
3335

3436
#include "cif/builtins/memory/buffer/impl/buffer_impl.h"
3537
#include "cif/export/pimpl_base.h"
@@ -49,6 +51,8 @@ namespace TC{
4951

5052
namespace IGC {
5153

54+
static constexpr const char* UseLegacyCMCPrefixEnv = "IGC_USE_LEGACY_CMC_PREFIX";
55+
5256
CIF_DECLARE_INTERFACE_PIMPL(FclOclTranslationCtx) : CIF::PimplBase
5357
{
5458
CIF_PIMPL_DECLARE_CONSTRUCTOR(CIF::Version_t version, CIF_PIMPL(FclOclDeviceCtx) *globalState,
@@ -109,7 +113,19 @@ CIF_DECLARE_INTERFACE_PIMPL(FclOclTranslationCtx) : CIF::PimplBase
109113
CIF::Builtins::BufferSimple *tracingOptions,
110114
uint32_t tracingOptionsCount
111115
) {
112-
if ((options != nullptr) && (options->GetSizeRaw() > 0) && (strstr(options->GetMemory<char>(), "-cmc"))) {
116+
auto needsCMFE = [](const char *optStart, size_t size) {
117+
if (!optStart)
118+
return false;
119+
120+
// TODO: remove this once all clients fixed their tests
121+
if (std::getenv(UseLegacyCMCPrefixEnv)) {
122+
return strstr(optStart, "-cmc") != nullptr;
123+
}
124+
// "-cmc" should be present as the first argument to invoke CM frontend
125+
return std::regex_match(optStart, optStart + size,
126+
std::regex("^\\s*-cmc(($)|(\\s+.*))"));
127+
};
128+
if (options != nullptr && needsCMFE(options->GetMemory<char>(), options->GetSizeRaw())) {
113129
assert(this->outType == CodeType::spirV);
114130
return TranslateCM(outVersion, src, options, internalOptions, tracingOptions, tracingOptionsCount);
115131
}

0 commit comments

Comments
 (0)