user_base.c 3.2 KB

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