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

[PROTOTYPE] Generalized two pass algorithm and copy_if #1700

Merged

Conversation

danhoeflinger
Copy link
Contributor

@danhoeflinger danhoeflinger commented Jul 16, 2024

Summary

This PR changes the two pass algorithm to be more generalized for use with other scan-like algorithms like copy_if.

This PR adds copy_if as an example. partition and unique patterns should follow easily. Set algorithms have not been evaluated, but should also be possible.

Structural changes

The "bridge" between blocks now uses a saved carry-out value from the previous block (where it used to depend on the output of the previous block). The output of the previous block only applies to transform_scan patterns, and not scan_copy algorithms. It also required different logic for inclusive and exclusive scans. The change to use the carry unifies this logic between inclusive and exclusive scans.

The following operations have been defined to encode a generalized scan-like pattern:

  • _GenReduceInput : a function which accepts the input range and index to generate the data needed by the main output used in the reduction operation (to calculate the global carries)
  • _GenScanInput : a function which accepts the input range and index to generate the data needed by the final scan and write operations, for scan patterns
  • _ScanPred : a unary function applied to the ouput of _GenScanInput to extract the component used in the scan, but not the part only required for the final write operation
  • _ReduceOp : a binary function which is used in the reduction and scan operations
  • _FinalOp: A function which accepts output range, index, and output of _GenScanInput applied to the input range.

For transform_scan, these are defined as follows:

  • _GenReduceInput : apply the transfom to input at index and return
  • _GenScanInput : apply the transfom to input at index and return
  • _ScanPred : no_op passthrough
  • _ReduceOp : user supplied binary scan operation
  • _FinalOp: Simple write value to output range at index

For copy_if these are defined as follows:

  • _GenReduceInput : apply user supplied predicate to input at index and return 1 for true, 0 for false
  • _GenScanInput : a tuple with 3 elements:
    1) apply user supplied predicate to input at index and return 1 for true, 0 for false (contribution to count)
    2) apply user supplied predicate to input at index (condition for final copy)
    3) original value (value for final copy)
  • _ScanPred : std::get<0>(input)
  • _ReduceOp : std::plus
  • _FinalOp: if the second element of the tuple is true, write the third element to the output range using the index found in the first element of the tuple

Odds and ends

  • Makes the two pass scan pattern asynchronous, depending on __result_and_scratch_space for async deallocation

  • Changes the single workgroup copy_if to have a smaller threshold, and to use the __result_and_scratch_space struct to match return future type with the copy_if implementation.

  • Limits range to only launch non-empty workgroups (removed early exit for empty workgroups)

TODO next:

Replace usages of __parallel_transform_scan_base to route to __parallel_transform_reduce_then_scan instead. Modify the calling code as necessary. This should cover the rest of the scan-like patterns. Prioritize partition, then unique, then finally, set algorithms as time allows.

Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
…ges of __parallel_transform_scan_base)

Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Copy link
Contributor

@adamfidel adamfidel left a comment

Choose a reason for hiding this comment

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

Just some initial comments.

danhoeflinger and others added 2 commits July 16, 2024 10:40
Co-authored-by: Adam Fidel <110841220+adamfidel@users.noreply.github.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Copy link
Contributor

@mmichel11 mmichel11 left a comment

Choose a reason for hiding this comment

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

First few minor things I see.

Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
danhoeflinger and others added 5 commits July 16, 2024 11:40
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
… type is not trivially copyable (#1707)

Signed-off-by: Matthew Michel <matthew.michel@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
…a future already)

Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Copy link
Contributor

@mmichel11 mmichel11 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@adamfidel adamfidel left a comment

Choose a reason for hiding this comment

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

LGTM.

…returns a future already)"

This reverts commit c787091.
@danhoeflinger danhoeflinger merged commit adec222 into dev/shared/reduce_then_scan_impl Jul 17, 2024
@danhoeflinger danhoeflinger deleted the dev/dhoeflin/generalized_two_pass branch July 17, 2024 21:32
adamfidel added a commit that referenced this pull request Jul 24, 2024
This PR changes the two pass algorithm to be more generalized for use with other scan-like algorithms like copy_if.

This PR adds copy_if as an example

---------

Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Matthew Michel <matthew.michel@intel.com>
Co-authored-by: Adam Fidel <110841220+adamfidel@users.noreply.github.com>
Co-authored-by: Matthew Michel <106704043+mmichel11@users.noreply.github.com>
mmichel11 added a commit that referenced this pull request Jul 31, 2024
This PR changes the two pass algorithm to be more generalized for use with other scan-like algorithms like copy_if.

