non_linear_regression_based.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #include "../helper.h"
  18. #ifdef STARPU_USE_CUDA
  19. static void memset_cuda(void *descr[], void *arg)
  20. {
  21. int *ptr = (int *)STARPU_VECTOR_GET_PTR(descr[0]);
  22. unsigned n = STARPU_VECTOR_GET_NX(descr[0]);
  23. cudaMemset(ptr, 42, n);
  24. cudaThreadSynchronize();
  25. }
  26. #endif
  27. static void memset_cpu(void *descr[], void *arg)
  28. {
  29. int *ptr = (int *)STARPU_VECTOR_GET_PTR(descr[0]);
  30. unsigned n = STARPU_VECTOR_GET_NX(descr[0]);
  31. memset(ptr, 42, n);
  32. }
  33. static struct starpu_perfmodel model =
  34. {
  35. .type = STARPU_NL_REGRESSION_BASED,
  36. .symbol = "non_linear_memset_regression_based"
  37. };
  38. static struct starpu_codelet memset_cl =
  39. {
  40. .where = STARPU_CUDA|STARPU_CPU,
  41. #ifdef STARPU_USE_CUDA
  42. .cuda_funcs = {memset_cuda, NULL},
  43. #endif
  44. .cpu_funcs = {memset_cpu, NULL},
  45. .model = &model,
  46. .nbuffers = 1
  47. };
  48. static void test_memset(int nelems)
  49. {
  50. starpu_data_handle_t handle;
  51. starpu_vector_data_register(&handle, -1, (uintptr_t)NULL, nelems, sizeof(int));
  52. int nloops = 200;
  53. int loop;
  54. for (loop = 0; loop < nloops; loop++)
  55. {
  56. struct starpu_task *task = starpu_task_create();
  57. task->cl = &memset_cl;
  58. task->buffers[0].handle = handle;
  59. task->buffers[0].mode = STARPU_W;
  60. int ret = starpu_task_submit(task);
  61. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  62. }
  63. starpu_data_unregister(handle);
  64. }
  65. int main(int argc, char **argv)
  66. {
  67. int ret;
  68. struct starpu_conf conf;
  69. starpu_conf_init(&conf);
  70. conf.sched_policy_name = "eager";
  71. conf.calibrate = 2;
  72. ret = starpu_init(&conf);
  73. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  74. int slog;
  75. for (slog = 8; slog < 25; slog++)
  76. {
  77. int size = 1 << slog;
  78. test_memset(size);
  79. }
  80. starpu_shutdown();
  81. return EXIT_SUCCESS;
  82. }