-
Notifications
You must be signed in to change notification settings - Fork 187
Added some wording for the init function. #74
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -23,26 +23,35 @@ cuda::std::barrier<> bb; | |||||||||||||
cuda::barrier<cuda::thread_scope_block> c; | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
The class template `barrier` may also be declared without initialization; a | ||||||||||||||
The class template `barrier` may also be declared without initialization in the `cuda::` namespace; a | ||||||||||||||
friend function `init` may be used to initialize the object. | ||||||||||||||
Comment on lines
+26
to
27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think the "class template There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
How about the above? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at my suggested change now, I think I'll want to tweak further, but that's a thing for tomorrow. |
||||||||||||||
|
||||||||||||||
```c++ | ||||||||||||||
// Shared memory does not allow initialization. | ||||||||||||||
__shared__ cuda::barrier<cuda::thread_scope_block> b; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know of a specification of the exact semantics of cuda::barrier<cuda::thread_scope_block>* b = ...points to uninitialized storage...; where Placement-new guarantees that the object will be initialized in place. Why do we need cuda::barrier<cuda::thread_scope_block>::barrier(ptrdiff_t expected) {
init(this, expected);
} and just use "placement There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is more or less what happens; but having non-experts write placement new expressions is probably not the greatest idea. |
||||||||||||||
|
||||||||||||||
init(&b, 1); // Use this friend function to initialize the object. | ||||||||||||||
/* | ||||||||||||||
namespace cuda { | ||||||||||||||
template<thread_scope Sco, class CompletionF> | ||||||||||||||
__host__ __device__ void init(barrier<Sco,CompletionF>* bar, std::ptrdiff_t expected); | ||||||||||||||
template<thread_scope Sco, class CompletionF> | ||||||||||||||
__host__ __device__ void init(barrier<Sco,CompletionF>* bar, std::ptrdiff_t expected, CompletionF completion); | ||||||||||||||
Comment on lines
+36
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we add two overloads of
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with Gonzalo that we should document this with just a single overload with The reason for why this is implemented as two overloads is that the friend functions are instantiated when you instantiate the class template, so that they can be found by ADL; and if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense. The standard requires the default type of |
||||||||||||||
} | ||||||||||||||
*/ | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
- Expects: `*bar` is trivially initialized. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the intent is to exhibit undefined behavior if this condition is not met:
Suggested change
|
||||||||||||||
- Effects: equivalent to initializing `*bar` with a constructor. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which constructor? Arguable there is only one:
Suggested change
|
||||||||||||||
|
||||||||||||||
In the `device::` namespace, a `__device__` free function is available that | ||||||||||||||
provides direct access to the underlying PTX state of a `barrier` object, if | ||||||||||||||
its scope is `thread_scope_block` and it is allocated in shared memory. | ||||||||||||||
|
||||||||||||||
```c++ | ||||||||||||||
namespace cuda { namespace device { | ||||||||||||||
|
||||||||||||||
__device__ std::uint64_t* barrier_native_handle( | ||||||||||||||
__device__ std::uint64_t* barrier_native_handle( | ||||||||||||||
barrier<thread_scope_block>& b); | ||||||||||||||
|
||||||||||||||
}} | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
|
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.
What does this default/value/trivial initialization do for barrier?
std::barrier
only has the constructorbarrierbarrier(ptrdiff_t expected, CompletionFunction f = CompletionFunction());
What is the
expected
count set to when using default/value/trivial initialization?