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

proc config function should be able to index non-channel type #1747

Open
proppy opened this issue Nov 28, 2024 · 2 comments
Open

proc config function should be able to index non-channel type #1747

proppy opened this issue Nov 28, 2024 · 2 comments
Labels
bug Something isn't working or is incorrect dslx DSLX (domain specific language) implementation / front-end

Comments

@proppy
Copy link
Member

proppy commented Nov 28, 2024

Describe the bug
It seems that proc's config function assuming that all indexing is done against channel types.

To Reproduce
ir_convert on the following code:

const F32_0 = float32::zero(false);
const F32_2 = F32 { sign: false, bexp: u8:128, fraction: u23:0 };
const WEIGHTS = F32[u32:4][u32:4]:[
    [F32_2, F32_0, F32_0, F32_0], [F32_0, F32_2, F32_0, F32_0], [F32_0, F32_0, F32_2, F32_0],
    [F32_0, F32_0, F32_0, F32_2],
];

proc matmul<ROWS: u32, COLS: u32> {
    south_outputs: chan<F32>[COLS][ROWS] out;
    west_inputs: chan<F32>[COLS][ROWS] in;

    config(activations_in: chan<F32>[ROWS] in, results_out: chan<F32>[COLS] out) {
        let (east_outputs, west_inputs) = chan<F32>[COLS][ROWS]("east_west");

        let (south_outputs, north_inputs) = chan<F32>[COLS][ROWS]("north_south");

        spawn node(
            activations_in[0], north_inputs[0][0], east_outputs[0][0], south_outputs[1][0],
            WEIGHTS[0][0]);
        spawn node(
            west_inputs[0][0], north_inputs[0][1], east_outputs[0][1], south_outputs[1][1],
            WEIGHTS[0][1]);
        spawn node(
            west_inputs[0][1], north_inputs[0][2], east_outputs[0][2], south_outputs[1][2],
            WEIGHTS[0][2]);
        spawn node(
            west_inputs[0][2], north_inputs[0][3], east_outputs[0][3], south_outputs[1][3],
            WEIGHTS[0][3]);

        spawn node(
            activations_in[1], north_inputs[1][0], east_outputs[1][0], south_outputs[2][0],
            WEIGHTS[1][0]);
        spawn node(
            west_inputs[1][0], north_inputs[1][1], east_outputs[1][1], south_outputs[2][1],
            WEIGHTS[1][1]);
        spawn node(
            west_inputs[1][1], north_inputs[1][2], east_outputs[1][2], south_outputs[2][2],
            WEIGHTS[1][2]);
        spawn node(
            west_inputs[1][2], north_inputs[1][3], east_outputs[1][3], south_outputs[2][3],
            WEIGHTS[1][3]);

        spawn node(
            activations_in[2], north_inputs[2][0], east_outputs[2][0], south_outputs[3][0],
            WEIGHTS[2][0]);
        spawn node(
            west_inputs[2][0], north_inputs[2][1], east_outputs[2][1], south_outputs[3][1],
            WEIGHTS[2][1]);
        spawn node(
            west_inputs[2][1], north_inputs[2][2], east_outputs[2][2], south_outputs[3][2],
            WEIGHTS[2][2]);
        spawn node(
            west_inputs[2][2], north_inputs[2][3], east_outputs[2][3], south_outputs[3][3],
            WEIGHTS[2][3]);

        spawn node(
            activations_in[3], north_inputs[3][0], east_outputs[3][0], results_out[0], WEIGHTS[3][0]);
        spawn node(
            west_inputs[3][0], north_inputs[3][1], east_outputs[3][1], results_out[1], WEIGHTS[3][1]);
        spawn node(
            west_inputs[3][1], north_inputs[3][2], east_outputs[3][2], results_out[2], WEIGHTS[3][2]);
        spawn node(
            west_inputs[3][2], north_inputs[3][3], east_outputs[3][3], results_out[3], WEIGHTS[3][3]);

        (south_outputs, west_inputs)
    }

    init { () }
    next(state: ()) {
        unroll_for! (col, _): (u32, ()) in u32:0..COLS {
            send(join(), south_outputs[0][col], float32::zero(false));
        }(());
        unroll_for! (row, _): (u32, ()) in u32:0..ROWS {
            recv(join(), west_inputs[row][3]);
        }(());
    }
}

