phanrahan / magma

magma circuits
Other
253 stars 24 forks source link

magma error: test_clock_tuple_compile.py #774

Closed phanrahan closed 4 years ago

phanrahan commented 4 years ago

Any ideas what is causing this error? I updated coreir.

tests/test_coreir/test_clock_tuple_compile.py ERROR:magma:Input port Foo_inst0.clocks not driven
  Def:
    Instances:
      Foo_inst0 : Foo
    Connections:
      Foo_inst0.I <=> self.I
      Foo_inst0.O <=> self.O

ERROR: {Main}.Foo_inst0.clocks_clk Is not fully connected (N)
{Main}.Foo_inst0.clocks_rst Is not connected

I AM DYING!
Assertion failed: (0), function die, file /Users/hanrahan/git/coreir/src/ir/context.cpp, line 104.
F

=================================== FAILURES ===================================
_________________________ test_auto_wire_tuple_clocks __________________________

    def test_auto_wire_tuple_clocks():
        class Intf(m.Product):
            clk = m.In(m.Clock)
            rst = m.In(m.Reset)

        class Foo(m.Circuit):
            io = m.IO(clocks=Intf, I=m.In(m.Bit), O=m.Out(m.Bit))

        class Main(m.Circuit):
            io = m.IO(clocks=Intf, I=m.In(m.Bit), O=m.Out(m.Bit))

            foo = Foo()
            foo.I @= io.I
            io.O @= foo.O

>       m.compile("build/test_auto_wire_tuple_clocks", Main)

tests/test_coreir/test_clock_tuple_compile.py:22: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
magma/compile.py:62: in compile
    compiler.compile()
magma/backend/coreir_compiler.py:73: in compile
    fn()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <magma.backend.coreir_compiler.CoreIRCompiler object at 0x7fa4fad29410>

    def _compile_verilog(self):
        cmd = _make_verilog_cmd(self.deps, self.basename, self.opts)
        ret = subprocess.run(cmd, shell=True).returncode
        if ret:
>           raise RuntimeError(f"CoreIR cmd '{cmd}' failed with code {ret}")
E           RuntimeError: CoreIR cmd 'coreir -l global -i /Users/hanrahan/git/magma/tests/test_coreir/build/test_auto_wire_tuple_clocks.json -o /Users/hanrahan/git/magma/tests/test_coreir/build/test_auto_wire_tuple_clocks.v' failed with code -6

magma/backend/coreir_compiler.py:87: RuntimeError
------------------------------ Captured log call -------------------------------
ERROR    magma:logging.py:87 Input port Foo_inst0.clocks not driven
=========================== short test summary info ============================
FAILED tests/test_coreir/test_clock_tuple_compile.py::test_auto_wire_tuple_clocks
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
=================== 1 failed, 99 passed, 3 skipped in 2.64s ====================
leonardt commented 4 years ago

Hmm, can you do $ pip show magma-lang coreir fault hwtypes to see what versions of the various packages you're running? I have

Name: magma-lang
Version: 2.0.68
...
---
Name: coreir
Version: 2.0.87
...
---
Name: fault
Version: 3.0.24
...
---
Name: hwtypes
Version: 1.4.2
...
leonardt commented 4 years ago

Also, it looks like you're using a local installation of coreir (based on /Users/hanrahan/git/coreir/src/ir/context.cpp). One sanity check would be to uninstall this version (remove it from your path or use make uninstall in your build directory), install the latest pycoreir package (pip install --upgrade coreir), then re-run the test. If this works, that would suggest a problem with your local build that we can investigate

phanrahan commented 4 years ago

Hmm. I have the development versions checked out. They don't work?

