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

Divide by zero during vectorize loops #7888

Closed
TH3CHARLie opened this issue Oct 9, 2023 · 1 comment · Fixed by #7889
Closed

Divide by zero during vectorize loops #7888

TH3CHARLie opened this issue Oct 9, 2023 · 1 comment · Fixed by #7889
Assignees
Labels

Comments

@TH3CHARLie
Copy link
Contributor

TH3CHARLie commented Oct 9, 2023

A repro:

#include "Halide.h"
using namespace Halide;

int main() {
    Func input("input");
    Func local_sum("local_sum");
    Func blurry("blurry");
    Var x("x"), y("y");
    input(x, y) = 2 * x + 5 * y;
    RDom r(-2, 5, -2, 5);
    local_sum(x, y) = 0;
    local_sum(x, y) += input(x + r.x, y + r.y);
    blurry(x, y) = cast<int32_t>(local_sum(x, y) / 25);
    {
        Var yo, yi, yoo, yoi, yooo, yooi, yoio, yoii, yoio_x_f, v;
        local_sum.update(0).vectorize(y).split(y, yo, yi, 8, TailStrategy::Auto).split(yo, yoo, yoi, 8, TailStrategy::Auto).split(yoo, yooo, yooi, 8, TailStrategy::Auto);
        local_sum.update(0).rfactor(r.x, v);
        Pipeline p({blurry});
        Buffer<int> buf = p.realize({128, 128});
    }
    return 0;
}

Crash:

