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

DSLX interpreter is not properly resetting channels between test_procs #1789

Closed
meheff opened this issue Dec 12, 2024 · 2 comments
Closed

DSLX interpreter is not properly resetting channels between test_procs #1789

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

Comments

@meheff
Copy link
Collaborator

meheff commented Dec 12, 2024

Channels are not cleared completely between test_proc invocations in DSLX interpreter. Code is below. Each of the layers seems to be necessary (top, middle, and bottom). Also the bottom layer needs to not send/receive every cycle. Running both tests results in the second test failing with channel values seemingly coming from the first test. Running the second test alone results in it passing.

Repro

$ interpreter_main bad.x
[ RUN UNITTEST  ] test1
[            OK ]
[ RUN UNITTEST  ] test2
/usr/local/google/home/meheff/tmp/bad_procs.x:84:18-84:29
0082:         let tok = send(tok, i, u32:42);
0083:         let (tok, d) = recv(tok, o);
0084:         assert_eq(d, u32:42);
~~~~~~~~~~~~~~~~~~~~~~~^---------^ FailureError: The program being interpreted failed!
  lhs: u32:100
  rhs: u32:42
  were not equal
0085:         let tok = send(tok, terminator, true);
0086:     }
[        FAILED ] test2
[===============] 2 test(s) ran; 1 failed; 0 skipped.

$ interpreter_main  bad.x --test_filter=test2
[ RUN UNITTEST  ] test2
[            OK ]
[===============] 2 test(s) ran; 0 failed; 1 skipped.

It works with IR interpreter:

$ interpreter_main bad.x --evaluator=ir-interpreter
[ RUN UNITTEST  ] test1
[            OK ]
[ RUN UNITTEST  ] test2
[            OK ]

Code:

// Receives an input once and sends it twice.
proc bottom {
  i: chan<u32> in;
  o: chan<u32> out;
  config(i: chan<u32> in, o: chan<u32> out) {
    (i, o)
  }
  init { (u1:0, u32:0) }
  next(s: (u1, u32)) {
    let tok = join();
    let (tok, d) = recv_if(tok, i, s.0==u1:0, u32:0);
    let next_d = if s.0==u1:0 { d } else {s.1} ;
    let tok = send(tok, o, next_d);
    (s.0 + u1:1, next_d)
  }
}

// Receives an input once and sends it four times by spawning bottom twice in series.
proc middle {
  config(i: chan<u32> in, o: chan<u32> out) {
    let (tmp0_s, tmp0_r)= chan<u32>("passthru");
    spawn bottom(i, tmp0_s);
    spawn bottom(tmp0_r, o);
  }
  init { () }
  next(state: ()) { () }
}

// Receives an input once and sends it four times by trivially spawning `middle`.
proc top {
  config(i: chan<u32> in, o: chan<u32> out) {
    spawn middle(i, o);
  }
  init { () }
  next(state: ()) { () }
}

#[test_proc]
proc test1 {
    terminator: chan<bool> out;
    i: chan<u32> out;
    o: chan<u32> in;

    config(terminator: chan<bool> out) {
        let (i_s, i_r) = chan<u32>("i");
        let (o_s, o_r) = chan<u32>("o");
        spawn top(i_r, o_s);
        (terminator, i_s, o_r)
    }

    init { () }

    next(state: ()) {
        let tok = join();
        let tok = send(tok, i, u32:100);

        let (tok, d) = recv(tok, o);
        assert_eq(d, u32:100);
        let (tok, d) = recv(tok, o);
        assert_eq(d, u32:100);
        let tok = send(tok, terminator, true);
    }
}

#[test_proc]
proc test2 {
    terminator: chan<bool> out;
    i: chan<u32> out;
    o: chan<u32> in;

    config(terminator: chan<bool> out) {
        let (i_s, i_r) = chan<u32>("i");
        let (o_s, o_r) = chan<u32>("o");
        spawn top(i_r, o_s);
        (terminator, i_s, o_r)
    }

    init { () }

    next(state: ()) {
        let tok = join();
        let tok = send(tok, i, u32:42);
        let (tok, d) = recv(tok, o);
        assert_eq(d, u32:42);
        let tok = send(tok, terminator, true);
    }
}
@meheff meheff added bug Something isn't working or is incorrect dslx DSLX (domain specific language) implementation / front-end labels Dec 12, 2024
@meheff
Copy link
Collaborator Author

