Skip to content

Commit 1c27d57

Browse files
Add two new memory deallocation functions that take an annotated_ptr instead of a raw pointer.
1 parent 6acb364 commit 1c27d57

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

sycl/doc/extensions/proposed/sycl_ext_oneapi_usm_malloc_properties.asciidoc

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
== Notice
88

9-
Copyright (c) 2022 Intel Corporation. All rights reserved.
9+
Copyright (c) 2023 Intel Corporation. All rights reserved.
1010

1111
NOTE: Khronos(R) is a registered trademark and SYCL(TM) and SPIR(TM) are
1212
trademarks of The Khronos Group Inc. OpenCL(TM) is a trademark of Apple Inc.
@@ -292,7 +292,7 @@ contained by `syclContext` or it must be a descendent device of some
292292
device that is contained by that context, otherwise this function throws a
293293
synchronous `exception` with the `errc::invalid` error code.
294294

295-
And error is reported if `propList` contains
295+
An error is reported if `propList` contains
296296
a `usm_kind` property with value different than `sycl::usm::alloc::device`.
297297

298298
Available only if `propertyListA` and `propertyListB` are specializations of the `properties` class.
@@ -1556,23 +1556,53 @@ The `sycl::ext::oneapi::experimental::usm_kind` property is supported by `annota
15561556

15571557
=== Deallocation
15581558

1559-
To avoid memory leaks, USM memory allocated using the USM memory allocation functions with `properties` support defined in this extension, must be deallocated using one of the `sycl::free` functions listed in Table 107 "USM Deallocation Functions" of Section 4.8.3.6 "Memory deallocation functions" of the core SYCL specification.
1559+
This extension introduces two new functions called `sycl::ext::oneapi::experimental::free` that take an `annotated_ptr` as argument. These functions deallocate the memory pointed to by the raw pointer belonging to the `annotated_ptr`. The new deallocation functions are listed in Table <<table.usm.malloc.free>>. These functions belong to the namespace `sycl::ext::oneapi::experimental`.
1560+
To avoid memory leaks, USM memory allocated using the USM memory allocation functions with `properties` support defined in this extension, must be deallocated using `sycl::ext::oneapi::experimental::free` or `sycl::free`.
15601561

1561-
The following example shows how USM memory allocated using one of the functions defined in this extension should be deallocated, to avoid memory leaks.
1562+
The following example shows how USM memory allocated using one of the functions defined in this extension can be deallocated, to avoid memory leaks.
15621563

15631564
==== Example
15641565

15651566
[source,c++]
15661567
----
15671568
using namespace sycl::ext::oneapi::experimental;
15681569
1569-
properties P1{alignment<512>};
1570-
// APtr is of type annotated_ptr<int*, decltype(properties{alignment<512>, usm_kind<sycl::usm::alloc::device>})>
1571-
auto APtr = annotated_malloc_device<int>(N, q, P1);
1570+
// APtr and BPtr are of type
1571+
// annotated_ptr<int*, decltype(properties{usm_kind<sycl::usm::alloc::device>})>
1572+
auto APtr = annotated_malloc_device<int>(N, q);
1573+
auto BPtr = annotated_malloc_device<int>(N, q);
1574+
1575+
// Deallocate the memory pointed to by the raw pointer of APtr
1576+
free(APtr, q);
1577+
1578+
// Deallocate the memory pointed to by the raw pointer of BPtr, using sycl::free
1579+
free(BPtr.get(), q);
1580+
----
15721581

1573-
// Deallocate the memory using the raw pointer of APtr
1574-
sycl::free(APtr.get(), q);
1582+
[[table.usm.malloc.free]]
1583+
.New USM memory deallocation functions introduced by this extension
1584+
[options="header"]
1585+
|====
1586+
|Function|Description
1587+
a|
1588+
[source,c++]
1589+
----
1590+
template<typename T, typename propList>
1591+
void free(annotated_ptr<T, propList> &ptr,
1592+
const context& syclContext)
15751593
----
1594+
| Frees an allocation. The memory pointed to by the raw pointer belonging to `ptr` must have been allocated using one of the USM memory allocation functions with `properties` support defined in this extension, or one of the
1595+
SYCL USM allocation routines. `syclContext` must be the same `context` that was used to allocate the memory. The memory is freed without waiting for `commands` operating on it to be completed. If `commands` that use this memory
1596+
are in-progress or are enqueued the behavior is undefined.
1597+
a|
1598+
[source,c++]
1599+
----
1600+
template<typename T, typename propList>
1601+
void free(annotated_ptr<T, propList> &ptr,
1602+
const queue& syclQueue)
1603+
----
1604+
| Alternate form where `syclQueue` provides the `context`.
1605+
|====
15761606

15771607
== Revision History
15781608

@@ -1581,5 +1611,5 @@ sycl::free(APtr.get(), q);
15811611
[options="header"]
15821612
|========================================
15831613
|Rev|Date|Author|Changes
1584-
|1|2022-12-15|Jessica Davies|*Initial public working draft*
1614+
|1|2023-01-25|Jessica Davies|*Initial public working draft*
15851615
|========================================

0 commit comments

Comments
 (0)