-
Notifications
You must be signed in to change notification settings - Fork 125
add UR loader, null adapter and basic example #93
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: CMake | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
env: | ||
BUILD_TYPE: Release | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Install apt package | ||
run: sudo apt-get install -y doxygen | ||
|
||
- name: Install pip packages | ||
run: pip install -r third_party/requirements.txt | ||
|
||
- name: Configure CMake | ||
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} | ||
|
||
- name: Generate source from spec, check for uncommitted diff | ||
run: cmake --build ${{github.workspace}}/build --target check-generated | ||
|
||
- name: Build | ||
run: cmake --build ${{github.workspace}}/build | ||
|
||
- name: Test | ||
working-directory: ${{github.workspace}}/build | ||
run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,10 @@ | |
# Debug files | ||
scripts/**/*.json | ||
|
||
# Python cache | ||
__pycache__/ | ||
*.py[cod] | ||
|
||
# Generated docs | ||
docs/ | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Unified Runtime changelog | ||
|
||
## v.X.X.X | ||
* Placeholder for first release |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Security Policy | ||
|
||
## Report a Vulnerability | ||
|
||
Please report security issues or vulnerabilities to the [Intel Security Center]. | ||
|
||
For more information on how Intel works to resolve security issues, see [Vulnerability Handling Guidelines]. | ||
|
||
[Intel Security Center]:https://www.intel.com/security | ||
|
||
[Vulnerability Handling Guidelines]:https://www.intel.com/content/www/us/en/security-center/vulnerability-handling-guidelines.html |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) | ||
|
||
add_subdirectory(hello_world) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
set(TARGET_NAME hello_world) | ||
|
||
add_executable(${TARGET_NAME} | ||
${CMAKE_CURRENT_SOURCE_DIR}/hello_world.cpp | ||
) | ||
|
||
target_include_directories(${TARGET_NAME} PRIVATE | ||
${CMAKE_SOURCE_DIR}/include | ||
) | ||
|
||
if(MSVC) | ||
set_target_properties(${TARGET_NAME} | ||
PROPERTIES | ||
VS_DEBUGGER_COMMAND_ARGUMENTS "" | ||
VS_DEBUGGER_WORKING_DIRECTORY "$(OutDir)" | ||
) | ||
endif() | ||
|
||
target_link_libraries(${TARGET_NAME} | ||
${PROJECT_NAME}::loader | ||
${CMAKE_DL_LIBS} | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* | ||
* Copyright (C) 2020-2021 Intel Corporation | ||
* | ||
* SPDX-License-Identifier: MIT | ||
* | ||
*/ | ||
#include <stdlib.h> | ||
#include <memory> | ||
#include <iostream> | ||
#include <vector> | ||
|
||
#include "ur_api.h" | ||
|
||
////////////////////////////////////////////////////////////////////////// | ||
int main(int argc, char *argv[]) | ||
{ | ||
ur_result_t status; | ||
|
||
ur_platform_handle_t platform = nullptr; | ||
ur_device_handle_t pDevice = nullptr; | ||
|
||
// Initialize the platform | ||
status = urInit(0, 0); | ||
if (status != UR_RESULT_SUCCESS) | ||
{ | ||
std::cout << "urInit failed with return code: " << status << std::endl; | ||
return 1; | ||
} | ||
std::cout << "Platform initialized.\n"; | ||
|
||
uint32_t platformCount = 0; | ||
std::vector<ur_platform_handle_t> platforms; | ||
|
||
status = urPlatformGet(1, nullptr, &platformCount); | ||
if (status != UR_RESULT_SUCCESS) | ||
{ | ||
std::cout << "urPlatformGet failed with return code: " << status << std::endl; | ||
goto out; | ||
} | ||
|
||
platforms.resize(platformCount); | ||
status = urPlatformGet(platformCount, platforms.data(), nullptr); | ||
if (status != UR_RESULT_SUCCESS) | ||
{ | ||
std::cout << "urPlatformGet failed with return code: " << status << std::endl; | ||
goto out; | ||
} | ||
|
||
for (auto p : platforms) | ||
{ | ||
uint32_t deviceCount = 0; | ||
status = urDeviceGet(p, UR_DEVICE_TYPE_GPU, 0, nullptr, &deviceCount); | ||
if (status != UR_RESULT_SUCCESS) | ||
{ | ||
std::cout << "urDeviceGet failed with return code: " << status << std::endl; | ||
goto out; | ||
} | ||
|
||
std::vector<ur_device_handle_t> devices(deviceCount); | ||
status = urDeviceGet(p, UR_DEVICE_TYPE_GPU, deviceCount, devices.data(), nullptr); | ||
if (status != UR_RESULT_SUCCESS) | ||
{ | ||
std::cout << "urDeviceGet failed with return code: " << status << std::endl; | ||
goto out; | ||
} | ||
for (auto d : devices) | ||
{ | ||
ur_device_type_t device_type; | ||
status = urDeviceGetInfo(d, UR_DEVICE_INFO_TYPE, sizeof(ur_device_type_t), static_cast<void *>(&device_type), nullptr); | ||
if (status != UR_RESULT_SUCCESS) | ||
{ | ||
std::cout << "urDeviceGet failed with return code: " << status << std::endl; | ||
goto out; | ||
} | ||
static const size_t DEVICE_NAME_MAX_LEN = 1024; | ||
char device_name[DEVICE_NAME_MAX_LEN] = {0}; | ||
status = urDeviceGetInfo(d, UR_DEVICE_INFO_NAME, DEVICE_NAME_MAX_LEN - 1, static_cast<void *>(&device_name), nullptr); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be extended by the check on the actual device name length returned from this function (with a last parameter). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather keep the example short. Checking the length here doesn't add much - device_name will be a valid NULL-terminated C string, which In a test, on the other hand, we should verify that if this function returns success, the name is populated with a non-zero length string. |
||
if (status != UR_RESULT_SUCCESS) | ||
{ | ||
std::cout << "urDeviceGet failed with return code: " << status << std::endl; | ||
goto out; | ||
} | ||
if (device_type == UR_DEVICE_TYPE_GPU) | ||
{ | ||
std::cout << "Found a " << device_name << " gpu.\n"; | ||
} | ||
} | ||
} | ||
|
||
out: | ||
urTearDown(nullptr); | ||
return status == UR_RESULT_SUCCESS ? 0 : 1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to move this section to be one of the first ones, so this will be something that the user will try using first instead of doing this the hard way (by figuring out which script should be run and with which params, see Source Code Generation section and the linked README).