diff --git a/sycl/source/detail/queue_impl.cpp b/sycl/source/detail/queue_impl.cpp index 9be486bba066b..848506ddf6dcb 100644 --- a/sycl/source/detail/queue_impl.cpp +++ b/sycl/source/detail/queue_impl.cpp @@ -121,9 +121,23 @@ event queue_impl::memset(const std::shared_ptr &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 &Self, void *Dest, const void *Src, size_t Count, - const std::vector &DepEvents) { + const std::vector &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 @@ -155,6 +169,11 @@ event queue_impl::memcpy(const std::shared_ptr &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); diff --git a/sycl/source/detail/queue_impl.hpp b/sycl/source/detail/queue_impl.hpp index a30a46bde31e0..9fd380e0ce3d8 100644 --- a/sycl/source/detail/queue_impl.hpp +++ b/sycl/source/detail/queue_impl.hpp @@ -616,7 +616,8 @@ class queue_impl { /// \return an event representing copy operation. event memcpy(const std::shared_ptr &Self, void *Dest, const void *Src, size_t Count, - const std::vector &DepEvents); + const std::vector &DepEvents, + const code_location &CodeLoc); /// Provides additional information to the underlying runtime about how /// different allocations are used. /// diff --git a/sycl/source/queue.cpp b/sycl/source/queue.cpp index 7b69e5bfe3001..ad71c12e89fca 100644 --- a/sycl/source/queue.cpp +++ b/sycl/source/queue.cpp @@ -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 &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, diff --git a/sycl/test-e2e/Basic/report_code_loc.cpp b/sycl/test-e2e/Basic/report_code_loc.cpp new file mode 100644 index 0000000000000..38019e7b4f133 --- /dev/null +++ b/sycl/test-e2e/Basic/report_code_loc.cpp @@ -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 +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(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 + } +}