non_linear_regression_based.c 3.4 KB

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