Skip to content

Commit 83c9115

Browse files
author
Jaime Arteaga
committed
[SYCL][UR] Add UR bindings
Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
1 parent 7df9b5e commit 83c9115

28 files changed

+625
-40
lines changed

sycl/plugins/level_zero/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,29 @@ add_sycl_plugin(level_zero
101101
"../unified_runtime/ur/usm_allocator_config.cpp"
102102
"../unified_runtime/ur/usm_allocator_config.hpp"
103103
"../unified_runtime/ur/adapters/level_zero/ur_level_zero.hpp"
104+
"../unified_runtime/ur/adapters/level_zero/ur_level_zero_common.hpp"
105+
"../unified_runtime/ur/adapters/level_zero/ur_level_zero_context.hpp"
106+
"../unified_runtime/ur/adapters/level_zero/ur_level_zero_device.hpp"
107+
"../unified_runtime/ur/adapters/level_zero/ur_level_zero_event.hpp"
108+
"../unified_runtime/ur/adapters/level_zero/ur_level_zero_mem.hpp"
109+
"../unified_runtime/ur/adapters/level_zero/ur_level_zero_module.hpp"
110+
"../unified_runtime/ur/adapters/level_zero/ur_level_zero_native.hpp"
111+
"../unified_runtime/ur/adapters/level_zero/ur_level_zero_platform.hpp"
112+
"../unified_runtime/ur/adapters/level_zero/ur_level_zero_program.hpp"
113+
"../unified_runtime/ur/adapters/level_zero/ur_level_zero_queue.hpp"
114+
"../unified_runtime/ur/adapters/level_zero/ur_level_zero_sampler.hpp"
104115
"../unified_runtime/ur/adapters/level_zero/ur_level_zero.cpp"
116+
"../unified_runtime/ur/adapters/level_zero/ur_level_zero_common.cpp"
117+
"../unified_runtime/ur/adapters/level_zero/ur_level_zero_context.cpp"
118+
"../unified_runtime/ur/adapters/level_zero/ur_level_zero_device.cpp"
119+
"../unified_runtime/ur/adapters/level_zero/ur_level_zero_event.cpp"
120+
"../unified_runtime/ur/adapters/level_zero/ur_level_zero_mem.cpp"
121+
"../unified_runtime/ur/adapters/level_zero/ur_level_zero_module.cpp"
122+
"../unified_runtime/ur/adapters/level_zero/ur_level_zero_native.cpp"
123+
"../unified_runtime/ur/adapters/level_zero/ur_level_zero_platform.cpp"
124+
"../unified_runtime/ur/adapters/level_zero/ur_level_zero_program.cpp"
125+
"../unified_runtime/ur/adapters/level_zero/ur_level_zero_queue.cpp"
126+
"../unified_runtime/ur/adapters/level_zero/ur_level_zero_sampler.cpp"
105127
# Following are the PI Level-Zero Plugin only codes.
106128
"pi_level_zero.cpp"
107129
"pi_level_zero.hpp"

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include <zet_api.h>
2828

29+
#include "../unified_runtime/ur/adapters/level_zero/ur_level_zero_common.hpp"
2930
#include "ur/usm_allocator_config.hpp"
3031
#include "ur_bindings.hpp"
3132

sycl/plugins/level_zero/ur_bindings.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,31 @@ struct ur_platform_handle_t_ : public _pi_platform {
1919
struct ur_device_handle_t_ : public _pi_device {
2020
using _pi_device::_pi_device;
2121
};
22+
23+
struct ur_context_handle_t_ : public _pi_context {
24+
using _pi_context::_pi_context;
25+
};
26+
27+
struct ur_event_handle_t_ : public _pi_event {
28+
using _pi_event::_pi_event;
29+
};
30+
31+
struct ur_program_handle_t_ : public _pi_program {
32+
using _pi_program::_pi_program;
33+
};
34+
35+
struct ur_kernel_handle_t_ : public _pi_kernel {
36+
using _pi_kernel::_pi_kernel;
37+
};
38+
39+
struct ur_queue_handle_t_ : public _pi_queue {
40+
using _pi_queue::_pi_queue;
41+
};
42+
43+
struct ur_sampler_handle_t_ : public _pi_sampler {
44+
using _pi_sampler::_pi_sampler;
45+
};
46+
47+
struct ur_mem_handle_t_ : public _pi_mem {
48+
using _pi_mem::_pi_mem;
49+
};

sycl/plugins/unified_runtime/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,29 @@ add_sycl_plugin(unified_runtime
5959
"ur/ur.hpp"
6060
"ur/ur.cpp"
6161
"ur/adapters/level_zero/ur_level_zero.hpp"
62+
"ur/adapters/level_zero/ur_level_zero_common.hpp"
63+
"ur/adapters/level_zero/ur_level_zero_context.hpp"
64+
"ur/adapters/level_zero/ur_level_zero_device.hpp"
65+
"ur/adapters/level_zero/ur_level_zero_event.hpp"
66+
"ur/adapters/level_zero/ur_level_zero_mem.hpp"
67+
"ur/adapters/level_zero/ur_level_zero_module.hpp"
68+
"ur/adapters/level_zero/ur_level_zero_native.hpp"
69+
"ur/adapters/level_zero/ur_level_zero_platform.hpp"
70+
"ur/adapters/level_zero/ur_level_zero_program.hpp"
71+
"ur/adapters/level_zero/ur_level_zero_queue.hpp"
72+
"ur/adapters/level_zero/ur_level_zero_sampler.hpp"
6273
"ur/adapters/level_zero/ur_level_zero.cpp"
74+
"ur/adapters/level_zero/ur_level_zero_common.cpp"
75+
"ur/adapters/level_zero/ur_level_zero_context.cpp"
76+
"ur/adapters/level_zero/ur_level_zero_device.cpp"
77+
"ur/adapters/level_zero/ur_level_zero_event.cpp"
78+
"ur/adapters/level_zero/ur_level_zero_mem.cpp"
79+
"ur/adapters/level_zero/ur_level_zero_module.cpp"
80+
"ur/adapters/level_zero/ur_level_zero_native.cpp"
81+
"ur/adapters/level_zero/ur_level_zero_platform.cpp"
82+
"ur/adapters/level_zero/ur_level_zero_program.cpp"
83+
"ur/adapters/level_zero/ur_level_zero_queue.cpp"
84+
"ur/adapters/level_zero/ur_level_zero_sampler.cpp"
6385
"ur/usm_allocator.hpp"
6486
"ur/usm_allocator.cpp"
6587
# These below belong to Unified Runtime PI Plugin only

sycl/plugins/unified_runtime/ur/adapters/level_zero/ur_level_zero.hpp

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include <ze_api.h>
2121
#include <zes_api.h>
2222

23+
#include "ur_level_zero_common.hpp"
24+
2325
// Returns the ze_structure_type_t to use in .stype of a structured descriptor.
2426
// Intentionally not defined; will give an error if no proper specialization
2527
template <class T> ze_structure_type_t getZeStructureType();
@@ -80,46 +82,6 @@ class ZeCall {
8082
const char *ZeArgs, bool TraceError = true);
8183
};
8284

83-
// Map Level Zero runtime error code to UR error code.
84-
static ur_result_t ze2urResult(ze_result_t ZeResult) {
85-
static std::unordered_map<ze_result_t, ur_result_t> ErrorMapping = {
86-
{ZE_RESULT_SUCCESS, UR_RESULT_SUCCESS},
87-
{ZE_RESULT_ERROR_DEVICE_LOST, UR_RESULT_ERROR_DEVICE_LOST},
88-
{ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS,
89-
UR_RESULT_ERROR_INVALID_OPERATION},
90-
{ZE_RESULT_ERROR_NOT_AVAILABLE, UR_RESULT_ERROR_INVALID_OPERATION},
91-
{ZE_RESULT_ERROR_UNINITIALIZED, UR_RESULT_ERROR_INVALID_PLATFORM},
92-
{ZE_RESULT_ERROR_INVALID_ARGUMENT, UR_RESULT_ERROR_INVALID_ARGUMENT},
93-
{ZE_RESULT_ERROR_INVALID_NULL_POINTER, UR_RESULT_ERROR_INVALID_VALUE},
94-
{ZE_RESULT_ERROR_INVALID_SIZE, UR_RESULT_ERROR_INVALID_VALUE},
95-
{ZE_RESULT_ERROR_UNSUPPORTED_SIZE, UR_RESULT_ERROR_INVALID_VALUE},
96-
{ZE_RESULT_ERROR_UNSUPPORTED_ALIGNMENT, UR_RESULT_ERROR_INVALID_VALUE},
97-
{ZE_RESULT_ERROR_INVALID_SYNCHRONIZATION_OBJECT,
98-
UR_RESULT_ERROR_INVALID_EVENT},
99-
{ZE_RESULT_ERROR_INVALID_ENUMERATION, UR_RESULT_ERROR_INVALID_VALUE},
100-
{ZE_RESULT_ERROR_UNSUPPORTED_ENUMERATION, UR_RESULT_ERROR_INVALID_VALUE},
101-
{ZE_RESULT_ERROR_UNSUPPORTED_IMAGE_FORMAT, UR_RESULT_ERROR_INVALID_VALUE},
102-
{ZE_RESULT_ERROR_INVALID_NATIVE_BINARY, UR_RESULT_ERROR_INVALID_BINARY},
103-
{ZE_RESULT_ERROR_INVALID_KERNEL_NAME,
104-
UR_RESULT_ERROR_INVALID_KERNEL_NAME},
105-
{ZE_RESULT_ERROR_INVALID_FUNCTION_NAME,
106-
UR_RESULT_ERROR_INVALID_FUNCTION_NAME},
107-
{ZE_RESULT_ERROR_OVERLAPPING_REGIONS, UR_RESULT_ERROR_INVALID_OPERATION},
108-
{ZE_RESULT_ERROR_INVALID_GROUP_SIZE_DIMENSION,
109-
UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE},
110-
{ZE_RESULT_ERROR_MODULE_BUILD_FAILURE,
111-
UR_RESULT_ERROR_MODULE_BUILD_FAILURE},
112-
{ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY,
113-
UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY},
114-
{ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY, UR_RESULT_ERROR_OUT_OF_HOST_MEMORY}};
115-
116-
auto It = ErrorMapping.find(ZeResult);
117-
if (It == ErrorMapping.end()) {
118-
return UR_RESULT_ERROR_UNKNOWN;
119-
}
120-
return It->second;
121-
}
122-
12385
// Controls Level Zero calls tracing.
12486
enum DebugLevel {
12587
ZE_DEBUG_NONE = 0x0,
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//===--------- ur_level_zero.hpp - Level Zero Adapter -----------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===-----------------------------------------------------------------===//
8+
9+
#include <algorithm>
10+
#include <climits>
11+
#include <string.h>
12+
13+
#include "ur_level_zero_common.hpp"
14+
#include <ur_bindings.hpp>
15+
16+
std::unordered_map<ze_result_t, ur_result_t> Ze2UrErrorMapping = {
17+
{ZE_RESULT_SUCCESS, UR_RESULT_SUCCESS},
18+
{ZE_RESULT_ERROR_DEVICE_LOST, UR_RESULT_ERROR_DEVICE_LOST},
19+
{ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS,
20+
UR_RESULT_ERROR_INVALID_OPERATION},
21+
{ZE_RESULT_ERROR_NOT_AVAILABLE, UR_RESULT_ERROR_INVALID_OPERATION},
22+
{ZE_RESULT_ERROR_UNINITIALIZED, UR_RESULT_ERROR_INVALID_PLATFORM},
23+
{ZE_RESULT_ERROR_INVALID_ARGUMENT, UR_RESULT_ERROR_INVALID_ARGUMENT},
24+
{ZE_RESULT_ERROR_INVALID_NULL_POINTER, UR_RESULT_ERROR_INVALID_VALUE},
25+
{ZE_RESULT_ERROR_INVALID_SIZE, UR_RESULT_ERROR_INVALID_VALUE},
26+
{ZE_RESULT_ERROR_UNSUPPORTED_SIZE, UR_RESULT_ERROR_INVALID_VALUE},
27+
{ZE_RESULT_ERROR_UNSUPPORTED_ALIGNMENT, UR_RESULT_ERROR_INVALID_VALUE},
28+
{ZE_RESULT_ERROR_INVALID_SYNCHRONIZATION_OBJECT,
29+
UR_RESULT_ERROR_INVALID_EVENT},
30+
{ZE_RESULT_ERROR_INVALID_ENUMERATION, UR_RESULT_ERROR_INVALID_VALUE},
31+
{ZE_RESULT_ERROR_UNSUPPORTED_ENUMERATION, UR_RESULT_ERROR_INVALID_VALUE},
32+
{ZE_RESULT_ERROR_UNSUPPORTED_IMAGE_FORMAT, UR_RESULT_ERROR_INVALID_VALUE},
33+
{ZE_RESULT_ERROR_INVALID_NATIVE_BINARY, UR_RESULT_ERROR_INVALID_BINARY},
34+
{ZE_RESULT_ERROR_INVALID_KERNEL_NAME, UR_RESULT_ERROR_INVALID_KERNEL_NAME},
35+
{ZE_RESULT_ERROR_INVALID_FUNCTION_NAME,
36+
UR_RESULT_ERROR_INVALID_FUNCTION_NAME},
37+
{ZE_RESULT_ERROR_OVERLAPPING_REGIONS, UR_RESULT_ERROR_INVALID_OPERATION},
38+
{ZE_RESULT_ERROR_INVALID_GROUP_SIZE_DIMENSION,
39+
UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE},
40+
{ZE_RESULT_ERROR_MODULE_BUILD_FAILURE,
41+
UR_RESULT_ERROR_MODULE_BUILD_FAILURE},
42+
{ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY,
43+
UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY},
44+
{ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY, UR_RESULT_ERROR_OUT_OF_HOST_MEMORY}};
45+
46+
ur_result_t ze2urResult(ze_result_t ZeResult) {
47+
auto It = Ze2UrErrorMapping.find(ZeResult);
48+
if (It == Ze2UrErrorMapping.end()) {
49+
return UR_RESULT_ERROR_UNKNOWN;
50+
}
51+
return It->second;
52+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//===--------- ur_level_zero.hpp - Level Zero Adapter -----------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===-----------------------------------------------------------------===//
8+
#pragma once
9+
10+
#include <cassert>
11+
#include <list>
12+
#include <map>
13+
#include <stdarg.h>
14+
#include <string>
15+
#include <unordered_map>
16+
#include <vector>
17+
18+
#include <sycl/detail/pi.h>
19+
#include <ur/ur.hpp>
20+
#include <ur_api.h>
21+
#include <ze_api.h>
22+
#include <zes_api.h>
23+
24+
#include "ur_level_zero_context.hpp"
25+
#include "ur_level_zero_device.hpp"
26+
#include "ur_level_zero_event.hpp"
27+
#include "ur_level_zero_mem.hpp"
28+
#include "ur_level_zero_module.hpp"
29+
#include "ur_level_zero_native.hpp"
30+
#include "ur_level_zero_platform.hpp"
31+
#include "ur_level_zero_program.hpp"
32+
#include "ur_level_zero_queue.hpp"
33+
#include "ur_level_zero_sampler.hpp"
34+
35+
// Map Level Zero runtime error code to UR error code.
36+
ur_result_t ze2urResult(ze_result_t ZeResult);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//===--------- ur_level_zero.hpp - Level Zero Adapter -----------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===-----------------------------------------------------------------===//
8+
9+
#include <algorithm>
10+
#include <climits>
11+
#include <string.h>
12+
13+
#include "ur_level_zero.hpp"
14+
#include "ur_level_zero_context.hpp"
15+
#include <ur_bindings.hpp>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===--------- ur_level_zero.hpp - Level Zero Adapter -----------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===-----------------------------------------------------------------===//
8+
#pragma once
9+
10+
#include <cassert>
11+
#include <list>
12+
#include <map>
13+
#include <stdarg.h>
14+
#include <string>
15+
#include <unordered_map>
16+
#include <vector>
17+
18+
#include <sycl/detail/pi.h>
19+
#include <ur/ur.hpp>
20+
#include <ur_api.h>
21+
#include <ze_api.h>
22+
#include <zes_api.h>
23+
24+
#include "ur_level_zero_common.hpp"
25+
26+
struct _ur_context_handle_t : _pi_object {
27+
_ur_context_handle_t() {}
28+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//===--------- ur_level_zero.hpp - Level Zero Adapter -----------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===-----------------------------------------------------------------===//
8+
9+
#include <algorithm>
10+
#include <climits>
11+
#include <string.h>
12+
13+
#include "ur_level_zero.hpp"
14+
#include "ur_level_zero_device.hpp"
15+
#include <ur_bindings.hpp>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//===--------- ur_level_zero.hpp - Level Zero Adapter -----------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===-----------------------------------------------------------------===//
8+
#pragma once
9+
10+
#include <cassert>
11+
#include <list>
12+
#include <map>
13+
#include <stdarg.h>
14+
#include <string>
15+
#include <unordered_map>
16+
#include <vector>
17+
18+
#include <sycl/detail/pi.h>
19+
#include <ur/ur.hpp>
20+
#include <ur_api.h>
21+
#include <ze_api.h>
22+
#include <zes_api.h>
23+
24+
#include "ur_level_zero_common.hpp"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//===--------- ur_level_zero.hpp - Level Zero Adapter -----------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===-----------------------------------------------------------------===//
8+
9+
#include <algorithm>
10+
#include <climits>
11+
#include <string.h>
12+
13+
#include "ur_level_zero.hpp"
14+
#include "ur_level_zero_event.hpp"
15+
#include <ur_bindings.hpp>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===--------- ur_level_zero.hpp - Level Zero Adapter -----------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===-----------------------------------------------------------------===//
8+
#pragma once
9+
10+
#include <cassert>
11+
#include <list>
12+
#include <map>
13+
#include <stdarg.h>
14+
#include <string>
15+
#include <unordered_map>
16+
#include <vector>
17+
18+
#include <sycl/detail/pi.h>
19+
#include <ur/ur.hpp>
20+
#include <ur_api.h>
21+
#include <ze_api.h>
22+
#include <zes_api.h>
23+
24+
#include "ur_level_zero_common.hpp"
25+
26+
struct _ur_event_handle_t : _pi_object {
27+
_ur_event_handle_t() {}
28+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//===--------- ur_level_zero.hpp - Level Zero Adapter -----------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===-----------------------------------------------------------------===//
8+
9+
#include <algorithm>
10+
#include <climits>
11+
#include <string.h>
12+
13+
#include "ur_level_zero.hpp"
14+
#include "ur_level_zero_event.hpp"
15+
#include <ur_bindings.hpp>

0 commit comments

Comments
 (0)