non_linear_regression_based.c 3.2 KB

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