Skip to content

[SYCL] Introduce sycl-sanitizer tool #4174

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

Closed
wants to merge 7 commits into from
Closed
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
3 changes: 3 additions & 0 deletions sycl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ endif()

if (SYCL_ENABLE_XPTI_TRACING)
set(XPTIFW_LIBS xpti xptifw)
set(SYCL_TOOLS sycl-sanitizer)
endif()

# SYCL toolchain builds all components: compiler, libraries, headers, etc.
Expand All @@ -215,6 +216,7 @@ add_custom_target( sycl-toolchain
sycl-compiler
sycl-ls
${XPTIFW_LIBS}
${SYCL_TOOLS}
COMMENT "Building SYCL compiler toolchain..."
)

Expand Down Expand Up @@ -277,6 +279,7 @@ set( SYCL_TOOLCHAIN_DEPLOY_COMPONENTS
pi_level_zero
libsycldevice
${XPTIFW_LIBS}
${SYCL_TOOLS}
)

if(OpenCL_INSTALL_KHRONOS_ICD_LOADER AND TARGET OpenCL-ICD)
Expand Down
10 changes: 7 additions & 3 deletions sycl/include/CL/sycl/detail/usm_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// ===--------------------------------------------------------------------=== //
#pragma once

#include <CL/sycl/detail/common.hpp>
#include <CL/sycl/detail/export.hpp>
#include <CL/sycl/usm/usm_enums.hpp>

Expand All @@ -17,13 +18,16 @@ namespace usm {

__SYCL_EXPORT void *alignedAlloc(size_t Alignment, size_t Bytes,
const context &Ctxt, const device &Dev,
cl::sycl::usm::alloc Kind);
cl::sycl::usm::alloc Kind,
const code_location &CL);

__SYCL_EXPORT void *alignedAllocHost(size_t Alignment, size_t Bytes,
const context &Ctxt,
cl::sycl::usm::alloc Kind);
cl::sycl::usm::alloc Kind,
const code_location &CL);

__SYCL_EXPORT void free(void *Ptr, const context &Ctxt);
__SYCL_EXPORT void free(void *Ptr, const context &Ctxt,
const code_location &CL);

} // namespace usm
} // namespace detail
Expand Down
330 changes: 197 additions & 133 deletions sycl/include/CL/sycl/usm.hpp

Large diffs are not rendered by default.

18 changes: 12 additions & 6 deletions sycl/include/CL/sycl/usm/usm_allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#pragma once

#include <CL/sycl/context.hpp>
#include <CL/sycl/detail/common.hpp>
#include <CL/sycl/detail/export.hpp>
#include <CL/sycl/device.hpp>
#include <CL/sycl/exception.hpp>
Expand All @@ -24,8 +25,10 @@ namespace sycl {
__SYCL_EXPORT void *aligned_alloc(size_t alignment, size_t size,
const device &dev, const context &ctxt,
usm::alloc kind,
const property_list &propList);
__SYCL_EXPORT void free(void *ptr, const context &ctxt);
const property_list &propList,
const detail::code_location CL);
__SYCL_EXPORT void free(void *ptr, const context &ctxt,
const detail::code_location CL);

template <typename T, usm::alloc AllocKind, size_t Alignment = alignof(T)>
class usm_allocator {
Expand Down Expand Up @@ -74,11 +77,12 @@ class usm_allocator {
/// Allocates memory.
///
/// \param NumberOfElements is a count of elements to allocate memory for.
T *allocate(size_t NumberOfElements) {
T *allocate(size_t NumberOfElements, const detail::code_location CL =
detail::code_location::current()) {

auto Result = reinterpret_cast<T *>(
aligned_alloc(getAlignment(), NumberOfElements * sizeof(value_type),
MDevice, MContext, AllocKind, MPropList));
MDevice, MContext, AllocKind, MPropList, CL));
if (!Result) {
throw memory_allocation_error();
}
Expand All @@ -89,9 +93,11 @@ class usm_allocator {
///
/// \param Ptr is a pointer to memory being deallocated.
/// \param Size is a number of elements previously passed to allocate.
void deallocate(T *Ptr, size_t) {
void deallocate(
T *Ptr, size_t,
const detail::code_location CL = detail::code_location::current()) {
if (Ptr) {
free(Ptr, MContext);
free(Ptr, MContext, CL);
}
}

Expand Down
Loading