user_base.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  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 <starpu_scheduler.h>
  18. #include <unistd.h>
  19. #include "../helper.h"
  20. /*
  21. * Test using a user-provided base for the perfmodel
  22. */
  23. void func(void *descr[], void *arg)
  24. {
  25. (void)descr;
  26. (void)arg;
  27. usleep(1000);
  28. }
  29. size_t get_size_base(struct starpu_task *task, unsigned nimpl)
  30. {
  31. (void)task;
  32. (void)nimpl;
  33. return 3;
  34. };
  35. uint32_t get_footprint(struct starpu_task *task)
  36. {
  37. uint32_t orig = starpu_task_data_footprint(task);
  38. return starpu_hash_crc32c_be(42, orig);
  39. };
  40. static struct starpu_perfmodel rb_model =
  41. {
  42. .type = STARPU_REGRESSION_BASED,
  43. .symbol = "user_base_valid_model_regression_based",
  44. .size_base = get_size_base,
  45. };
  46. static struct starpu_perfmodel nlrb_model =
  47. {
  48. .type = STARPU_NL_REGRESSION_BASED,
  49. .symbol = "user_base_valid_model_non_linear_regression_based",
  50. .size_base = get_size_base,
  51. };
  52. static struct starpu_perfmodel hb_model =
  53. {
  54. .type = STARPU_HISTORY_BASED,
  55. .symbol = "user_base_valid_model_history_based",
  56. .size_base = get_size_base,
  57. };
  58. static struct starpu_perfmodel hb_model_foot =
  59. {
  60. .type = STARPU_HISTORY_BASED,
  61. .symbol = "user_base_valid_model_history_based_footprint",
  62. .footprint = get_footprint,
  63. };
  64. static struct starpu_codelet mycodelet =
  65. {
  66. .cuda_funcs = {func},
  67. .opencl_funcs = {func},
  68. .cpu_funcs = {func},
  69. .cpu_funcs_name = {"func"},
  70. .nbuffers = 1,
  71. .modes = {STARPU_W}
  72. };
  73. static int submit(struct starpu_codelet *codelet, struct starpu_perfmodel *model)
  74. {
  75. int nloops = 123;
  76. int loop;
  77. starpu_data_handle_t handle;
  78. int ret;
  79. struct starpu_conf conf;
  80. starpu_conf_init(&conf);
  81. conf.sched_policy_name = "eager";
  82. conf.calibrate = 1;
  83. ret = starpu_init(&conf);
  84. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  85. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  86. codelet->model = model;
  87. starpu_vector_data_register(&handle, -1, (uintptr_t)NULL, 100, sizeof(int));
  88. for (loop = 0; loop < nloops; loop++)
  89. {
  90. ret = starpu_task_insert(codelet, STARPU_W, handle, 0);
  91. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  92. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  93. }
  94. starpu_data_unregister(handle);
  95. starpu_shutdown();
  96. return EXIT_SUCCESS;
  97. }
  98. int main(void)
  99. {
  100. int ret;
  101. /* Use a linear regression model */
  102. ret = submit(&mycodelet, &rb_model);
  103. if (ret) return ret;
  104. /* Use a non-linear regression model */
  105. ret = submit(&mycodelet, &nlrb_model);
  106. if (ret) return ret;
  107. /* Use a history model */
  108. ret = submit(&mycodelet, &hb_model);
  109. if (ret) return ret;
  110. /* Use a history model with footprints*/
  111. ret = submit(&mycodelet, &hb_model_foot);
  112. if (ret) return ret;
  113. return EXIT_SUCCESS;
  114. }