Skip to content

Commit b0f64aa

Browse files
author
Alexander Batashev
committed
[SYCL] Add instrumentation for USM allocations
1 parent 1f8874f commit b0f64aa

File tree

8 files changed

+644
-220
lines changed

8 files changed

+644
-220
lines changed

sycl/include/CL/sycl/detail/usm_impl.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// ===--------------------------------------------------------------------=== //
88
#pragma once
99

10+
#include <CL/sycl/detail/common.hpp>
1011
#include <CL/sycl/detail/export.hpp>
1112
#include <CL/sycl/usm/usm_enums.hpp>
1213

@@ -17,13 +18,16 @@ namespace usm {
1718

1819
__SYCL_EXPORT void *alignedAlloc(size_t Alignment, size_t Bytes,
1920
const context &Ctxt, const device &Dev,
20-
cl::sycl::usm::alloc Kind);
21+
cl::sycl::usm::alloc Kind,
22+
const code_location &CL);
2123

2224
__SYCL_EXPORT void *alignedAllocHost(size_t Alignment, size_t Bytes,
2325
const context &Ctxt,
24-
cl::sycl::usm::alloc Kind);
26+
cl::sycl::usm::alloc Kind,
27+
const code_location &CL);
2528

26-
__SYCL_EXPORT void free(void *Ptr, const context &Ctxt);
29+
__SYCL_EXPORT void free(void *Ptr, const context &Ctxt,
30+
const code_location &CL);
2731

2832
} // namespace usm
2933
} // namespace detail

sycl/include/CL/sycl/usm.hpp

Lines changed: 197 additions & 133 deletions
Large diffs are not rendered by default.

sycl/include/CL/sycl/usm/usm_allocator.hpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#pragma once
99

1010
#include <CL/sycl/context.hpp>
11+
#include <CL/sycl/detail/common.hpp>
1112
#include <CL/sycl/detail/export.hpp>
1213
#include <CL/sycl/device.hpp>
1314
#include <CL/sycl/exception.hpp>
@@ -24,8 +25,10 @@ namespace sycl {
2425
__SYCL_EXPORT void *aligned_alloc(size_t alignment, size_t size,
2526
const device &dev, const context &ctxt,
2627
usm::alloc kind,
27-
const property_list &propList);
28-
__SYCL_EXPORT void free(void *ptr, const context &ctxt);
28+
const property_list &propList,
29+
const detail::code_location CL);
30+
__SYCL_EXPORT void free(void *ptr, const context &ctxt,
31+
const detail::code_location CL);
2932

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

7983
auto Result = reinterpret_cast<T *>(
8084
aligned_alloc(getAlignment(), NumberOfElements * sizeof(value_type),
81-
MDevice, MContext, AllocKind, MPropList));
85+
MDevice, MContext, AllocKind, MPropList, CL));
8286
if (!Result) {
8387
throw memory_allocation_error();
8488
}
@@ -89,9 +93,11 @@ class usm_allocator {
8993
///
9094
/// \param Ptr is a pointer to memory being deallocated.
9195
/// \param Size is a number of elements previously passed to allocate.
92-
void deallocate(T *Ptr, size_t) {
96+
void deallocate(
97+
T *Ptr, size_t,
98+
const detail::code_location CL = detail::code_location::current()) {
9399
if (Ptr) {
94-
free(Ptr, MContext);
100+
free(Ptr, MContext, CL);
95101
}
96102
}
97103

0 commit comments

Comments
 (0)