graph.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. from cmsisdsp.cg.scheduler import *
  2. ### Define new types of Nodes
  3. class Node(GenericNode):
  4. def __init__(self,name,theType,inLength,outLength):
  5. GenericNode.__init__(self,name)
  6. self.addInput("ia",theType,inLength)
  7. self.addInput("ib",theType,inLength)
  8. self.addOutput("o",theType,outLength)
  9. class Sink(GenericSink):
  10. def __init__(self,name,theType,inLength):
  11. GenericSink.__init__(self,name)
  12. self.addInput("i",theType,inLength)
  13. @property
  14. def typeName(self):
  15. return "Sink"
  16. class Source(GenericSource):
  17. def __init__(self,name,theType,inLength):
  18. GenericSource.__init__(self,name)
  19. self.addOutput("o",theType,inLength)
  20. @property
  21. def typeName(self):
  22. return "Source"
  23. class ProcessingNode(Node):
  24. @property
  25. def typeName(self):
  26. return "ProcessingNode"
  27. ### Define nodes
  28. floatType=CType(F32)
  29. src=Source("source",floatType,5)
  30. b=ProcessingNode("filter",floatType,5,5)
  31. sink=Sink("sink",floatType,5)
  32. g = Graph()
  33. g.connect(src.o,b.ia)
  34. g.connect(b.o,sink.i)
  35. # With less than 5, the tool cannot find a possible schedule
  36. # and is generating a DeadLock error
  37. g.connectWithDelay(b.o,b.ib,5)
  38. print("Generate graphviz and code")
  39. conf=Configuration()
  40. conf.debugLimit=2
  41. conf.cOptionalArgs="int someVariable"
  42. #conf.displayFIFOSizes=True
  43. # Prefix for global FIFO buffers
  44. #conf.prefix="sched1"
  45. #conf.dumpSchedule = True
  46. sched = g.computeSchedule(config=conf)
  47. #print(sched.schedule)
  48. print("Schedule length = %d" % sched.scheduleLength)
  49. print("Memory usage %d bytes" % sched.memory)
  50. #
  51. #conf.codeArray=True
  52. sched.ccode("generated",conf)
  53. with open("test.dot","w") as f:
  54. sched.graphviz(f)