Skip to content

Commit 7ef04f9

Browse files
authored
Merge pull request #93 from pbalcer/ur-rebase
add UR loader, null adapter and basic example
2 parents 62dedb0 + eef1a3f commit 7ef04f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+14808
-64
lines changed

.github/workflows/cmake.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: CMake
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
env:
10+
BUILD_TYPE: Release
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Install apt package
20+
run: sudo apt-get install -y doxygen
21+
22+
- name: Install pip packages
23+
run: pip install -r third_party/requirements.txt
24+
25+
- name: Configure CMake
26+
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
27+
28+
- name: Generate source from spec, check for uncommitted diff
29+
run: cmake --build ${{github.workspace}}/build --target check-generated
30+
31+
- name: Build
32+
run: cmake --build ${{github.workspace}}/build
33+
34+
- name: Test
35+
working-directory: ${{github.workspace}}/build
36+
run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure

.github/workflows/pull_request.yaml

Lines changed: 0 additions & 37 deletions
This file was deleted.

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
# Debug files
5454
scripts/**/*.json
5555

56+
# Python cache
57+
__pycache__/
58+
*.py[cod]
59+
5660
# Generated docs
5761
docs/
5862

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Unified Runtime changelog
2+
3+
## v.X.X.X
4+
* Placeholder for first release

CMakeLists.txt

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
cmake_minimum_required(VERSION 3.2.0 FATAL_ERROR)
1+
cmake_minimum_required(VERSION 3.8.0 FATAL_ERROR)
22
project(unified-runtime VERSION 0.5.0)
33

44
include(GNUInstallDirs)
55
include(CMakePackageConfigHelpers)
6+
include(CTest)
7+
8+
find_package(Python3 COMPONENTS Interpreter)
69

710
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
811
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
912
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
1013

