user_base.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2014-2015 Université Bordeaux
  4. * Copyright (C) 2012, 2013, 2014 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. 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},
  60. .opencl_funcs = {func},
  61. .cpu_funcs = {func},
  62. .cpu_funcs_name = {"func"},
  63. .nbuffers = 1,
  64. .modes = {STARPU_W}
  65. };
  66. static int submit(struct starpu_codelet *codelet, struct starpu_perfmodel *model)
  67. {
  68. int nloops = 123;
  69. int loop;
  70. starpu_data_handle_t handle;
  71. struct starpu_perfmodel lmodel;
  72. int ret;
  73. int old_nsamples, new_nsamples;
  74. struct starpu_conf conf;
  75. unsigned archid, archtype, devid, ncore;
  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. }