multiformat_conversion_codelets_opencl.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 Institut National de Recherche en Informatique et Automatique
  4. * Copyright (C) 2012 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu.h>
  18. #include <starpu_opencl.h>
  19. #include "../../../helper.h"
  20. #define KERNEL_LOCATION "tests/datawizard/interfaces/multiformat/multiformat_conversion_codelets_kernel.cl"
  21. static struct starpu_opencl_program opencl_conversion_program;
  22. void cpu_to_opencl_opencl_func(void *buffers[], void *args)
  23. {
  24. (void) args;
  25. int id, devid, ret;
  26. cl_int err;
  27. cl_kernel kernel;
  28. cl_command_queue queue;
  29. cl_event event;
  30. unsigned n = STARPU_MULTIFORMAT_GET_NX(buffers[0]);
  31. cl_mem src = (cl_mem) STARPU_MULTIFORMAT_GET_PTR(buffers[0]);
  32. cl_mem dst = (cl_mem) STARPU_MULTIFORMAT_GET_OPENCL_PTR(buffers[0]);
  33. id = starpu_worker_get_id();
  34. devid = starpu_worker_get_devid(id);
  35. ret = starpu_opencl_load_opencl_from_file(KERNEL_LOCATION,
  36. &opencl_conversion_program,
  37. NULL);
  38. STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_load_opencl_from_file");
  39. err = starpu_opencl_load_kernel(&kernel,
  40. &queue,
  41. &opencl_conversion_program,
  42. "cpu_to_opencl_opencl",
  43. devid);
  44. if (err != CL_SUCCESS)
  45. STARPU_OPENCL_REPORT_ERROR(err);
  46. err = clSetKernelArg(kernel, 0, sizeof(src), &src);
  47. if (err != CL_SUCCESS)
  48. STARPU_OPENCL_REPORT_ERROR(err);
  49. err = clSetKernelArg(kernel, 1, sizeof(dst), &dst);
  50. if (err != CL_SUCCESS)
  51. STARPU_OPENCL_REPORT_ERROR(err);
  52. err = clSetKernelArg(kernel, 2, sizeof(n), &n);
  53. if (err != CL_SUCCESS)
  54. STARPU_OPENCL_REPORT_ERROR(err);
  55. {
  56. size_t global=n;
  57. size_t local;
  58. size_t s;
  59. cl_device_id device;
  60. starpu_opencl_get_device(devid, &device);
  61. err = clGetKernelWorkGroupInfo (kernel,
  62. device,
  63. CL_KERNEL_WORK_GROUP_SIZE,
  64. sizeof(local),
  65. &local,
  66. &s);
  67. if (err != CL_SUCCESS)
  68. STARPU_OPENCL_REPORT_ERROR(err);
  69. if (local > global)
  70. local = global;
  71. err = clEnqueueNDRangeKernel(queue,
  72. kernel,
  73. 1,
  74. NULL,
  75. &global,
  76. &local,
  77. 0,
  78. NULL,
  79. &event);
  80. if (err != CL_SUCCESS)
  81. STARPU_OPENCL_REPORT_ERROR(err);
  82. }
  83. clFinish(queue);
  84. starpu_opencl_collect_stats(event);
  85. clReleaseEvent(event);
  86. starpu_opencl_release_kernel(kernel);
  87. starpu_opencl_unload_opencl(&opencl_conversion_program);
  88. }