forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unify reduction types from different operators: scatter, scatter_redu…
…ce, segment_reduce (pytorch#91499) The target of this PR is to unify `ReductionType` for reduce operators so that we have the same set of reduce utils for `init`, or `update` for vectorization. Pull Request resolved: pytorch#91499 Approved by: https://github.com/ngimel
- Loading branch information
1 parent
a70387f
commit eb7b897
Showing
12 changed files
with
211 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#pragma once | ||
|
||
#include <c10/core/Scalar.h> | ||
|
||
namespace at { namespace native { | ||
|
||
enum ReductionType {MAX, MEAN, MIN, SUM, PROD}; | ||
|
||
static inline ReductionType get_reduction_enum(const c10::string_view& reduce) { | ||
if (reduce == "amax") { | ||
return ReductionType::MAX; | ||
} else if (reduce == "mean") { | ||
return ReductionType::MEAN; | ||
} else if (reduce == "amin") { | ||
return ReductionType::MIN; | ||
} else if (reduce == "sum") { | ||
return ReductionType::SUM; | ||
} else if (reduce == "prod") { | ||
return ReductionType::PROD; | ||
} else { | ||
TORCH_CHECK(false, "reduce argument must be either sum, prod, mean, amax or amin, got ", reduce); | ||
} | ||
} | ||
|
||
// used for `scatter_reduce`, old options for BC. | ||
static inline ReductionType get_operator_enum(const c10::string_view reduce, bool use_new_options) { | ||
if (use_new_options) { | ||
return get_reduction_enum(reduce); | ||
} else { | ||
if (reduce == "add") { | ||
return ReductionType::SUM; | ||
} else if (reduce == "multiply") { | ||
return ReductionType::PROD; | ||
} else { | ||
TORCH_CHECK(false, "reduce argument must be either add or multiply.") | ||
} | ||
} | ||
} | ||
|
||
}} // at::native |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.