write_only_tmp_buffer.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. static void cuda_codelet_null(starpu_data_interface_t *buffers, __attribute__ ((unused)) void *_args)
  24. {
  25. fprintf(stderr, "POUET CUDA\n");
  26. int *buf = (int *)buffers[0].vector.ptr;
  27. cudaMemset(buf, 42, sizeof(int));
  28. }
  29. static void core_codelet_null(starpu_data_interface_t *buffers, __attribute__ ((unused)) void *_args)
  30. {
  31. fprintf(stderr, "POUET CUDA\n");
  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. fprintf(stderr, "Value = %d (should be %d)\n", *buf, 42);
  39. fflush(stderr);
  40. if (*buf != 42)
  41. exit(-1);
  42. }
  43. static starpu_codelet cl = {
  44. .where = CORE|CUDA,
  45. .core_func = core_codelet_null,
  46. .cuda_func = cuda_codelet_null,
  47. .nbuffers = 1
  48. };
  49. static starpu_codelet display_cl = {
  50. .where = CORE,
  51. .core_func = display_var,
  52. .nbuffers = 1
  53. };
  54. int main(int argc, char **argv)
  55. {
  56. starpu_init(NULL);
  57. /* The buffer should never be explicitely allocated */
  58. starpu_register_vector_data(&v_handle, (uint32_t)-1, (uintptr_t)NULL, VECTORSIZE, sizeof(int));
  59. struct starpu_task *task = starpu_task_create();
  60. task->cl = &cl;
  61. task->buffers[0].handle = v_handle;
  62. task->buffers[0].mode = STARPU_W;
  63. task->synchronous = 1;
  64. int ret = starpu_submit_task(task);
  65. if (ret == -ENODEV)
  66. goto enodev;
  67. // starpu_wait_task(task);
  68. task = starpu_task_create();
  69. task->cl = &display_cl;
  70. task->buffers[0].handle = v_handle;
  71. task->buffers[0].mode = STARPU_R;
  72. task->synchronous = 1;
  73. ret = starpu_submit_task(task);
  74. if (ret == -ENODEV)
  75. goto enodev;
  76. // starpu_wait_task(task);
  77. /* this should get rid of automatically allocated buffers */
  78. starpu_delete_data(v_handle);
  79. starpu_shutdown();
  80. return 0;
  81. enodev:
  82. fprintf(stderr, "WARNING: No one can execute this task\n");
  83. /* yes, we do not perform the computation but we did detect that no one
  84. * could perform the kernel, so this is not an error from StarPU */
  85. return 0;
  86. }