Skip to content

2D array channel out shows errors like it was not constexpr: c_out: INVALID_ARGUMENT #1830

@Mars-Cat2023

Description

@Mars-Cat2023

Describe the bug
When adapt the example DSLX code matmul_4x4.x. I add another 2D array channel out (c_out: chan[3][3] out). But it gives me the error like not constexpr: 'c_out': INVALID_ARGUMENT. I didn't know where it needs this constexpr attribute.

To Reproduce
Steps to reproduce the behavior:

...
// well defined `proc node` here.
...

proc matmul<ROWS: u32, COLS: u32> {
    // Public Interface:
    a_in: chan<F32>[ROWS] in;
    b_in: chan<F32>[COLS] in;
    c_out: chan<F32>[COLS][ROWS] out;
    screenshot_reset: chan<bool> in;

    // Private (Internal) Members:
    west_inputs: chan<F32>[COLS + u32:1][ROWS] in;
    north_inputs: chan<F32>[COLS][ROWS + u32:1] in;
    east_outputs: chan<F32>[COLS + u32:1][ROWS] out;
    south_outputs: chan<F32>[COLS][ROWS + u32:1] out;


    config(a_in: chan<F32>[ROWS] in, b_in: chan<F32>[COLS] in, 
           c_out: chan<F32>[COLS][ROWS] out, screenshot_reset: chan<u1> in) {
        // Declare internal east-to-west channels and south-to-north channels.
        let (east_outputs, west_inputs) = chan<F32>[COLS + u32:1][ROWS]("east_west");
        let (south_outputs, north_inputs) = chan<F32>[COLS][ROWS + u32:1]("south_north");

        unroll_for! (row, _): (u32, ()) in u32:0..ROWS {
            unroll_for! (col, _): (u32, ()) in u32:0..COLS {
                spawn node(
                    west_inputs[row][col], north_inputs[row][col], east_outputs[row][col + u32:1], 
                    south_outputs[row + u32:1][col], screenshot_reset,
                    c_out[row][col]);
            }(());
        }(());
        
        (a_in, b_in, c_out, screenshot_reset, west_inputs, north_inputs, east_outputs, south_outputs)
    }

    init { () }

    next(state: ()) {
        // Send input matricies:
        let zero = u32:0;
        unroll_for! (row, _): (u32, ()) in u32:0..ROWS {
            let (tok, local_a) = recv(join(), a_in[row]);
            send(tok, east_outputs[row][zero], local_a);
        }(());
        unroll_for! (col, _): (u32, ()) in u32:0..COLS {
            let (tok, local_b) = recv(join(), b_in[col]);
            send(tok, south_outputs[zero][col], local_b);
        }(());

        // No useful outputs from the other side (Drop):
        // TODO - google/xls#1750: remove unroll_for! workaround.
        unroll_for! (cols, _): (u32, ()) in COLS..COLS + u32:1 {
            unroll_for! (row, _): (u32, ()) in u32:0..ROWS {
                recv(join(), west_inputs[row][cols]);
            }(());
        }(());
        unroll_for! (rows, _): (u32, ()) in ROWS..ROWS + u32:1 {
            unroll_for! (col, _): (u32, ()) in u32:0..COLS {
                recv(join(), north_inputs[rows][col]);
            }(());
        }(());
    }
}

// proc matmul_3x3 {
//     config(a_in: chan<F32>[3] in, b_in: chan<F32>[3] in, 
//            c_out: chan<F32>[3][3] out, screenshot_reset: chan<bool> in) {
//         spawn matmul<u32:3, u32:3>(a_in, b_in, c_out, screenshot_reset);
//     }

//     init { () }

//     next(state: ()) { }
// }

Expected behavior

If you remove the comment sign before this part :

proc matmul_3x3 {
    config(a_in: chan<F32>[3] in, b_in: chan<F32>[3] in, 
           c_out: chan<F32>[3][3] out, screenshot_reset: chan<bool> in) {
        spawn matmul<u32:3, u32:3>(a_in, b_in, c_out, screenshot_reset);
    }

    init { () }

    next(state: ()) { }
}

Then when you call it by spawn matmul_3x3(a_in, b_in, c_out, screenshot_reset); in the following test_proc, it will give you error like this:

$ ./bazel-bin/xls/dslx/interpreter_main  E3_F32_matrixmul4_3_2025.x
E0106 16:52:13.244860   19019 command_line_utils.cc:50] Could not extract a textual position from error message: INVALID_ARGUMENT: Expression @ E3_F32_matrixmul4_3_2025.x:126:48-126:53 was not constexpr: `c_out`: INVALID_ARGUMENT: Provided status is not in recognized error form: INVALID_ARGUMENT: Expression @ E3_F32_matrixmul4_3_2025.x:126:48-126:53 was not constexpr: `c_out`
Error: INVALID_ARGUMENT: Expression @ E3_F32_matrixmul4_3_2025.x:126:48-126:53 was not constexpr: `c_out`

but if I remove that layer of abstraction by calling the spawn matmul<u32:3, u32:3>(a_in, b_in, c_out, screenshot_reset); myself, it will not give any problems. Why?
I am confusing where do I use constexpr in my code? Why it doesn't work if I define 2D output channels? But it still work well if I only define 1D output channels like example code from your github repo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working or is incorrectdslxDSLX (domain specific language) implementation / front-end

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions