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

Some misc cleanups/refactor split out from #1854 #1867

Merged
merged 12 commits into from
Jul 27, 2022
Merged

Conversation

zasdfgbnm
Copy link
Collaborator

Split out from #1854

  • The InlinePropagatorSelector seems to be less generally useful than BoundedPropagationSelector, so I made InlinePropagatorSelector a private class of compute_at.cpp and renamed it to ComputeAtSelector, and moved BoundedPropagationSelector to maxinfo_propagator.h and renamed it to SetSelector.
  • Split DomainMap from pointwise.cpp into pointwise_utils.cpp, and renamed some functions.
  • Add two cache entry: DOMAIN_MAP and REFERENCE_TENSORS, and use them to in the pointwise scheduler.

}

// Determine if all IterDomains in input are mapped to output
bool DomainMap::areAllInputIdsMappedToOutput(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Renamed from areAllMapped, see #1854 (comment)

@zasdfgbnm zasdfgbnm mentioned this pull request Jul 26, 2022
4 tasks
Comment on lines +58 to +60
// Currently this function only allow having one view on the path from input to
// output. If there are multiple views, then likely the pointwise scheduler will
// reject the fusion because we can not correctly find a reference tensor.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This comment is newly added, see #1854 (comment)

// Currently this function only allow having one view on the path from input to
// output. If there are multiple views, then likely the pointwise scheduler will
// reject the fusion because we can not correctly find a reference tensor.
void DomainMap::eraseIfInputMappedThroughViewToOutput(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Renamed from eraseIfMappedThroughView

class DomainMap {
public:
DomainMap(Fusion* fusion);
virtual ~DomainMap() = default;
Copy link

Choose a reason for hiding this comment

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

This would be a very useful cache entry and I do expect it to be useful in many coming scheduler variants.

Copy link

Choose a reason for hiding this comment

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

Also just wondering, why does this need to be virtual? Meanwhile, could you add an interface function that exposes the underlying ca_map_ ? That'd be very helpful in many scenarios.

Copy link
Owner

Choose a reason for hiding this comment

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

The compute at map seems a bit dangerous to expose directly during scheduling as it will become out of date during scheduling. Though if we need the unscheduled ca_map_ that could make sense.

Copy link

Choose a reason for hiding this comment

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

Yes was hoping that this would cover the unscheduled ca_map usage for the heuristic cache entry. If this domain map is also used in scheduling phase, it'd need to be guarded.

Copy link

Choose a reason for hiding this comment

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

We could just revisit when other schedulers need to use ca_map_ as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think data caching is not available in the scheduling phase, so whenever you need it in scheduling, you rebuild it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added a

  const ComputeAtMap &getComputeAtMap() const {
    return ca_map_;
  }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also just wondering, why does this need to be virtual?

I would expect different schedulers to subclass this, but uses the same cache entry for caching. For this to work, I would need dynamic_cast, which requires the base class to be polymorphic.

@@ -24,6 +25,8 @@ namespace HeuristicCompileTime {

//! Enum for all possible types of cached entries of compile-time info.
enum class CompileTimeEntryType {
DOMAIN_MAP,
REFERENCE_TENSORS,
Copy link

Choose a reason for hiding this comment

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

Would appreciate more specific namings for the new entries.

DOMAIN_MAP probably ok if it can expose both ca_map and root_map to all schedulers.

REFERENCE_TENSORS sounds quite likely to have naming collision with other schedulers.

Copy link
Owner

Choose a reason for hiding this comment

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

Seems fine to me for now, we should mark this as a todo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

REFERENCE_TENSORS is a vector of tensors, and it is intended to be shared by many schedulers. For example, the pointwise scheduler can cache {reference_tv} and the transpose scheduler can cache {reference1, reference2}

std::vector<TensorView*> data{domain_map.findReferenceTensorView()};
return std::make_unique<std::vector<TensorView*>>(std::move(data));
});
TensorView* largest_out = largest_out_entry.get()[0];

Copy link

Choose a reason for hiding this comment

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

Thanks for caching these entries here. This path looks lightweight enough to me now.

Copy link
Owner

@csarofeen csarofeen left a comment

Choose a reason for hiding this comment

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

This seems good enough to me as is, definitely improvement on current state. I think we should take it so we can keep moving forward with the transpose scheduler.

@@ -24,6 +25,8 @@ namespace HeuristicCompileTime {

//! Enum for all possible types of cached entries of compile-time info.
enum class CompileTimeEntryType {
DOMAIN_MAP,
REFERENCE_TENSORS,
Copy link
Owner

Choose a reason for hiding this comment

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

Seems fine to me for now, we should mark this as a todo.

class DomainMap {
public:
DomainMap(Fusion* fusion);
virtual ~DomainMap() = default;
Copy link
Owner

Choose a reason for hiding this comment

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

The compute at map seems a bit dangerous to expose directly during scheduling as it will become out of date during scheduling. Though if we need the unscheduled ca_map_ that could make sense.

@zasdfgbnm zasdfgbnm merged commit d1caf33 into devel Jul 27, 2022
@zasdfgbnm zasdfgbnm deleted the refactor-pointwise branch July 27, 2022 18:19
jjsjann123 added a commit that referenced this pull request Aug 29, 2022
Syncing nvfuser devel branch to upstream master. https://github.com/csarofeen/pytorch/

Code changes includes:

- codegen improvements:
  1. removes un-necessary sync from redundant thread compute analysis
  2. symmetric API for BestEffortReplay
  3. support merge on trivial reductions
  4. Ampere async copy improvements
- bug fixes:
  1. vectorization bug fixes
  2. type inference patch : fixes upstream pytorch#81725
  3. segmenter bug fix with deterministic iteration ordering
- parser update
  1. added leaky_relu
- scheduler
  1. normalization scheduler clean up.
  2. simplifies matmul scheduling with new transform propagator
  3. merge all dimensions in PW scheduler
  4. various gemm related improvements
- debuggability
  1. nsight compute support
  2. debug dump for InlinePropagator
  3. Add `UnaryOpType::Print`

Squashed commits to WAR github API
Commits that's actually in this PR from the devel branch:

```
dfe02f3 Merge remote-tracking branch 'csarofeen/devel' into HEAD
1617373 Add `TensorViewBuilder::shape(std::vector<Val*> shape)` (#1884)
7cfb779 Merge pull request #1887 from csarofeen/upstream_merge_0803
3399f6d Merge remote-tracking branch 'origin/viable/strict' into HEAD
01208f5 Add `UnaryOpType::Print` which can be helpful for debugging (#1878)
0646522 Remove redundant TORCH_INTERNAL_ASSERT in lower_magic_zero.cpp (#1881)
7bc76aa Fix most inlined propagator for mismatched dims (#1875)
501f4aa Nonaffine swizzle formulation ep.2: Loop swizzle variant. (#1826)
d863d69 Ampere async copy ep.2: circular buffering extension to support pipelined matmul operand load (#1827)
e0ae11a Larger sized mma instructions to support full vectorization (#1824)
9bb4cf7 fragment iteration to support fully unrolled mma ops (#1823)
a48270a Merge all dims in pointwise scheduler (#1872)
172fb36 Make MostInlined and BestEffort inline propagation no longer assert replayed (#1868)
a64462a Allow trivial reduction to be merged (#1871)
440102b Symmetric API for BestEffortReplay (#1870)
d1caf33 Some misc cleanups/refactor split out from #1854 (#1867)
1013eda Remove some welford specific logic. (#1864)
51589d3 Some cleanups on tests and heuristics params (#1866)
a6b3e70 Segmenter bug fix, and deterministic iteration ordering.  (#1865)
1b665b9 Add nullptr checks to IrBuilder (#1861)
1cd9451 Simplify matmul scheduling with the new transform propagator.  (#1817)
bbc1fb9 Add leaky_relu operation (#1852)
e842a9b Minor cleanup in pointwise scheduler (#1858)
9ee850c Fix stringstream usage (#1857)
20a36c1 Improve nsight compute support (#1855)
4059103 Remove debugging `true ||` from getPointwiseHeuristics (#1822)
01117bf Misc cleanup (#1853)
5cc6494 Apply the magic-zero protection to each indexed domain individually for predicate indexing (#1846)
92e6f02 Cleanup normalization scheduler (#1845)
db89c65 Type inference patch (#1848)
102fe93 Add debug dump for InlinePropagator (#1847)
b7a4d93 Redundant thread compute analysis to avoid un-necessary sync insertion (#1687)
942be5b Upstream ci build fixes (#1842)
0b83645 Fix vectorization bug introduced in #1831 (#1840)
63630f1 Move MaxProducerPosUpdater into InlinePropagator::tearDown (#1825)
9135a96 Fix transpose benchmark dtype (#1839)
2c9a6c0 Add extra configurability to `parallelizeAllLike` (#1831)
```

RUN_TORCHBENCH: nvfuser

Differential Revision: [D38543000](https://our.internmc.facebook.com/intern/diff/D38543000)
Pull Request resolved: pytorch#83067
Approved by: https://github.com/davidberard98
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.

4 participants