-
Notifications
You must be signed in to change notification settings - Fork 75
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
Add Accessor, an interface for accessing buffers in kernels #1249
Conversation
237f2e4
to
931b769
Compare
Here is a concept based way to declare if an struct ReadWriteKernel {
void operator()(const auto& acc, const Accessor auto& data){
}
};
struct ReadOnlyKernel {
void operator()(const auto& acc, const ConstAccessor auto& data){
}
}; I think this is an abuse of concepts though. |
2ea7202
to
0b6a4e7
Compare
I have an item from my SYCL wish list:
What about this? template <typename TAcc>
struct ReadWriteKernel
{
auto operator()(TAcc const& acc, Accessor<TAcc, int> data)
{
}
};
template <typename TAcc>
struct ReadOnlyKernel
{
auto operator()(TAcc const& acc, Accessor<TAcc, int const> data)
{
}
}; This would also allow to specialize accessors for backends if required. |
d278257
to
7c50157
Compare
We had a longer discussion today during the alpaka meeting on what further aspects should accessors should address:
|
5f09c59
to
6defb3f
Compare
I started implementing features 1, 2 and 3 and we need further clarification: What is the return type of void f(float& out) {
out = 42.0f;
}
struct Kernel {
template<typename TAcc, typename Idx>
auto operator()(TAcc const&, alpaka::Accessor<float*, float, Idx, 1, alpaka::WriteAccess> data) const {
f(data[42]); // compile error
}
}; Continuing with this thought, an accessor which could return a |
During the alpaka VC today we decided:
|
e890d61
to
745cc1b
Compare
a567f2b
to
42d7692
Compare
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.
Added tiny annotations, in general, it looks good.
c3e7877
to
8de4f62
Compare
8de4f62
to
6b488bc
Compare
I squashed all changesets so far into the implementation, update of copyright and documentation. |
7f21964
to
2fe1ba0
Compare
2fe1ba0
to
ef95f1c
Compare
This PR is now only blocked by the CI still using clang-format 12.0.0. I proposed an upstream fix to the GitHub action here: DoozyX/clang-format-lint-action#36 |
f62c9dc
to
8507a3b
Compare
To make this easier to review, I split off the feature from changing the tests and examples. Please review and merge this first: #1433. |
From the PR description:
Why return a |
This would be a blocker for adoption in CMS. |
Because when we started to design accessors, we foresaw their use also for textures and for hardware dependend load instructions. If an accessor is backed by an image, we cannot return a const reference, because there is no memory to point to. See a potential example here: #1253 (comment) The current status of this PR is to ship a minimum viable accessor for alpaka's views that has enough features for the SYCL backend living here #789.
The current design here does not have this problem. This problem would occur if we bind accessors to accelerators, which is something that comes up every now and then. Be also aware that the split-off PR #1433 will merge accessors in an experimental namespace and not touch anything else. Alpaka will continue to support pointers as kernel arguments for the near future until we figure out how accessors can be used ergonomically. Or all SYCL vendors adopt SYCL 2020 and also support pointers in their API, in which case we could use a simpler design. We will see. |
8507a3b
to
21626fa
Compare
21626fa
to
de4dd6c
Compare
Isn't there somewhere (I guess Boost, but maybe also future C++) a trait that defines a best way to pass a constant value for a type - by value or by const reference Edit: so it this is customizable for a combination of type + accelerator + memory level + whatever else we need, a user can define this copy hehavior and we can disable unsupported combinations |
This PR adds a new class template
Accessor
:An accessor is an interface to access the data stored by a memory object.
Memory objects in alpaka are currently all objects fulfulling the view concept, which includes buffers.
An accessor is created via one of the following calls:
Currently, alpaka defines the access modes via the tags
ReadAccess
,WriteAccess
andReadWriteAccess
.However, the user is free to add their own tags and specialize
Accessor
based on them.The access functions construct an accessor by retrieving a memory handle from the memory object, which is stored in the accessor.
An accessor additionally has an element type
TElem
which is the type of the instances returned on access.This type may be mutated depending on the access modes.
E.g. a read/write accessor will return a
TElem&
whereas a read accessor will just returnTElem
.The
TBufferIdx
is the integral type used for indexing and index computations.TDim
is the integral dimension of the accessor.TAccessModes
is either one access tag or astd::tuple
of access tags. In the latter case, the accessor behaves as if only the first access tag was specified.Accessors with multiple access tags can be further constrained to a single access tag (contained in the list of existing tags) by again calling one of the access functions on them.
The alias
BufferAccessor
specifies the accessor type for the buffer object of a given accelerator and may simplify specifying a kernel's interface.For data access, the accessor overloads
operator()
andoperator[]
, which can be called with eitherTDim
integrals or a correspondingVec
.Releated issue: #38