valid_model.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012 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. static 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. static struct starpu_perfmodel hb_model =
  33. {
  34. .type = STARPU_HISTORY_BASED,
  35. .symbol = "valid_model_history_based"
  36. };
  37. static struct starpu_codelet codelet =
  38. {
  39. .cuda_funcs = {func, NULL},
  40. .opencl_funcs = {func, NULL},
  41. .cpu_funcs = {func, NULL},
  42. .nbuffers = 1,
  43. .modes = {STARPU_W}
  44. };
  45. static int submit(struct starpu_codelet *codelet, struct starpu_perfmodel *model)
  46. {
  47. int nloops = 123;
  48. int loop;
  49. starpu_data_handle_t handle;
  50. struct starpu_perfmodel lmodel;
  51. int ret;
  52. int old_nsamples, new_nsamples;
  53. struct starpu_conf conf;
  54. unsigned archid;
  55. starpu_conf_init(&conf);
  56. conf.sched_policy_name = "eager";
  57. conf.calibrate = 1;
  58. ret = starpu_init(&conf);
  59. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  60. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  61. codelet->model = model;
  62. old_nsamples = 0;
  63. ret = starpu_load_history_debug(codelet->model->symbol, &lmodel);
  64. if (ret != 1)
  65. for (archid = 0; archid < STARPU_NARCH_VARIATIONS; archid++)
  66. old_nsamples += lmodel.per_arch[archid][0].regression.nsample;
  67. starpu_vector_data_register(&handle, -1, (uintptr_t)NULL, 100, sizeof(int));
  68. for (loop = 0; loop < nloops; loop++)
  69. {
  70. ret = starpu_insert_task(codelet, STARPU_W, handle, 0);
  71. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  72. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  73. }
  74. starpu_data_unregister(handle);
  75. starpu_shutdown(); // To force dumping perf models on disk
  76. ret = starpu_load_history_debug(codelet->model->symbol, &lmodel);
  77. if (ret == 1)
  78. {
  79. FPRINTF(stderr, "The performance model could not be loaded\n");
  80. return 1;
  81. }
  82. new_nsamples = 0;
  83. for (archid = 0; archid < STARPU_NARCH_VARIATIONS; archid++)
  84. new_nsamples += lmodel.per_arch[archid][0].regression.nsample;
  85. if (old_nsamples + nloops == new_nsamples)
  86. {
  87. FPRINTF(stderr, "Sampling for <%s> OK %d + %d == %d\n", codelet->model->symbol, old_nsamples, nloops, new_nsamples);
  88. return EXIT_SUCCESS;
  89. }
  90. else
  91. {
  92. FPRINTF(stderr, "Sampling for <%s> failed %d + %d != %d\n", codelet->model->symbol, old_nsamples, nloops, new_nsamples);
  93. return EXIT_FAILURE;
  94. }
  95. }
  96. int main(int argc, char **argv)
  97. {
  98. int ret;
  99. /* Use a linear regression model */
  100. ret = submit(&codelet, &rb_model);
  101. if (ret) return ret;
  102. /* Use a non-linear regression model */
  103. ret = submit(&codelet, &nlrb_model);
  104. if (ret) return ret;
  105. #warning history based model cannot be validated with regression.nsample
  106. #if 0
  107. /* Use a history model */
  108. ret = submit(&codelet, &hb_model);
  109. if (ret) return ret;
  110. #endif
  111. return EXIT_SUCCESS;
  112. }