Skip to content
Snippets Groups Projects

Reduce by Key Worklet Type

Merged Kenneth Moreland requested to merge kmorel/vtk-m:reduce-by-key-worklet into master
3 unresolved threads

Added a Reduce By Key worklet type. This is a very helpful type of worklet that lets you gather associated values. It typically follows a parallel operation where several threads produce values that are coincident or otherwise have to be gathered together.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
79 }
80
81 VTKM_CONT
82 vtkm::Id GetInputRange() const
83 {
84 return this->UniqueKeys.GetNumberOfValues();
85 }
86
87 VTKM_CONT
88 KeyArrayHandleType GetUniqueKeys() const
89 {
90 return this->UniqueKeys;
91 }
92
93 VTKM_CONT
94 vtkm::cont::ArrayHandle<vtkm::Id> GetSortedValuesMap() const
  • Do we really need the SortedValuesMap? isn't this just the unique keys?

  • Author Maintainer

    No. SortedValuesMap is very different from the unique keys. SortedValuesMap allows you to take an index in the sorted keys and find the corresponding value.

    Typically in a reduce-by-key, you do a SortByKey using the keys and values. However, in the worklet you can have an arbitrary number of values that you want to reduce, and it would be inefficient to do a SortByKey for all of them. So instead we shuffle the indices and do a lookup of which value would have been sorted to there.

  • Please register or sign in to reply
  • 91 }
    92
    93 VTKM_CONT
    94 vtkm::cont::ArrayHandle<vtkm::Id> GetSortedValuesMap() const
    95 {
    96 return this->SortedValuesMap;
    97 }
    98
    99 VTKM_CONT
    100 vtkm::cont::ArrayHandle<vtkm::Id> GetOffsets() const
    101 {
    102 return this->Offsets;
    103 }
    104
    105 VTKM_CONT
    106 vtkm::cont::ArrayHandle<vtkm::IdComponent> GetCounts() const
    • I wonder if we should instead be able to provide the count for a given index instead of returning the whole array. This way we can save uploading the counts and instead compute it just from the offsets.

    • Author Maintainer

      I think I was considering it, but it seemed like a hassle. You have to carry around the size of the values array and do a special case at the end of the array. Considering that you would have to do this not in the Keys class but somewhere in the fetch mechanism, it seemed more trouble than it was worth (at least initially).

      This has not been the first time this has come up. It happens in the scatter counting class as well. Actually, it even happens in the explicit cell set. If we want to worry about sharing offset/count arrays, we should probably have helper classes and/or fancy arrays to manage that.

    • Please register or sign in to reply
  • 55 /// needed to use the keys.
    56 ///
    57 /// The same \c Keys structure can be used for multiple different \c Invoke of
    58 /// different dispatchers. When used in this way, the processing done in the \c
    59 /// Keys structure is reused for all the \c Invoke. This is more efficient than
    60 /// creating a different \c Keys structure for each \c Invoke.
    61 ///
    62 template<typename _KeyType>
    63 class Keys
    64 {
    65 public:
    66 using KeyType = _KeyType;
    67 using KeyArrayHandleType = vtkm::cont::ArrayHandle<KeyType>;
    68
    69 VTKM_CONT
    70 Keys()
    • I think it would be valuable to have a constructor that allows you to pass in an already sorted array.

    • Author Maintainer

      I don't think that will work because you still need to create the SortedValuesMap.

      For what it's worth, the whole point of having the Keys class is to mange and reuse sorted/unique keys and the value map so you can apply it to multiple worklet invocations. I'm not sure why you would want to sort a keys array except for operations that you use the Keys class for anyway.

    • Please register or sign in to reply
  • Author Maintainer

    @robertmaynard Did you have any other questions about these changes?

  • No I think you have answered all my questions.

    +1

  • Author Maintainer

    Do: merge

  • Automatic merge failed!

    Error: failed to merge the tree:

  • Author Maintainer

    @robertmaynard The automatic merge failed. Should I click the button instead?

  • mentioned in commit 28b86692

  • Please register or sign in to reply
    Loading