Skip to content

Commit

Permalink
Merge branch 'main' of github.com:oneapi-src/unified-runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszpn committed Sep 9, 2024
2 parents c4854bf + cded5d9 commit 77b4ca7
Show file tree
Hide file tree
Showing 68 changed files with 3,706 additions and 2,718 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/build-hw-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ on:
required: false
type: string
default: OFF
static_adapter:
required: false
type: string
default: OFF

permissions:
contents: read
Expand All @@ -36,7 +40,7 @@ jobs:
strategy:
matrix:
adapter: [
{name: "${{inputs.adapter_name}}", platform: "${{inputs.platform}}", static_Loader: "${{inputs.static_loader}}"},
{name: "${{inputs.adapter_name}}", platform: "${{inputs.platform}}", static_Loader: "${{inputs.static_loader}}", static_adapter: "${{inputs.static_loader}}"},
]
build_type: [Debug, Release]
compiler: [{c: gcc, cxx: g++}, {c: clang, cxx: clang++}]
Expand All @@ -49,6 +53,10 @@ jobs:
build_type: Release
- adapter: {static_Loader: ON}
compiler: {c: clang, cxx: clang++}
- adapter: {static_adapter: ON}
build_type: Release
- adapter: {static_adapter: ON}
compiler: {c: clang, cxx: clang++}

runs-on: ${{inputs.runner_name}}

Expand Down Expand Up @@ -76,6 +84,7 @@ jobs:
-DUR_BUILD_TESTS=ON
-DUR_BUILD_ADAPTER_${{matrix.adapter.name}}=ON
-DUR_STATIC_LOADER=${{matrix.adapter.static_Loader}}
-DUR_STATIC_ADAPTER_${{matrix.adapter.name}}=${{matrix.adapter.static_adapter}}
-DUR_DPCXX=${{github.workspace}}/dpcpp_compiler/bin/clang++
-DUR_SYCL_LIBRARY_DIR=${{github.workspace}}/dpcpp_compiler/lib
${{ matrix.adapter.name == 'HIP' && '-DUR_CONFORMANCE_AMD_ARCH=gfx1030' || '' }}
Expand Down
13 changes: 12 additions & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ jobs:
adapter_name: L0
runner_name: L0
static_loader: ON
static_adapter: ON

opencl:
name: OpenCL
Expand Down Expand Up @@ -216,7 +217,8 @@ jobs:
os: ['windows-2019', 'windows-2022']
adapter: [
{name: None, var: ''}, {name: L0, var: '-DUR_BUILD_ADAPTER_L0=ON'},
{name: None, var: ''}, {name: L0_V2, var: '-DUR_BUILD_ADAPTER_L0_V2=ON'}
{name: None, var: ''}, {name: L0_V2, var: '-DUR_BUILD_ADAPTER_L0_V2=ON'},
{name: L0, var: '-DUR_BUILD_ADAPTER_L0=ON -DUR_STATIC_ADAPTER_L0=ON'}
]

# TODO: building level zero loader on windows-2019 and clang-cl is currently broken
Expand All @@ -225,16 +227,25 @@ jobs:
adapter: {name: L0, var: '-DUR_BUILD_ADAPTER_L0=ON'}
- os: 'windows-2019'
adapter: {name: L0_V2, var: '-DUR_BUILD_ADAPTER_L0_V2=ON'}
- os: 'windows-2019'
adapter: {name: L0, var: '-DUR_BUILD_ADAPTER_L0=ON -DUR_STATIC_ADAPTER_L0=ON'}
- adapter: {name: L0, var: '-DUR_BUILD_ADAPTER_L0=ON'}
compiler: {c: clang-cl, cxx: clang-cl}
- adapter: {name: L0_V2, var: '-DUR_BUILD_ADAPTER_L0_V2=ON'}
compiler: {c: clang-cl, cxx: clang-cl}
- adapter: {name: L0, var: '-DUR_BUILD_ADAPTER_L0=ON -DUR_STATIC_ADAPTER_L0=ON'}
compiler: {c: clang-cl, cxx: clang-cl}

build_type: [Debug, Release]
compiler: [{c: cl, cxx: cl}, {c: clang-cl, cxx: clang-cl}]
include:
- compiler: {c: clang-cl, cxx: clang-cl}
toolset: "-T ClangCL"
- os: 'windows-2022'
adapter: {name: L0, var: '-DUR_BUILD_ADAPTER_L0=ON -DUR_STATIC_ADAPTER_L0=ON'}
build_type: 'Release'
compiler: {c: cl, cxx: cl}

runs-on: ${{matrix.os}}

