user_base.c 3.2 KB

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