Skip to content

Commit

Permalink
Fix code formatting mistakes
Browse files Browse the repository at this point in the history
  • Loading branch information
Wee-Free-Scot committed Dec 15, 2023
1 parent 38659d5 commit 868742b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 69 deletions.
12 changes: 7 additions & 5 deletions include/ur_print.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15634,7 +15634,8 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct

os << ".hPlatform = ";

ur::details::printPtr(os, *(params->phPlatform));
ur::details::printPtr(os,
*(params->phPlatform));

os << ", ";
os << ".DeviceType = ";
Expand All @@ -15648,20 +15649,21 @@ inline std::ostream &operator<<(std::ostream &os, [[maybe_unused]] const struct

os << ", ";
os << ".phDevices = {";
for (size_t i = 0;
*(params->pphDevices) != NULL && i < *params->pNumEntries; ++i) {
for (size_t i = 0; *(params->pphDevices) != NULL && i < *params->pNumEntries; ++i) {
if (i != 0) {
os << ", ";
}

ur::details::printPtr(os, (*(params->pphDevices))[i]);
ur::details::printPtr(os,
(*(params->pphDevices))[i]);
}
os << "}";

os << ", ";
os << ".pNumDevices = ";

ur::details::printPtr(os, *(params->ppNumDevices));
ur::details::printPtr(os,
*(params->ppNumDevices));

return os;
}
Expand Down
101 changes: 45 additions & 56 deletions source/loader/ur_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,35 +312,36 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,

// validation regex for filterString (not used in this code)
std::regex validation_pattern("^("
"\\*" // C++ escape for \, regex escape for literal '*'
"|"
"cpu" // ensure case-insenitive, when using
"|"
"gpu" // ensure case-insenitive, when using
"|"
"fpga" // ensure case-insenitive, when using
"|"
"[[:digit:]]+" // '<num>'
"|"
"[[:digit:]]+\\.[[:digit:]]+" // '<num>.<num>'
"|"
"[[:digit:]]+\\.\\*" // '<num>.*.*'
"|"
"\\*\\.\\*" // C++ and regex escapes, literal '*.*'
"|"
"[[:digit:]]+\\.[[:digit:]]+\\.[[:digit:]]+" // '<num>.<num>.<num>'
"|"
"[[:digit:]]+\\.[[:digit:]]+\\.\\*" // '<num>.<num>.*'
"|"
"[[:digit:]]+\\.\\*\\.\\*" // '<num>.*.*'
"|"
"\\*\\.\\*\\.\\*" // C++ and regex escapes, literal '*.*.*'
")$", std::regex_constants::icase);
"\\*" // C++ escape for \, regex escape for literal '*'
"|"
"cpu" // ensure case-insenitive, when using
"|"
"gpu" // ensure case-insenitive, when using
"|"
"fpga" // ensure case-insenitive, when using
"|"
"[[:digit:]]+" // '<num>'
"|"
"[[:digit:]]+\\.[[:digit:]]+" // '<num>.<num>'
"|"
"[[:digit:]]+\\.\\*" // '<num>.*.*'
"|"
"\\*\\.\\*" // C++ and regex escapes, literal '*.*'
"|"
"[[:digit:]]+\\.[[:digit:]]+\\.[[:digit:]]+" // '<num>.<num>.<num>'
"|"
"[[:digit:]]+\\.[[:digit:]]+\\.\\*" // '<num>.<num>.*'
"|"
"[[:digit:]]+\\.\\*\\.\\*" // '<num>.*.*'
"|"
"\\*\\.\\*\\.\\*" // C++ and regex escapes, literal '*.*.*'
")$",
std::regex_constants::icase);

ur_platform_backend_t platformBackend;
if (UR_RESULT_SUCCESS !=
urPlatformGetInfo(hPlatform, UR_PLATFORM_INFO_BACKEND,
sizeof(ur_platform_backend_t), &platformBackend, 0)) {
sizeof(ur_platform_backend_t), &platformBackend, 0)) {
return UR_RESULT_ERROR_INVALID_PLATFORM;
}
const std::string platformBackendName = // hPlatform->get_backend_name();
Expand Down Expand Up @@ -375,11 +376,7 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,

