partition_lazy.c 2.5 KB

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