footprint.c 3.4 KB

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