Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/op/reduce.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,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:
Expand Down
Loading