Skip to content
21 changes: 20 additions & 1 deletion sycl/source/detail/queue_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,23 @@ event queue_impl::memset(const std::shared_ptr<detail::queue_impl> &Self,
return MDiscardEvents ? createDiscardedEvent() : ResEvent;
}

void report(const code_location &CodeLoc) {
std::cout << "Exception caught at ";
if (CodeLoc.fileName())
std::cout << "File: " << CodeLoc.fileName();
if (CodeLoc.functionName())
std::cout << " | Function: " << CodeLoc.functionName();
if (CodeLoc.lineNumber())
std::cout << " | Line: " << CodeLoc.lineNumber();
if (CodeLoc.columnNumber())
std::cout << " | Column: " << CodeLoc.columnNumber();
std::cout << '\n';
}

event queue_impl::memcpy(const std::shared_ptr<detail::queue_impl> &Self,
void *Dest, const void *Src, size_t Count,
const std::vector<event> &DepEvents) {
const std::vector<event> &DepEvents,
const code_location &CodeLoc) {
#if XPTI_ENABLE_INSTRUMENTATION
// We need a code pointer value and we duse the object ptr; If code location
// is available, we use the source file information along with the object
Expand Down Expand Up @@ -155,6 +169,11 @@ event queue_impl::memcpy(const std::shared_ptr<detail::queue_impl> &Self,
},
Self, {});
}
if ((!Src || !Dest) && Count != 0) {
report(CodeLoc);
throw runtime_error("NULL pointer argument in memory copy operation.",
PI_ERROR_INVALID_VALUE);
}
if (MHasDiscardEventsSupport) {
MemoryManager::copy_usm(Src, Self, Count, Dest,
getOrWaitEvents(DepEvents, MContext), nullptr);
Expand Down
3 changes: 2 additions & 1 deletion sycl/source/detail/queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,8 @@ class queue_impl {
/// \return an event representing copy operation.
event memcpy(const std::shared_ptr<queue_impl> &Self, void *Dest,
const void *Src, size_t Count,
const std::vector<event> &DepEvents);
const std::vector<event> &DepEvents,
const code_location &CodeLoc);
/// Provides additional information to the underlying runtime about how
/// different allocations are used.
///
Expand Down
6 changes: 3 additions & 3 deletions sycl/source/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,20 @@ event queue::memset(void *Ptr, int Value, size_t Count,
event queue::memcpy(void *Dest, const void *Src, size_t Count,
const detail::code_location &CodeLoc) {
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
return impl->memcpy(impl, Dest, Src, Count, {});
return impl->memcpy(impl, Dest, Src, Count, {}, CodeLoc);
}

event queue::memcpy(void *Dest, const void *Src, size_t Count, event DepEvent,
const detail::code_location &CodeLoc) {
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
return impl->memcpy(impl, Dest, Src, Count, {DepEvent});
return impl->memcpy(impl, Dest, Src, Count, {DepEvent}, CodeLoc);
}

event queue::memcpy(void *Dest, const void *Src, size_t Count,
const std::vector<event> &DepEvents,
const detail::code_location &CodeLoc) {
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
return impl->memcpy(impl, Dest, Src, Count, DepEvents);
return impl->memcpy(impl, Dest, Src, Count, DepEvents, CodeLoc);
}

event queue::mem_advise(const void *Ptr, size_t Length, pi_mem_advice Advice,
Expand Down
22 changes: 22 additions & 0 deletions sycl/test-e2e/Basic/report_code_loc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*This test checks that source information where an exception occured is
* reported*/

// RUN: %{build} -o %t.out
// RUN: env ZE_DEBUG=1 %{run} %t.out 2>&1 | FileCheck %s

#include <sycl/sycl.hpp>
using namespace sycl;
#define XFLOAT float
#define mdlXYZ 1000

int main() {
bool failed = true;
XFLOAT *mdlImag;
queue q{{property::queue::enable_profiling()}};
mdlImag = sycl::malloc_device<XFLOAT>(mdlXYZ, q);
try {
q.memcpy(mdlImag, 0, sizeof(XFLOAT));
} catch (...) {
// CHECK: Exception caught at File: {{.*}}report_code_loc.cpp | Function: main | Line: 18 | Column: 5
}
}