% pip show magma-lang coreir fault hwtypes
Name: magma-lang
Version: 2.0.68
Summary: An embedded DSL for constructing hardware circuits
Home-page: https://github.com/phanrahan/magma
Author: None
Author-email: None
License: MIT
Location: /Users/hanrahan/miniconda3/lib/python3.7/site-packages
Requires: hwtypes, numpy, coreir, ast-tools, six, kratos, graphviz, mako, staticfg, astor, pyverilog, colorlog, dataclasses
Required-by: gemstone, canal, fault, mantle
---
Name: coreir
Version: 2.0.87
Summary: Python bindings for CoreIR
Home-page: https://github.com/leonardt/pycoreir
Author: Leonard Truong
Author-email: lenny@cs.stanford.edu
License: BSD License
Location: /Users/hanrahan/git/pycoreir
Requires: hwtypes
Required-by: magma-lang, metamapper, CoSA, fault
---
Name: fault
Version: 3.0.23
Summary: A Python package for testing hardware (part of the magma ecosystem)
Home-page: https://github.com/leonardt/fault
Author: Leonard Truong
Author-email: lenny@cs.stanford.edu
License: BSD License
Location: /Users/hanrahan/git/fault
Requires: astor, coreir, cosa, z3-solver, hwtypes, magma-lang, pyyaml, scipy, numpy, DeCiDa
Required-by: gemstone, mantle
---
Name: hwtypes
Version: 1.4.2
Summary: Python implementations of fixed size hardware types (Bit, BitVector, UInt, SInt, ...) based on the SMT-LIB2 semantics
Home-page: https://github.com/leonardt/hwtypes
Author: Leonard Truong
Author-email: lenny@cs.stanford.edu
License: UNKNOWN
Location: /Users/hanrahan/miniconda3/lib/python3.7/site-packages
Requires: gmpy2, pysmt, z3-solver
Required-by: magma-lang, gemstone, canal, CoSA, coreir, fault
leonardt commented 4 years ago

The development versions should work, but I wanted to just verify that they are being used. Can you try using the release version of the pycoreir package? Perhaps there's some problem with your local installation.

Also, can you try doing /usr/local/bin/coreir --version to see which version you have installed? (You may need to change the path to where you have it installed if it's in a different location). The current master branch should be installing v0.1.40

phanrahan commented 4 years ago

When I install coreir from pycoreir it goes into my anaconda directory. Is that ok?

It reports v0.1.40

leonardt commented 4 years ago

yes that's okay, does the issue persist with the pycoreir only setup?

leonardt commented 4 years ago

Also maybe a which -a coreir, my suspicion is there is an old version of coreir lying around somewhere in your PATH or DYLD_LIBRARY_PATH

phanrahan commented 4 years ago
% which -a coreir
/Users/hanrahan/miniconda3/bin/coreir

A little further:

=================================== FAILURES ===================================
____________________________ test_sequential2_reset ____________________________

    def test_sequential2_reset():
>       @m.sequential2(reset_type=m.AsyncReset, has_enable=True)
        class Test2:

tests/test_syntax/test_sequential2.py:372: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
magma/syntax/sequential2.py:327: in seq_inner
    file_name=file_name)(cls.__init__)
../ast_tools/ast_tools/passes/util.py:208: in __call__
    return self.exec(etree, stree, env)
../ast_tools/ast_tools/passes/util.py:218: in exec
    return exec_def_in_file(etree, env, self.path, self.file_name, stree)
../ast_tools/ast_tools/common.py:40: in exec_def_in_file
    return exec_in_file(tree, st, path, file_name, serialized_tree)[tree.name]
../ast_tools/ast_tools/common.py:58: in exec_in_file
    source = astor.to_source(tree)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:52: in to_source
    generator.visit(node)
../../miniconda3/lib/python3.7/site-packages/astor/node_util.py:143: in visit
    return visitor(node)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:320: in visit_FunctionDef
    self.body(node.body)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:218: in body
    self.write(*statements)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:168: in write
    visit(item)
../../miniconda3/lib/python3.7/site-packages/astor/node_util.py:143: in visit
    return visitor(node)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:278: in visit_Assign
    self.visit(node.value)
../../miniconda3/lib/python3.7/site-packages/astor/node_util.py:143: in visit
    return visitor(node)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:514: in visit_Call
    self.visit(node.func)
../../miniconda3/lib/python3.7/site-packages/astor/node_util.py:143: in visit
    return visitor(node)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:524: in visit_Call
    write(write_comma, arg, '=' if arg else '**', keyword.value)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:168: in write
    visit(item)
../../miniconda3/lib/python3.7/site-packages/astor/node_util.py:143: in visit
    return visitor(node)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

