footprint.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010-2011, 2013 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012, 2013 Centre National de la Recherche Scientifique
  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_compute_buffers_footprint(struct starpu_perfmodel *model, struct starpu_perfmodel_arch * arch, unsigned nimpl, struct _starpu_job *j)
  22. {
  23. if (j->footprint_is_computed)
  24. return j->footprint;
  25. uint32_t footprint = 0;
  26. unsigned buffer;
  27. struct starpu_task *task = j->task;
  28. if (model != NULL &&
  29. model->per_arch[arch->type] != NULL &&
  30. model->per_arch[arch->type][arch->devid] != NULL &&
  31. model->per_arch[arch->type][arch->devid][arch->ncore] != NULL &&
  32. model->per_arch[arch->type][arch->devid][arch->ncore][nimpl].size_base)
  33. {
  34. size_t size = model->per_arch[arch->type][arch->devid][arch->ncore][nimpl].size_base(task, arch, nimpl);
  35. footprint = starpu_hash_crc32c_be_n(&size, sizeof(size), footprint);
  36. }
  37. else if (model && model->size_base)
  38. {
  39. size_t size = model->size_base(task, nimpl);
  40. footprint = starpu_hash_crc32c_be_n(&size, sizeof(size), footprint);
  41. }
  42. else
  43. {
  44. for (buffer = 0; buffer < task->cl->nbuffers; buffer++)
  45. {
  46. starpu_data_handle_t handle = STARPU_TASK_GET_HANDLE(task, buffer);
  47. uint32_t handle_footprint = _starpu_data_get_footprint(handle);
  48. footprint = starpu_hash_crc32c_be(handle_footprint, footprint);
  49. }
  50. }
  51. j->footprint = footprint;
  52. j->footprint_is_computed = 1;
  53. return footprint;
  54. }
  55. uint32_t _starpu_compute_data_footprint(starpu_data_handle_t handle)
  56. {
  57. uint32_t interfaceid = (uint32_t)starpu_data_get_interface_id(handle);
  58. STARPU_ASSERT(handle->ops->footprint);
  59. uint32_t handle_footprint = handle->ops->footprint(handle);
  60. return starpu_hash_crc32c_be(handle_footprint, interfaceid);
  61. }
  62. uint32_t starpu_task_footprint(struct starpu_perfmodel *model, struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  63. {
  64. struct _starpu_job *j = _starpu_get_job_associated_to_task(task);
  65. return _starpu_compute_buffers_footprint(model, arch, nimpl, j);
  66. }