Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parsing of OpenCL C++ -cl-std flags #328

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 36 additions & 18 deletions IGC/OCLFE/igd_fcl_mcl/source/clang_tb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,34 +771,49 @@ namespace TC

const char * optValue = optSubstring + optName.size();
const char * end = optValue + strlen(optValue);
std::string_view opt(optValue, end - optValue);

// parse
const std::string invalidFormatMessage = "Invalid format of -cl-std option, expected -cl-std=CLMAJOR.MINOR";
auto isNumeric = [](char v) { return (v >= '0') && (v <= '9'); };
if (false == ((end - optValue >= 5) && (optValue[0] == 'C') && (optValue[1] == 'L') && isNumeric(optValue[2])
&& (optValue[3] == '.') && isNumeric(optValue[4])
)
) {
exceptString = invalidFormatMessage;
return 0;
}

unsigned int retVersion = 0;
// subverions
if ((end - optValue >= 7) && (optValue[5] != ' ')) {
if ((optValue[5] == '.') || isNumeric(optValue[6])) {
retVersion += optValue[6] - '0';
if (opt.find("CLC++") == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we should define invalidFormatMessage with appropriate msg for CLC++

Suggested change
if (opt.find("CLC++") == 0) {
if (opt.find("CLC++") == 0) {
const std::string invalidFormatMessage = "Invalid format of -cl-std option, expected -cl-std=CLC++, -cl-std=CLC++1.0, or -cl-std=CLC++2021";

if (opt == "CLC++" || opt == "CLC++1.0") {
retVersion = 200;
}
else if (isNumeric(optValue[5])) {
retVersion += optValue[5] - '0';
else if (opt == "CLC++2021") {
retVersion = 300;
}
else {
const std::string invalidFormatMessage = "Invalid format of -cl-std option, expected -cl-std=CLC++, -cl-std=CLC++1.0, or -cl-std=CLC++2021";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here we need to assign invalidFormatMessage to the exceptString and return 0.

Suggested change
const std::string invalidFormatMessage = "Invalid format of -cl-std option, expected -cl-std=CLC++, -cl-std=CLC++1.0, or -cl-std=CLC++2021";
exceptString = invalidFormatMessage;
return 0;

}
}
else
{
const std::string invalidFormatMessage = "Invalid format of -cl-std option, expected -cl-std=CLMAJOR.MINOR";
auto isNumeric = [](char v) { return (v >= '0') && (v <= '9'); };
if (false == ((end - optValue >= 5) && (optValue[0] == 'C') && (optValue[1] == 'L') && isNumeric(optValue[2])
&& (optValue[3] == '.') && isNumeric(optValue[4])
)
) {
exceptString = invalidFormatMessage;
return 0;
}
}

retVersion += 100 * (optValue[2] - '0') + 10 * (optValue[4] - '0');
// subverions
if ((end - optValue >= 7) && (optValue[5] != ' ')) {
if ((optValue[5] == '.') || isNumeric(optValue[6])) {
retVersion += optValue[6] - '0';
}
else if (isNumeric(optValue[5])) {
retVersion += optValue[5] - '0';
}
else {
exceptString = invalidFormatMessage;
return 0;
}
}

retVersion += 100 * (optValue[2] - '0') + 10 * (optValue[4] - '0');
}

if (validate == false) {
return retVersion;
Expand Down Expand Up @@ -1317,6 +1332,9 @@ namespace TC
(strcmp(pParam, "-cl-std=CL2.0") == 0) ||
(strcmp(pParam, "-cl-std=CL2.1") == 0) ||
(strcmp(pParam, "-cl-std=CL3.0") == 0) ||
(strcmp(pParam, "-cl-std=CLC++") == 0) ||
(strcmp(pParam, "-cl-std=CLC++1.0") == 0) ||
(strcmp(pParam, "-cl-std=CLC++2021") == 0) ||
(strcmp(pParam, "-cl-uniform-work-group-size") == 0) || //it's work only for OCL version greater than 1.2
(strcmp(pParam, "-cl-kernel-arg-info") == 0) ||
(strncmp(pParam, "-x", 2) == 0) ||
Expand Down