regression_based.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 = 100;
  63. int loop;
  64. starpu_data_handle handle;
  65. starpu_vector_data_register(&handle, -1, (uintptr_t)NULL, nelems, sizeof(int));
  66. for (loop = 0; loop < nloops; loop++)
  67. {
  68. struct starpu_task *task = starpu_task_create();
  69. task->cl = codelet;
  70. task->buffers[0].handle = handle;
  71. task->buffers[0].mode = STARPU_W;
  72. int ret = starpu_task_submit(task);
  73. assert(!ret);
  74. }
  75. starpu_data_unregister(handle);
  76. }
  77. int main(int argc, char **argv)
  78. {
  79. struct starpu_conf conf;
  80. starpu_conf_init(&conf);
  81. conf.sched_policy_name = "greedy";
  82. conf.calibrate = 1;
  83. starpu_init(&conf);
  84. int size;
  85. for (size = 1024; size < 16777216; size *= 2)
  86. {
  87. /* Use a linear regression */
  88. test_memset(size, &memset_cl);
  89. /* Use a non-linear regression */
  90. test_memset(size, &nl_memset_cl);
  91. }
  92. starpu_task_wait_for_all();
  93. starpu_shutdown();
  94. return 0;
  95. }