non_linear_regression_based.c 2.3 KB

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