Skip to content

[SYCL][XPTI] Add missing buffer constructor data #5259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 69 additions & 19 deletions sycl/include/CL/sycl/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,22 @@ class buffer {
using EnableIfSameNonConstIterators = typename detail::enable_if_t<
std::is_same<ItA, ItB>::value && !std::is_const<ItA>::value, ItA>;

std::array<size_t, 3> rangeToArray(range<3> &r) { return {r[0], r[1], r[2]}; }

std::array<size_t, 3> rangeToArray(range<2> &r) { return {r[0], r[1], 0}; }

std::array<size_t, 3> rangeToArray(range<1> &r) { return {r[0], 0, 0}; }

buffer(const range<dimensions> &bufferRange,
const property_list &propList = {},
const detail::code_location CodeLoc = detail::code_location::current())
: Range(bufferRange) {
impl = std::make_shared<detail::buffer_impl>(
size() * sizeof(T), detail::getNextPowerOfTwo(sizeof(T)), propList,
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>());
impl->constructorNotification(CodeLoc, (void *)impl.get());
impl->constructorNotification(CodeLoc, (void *)impl.get(), nullptr,
(const void *)typeid(T).name(), dimensions,
sizeof(T), rangeToArray(Range).data());
}

buffer(const range<dimensions> &bufferRange, AllocatorT allocator,
Expand All @@ -90,7 +98,9 @@ class buffer {
size() * sizeof(T), detail::getNextPowerOfTwo(sizeof(T)), propList,
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(
allocator));
impl->constructorNotification(CodeLoc, (void *)impl.get());
impl->constructorNotification(CodeLoc, (void *)impl.get(), nullptr,
(const void *)typeid(T).name(), dimensions,
sizeof(T), rangeToArray(Range).data());
}

buffer(T *hostData, const range<dimensions> &bufferRange,
Expand All @@ -101,7 +111,9 @@ class buffer {
hostData, size() * sizeof(T), detail::getNextPowerOfTwo(sizeof(T)),
propList,
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>());
impl->constructorNotification(CodeLoc, (void *)impl.get());
impl->constructorNotification(CodeLoc, (void *)impl.get(), hostData,
(const void *)typeid(T).name(), dimensions,
sizeof(T), rangeToArray(Range).data());
}

buffer(T *hostData, const range<dimensions> &bufferRange,
Expand All @@ -113,7 +125,9 @@ class buffer {
propList,
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(
allocator));
impl->constructorNotification(CodeLoc, (void *)impl.get());
impl->constructorNotification(CodeLoc, (void *)impl.get(), hostData,
(const void *)typeid(T).name(), dimensions,
sizeof(T), rangeToArray(Range).data());
}

template <typename _T = T>
Expand All @@ -126,7 +140,9 @@ class buffer {
hostData, size() * sizeof(T), detail::getNextPowerOfTwo(sizeof(T)),
propList,
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>());
impl->constructorNotification(CodeLoc, (void *)impl.get());
impl->constructorNotification(CodeLoc, (void *)impl.get(), hostData,
(const void *)typeid(T).name(), dimensions,
sizeof(T), rangeToArray(Range).data());
}

template <typename _T = T>
Expand All @@ -140,7 +156,9 @@ class buffer {
propList,
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(
allocator));
impl->constructorNotification(CodeLoc, (void *)impl.get());
impl->constructorNotification(CodeLoc, (void *)impl.get(), hostData,
(const void *)typeid(T).name(), dimensions,
sizeof(T), rangeToArray(Range).data());
}

buffer(const std::shared_ptr<T> &hostData,
Expand All @@ -153,7 +171,10 @@ class buffer {
propList,
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(
allocator));
impl->constructorNotification(CodeLoc, (void *)impl.get());
impl->constructorNotification(CodeLoc, (void *)impl.get(),
(void *)hostData.get(),
(const void *)typeid(T).name(), dimensions,
sizeof(T), rangeToArray(Range).data());
}

buffer(const std::shared_ptr<T[]> &hostData,
Expand All @@ -166,7 +187,10 @@ class buffer {
propList,
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(
allocator));
impl->constructorNotification(CodeLoc, (void *)impl.get());
impl->constructorNotification(CodeLoc, (void *)impl.get(),
(void *)hostData.get(),
(const void *)typeid(T).name(), dimensions,
sizeof(T), rangeToArray(Range).data());
}

buffer(const std::shared_ptr<T> &hostData,
Expand All @@ -178,7 +202,10 @@ class buffer {
hostData, size() * sizeof(T), detail::getNextPowerOfTwo(sizeof(T)),
propList,
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>());
impl->constructorNotification(CodeLoc, (void *)impl.get());
impl->constructorNotification(CodeLoc, (void *)impl.get(),
(void *)hostData.get(),
(const void *)typeid(T).name(), dimensions,
sizeof(T), rangeToArray(Range).data());
}

buffer(const std::shared_ptr<T[]> &hostData,
Expand All @@ -190,7 +217,10 @@ class buffer {
hostData, size() * sizeof(T), detail::getNextPowerOfTwo(sizeof(T)),
propList,
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>());
impl->constructorNotification(CodeLoc, (void *)impl.get());
impl->constructorNotification(CodeLoc, (void *)impl.get(),
(void *)hostData.get(),
(const void *)typeid(T).name(), dimensions,
sizeof(T), rangeToArray(Range).data());
}

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

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

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

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

if (b.is_sub_buffer())
throw cl::sycl::invalid_object_error(
Expand Down Expand Up @@ -281,22 +321,28 @@ class buffer {
detail::pi::cast<pi_native_handle>(MemObject), SyclContext, BufSize,
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(),
AvailableEvent);
impl->constructorNotification(CodeLoc, (void *)impl.get());
impl->constructorNotification(CodeLoc, (void *)impl.get(), &MemObject,
(const void *)typeid(T).name(), dimensions,
sizeof(T), rangeToArray(Range).data());
}
#endif

buffer(const buffer &rhs,
const detail::code_location CodeLoc = detail::code_location::current())
: impl(rhs.impl), Range(rhs.Range), OffsetInBytes(rhs.OffsetInBytes),
IsSubBuffer(rhs.IsSubBuffer) {
impl->constructorNotification(CodeLoc, (void *)impl.get());
impl->constructorNotification(CodeLoc, (void *)impl.get(), impl.get(),
(const void *)typeid(T).name(), dimensions,
sizeof(T), rangeToArray(Range).data());
}

buffer(buffer &&rhs,
const detail::code_location CodeLoc = detail::code_location::current())
: impl(std::move(rhs.impl)), Range(rhs.Range),
OffsetInBytes(rhs.OffsetInBytes), IsSubBuffer(rhs.IsSubBuffer) {
impl->constructorNotification(CodeLoc, (void *)impl.get());
impl->constructorNotification(CodeLoc, (void *)impl.get(), impl.get(),
(const void *)typeid(T).name(), dimensions,
sizeof(T), rangeToArray(Range).data());
}

buffer &operator=(const buffer &rhs) = default;
Expand Down Expand Up @@ -485,7 +531,9 @@ class buffer {
MemObject, SyclContext, BufSize,
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(),
AvailableEvent);
impl->constructorNotification(CodeLoc, (void *)impl.get());
impl->constructorNotification(CodeLoc, (void *)impl.get(), &MemObject,
(const void *)typeid(T).name(), dimensions,
sizeof(T), rangeToArray(Range).data());
}

// Reinterpret contructor
Expand All @@ -495,7 +543,9 @@ class buffer {
const detail::code_location CodeLoc = detail::code_location::current())
: impl(Impl), Range(reinterpretRange), OffsetInBytes(reinterpretOffset),
IsSubBuffer(isSubBuffer) {
impl->constructorNotification(CodeLoc, (void *)impl.get());
impl->constructorNotification(CodeLoc, (void *)impl.get(), Impl.get(),
(const void *)typeid(T).name(), dimensions,
sizeof(T), rangeToArray(Range).data());
}

template <typename Type, int N>
Expand Down
5 changes: 5 additions & 0 deletions sycl/include/CL/sycl/detail/buffer_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ class __SYCL_EXPORT buffer_impl final : public SYCLMemObjT {

void *allocateMem(ContextImplPtr Context, bool InitFromUserData,
void *HostPtr, RT::PiEvent &OutEventToWait) override;
void constructorNotification(const detail::code_location &CodeLoc,
void *UserObj, const void *HostObj,
const void *Type, uint32_t Dim,
uint32_t ElemType, size_t Range[3]);
// TODO: remove once ABI break is allowed
void constructorNotification(const detail::code_location &CodeLoc,
void *UserObj);
void destructorNotification(void *UserObj);
Expand Down
12 changes: 11 additions & 1 deletion sycl/source/detail/buffer_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,20 @@ void *buffer_impl::allocateMem(ContextImplPtr Context, bool InitFromUserData,
std::move(Context), this, HostPtr, HostPtrReadOnly, BaseT::getSize(),
BaseT::MInteropEvent, BaseT::MInteropContext, MProps, OutEventToWait);
}
void buffer_impl::constructorNotification(const detail::code_location &CodeLoc,
void *UserObj, const void *HostObj,
const void *Type, uint32_t Dim,
uint32_t ElemSize, size_t Range[3]) {
XPTIRegistry::bufferConstructorNotification(UserObj, CodeLoc, HostObj, Type,
Dim, ElemSize, Range);
}
// TODO: remove once ABI break is allowed
void buffer_impl::constructorNotification(const detail::code_location &CodeLoc,
void *UserObj) {
XPTIRegistry::bufferConstructorNotification(UserObj, CodeLoc);
size_t r[3] = {0, 0, 0};
constructorNotification(CodeLoc, UserObj, nullptr, "", 0, 0, r);
}