meheff commented Dec 12, 2024

Looking deeper into the problem, it looks like exactly one channel object is reused between the tests. I think it is the one declared as passthru in the proc middle.

@meheff
Copy link
Collaborator Author

meheff commented Dec 12, 2024

Here's the results with --trace_channels. At the start of the second test the second instantiation of bottom is reading stale information from the channel.

[ RUN UNITTEST  ] test1
I1211 17:55:00.995284 1521651 bad_procs.x:55] Sent data on channel `test1::i` [1]:
I1211 17:55:00.995319 1521651 bad_procs.x:55]   u32:100
I1211 17:55:00.995391 1521651 bad_procs.x:11] Received data on channel `bottom::i (test1->top:0->middle:0->bottom:0)` [0]:
I1211 17:55:00.995429 1521651 bad_procs.x:11]   u32:100
I1211 17:55:00.995477 1521651 bad_procs.x:13] Sent data on channel `bottom::o (test1->top:0->middle:0->bottom:0)` [1]:
I1211 17:55:00.995491 1521651 bad_procs.x:13]   u32:100
I1211 17:55:00.995535 1521651 bad_procs.x:11] Received data on channel `bottom::i (test1->top:0->middle:0->bottom:1)` [0]:
I1211 17:55:00.995549 1521651 bad_procs.x:11]   u32:100
I1211 17:55:00.995587 1521651 bad_procs.x:13] Sent data on channel `bottom::o (test1->top:0->middle:0->bottom:1)` [1]:
I1211 17:55:00.995604 1521651 bad_procs.x:13]   u32:100
I1211 17:55:00.995649 1521651 bad_procs.x:57] Received data on channel `test1::o` [0]:
I1211 17:55:00.995685 1521651 bad_procs.x:57]   u32:100
I1211 17:55:00.995764 1521651 bad_procs.x:13] Sent data on channel `bottom::o (test1->top:0->middle:0->bottom:0)` [1]:
I1211 17:55:00.995778 1521651 bad_procs.x:13]   u32:100
I1211 17:55:00.995842 1521651 bad_procs.x:13] Sent data on channel `bottom::o (test1->top:0->middle:0->bottom:1)` [1]:
I1211 17:55:00.995856 1521651 bad_procs.x:13]   u32:100
I1211 17:55:00.995897 1521651 bad_procs.x:59] Received data on channel `test1::o` [0]:
I1211 17:55:00.995913 1521651 bad_procs.x:59]   u32:100
I1211 17:55:00.995952 1521651 bad_procs.x:61] Sent data on channel `test1::terminator` [1]:
I1211 17:55:00.995988 1521651 bad_procs.x:61]   u1:1
[            OK ]
[ RUN UNITTEST  ] test2
I1211 17:55:00.996839 1521651 bad_procs.x:11] Received data on channel `bottom::i (test2->top:0->middle:0->bottom:1)` [0]:
I1211 17:55:00.996863 1521651 bad_procs.x:11]   u32:100
I1211 17:55:00.996911 1521651 bad_procs.x:13] Sent data on channel `bottom::o (test2->top:0->middle:0->bottom:1)` [1]:
I1211 17:55:00.996925 1521651 bad_procs.x:13]   u32:100
I1211 17:55:00.996985 1521651 bad_procs.x:82] Sent data on channel `test2::i` [1]:
I1211 17:55:00.997020 1521651 bad_procs.x:82]   u32:42
I1211 17:55:00.997047 1521651 bad_procs.x:83] Received data on channel `test2::o` [0]:
I1211 17:55:00.997060 1521651 bad_procs.x:83]   u32:100
/usr/local/google/home/meheff/tmp/bad_procs.x:84:18-84:29
0082:         let tok = send(tok, i, u32:42);
0083:         let (tok, d) = recv(tok, o);
0084:         assert_eq(d, u32:42);
~~~~~~~~~~~~~~~~~~~~~~~^---------^ FailureError: The program being interpreted failed!
  lhs: u32:100
  rhs: u32:42
  were not equal
0085:         let tok = send(tok, terminator, true);
0086:     }
[        FAILED ] test2
[===============] 2 test(s) ran; 1 failed; 0 skipped.

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: Done
Development

No branches or pull requests

1 participant