graph.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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("i",theType,inLength)
  7. self.addOutput("o",theType,outLength)
  8. class Sink(GenericSink):
  9. def __init__(self,name,theType,inLength):
  10. GenericSink.__init__(self,name)
  11. self.addInput("i",theType,inLength)
  12. @property
  13. def typeName(self):
  14. return "Sink"
  15. class Source(GenericSource):
  16. def __init__(self,name,theType,inLength):
  17. GenericSource.__init__(self,name)
  18. self.addOutput("o",theType,inLength)
  19. @property
  20. def typeName(self):
  21. return "Source"
  22. class ProcessingNode(Node):
  23. @property
  24. def typeName(self):
  25. return "ProcessingNode"
  26. ### Define nodes
  27. floatType=CType(F32)
  28. src=Source("source",floatType,5)
  29. b=ProcessingNode("filter",floatType,7,5)
  30. b.addLiteralArg(4,"Test")
  31. b.addVariableArg("someVariable")
  32. sink=Sink("sink",floatType,5)
  33. g = Graph()
  34. g.connect(src.o,b.i)
  35. g.connect(b.o,sink.i)
  36. print("Generate graphviz and code")
  37. conf=Configuration()
  38. conf.debugLimit=1
  39. conf.cOptionalArgs="int someVariable"
  40. #conf.displayFIFOSizes=True
  41. # Prefix for global FIFO buffers
  42. #conf.prefix="sched1"
  43. #conf.dumpSchedule = True
  44. sched = g.computeSchedule(config=conf)
  45. #print(sched.schedule)
  46. print("Schedule length = %d" % sched.scheduleLength)
  47. print("Memory usage %d bytes" % sched.memory)
  48. #
  49. #conf.postCustomCName = "post.h"
  50. #conf.CAPI = True
  51. #conf.prefix="global"
  52. #conf.dumpFIFO = True
  53. #conf.CMSISDSP = False
  54. #conf.switchCase = False
  55. sched.ccode("generated",conf)
  56. with open("test.dot","w") as f:
  57. sched.graphviz(f)