Program received signal SIGFPE, Arithmetic exception.
0x00007ffff0b64584 in Halide::Internal::(anonymous namespace)::VectorSubs::widen(Halide::Expr, int) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
(gdb) bt
#0  0x00007ffff0b64584 in Halide::Internal::(anonymous namespace)::VectorSubs::widen(Halide::Expr, int) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#1  0x00007ffff0b5ae6f in Halide::Internal::(anonymous namespace)::VectorSubs::visit(Halide::Internal::Mul const*) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#2  0x00007ffff073e713 in Halide::Internal::ExprNode<Halide::Internal::Mul>::mutate_expr(Halide::Internal::IRMutator*) const () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#3  0x00007ffff0749c8b in Halide::Internal::IRMutator::mutate(Halide::Expr const&) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#4  0x00007ffff0b5aa19 in Halide::Internal::(anonymous namespace)::VectorSubs::visit(Halide::Internal::Add const*) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#5  0x00007ffff073e6d3 in Halide::Internal::ExprNode<Halide::Internal::Add>::mutate_expr(Halide::Internal::IRMutator*) const () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#6  0x00007ffff0749c8b in Halide::Internal::IRMutator::mutate(Halide::Expr const&) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#7  0x00007ffff0b5ae19 in Halide::Internal::(anonymous namespace)::VectorSubs::visit(Halide::Internal::Mul const*) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#8  0x00007ffff073e713 in Halide::Internal::ExprNode<Halide::Internal::Mul>::mutate_expr(Halide::Internal::IRMutator*) const () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#9  0x00007ffff0749c8b in Halide::Internal::IRMutator::mutate(Halide::Expr const&) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#10 0x00007ffff0b5aa19 in Halide::Internal::(anonymous namespace)::VectorSubs::visit(Halide::Internal::Add const*) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#11 0x00007ffff073e6d3 in Halide::Internal::ExprNode<Halide::Internal::Add>::mutate_expr(Halide::Internal::IRMutator*) const () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#12 0x00007ffff0749c8b in Halide::Internal::IRMutator::mutate(Halide::Expr const&) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#13 0x00007ffff0b5fef6 in Halide::Internal::(anonymous namespace)::VectorSubs::visit(Halide::Internal::For const*) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#14 0x00007ffff073ea36 in Halide::Internal::StmtNode<Halide::Internal::For>::mutate_stmt(Halide::Internal::IRMutator*) const () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#15 0x00007ffff0749cbb in Halide::Internal::IRMutator::mutate(Halide::Internal::Stmt const&) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#16 0x00007ffff0b5ef2e in Halide::Internal::(anonymous namespace)::VectorSubs::visit(Halide::Internal::LetStmt const*) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#17 0x00007ffff073e9d6 in Halide::Internal::StmtNode<Halide::Internal::LetStmt>::mutate_stmt(Halide::Internal::IRMutator*) const () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#18 0x00007ffff0749cbb in Halide::Internal::IRMutator::mutate(Halide::Internal::Stmt const&) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#19 0x00007ffff0b5ffed in Halide::Internal::(anonymous namespace)::VectorSubs::visit(Halide::Internal::For const*) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#20 0x00007ffff073ea36 in Halide::Internal::StmtNode<Halide::Internal::For>::mutate_stmt(Halide::Internal::IRMutator*) const () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#21 0x00007ffff0749cbb in Halide::Internal::IRMutator::mutate(Halide::Internal::Stmt const&) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#22 0x00007ffff0b5ffed in Halide::Internal::(anonymous namespace)::VectorSubs::visit(Halide::Internal::For const*) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#23 0x00007ffff073ea36 in Halide::Internal::StmtNode<Halide::Internal::For>::mutate_stmt(Halide::Internal::IRMutator*) const () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#24 0x00007ffff0749cbb in Halide::Internal::IRMutator::mutate(Halide::Internal::Stmt const&) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#25 0x00007ffff074d19c in Halide::Internal::IRMutator::visit(Halide::Internal::Block const*) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#26 0x00007ffff073eaf6 in Halide::Internal::StmtNode<Halide::Internal::Block>::mutate_stmt(Halide::Internal::IRMutator*) const () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#27 0x00007ffff0749cbb in Halide::Internal::IRMutator::mutate(Halide::Internal::Stmt const&) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#28 0x00007ffff074c38c in Halide::Internal::IRMutator::visit(Halide::Internal::ProducerConsumer const*) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#29 0x00007ffff073ea16 in Halide::Internal::StmtNode<Halide::Internal::ProducerConsumer>::mutate_stmt(Halide::Internal::IRMutator*) const () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#30 0x00007ffff0749cbb in Halide::Internal::IRMutator::mutate(Halide::Internal::Stmt const&) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#31 0x00007ffff074d188 in Halide::Internal::IRMutator::visit(Halide::Internal::Block const*) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#32 0x00007ffff073eaf6 in Halide::Internal::StmtNode<Halide::Internal::Block>::mutate_stmt(Halide::Internal::IRMutator*) const () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#33 0x00007ffff0749cbb in Halide::Internal::IRMutator::mutate(Halide::Internal::Stmt const&) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#34 0x00007ffff0b61210 in Halide::Internal::(anonymous namespace)::VectorSubs::visit(Halide::Internal::Allocate const*) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#35 0x00007ffff073ea96 in Halide::Internal::StmtNode<Halide::Internal::Allocate>::mutate_stmt(Halide::Internal::IRMutator*) const () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#36 0x00007ffff0749cbb in Halide::Internal::IRMutator::mutate(Halide::Internal::Stmt const&) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#37 0x00007ffff0b5fbb3 in Halide::Internal::(anonymous namespace)::VectorSubs::visit(Halide::Internal::For const*) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#38 0x00007ffff073ea36 in Halide::Internal::StmtNode<Halide::Internal::For>::mutate_stmt(Halide::Internal::IRMutator*) const () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#39 0x00007ffff0749cbb in Halide::Internal::IRMutator::mutate(Halide::Internal::Stmt const&) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#40 0x00007ffff0b5ffed in Halide::Internal::(anonymous namespace)::VectorSubs::visit(Halide::Internal::For const*) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#41 0x00007ffff073ea36 in Halide::Internal::StmtNode<Halide::Internal::For>::mutate_stmt(Halide::Internal::IRMutator*) const () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#42 0x00007ffff0749cbb in Halide::Internal::IRMutator::mutate(Halide::Internal::Stmt const&) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#43 0x00007ffff0b5ffed in Halide::Internal::(anonymous namespace)::VectorSubs::visit(Halide::Internal::For const*) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#44 0x00007ffff073ea36 in Halide::Internal::StmtNode<Halide::Internal::For>::mutate_stmt(Halide::Internal::IRMutator*) const () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#45 0x00007ffff0749cbb in Halide::Internal::IRMutator::mutate(Halide::Internal::Stmt const&) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#46 0x00007ffff0b58cae in Halide::Internal::(anonymous namespace)::VectorizeLoops::visit(Halide::Internal::For const*) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#47 0x00007ffff073ea36 in Halide::Internal::StmtNode<Halide::Internal::For>::mutate_stmt(Halide::Internal::IRMutator*) const () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#48 0x00007ffff0749cbb in Halide::Internal::IRMutator::mutate(Halide::Internal::Stmt const&) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#49 0x00007ffff074d19c in Halide::Internal::IRMutator::visit(Halide::Internal::Block const*) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#50 0x00007ffff073eaf6 in Halide::Internal::StmtNode<Halide::Internal::Block>::mutate_stmt(Halide::Internal::IRMutator*) const () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#51 0x00007ffff0749cbb in Halide::Internal::IRMutator::mutate(Halide::Internal::Stmt const&) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#52 0x00007ffff074c38c in Halide::Internal::IRMutator::visit(Halide::Internal::ProducerConsumer const*) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#53 0x00007ffff073ea16 in Halide::Internal::StmtNode<Halide::Internal::ProducerConsumer>::mutate_stmt(Halide::Internal::IRMutator*) const () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#54 0x00007ffff0749cbb in Halide::Internal::IRMutator::mutate(Halide::Internal::Stmt const&) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#55 0x00007ffff074d188 in Halide::Internal::IRMutator::visit(Halide::Internal::Block const*) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#56 0x00007ffff073eaf6 in Halide::Internal::StmtNode<Halide::Internal::Block>::mutate_stmt(Halide::Internal::IRMutator*) const () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#57 0x00007ffff0749cbb in Halide::Internal::IRMutator::mutate(Halide::Internal::Stmt const&) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#58 0x00007ffff074caae in Halide::Internal::IRMutator::visit(Halide::Internal::Allocate const*) () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
#59 0x00007ffff073ea96 in Halide::Internal::StmtNode<Halide::Internal::Allocate>::mutate_stmt(Halide::Internal::IRMutator*) const () from /home/xuanda/dev/Serializer/Halide-clean/build/src/libHalide.so.17
@TH3CHARLie TH3CHARLie added the bug label Oct 9, 2023
@abadams
Copy link
Member

abadams commented Oct 10, 2023

This schedule creates vectors with 262144 lanes, because there are 6 nested for loops, each vectorized by a factor of 8. We only support vectors with up to 65535 lanes, so this overflows somewhere and ends up creating a zero-lane vector and then modding by zero. I'll add an overflow check somewhere to make this an error instead of a compiler crash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants