Skip to content

Commit fc0d28a

Browse files
authored
[SYCL][XPTI] Add missing buffer constructor data (#5259)
Extend information about created buffer: - Host object used to create buffer; - A string representing the type of buffer element; - Buffer element size in bytes - Buffer dimensions number. - Buffer size for each dimension. The test changes available in intel/llvm-test-suite#788
1 parent 375d213 commit fc0d28a

File tree

10 files changed

+151
-59
lines changed

10 files changed

+151
-59
lines changed

sycl/include/CL/sycl/buffer.hpp

+69-19
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,22 @@ class buffer {
7272
using EnableIfSameNonConstIterators = typename detail::enable_if_t<
7373
std::is_same<ItA, ItB>::value && !std::is_const<ItA>::value, ItA>;
7474

75+
std::array<size_t, 3> rangeToArray(range<3> &r) { return {r[0], r[1], r[2]}; }
76+
77+
std::array<size_t, 3> rangeToArray(range<2> &r) { return {r[0], r[1], 0}; }
78+
79+
std::array<size_t, 3> rangeToArray(range<1> &r) { return {r[0], 0, 0}; }
80+
7581
buffer(const range<dimensions> &bufferRange,
7682
const property_list &propList = {},
7783
const detail::code_location CodeLoc = detail::code_location::current())
7884
: Range(bufferRange) {
7985
impl = std::make_shared<detail::buffer_impl>(
8086
size() * sizeof(T), detail::getNextPowerOfTwo(sizeof(T)), propList,
8187
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>());
82-
impl->constructorNotification(CodeLoc, (void *)impl.get());
88+
impl->constructorNotification(CodeLoc, (void *)impl.get(), nullptr,
89+
(const void *)typeid(T).name(), dimensions,
90+
sizeof(T), rangeToArray(Range).data());
8391
}
8492

8593
buffer(const range<dimensions> &bufferRange, AllocatorT allocator,
@@ -90,7 +98,9 @@ class buffer {
9098
size() * sizeof(T), detail::getNextPowerOfTwo(sizeof(T)), propList,
9199
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(
92100
allocator));
93-
impl->constructorNotification(CodeLoc, (void *)impl.get());
101+
impl->constructorNotification(CodeLoc, (void *)impl.get(), nullptr,
102+
(const void *)typeid(T).name(), dimensions,
103+
sizeof(T), rangeToArray(Range).data());
94104
}
95105

96106
buffer(T *hostData, const range<dimensions> &bufferRange,
@@ -101,7 +111,9 @@ class buffer {
101111
hostData, size() * sizeof(T), detail::getNextPowerOfTwo(sizeof(T)),
102112
propList,
103113
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>());
104-
impl->constructorNotification(CodeLoc, (void *)impl.get());
114+
impl->constructorNotification(CodeLoc, (void *)impl.get(), hostData,
115+
(const void *)typeid(T).name(), dimensions,
116+
sizeof(T), rangeToArray(Range).data());
105117
}
106118

107119
buffer(T *hostData, const range<dimensions> &bufferRange,
@@ -113,7 +125,9 @@ class buffer {
113125
propList,
114126
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(
115127
allocator));
116-
impl->constructorNotification(CodeLoc, (void *)impl.get());
128+
impl->constructorNotification(CodeLoc, (void *)impl.get(), hostData,
129+
(const void *)typeid(T).name(), dimensions,
130+
sizeof(T), rangeToArray(Range).data());
117131
}
118132

119133
template <typename _T = T>
@@ -126,7 +140,9 @@ class buffer {
126140
hostData, size() * sizeof(T), detail::getNextPowerOfTwo(sizeof(T)),
127141
propList,
128142
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>());
129-
impl->constructorNotification(CodeLoc, (void *)impl.get());
143+
impl->constructorNotification(CodeLoc, (void *)impl.get(), hostData,
144+
(const void *)typeid(T).name(), dimensions,
145+
sizeof(T), rangeToArray(Range).data());
130146
}
131147

132148
template <typename _T = T>
@@ -140,7 +156,9 @@ class buffer {
140156
propList,
141157
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(
142158
allocator));
143-
impl->constructorNotification(CodeLoc, (void *)impl.get());
159+
impl->constructorNotification(CodeLoc, (void *)impl.get(), hostData,
160+
(const void *)typeid(T).name(), dimensions,
161+
sizeof(T), rangeToArray(Range).data());
144162
}
145163

