gpu_concurrency.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2014-2015 Université de Bordeaux
  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 <config.h>
  17. #include <stdio.h>
  18. #include <unistd.h>
  19. #include <errno.h>
  20. #include <starpu.h>
  21. #include <stdlib.h>
  22. #include "../helper.h"
  23. #include <common/thread.h>
  24. #ifdef STARPU_QUICK_CHECK
  25. #define NITERS 100000
  26. #else
  27. #define NITERS 1000000
  28. #endif
  29. #define NTASKS 64
  30. #define SYNC 16
  31. #ifdef STARPU_USE_CUDA
  32. extern void long_kernel_cuda(unsigned long niters);
  33. void codelet_long_kernel_async(STARPU_ATTRIBUTE_UNUSED void *descr[], STARPU_ATTRIBUTE_UNUSED void *_args)
  34. {
  35. long_kernel_cuda(NITERS);
  36. }
  37. void codelet_long_kernel_sync(STARPU_ATTRIBUTE_UNUSED void *descr[], STARPU_ATTRIBUTE_UNUSED void *_args)
  38. {
  39. long_kernel_cuda(NITERS);
  40. cudaStreamSynchronize(starpu_cuda_get_local_stream());
  41. }
  42. static struct starpu_perfmodel model_async =
  43. {
  44. .type = STARPU_HISTORY_BASED,
  45. .symbol = "long_kernel_async",
  46. };
  47. static struct starpu_perfmodel model_sync =
  48. {
  49. .type = STARPU_HISTORY_BASED,
  50. .symbol = "long_kernel_sync",
  51. };
  52. static struct starpu_codelet cl_async =
  53. {
  54. .cuda_funcs = {codelet_long_kernel_async},
  55. .cuda_flags = {STARPU_CUDA_ASYNC},
  56. .nbuffers = 0,
  57. .model = &model_async,
  58. };
  59. static struct starpu_codelet cl =
  60. {
  61. .cuda_funcs = {codelet_long_kernel_sync},
  62. .nbuffers = 0,
  63. .model = &model_sync,
  64. };
  65. #endif
  66. int main(int argc, char **argv)
  67. {
  68. #ifndef STARPU_USE_CUDA
  69. return STARPU_TEST_SKIPPED;
  70. #else
  71. setenv("STARPU_NWORKER_PER_CUDA", "4", 1);
  72. int ret = starpu_initialize(NULL, &argc, &argv);
  73. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  74. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  75. if (starpu_cuda_worker_get_count() == 0)
  76. {
  77. starpu_shutdown();
  78. return STARPU_TEST_SKIPPED;
  79. }
  80. unsigned iter;
  81. for (iter = 0; iter < NTASKS; iter++)
  82. {
  83. struct starpu_task *task = starpu_task_create();
  84. if (!(iter % SYNC))
  85. task->cl = &cl;
  86. else
  87. task->cl = &cl_async;
  88. ret = starpu_task_submit(task);
  89. if (ret == -ENODEV) goto enodev;
  90. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  91. }
  92. starpu_shutdown();
  93. STARPU_RETURN(EXIT_SUCCESS);
  94. enodev:
  95. fprintf(stderr, "WARNING: No one can execute this task\n");
  96. /* yes, we do not perform the computation but we did detect that no one
  97. * could perform the kernel, so this is not an error from StarPU */
  98. starpu_shutdown();
  99. STARPU_RETURN(STARPU_TEST_SKIPPED);
  100. #endif
  101. }