14+
# define rpath for libraries so that adapters can be found automatically
15+
set(CMAKE_BUILD_RPATH "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
16+
1117
#Define a path for custom commands to work around MSVC
1218
set(CUSTOM_COMMAND_BINARY_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
1319
if(MSVC)
@@ -70,6 +76,8 @@ install(
7076
EXPORT ${PROJECT_NAME}-targets)
7177

7278
add_subdirectory(source)
79+
add_subdirectory(examples)
80+
add_subdirectory(test)
7381

7482
# Add the list of installed targets to the install. This includes the namespace
7583
# which all installed targets will be prefixed with, e.g. for the headers
@@ -90,9 +98,32 @@ configure_package_config_file(
9098
${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in
9199
${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}-config.cmake
92100
INSTALL_DESTINATION lib/cmake/${PROJECT_NAME})
101+
93102
# Add the package files to the install.
94103
install(
95104
FILES
96105
${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}-config.cmake
97106
${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}-config-version.cmake
98107
DESTINATION lib/cmake/${PROJECT_NAME})
108+
109+
set(API_JSON_FILE ${PROJECT_BINARY_DIR}/unified_runtime.json)
110+
111+
# generate source from the specification
112+
add_custom_command (
113+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/scripts
114+
DEPENDS ${CMAKE_SOURCE_DIR}/scripts/*
115+
OUTPUT ${API_JSON_FILE}
116+
COMMAND ${Python3_EXECUTABLE} run.py --api-json ${API_JSON_FILE}
117+
COMMAND ${Python3_EXECUTABLE} json2src.py --api-json ${API_JSON_FILE} ${CMAKE_SOURCE_DIR}
118+
)
119+
120+
add_custom_target(generate ALL
121+
DEPENDS ${API_JSON_FILE}
122+
)
123+
124+
# generate source and check for uncommitted diffs
125+
add_custom_target(check-generated
126+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
127+
COMMAND git diff --exit-code
128+
DEPENDS generate
129+
)

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 Intel Corporation
3+
Copyright (C) 2022 Intel Corporation
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# Unified Runtime
22

3+
[![GHA build status](https://github.com/oneapi-src/unified-runtime/actions/workflows/cmake.yml/badge.svg?branch=main)](https://github.com/oneapi-src/unified-runtime/actions)
4+
35
## Contents
46

57
This repo contains the following:
68

79
- API specification in YaML
810
- API programming guide in RST
11+
- Loader and a null adapter implementation (partially generated)
12+
- Example applications
913
- API C/C++ header files (generated)
1014
- API Python module (generated)
1115
- Sample C++ wrapper (generated)
@@ -33,7 +37,7 @@ target_link_libraries(example PUBLIC unified-runtime::headers)
3337

3438
## Source Code Generation
3539

36-
Code is generated using included [Python scripts](/scripts/README.md).
40+
Code is generated using included [Python scripts](/scripts/README.md).
3741

3842
## Documentation
3943

@@ -48,22 +52,31 @@ Tools can be acquired via instructions in [third_party](/third_party/README.md).
4852
Project is defined using [CMake](https://cmake.org/).
4953

5054
**Windows**:
55+
5156
Generating Visual Studio Project. EXE and binaries will be in **build/bin/{build_config}**
5257

5358
~~~~
54-
mkdir build
55-
cd build
56-
cmake {path_to_source_dir} -G "Visual Studio 15 2017 Win64"
59+
$ mkdir build
60+
$ cd build
61+
$ cmake {path_to_source_dir} -G "Visual Studio 15 2017 Win64"
5762
~~~~
5863

5964
**Linux**:
6065

6166
Executable and binaries will be in **build/bin**
6267

6368
~~~~
64-
mkdir build
65-
cd build
66-
cmake {path_to_source_dir}
67-
make
69+
$ mkdir build
70+
$ cd build
71+
$ cmake {path_to_source_dir}
72+
$ make
73+
~~~~
74+
75+
**General**:
76+
77+
If you've made modifications to the specification, you can also run a custom `generate` target prior to building.
78+
~~~~
79+
$ make generate
6880
~~~~
6981

82+
This call will automatically generate the source code.

SECURITY.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Security Policy
2+
3+
## Report a Vulnerability
4+
5+
Please report security issues or vulnerabilities to the [Intel Security Center].
6+
7+
For more information on how Intel works to resolve security issues, see [Vulnerability Handling Guidelines].
8+
9+
[Intel Security Center]:https://www.intel.com/security
10+
11+
[Vulnerability Handling Guidelines]:https://www.intel.com/content/www/us/en/security-center/vulnerability-handling-guidelines.html

examples/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
2+
3+
add_subdirectory(hello_world)

examples/hello_world/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
set(TARGET_NAME hello_world)
2+
3+
add_executable(${TARGET_NAME}
4+
${CMAKE_CURRENT_SOURCE_DIR}/hello_world.cpp
5+
)
6+
7+
target_include_directories(${TARGET_NAME} PRIVATE
8+
${CMAKE_SOURCE_DIR}/include
9+
)
10+
11+
if(MSVC)
12+
set_target_properties(${TARGET_NAME}
13+
PROPERTIES
14+
VS_DEBUGGER_COMMAND_ARGUMENTS ""
15+
VS_DEBUGGER_WORKING_DIRECTORY "$(OutDir)"
16+
)
17+
endif()
18+
19+
target_link_libraries(${TARGET_NAME}
20+
${PROJECT_NAME}::loader
21+
${CMAKE_DL_LIBS}
22+
)

examples/hello_world/hello_world.cpp

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
*
3+
* Copyright (C) 2020-2021 Intel Corporation
4+
*
5+
* SPDX-License-Identifier: MIT
6+
*
7+
*/
8+
#include <stdlib.h>
9+
#include <memory>
10+
#include <iostream>
11+
#include <vector>
12+
13+
#include "ur_api.h"
14+
15+
//////////////////////////////////////////////////////////////////////////
16+
int main(int argc, char *argv[])
17+
{
18+
ur_result_t status;
19+
20+
ur_platform_handle_t platform = nullptr;
21+
ur_device_handle_t pDevice = nullptr;
22+
23+
// Initialize the platform
24+
status = urInit(0, 0);
25+
if (status != UR_RESULT_SUCCESS)
26+
{
27+
std::cout << "urInit failed with return code: " << status << std::endl;
28+
return 1;
29+
}
30+
std::cout << "Platform initialized.\n";
31+
32+
uint32_t platformCount = 0;
33+
std::vector<ur_platform_handle_t> platforms;
34+
35+
status = urPlatformGet(1, nullptr, &platformCount);
36+
if (status != UR_RESULT_SUCCESS)
37+
{
38+
std::cout << "urPlatformGet failed with return code: " << status << std::endl;
39+
goto out;
40+
}
41+
42+
platforms.resize(platformCount);
43+
status = urPlatformGet(platformCount, platforms.data(), nullptr);
44+
if (status != UR_RESULT_SUCCESS)
45+
{
46+
std::cout << "urPlatformGet failed with return code: " << status << std::endl;
47+
goto out;
48+
}
49+
50+
for (auto p : platforms)
51+
{
52+
uint32_t deviceCount = 0;
53+
status = urDeviceGet(p, UR_DEVICE_TYPE_GPU, 0, nullptr, &deviceCount);
54+
if (status != UR_RESULT_SUCCESS)
55+
{
56+
std::cout << "urDeviceGet failed with return code: " << status << std::endl;
57+
goto out;
58+
}
59+
60+
std::vector<ur_device_handle_t> devices(deviceCount);
61+
status = urDeviceGet(p, UR_DEVICE_TYPE_GPU, deviceCount, devices.data(), nullptr);
62+
if (status != UR_RESULT_SUCCESS)
63+
{
64+
std::cout << "urDeviceGet failed with return code: " << status << std::endl;
65+
goto out;
66+
}
67+
for (auto d : devices)
68+
{
69+
ur_device_type_t device_type;
70+
status = urDeviceGetInfo(d, UR_DEVICE_INFO_TYPE, sizeof(ur_device_type_t), static_cast<void *>(&device_type), nullptr);
71+
if (status != UR_RESULT_SUCCESS)
72+
{
73+
std::cout << "urDeviceGet failed with return code: " << status << std::endl;
74+
goto out;
75+
}
76+
static const size_t DEVICE_NAME_MAX_LEN = 1024;
77+
char device_name[DEVICE_NAME_MAX_LEN] = {0};
78+
status = urDeviceGetInfo(d, UR_DEVICE_INFO_NAME, DEVICE_NAME_MAX_LEN - 1, static_cast<void *>(&device_name), nullptr);
79+
if (status != UR_RESULT_SUCCESS)
80+
{
81+
std::cout << "urDeviceGet failed with return code: " << status << std::endl;
82+
goto out;
83+
}
84+
if (device_type == UR_DEVICE_TYPE_GPU)
85+
{
86+
std::cout << "Found a " << device_name << " gpu.\n";
87+
}
88+
}
89+
}
90+
91+
out:
92+
urTearDown(nullptr);
93+
return status == UR_RESULT_SUCCESS ? 0 : 1;
94+
}

0 commit comments

Comments
 (0)