node = <_ast.Constant object at 0x7fd9de825ad0>

    def abort_visit(node):  # XXX: self?
        msg = 'No defined handler for node of type %s'
>       raise AttributeError(msg % node.__class__.__name__)
E       AttributeError: No defined handler for node of type Constant

../../miniconda3/lib/python3.7/site-packages/astor/node_util.py:137: AttributeError
__________________________________ test_jtag ___________________________________

    def test_jtag():
        TEST_LOGIC_RESET = m.bits(15, 4)
        RUN_TEST_IDLE = m.bits(12, 4)
        SELECT_DR_SCAN = m.bits(7, 4)
        CAPTURE_DR = m.bits(6, 4)
        SHIFT_DR = m.bits(2, 4)
        EXIT1_DR = m.bits(1, 4)
        PAUSE_DR = m.bits(3, 4)
        EXIT2_DR = m.bits(0, 4)
        UPDATE_DR = m.bits(5, 4)
        SELECT_IR_SCAN = m.bits(4, 4)
        CAPTURE_IR = m.bits(14, 4)
        SHIFT_IR = m.bits(10, 4)
        EXIT1_IR = m.bits(9, 4)
        PAUSE_IR = m.bits(11, 4)
        EXIT2_IR = m.bits(8, 4)
        UPDATE_IR = m.bits(13, 4)

>       @m.coroutine(manual_encoding=True, reset_type=m.AsyncReset)
        class JTAG:

tests/test_syntax/test_coroutine/test_jtag.py:33: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
magma/syntax/coroutine.py:312: in inner
    )(cls)
magma/syntax/sequential2.py:327: in seq_inner
    file_name=file_name)(cls.__init__)
../ast_tools/ast_tools/passes/util.py:208: in __call__
    return self.exec(etree, stree, env)
../ast_tools/ast_tools/passes/util.py:218: in exec
    return exec_def_in_file(etree, env, self.path, self.file_name, stree)
../ast_tools/ast_tools/common.py:40: in exec_def_in_file
    return exec_in_file(tree, st, path, file_name, serialized_tree)[tree.name]
../ast_tools/ast_tools/common.py:58: in exec_in_file
    source = astor.to_source(tree)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:52: in to_source
    generator.visit(node)
../../miniconda3/lib/python3.7/site-packages/astor/node_util.py:143: in visit
    return visitor(node)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:320: in visit_FunctionDef
    self.body(node.body)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:218: in body
    self.write(*statements)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:168: in write
    visit(item)
../../miniconda3/lib/python3.7/site-packages/astor/node_util.py:143: in visit
    return visitor(node)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:278: in visit_Assign
    self.visit(node.value)
../../miniconda3/lib/python3.7/site-packages/astor/node_util.py:143: in visit
    return visitor(node)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:514: in visit_Call
    self.visit(node.func)
../../miniconda3/lib/python3.7/site-packages/astor/node_util.py:143: in visit
    return visitor(node)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:524: in visit_Call
    write(write_comma, arg, '=' if arg else '**', keyword.value)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:168: in write
    visit(item)
../../miniconda3/lib/python3.7/site-packages/astor/node_util.py:143: in visit
    return visitor(node)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

node = <_ast.Constant object at 0x7fd9deb20e90>

    def abort_visit(node):  # XXX: self?
        msg = 'No defined handler for node of type %s'
>       raise AttributeError(msg % node.__class__.__name__)
E       AttributeError: No defined handler for node of type Constant

