pymtl3 icon indicating copy to clipboard operation
pymtl3 copied to clipboard

Handle U-M1-M2 constraint chain when M is a top level method

Open jsn1993 opened this issue 6 years ago • 0 comments

from pymtl3 import *
from pymtl3.passes.GenDAGPass import GenDAGPass
from pymtl3.passes.OpenLoopCLPass import OpenLoopCLPass

class QueueCL( Component ):
  def construct( s, maxsize ):
    s.q = deque( maxlen=maxsize )
    s.add_constraints( M(s.deq) < M(s.enq) )

  @non_blocking( lambda s: len(s.q) < s.q.maxlen )
  def enq( s, value ):
    s.q.appendleft( value )

  @non_blocking( lambda s: len(s.q) > 0 )
  def deq( s ):
    return s.q.pop()

  def line_trace( s ):
    return str(s.enq) + "()" + str(s.deq)

class TwoQueueCL( Component ):
  def construct( s ):
    s.enq = NonBlockingCalleeIfc()
    s.deq = NonBlockingCalleeIfc()

    s.q1 = QueueCL(2)
    s.q2 = QueueCL(2)

    s.connect( s.enq,    s.q1.enq )
    s.connect( s.q2.deq, s.deq    )

    @s.update
    def upA():
      if s.q1.deq.rdy() and s.q2.enq.rdy():
        s.q2.enq( s.q1.deq() )

  def line_trace( s ):
    return str(s.enq) + "()" + str(s.deq)

A = TwoQueueCL()
A.elaborate()
A.apply( GenDAGPass() )
A.apply( OpenLoopCLPass() )
A.lock_in_simulation()

if A.enq.rdy():
  A.enq(3)
if A.enq.rdy():
  A.enq(4)
if A.enq.rdy():
  A.enq(5)

if A.deq.rdy():
  print A.deq()
if A.deq.rdy():
  print A.deq()
if A.deq.rdy():
  print A.deq()

In this example, upA calls s.q1.deq and I currently fail to handle this dependency of top level s.enq < s.q1.deq = upA.

jsn1993 avatar Jun 18 '19 03:06 jsn1993