Skip to content
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

Allow to load and store between virtual datum and any tuple like type #143

Merged
merged 1 commit into from
Jan 4, 2021

Conversation

bernhardmgruber
Copy link
Member

A virtual datum can be seen as a tuple/struct of references. This PR improves interoperability between a virtual datum vd and user defined structs:

vd.loadAs<T>() and T value = vd.load(); allow to load the referenced data represented by a virtual datum into a type T, if T adheres to the following requirement:

  • T is direct list-initializable from a sequence of U... or U&..., where the pack U denotes the types referenced by the virtual datum. In other words, the expression T{std::declval<U>()...} must be valid.

vd.store(const TupleLike& t); allows to store a value of a tuple-like type into the referenced memory locations of the virtual datum. Requires:

  • TupleLike to by a type for which std::tuple_size_v<TupleLike> and get<I>(std::declval<TupleLike>()) (for I in [0;std::tuple_size_v<TupleLike>[) are valid expressions.
  • The tuple sizes of TupleLike and recursively its data members are the same as the tuple sizes of the virtual datum and its sub-virtual datums.

Examples are found in the unit tests. Motivating example:

using DD = llama::DS<
    llama::DE<tag::Pos, llama::DS<
        llama::DE<tag::A, int>,
        llama::DE<tag::Y, int>>>,
    llama::DE<tag::Vel, llama::DS<
        llama::DE<tag::X, int>,
        llama::DE<tag::Y, int>,
        llama::DE<tag::Z, int>>>,
    llama::DE<tag::Weight, int>>;
...
struct MyDatum {
    struct MyPos { int a, y; } pos;
    struct MyVel { int x, y, z; } vel;
    int weight;
};
... // tuple protocol for MyDatum

void f() {
    llama::One<DD> vd;
    MyDatum d = vd.load(); // loads from virtual datum into a user defined struct
    d.vel.y += d.pos.y;
    vd.store(d); // stores from a user defined struct into a virtual datum
}

@bernhardmgruber bernhardmgruber merged commit 0e33396 into alpaka-group:develop Jan 4, 2021
@bernhardmgruber bernhardmgruber deleted the loadstore branch January 4, 2021 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant