Skip to content

Commit 1f60bbe

Browse files
committed
Merge from 'sycl' to 'sycl-web' (5 commits)
This patch revert f33a719 "[SYCL] Fix Windows build configure issue (#6060)"
2 parents ad4e4a0 + f33a719 commit 1f60bbe

20 files changed

+1191
-72
lines changed

opencl/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ set(OCL_LOADER_REPO
2121
# Repo tags/hashes
2222

2323
set(OCL_HEADERS_TAG dcd5bede6859d26833cd85f0d6bbcee7382dc9b3)
24-
set(OCL_LOADER_TAG 5d9177ee79bfbcc75ee9a8cff6415eab2c3113f6)
24+
set(OCL_LOADER_TAG aec3952654832211636fc4af613710f80e203b0a)
2525

2626
# OpenCL Headers
2727
if(NOT OpenCL_HEADERS)

sycl/doc/design/SYCLInstrumentationUsingXPTI.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,23 @@ All trace point types in bold provide semantic information about the graph, node
300300
| `mem_alloc_end` | <div style="text-align: left"><li>**trace_type**: `xpti::trace_point_type_t::mem_alloc_end` that marks the end of memory allocation process</li> <li> **parent**: Event ID created for all functions in the `oneapi.level_zero.experimental.mem_alloc` layer.</li> <li> **event**: `nullptr` - since the stream of data just captures functions being called.</li> <li> **instance**: Unique ID to allow the correlation of the `mem_alloc_begin` event with the `mem_alloc_end` event. This value is guaranteed to be the same value received by the trace event for the corresponding `mem_alloc_begin`.</li> <li> **user_data**: A pointer to `mem_alloc_data_t` object, that includes memory object ID (if any), allocated pointer, allocation size, and guard zone size (if any). </li></div> | None |
301301
| `mem_release_begin` | <div style="text-align: left"><li>**trace_type**: `xpti::trace_point_type_t::mem_release_begin` that marks the beginning of memory allocation process</li> <li> **parent**: Event ID created for all functions in the `oneapi.level_zero.experimental.mem_alloc` layer.</li> <li> **event**: `nullptr` - since the stream of data just captures functions being called.</li> <li> **instance**: Unique ID to allow the correlation of the `mem_release_begin` event with the `mem_release_end` event. </li> <li> **user_data**: A pointer to `mem_alloc_data_t` object, that includes memory object ID (if any) and released pointer. </li></div> | None |
302302
| `mem_release_end` | <div style="text-align: left"><li>**trace_type**: `xpti::trace_point_type_t::mem_release_end` that marks the end of memory allocation process</li> <li> **parent**: Event ID created for all functions in the `oneapi.level_zero.experimental.mem_alloc` layer.</li> <li> **event**: `nullptr` - since the stream of data just captures functions being called.</li> <li> **instance**: Unique ID to allow the correlation of the `mem_release_begin` event with the `mem_release_end` event. This value is guaranteed to be the same value received by the trace event for the corresponding `mem_release_begin`.</li> <li> **user_data**: A pointer to `mem_alloc_data_t` object, that includes memory object ID (if any) and released pointer. </li></div> | None |
303+
304+
## SYCL Stream `"sycl.experimental.level_zero.call"` Notification Signatures
305+
306+
This stream transfers events about Level Zero API calls made by SYCL
307+
application.
308+
309+
| Trace Point Type | Parameter Description | Metadata |
310+
| :--------------: | :-------------------- | :------- |
311+
| `function_begin` | <div style="text-align: left"><li>**trace_type**: `xpti::trace_point_type_t::function_begin` that marks the beginning of a function</li> <li> **parent**: Event ID created for all functions in the `sycl.pi` layer.</li> <li> **event**: `nullptr` - since the stream of data just captures functions being called.</li> <li> **instance**: Unique ID to allow the correlation of the `function_begin` event with the `function_end` event. </li> <li> **user_data**: Name of the function being called sent in as `const char *` </li></div> | None |
312+
| `function_end` | <div style="text-align: left"><li>**trace_type**: `xpti::trace_point_type_t::function_end` that marks the beginning of a function</li> <li> **parent**: Event ID created for all functions in the `sycl.pi` layer.</li> <li> **event**: `nullptr` - since the stream of data just captures functions being called.</li> <li> **instance**: Unique ID to allow the correlation of the `function_begin` event with the `function_end` event. This value is guaranteed to be the same value received by the trace event for the corresponding `function_begin` </li> <li> **user_data**: Name of the function being called sent in as `const char *` </li></div> | None |
313+
314+
## SYCL Stream `"sycl.experimental.level_zero.debug"` Notification Signatures
315+
316+
This stream transfers events about Level Zero API calls and their function
317+
arguments made by SYCL application.
318+
319+
| Trace Point Type | Parameter Description | Metadata |
320+
| :------------------------: | :-------------------- | :------- |
321+
| `function_with_args_begin` | <div style="text-align: left"><li>**trace_type**: `xpti::trace_point_type_t::function_with_args_begin` that marks the beginning of a function</li> <li> **parent**: Event ID created for all functions in the `sycl.pi.debug` layer.</li> <li> **event**: `nullptr` - since the stream of data just captures functions being called.</li> <li> **instance**: Unique ID to allow the correlation of the `function_with_args_begin` event with the `function_with_args_end` event. </li> <li> **user_data**: A pointer to `function_with_args_t` object, that includes function ID, name, and arguments. </li></div> | None |
322+
| `function_with_args_end` | <div style="text-align: left"><li>**trace_type**: `xpti::trace_point_type_t::function_with_args_end` that marks the beginning of a function</li> <li> **parent**: Event ID created for all functions in the `sycl.pi.debug` layer.</li> <li> **event**: `nullptr` - since the stream of data just captures functions being called.</li> <li> **instance**: Unique ID to allow the correlation of the `function_with_args_begin` event with the `function_with_args_end` event. This value is guaranteed to be the same value received by the trace event for the corresponding `function_with_args_begin` </li> <li> **user_data**: A pointer to `function_with_args_t` object, that includes function ID, name, arguments, and return value. </li></div> | None |

sycl/include/CL/sycl/backend.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#if SYCL_EXT_ONEAPI_BACKEND_CUDA
2121
#include <CL/sycl/detail/backend_traits_cuda.hpp>
2222
#endif
23+
#if SYCL_EXT_ONEAPI_BACKEND_HIP
24+
#include <CL/sycl/detail/backend_traits_hip.hpp>
25+
#endif
2326
#if SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
2427
#include <CL/sycl/detail/backend_traits_level_zero.hpp>
2528
#endif
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
//===------- backend_traits_hip.hpp - Backend traits for HIP ---*-C++ -*-===//
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+
// This file defines the specializations of the sycl::detail::interop,
10+
// sycl::detail::BackendInput and sycl::detail::BackendReturn class templates
11+
// for the HIP backend but there is no sycl::detail::InteropFeatureSupportMap
12+
// specialization for the HIP backend.
13+
//===----------------------------------------------------------------------===//
14+
15+
#pragma once
16+
17+
#include <CL/sycl/accessor.hpp>
18+
#include <CL/sycl/context.hpp>
19+
#include <CL/sycl/detail/backend_traits.hpp>
20+
#include <CL/sycl/device.hpp>
21+
#include <CL/sycl/event.hpp>
22+
#include <CL/sycl/kernel_bundle.hpp>
23+
#include <CL/sycl/queue.hpp>
24+
25+
typedef int HIPdevice;
26+
typedef struct ihipCtx_t *HIPcontext;
27+
typedef struct ihipStream_t *HIPstream;
28+
typedef struct ihipEvent_t *HIPevent;
29+
typedef struct ihipModule_t *HIPmodule;
30+
typedef void *HIPdeviceptr;
31+
32+
__SYCL_INLINE_NAMESPACE(cl) {
33+
namespace sycl {
34+
namespace detail {
35+
36+
// TODO the interops for context, device, event, platform and program
37+
// may be removed after removing the deprecated 'get_native()' methods
38+
// from the corresponding classes. The interop<backend, queue> specialization
39+
// is also used in the get_queue() method of the deprecated class
40+
// interop_handler and also can be removed after API cleanup.
41+
template <> struct interop<backend::ext_oneapi_hip, context> {
42+
using type = HIPcontext;
43+
};
44+
45+
template <> struct interop<backend::ext_oneapi_hip, device> {
46+
using type = HIPdevice;
47+
};
48+
49+
template <> struct interop<backend::ext_oneapi_hip, event> {
50+
using type = HIPevent;
51+
};
52+
53+
template <> struct interop<backend::ext_oneapi_hip, queue> {
54+
using type = HIPstream;
55+
};
56+
57+
#ifdef __SYCL_INTERNAL_API
58+
template <> struct interop<backend::ext_oneapi_hip, program> {
59+
using type = HIPmodule;
60+
};
61+
#endif
62+
63+
// TODO the interops for accessor is used in the already deprecated class
64+
// interop_handler and can be removed after API cleanup.
65+
template <typename DataT, int Dimensions, access::mode AccessMode>
66+
struct interop<backend::ext_oneapi_hip,
67+
accessor<DataT, Dimensions, AccessMode, access::target::device,
68+
access::placeholder::false_t>> {
69+
using type = HIPdeviceptr;
70+
};
71+
72+
template <typename DataT, int Dimensions, access::mode AccessMode>
73+
struct interop<
74+
backend::ext_oneapi_hip,
75+
accessor<DataT, Dimensions, AccessMode, access::target::constant_buffer,
76+
access::placeholder::false_t>> {
77+
using type = HIPdeviceptr;
78+
};
79+
80+
template <typename DataT, int Dimensions, typename AllocatorT>
81+
struct BackendInput<backend::ext_oneapi_hip,
82+
buffer<DataT, Dimensions, AllocatorT>> {
83+
using type = HIPdeviceptr;
84+
};
85+
86+
template <typename DataT, int Dimensions, typename AllocatorT>
87+
struct BackendReturn<backend::ext_oneapi_hip,
88+
buffer<DataT, Dimensions, AllocatorT>> {
89+
using type = HIPdeviceptr;
90+
};
91+
92+
template <> struct BackendInput<backend::ext_oneapi_hip, context> {
93+
using type = HIPcontext;
94+
};
95+
96+
template <> struct BackendReturn<backend::ext_oneapi_hip, context> {
97+
using type = HIPcontext;
98+
};
99+
100+
template <> struct BackendInput<backend::ext_oneapi_hip, device> {
101+
using type = HIPdevice;
102+
};
103+
104+
template <> struct BackendReturn<backend::ext_oneapi_hip, device> {
105+
using type = HIPdevice;
106+
};
107+
108+
template <> struct BackendInput<backend::ext_oneapi_hip, event> {
109+
using type = HIPevent;
110+
};
111+
112+
template <> struct BackendReturn<backend::ext_oneapi_hip, event> {
113+
using type = HIPevent;
114+
};
115+
116+
template <> struct BackendInput<backend::ext_oneapi_hip, queue> {
117+
using type = HIPstream;
118+
};
119+
120+
template <> struct BackendReturn<backend::ext_oneapi_hip, queue> {
121+
using type = HIPstream;
122+
};
123+
124+
#ifdef __SYCL_INTERNAL_API
125+
template <> struct BackendInput<backend::ext_oneapi_hip, program> {
126+
using type = HIPmodule;
127+
};
128+
129+
template <> struct BackendReturn<backend::ext_oneapi_hip, program> {
130+
using type = HIPmodule;
131+
};
132+
#endif
133+
134+
} // namespace detail
135+
} // namespace sycl
136+
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/plugins/hip/pi_hip.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2101,6 +2101,12 @@ pi_result hip_piMemGetInfo(pi_mem memObj, pi_mem_info queriedInfo,
21012101
/// \param[out] nativeHandle Set to the native handle of the PI mem object.
21022102
///
21032103
/// \return PI_SUCCESS
2104+
pi_result hip_piextMemGetNativeHandle(pi_mem mem,
2105+
pi_native_handle *nativeHandle) {
2106+
*nativeHandle =
2107+
reinterpret_cast<pi_native_handle>(mem->mem_.buffer_mem_.get());
2108+
return PI_SUCCESS;
2109+
}
21042110

21052111
/// Created a PI mem object from a HIP mem handle.
21062112
/// TODO: Implement this.
@@ -4910,7 +4916,7 @@ pi_result piPluginInit(pi_plugin *PluginInit) {
49104916
_PI_CL(piMemRetain, hip_piMemRetain)
49114917
_PI_CL(piMemRelease, hip_piMemRelease)
49124918
_PI_CL(piMemBufferPartition, hip_piMemBufferPartition)
4913-
//_PI_CL(piextMemGetNativeHandle, hip_piextMemGetNativeHandle)
4919+
_PI_CL(piextMemGetNativeHandle, hip_piextMemGetNativeHandle)
49144920
_PI_CL(piextMemCreateWithNativeHandle, hip_piextMemCreateWithNativeHandle)
49154921
// Program
49164922
_PI_CL(piProgramCreate, hip_piProgramCreate)

sycl/plugins/level_zero/CMakeLists.txt

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,46 @@ target_include_directories(LevelZeroLoader-Headers
9999
INTERFACE "${LEVEL_ZERO_INCLUDE_DIR}"
100100
)
101101

102-
find_package(Threads REQUIRED)
102+
if (SYCL_ENABLE_XPTI_TRACING)
103+
set(XPTI_PROXY_SRC "${CMAKE_SOURCE_DIR}/../xpti/src/xpti_proxy.cpp")
104+
endif()
105+
103106
add_sycl_plugin(level_zero
104107
SOURCES
105108
"${sycl_inc_dir}/CL/sycl/detail/pi.h"
106109
"${CMAKE_CURRENT_SOURCE_DIR}/pi_level_zero.cpp"
107110
"${CMAKE_CURRENT_SOURCE_DIR}/pi_level_zero.hpp"
108111
"${CMAKE_CURRENT_SOURCE_DIR}/usm_allocator.cpp"
109112
"${CMAKE_CURRENT_SOURCE_DIR}/usm_allocator.hpp"
113+
"${CMAKE_CURRENT_SOURCE_DIR}/tracing.cpp"
114+
${XPTI_PROXY_SRC}
110115
LIBRARIES
111116
"${LEVEL_ZERO_LOADER}"
112117
Threads::Threads
113118
)
114119

120+
find_package(Python3 REQUIRED)
121+
122+
add_custom_target(ze-api
123+
COMMAND ${Python3_EXECUTABLE}
124+
${CMAKE_CURRENT_SOURCE_DIR}/ze_api_generator.py
125+
${LEVEL_ZERO_INCLUDE_DIR}/level_zero/ze_api.h
126+
BYPRODUCTS
127+
${CMAKE_CURRENT_BINARY_DIR}/ze_api.def
128+
)
129+
target_include_directories(pi_level_zero PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
130+
add_dependencies(pi_level_zero ze-api)
131+
132+
if (SYCL_ENABLE_XPTI_TRACING)
133+
target_compile_definitions(pi_level_zero PRIVATE
134+
XPTI_ENABLE_INSTRUMENTATION
135+
XPTI_STATIC_LIBRARY
136+
)
137+
target_include_directories(pi_level_zero PRIVATE "${CMAKE_SOURCE_DIR}/../xpti/include")
138+
target_link_libraries(pi_level_zero PRIVATE ${CMAKE_DL_LIBS})
139+
endif()
140+
115141
if (TARGET level-zero-loader)
142+
add_dependencies(ze-api level-zero-loader)
116143
add_dependencies(pi_level_zero level-zero-loader)
117144
endif()
118-

sycl/plugins/level_zero/pi_level_zero.cpp

100644100755
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ static pi_result EventCreate(pi_context Context, pi_queue Queue,
3636
bool HostVisible, pi_event *RetEvent);
3737
}
3838

39+
// Defined in tracing.cpp
40+
void enableZeTracing();
41+
void disableZeTracing();
42+
3943
namespace {
4044

4145
// Controls Level Zero calls serialization to w/a Level Zero driver being not MT
@@ -7942,6 +7946,7 @@ pi_result piPluginInit(pi_plugin *PluginInit) {
79427946
(PluginInit->PiFunctionTable).api = (decltype(&::api))(&api);
79437947
#include <CL/sycl/detail/pi.def>
79447948

7949+
enableZeTracing();
79457950
return PI_SUCCESS;
79467951
}
79477952

@@ -8048,6 +8053,8 @@ pi_result piTearDown(void *PluginParameter) {
80488053
}
80498054
if (LeakFound)
80508055
return PI_INVALID_MEM_OBJECT;
8056+
8057+
disableZeTracing();
80518058
return PI_SUCCESS;
80528059
}
80538060

0 commit comments

Comments
 (0)