regression_based.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 Université de Bordeaux 1
  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 <starpu.h>
  17. #ifdef STARPU_USE_CUDA
  18. static void memset_cuda(void *descr[], void *arg)
  19. {
  20. int *ptr = (int *)STARPU_VECTOR_GET_PTR(descr[0]);
  21. unsigned n = STARPU_VECTOR_GET_NX(descr[0]);
  22. cudaMemset(ptr, 42, n);
  23. cudaThreadSynchronize();
  24. }
  25. #endif
  26. static void memset_cpu(void *descr[], void *arg)
  27. {
  28. int *ptr = (int *)STARPU_VECTOR_GET_PTR(descr[0]);
  29. unsigned n = STARPU_VECTOR_GET_NX(descr[0]);
  30. memset(ptr, 42, n);
  31. }
  32. static struct starpu_perfmodel_t model = {
  33. .type = STARPU_REGRESSION_BASED,
  34. .symbol = "memset_regression_based"
  35. };
  36. static struct starpu_perfmodel_t nl_model = {
  37. .type = STARPU_NL_REGRESSION_BASED,
  38. .symbol = "non_linear_memset_regression_based"
  39. };
  40. static starpu_codelet memset_cl =
  41. {
  42. .where = STARPU_CUDA|STARPU_CPU,
  43. #ifdef STARPU_USE_CUDA
  44. .cuda_func = memset_cuda,
  45. #endif
  46. .cpu_func = memset_cpu,
  47. .model = &model,
  48. .nbuffers = 1
  49. };
  50. static starpu_codelet nl_memset_cl =
  51. {
  52. .where = STARPU_CUDA|STARPU_CPU,
  53. #ifdef STARPU_USE_CUDA
  54. .cuda_func = memset_cuda,
  55. #endif
  56. .cpu_func = memset_cpu,
  57. .model = &nl_model,
  58. .nbuffers = 1
  59. };
  60. static void test_memset(int nelems, starpu_codelet *codelet)
  61. {
  62. int nloops = 20;
  63. int loop;
  64. starpu_data_handle *handle;
  65. handle = malloc(nloops*sizeof(starpu_data_handle));
  66. assert(handle);
  67. for (loop = 0; loop < nloops; loop++)
  68. {
  69. starpu_vector_data_register(&handle[loop], -1, (uintptr_t)NULL, nelems, sizeof(int));
  70. struct starpu_task *task = starpu_task_create();
  71. task->cl = codelet;
  72. task->buffers[0].handle = handle[loop];
  73. task->buffers[0].mode = STARPU_W;
  74. int ret = starpu_task_submit(task);
  75. assert(!ret);
  76. }
  77. for (loop = 0; loop < nloops; loop++)
  78. starpu_data_unregister(handle[loop]);
  79. free(handle);
  80. }
  81. int main(int argc, char **argv)
  82. {
  83. struct starpu_conf conf;
  84. starpu_conf_init(&conf);
  85. conf.sched_policy_name = "dm";
  86. conf.calibrate = 1;
  87. starpu_init(&conf);
  88. int size;
  89. for (size = 1024; size < 16777216; size *= 2)
  90. {
  91. /* Use a linear regression */
  92. test_memset(size, &memset_cl);
  93. /* Use a non-linear regression */
  94. test_memset(size, &nl_memset_cl);
  95. }
  96. starpu_task_wait_for_all();
  97. starpu_shutdown();
  98. return 0;
  99. }