void buffer_impl::destructorNotification(void *UserObj) {
XPTIRegistry::bufferDestructorNotification(UserObj);
}
Expand Down
1 change: 0 additions & 1 deletion sycl/source/detail/memory_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ void *MemoryManager::allocateHostMemory(SYCLMemObjI *MemObj, void *UserPtr,
return UserPtr;

void *NewMem = MemObj->allocateHostMem();

// Need to initialize new memory if user provides pointer to read only
// memory.
if (UserPtr && HostPtrReadOnly == true)
Expand Down
53 changes: 30 additions & 23 deletions sycl/source/detail/xpti_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,15 @@ __SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {
namespace detail {
#ifdef XPTI_ENABLE_INSTRUMENTATION
xpti::trace_event_data_t *
XPTIRegistry::createTraceEvent(void *Obj, const char *ObjName, uint64_t &IId,
const detail::code_location &CodeLoc,
uint16_t TraceEventType) {
std::string Name;
if (CodeLoc.fileName()) {
Name = std::string(CodeLoc.fileName()) + ":" +
std::to_string(CodeLoc.lineNumber()) + ":" +
std::to_string(CodeLoc.columnNumber());
} else {
xpti::utils::StringHelper NG;
Name = NG.nameWithAddress<void *>(ObjName, Obj);
}
xpti::payload_t Payload(
Name.c_str(), (CodeLoc.fileName() ? CodeLoc.fileName() : ""),
CodeLoc.lineNumber(), CodeLoc.columnNumber(), (void *)Obj);
xpti::trace_event_data_t *XPTIRegistry::createTraceEvent(
const void *Obj, const void *FuncPtr, uint64_t &IId,
const detail::code_location &CodeLoc, uint16_t TraceEventType) {
xpti::utils::StringHelper NG;
auto Name = NG.nameWithAddress<void *>(CodeLoc.functionName(),
const_cast<void *>(FuncPtr));
xpti::payload_t Payload(Name.c_str(),
(CodeLoc.fileName() ? CodeLoc.fileName() : ""),
CodeLoc.lineNumber(), CodeLoc.columnNumber(), Obj);

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

void XPTIRegistry::bufferConstructorNotification(
void *UserObj, const detail::code_location &CodeLoc) {
const void *UserObj, const detail::code_location &CodeLoc,
const void *HostObj, const void *Type, uint32_t Dim, uint32_t ElemSize,
size_t Range[3]) {
(void)UserObj;
(void)CodeLoc;
(void)HostObj;
(void)Type;
(void)Dim;
(void)ElemSize;
(void)Range;
#ifdef XPTI_ENABLE_INSTRUMENTATION
GlobalHandler::instance().getXPTIRegistry().initializeFrameworkOnce();
if (!xptiTraceEnabled())
return;

uint64_t IId;
xpti::offload_buffer_data_t BufConstr{(uintptr_t)UserObj};
xpti::offload_buffer_data_t BufConstr{(uintptr_t)UserObj,
(uintptr_t)HostObj,
(const char *)Type,
ElemSize,
Dim,
{Range[0], Range[1], Range[2]}};

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

void XPTIRegistry::bufferAssociateNotification(void *UserObj, void *MemObj) {
void XPTIRegistry::bufferAssociateNotification(const void *UserObj,
const void *MemObj) {
(void)UserObj;
(void)MemObj;
#ifdef XPTI_ENABLE_INSTRUMENTATION
Expand All @@ -77,7 +83,8 @@ void XPTIRegistry::bufferAssociateNotification(void *UserObj, void *MemObj) {
#endif
}

void XPTIRegistry::bufferReleaseNotification(void *UserObj, void *MemObj) {
void XPTIRegistry::bufferReleaseNotification(const void *UserObj,
const void *MemObj) {
(void)UserObj;
(void)MemObj;
#ifdef XPTI_ENABLE_INSTRUMENTATION
Expand All @@ -93,7 +100,7 @@ void XPTIRegistry::bufferReleaseNotification(void *UserObj, void *MemObj) {
#endif
}

void XPTIRegistry::bufferDestructorNotification(void *UserObj) {
void XPTIRegistry::bufferDestructorNotification(const void *UserObj) {
(void)UserObj;
#ifdef XPTI_ENABLE_INSTRUMENTATION
if (!xptiTraceEnabled())
Expand All @@ -107,8 +114,8 @@ void XPTIRegistry::bufferDestructorNotification(void *UserObj) {
}

void XPTIRegistry::bufferAccessorNotification(
void *UserObj, void *AccessorObj, uint32_t Target, uint32_t Mode,
const detail::code_location &CodeLoc) {
const void *UserObj, const void *AccessorObj, uint32_t Target,
uint32_t Mode, const detail::code_location &CodeLoc) {
(void)UserObj;
(void)AccessorObj;
(void)CodeLoc;
Expand Down
Loading