write_only_tmp_buffer.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
  4. *
  5. * This program 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. * This program 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 <stdio.h>
  17. #include <unistd.h>
  18. #include <errno.h>
  19. #include <starpu.h>
  20. #include <stdlib.h>
  21. #define VECTORSIZE 1024
  22. starpu_data_handle v_handle;
  23. #ifdef USE_CUDA
  24. static void cuda_codelet_null(starpu_data_interface_t *buffers, __attribute__ ((unused)) void *_args)
  25. {
  26. int *buf = (int *)buffers[0].vector.ptr;
  27. cudaMemset(buf, 42, sizeof(int));
  28. }
  29. #endif
  30. static void core_codelet_null(starpu_data_interface_t *buffers, __attribute__ ((unused)) void *_args)
  31. {
  32. int *buf = (int *)buffers[0].vector.ptr;
  33. *buf = 42;
  34. }
  35. static void display_var(starpu_data_interface_t *buffers, __attribute__ ((unused)) void *_args)
  36. {
  37. int *buf = (int *)buffers[0].vector.ptr;
  38. if (*buf != 42)
  39. {
  40. fprintf(stderr, "Value = %d (should be %d)\n", *buf, 42);
  41. exit(-1);
  42. }
  43. }
  44. static starpu_codelet cl = {
  45. .where = CORE|CUDA,
  46. .core_func = core_codelet_null,
  47. #ifdef USE_CUDA
  48. .cuda_func = cuda_codelet_null,
  49. #endif
  50. .nbuffers = 1
  51. };
  52. static starpu_codelet display_cl = {
  53. .where = CORE,
  54. .core_func = display_var,
  55. .nbuffers = 1
  56. };
  57. int main(int argc, char **argv)
  58. {
  59. int ret;
  60. starpu_init(NULL);
  61. /* The buffer should never be explicitely allocated */
  62. starpu_register_vector_data(&v_handle, (uint32_t)-1, (uintptr_t)NULL, VECTORSIZE, sizeof(int));
  63. struct starpu_task *task = starpu_task_create();
  64. task->cl = &cl;
  65. task->buffers[0].handle = v_handle;
  66. task->buffers[0].mode = STARPU_W;
  67. task->detach = 0;
  68. ret = starpu_submit_task(task);
  69. if (ret == -ENODEV)
  70. goto enodev;
  71. ret = starpu_wait_task(task);
  72. if (ret)
  73. exit(-1);
  74. task = starpu_task_create();
  75. task->cl = &display_cl;
  76. task->buffers[0].handle = v_handle;
  77. task->buffers[0].mode = STARPU_R;
  78. task->detach = 0;
  79. ret = starpu_submit_task(task);
  80. if (ret == -ENODEV)
  81. goto enodev;
  82. ret = starpu_wait_task(task);
  83. if (ret)
  84. exit(-1);
  85. /* this should get rid of automatically allocated buffers */
  86. starpu_delete_data(v_handle);
  87. starpu_shutdown();
  88. return 0;
  89. enodev:
  90. fprintf(stderr, "WARNING: No one can execute this task\n");
  91. /* yes, we do not perform the computation but we did detect that no one
  92. * could perform the kernel, so this is not an error from StarPU */
  93. return 0;
  94. }