graph.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. processing=ProcessingNode("processing",floatType,7,5)
  30. processing.addLiteralArg(4,"testString")
  31. processing.addVariableArg("someVariable")
  32. sink=Sink("sink",floatType,5)
  33. g = Graph()
  34. g.connect(src.o,processing.i)
  35. g.connect(processing.o,sink.i)
  36. print("Generate graphviz and code")
  37. conf=Configuration()
  38. conf.debugLimit=1
  39. conf.cOptionalArgs=["int someVariable"
  40. ]
  41. sched = g.computeSchedule(config=conf)
  42. print("Schedule length = %d" % sched.scheduleLength)
  43. print("Memory usage %d bytes" % sched.memory)
  44. sched.ccode("generated",conf)
  45. with open("test.dot","w") as f:
  46. sched.graphviz(f)