feed.c 2.8 KB

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