using DeviceHardwareType = ur_device_type_t;

enum class DevicePartLevel {
ROOT,
SUB,
SUBSUB
};
enum class DevicePartLevel { ROOT, SUB, SUBSUB };

using DeviceIdType = unsigned long;
constexpr DeviceIdType DeviceIdTypeALL = -1; // ULONG_MAX but without #include <climits>
Expand All @@ -393,7 +390,8 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,
ur_device_handle_t urDeviceHandle;
};

auto getRootHardwareType = [](const std::string &input) -> DeviceHardwareType {
auto getRootHardwareType =
[](const std::string &input) -> DeviceHardwareType {
std::string lowerInput(input);
std::transform(lowerInput.cbegin(), lowerInput.cend(),
lowerInput.begin(), ::tolower);
Expand All @@ -409,8 +407,7 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,
return ::UR_DEVICE_TYPE_ALL;
};

auto getDeviceId =
[&](const std::string &input) -> DeviceIdType {
auto getDeviceId = [&](const std::string &input) -> DeviceIdType {
if (input.find_first_not_of("0123456789") == std::string::npos) {
return std::stoul(input);
}
Expand Down Expand Up @@ -524,9 +521,8 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,
filterString.substr(locationDot2 + 1);
const auto thirdDeviceId = getDeviceId(thirdPart);
deviceList.push_back(DeviceSpec{
DevicePartLevel::SUBSUB, hardwareType,
firstDeviceId, secondDeviceId,
thirdDeviceId});
DevicePartLevel::SUBSUB, hardwareType, firstDeviceId,
secondDeviceId, thirdDeviceId});
} else {
// second dot not found, this is a subdevice
deviceList.push_back(DeviceSpec{DevicePartLevel::SUB,
Expand All @@ -539,8 +535,8 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,
const auto firstDeviceId = getDeviceId(filterString);
deviceList.push_back(DeviceSpec{DevicePartLevel::ROOT,
hardwareType, firstDeviceId});
}
}
}

if (termType != AcceptFilter) {
discardFilters.insert(discardFilters.end(),
Expand All @@ -557,9 +553,8 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,
acceptFilters.insert(acceptFilters.end(), 1, "*");
}
if (acceptDeviceList.size() == 0) {
acceptDeviceList.push_back(
DeviceSpec{DevicePartLevel::ROOT, ::UR_DEVICE_TYPE_ALL,
DeviceIdTypeALL});
acceptDeviceList.push_back(DeviceSpec{
DevicePartLevel::ROOT, ::UR_DEVICE_TYPE_ALL, DeviceIdTypeALL});
}

std::vector<DeviceSpec> rootDevices;
Expand Down Expand Up @@ -616,8 +611,7 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,

// To support sub-device terms:
std::for_each(
rootDevices.cbegin(), rootDevices.cend(),
[&](DeviceSpec device) {
rootDevices.cbegin(), rootDevices.cend(), [&](DeviceSpec device) {
ur_device_partition_property_t propNextPart{
UR_DEVICE_PARTITION_BY_AFFINITY_DOMAIN,
{UR_DEVICE_AFFINITY_DOMAIN_FLAG_NEXT_PARTITIONABLE}};
Expand Down Expand Up @@ -651,8 +645,7 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,

// To support sub-sub-device terms:
std::for_each(
subDevices.cbegin(), subDevices.cend(),
[&](DeviceSpec device) {
subDevices.cbegin(), subDevices.cend(), [&](DeviceSpec device) {
ur_device_partition_property_t propNextPart{
UR_DEVICE_PARTITION_BY_AFFINITY_DOMAIN,
{UR_DEVICE_AFFINITY_DOMAIN_FLAG_NEXT_PARTITIONABLE}};
Expand All @@ -674,14 +667,14 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,
return UR_RESULT_ERROR_DEVICE_PARTITION_FAILED;
}
DeviceIdType subSubDeviceCount = 0;
std::transform(subSubDeviceHandles.cbegin(),
subSubDeviceHandles.cend(),
std::back_inserter(subSubDevices),
[&](ur_device_handle_t urDeviceHandle) {
std::transform(
subSubDeviceHandles.cbegin(), subSubDeviceHandles.cend(),
std::back_inserter(subSubDevices),
[&](ur_device_handle_t urDeviceHandle) {
return DeviceSpec{DevicePartLevel::SUBSUB, device.hwType,
device.rootId, device.subId,
subSubDeviceCount++, urDeviceHandle};
});
});
return UR_RESULT_SUCCESS;
});

Expand Down Expand Up @@ -721,13 +714,11 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,
return matches;
};


// apply each discard filter in turn by removing all matching elements
// from the appropriate device handle vector returned by the platform;
// no side-effect: the matching devices are just removed and discarded
for (auto &discard: discardDeviceList) {
auto ApplyDiscardFilter =
[&](auto &device) -> bool {
for (auto &discard : discardDeviceList) {
auto ApplyDiscardFilter = [&](auto &device) -> bool {
return ApplyFilter(discard, device);
};
if (discard.level == DevicePartLevel::ROOT) {
Expand Down Expand Up @@ -759,8 +750,7 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,
// removing each item as it is selected prevents us taking duplicates
// without needing O(n^2) de-duplicatation or symbolic simplification
for (auto &accept : acceptDeviceList) {
auto ApplyAcceptFilter =
[&](auto &device) -> bool {
auto ApplyAcceptFilter = [&](auto &device) -> bool {
const bool matches = ApplyFilter(accept, device);
if (matches) {
selectedDevices.push_back(device.urDeviceHandle);
Expand Down Expand Up @@ -801,7 +791,6 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,
}
}


return UR_RESULT_SUCCESS;
}
} // namespace ur_lib
14 changes: 6 additions & 8 deletions test/conformance/device/urDeviceGetSelected.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,22 @@ TEST_F(urDeviceGetSelectedTest, SuccessSubsetOfDevices) {
}
std::vector<ur_device_handle_t> devices(count - 1);
ASSERT_SUCCESS(urDeviceGetSelected(platform, UR_DEVICE_TYPE_ALL, count - 1,
devices.data(), nullptr));
devices.data(), nullptr));
for (auto device : devices) {
ASSERT_NE(nullptr, device);
}
}

TEST_F(urDeviceGetSelectedTest, InvalidNullHandlePlatform) {
uint32_t count = 0;
ASSERT_EQ_RESULT(
UR_RESULT_ERROR_INVALID_NULL_HANDLE,
urDeviceGetSelected(nullptr, UR_DEVICE_TYPE_ALL, 0, nullptr, &count));
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
urDeviceGetSelected(nullptr, UR_DEVICE_TYPE_ALL,
0, nullptr, &count));
}

TEST_F(urDeviceGetSelectedTest, InvalidEnumerationDevicesType) {
uint32_t count = 0;
ASSERT_EQ_RESULT(
UR_RESULT_ERROR_INVALID_ENUMERATION,
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_ENUMERATION,
urDeviceGetSelected(platform, UR_DEVICE_TYPE_FORCE_UINT32,
0, nullptr, &count));
}
Expand All @@ -62,8 +61,7 @@ TEST_F(urDeviceGetSelectedTest, InvalidValueNumEntries) {
urDeviceGetSelected(platform, UR_DEVICE_TYPE_ALL, 0, nullptr, &count));
ASSERT_NE(count, 0);
std::vector<ur_device_handle_t> devices(count);
ASSERT_EQ_RESULT(
UR_RESULT_ERROR_INVALID_SIZE,
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_SIZE,
urDeviceGetSelected(platform, UR_DEVICE_TYPE_ALL, 0,
devices.data(), nullptr));
}

0 comments on commit 868742b

Please sign in to comment.