gpu_concurrency.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2014 Université de Bordeaux 1
  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. #define NITERS 1000000
  25. #define NTASKS 128
  26. #ifdef STARPU_USE_CUDA
  27. extern void long_kernel_cuda(unsigned long niters);
  28. void codelet_long_kernel(STARPU_ATTRIBUTE_UNUSED void *descr[], STARPU_ATTRIBUTE_UNUSED void *_args)
  29. {
  30. long_kernel_cuda(NITERS);
  31. }
  32. static struct starpu_perfmodel model =
  33. {
  34. .type = STARPU_HISTORY_BASED,
  35. .symbol = "long_kernel",
  36. };
  37. static struct starpu_codelet cl =
  38. {
  39. .cuda_funcs = {codelet_long_kernel, NULL},
  40. .cuda_flags = {STARPU_CUDA_ASYNC},
  41. .nbuffers = 0,
  42. .model = &model
  43. };
  44. #endif
  45. int main(int argc, char **argv)
  46. {
  47. #ifndef STARPU_USE_CUDA
  48. return STARPU_TEST_SKIPPED;
  49. #else
  50. int ret = starpu_initialize(NULL, &argc, &argv);
  51. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  52. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  53. if (starpu_cuda_worker_get_count() == 0)
  54. {
  55. starpu_shutdown();
  56. return STARPU_TEST_SKIPPED;
  57. }
  58. unsigned iter;
  59. for (iter = 0; iter < NTASKS; iter++)
  60. {
  61. struct starpu_task *task = starpu_task_create();
  62. task->cl = &cl;
  63. ret = starpu_task_submit(task);
  64. if (ret == -ENODEV) goto enodev;
  65. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  66. }
  67. starpu_shutdown();
  68. STARPU_RETURN(EXIT_SUCCESS);
  69. enodev:
  70. fprintf(stderr, "WARNING: No one can execute this task\n");
  71. /* yes, we do not perform the computation but we did detect that no one
  72. * could perform the kernel, so this is not an error from StarPU */
  73. starpu_shutdown();
  74. STARPU_RETURN(STARPU_TEST_SKIPPED);
  75. #endif
  76. }