feed.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2012 Inria
  4. * Copyright (C) 2011-2012,2014,2016 Université de Bordeaux
  5. * Copyright (C) 2011-2014,2017 CNRS
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <starpu.h>
  19. #include "../helper.h"
  20. /*
  21. * Test the starpu_perfmodel_update_history function
  22. */
  23. static struct starpu_perfmodel model =
  24. {
  25. .type = STARPU_REGRESSION_BASED,
  26. .symbol = "feed"
  27. };
  28. static struct starpu_perfmodel nl_model =
  29. {
  30. .type = STARPU_NL_REGRESSION_BASED,
  31. .symbol = "nlfeed"
  32. };
  33. static struct starpu_codelet cl =
  34. {
  35. .model = &model,
  36. .nbuffers = 1,
  37. .modes = {STARPU_W}
  38. };
  39. int main(void)
  40. {
  41. struct starpu_task task;
  42. int ret;
  43. ret = starpu_init(NULL);
  44. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  45. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  46. if (starpu_worker_get_count_by_type(STARPU_CUDA_WORKER) < 2)
  47. {
  48. starpu_shutdown();
  49. return STARPU_TEST_SKIPPED;
  50. }
  51. starpu_task_init(&task);
  52. task.cl = &cl;
  53. int size;
  54. for (size = 1024; size < 16777216; size *= 2)
  55. {
  56. float measured_fast, measured_slow;
  57. starpu_data_handle_t handle;
  58. starpu_vector_data_register(&handle, -1, 0, size, sizeof(float));
  59. task.handles[0] = handle;
  60. /* Simulate Fast GPU. In real applications this would be
  61. * replaced by fetching from actual measurement */
  62. measured_fast = 0.002+size*0.00000001;
  63. measured_slow = 0.001+size*0.0000001;
  64. struct starpu_perfmodel_arch arch;
  65. arch.ndevices = 1;
  66. arch.devices = (struct starpu_perfmodel_device*)malloc(sizeof(struct starpu_perfmodel_device));
  67. arch.devices[0].type = STARPU_CUDA_WORKER;
  68. arch.devices[0].ncores = 0;
  69. /* Simulate Fast GPU */
  70. arch.devices[0].devid = 0;
  71. starpu_perfmodel_update_history(&model, &task, &arch, 0, 0, measured_fast);
  72. starpu_perfmodel_update_history(&nl_model, &task, &arch, 0, 0, measured_fast);
  73. /* Simulate Slow GPU */
  74. arch.devices[0].devid = 1;
  75. starpu_perfmodel_update_history(&model, &task, &arch, 0, 0, measured_slow);
  76. starpu_perfmodel_update_history(&nl_model, &task, &arch, 0, 0, measured_slow);
  77. starpu_task_clean(&task);
  78. starpu_data_unregister(handle);
  79. }
  80. starpu_shutdown();
  81. return EXIT_SUCCESS;
  82. }