non_linear_regression_based.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. #ifdef STARPU_USE_OPENCL
  21. #include <starpu_opencl.h>
  22. #endif
  23. #ifdef STARPU_USE_CUDA
  24. #include <starpu_cuda.h>
  25. #endif
  26. #include "../helper.h"
  27. #ifdef STARPU_USE_CUDA
  28. static void memset_cuda(void *descr[], void *arg)
  29. {
  30. STARPU_SKIP_IF_VALGRIND;
  31. int *ptr = (int *)STARPU_VECTOR_GET_PTR(descr[0]);
  32. unsigned n = STARPU_VECTOR_GET_NX(descr[0]);
  33. cudaMemsetAsync(ptr, 42, n * sizeof(*ptr), starpu_cuda_get_local_stream());
  34. cudaStreamSynchronize(starpu_cuda_get_local_stream());
  35. }
  36. #endif
  37. static void memset_cpu(void *descr[], void *arg)
  38. {
  39. STARPU_SKIP_IF_VALGRIND;
  40. int *ptr = (int *)STARPU_VECTOR_GET_PTR(descr[0]);
  41. unsigned n = STARPU_VECTOR_GET_NX(descr[0]);
  42. memset(ptr, 42, n * sizeof(*ptr));
  43. }
  44. static struct starpu_perfmodel model =
  45. {
  46. .type = STARPU_NL_REGRESSION_BASED,
  47. .symbol = "non_linear_memset_regression_based"
  48. };
  49. #ifdef STARPU_USE_OPENCL
  50. extern void memset_opencl(void *buffers[], void *args);
  51. #endif
  52. static struct starpu_codelet memset_cl =
  53. {
  54. #ifdef STARPU_USE_CUDA
  55. .cuda_funcs = {memset_cuda, NULL},
  56. #endif
  57. #ifdef STARPU_USE_OPENCL
  58. .opencl_funcs = {memset_opencl, NULL},
  59. #endif
  60. .cpu_funcs = {memset_cpu, NULL},
  61. .model = &model,
  62. .nbuffers = 1,
  63. .modes = {STARPU_W}
  64. };
  65. static void test_memset(int nelems)
  66. {
  67. starpu_data_handle_t handle;
  68. starpu_vector_data_register(&handle, -1, (uintptr_t)NULL, nelems, sizeof(int));
  69. int nloops = 200;
  70. int loop;
  71. for (loop = 0; loop < nloops; loop++)
  72. {
  73. struct starpu_task *task = starpu_task_create();
  74. task->cl = &memset_cl;
  75. task->handles[0] = handle;
  76. int ret = starpu_task_submit(task);
  77. if (ret == -ENODEV)
  78. exit(STARPU_TEST_SKIPPED);
  79. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  80. }
  81. starpu_data_unregister(handle);
  82. }
  83. #ifdef STARPU_USE_OPENCL
  84. struct starpu_opencl_program opencl_program;
  85. #endif
  86. int main(int argc, char **argv)
  87. {
  88. int ret;
  89. struct starpu_conf conf;
  90. starpu_conf_init(&conf);
  91. conf.sched_policy_name = "eager";
  92. conf.calibrate = 2;
  93. ret = starpu_init(&conf);
  94. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  95. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  96. #ifdef STARPU_USE_OPENCL
  97. ret = starpu_opencl_load_opencl_from_file("tests/perfmodels/opencl_memset_kernel.cl",
  98. &opencl_program, NULL);
  99. STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_load_opencl_from_file");
  100. #endif
  101. int slog;
  102. for (slog = 8; slog < 25; slog++)
  103. {
  104. int size = 1 << slog;
  105. test_memset(size);
  106. }
  107. #ifdef STARPU_USE_OPENCL
  108. ret = starpu_opencl_unload_opencl(&opencl_program);
  109. STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_unload_opencl");
  110. #endif
  111. starpu_shutdown();
  112. return EXIT_SUCCESS;
  113. }