../../miniconda3/lib/python3.7/site-packages/astor/node_util.py:137: AttributeError
__________________________________ test_sdram __________________________________

    def test_sdram():
        CLK_FREQUENCY = 133   # Mhz
        REFRESH_TIME = 32     # ms     (how often we need to refresh)
        REFRESH_COUNT = 8192  # cycles (how many refreshes required per refresh time)

        # clk / refresh =  clk / sec
        #                , sec / refbatch
        #                , ref / refbatch
        CYCLES_BETWEEN_REFRESH = \
            (CLK_FREQUENCY * 1_000 * REFRESH_TIME) // REFRESH_COUNT

        # IDLE = "5'b00000"
        IDLE = m.bits(0, 5)

        # INIT_NOP1 = "5'b01000"
        # INIT_PRE1 = "5'b01001"
        # INIT_NOP1_1 = "5'b00101"
        # INIT_REF1 = "5'b01010"
        # INIT_NOP2 = "5'b01011"
        # INIT_REF2 = "5'b01100"
        # INIT_NOP3 = "5'b01101"
        # INIT_LOAD = "5'b01110"
        # INIT_NOP4 = "5'b01111"

        # REF_PRE = "5'b00001"
        # REF_NOP1 = "5'b00010"
        # REF_REF = "5'b00011"
        # REF_NOP2 = "5'b00100"

        # READ_ACT = "5'b10000"
        # READ_NOP1 = "5'b10001"
        # READ_CAS = "5'b10010"
        # READ_NOP2 = "5'b10011"
        # READ_READ = "5'b10100"

        # WRIT_ACT = "5'b11000"
        # WRIT_NOP1 = "5'b11001"
        # WRIT_CAS = "5'b11010"
        # WRIT_NOP2 = "5'b11011"

        INIT_NOP1 = m.bits(0b01000, 5)
        INIT_PRE1 = m.bits(0b01001, 5)
        INIT_NOP1_1 = m.bits(0b00101, 5)
        INIT_REF1 = m.bits(0b01010, 5)
        INIT_NOP2 = m.bits(0b01011, 5)
        INIT_REF2 = m.bits(0b01100, 5)
        INIT_NOP3 = m.bits(0b01101, 5)
        INIT_LOAD = m.bits(0b01110, 5)
        INIT_NOP4 = m.bits(0b01111, 5)

        REF_PRE = m.bits(0b00001, 5)
        REF_NOP1 = m.bits(0b00010, 5)
        REF_REF = m.bits(0b00011, 5)
        REF_NOP2 = m.bits(0b00100, 5)

        READ_ACT = m.bits(0b10000, 5)
        READ_NOP1 = m.bits(0b10001, 5)
        READ_CAS = m.bits(0b10010, 5)
        READ_NOP2 = m.bits(0b10011, 5)
        READ_READ = m.bits(0b10100, 5)

        WRIT_ACT = m.bits(0b11000, 5)
        WRIT_NOP1 = m.bits(0b11001, 5)
        WRIT_CAS = m.bits(0b11010, 5)
        WRIT_NOP2 = m.bits(0b11011, 5)

        # CMD_PALL = "8'b10010001"
        # CMD_REF = "8'b10001000"
        # CMD_NOP = "8'b10111000"
        # CMD_MRS = "8'b1000000x"
        # CMD_BACT = "8'b10011xxx"
        # CMD_READ = "8'b10101xx1"
        # CMD_WRIT = "8'b10100xx1"

        CMD_PALL = m.bits(0b10010001, 8)
        CMD_REF = m.bits(0b10001000, 8)
        CMD_NOP = m.bits(0b10111000, 8)
        CMD_MRS = m.bits(0b10000000, 8)
        CMD_BACT = m.bits(0b10011000, 8)
        CMD_READ = m.bits(0b10101001, 8)
        CMD_WRIT = m.bits(0b10100001, 8)

>       @m.coroutine(manual_encoding=True, reset_type=m.AsyncResetN)
        class SDRAMController:

tests/test_syntax/test_coroutine/test_sdram.py:97: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
magma/syntax/coroutine.py:312: in inner
    )(cls)
magma/syntax/sequential2.py:327: in seq_inner
    file_name=file_name)(cls.__init__)
../ast_tools/ast_tools/passes/util.py:208: in __call__
    return self.exec(etree, stree, env)
../ast_tools/ast_tools/passes/util.py:218: in exec
    return exec_def_in_file(etree, env, self.path, self.file_name, stree)
../ast_tools/ast_tools/common.py:40: in exec_def_in_file
    return exec_in_file(tree, st, path, file_name, serialized_tree)[tree.name]
../ast_tools/ast_tools/common.py:58: in exec_in_file
    source = astor.to_source(tree)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:52: in to_source
    generator.visit(node)
../../miniconda3/lib/python3.7/site-packages/astor/node_util.py:143: in visit
    return visitor(node)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:320: in visit_FunctionDef
    self.body(node.body)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:218: in body
    self.write(*statements)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:168: in write
    visit(item)
