graph.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. from cmsisdsp.sdf.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.addLiteralArg("Test")
  32. b.addVariableArg("someVariable")
  33. sink=Sink("sink",floatType,5)
  34. g = Graph()
  35. g.connect(src.o,b.i)
  36. g.connect(b.o,sink.i)
  37. print("Generate graphviz and code")
  38. conf=Configuration()
  39. conf.debugLimit=1
  40. conf.cOptionalArgs="int someVariable"
  41. #conf.displayFIFOSizes=True
  42. # Prefix for global FIFO buffers
  43. #conf.prefix="sched1"
  44. #print(g.nullVector())
  45. sched = g.computeSchedule()
  46. #print(sched.schedule)
  47. print("Schedule length = %d" % sched.scheduleLength)
  48. print("Memory usage %d bytes" % sched.memory)
  49. #
  50. #conf.codeArray=True
  51. sched.ccode("generated",conf)
  52. with open("test.dot","w") as f:
  53. sched.graphviz(f)