valid_model.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012, 2013 Centre National de la Recherche Scientifique
  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 <config.h>
  17. #include <starpu.h>
  18. #include "../helper.h"
  19. void func(void *descr[], void *arg)
  20. {
  21. }
  22. static struct starpu_perfmodel rb_model =
  23. {
  24. .type = STARPU_REGRESSION_BASED,
  25. .symbol = "valid_model_regression_based"
  26. };
  27. static struct starpu_perfmodel nlrb_model =
  28. {
  29. .type = STARPU_NL_REGRESSION_BASED,
  30. .symbol = "valid_model_non_linear_regression_based"
  31. };
  32. #if 0
  33. static struct starpu_perfmodel hb_model =
  34. {
  35. .type = STARPU_HISTORY_BASED,
  36. .symbol = "valid_model_history_based"
  37. };
  38. #endif
  39. static struct starpu_codelet mycodelet =
  40. {
  41. .cuda_funcs = {func, NULL},
  42. .opencl_funcs = {func, NULL},
  43. .cpu_funcs = {func, NULL},
  44. .nbuffers = 1,
  45. .modes = {STARPU_W}
  46. };
  47. static int submit(struct starpu_codelet *codelet, struct starpu_perfmodel *model)
  48. {
  49. int nloops = 123;
  50. int loop;
  51. starpu_data_handle_t handle;
  52. struct starpu_perfmodel lmodel;
  53. int ret;
  54. int old_nsamples, new_nsamples;
  55. struct starpu_conf conf;
  56. unsigned archid, archtype, devid, ncore;
  57. starpu_conf_init(&conf);
  58. conf.sched_policy_name = "eager";
  59. conf.calibrate = 1;
  60. ret = starpu_init(&conf);
  61. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  62. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  63. codelet->model = model;
  64. old_nsamples = 0;
  65. lmodel.is_init=0;
  66. lmodel.type = model->type;
  67. ret = starpu_perfmodel_load_symbol(codelet->model->symbol, &lmodel);
  68. int narch_combs = starpu_get_narch_combs();
  69. int comb;
  70. if (ret != 1)
  71. for(comb = 0; comb < narch_combs; comb++)
  72. old_nsamples += lmodel.per_arch[comb][0].regression.nsample;
  73. starpu_vector_data_register(&handle, -1, (uintptr_t)NULL, 100, sizeof(int));
  74. for (loop = 0; loop < nloops; loop++)
  75. {
  76. ret = starpu_task_insert(codelet, STARPU_W, handle, 0);
  77. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  78. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  79. }
  80. starpu_data_unregister(handle);
  81. starpu_perfmodel_unload_model(&lmodel);
  82. starpu_shutdown(); // To force dumping perf models on disk
  83. // We need to call starpu_init again to initialise values used by perfmodels
  84. ret = starpu_init(NULL);
  85. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  86. ret = starpu_perfmodel_load_symbol(codelet->model->symbol, &lmodel);
  87. if (ret == 1)
  88. {
  89. FPRINTF(stderr, "The performance model for the symbol <%s> could not be loaded\n", codelet->model->symbol);
  90. starpu_shutdown();
  91. return 1;
  92. }
  93. new_nsamples = 0;
  94. for(comb = 0; comb < narch_combs; comb++)
  95. new_nsamples += lmodel.per_arch[comb][0].regression.nsample;
  96. ret = starpu_perfmodel_unload_model(&lmodel);
  97. starpu_shutdown();
  98. if (ret == 1)
  99. {
  100. FPRINTF(stderr, "The performance model for the symbol <%s> could not be UNloaded\n", codelet->model->symbol);
  101. return 1;
  102. }
  103. if (old_nsamples + nloops == new_nsamples)
  104. {
  105. FPRINTF(stderr, "Sampling for <%s> OK %d + %d == %d\n", codelet->model->symbol, old_nsamples, nloops, new_nsamples);
  106. return EXIT_SUCCESS;
  107. }
  108. else
  109. {
  110. FPRINTF(stderr, "Sampling for <%s> failed %d + %d != %d\n", codelet->model->symbol, old_nsamples, nloops, new_nsamples);
  111. return EXIT_FAILURE;
  112. }
  113. }
  114. int main(int argc, char **argv)
  115. {
  116. int ret;
  117. /* Use a linear regression model */
  118. ret = submit(&mycodelet, &rb_model);
  119. if (ret) return ret;
  120. /* Use a non-linear regression model */
  121. ret = submit(&mycodelet, &nlrb_model);
  122. if (ret) return ret;
  123. #ifdef STARPU_DEVEL
  124. # warning history based model cannot be validated with regression.nsample
  125. #endif
  126. #if 0
  127. /* Use a history model */
  128. ret = submit(&mycodelet, &hb_model);
  129. if (ret) return ret;
  130. #endif
  131. return EXIT_SUCCESS;
  132. }