legacy codegen: four kinds of rank-1 tensor arithmetic fail, also for f32

Open
#3,549 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
52/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
rust
Domain
compilers

Research direction

Start with the legacy AST code generator (--legacy-codegen) and the failing cases described in the issue. Read tests/backend/pass/arithmetic_on_borrowed_half_tensors.vx and its REQUIRES: flat-codegen annotation, then compare the legacy and default code generator behavior for the four rank-1 arithmetic cases. Done means all four cases verify and produce the expected values, including with f32 tensors.

Written by the indexing model from the issue text.

Description

bug codegen

The AST code generator (--legacy-codegen) fails on four kinds of rank-1 tensor arithmetic. The default code generator prints the right value for each of them. Each one also fails with f32 tensors, so the cause is not the half types.

  1. A whole tensor and a scalar:

    let mut a = Tensor<f32, [2]>::new();
    a[0] = 2048.0;
    let s : f32 = 1.0;
    let c : Tensor<f32, [2]> = a + s;
    

    Warning: Falling back to bitcast from f32 to memref<?xf32>, and then MLIR verification fails.

  2. Two whole tensors of different element types, such as an f16 tensor plus an f32 tensor. The result is an f32 tensor:

    'memref.cast' op operand type 'memref<?xf32>' and result type 'memref<?xf16>' are cast incompatible

  3. Two borrowed tensors, let c = &a + &b;:

    'memref.dim' op operand #0 must be unranked.memref of any type values or non-0-ranked.memref of any type values, but got 'memref<memref<?xf32>>'

  4. A let that holds an operation on two rows, followed by an index into it:

    let r : Tensor<f32, [2]> = o[0] + o[1];
    println!("{}", r[0]);
    

    'memref.load' op operand #0 must be memref of any type values, but got 'vector<2xf32>'

tests/backend/pass/arithmetic_on_borrowed_half_tensors.vx has REQUIRES: flat-codegen because of the third case.

Found while working on #3267.

Dominant language
Rust
Stars
35
Forks
5
Avg merge
12h 26m
Merged PRs (30d)
799

Getting set up

We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vx-lang/Vx

All issues in vx-lang/Vx

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.