non_linear_regression_based.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 Université de Bordeaux 1
  4. * Copyright (C) 2012 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <config.h>
  18. #include <starpu.h>
  19. #include "../helper.h"
  20. #ifdef STARPU_USE_CUDA
  21. static void memset_cuda(void *descr[], void *arg)
  22. {
  23. STARPU_SKIP_IF_VALGRIND;
  24. int *ptr = (int *)STARPU_VECTOR_GET_PTR(descr[0]);
  25. unsigned n = STARPU_VECTOR_GET_NX(descr[0]);
  26. cudaMemset(ptr, 42, n);
  27. cudaThreadSynchronize();
  28. }
  29. #endif
  30. static void memset_cpu(void *descr[], void *arg)
  31. {
  32. STARPU_SKIP_IF_VALGRIND;
  33. int *ptr = (int *)STARPU_VECTOR_GET_PTR(descr[0]);
  34. unsigned n = STARPU_VECTOR_GET_NX(descr[0]);
  35. memset(ptr, 42, n);
  36. }
  37. static struct starpu_perfmodel model =
  38. {
  39. .type = STARPU_NL_REGRESSION_BASED,
  40. .symbol = "non_linear_memset_regression_based"
  41. };
  42. static struct starpu_codelet memset_cl =
  43. {
  44. .where = STARPU_CUDA|STARPU_CPU,
  45. #ifdef STARPU_USE_CUDA
  46. .cuda_funcs = {memset_cuda, NULL},
  47. #endif
  48. .cpu_funcs = {memset_cpu, NULL},
  49. .model = &model,
  50. .nbuffers = 1,
  51. .modes = {STARPU_W}
  52. };
  53. static void test_memset(int nelems)
  54. {
  55. starpu_data_handle_t handle;
  56. starpu_vector_data_register(&handle, -1, (uintptr_t)NULL, nelems, sizeof(int));
  57. int nloops = 200;
  58. int loop;
  59. for (loop = 0; loop < nloops; loop++)
  60. {
  61. struct starpu_task *task = starpu_task_create();
  62. task->cl = &memset_cl;
  63. task->handles[0] = handle;
  64. int ret = starpu_task_submit(task);
  65. if (ret == -ENODEV)
  66. exit(STARPU_TEST_SKIPPED);
  67. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  68. }
  69. starpu_data_unregister(handle);
  70. }
  71. int main(int argc, char **argv)
  72. {
  73. int ret;
  74. struct starpu_conf conf;
  75. starpu_conf_init(&conf);
  76. conf.sched_policy_name = "eager";
  77. conf.calibrate = 2;
  78. ret = starpu_init(&conf);
  79. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  80. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  81. int slog;
  82. for (slog = 8; slog < 25; slog++)
  83. {
  84. int size = 1 << slog;
  85. test_memset(size);
  86. }
  87. starpu_shutdown();
  88. return EXIT_SUCCESS;
  89. }