footprint.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010-2011, 2013-2014 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013, 2014 CNRS
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <datawizard/footprint.h>
  18. #include <starpu_hash.h>
  19. #include <core/task.h>
  20. #include <starpu_scheduler.h>
  21. uint32_t starpu_task_data_footprint(struct starpu_task *task)
  22. {
  23. uint32_t footprint = 0;
  24. unsigned buffer;
  25. unsigned nbuffers = STARPU_TASK_GET_NBUFFERS(task);
  26. for (buffer = 0; buffer < nbuffers; buffer++)
  27. {
  28. starpu_data_handle_t handle = STARPU_TASK_GET_HANDLE(task, buffer);
  29. uint32_t handle_footprint = _starpu_data_get_footprint(handle);
  30. footprint = starpu_hash_crc32c_be(handle_footprint, footprint);
  31. }
  32. return footprint;
  33. }
  34. uint32_t _starpu_compute_buffers_footprint(struct starpu_perfmodel *model, struct starpu_perfmodel_arch* arch, unsigned nimpl, struct _starpu_job *j)
  35. {
  36. if (j->footprint_is_computed)
  37. return j->footprint;
  38. uint32_t footprint = 0;
  39. struct starpu_task *task = j->task;
  40. if (model)
  41. {
  42. if (model->footprint)
  43. {
  44. footprint = model->footprint(task);
  45. }
  46. else
  47. {
  48. struct starpu_perfmodel_per_arch *per_arch;
  49. if (arch)
  50. per_arch = starpu_perfmodel_get_model_per_arch(model, arch, nimpl);
  51. if (arch && per_arch != NULL && per_arch->size_base)
  52. {
  53. size_t size = per_arch->size_base(task, arch, nimpl);
  54. footprint = starpu_hash_crc32c_be_n(&size, sizeof(size), footprint);
  55. }
  56. else if (model->size_base)
  57. {
  58. size_t size = model->size_base(task, nimpl);
  59. footprint = starpu_hash_crc32c_be_n(&size, sizeof(size), footprint);
  60. }
  61. else
  62. {
  63. footprint = starpu_task_data_footprint(task);
  64. }
  65. }
  66. }
  67. else
  68. {
  69. footprint = starpu_task_data_footprint(task);
  70. }
  71. j->footprint = footprint;
  72. j->footprint_is_computed = 1;
  73. return footprint;
  74. }
  75. uint32_t _starpu_compute_data_footprint(starpu_data_handle_t handle)
  76. {
  77. uint32_t interfaceid = (uint32_t)starpu_data_get_interface_id(handle);
  78. STARPU_ASSERT(handle->ops->footprint);
  79. uint32_t handle_footprint = handle->ops->footprint(handle);
  80. return starpu_hash_crc32c_be(handle_footprint, interfaceid);
  81. }
  82. uint32_t starpu_task_footprint(struct starpu_perfmodel *model, struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  83. {
  84. struct _starpu_job *j = _starpu_get_job_associated_to_task(task);
  85. return _starpu_compute_buffers_footprint(model, arch, nimpl, j);
  86. }