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

Verilator Error: Circular Combinational Logic #2331

Closed
polybeandip opened this issue Nov 4, 2024 · 3 comments
Closed

Verilator Error: Circular Combinational Logic #2331

polybeandip opened this issue Nov 4, 2024 · 3 comments
Labels
C: Calyx Extension or change to the Calyx IL Type: Bug Bug in the implementation

Comments

@polybeandip
Copy link
Collaborator

polybeandip commented Nov 4, 2024

Consider the following snippet of Calyx code from this Zulip thread:

# bad.futil
import "primitives/core.futil";

component store(val: 32) -> () {
  cells {
    ref refreg = std_reg(32);
  }
  wires {
   group write {
     refreg.write_en = 1'b1;
     refreg.in = val;
     write[done] = refreg.done;
   }
  }
  control {
      write;
  }
}

component main() -> () {
  cells {
    storage = std_reg(32);
    propogate = std_reg(32);
    store = store();
    one = std_const(32, 1);
  }
  wires {
    group read {
      propogate.in = storage.out;
      propogate.write_en = 1'b1;
      read[done] = propogate.done;
    }
  }
  control {
      seq {
        invoke store[refreg=storage](val=one.out)();
        read;
      }
  }
}

This tries to store 32'b1 into the storage register and then move that data into the propogate register.

It appears Calyx compiles this to malformed Verilog since running this with

fud exec bad.futil --to dat --through verilog

gives the following Verilator error:

[fud] ERROR: `/opt/verilator/bin/verilator --trace /tmp/tmpx7bk5crd /scratch/ad739/calyx/fud/icarus/tb.sv --binary --top-module toplevel --Mdir /tmp/tmpj8622ain -fno-inline>&2' failed:
=====STDERR=====
%Warning-UNOPTFLAT: /tmp/tmpx7bk5crd:388:7: Signal unoptimizable: Circular combinational logic: 'toplevel.main.store_refreg_done'
                                          : ... In instance toplevel.main
  388 | logic store_refreg_done;
      |       ^~~~~~~~~~~~~~~~~
                    ... For warning description see https://verilator.org/warn/UNOPTFLAT?v=5.006
                    ... Use "/* verilator lint_off UNOPTFLAT */" and lint_on around source to disable this message.
                    /tmp/tmpx7bk5crd:388:7:      Example path: toplevel.main.store_refreg_done
                    /tmp/tmpx7bk5crd:555:22:      Example path: ASSIGNW
                    /tmp/tmpx7bk5crd:396:7:      Example path: toplevel.main.invoke0_go_in
                    /tmp/tmpx7bk5crd:565:26:      Example path: ASSIGNW
                    /tmp/tmpx7bk5crd:388:7:      Example path: toplevel.main.store_refreg_done
%Error: Exiting due to 1 warning(s)

=====STDOUT=====

In contrast, running our code with cider2 yields the correct result:

 cargo run -- circ.futil -l ../../ --dump-registers | ../../target/debug/cider-data-converter --to json
    Finished `dev` profile [unoptimized] target(s) in 0.09s
     Running `/Users/griffin/research/calyx/target/debug/cider bad.futil -l ../../ --dump-registers`
{
  "storage": [
    1
  ],
  "propogate": [
    1
  ]
}

(run locally by @EclecticGriffin)

@polybeandip polybeandip added Type: Bug Bug in the implementation C: Calyx Extension or change to the Calyx IL labels Nov 4, 2024
@rachitnigam
Copy link
Contributor

#2198 is the cause.

@polybeandip
Copy link
Collaborator Author

Apologies, I should've found that issue before posting. I'll close this one to avoid duplicates.

@polybeandip polybeandip closed this as not planned Won't fix, can't repro, duplicate, stale Nov 4, 2024
@rachitnigam
Copy link
Contributor

No worries! It is a tricky one!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: Calyx Extension or change to the Calyx IL Type: Bug Bug in the implementation
Projects
None yet
Development

No branches or pull requests

2 participants