"vscode:/vscode.git/clone" did not exist on "d3536d9efab35511224926d7104b6e855b207097"
Commit 80ffea6d authored by Lei Wang's avatar Lei Wang Committed by LeiWang1999
Browse files

[Enhancement] Update ReduceOp initialization values for integer types (#614)

* [Enhancement] Update ReduceOp initialization values for integer types

- Modified the `MakeInitValue` method in `ReduceOp` to handle integer data types correctly by returning appropriate minimum and maximum values based on the bit width.
- Added checks for integer types to ensure correct initialization for `kMax` and `kMin` reduction types, enhancing the robustness of the reduction operations.

* [Enhancement] Update ReduceOp to handle unsigned integer initialization values

- Enhanced the `MakeInitValue` method in `ReduceOp` to include support for unsigned integer data types.
- Added conditions to return appropriate initialization values for `kMax` and `kMin` reduction types based on the data type, improving the robustness of reduction operations.
parent 42c3b452
......@@ -41,15 +41,32 @@ ReduceOp::ReduceOp(Array<PrimExpr> args, BufferMap vmap) {
}
PrimExpr ReduceOp::MakeInitValue() const {
auto dst_dtype = dst->dtype;
auto is_int = dst_dtype.is_int();
bool is_uint = dst_dtype.is_uint();
auto bits = dst_dtype.bits();
switch (type) {
case ReduceType::kSum:
return make_zero(dst->dtype);
case ReduceType::kAbsSum:
return make_zero(dst->dtype);
case ReduceType::kMax:
return make_const(dst->dtype, -INFINITY);
if (is_int) {
return make_const(dst->dtype, -(1 << (bits - 1)));
} else if (is_uint) {
return make_const(dst->dtype, 0);
} else {
return make_const(dst->dtype, -INFINITY);
}
case ReduceType::kMin:
return make_const(dst->dtype, INFINITY);
if (is_int) {
return make_const(dst->dtype, (1 << (bits - 1)) - 1);
} else if (is_uint) {
return make_const(dst->dtype, (1 << bits) - 1);
} else {
return make_const(dst->dtype, INFINITY);
}
case ReduceType::kAbsMax:
return make_const(dst->dtype, 0);
default:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment