Skip to content

Commit 5a5ad64

Browse files
Ocloc compile: support gen families exposed in help
fix typo in method name Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
1 parent 85a18d4 commit 5a5ad64

File tree

5 files changed

+79
-18
lines changed

5 files changed

+79
-18
lines changed

opencl/test/unit_test/offline_compiler/ocloc_api_tests.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020 Intel Corporation
2+
* Copyright (C) 2020-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -12,6 +12,7 @@
1212

1313
#include "environment.h"
1414
#include "gtest/gtest.h"
15+
#include "hw_cmds.h"
1516

1617
#include <string>
1718

@@ -43,6 +44,26 @@ TEST(OclocApiTests, WhenGoodArgsAreGivenThenSuccessIsReturned) {
4344
EXPECT_EQ(std::string::npos, output.find("Command was: ocloc -file test_files/copybuffer.cl -device "s + argv[4]));
4445
}
4546

47+
TEST(OclocApiTests, WhenGoodFamilyNameIsProvidedThenSuccessIsReturned) {
48+
const char *argv[] = {
49+
"ocloc",
50+
"-file",
51+
"test_files/copybuffer.cl",
52+
"-device",
53+
NEO::familyName[NEO::DEFAULT_PLATFORM::hwInfo.platform.eRenderCoreFamily]};
54+
unsigned int argc = sizeof(argv) / sizeof(const char *);
55+
56+
testing::internal::CaptureStdout();
57+
int retVal = oclocInvoke(argc, argv,
58+
0, nullptr, nullptr, nullptr,
59+
0, nullptr, nullptr, nullptr,
60+
nullptr, nullptr, nullptr, nullptr);
61+
std::string output = testing::internal::GetCapturedStdout();
62+
63+
EXPECT_EQ(retVal, NEO::SUCCESS);
64+
EXPECT_EQ(std::string::npos, output.find("Command was: ocloc -file test_files/copybuffer.cl -device "s + argv[4]));
65+
}
66+
4667
TEST(OclocApiTests, WhenArgsWithMissingFileAreGivenThenErrorMessageIsProduced) {
4768
const char *argv[] = {
4869
"ocloc",

shared/offline_compiler/source/ocloc_fatbinary.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020 Intel Corporation
2+
* Copyright (C) 2020-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -29,7 +29,7 @@ bool requestedFatBinary(const std::vector<std::string> &args) {
2929
const bool hasMoreArgs = (argIndex + 1 < args.size());
3030
if ((ConstStringRef("-device") == currArg) && hasMoreArgs) {
3131
ConstStringRef deviceArg(args[argIndex + 1]);
32-
return deviceArg.contains("*") || deviceArg.contains("-") || deviceArg.contains(",") || deviceArg.contains("gen");
32+
return deviceArg.contains("*") || deviceArg.contains("-") || deviceArg.contains(",") || deviceArg.containsCaseInsensitive("gen");
3333
}
3434
}
3535
return false;
@@ -112,7 +112,7 @@ std::vector<ConstStringRef> getTargetPlatformsForFatbinary(ConstStringRef device
112112

113113
if (range.size() == 1) {
114114
// open range , from-max or min-to
115-
if (range[0].contains("gen")) {
115+
if (range[0].containsCaseInsensitive("gen")) {
116116
auto coreIdList = asGfxCoreIdList(range[0]);
117117
if (coreIdList.empty()) {
118118
argHelper->printf("Unknown device : %s\n", set.str().c_str());
@@ -197,7 +197,7 @@ std::vector<ConstStringRef> getTargetPlatformsForFatbinary(ConstStringRef device
197197
requestedPlatforms.insert(requestedPlatforms.end(), from, to);
198198
}
199199
}
200-
} else if (set.contains("gen")) {
200+
} else if (set.containsCaseInsensitive("gen")) {
201201
if (set.size() == genArg.size()) {
202202
argHelper->printf("Invalid gen-based device : %s - gen should be followed by a number\n", set.str().c_str());
203203
} else {

shared/source/device_binary_format/yaml/yaml_parser.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020 Intel Corporation
2+
* Copyright (C) 2020-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -595,7 +595,7 @@ inline bool YamlParser::readValueChecked<bool>(const Node &node, bool &outValue)
595595
case 1:
596596
return true;
597597
case 3:
598-
return equalsCaseInsesitive(ConstStringRef("es"), ConstStringRef(token.cstrref().begin() + 1, 2));
598+
return equalsCaseInsensitive(ConstStringRef("es"), ConstStringRef(token.cstrref().begin() + 1, 2));
599599
}
600600
break;
601601
}
@@ -618,15 +618,15 @@ inline bool YamlParser::readValueChecked<bool>(const Node &node, bool &outValue)
618618
if (token.len != 4) {
619619
return false;
620620
}
621-
return equalsCaseInsesitive(ConstStringRef("rue"), ConstStringRef(token.cstrref().begin() + 1, 3));
621+
return equalsCaseInsensitive(ConstStringRef("rue"), ConstStringRef(token.cstrref().begin() + 1, 3));
622622
}
623623
case 'f':
624624
case 'F': {
625625
outValue = false;
626626
if (token.len != 5) {
627627
return false;
628628
}
629-
return equalsCaseInsesitive(ConstStringRef("alse"), ConstStringRef(token.cstrref().begin() + 1, 4));
629+
return equalsCaseInsensitive(ConstStringRef("alse"), ConstStringRef(token.cstrref().begin() + 1, 4));
630630
}
631631
case 'o':
632632
case 'O': {
@@ -638,7 +638,7 @@ inline bool YamlParser::readValueChecked<bool>(const Node &node, bool &outValue)
638638
return ((token.cstrref()[1] == 'n') | (token.cstrref()[1] == 'N'));
639639
case 3:
640640
outValue = false;
641-
return equalsCaseInsesitive(ConstStringRef("ff"), ConstStringRef(token.cstrref().begin() + 1, 2));
641+
return equalsCaseInsensitive(ConstStringRef("ff"), ConstStringRef(token.cstrref().begin() + 1, 2));
642642
}
643643
break;
644644
}

shared/source/utilities/const_stringref.h

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2020 Intel Corporation
2+
* Copyright (C) 2019-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -137,6 +137,24 @@ class ConstStringRef {
137137
return false;
138138
}
139139

140+
constexpr bool containsCaseInsensitive(const char *subString) const noexcept {
141+
const char *findBeg = ptr;
142+
const char *findEnd = ptr + len;
143+
while (findBeg != findEnd) {
144+
const char *lhs = findBeg;
145+
const char *rhs = subString;
146+
while ((lhs < findEnd) && (std::tolower(*lhs) == std::tolower(*rhs)) && ('\0' != *rhs)) {
147+
++lhs;
148+
++rhs;
149+
}
150+
if ('\0' == *rhs) {
151+
return true;
152+
}
153+
++findBeg;
154+
}
155+
return false;
156+
}
157+
140158
constexpr bool startsWith(const char *subString) const noexcept {
141159
const char *findEnd = ptr + len;
142160
const char *lhs = ptr;
@@ -207,7 +225,7 @@ constexpr bool operator!=(const char *lhs, const ConstStringRef &rhs) {
207225
return false == equals(rhs, lhs);
208226
}
209227

210-
constexpr bool equalsCaseInsesitive(const ConstStringRef &lhs, const ConstStringRef &rhs) {
228+
constexpr bool equalsCaseInsensitive(const ConstStringRef &lhs, const ConstStringRef &rhs) {
211229
if (lhs.size() != rhs.size()) {
212230
return false;
213231
}
@@ -223,4 +241,4 @@ constexpr bool equalsCaseInsesitive(const ConstStringRef &lhs, const ConstString
223241
return true;
224242
}
225243

226-
} // namespace NEO
244+
} // namespace NEO

shared/test/unit_test/utilities/const_stringref_tests.cpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2020 Intel Corporation
2+
* Copyright (C) 2017-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -115,6 +115,28 @@ TEST(ConstStringRef, WhenCopyAsignedThenIdenticalAsOrigin) {
115115
EXPECT_EQ(a, b);
116116
}
117117

118+
TEST(ConstStringRef, WhenCheckingForInclusionCaseInsensitivelyThenDoesNotReadOutOfBounds) {
119+
static constexpr ConstStringRef str1("Text", 2);
120+
ConstStringRef substr1("tex");
121+
EXPECT_FALSE(str1.containsCaseInsensitive(substr1.data()));
122+
123+
static constexpr ConstStringRef str2("AabAac");
124+
ConstStringRef substr2("aac");
125+
EXPECT_TRUE(str2.containsCaseInsensitive(substr2.data()));
126+
127+
static constexpr ConstStringRef str3("AabAac");
128+
ConstStringRef substr3("aacd");
129+
EXPECT_FALSE(str3.containsCaseInsensitive(substr3.data()));
130+
}
131+
132+
TEST(ConstStringRef, GivenConstStringRefWithDifferentCasesWhenCheckingIfOneContainsTheOtherOneCaseInsensitivelyThenTrueIsReturned) {
133+
static constexpr ConstStringRef str1("TexT");
134+
static constexpr ConstStringRef str2("tEXt");
135+
136+
EXPECT_FALSE(str1.contains(str2.data()));
137+
EXPECT_TRUE(str1.containsCaseInsensitive(str2.data()));
138+
}
139+
118140
TEST(ConstStringRef, WhenCheckingForInclusionThenDoesNotReadOutOfBounds) {
119141
static constexpr ConstStringRef str1("Text", 2);
120142
ConstStringRef substr1("Tex");
@@ -189,19 +211,19 @@ TEST(ConstStringRefTruncated, GivenNegativeLengthThenCountFromRight) {
189211
TEST(ConstStringRefEqualsCaseInsesitive, WhenSizesDifferReturnFalse) {
190212
ConstStringRef lhs = ConstStringRef::fromArray("\0");
191213
ConstStringRef rhs = ConstStringRef::fromArray("\0\0");
192-
EXPECT_FALSE(equalsCaseInsesitive(lhs, rhs));
214+
EXPECT_FALSE(equalsCaseInsensitive(lhs, rhs));
193215
}
194216

195217
TEST(ConstStringRefEqualsCaseInsesitive, WhenStringsDontMatchThenReturnFalse) {
196-
EXPECT_FALSE(equalsCaseInsesitive(ConstStringRef("abc"), ConstStringRef("abd")));
218+
EXPECT_FALSE(equalsCaseInsensitive(ConstStringRef("abc"), ConstStringRef("abd")));
197219
}
198220

199221
TEST(ConstStringRefEqualsCaseInsesitive, WhenStringsIdenticalThenReturnTrue) {
200-
EXPECT_TRUE(equalsCaseInsesitive(ConstStringRef("abc"), ConstStringRef("abc")));
222+
EXPECT_TRUE(equalsCaseInsensitive(ConstStringRef("abc"), ConstStringRef("abc")));
201223
}
202224

203225
TEST(ConstStringRefEqualsCaseInsesitive, WhenStringsDifferOnlyByCaseThenReturnTrue) {
204-
EXPECT_TRUE(equalsCaseInsesitive(ConstStringRef("aBc"), ConstStringRef("Abc")));
226+
EXPECT_TRUE(equalsCaseInsensitive(ConstStringRef("aBc"), ConstStringRef("Abc")));
205227
}
206228

207229
TEST(ConstStringStartsWith, GivenRightPrefixThenReturnsTrue) {

0 commit comments

Comments
 (0)