non_linear_regression_based.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2012, 2014-2016 Université de Bordeaux
  4. * Copyright (C) 2012, 2013 CNRS
  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. /*
  22. * Benchmark memset with a non-linear regression
  23. */
  24. #define START_LOG 8
  25. #ifdef STARPU_QUICK_CHECK
  26. #define END_LOG 20
  27. #else
  28. #define END_LOG 25
  29. #endif
  30. #ifdef STARPU_USE_CUDA
  31. static void memset_cuda(void *descr[], void *arg)
  32. {
  33. (void)arg;
  34. STARPU_SKIP_IF_VALGRIND;
  35. int *ptr = (int *)STARPU_VECTOR_GET_PTR(descr[0]);
  36. unsigned n = STARPU_VECTOR_GET_NX(descr[0]);
  37. cudaMemsetAsync(ptr, 42, n * sizeof(*ptr), starpu_cuda_get_local_stream());
  38. }
  39. #endif
  40. void memset_cpu(void *descr[], void *arg)
  41. {
  42. (void)arg;
  43. STARPU_SKIP_IF_VALGRIND;
  44. int *ptr = (int *)STARPU_VECTOR_GET_PTR(descr[0]);
  45. unsigned n = STARPU_VECTOR_GET_NX(descr[0]);
  46. memset(ptr, 42, n * sizeof(*ptr));
  47. }
  48. static struct starpu_perfmodel model =
  49. {
  50. .type = STARPU_NL_REGRESSION_BASED,
  51. .symbol = "non_linear_memset_regression_based"
  52. };
  53. #ifdef STARPU_USE_OPENCL
  54. extern void memset_opencl(void *buffers[], void *args);
  55. #endif
  56. static struct starpu_codelet memset_cl =
  57. {
  58. #ifdef STARPU_USE_CUDA
  59. .cuda_funcs = {memset_cuda},
  60. .cuda_flags = {STARPU_CUDA_ASYNC},
  61. #endif
  62. #ifdef STARPU_USE_OPENCL
  63. .opencl_funcs = {memset_opencl},
  64. .opencl_flags = {STARPU_OPENCL_ASYNC},
  65. #endif
  66. .cpu_funcs = {memset_cpu},
  67. .cpu_funcs_name = {"memset_cpu"},
  68. .model = &model,
  69. .nbuffers = 1,
  70. .modes = {STARPU_W}
  71. };
  72. static void test_memset(int nelems)
  73. {
  74. starpu_data_handle_t handle;
  75. starpu_vector_data_register(&handle, -1, (uintptr_t)NULL, nelems, sizeof(int));
  76. int nloops = 200;
  77. int loop;
  78. for (loop = 0; loop < nloops; loop++)
  79. {
  80. struct starpu_task *task = starpu_task_create();
  81. task->cl = &memset_cl;
  82. task->handles[0] = handle;
  83. int ret = starpu_task_submit(task);
  84. if (ret == -ENODEV)
  85. exit(STARPU_TEST_SKIPPED);
  86. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  87. }
  88. starpu_data_unregister(handle);
  89. }
  90. #ifdef STARPU_USE_OPENCL
  91. struct starpu_opencl_program opencl_program;
  92. #endif
  93. int main(int argc, char **argv)
  94. {
  95. int ret;
  96. struct starpu_conf conf;
  97. starpu_conf_init(&conf);
  98. conf.sched_policy_name = "eager";
  99. conf.calibrate = 2;
  100. ret = starpu_initialize(&conf, &argc, &argv);
  101. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  102. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  103. #ifdef STARPU_USE_OPENCL
  104. ret = starpu_opencl_load_opencl_from_file("tests/perfmodels/opencl_memset_kernel.cl",
  105. &opencl_program, NULL);
  106. STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_load_opencl_from_file");
  107. #endif
  108. int slog;
  109. for (slog = START_LOG; slog < END_LOG; slog++)
  110. {
  111. int size = 1 << slog;
  112. test_memset(size);
  113. }
  114. #ifdef STARPU_USE_OPENCL
  115. ret = starpu_opencl_unload_opencl(&opencl_program);
  116. STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_unload_opencl");
  117. #endif
  118. starpu_shutdown();
  119. return EXIT_SUCCESS;
  120. }