partition_lazy.c 2.6 KB

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