146164
buffer(const std::shared_ptr<T> &hostData,
@@ -153,7 +171,10 @@ class buffer {
153171
propList,
154172
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(
155173
allocator));
156-
impl->constructorNotification(CodeLoc, (void *)impl.get());
174+
impl->constructorNotification(CodeLoc, (void *)impl.get(),
175+
(void *)hostData.get(),
176+
(const void *)typeid(T).name(), dimensions,
177+
sizeof(T), rangeToArray(Range).data());
157178
}
158179

159180
buffer(const std::shared_ptr<T[]> &hostData,
@@ -166,7 +187,10 @@ class buffer {
166187
propList,
167188
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(
168189
allocator));
169-
impl->constructorNotification(CodeLoc, (void *)impl.get());
190+
impl->constructorNotification(CodeLoc, (void *)impl.get(),
191+
(void *)hostData.get(),
192+
(const void *)typeid(T).name(), dimensions,
193+
sizeof(T), rangeToArray(Range).data());
170194
}
171195

172196
buffer(const std::shared_ptr<T> &hostData,
@@ -178,7 +202,10 @@ class buffer {
178202
hostData, size() * sizeof(T), detail::getNextPowerOfTwo(sizeof(T)),
179203
propList,
180204
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>());
181-
impl->constructorNotification(CodeLoc, (void *)impl.get());
205+
impl->constructorNotification(CodeLoc, (void *)impl.get(),
206+
(void *)hostData.get(),
207+
(const void *)typeid(T).name(), dimensions,
208+
sizeof(T), rangeToArray(Range).data());
182209
}
183210

184211
buffer(const std::shared_ptr<T[]> &hostData,
@@ -190,7 +217,10 @@ class buffer {
190217
hostData, size() * sizeof(T), detail::getNextPowerOfTwo(sizeof(T)),
191218
propList,
192219
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>());
193-
impl->constructorNotification(CodeLoc, (void *)impl.get());
220+
impl->constructorNotification(CodeLoc, (void *)impl.get(),
221+
(void *)hostData.get(),
222+
(const void *)typeid(T).name(), dimensions,
223+
sizeof(T), rangeToArray(Range).data());
194224
}
195225

196226
template <class InputIterator, int N = dimensions,
@@ -205,7 +235,9 @@ class buffer {
205235
propList,
206236
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(
207237
allocator));
208-
impl->constructorNotification(CodeLoc, (void *)impl.get());
238+
impl->constructorNotification(CodeLoc, (void *)impl.get(), &*first,
239+
(const void *)typeid(T).name(), dimensions,
240+
sizeof(T), {Range[0], 0, 0});
209241
}
210242

211243
template <class InputIterator, int N = dimensions,
@@ -219,7 +251,10 @@ class buffer {
219251
first, last, size() * sizeof(T), detail::getNextPowerOfTwo(sizeof(T)),
220252
propList,
221253
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>());
222-
impl->constructorNotification(CodeLoc, (void *)impl.get());
254+
size_t r[3] = {Range[0], 0, 0};
255+
impl->constructorNotification(CodeLoc, (void *)impl.get(), &*first,
256+
(const void *)typeid(T).name(), dimensions,
257+
sizeof(T), r);
223258
}
224259

225260
// This constructor is a prototype for a future SYCL specification
@@ -235,7 +270,10 @@ class buffer {
235270
detail::getNextPowerOfTwo(sizeof(T)), propList,
236271
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(
237272
allocator));
238-
impl->constructorNotification(CodeLoc, (void *)impl.get());
273+
size_t r[3] = {Range[0], 0, 0};
274+
impl->constructorNotification(CodeLoc, (void *)impl.get(), container.data(),
275+
(const void *)typeid(T).name(), dimensions,
276+
sizeof(T), r);
239277
}
240278