steps:
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ option(UR_BUILD_ADAPTER_HIP "Build the HIP adapter" OFF)
option(UR_BUILD_ADAPTER_NATIVE_CPU "Build the Native-CPU adapter" OFF)
option(UR_BUILD_ADAPTER_ALL "Build all currently supported adapters" OFF)
option(UR_BUILD_ADAPTER_L0_V2 "Build the (experimental) Level-Zero v2 adapter" OFF)
option(UR_STATIC_ADAPTER_L0 "Build the Level-Zero adapter as static and embed in the loader" OFF)
option(UR_BUILD_EXAMPLE_CODEGEN "Build the codegen example." OFF)
option(VAL_USE_LIBBACKTRACE_BACKTRACE "enable libbacktrace validation backtrace for linux" OFF)
option(UR_ENABLE_ASSERTIONS "Enable assertions for all build types" OFF)
Expand Down
3 changes: 1 addition & 2 deletions include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1569,8 +1569,7 @@ typedef enum ur_device_info_t {
///< ::urDevicePartition
UR_DEVICE_INFO_MAX_NUM_SUB_GROUPS = 80, ///< [uint32_t] max number of sub groups
UR_DEVICE_INFO_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS = 81, ///< [::ur_bool_t] support sub group independent forward progress
UR_DEVICE_INFO_SUB_GROUP_SIZES_INTEL = 82, ///< [uint32_t[]] return an array of sub group sizes supported on Intel
///< device
UR_DEVICE_INFO_SUB_GROUP_SIZES_INTEL = 82, ///< [uint32_t[]] return an array of supported sub group sizes
UR_DEVICE_INFO_USM_HOST_SUPPORT = 83, ///< [::ur_device_usm_access_capability_flags_t] support USM host memory
///< access
UR_DEVICE_INFO_USM_DEVICE_SUPPORT = 84, ///< [::ur_device_usm_access_capability_flags_t] support USM device memory
Expand Down
8 changes: 8 additions & 0 deletions scripts/core/INTRO.rst
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,14 @@ Specific environment variables can be set to control the behavior of unified run

See the Layers_ section for details of the layers currently included in the runtime.

.. envvar:: UR_LOADER_PRELOAD_FILTER

If set, the loader will read `ONEAPI_DEVICE_SELECTOR` before loading the UR Adapters to determine which backends should be loaded.

.. note::

This environment variable is default enabled on Linux, but default disabled on Windows.

Service identifiers
---------------------

Expand Down
2 changes: 1 addition & 1 deletion scripts/core/device.yml
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ etors:
- name: SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS
desc: "[$x_bool_t] support sub group independent forward progress"
- name: SUB_GROUP_SIZES_INTEL
desc: "[uint32_t[]] return an array of sub group sizes supported on Intel device"
desc: "[uint32_t[]] return an array of supported sub group sizes"
- name: USM_HOST_SUPPORT
desc: "[$x_device_usm_access_capability_flags_t] support USM host memory access"
- name: USM_DEVICE_SUPPORT
Expand Down
30 changes: 30 additions & 0 deletions scripts/generate_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,32 @@ def generate_loader(path, section, namespace, tags, version, specs, meta):
)
print("Generated %s lines of code.\n"%loc)

"""
generates c/c++ files from the specification documents
"""
def _mako_interface_loader_api(path, adapter, ext, namespace, tags, version, specs, meta):
dstpath = os.path.join(path, adapter)
os.makedirs(dstpath, exist_ok=True)

template = f"ur_interface_loader.{ext}.mako"
fin = os.path.join(templates_dir, template)

name = f"ur_interface_loader"

filename = f"{name}.{ext}"
fout = os.path.join(dstpath, filename)

print("Generating %s..."%fout)
return util.makoWrite(
fin, fout,
name=name,
adapter=adapter,
ver=version,
namespace=namespace,
tags=tags,
specs=specs,
meta=meta,)

