-
Notifications
You must be signed in to change notification settings - Fork 797
[SYCL][Doc] USM allocation functions with properties support #6346
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
Conversation
All properties that are valid for annotated_ptr must be supported by the USM memory allocation functions with `properties` support. | ||
Unless otherwise specified, supported properties do not affect the behavior of the USM memory allocation functions with `properties` support. | ||
|
||
[NOTE] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This note repeats the same information said immediately before it. You probably only need to say it once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to reword this so it is less repetitive. The NOTE now just mentions that the motivation is for user convenience in only needing to specify the properties in one place.
The `usm_alloc` property is supported by annotated_ptr, and therefore by the USM memory allocation functions defined in this extension. | ||
This property will always appear on the annotated_ptr returned by the USM memory allocation functions defined in this extension that do not have a `usm::alloc` parameter. | ||
The `usm_alloc` property may also be passed to the USM memory allocation functions defined in this extension. | ||
If the USM memory allocation kind specified by a function's `usm::alloc` parameter is different from the `usm_alloc` property, the result is undefined behavior. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is easy to diagnose at compile-time, right? If so, let's make it an "error, diagnostic required" instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usm::alloc parameter's value is not known until runtime. I will change this from UB to an exception.
|
||
// This section needs to be after the document title. | ||
:doctype: book | ||
:toc2: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you intend to add a table of contents? I don't think I've seen it on any of the other extensions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed these lines. I don't want a table of contents.
@@ -0,0 +1,1468 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No title
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the title. Thanks.
== Examples | ||
|
||
Runtime and compile-time constant properties can be passed to the USM memory allocation functions introduced by this extension. | ||
Properties passed to an allocation function may or may not appear on the returned `annotated_ptr` object: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Properties passed to an allocation function may or may not appear on the returned `annotated_ptr` object: | |
Properties passed to an allocation function may or may not appear on the returned `annotated_ptr` object; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why isn't a colon appropriate here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The part before the punctuation doesn't introduce the part after. Each part is a full sentence. You could use a period, but a semi-colon seems more appropriate since you want to show that they are related.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed my mind after looking at more style guides. I think the colon is fine here.
|
||
---- | ||
|
||
If the USM memory allocation kind specified by a parameter to the allocation function is different than the USM memory allocation kind specified by the `sycl::ext::oneapi::experimental::usm_kind` property, the USM memory allocation kind specified by the property takes precedence. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you said you would make this throw an exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I have now updated this to throw an exception.
auto APtr11 = annotated_malloc_host<int>(N, q, P7); // Error | ||
---- | ||
|
||
The following example uses the compile-time-constant property `alignment`, defined in the link:../proposed/sycl_ext_oneapi_annotated_ptr.asciidoc[sycl_ext_oneapi_annotated_ptr] extension. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
link is broken
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The link will be broken until the annotated_ptr spec PR is merged. I will wait to merge the malloc extension until annotated_ptr is merged (and then I'll also double-check the links).
|
||
properties P9{alignment<1>}; | ||
// Allocate N integers. | ||
// Alignment must be at least sizeof(int) bytes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this actually convey what you want to say? I worry that an alignment of 7 satisfies this requirement as written. Can we simply say that the resulting pointer has an alignment of sizeof(int) bytes? Isn't it already part of the definition of alignment that alignment of N can be satisfied by a pointer whose value is any multiple of N (and can therefore be a multiple of XN as well where X is a natural number)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"alignment must be at least sizeof(int) bytes" is a necessary condition but not sufficient.
I can change this to "alignment must be a positive non-zero integer multiple of sizeof(int)".
---- | ||
|
||
This extension also introduces USM memory allocation functions with `properties` support that allow alignment to be specified at runtime, using a separate parameter of type `size_t`. | ||
If the compile-time constant `alignment` property is also passed in, it takes precedence over the alignment specified by the parameter of type `size_t`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem user friendly. I would expect the resulting pointer to have both specified alignments. I.e. the resulting pointer value should be multiple of the lowest common multiple of the two specified alignments. Assuming both specified alignments are powers of two, that would mean that the larger of the two should take precedence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have made this change. I've removed all exceptions and errors that were caused by differing alignments.
|
||
[[table.usm.device.allocs]] | ||
.USM Device Memory Allocation Functions with properties Support | ||
[width="100%",options="header",separator="@",cols="65%,35%"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This table doesn't render nicely for me. Is that just my setup or is there something wrong with it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I improved the formatting of the first column that contains the function declarations.
|
||
The following five tables list all functions introduced by this extension. | ||
|
||
TODO: How is propertyListB going to be inferred? Do we need support for getting the type of a properties list with only the compile-time properties, and also adding a new compile-time property? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think we want both of these.
c620431
to
ea0a68f
Compare
I am not clear how to view the rendered asciidoc file. Could you please explain how CUDA's constant memory is migrated to SYCL using USM ? Thanks. |
device that is contained by that context, otherwise this function throws a | ||
synchronous `exception` with the `errc::invalid` error code. | ||
|
||
And error is reported if `propList` contains |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And error is reported if `propList` contains | |
An error is reported if `propList` contains |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Done.
The `sycl::ext::oneapi::experimental::usm_kind` property is a compile-time constant property with a single non-type parameter. This parameter is a value belonging to the enumeration `sycl::usm::alloc`. | ||
The `sycl::ext::oneapi::experimental::usm_kind` property is supported by `annotated_ptr` and the USM memory allocation functions defined in this extension. | ||
|
||
=== Deallocation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add an overload of sycl::free that takes an annotated_ptr to make this easier?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good proposal which trusts the C++ type-system instead of fighting against it.
success. The allocation size is specified in bytes. This memory is not | ||
accessible on the host. Memory allocated by `annotated_malloc_device` | ||
must be deallocated with `sycl::free` to avoid memory leaks. | ||
On failure, the raw pointer of the returned `annotated_ptr` will be `nullptr`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it is not possible to return nullptr
here which is a C++ keyword and obviously is of type https://en.cppreference.com/w/cpp/types/nullptr_t
Perhaps you could have a using nullptr_t = ...
and constexpr static nullptr_v = ...
inside your annotated pointer class for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are discussing adding a comparison operator to annotated_ptr
, e.g.:
bool operator == (const nullptr_t &other) const { return this->ptr == nullptr; }
which would allow us to write
annotated_ptr x = malloc_device_annotated<int>(N, q); if (x == nullptr) {…}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea.
You could also have a conversion-to-bool operator, if you do not have one already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The annotated_ptr spec currently lists a conversion to bool operator:
explicit operator bool() const noexcept;
Returns false if the underlying pointer is null, returns true otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some specific comments below, but I'd also like to bikeshed on the names. The current naming is like:
annotated_malloc_host
This seems weird to me, though. The function is primarily used for memory allocation, so shouldn't the "malloc" come first? How about:
malloc_host_annotated
It would be nice to drop the "annotated" entirely, but I don't see we can do that and still coexist with the sycl::malloc_host
that is already in the spec.
sycl/doc/extensions/proposed/sycl_ext_oneapi_usm_malloc_properties.asciidoc
Show resolved
Hide resolved
sycl/doc/extensions/proposed/sycl_ext_oneapi_usm_malloc_properties.asciidoc
Outdated
Show resolved
Hide resolved
sycl/doc/extensions/proposed/sycl_ext_oneapi_usm_malloc_properties.asciidoc
Outdated
Show resolved
Hide resolved
sycl/doc/extensions/proposed/sycl_ext_oneapi_usm_malloc_properties.asciidoc
Show resolved
Hide resolved
sycl/doc/extensions/proposed/sycl_ext_oneapi_usm_malloc_properties.asciidoc
Outdated
Show resolved
Hide resolved
sycl/doc/extensions/proposed/sycl_ext_oneapi_usm_malloc_properties.asciidoc
Show resolved
Hide resolved
sycl/doc/extensions/proposed/sycl_ext_oneapi_usm_malloc_properties.asciidoc
Outdated
Show resolved
Hide resolved
…support extension.
…tr can now differ from those passed to the allocation function.
…l properties supported by annotated_ptr are supported by malloc. All compile-time and no runtime properties are propagated from malloc to the returned annotated_ptr.
…y on the annotated_ptr by default. Add support for specifying alignment and allocation kind at runtime. Provide additional functions that require the usm_kind property.
…d default argument syntax for propList.
bc3415b
to
063cd09
Compare
I like |
sycl/doc/extensions/proposed/sycl_ext_oneapi_usm_malloc_properties.asciidoc
Outdated
Show resolved
Hide resolved
sycl/doc/extensions/proposed/sycl_ext_oneapi_usm_malloc_properties.asciidoc
Outdated
Show resolved
Hide resolved
sycl/doc/extensions/proposed/sycl_ext_oneapi_usm_malloc_properties.asciidoc
Show resolved
Hide resolved
sycl/doc/extensions/proposed/sycl_ext_oneapi_usm_malloc_properties.asciidoc
Show resolved
Hide resolved
sycl/doc/extensions/proposed/sycl_ext_oneapi_usm_malloc_properties.asciidoc
Outdated
Show resolved
Hide resolved
@jessicadavies-intel, please, update PR title tags when PR is ready for merge. |
This extension introduces USM memory allocation functions that take a
sycl::ext::oneapi::experimental::properties
argument instead of asycl::property_list
. They return asycl::ext::oneapi::experimental::annotated_ptr
object.This PR replaces the initial draft #5656 opened by Sherry who is no longer working at Intel.