This PR adds copy_if as an example

---------

Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Matthew Michel <matthew.michel@intel.com>
Co-authored-by: Adam Fidel <110841220+adamfidel@users.noreply.github.com>
Co-authored-by: Matthew Michel <106704043+mmichel11@users.noreply.github.com>
danhoeflinger added a commit that referenced this pull request Aug 5, 2024
This PR changes the two pass algorithm to be more generalized for use with other scan-like algorithms like copy_if.

This PR adds copy_if as an example

---------

Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Matthew Michel <matthew.michel@intel.com>
Co-authored-by: Adam Fidel <110841220+adamfidel@users.noreply.github.com>
Co-authored-by: Matthew Michel <106704043+mmichel11@users.noreply.github.com>
danhoeflinger added a commit that referenced this pull request Aug 6, 2024
This PR changes the two pass algorithm to be more generalized for use with other scan-like algorithms like copy_if.

This PR adds copy_if as an example

---------

Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Matthew Michel <matthew.michel@intel.com>
Co-authored-by: Adam Fidel <110841220+adamfidel@users.noreply.github.com>
Co-authored-by: Matthew Michel <106704043+mmichel11@users.noreply.github.com>
danhoeflinger added a commit that referenced this pull request Aug 6, 2024
This PR changes the two pass algorithm to be more generalized for use with other scan-like algorithms like copy_if.

This PR adds copy_if as an example

---------

Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Matthew Michel <matthew.michel@intel.com>
Co-authored-by: Adam Fidel <110841220+adamfidel@users.noreply.github.com>
Co-authored-by: Matthew Michel <106704043+mmichel11@users.noreply.github.com>
danhoeflinger added a commit that referenced this pull request Aug 7, 2024
This PR changes the two pass algorithm to be more generalized for use with other scan-like algorithms like copy_if.

This PR adds copy_if as an example

---------

Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Matthew Michel <matthew.michel@intel.com>
Co-authored-by: Adam Fidel <110841220+adamfidel@users.noreply.github.com>
Co-authored-by: Matthew Michel <106704043+mmichel11@users.noreply.github.com>
danhoeflinger added a commit that referenced this pull request Aug 7, 2024
This PR changes the two pass algorithm to be more generalized for use with other scan-like algorithms like copy_if.

This PR adds copy_if as an example

---------

Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Matthew Michel <matthew.michel@intel.com>
Co-authored-by: Adam Fidel <110841220+adamfidel@users.noreply.github.com>
Co-authored-by: Matthew Michel <106704043+mmichel11@users.noreply.github.com>
danhoeflinger added a commit that referenced this pull request Aug 8, 2024
This PR changes the two pass algorithm to be more generalized for use with other scan-like algorithms like copy_if.

This PR adds copy_if as an example

---------

Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Matthew Michel <matthew.michel@intel.com>
Co-authored-by: Adam Fidel <110841220+adamfidel@users.noreply.github.com>
Co-authored-by: Matthew Michel <106704043+mmichel11@users.noreply.github.com>
danhoeflinger added a commit that referenced this pull request Aug 8, 2024
This PR changes the two pass algorithm to be more generalized for use with other scan-like algorithms like copy_if.

This PR adds copy_if as an example

---------

Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Matthew Michel <matthew.michel@intel.com>
Co-authored-by: Adam Fidel <110841220+adamfidel@users.noreply.github.com>
Co-authored-by: Matthew Michel <106704043+mmichel11@users.noreply.github.com>
danhoeflinger added a commit that referenced this pull request Aug 8, 2024
This PR changes the two pass algorithm to be more generalized for use with other scan-like algorithms like copy_if.

This PR adds copy_if as an example

---------

Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Matthew Michel <matthew.michel@intel.com>
Co-authored-by: Adam Fidel <110841220+adamfidel@users.noreply.github.com>
Co-authored-by: Matthew Michel <106704043+mmichel11@users.noreply.github.com>
danhoeflinger added a commit that referenced this pull request Aug 14, 2024
This PR changes the two pass algorithm to be more generalized for use with other scan-like algorithms like copy_if.

This PR adds copy_if as an example

---------

Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Matthew Michel <matthew.michel@intel.com>
Co-authored-by: Adam Fidel <110841220+adamfidel@users.noreply.github.com>
Co-authored-by: Matthew Michel <106704043+mmichel11@users.noreply.github.com>
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.

3 participants