"""
Entry-point:
generates adapter for unified_runtime
Expand All @@ -416,6 +442,10 @@ def generate_adapters(path, section, namespace, tags, version, specs, meta):
loc += _mako_linker_scripts(
dstpath, "adapter", "def", namespace, tags, version, specs, meta
)

loc += _mako_interface_loader_api(dstpath, "level_zero", "cpp", namespace, tags, version, specs, meta)
loc += _mako_interface_loader_api(dstpath, "level_zero", "hpp", namespace, tags, version, specs, meta)

print("Generated %s lines of code.\n"%loc)

"""
Expand Down
4 changes: 4 additions & 0 deletions scripts/templates/ldrddi.cpp.mako
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ ${tbl['export']['name']}(
// Load the device-platform DDI tables
for( auto& platform : ur_loader::getContext()->platforms )
{
// statically linked adapter inside of the loader
if (platform.handle == nullptr)
continue;
if(platform.initStatus != ${X}_RESULT_SUCCESS)
continue;
auto getTable = reinterpret_cast<${tbl['pfn']}>(
Expand Down
4 changes: 3 additions & 1 deletion scripts/templates/queue_api.cpp.mako
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ from templates import helper as th
ur_queue_handle_t_::~ur_queue_handle_t_() {}

## FUNCTION ###################################################################
namespace ${x}::level_zero {
%for obj in th.get_queue_related_functions(specs, n, tags):
${X}_APIEXPORT ${x}_result_t ${X}_APICALL
${x}_result_t
${th.make_func_name(n, tags, obj)}(
%for line in th.make_param_lines(n, tags, obj, format=["name", "type", "delim"]):
${line}
Expand All @@ -35,3 +36,4 @@ ${th.make_func_name(n, tags, obj)}(
return ${obj['params'][0]['name']}->${th.transform_queue_related_function_name(n, tags, obj, format=["name"])};
}
%endfor
}
88 changes: 88 additions & 0 deletions scripts/templates/ur_interface_loader.cpp.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<%!
import re
from templates import helper as th
%><%
n=namespace
N=n.upper()
x=tags['$x']
X=x.upper()
Adapter=adapter.upper()
%>//===--------- ${n}_interface_loader.cpp - Level Zero Adapter ------------===//
//
// Copyright (C) 2024 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 <${n}_api.h>
#include <${n}_ddi.h>

#include "ur_interface_loader.hpp"

static ur_result_t validateProcInputs(ur_api_version_t version, void *pDdiTable) {
if (nullptr == pDdiTable) {
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
}
// Pre 1.0 we enforce loader and adapter must have same version.
// Post 1.0 only major version match should be required.
if (version != UR_API_VERSION_CURRENT) {
return UR_RESULT_ERROR_UNSUPPORTED_VERSION;
}
return UR_RESULT_SUCCESS;
}

#ifdef UR_STATIC_ADAPTER_${Adapter}
namespace ${n}::${adapter} {
#elif defined(__cplusplus)
extern "C" {
#endif

%for tbl in th.get_pfntables(specs, meta, n, tags):
${X}_APIEXPORT ${x}_result_t ${X}_APICALL ${tbl['export']['name']}(
%for line in th.make_param_lines(n, tags, tbl['export'], format=["type", "name", "delim"]):
${line}
%endfor
)
{
auto result = validateProcInputs(version, pDdiTable);
if (UR_RESULT_SUCCESS != result) {
return result;
}

%for obj in tbl['functions']:
pDdiTable->${th.append_ws(th.make_pfn_name(n, tags, obj), 43)} = ${n}::${adapter}::${th.make_func_name(n, tags, obj)};
%endfor

return result;
}

%endfor

#ifdef UR_STATIC_ADAPTER_${Adapter}
} // namespace ur::${adapter}
#elif defined(__cplusplus)
} // extern "C"
#endif

#ifdef UR_STATIC_ADAPTER_${Adapter}
namespace ur::${adapter} {
ur_result_t urAdapterGetDdiTables(ur_dditable_t *ddi) {
if (ddi == nullptr) {
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
}

ur_result_t result;

%for tbl in th.get_pfntables(specs, meta, n, tags):
result = ${n}::${adapter}::${tbl['export']['name']}( ${X}_API_VERSION_CURRENT, &ddi->${tbl['name']} );
if (result != UR_RESULT_SUCCESS)
return result;
%endfor

return result;
}
}
#endif
38 changes: 38 additions & 0 deletions scripts/templates/ur_interface_loader.hpp.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<%!
import re
from templates import helper as th
%><%
n=namespace
N=n.upper()
x=tags['$x']
X=x.upper()
Adapter=adapter.upper()
%>//===--------- ${n}_interface_loader.hpp - Level Zero Adapter ------------===//
//
// Copyright (C) 2024 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 <${n}_api.h>
#include <${n}_ddi.h>

namespace ${n}::${adapter} {
%for s in specs:
%for obj in th.filter_items(s['objects'], 'type', 'function'):
%if not th.obj_traits.is_loader_only(obj):
${x}_result_t ${th.make_func_name(n, tags, obj)}(
%for line in th.make_param_lines(n, tags, obj, format=["type", "name", "delim"]):
${line}
%endfor
);
%endif
%endfor
%endfor
#ifdef UR_STATIC_ADAPTER_LEVEL_ZERO
ur_result_t urAdapterGetDdiTables(ur_dditable_t *ddi);
#endif
}
Loading

0 comments on commit 77b4ca7

Please sign in to comment.