feed.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012, 2016 Université de Bordeaux
  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. #include <starpu.h>
  17. #include "../helper.h"
  18. /*
  19. * Test the starpu_perfmodel_update_history function
  20. */
  21. static struct starpu_perfmodel model =
  22. {
  23. .type = STARPU_REGRESSION_BASED,
  24. .symbol = "feed"
  25. };
  26. static struct starpu_perfmodel nl_model =
  27. {
  28. .type = STARPU_NL_REGRESSION_BASED,
  29. .symbol = "nlfeed"
  30. };
  31. static struct starpu_codelet cl =
  32. {
  33. .model = &model,
  34. .nbuffers = 1,
  35. .modes = {STARPU_W}
  36. };
  37. int main(void)
  38. {
  39. struct starpu_task task;
  40. int ret;
  41. ret = starpu_init(NULL);
  42. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  43. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  44. if (starpu_worker_get_count_by_type(STARPU_CUDA_WORKER) < 2)
  45. {
  46. starpu_shutdown();
  47. return STARPU_TEST_SKIPPED;
  48. }
  49. starpu_task_init(&task);
  50. task.cl = &cl;
  51. int size;
  52. for (size = 1024; size < 16777216; size *= 2)
  53. {
  54. float measured_fast, measured_slow;
  55. starpu_data_handle_t handle;
  56. starpu_vector_data_register(&handle, -1, 0, size, sizeof(float));
  57. task.handles[0] = handle;
  58. /* Simulate Fast GPU. In real applications this would be
  59. * replaced by fetching from actual measurement */
  60. measured_fast = 0.002+size*0.00000001;
  61. measured_slow = 0.001+size*0.0000001;
  62. struct starpu_perfmodel_arch arch;
  63. arch.ndevices = 1;
  64. arch.devices = (struct starpu_perfmodel_device*)malloc(sizeof(struct starpu_perfmodel_device));
  65. arch.devices[0].type = STARPU_CUDA_WORKER;
  66. arch.devices[0].ncores = 0;
  67. /* Simulate Fast GPU */
  68. arch.devices[0].devid = 0;
  69. starpu_perfmodel_update_history(&model, &task, &arch, 0, 0, measured_fast);
  70. starpu_perfmodel_update_history(&nl_model, &task, &arch, 0, 0, measured_fast);
  71. /* Simulate Slow GPU */
  72. arch.devices[0].devid = 1;
  73. starpu_perfmodel_update_history(&model, &task, &arch, 0, 0, measured_slow);
  74. starpu_perfmodel_update_history(&nl_model, &task, &arch, 0, 0, measured_slow);
  75. starpu_task_clean(&task);
  76. starpu_data_unregister(handle);
  77. }
  78. starpu_shutdown();
  79. return EXIT_SUCCESS;
  80. }