Skip to content

No asserts emitted for strides based on other dims extent. #9327

Description

@mcourteaux

When promising dense data:

      int bsx = 16; // block size x
      output.dim(0).extent() = output.dim(0).extent() / bsx * bsx;
      output.dim(1).stride() = output.dim(0).extent();
      output.dim(2).stride() = output.dim(0).stride() * output.dim(1).extent();

Not a single assert is emitted that checks this.

I validated that this both happens on main and on @alexreinking/fix-extent-alignment

Activity

  1. alexreinking commented on Aug 13, 2026

    @alexreinking
    Member

    Try this:

    int bsx = 16; // block size x
    output.dim(0).set_extent(output.dim(0).extent() / bsx * bsx);
    output.dim(1).set_stride(output.dim(0).extent());
    output.dim(2).set_stride(output.dim(0).stride() * output.dim(1).extent());
  2. mcourteaux commented on Aug 13, 2026

    @mcourteaux
    ContributorAuthor

    Dang. 💀 These should probably return const & or const to avoid usage bugs like this.

  3. mcourteaux commented on Aug 13, 2026

    @mcourteaux
    ContributorAuthor

    Yes that does emit the asserts for the first two:

    assert(((output$2.extent.0 % 16) == 0), halide_error_constraint_violated("output$2.extent.0", output$2.extent.0, "((output$2.extent.0/16)*16)", ((output$2.extent.0 / 16) * 16)))
    assert((output$2.extent.0 == output$2.stride.1), halide_error_constraint_violated("output$2.stride.1", output$2.stride.1, "output$2.extent.0", output$2.extent.0))

    However, the third one, regarding output.stride.2 is missing.

    On a side-note: I do spot this weird let:

    let output$2.total_extent.1 = (int64(output$2.stride.2) * int64(output$2.stride.1))

    I cannot think of anything where multiplying strides together makes any sense. Comparing the same Let, but with add_requirements() as described in #9328 generates a reasonable Let:

    let output$2.total_extent.1 = (int64(output$2.extent.1) * int64(output$2.extent.0))
  4. alexreinking commented on Aug 13, 2026

    @alexreinking
    Member

    On a side-note: I do spot this weird let:

    let output$2.total_extent.1 = (int64(output$2.stride.2) * int64(output$2.stride.1))

    Well, you did say that output$2.stride.1 and output$2.extent.0 are equal. 🙂

  5. mcourteaux commented on Aug 13, 2026

    @mcourteaux
    ContributorAuthor

    Yes, but I didn't specify that stride.2 equals extent.1. That doesn't make any sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions