graph.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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)
  31. b.addVariableArg("testString","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=["const char *testString"
  40. ,"int someVariable"
  41. ]
  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.postCustomCName = "post.h"
  52. #conf.CAPI = True
  53. #conf.prefix="global"
  54. #conf.dumpFIFO = True
  55. #conf.CMSISDSP = False
  56. #conf.switchCase = False
  57. sched.ccode("generated",conf)
  58. with open("test.dot","w") as f:
  59. sched.graphviz(f)