partition_lazy.c 2.8 KB

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