Skip to content

Commit 0cfec31

Browse files
author
Pavel Samolysov
authored
[SYCL][XPTI] Fix the build of SYCL without XPTI tracing (#5237)
Then the SYCL_ENABLE_XPTI_TRACING option is disabled, some compilation errors occur. The patch fixes such errors.
1 parent 53f1cce commit 0cfec31

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

sycl/source/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ configure_file(
1010
@ONLY)
1111

1212
if (SYCL_ENABLE_XPTI_TRACING)
13-
if (NOT EXISTS ${LLVM_EXTERNAL_XPTI_SOURCE_DIR})
13+
if (NOT DEFINED LLVM_EXTERNAL_XPTI_SOURCE_DIR)
1414
message (FATAL_ERROR "Undefined LLVM_EXTERNAL_XPTI_SOURCE_DIR variable: Must be set when XPTI tracing is set to ON")
1515
endif()
1616
include_directories(${LLVM_EXTERNAL_XPTI_SOURCE_DIR}/include)

sycl/source/detail/memory_manager.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ void emitMemAllocEndTrace(uintptr_t ObjHandle, uintptr_t AllocPtr,
7676
uint64_t emitMemReleaseBeginTrace(uintptr_t ObjHandle, uintptr_t AllocPtr) {
7777
(void)ObjHandle;
7878
(void)AllocPtr;
79-
#ifdef XPTI_ENABLE_INSTRUMENTATION
8079
uint64_t CorrelationID = 0;
80+
#ifdef XPTI_ENABLE_INSTRUMENTATION
8181
if (xptiTraceEnabled()) {
8282
xpti::mem_alloc_data_t MemAlloc{ObjHandle, AllocPtr, 0 /* alloc size */,
8383
0 /* guard zone */};
@@ -127,9 +127,12 @@ static void waitForEvents(const std::vector<EventImplPtr> &Events) {
127127
void memBufferCreateHelper(const plugin &Plugin, pi_context Ctx,
128128
pi_mem_flags Flags, size_t Size, void *HostPtr,
129129
pi_mem *RetMem, const pi_mem_properties *Props) {
130+
#ifdef XPTI_ENABLE_INSTRUMENTATION
130131
uint64_t CorrID = 0;
132+
#endif
131133
// We only want to instrument piMemBufferCreate
132134
{
135+
#ifdef XPTI_ENABLE_INSTRUMENTATION
133136
CorrID =
134137
emitMemAllocBeginTrace(0 /* mem object */, Size, 0 /* guard zone */);
135138
xpti::utils::finally _{[&] {
@@ -143,6 +146,7 @@ void memBufferCreateHelper(const plugin &Plugin, pi_context Ctx,
143146
emitMemAllocEndTrace(MemObjID, (uintptr_t)(Ptr), Size, 0 /* guard zone */,
144147
CorrID);
145148
}};
149+
#endif
146150
Plugin.call<PiApiKind::piMemBufferCreate>(Ctx, Flags, Size, HostPtr, RetMem,
147151
Props);
148152
}
@@ -152,6 +156,7 @@ void memReleaseHelper(const plugin &Plugin, pi_mem Mem) {
152156
// FIXME piMemRelease does not guarante memory release. It is only true if
153157
// reference counter is 1. However, SYCL runtime currently only calls
154158
// piMemRetain only for OpenCL interop
159+
#ifdef XPTI_ENABLE_INSTRUMENTATION
155160
uint64_t CorrID = 0;
156161
// C-style cast is required for MSVC
157162
uintptr_t MemObjID = (uintptr_t)(Mem);
@@ -162,11 +167,14 @@ void memReleaseHelper(const plugin &Plugin, pi_mem Mem) {
162167
Plugin.call<PiApiKind::piextMemGetNativeHandle>(Mem, &PtrHandle);
163168
Ptr = (uintptr_t)(PtrHandle);
164169
}
170+
#endif
165171
// We only want to instrument piMemRelease
166172
{
173+
#ifdef XPTI_ENABLE_INSTRUMENTATION
167174
CorrID = emitMemReleaseBeginTrace(MemObjID, Ptr);
168175
xpti::utils::finally _{
169176
[&] { emitMemReleaseEndTrace(MemObjID, Ptr, CorrID); }};
177+
#endif
170178
Plugin.call<PiApiKind::piMemRelease>(Mem);
171179
}
172180
}
@@ -176,15 +184,19 @@ void memBufferMapHelper(const plugin &Plugin, pi_queue Queue, pi_mem Buffer,
176184
size_t Size, pi_uint32 NumEvents,
177185
const pi_event *WaitList, pi_event *Event,
178186
void **RetMap) {
187+
#ifdef XPTI_ENABLE_INSTRUMENTATION
179188
uint64_t CorrID = 0;
180189
uintptr_t MemObjID = (uintptr_t)(Buffer);
190+
#endif
181191
// We only want to instrument piEnqueueMemBufferMap
182192
{
193+
#ifdef XPTI_ENABLE_INSTRUMENTATION
183194
CorrID = emitMemAllocBeginTrace(MemObjID, Size, 0 /* guard zone */);
184195
xpti::utils::finally _{[&] {
185196
emitMemAllocEndTrace(MemObjID, (uintptr_t)(*RetMap), Size,
186197
0 /* guard zone */, CorrID);
187198
}};
199+
#endif
188200
Plugin.call<PiApiKind::piEnqueueMemBufferMap>(
189201
Queue, Buffer, Blocking, Flags, Offset, Size, NumEvents, WaitList,
190202
Event, RetMap);
@@ -194,11 +206,14 @@ void memBufferMapHelper(const plugin &Plugin, pi_queue Queue, pi_mem Buffer,
194206
void memUnmapHelper(const plugin &Plugin, pi_queue Queue, pi_mem Mem,
195207
void *MappedPtr, pi_uint32 NumEvents,
196208
const pi_event *WaitList, pi_event *Event) {
209+
#ifdef XPTI_ENABLE_INSTRUMENTATION
197210
uint64_t CorrID = 0;
198211
uintptr_t MemObjID = (uintptr_t)(Mem);
199212
uintptr_t Ptr = (uintptr_t)(MappedPtr);
213+
#endif
200214
// We only want to instrument piEnqueueMemUnmap
201215
{
216+
#ifdef XPTI_ENABLE_INSTRUMENTATION
202217
CorrID = emitMemReleaseBeginTrace(MemObjID, Ptr);
203218
xpti::utils::finally _{[&] {
204219
// There's no way for SYCL to know, when the pointer is freed, so we have
@@ -210,6 +225,7 @@ void memUnmapHelper(const plugin &Plugin, pi_queue Queue, pi_mem Mem,
210225
Plugin.call_nocheck<PiApiKind::piEventsWait>(1, Event);
211226
emitMemReleaseEndTrace(MemObjID, Ptr, CorrID);
212227
}};
228+
#endif
213229
Plugin.call<PiApiKind::piEnqueueMemUnmap>(Queue, Mem, MappedPtr, NumEvents,
214230
WaitList, Event);
215231
}

0 commit comments

Comments
 (0)