non_linear_regression_based.c 3.2 KB

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