../../miniconda3/lib/python3.7/site-packages/astor/node_util.py:143: in visit
    return visitor(node)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:278: in visit_Assign
    self.visit(node.value)
../../miniconda3/lib/python3.7/site-packages/astor/node_util.py:143: in visit
    return visitor(node)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:514: in visit_Call
    self.visit(node.func)
../../miniconda3/lib/python3.7/site-packages/astor/node_util.py:143: in visit
    return visitor(node)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:524: in visit_Call
    write(write_comma, arg, '=' if arg else '**', keyword.value)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:168: in write
    visit(item)
../../miniconda3/lib/python3.7/site-packages/astor/node_util.py:143: in visit
    return visitor(node)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

node = <_ast.Constant object at 0x7fd9dee80590>

    def abort_visit(node):  # XXX: self?
        msg = 'No defined handler for node of type %s'
>       raise AttributeError(msg % node.__class__.__name__)
E       AttributeError: No defined handler for node of type Constant

../../miniconda3/lib/python3.7/site-packages/astor/node_util.py:137: AttributeError
__________________________________ test_uart ___________________________________

    def test_uart():
>       @m.coroutine(reset_type=m.AsyncReset)
        class UART:

tests/test_syntax/test_coroutine/test_uart.py:16: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
magma/syntax/coroutine.py:312: in inner
    )(cls)
magma/syntax/sequential2.py:327: in seq_inner
    file_name=file_name)(cls.__init__)
../ast_tools/ast_tools/passes/util.py:208: in __call__
    return self.exec(etree, stree, env)
../ast_tools/ast_tools/passes/util.py:218: in exec
    return exec_def_in_file(etree, env, self.path, self.file_name, stree)
../ast_tools/ast_tools/common.py:40: in exec_def_in_file
    return exec_in_file(tree, st, path, file_name, serialized_tree)[tree.name]
../ast_tools/ast_tools/common.py:58: in exec_in_file
    source = astor.to_source(tree)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:52: in to_source
    generator.visit(node)
../../miniconda3/lib/python3.7/site-packages/astor/node_util.py:143: in visit
    return visitor(node)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:320: in visit_FunctionDef
    self.body(node.body)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:218: in body
    self.write(*statements)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:168: in write
    visit(item)
../../miniconda3/lib/python3.7/site-packages/astor/node_util.py:143: in visit
    return visitor(node)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:278: in visit_Assign
    self.visit(node.value)
../../miniconda3/lib/python3.7/site-packages/astor/node_util.py:143: in visit
    return visitor(node)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:514: in visit_Call
    self.visit(node.func)
../../miniconda3/lib/python3.7/site-packages/astor/node_util.py:143: in visit
    return visitor(node)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:524: in visit_Call
    write(write_comma, arg, '=' if arg else '**', keyword.value)
../../miniconda3/lib/python3.7/site-packages/astor/code_gen.py:168: in write
    visit(item)
../../miniconda3/lib/python3.7/site-packages/astor/node_util.py:143: in visit
    return visitor(node)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

node = <_ast.Constant object at 0x7fd9dede0e50>

    def abort_visit(node):  # XXX: self?
        msg = 'No defined handler for node of type %s'
>       raise AttributeError(msg % node.__class__.__name__)
E       AttributeError: No defined handler for node of type Constant

../../miniconda3/lib/python3.7/site-packages/astor/node_util.py:137: AttributeError
=========================== short test summary info ============================
FAILED tests/test_syntax/test_sequential2.py::test_sequential2_reset - Attrib...
FAILED tests/test_syntax/test_coroutine/test_jtag.py::test_jtag - AttributeEr...
FAILED tests/test_syntax/test_coroutine/test_sdram.py::test_sdram - Attribute...
FAILED tests/test_syntax/test_coroutine/test_uart.py::test_uart - AttributeEr...
============= 4 failed, 611 passed, 6 skipped in 371.16s (0:06:11) =============
% 
leonardt commented 4 years ago

Can you try pip install --upgrade astor? It looks like support for Constant was added in a recent version (see https://github.com/berkerpeksag/astor/commit/641390339bea88f13bcdd0abaa576e078191a86c)

phanrahan commented 4 years ago

Yeah. That did it. The tests pass now.