intermedia.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # StarPU --- Runtime system for heterogeneous multicore architectures.
  2. #
  3. # Copyright (C) 2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. #
  5. # StarPU is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU Lesser General Public License as published by
  7. # the Free Software Foundation; either version 2.1 of the License, or (at
  8. # your option) any later version.
  9. #
  10. # StarPU is distributed in the hope that it will be useful, but
  11. # WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. #
  14. # See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. #
  16. from starpu import starpupy
  17. import os
  18. #class perfmodel
  19. class Perfmodel(object):
  20. def __init__(self, symbol):
  21. self.symbol=symbol
  22. self.pstruct=starpupy.init_perfmodel(self.symbol)
  23. def get_struct(self):
  24. return self.pstruct
  25. def __del__(self):
  26. #def free_struct(self):
  27. starpupy.free_perfmodel(self.pstruct)
  28. # generate the dictionary which contains the perfmodel symbol and its struct pointer
  29. dict_perf={}
  30. def dict_perf_generator(perfsymbol):
  31. if dict_perf.get(perfsymbol)==None:
  32. p=Perfmodel(perfsymbol)
  33. dict_perf[perfsymbol]=p
  34. else:
  35. p=dict_perf[perfsymbol]
  36. return p
  37. #add options in function task_submit
  38. def task_submit(*, name=None, synchronous=0, priority=0, color=None, flops=None, perfmodel=None):
  39. if perfmodel==None:
  40. dict_option={'name': name, 'synchronous': synchronous, 'priority': priority, 'color': color, 'flops': flops, 'perfmodel': None}
  41. else:
  42. p=dict_perf_generator(perfmodel)
  43. dict_option={'name': name, 'synchronous': synchronous, 'priority': priority, 'color': color, 'flops': flops, 'perfmodel': p.get_struct()}
  44. def call_task_submit(f, *args):
  45. fut=starpupy._task_submit(f, *args, dict_option)
  46. return fut
  47. return call_task_submit
  48. # dump performance model and show the plot
  49. def perfmodel_plot(perfmodel, view=True):
  50. p=dict_perf[perfmodel]
  51. starpupy.save_history_based_model(p.get_struct())
  52. if view == True:
  53. os.system('starpu_perfmodel_plot -s "' + perfmodel +'"')
  54. os.system('gnuplot starpu_'+perfmodel+'.gp')
  55. os.system('gv starpu_'+perfmodel+'.eps')