Conversation
cf23f8d to
7ed97ca
Compare
5d61050 to
69d0f26
Compare
fd4584f to
7be2138
Compare
94533b2 to
1bc1e2b
Compare
| // If __kind == sycl::usm::alloc::host, __usm_ptr points directly to the result. | ||
| // If __kind == sycl::usm::alloc::device, the result is at __usm_ptr + __offset in device memory. | ||
| // If __kind == sycl::usm::alloc::unknown, the result is in __sycl_buf at __offset. |
There was a problem hiding this comment.
If my understanding is correct, and we have device memory / buffer and an offset, this means we are holding alive both a result and a scratch, where the offset determines where we transition from one to the other.
Should we make this more clear here in the comments (and perhaps naming of the struct?).
There was a problem hiding this comment.
Changed my answer after re-reading the comment. The understanding is correct, but the goal of the struct is to hold the memory where the result resides. A part of that memory might have been used as a scratch, but at least now that does not matter anymore, as the memory will be released, not reused.
There was a problem hiding this comment.
If the intent for these is to only be a "sink" whose main purpose is lifetime extension, we may want to consider making them more opaque (protected fields).
I think the one instance where we pull stuff out of this is to produce the final results from within __storage_holder. That storage holder could be friends with __result_keepalive to make more clear the intention here that this is a data sink, meant for lifetime extension and that extracting data from them is the exception.
It really is a preference thing, at the most a defense against future misuse, so perhaps just a small change to the comments would suffice without more complexity.
There was a problem hiding this comment.
Given that these are internal types designed specifically for the device data usage pipeline (allocate storage / use it on the device / transfer results to the host across code layers / keep alive until the kernel completes / extract results / deallocate) and all the same functions/classes that currently operate with these structs would all be declared friends, that sounds like just-in-case overengineering to me. Improving the comments is of course reasonable :)
| template <typename _T> | ||
| void | ||
| __copy_n(_T* __dst, std::size_t __n, const __result_keepalive<_T>& __ka, sycl::queue& __q) |
There was a problem hiding this comment.
Should this be a const member function of __result_keepalive?
Or if we don't want it as a member function, perhaps a static function to keep the implementation together?
There was a problem hiding this comment.
I prefer the keepalive and copyable state to be just simple structs without member functions, not encapsulating any functionality but instead fully exposing their state for any function to operate on.
| // If __kind == sycl::usm::alloc::device, the result is at __usm_ptr + __offset in device memory. | ||
| // If __kind == sycl::usm::alloc::unknown, the result is in __sycl_buf at __offset. | ||
| template <typename _T> | ||
| struct __result_keepalive |
There was a problem hiding this comment.
I wont insist, but I think I would prefer a name like __raw_result_storage, and __raw_scratch_storage, instead of keepalive which, despite the comment above, may make it confusing in thinking these are RAII storage with ownership.
There was a problem hiding this comment.
Well, it's not a storage either, at least not in the sense of other "storage" types which provide access to data. Maybe __scratch/result_raw_state.
There was a problem hiding this comment.
yeah or __scratch/result_raw_record?
There was a problem hiding this comment.
Renamed and updated comments.
8ef73cf to
641a89a
Compare
641a89a to
f67f551
Compare
This PR continues improving the internal SYCL backend infrastructure to deal with temporary buffers and device-computed results. It complements the storage types (
__device/result/combined/_storage) with a "storage holder" to keep the allocated memory alive and pass it from a backend pattern to its caller.Changes made:
__result_and_scratch_storageand__futureare not moved and will mostly remain intact until fully replaced.__storage_holderclass tempate to specify a set of storage buffers that a backend pattern may deal with.__result_and_scratch_storagein merge sort (__parallel_sort_impl)How it is supposed to work:
__storage_holderto specialize its return types and limit the number of scratch buffers.__takemethod.sycl::eventthat signals kernel completion remains (a part of) the returned value.__copy_resultmethod.__future.