feed.c 2.6 KB

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