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

simplify alpaka usage #1017

Merged

Conversation

psychocoderHPC
Copy link
Member

@psychocoderHPC psychocoderHPC commented May 29, 2020

Motivation

Currently alpaka is hard to use because the user needs to know how all concepts e.g platform, accelerator, device, queue,... and how they are connected to each other and which concept must be used where.
I started a discussion in #944 to simplify the interface for alpaka.
This PR is introducing a full change of the usage, instead it provides the required trait specifications to allow the user a accelerator based programming. This means instead that the user needs to handle device and platform types he can use the accelerator to allocate buffers, query device information.
Before this PR the user got the device type from an accelerator and used the device type to get the platform. This explicit traversing over types with a 1:1 relation is removed by forwarding traits to the next hierarchy level when needed.

General Simple Workflow

  1. define an accelerator type Acc
  2. get the device instance based on Acc
  3. use Acc to create buffers

Changes

  • accelerator
    • specialize platform traits to query device information (redirect to
      platform trait)
    • specialize buffer for accelerators
  • device
    • add concept ConceptDev
    • specialize DevType for a device
    • specialize platform traits to query device information (redirect to
      platform trait)
  • mem
    • Buffer and views not using the template parameter TDev directly.
      Instead TDev is handled as concept and the device type is first
      evaluated.
  • Use the simplified accelerator centric view for all examples.

- accelerator
  - specialize platform traits to query device information (redirect to
platform trait)
  - specialize buffer for accelerators
- device
  - add concept `ConceptDev`
  - specialize `DevType` for a device
  - specialize platform traits to query device information (redirect to
platform trait)
- mem
   - Buffer and views not using the template parameter `TDev` directly.
     Instead `TDev` is handled as concept and the device type is first
evaluated.
Use the simplified accelerator centric view for all examples.
@bertwesarg
Copy link
Contributor

Hi, nice simplification. One question though, why not moving alpaka::pltf::getDevByIdx into alpaka::getDevByIdx or some other name space? This way, the term `pltf' should be completely avoidable.

@psychocoderHPC
Copy link
Member Author

Hi, nice simplification. One question though, why not moving alpaka::pltf::getDevByIdx into alpaka::getDevByIdx or some other name space? This way, the term `pltf' should be completely avoidable.

I like that idea. This will than also mirror the fact that getDevByIdx, getDevCount can be used with different concepts.
We can make another PR if this gets excepted.

@@ -99,7 +99,8 @@ namespace alpaka
typename TElem,
typename TDim,
typename TIdx>
using Buf = typename traits::BufType<TDev, TElem, TDim, TIdx>::type;
using Buf = typename traits::BufType<
alpaka::dev::Dev<TDev>, TElem, TDim, TIdx>::type;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this version. You are passing in something (TDev) that can give you the real device type via alpaka::dev::Dev<>. This extends the valid types easily.
If it is already a device, it uses the reflexive alpaka::dev::Dev<> specialization of the device type itself.
If it is not a device, it simply has to have a specialization of alpaka::dev::Dev<>.

typename pltf::traits::PltfType<TDev>::type>
::getDevCount();
}
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if we could get rid of those specializations here.
We should do the same that is done for the Buffer (if possible).
May we change the implementation of the trait accessor methods below?
Instead of calling traits::GetDevCount<TPltf>::getDevCount() they could call traits::GetDevCount<alpaka::pltf::Pltf<TPltf>>::getDevCount().
The platforms would need a reflexive specialization of the alpaka::pltf::Pltf<> trait and the device already has a alpaka::pltf::Pltf<> specialization.

@BenjaminW3
Copy link
Member

BenjaminW3 commented May 30, 2020

@psychocoderHPC I have pushed a simplification of your simplification onto your branch. So nothing to do for you anymore ;-)

@psychocoderHPC
Copy link
Member Author

@BenjaminW3 From my side the changes looks good. We should check if it is useful to add self reflection also to other traits e.g. QueueType in a separate PR.

@psychocoderHPC psychocoderHPC merged commit a49f4d3 into alpaka-group:develop Jun 3, 2020
@psychocoderHPC psychocoderHPC deleted the topic-simplifyAlpakaUsage branch June 3, 2020 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants