-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #751 from kbenzie/benie/urinfo
[ur] Introduce urinfo tool
- Loading branch information
Showing
8 changed files
with
923 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<%! | ||
import re | ||
from templates import helper as th | ||
%><% | ||
n=namespace | ||
N=n.upper() | ||
x=tags['$x'] | ||
X=x.upper() | ||
%>/* | ||
* | ||
* Copyright (C) 2023 Intel Corporation | ||
* | ||
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. | ||
* See LICENSE.TXT | ||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
* | ||
* @file ${name}.cpp | ||
* | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <ur_api.h> | ||
#include "utils.hpp" | ||
#include <cstdlib> | ||
#include <string_view> | ||
|
||
namespace urinfo { | ||
%for obj in th.extract_objs(specs, r"enum"): | ||
%if obj["name"] == '$x_loader_config_info_t': | ||
inline void printLoaderConfigInfos(${x}_loader_config_handle_t hLoaderConfig, std::string_view prefix = " ") { | ||
%for etor in obj['etors']: | ||
%if 'REFERENCE_COUNT' not in etor['name']: | ||
std::cout << prefix; | ||
printLoaderConfigInfo<${etor['desc'][1:etor['desc'].find(' ')-1].replace('$x', x)}>(hLoaderConfig, ${etor['name'].replace('$X', X)}); | ||
%endif | ||
%endfor | ||
} | ||
%endif | ||
%if obj["name"] == '$x_adapter_info_t': | ||
inline void printAdapterInfos(${x}_adapter_handle_t hAdapter, std::string_view prefix = " ") { | ||
%for etor in obj['etors']: | ||
%if 'REFERENCE_COUNT' not in etor['name']: | ||
std::cout << prefix; | ||
printAdapterInfo<${etor['desc'][1:etor['desc'].find(' ')-1].replace('$x', x)}>(hAdapter, ${etor['name'].replace('$X', X)}); | ||
%endif | ||
%endfor | ||
} | ||
|
||
%endif | ||
%if obj["name"] == '$x_platform_info_t': | ||
inline void printPlatformInfos(${x}_platform_handle_t hPlatform, std::string_view prefix = " ") { | ||
%for etor in obj['etors']: | ||
std::cout << prefix; | ||
printPlatformInfo<${etor['desc'][1:etor['desc'].find(' ')-1].replace('$x', x)}>(hPlatform, ${etor['name'].replace('$X', X)}); | ||
%endfor | ||
} | ||
|
||
%endif | ||
%if obj['name'] == '$x_device_info_t': | ||
inline void printDeviceInfos(${x}_device_handle_t hDevice, std::string_view prefix = " ") { | ||
%for etor in obj['etors']: | ||
std::cout << prefix; | ||
printDeviceInfo<${etor['desc'][1:etor['desc'].find(' ')-1].replace('$x', x)}>(hDevice, ${etor['name'].replace('$X', X)}); | ||
%endfor | ||
} | ||
%endif | ||
%endfor | ||
} // namespace urinfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright (C) 2023 Intel Corporation | ||
# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. | ||
# See LICENSE.TXT | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
add_ur_executable(urinfo | ||
urinfo.hpp | ||
utils.hpp | ||
urinfo.cpp | ||
) | ||
target_compile_definitions(urinfo PRIVATE | ||
UR_VERSION="${PROJECT_VERSION}" | ||
) | ||
target_include_directories(urinfo PRIVATE | ||
${PROJECT_SOURCE_DIR}/source/common | ||
) | ||
target_link_libraries(urinfo PRIVATE | ||
${PROJECT_NAME}::headers | ||
${PROJECT_NAME}::loader | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
// Copyright (C) 2023 Intel Corporation | ||
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See LICENSE.TXT | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
#include "urinfo.hpp" | ||
#include <cstdlib> | ||
#include <iostream> | ||
#include <string> | ||
#include <string_view> | ||
#include <unordered_map> | ||
#include <vector> | ||
|
||
namespace urinfo { | ||
struct app { | ||
bool verbose = false; | ||
ur_loader_config_handle_t loaderConfig = nullptr; | ||
std::vector<ur_adapter_handle_t> adapters; | ||
std::unordered_map<ur_adapter_handle_t, std::vector<ur_platform_handle_t>> | ||
adapterPlatformsMap; | ||
std::unordered_map<ur_platform_handle_t, std::vector<ur_device_handle_t>> | ||
platformDevicesMap; | ||
|
||
app(int argc, const char **argv) { | ||
parseArgs(argc, argv); | ||
UR_CHECK(urLoaderConfigCreate(&loaderConfig)); | ||
UR_CHECK(urLoaderConfigEnableLayer(loaderConfig, | ||
"UR_LAYER_FULL_VALIDATION")); | ||
UR_CHECK(urInit(0, loaderConfig)); | ||
enumerateDevices(); | ||
} | ||
|
||
void parseArgs(int argc, const char **argv) { | ||
static const char *usage = R"(usage: %s [-h] [-v] [-V] | ||
This tool enumerates Unified Runtime layers, adapters, platforms, and | ||
devices which are currently visible in the local execution environment. | ||
options: | ||
-h, --help show this help message and exit | ||
--version show version number and exit | ||
-v, --verbose print additional information | ||
)"; | ||
for (int argi = 1; argi < argc; argi++) { | ||
std::string_view arg{argv[argi]}; | ||
if (arg == "-h" || arg == "--help") { | ||
std::printf(usage, argv[0]); | ||
std::exit(0); | ||
} else if (arg == "--version") { | ||
std::printf("%s v%s\n", argv[0], UR_VERSION); | ||
std::exit(0); | ||
} else if (arg == "-v" || arg == "--verbose") { | ||
verbose = true; | ||
} else { | ||
std::fprintf(stderr, "error: invalid argument: %s\n", | ||
argv[argi]); | ||
std::fprintf(stderr, usage, argv[0]); | ||
std::exit(1); | ||
} | ||
} | ||
} | ||
|
||
void enumerateDevices() { | ||
// Enumerate adapters. | ||
uint32_t numAdapters = 0; | ||
UR_CHECK(urAdapterGet(0, nullptr, &numAdapters)); | ||
if (numAdapters == 0) { | ||
std::cout << "No adapters found.\n"; | ||
std::exit(0); | ||
} | ||
adapters.resize(numAdapters); | ||
UR_CHECK(urAdapterGet(numAdapters, adapters.data(), nullptr)); | ||
|
||
for (size_t adapterIndex = 0; adapterIndex < adapters.size(); | ||
adapterIndex++) { | ||
auto adapter = adapters[adapterIndex]; | ||
// Enumerate platforms | ||
uint32_t numPlatforms = 0; | ||
UR_CHECK(urPlatformGet(&adapter, 1, 0, nullptr, &numPlatforms)); | ||
if (numPlatforms == 0) { | ||
std::cout << "No platforms found in adapter " << adapterIndex | ||
<< ".\n"; | ||
continue; | ||
} | ||
adapterPlatformsMap[adapter].resize(numPlatforms); | ||
UR_CHECK(urPlatformGet(&adapter, 1, numPlatforms, | ||
adapterPlatformsMap[adapter].data(), | ||
nullptr)); | ||
|
||
for (size_t platformIndex = 0; platformIndex < numPlatforms; | ||
platformIndex++) { | ||
auto platform = adapterPlatformsMap[adapter][platformIndex]; | ||
// Enumerate devices | ||
uint32_t numDevices = 0; | ||
UR_CHECK(urDeviceGet(platform, UR_DEVICE_TYPE_ALL, 0, nullptr, | ||
&numDevices)); | ||
if (numDevices == 0) { | ||
std::cout << "No devices found platform " << platformIndex | ||
<< ".\n"; | ||
continue; | ||
} | ||
platformDevicesMap[platform].resize(numDevices); | ||
UR_CHECK(urDeviceGet(platform, UR_DEVICE_TYPE_ALL, numDevices, | ||
platformDevicesMap[platform].data(), | ||
nullptr)); | ||
} | ||
} | ||
} | ||
|
||
void printSummary() { | ||
for (size_t adapterIndex = 0; adapterIndex < adapters.size(); | ||
adapterIndex++) { | ||
auto adapter = adapters[adapterIndex]; | ||
auto &platforms = adapterPlatformsMap[adapter]; | ||
for (size_t platformIndex = 0; platformIndex < platforms.size(); | ||
platformIndex++) { | ||
auto platform = platforms[platformIndex]; | ||
auto &devices = platformDevicesMap[platform]; | ||
for (size_t deviceIndex = 0; deviceIndex < devices.size(); | ||
deviceIndex++) { | ||
auto device = devices[deviceIndex]; | ||
std::cout << "[adapter(" << adapterIndex << "," | ||
<< urinfo::getAdapterBackend(adapter) << "):" | ||
<< "platform(" << platformIndex << "):" | ||
<< "device(" << deviceIndex << "," | ||
<< urinfo::getDeviceType(device) << ")] " | ||
<< urinfo::getPlatformName(platform) << ", " | ||
<< urinfo::getDeviceName(device) << " " | ||
<< urinfo::getDeviceVersion(device) << " " | ||
<< "[" << urinfo::getDeviceDriverVersion(device) | ||
<< "]\n"; | ||
} | ||
} | ||
} | ||
} | ||
|
||
void printDetail() { | ||
std::cout << "\n" | ||
<< "[loader]:" | ||
<< "\n"; | ||
urinfo::printLoaderConfigInfos(loaderConfig); | ||
|
||
for (size_t adapterIndex = 0; adapterIndex < adapters.size(); | ||
adapterIndex++) { | ||
auto adapter = adapters[adapterIndex]; | ||
std::cout << "\n" | ||
<< "[adapter(" << adapterIndex << ")]:" | ||
<< "\n"; | ||
urinfo::printAdapterInfos(adapter); | ||
|
||
size_t numPlatforms = adapterPlatformsMap[adapter].size(); | ||
for (size_t platformIndex = 0; platformIndex < numPlatforms; | ||
platformIndex++) { | ||
auto platform = adapterPlatformsMap[adapter][platformIndex]; | ||
std::cout << "\n" | ||
<< "[adapter(" << adapterIndex << ")," | ||
<< "platform(" << platformIndex << ")]:" | ||
<< "\n"; | ||
urinfo::printPlatformInfos(platform); | ||
|
||
size_t numDevices = platformDevicesMap[platform].size(); | ||
for (size_t deviceI = 0; deviceI < numDevices; deviceI++) { | ||
auto device = platformDevicesMap[platform][deviceI]; | ||
std::cout << "\n" | ||
<< "[adapter(" << adapterIndex << ")," | ||
<< "platform(" << platformIndex << ")," | ||
<< "device(" << deviceI << ")]:" | ||
<< "\n"; | ||
urinfo::printDeviceInfos(device); | ||
} | ||
} | ||
} | ||
} | ||
|
||
~app() { | ||
urLoaderConfigRelease(loaderConfig); | ||
urTearDown(nullptr); | ||
} | ||
}; | ||
} // namespace urinfo | ||
|
||
int main(int argc, const char **argv) { | ||
auto app = urinfo::app{argc, argv}; | ||
app.printSummary(); | ||
if (app.verbose) { | ||
app.printDetail(); | ||
} | ||
return 0; | ||
} |
Oops, something went wrong.