fails with the following error:

xls/dslx/frontend/bindings.cc:55
Error: NOT_FOUND: Not a channel or channel array: WEIGHTS; Failed to convert input to IR for comparison. Consider turning off comparison with `--compare=none`: 
=== Source Location Trace: === 
xls/common/status/status_builder.cc:197
xls/dslx/ir_convert/channel_scope.cc:368
xls/dslx/ir_convert/proc_config_ir_converter.cc:143
xls/dslx/ir_convert/proc_config_ir_converter.cc:260
xls/dslx/ir_convert/proc_config_ir_converter.cc:105
xls/dslx/ir_convert/ir_converter.cc:185
xls/dslx/ir_convert/ir_converter.cc:326
xls/dslx/ir_convert/ir_converter.cc:349
xls/dslx/ir_convert/ir_converter.cc:361
xls/dslx/run_routines/run_routines.cc:719
xls/dslx/interpreter_main.cc:203

Expected behavior

proc can access any array type in config.

@proppy proppy added bug Something isn't working or is incorrect dslx DSLX (domain specific language) implementation / front-end labels Nov 28, 2024
@proppy
Copy link
Member Author

proppy commented Nov 28, 2024

related, it seems that we currently throw an out of bound error when attempt to ir convert a proc spawning a child proc w/ a non channel array argument:

import float32;
type F32 = float32::F32;

proc matmul<ROWS: u32, COLS: u32> {
    south_outputs: chan<F32>[COLS][ROWS] out;
    west_inputs: chan<F32>[COLS][ROWS] in;

    config(activations_in: chan<F32>[ROWS] in, results_out: chan<F32>[COLS] out,
           weights: F32[ROWS][COLS]) {
        let (east_outputs, west_inputs) = chan<F32>[COLS][ROWS]("east_west");

        let (south_outputs, north_inputs) = chan<F32>[COLS][ROWS]("north_south");
        (south_outputs, west_inputs)
    }

    init { () }

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


const F32_0 = float32::zero(false);
const F32_2 = F32 { sign: false, bexp: u8:128, fraction: u23:0 };
const WEIGHTS = F32[u32:4][u32:4]:[
    [F32_2, F32_0, F32_0, F32_0], [F32_0, F32_2, F32_0, F32_0], [F32_0, F32_0, F32_2, F32_0],
    [F32_0, F32_0, F32_0, F32_2],
];


proc matmul_4x4 {
    config(activations_in: chan<F32>[4] in, results_out: chan<F32>[4] out) {
        spawn matmul<u32:4, u32:4>(activations_in, results_out, WEIGHTS);
    }

    init { () }

    next(state: ()) {  }
}
F1127 23:16:48.470303    6186 throw_delegate.cc:112] RAW: absl::container_internal::raw_hash_map<>::at
absl::raw_log_internal::RawLog()
absl::base_internal::ThrowStdOutOfRange()
xls::dslx::ProcConfigIrConverter::HandleSpawn()
xls::dslx::ProcConfigIrConverter::HandleStatement()
xls::dslx::ProcConfigIrConverter::HandleStatementBlock()
xls::dslx::ProcConfigIrConverter::HandleFunction()
xls::dslx::(anonymous namespace)::ConvertCallGraph()
xls::dslx::ConvertModuleIntoPackage()
xls::dslx::ConvertModuleToPackage()
xls::dslx::AbstractTestRunner::ParseAndTest()
main
__libc_start_main
_start

@proppy
Copy link
Member Author

proppy commented Nov 28, 2024

related, it seems that we currently throw an out of bound error when attempt to ir convert a proc spawning a child proc w/ a non channel array argument:

This seems to be related to the arguments being marked as const.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working or is incorrect dslx DSLX (domain specific language) implementation / front-end
Projects
Status: No status
Development

No branches or pull requests

1 participant