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

Sort subset of Kokkos::DynamicView #1160

Closed
bathmatt opened this issue Oct 11, 2017 · 9 comments
Closed

Sort subset of Kokkos::DynamicView #1160

bathmatt opened this issue Oct 11, 2017 · 9 comments
Assignees
Labels
Enhancement Improve existing capability; will potentially require voting
Milestone

Comments

@bathmatt
Copy link

I need to be able to get a subview of a dynamic view. Here is my use case

  Kokkos::Experimental::DynamicView<Vector3*> x_;
...
  Sorter.sort(Kokkos::subview(x_, reduced_size));
@hcedwar
Copy link
Contributor

hcedwar commented Oct 11, 2017

Subviews are problematic. However, sorting a subrange was added a while ago.
See https://github.com/kokkos/kokkos/blob/develop/algorithms/unit_tests/TestSort.hpp#L234
where the sort function can be given a [begin,end) range.
Hopefully that is sufficient.

@bathmatt
Copy link
Author

bathmatt commented Oct 11, 2017

I'm guessing I'm missing something

  KeyViewType local_ielement = Kokkos::subview(element_, reduced_size);

  Kokkos::BinSort<KeyViewType , BinOp > Sorter(local_ielement,binner,false);
  Sorter.create_permute_vector();
  Sorter.sort< KeyViewType >(local_ielement);
  Sorter.sort(x_, 0, reduced_size);

and it fails on the sort of x.

/home/mbetten/Trilinos/EMPIRE/src/PIC/ParticleContainer.cpp: In member function ‘void empire::pic::ParticleContainer::sort()’:
/home/mbetten/Trilinos/EMPIRE/src/PIC/ParticleContainer.cpp:92:34: error: no matching function for call to ‘Kokkos::BinSort<Kokkos::View<int*, Kokkos::OpenMP>, Kokkos::BinOp1D<Kokkos::View<int*, Kokkos::OpenMP> > >::sort(Kokkos::Experimental::DynamicView<empire::ConstLenVector<double, 3u>*>&, int, Kokkos::pair<long unsigned int, long unsigned int>&)’
   Sorter.sort(x_, 0, reduced_size);

@bathmatt
Copy link
Author

Is it that the KeyViewType needs to be a dynamic view as well?

@hcedwar
Copy link
Contributor

hcedwar commented Oct 11, 2017

Not required.
I had implemented the sort function with DynamicView for you:
https://github.com/kokkos/kokkos/blob/master/algorithms/src/Kokkos_Sort.hpp#L524
However, it does not appear to cover your use case of sorting key array and applying permutation to value array. Perhaps the linked implementation shows enough of the pieces to code your use case?

@bathmatt
Copy link
Author

Huh, not sure I understand this comment.

I need to apply the permutation to a lot of views. Are you saying I can do what I need to with kokkos the way it is or I need to redo my algorithm?

@hcedwar
Copy link
Contributor

hcedwar commented Oct 11, 2017

Can you copy & modify
https://github.com/kokkos/kokkos/blob/master/algorithms/src/Kokkos_Sort.hpp#L524
to implement what you need?

@bathmatt
Copy link
Author

bathmatt commented Oct 11, 2017

So, this code you do this bit of code.


  bin_sort.create_permute_vector();
  bin_sort.sort(view);

I thought you mentioned that I can't use that second function with ranges.

So, I guess I'm not smart enough to figure out what you're asking to do. Can I grab one of the guys who understands this and help work through all this/?

@bathmatt
Copy link
Author

Here is my base data class

I need to make all of these dynamic views

  Kokkos::View<LocalOrdinal*> element_;
  Kokkos::View<Vector3*> x_;
  Kokkos::View<Vector3*> x_ref_;
  Kokkos::View<Vector3*> v_;
  Kokkos::View<Vector3*> v_ref_;
  Kokkos::View<Vector3*> E_, B_;
  

and then I sort them

 typedef Kokkos::View<LocalOrdinal*, PHX::Device> KeyViewType;
  typedef Kokkos::BinOp1D< KeyViewType > BinOp;


  int max_elems = MapContainer::getElementMap()->getNodeNumElements();
  int min_elems = 0, num_elems = max_elems-min_elems+1;
  BinOp binner(num_elems, min_elems, max_elems);

  Kokkos::pair<size_t, size_t> reduced_size(0,size());
  KeyViewType local_ielement = Kokkos::subview(element_, reduced_size);

  Kokkos::BinSort<KeyViewType , BinOp > Sorter(local_ielement,binner,false);
  Sorter.create_permute_vector();
  Sorter.sort< KeyViewType >(local_ielement);

  Sorter.sort(Kokkos::subview(x_, reduced_size));
  Sorter.sort(Kokkos::subview(x_ref_, reduced_size));
  Sorter.sort(Kokkos::subview(v_, reduced_size));
  Sorter.sort(Kokkos::subview(v_ref_, reduced_size));
  Sorter.sort(Kokkos::subview(E_, reduced_size));
  Sorter.sort(Kokkos::subview(B_, reduced_size));
  Sorter.sort(Kokkos::subview(weight_, reduced_size));

@hcedwar
Copy link
Contributor

hcedwar commented Oct 16, 2017

Desired API along the lines of:

BinSort<...> Sorter(element_, pair<int,int>(begin,end), binner, false );
Sorter.sort( x_ , pair<int,int>(begin,end) );
// etc.

@hcedwar hcedwar added the Enhancement Improve existing capability; will potentially require voting label Oct 16, 2017
@hcedwar hcedwar self-assigned this Oct 16, 2017
@hcedwar hcedwar added this to the 2017 December milestone Oct 16, 2017
@hcedwar hcedwar modified the milestones: 2017 December, 2018 February Nov 29, 2017
@dsunder dsunder changed the title Subview for kokkos::DynamicViews Sort subset of Kokkos::DynamicView Jan 3, 2018
@dsunder dsunder modified the milestones: 2018 February, 2018 April Jan 3, 2018
@dsunder dsunder assigned ibaned and unassigned hcedwar and ndellingwood Jan 3, 2018
@dsunder dsunder modified the milestones: 2018 April, 2018 February Jan 3, 2018
ibaned added a commit that referenced this issue Jan 9, 2018
ibaned added a commit that referenced this issue Jan 10, 2018
ibaned added a commit that referenced this issue Jan 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Improve existing capability; will potentially require voting
Projects
None yet
Development

No branches or pull requests

6 participants