partition_lazy.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2020 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. #include "scal.h"
  19. /*
  20. * Test partitioning an uninitialized vector
  21. */
  22. struct starpu_codelet mycodelet =
  23. {
  24. .cpu_funcs = { scal_func_cpu },
  25. #ifdef STARPU_USE_OPENCL
  26. .opencl_funcs = { scal_func_opencl },
  27. .opencl_flags = {STARPU_OPENCL_ASYNC},
  28. #endif
  29. #ifdef STARPU_USE_CUDA
  30. .cuda_funcs = { scal_func_cuda },
  31. .cuda_flags = {STARPU_CUDA_ASYNC},
  32. #endif
  33. .cpu_funcs_name = {"scal_func_cpu"},
  34. .modes = { STARPU_W },
  35. .model = NULL,
  36. .nbuffers = 1
  37. };
  38. int main(int argc, char **argv)
  39. {
  40. unsigned *foo;
  41. starpu_data_handle_t handle;
  42. int ret;
  43. int n, size;
  44. unsigned i;
  45. ret = starpu_initialize(NULL, &argc, &argv);
  46. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  47. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  48. #ifdef STARPU_USE_OPENCL
  49. ret = starpu_opencl_load_opencl_from_file("tests/datawizard/scal_opencl.cl", &opencl_program, NULL);
  50. STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_load_opencl_from_file");
  51. #endif
  52. n = starpu_worker_get_count();
  53. size = 10 * n;
  54. starpu_vector_data_register(&handle, -1, (uintptr_t)NULL, size, sizeof(*foo));
  55. struct starpu_data_filter f =
  56. {
  57. .filter_func = starpu_vector_filter_block,
  58. .nchildren = n > 1 ? n : 2,
  59. };
  60. starpu_data_partition(handle, &f);
  61. for (i = 0; i < f.nchildren; i++)
  62. {
  63. ret = starpu_task_insert(&mycodelet,
  64. STARPU_W,
  65. starpu_data_get_sub_data(handle, 1, i),
  66. 0);
  67. if (ret == -ENODEV) goto enodev;
  68. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  69. }
  70. ret = starpu_task_wait_for_all();
  71. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  72. starpu_data_unpartition(handle, STARPU_MAIN_RAM);
  73. starpu_data_unregister(handle);
  74. starpu_shutdown();
  75. return 0;
  76. enodev:
  77. starpu_data_unregister(handle);
  78. fprintf(stderr, "WARNING: No one can execute this task\n");
  79. /* yes, we do not perform the computation but we did detect that no one
  80. * could perform the kernel, so this is not an error from StarPU */
  81. starpu_shutdown();
  82. return STARPU_TEST_SKIPPED;
  83. }