user_base.c 3.2 KB

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