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

Support structured bindings for VirtualDatum #142

Merged
merged 1 commit into from
Dec 22, 2020

Conversation

bernhardmgruber
Copy link
Member

No description provided.

@bernhardmgruber
Copy link
Member Author

bernhardmgruber commented Dec 22, 2020

This should allow us to write e.g. the nbody kernel as:

    template <typename VirtualParticleI, typename VirtualParticleJ>
    LLAMA_FN_HOST_ACC_INLINE void pPInteraction(VirtualParticleI&& pi, VirtualParticleJ pj)
    {
#ifdef USE_STRUCTURED_BINDING
        auto [piPos, piVel, _1] = pi;
        auto [pjPos, _2, pjMass] = pj;

        auto dist = piPos - pjPos;
        dist *= dist;
        auto [distX, distY, distZ] = dist;
        const FP distSqr = EPS2 + distX + distY + distZ;
        const FP distSixth = distSqr * distSqr * distSqr;
        const FP invDistCube = 1.0f / std::sqrt(distSixth);
        const FP sts = pjMass * invDistCube * TIMESTEP;
        piVel += dist * sts;
#else
        auto dist = pi(tag::Pos{}) - pj(tag::Pos{});
        dist *= dist;
        const FP distSqr = EPS2 + dist(tag::X{}) + dist(tag::Y{}) + dist(tag::Z{});
        const FP distSixth = distSqr * distSqr * distSqr;
        const FP invDistCube = 1.0f / std::sqrt(distSixth);
        const FP sts = pj(tag::Mass{}) * invDistCube * TIMESTEP;
        pi(tag::Vel{}) += dist * sts;
#endif
    }

This is great, because it allows us to navigate the VirtualDatum without tag types.

See also #141 for a version with asTuple.

Both versions produce identical assembly: https://godbolt.org/z/jEv33W

@bernhardmgruber bernhardmgruber force-pushed the vdbindings branch 2 times, most recently from b92a043 to fe65ad9 Compare December 22, 2020 22:25
@bernhardmgruber bernhardmgruber merged commit 3de4e5a into alpaka-group:develop Dec 22, 2020
@bernhardmgruber bernhardmgruber deleted the vdbindings branch December 22, 2020 23:49
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