user_base.c 3.2 KB

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