241279
// This constructor is a prototype for a future SYCL specification
@@ -252,7 +290,9 @@ class buffer {
252290
: impl(b.impl), Range(subRange),
253291
OffsetInBytes(getOffsetInBytes<T>(baseIndex, b.Range)),
254292
IsSubBuffer(true) {
255-
impl->constructorNotification(CodeLoc, (void *)impl.get());
293+
impl->constructorNotification(CodeLoc, (void *)impl.get(), impl.get(),
294+
(const void *)typeid(T).name(), dimensions,
295+
sizeof(T), rangeToArray(Range).data());
256296

257297
if (b.is_sub_buffer())
258298
throw cl::sycl::invalid_object_error(
@@ -281,22 +321,28 @@ class buffer {
281321
detail::pi::cast<pi_native_handle>(MemObject), SyclContext, BufSize,
282322
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(),
283323
AvailableEvent);
284-
impl->constructorNotification(CodeLoc, (void *)impl.get());
324+
impl->constructorNotification(CodeLoc, (void *)impl.get(), &MemObject,
325+
(const void *)typeid(T).name(), dimensions,
326+
sizeof(T), rangeToArray(Range).data());
285327
}
286328
#endif
287329

288330
buffer(const buffer &rhs,
289331
const detail::code_location CodeLoc = detail::code_location::current())
290332
: impl(rhs.impl), Range(rhs.Range), OffsetInBytes(rhs.OffsetInBytes),
291333
IsSubBuffer(rhs.IsSubBuffer) {
292-
impl->constructorNotification(CodeLoc, (void *)impl.get());
334+
impl->constructorNotification(CodeLoc, (void *)impl.get(), impl.get(),
335+
(const void *)typeid(T).name(), dimensions,
336+
sizeof(T), rangeToArray(Range).data());
293337
}
294338

295339
buffer(buffer &&rhs,
296340
const detail::code_location CodeLoc = detail::code_location::current())
297341
: impl(std::move(rhs.impl)), Range(rhs.Range),
298342
OffsetInBytes(rhs.OffsetInBytes), IsSubBuffer(rhs.IsSubBuffer) {
299-
impl->constructorNotification(CodeLoc, (void *)impl.get());
343+
impl->constructorNotification(CodeLoc, (void *)impl.get(), impl.get(),
344+
(const void *)typeid(T).name(), dimensions,
345+
sizeof(T), rangeToArray(Range).data());
300346
}
301347

302348
buffer &operator=(const buffer &rhs) = default;
@@ -485,7 +531,9 @@ class buffer {
485531
MemObject, SyclContext, BufSize,
486532
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(),
487533
AvailableEvent);
488-
impl->constructorNotification(CodeLoc, (void *)impl.get());
534+
impl->constructorNotification(CodeLoc, (void *)impl.get(), &MemObject,
535+
(const void *)typeid(T).name(), dimensions,
536+
sizeof(T), rangeToArray(Range).data());
489537
}
490538

491539
// Reinterpret contructor
@@ -495,7 +543,9 @@ class buffer {
495543
const detail::code_location CodeLoc = detail::code_location::current())
496544
: impl(Impl), Range(reinterpretRange), OffsetInBytes(reinterpretOffset),
497545
IsSubBuffer(isSubBuffer) {
498-
impl->constructorNotification(CodeLoc, (void *)impl.get());
546+
impl->constructorNotification(CodeLoc, (void *)impl.get(), Impl.get(),
547+
(const void *)typeid(T).name(), dimensions,
548+
sizeof(T), rangeToArray(Range).data());
499549
}
500550

501551
template <typename Type, int N>

sycl/include/CL/sycl/detail/buffer_impl.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ class __SYCL_EXPORT buffer_impl final : public SYCLMemObjT {
155155

156156
void *allocateMem(ContextImplPtr Context, bool InitFromUserData,
157157
void *HostPtr, RT::PiEvent &OutEventToWait) override;
158+
void constructorNotification(const detail::code_location &CodeLoc,
159+
void *UserObj, const void *HostObj,
160+
const void *Type, uint32_t Dim,
161+
uint32_t ElemType, size_t Range[3]);
162+
// TODO: remove once ABI break is allowed
158163
void constructorNotification(const detail::code_location &CodeLoc,
159164
void *UserObj);
160165
void destructorNotification(void *UserObj);

sycl/source/detail/buffer_impl.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,20 @@ void *buffer_impl::allocateMem(ContextImplPtr Context, bool InitFromUserData,
3131
std::move(Context), this, HostPtr, HostPtrReadOnly, BaseT::getSize(),
3232
BaseT::MInteropEvent, BaseT::MInteropContext, MProps, OutEventToWait);
3333
}
34+
void buffer_impl::constructorNotification(const detail::code_location &CodeLoc,
35+
void *UserObj, const void *HostObj,
36+
const void *Type, uint32_t Dim,
37+
uint32_t ElemSize, size_t Range[3]) {
38+
XPTIRegistry::bufferConstructorNotification(UserObj, CodeLoc, HostObj, Type,
39+
Dim, ElemSize, Range);
40+
}
41+
// TODO: remove once ABI break is allowed
3442
void buffer_impl::constructorNotification(const detail::code_location &CodeLoc,
3543
void *UserObj) {
36-
XPTIRegistry::bufferConstructorNotification(UserObj, CodeLoc);
44+
size_t r[3] = {0, 0, 0};
45+
constructorNotification(CodeLoc, UserObj, nullptr, "", 0, 0, r);
3746
}
47+
3848
void buffer_impl::destructorNotification(void *UserObj) {
3949
XPTIRegistry::bufferDestructorNotification(UserObj);
4050
}

sycl/source/detail/memory_manager.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ void *MemoryManager::allocateHostMemory(SYCLMemObjI *MemObj, void *UserPtr,
298298
return UserPtr;
299299

300300
void *NewMem = MemObj->allocateHostMem();
301-
302301
// Need to initialize new memory if user provides pointer to read only
303302
// memory.
304303
if (UserPtr && HostPtrReadOnly == true)

sycl/source/detail/xpti_registry.cpp

+30-23
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,15 @@ __SYCL_INLINE_NAMESPACE(cl) {
1717
namespace sycl {
1818
namespace detail {
1919
#ifdef XPTI_ENABLE_INSTRUMENTATION
20-
xpti::trace_event_data_t *
21-
XPTIRegistry::createTraceEvent(void *Obj, const char *ObjName, uint64_t &IId,
22-
const detail::code_location &CodeLoc,
23-
uint16_t TraceEventType) {
24-
std::string Name;
25-
if (CodeLoc.fileName()) {
26-
Name = std::string(CodeLoc.fileName()) + ":" +
27-
std::to_string(CodeLoc.lineNumber()) + ":" +
28-
std::to_string(CodeLoc.columnNumber());
29-
} else {
30-
xpti::utils::StringHelper NG;
31-
Name = NG.nameWithAddress<void *>(ObjName, Obj);
32-
}
33-
xpti::payload_t Payload(
34-
Name.c_str(), (CodeLoc.fileName() ? CodeLoc.fileName() : ""),
35-
CodeLoc.lineNumber(), CodeLoc.columnNumber(), (void *)Obj);
20+
xpti::trace_event_data_t *XPTIRegistry::createTraceEvent(
21+
const void *Obj, const void *FuncPtr, uint64_t &IId,
22+
const detail::code_location &CodeLoc, uint16_t TraceEventType) {
23+
xpti::utils::StringHelper NG;
24+
auto Name = NG.nameWithAddress<void *>(CodeLoc.functionName(),
25+
const_cast<void *>(FuncPtr));
26+
xpti::payload_t Payload(Name.c_str(),
27+
(CodeLoc.fileName() ? CodeLoc.fileName() : ""),
28+
CodeLoc.lineNumber(), CodeLoc.columnNumber(), Obj);
3629

3730
// Calls could be at different user-code locations; We create a new event
3831
// based on the code location info and if this has been seen before, a
@@ -43,16 +36,28 @@ XPTIRegistry::createTraceEvent(void *Obj, const char *ObjName, uint64_t &IId,
4336
#endif // XPTI_ENABLE_INSTRUMENTATION
4437

4538
void XPTIRegistry::bufferConstructorNotification(
46-
void *UserObj, const detail::code_location &CodeLoc) {
39+
const void *UserObj, const detail::code_location &CodeLoc,
40+
const void *HostObj, const void *Type, uint32_t Dim, uint32_t ElemSize,
41+
size_t Range[3]) {
4742
(void)UserObj;
4843
(void)CodeLoc;
44+
(void)HostObj;
45+
(void)Type;
46+
(void)Dim;
47+
(void)ElemSize;
48+
(void)Range;
4949
#ifdef XPTI_ENABLE_INSTRUMENTATION
5050
GlobalHandler::instance().getXPTIRegistry().initializeFrameworkOnce();
5151
if (!xptiTraceEnabled())
5252
return;
5353

5454
uint64_t IId;
55-
xpti::offload_buffer_data_t BufConstr{(uintptr_t)UserObj};
55+
xpti::offload_buffer_data_t BufConstr{(uintptr_t)UserObj,
56+
(uintptr_t)HostObj,
57+
(const char *)Type,
58+
ElemSize,
59+
Dim,
60+
{Range[0], Range[1], Range[2]}};
5661

5762
xpti::trace_event_data_t *TraceEvent = createTraceEvent(
5863
UserObj, "buffer", IId, CodeLoc, xpti::trace_offload_buffer_event);
@@ -61,7 +66,8 @@ void XPTIRegistry::bufferConstructorNotification(
6166
#endif
6267
}
6368

64-
void XPTIRegistry::bufferAssociateNotification(void *UserObj, void *MemObj) {
69+
void XPTIRegistry::bufferAssociateNotification(const void *UserObj,
70+
const void *MemObj) {
6571
(void)UserObj;
6672
(void)MemObj;
6773
#ifdef XPTI_ENABLE_INSTRUMENTATION
@@ -77,7 +83,8 @@ void XPTIRegistry::bufferAssociateNotification(void *UserObj, void *MemObj) {
7783
#endif
7884
}
7985

80-
void XPTIRegistry::bufferReleaseNotification(void *UserObj, void *MemObj) {
86+
void XPTIRegistry::bufferReleaseNotification(const void *UserObj,
87+
const void *MemObj) {
8188
(void)UserObj;
8289
(void)MemObj;
8390
#ifdef XPTI_ENABLE_INSTRUMENTATION
@@ -93,7 +100,7 @@ void XPTIRegistry::bufferReleaseNotification(void *UserObj, void *MemObj) {
93100
#endif
94101
}
95102

96-
void XPTIRegistry::bufferDestructorNotification(void *UserObj) {
103+
void XPTIRegistry::bufferDestructorNotification(const void *UserObj) {
97104
(void)UserObj;
98105
#ifdef XPTI_ENABLE_INSTRUMENTATION
99106
if (!xptiTraceEnabled())
@@ -107,8 +114,8 @@ void XPTIRegistry::bufferDestructorNotification(void *UserObj) {
107114
}
108115

109116
void XPTIRegistry::bufferAccessorNotification(
110-
void *UserObj, void *AccessorObj, uint32_t Target, uint32_t Mode,
111-
const detail::code_location &CodeLoc) {
117+
const void *UserObj, const void *AccessorObj, uint32_t Target,
118+
uint32_t Mode, const detail::code_location &CodeLoc) {
112119
(void)UserObj;
113120
(void)AccessorObj;
114121
(void)CodeLoc;

0 commit comments

Comments
 (0)