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

Test mdpsan for handling memory #91

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

SimeonEhrig
Copy link
Member

@SimeonEhrig SimeonEhrig commented Oct 27, 2022

The PR tests mdspan as alternative for raw pointers to handle the input and output memory.

Benefits of mdspan:

  • bundling of memory and size in one object
  • native support for multidimensional memory
  • handling of objects instead pointer makes the code easier
  • slicing of memory

The PR requires the mdspan support, which is not merged yet: alpaka-group/alpaka#1788

Is solving the same problem like in PR #88 with another approach.

- Support n dimensional mdspan as in- and output.
- The iteration order is fixed to iterate first over most right dimension and then iterate from the right to the left dimension.
- Only single core CPU is supported at the moment.
- Some code for developing with cppinsight is left.
- Requires the alpaka branch: https://github.com/bernhardmgruber/alpaka/tree/mdspan
@SimeonEhrig SimeonEhrig added enhancement New feature or request api change labels Oct 27, 2022
@SimeonEhrig SimeonEhrig added this to the release 0.2 milestone Oct 27, 2022
@SimeonEhrig
Copy link
Member Author

@bernhardmgruber ping

Copy link
Member

@bernhardmgruber bernhardmgruber left a comment

Choose a reason for hiding this comment

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

I think you should use an example where an mdspan actually makes sense over a 1D span. For the transform you have here, a 1D span is easier and potentially faster to handle.

Maybe mdspan is generally not a good fit for vikunja, since vikunja's primitives (e.g. transform, scan, for_each) are typically used on 1D sequences. Or in other words: there is no benefit of the n-dimensionality of the data structure.

One example I could think of would be batched matrix multiplication. You would have e.g. three mdspan<dynamic_extent, 4, 4> a, b, c and compute as many individual 4x4 matrix multiplications as the dynamic extent.

// Copy the data back to the host for validation.
alpaka::memcpy(queueAcc, hostMem, deviceMem, extent);

Data resultSum = std::accumulate(hostNativePtr, hostNativePtr + extent.prod(), 0);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Data resultSum = std::accumulate(hostNativePtr, hostNativePtr + extent.prod(), 0);
Data resultSum = std::reduce(hostNativePtr, hostNativePtr + extent.prod());

- only for testing purpose
- fix bug, which wrote everything to input
@bussmann
Copy link

bussmann commented Nov 15, 2022

I think any tensor example would fit extremely well for mdspan. Tensors are THE thing for machine learning.

@bernhardmgruber
Copy link
Member

I think any tensor example would fit extremely well for mdspan. Tensors are THE thing for machine learning.

I fully agree that mdspan is a good fit to represent tensors. I am unsure though whether tensors fit into vikunja. We can definitely have a tensor example in alpaka though. Can you please open an issue at alpaka and also suggest a concrete algorithm? And ideally assign a professional support to implement it! Thx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api change enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants