Skip to content

Commit

Permalink
Apply code formatting patches
Browse files Browse the repository at this point in the history
  • Loading branch information
Wee-Free-Scot committed Jan 4, 2024
1 parent 4906cb5 commit 27f5ff0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
37 changes: 20 additions & 17 deletions source/loader/ur_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,11 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,
// with `std::queue<std::pair<key_type_t, value_type_t>>` or something similar.)
auto maybeEnvVarMap = getenv_to_map("ONEAPI_DEVICE_SELECTOR", false);
std::cout
<< "DEBUG: " << (maybeEnvVarMap.has_value()
? "getenv_to_map parsed env var and produced a map"
: "getenv_to_map parsed env var and failed to produce a map")
<< std::endl;
<< "DEBUG: "
<< (maybeEnvVarMap.has_value()
? "getenv_to_map parsed env var and produced a map"
: "getenv_to_map parsed env var and failed to produce a map")
<< std::endl;

// if the ODS env var is not set at all, then pretend it was set to the default
using EnvVarMap = std::map<std::string, std::vector<std::string>>;
Expand Down Expand Up @@ -426,7 +427,8 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,

for (auto &termPair : mapODS) {
std::string backend = termPair.first;
if (backend.empty()) { // FIXME: never true because getenv_to_map rejects this case
if (backend
.empty()) { // FIXME: never true because getenv_to_map rejects this case
// malformed term: missing backend -- output ERROR, then continue
// TODO: replace std::cout with URT message output mechanism
std::cout << "ERROR: missing backend, format of filter = "
Expand All @@ -452,13 +454,14 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,
// Note the hPlatform -> platformBackend -> platformBackendName conversion above
// guarantees minimal sanity for the comparison with backend from the ODS string
if (backend.front() != '*' &&
!std::equal(platformBackendName.cbegin(), platformBackendName.cend(),
backend.cbegin(), backend.cend(),
[](const auto &a, const auto &b) {
// case-insensitive comparison by converting both tolower
return std::tolower(static_cast<unsigned char>(a)) ==
std::tolower(static_cast<unsigned char>(b));
})) {
!std::equal(platformBackendName.cbegin(),
platformBackendName.cend(), backend.cbegin(),
backend.cend(), [](const auto &a, const auto &b) {
// case-insensitive comparison by converting both tolower
return std::tolower(
static_cast<unsigned char>(a)) ==
std::tolower(static_cast<unsigned char>(b));
})) {
// irrelevant term for current request: different backend -- silently ignore
// TODO: replace std::cout with URT message output mechanism
std::cout << "WARNING: ignoring term with irrelevant backend"
Expand All @@ -475,7 +478,8 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,
}
if (std::find_if(termPair.second.cbegin(), termPair.second.cend(),
[](const auto &s) { return s.empty(); }) !=
termPair.second.cend()) { // FIXME: never true because getenv_to_map rejects this case
termPair.second
.cend()) { // FIXME: never true because getenv_to_map rejects this case
// malformed term: missing filterString -- output warning, then continue
// TODO: replace std::cout with URT message output mechanism
std::cout << "WARNING: empty filterString, format of filterStrings "
Expand Down Expand Up @@ -528,7 +532,7 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,
const auto firstDeviceId = getDeviceId(firstPart);
// first dot found, look for another
std::string::size_type locationDot2 =
filterString.find('.', locationDot1+1);
filterString.find('.', locationDot1 + 1);
std::string secondPart = filterString.substr(
locationDot1 + 1, locationDot2 == std::string::npos
? std::string::npos
Expand Down Expand Up @@ -571,7 +575,7 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,
acceptDeviceList.push_back(DeviceSpec{
DevicePartLevel::ROOT, ::UR_DEVICE_TYPE_ALL, DeviceIdTypeALL});
}

std::cout << "DEBUG: size of acceptDeviceList = " << acceptDeviceList.size()
<< std::endl
<< "DEBUG: size of discardDeviceList = "
Expand Down Expand Up @@ -816,8 +820,7 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,
std::cout << "WARNING: an accept term was ignored because it "
"does not select any additional devices"
"selectedDevices.size() = "
<< selectedDevices.size()
<< std::endl;
<< selectedDevices.size() << std::endl;
}
}

Expand Down
10 changes: 6 additions & 4 deletions test/conformance/device/urDeviceGetSelected.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <uur/fixtures.h>
#include "helpers.h"
#include <uur/fixtures.h>

using urDeviceGetSelectedTest = uur::urPlatformTest;

Expand Down Expand Up @@ -61,7 +61,7 @@ TEST_F(urDeviceGetSelectedTest, SuccessSelected_StarColonStar) {
ASSERT_EQ(countAll, count);
std::vector<ur_device_handle_t> devicesAll(countAll);
ASSERT_SUCCESS(urDeviceGet(platform, UR_DEVICE_TYPE_ALL, countAll,
devicesAll.data(), nullptr));
devicesAll.data(), nullptr));
for (auto &device : devicesAll) {
ASSERT_NE(nullptr, device);
}
Expand Down Expand Up @@ -115,7 +115,8 @@ TEST_F(urDeviceGetSelectedTest, SuccessSelected_SelectAndDiscard) {
ASSERT_EQ(count, 0);
}

TEST_F(urDeviceGetSelectedTest, SuccessSelected_SelectSomethingAndDiscardSomethingElse) {
TEST_F(urDeviceGetSelectedTest,
SuccessSelected_SelectSomethingAndDiscardSomethingElse) {
setenv("ONEAPI_DEVICE_SELECTOR", "*:0;!*:1", 1);
uint32_t count = 0;
ASSERT_SUCCESS(
Expand Down Expand Up @@ -178,7 +179,8 @@ TEST_F(urDeviceGetSelectedTest, InvalidGarbageBackendString) {
TEST_F(urDeviceGetSelectedTest, InvalidMissingFilterStrings) {
setenv("ONEAPI_DEVICE_SELECTOR", "*", 1);
uint32_t count = 0;
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_VALUE,
ASSERT_EQ_RESULT(
UR_RESULT_ERROR_INVALID_VALUE,
urDeviceGetSelected(platform, UR_DEVICE_TYPE_ALL, 0, nullptr, &count));
ASSERT_EQ(count, 0);
setenv("ONEAPI_DEVICE_SELECTOR", "*:", 1);
Expand Down

0 comments on commit 27f5ff0

Please sign in to comment.