non_linear_regression_based.c 2.1 KB

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