multiformat_conversion_codelets_opencl.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 Institut National de Recherche en Informatique et Automatique
  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 <starpu_opencl.h>
  18. #define KERNEL_LOCATION "tests/datawizard/interfaces/multiformat/multiformat_conversion_codelets_kernel.cl"
  19. static struct starpu_opencl_program opencl_conversion_program;
  20. void cpu_to_opencl_opencl_func(void *buffers[], void *args)
  21. {
  22. (void) args;
  23. int id, devid;
  24. cl_int err;
  25. cl_kernel kernel;
  26. cl_command_queue queue;
  27. cl_event event;
  28. unsigned n = STARPU_MULTIFORMAT_GET_NX(buffers[0]);
  29. cl_mem src = (cl_mem) STARPU_MULTIFORMAT_GET_PTR(buffers[0]);
  30. cl_mem dst = (cl_mem) STARPU_MULTIFORMAT_GET_OPENCL_PTR(buffers[0]);
  31. id = starpu_worker_get_id();
  32. devid = starpu_worker_get_devid(id);
  33. starpu_opencl_load_opencl_from_file(KERNEL_LOCATION,
  34. &opencl_conversion_program,
  35. NULL);
  36. err = starpu_opencl_load_kernel(&kernel,
  37. &queue,
  38. &opencl_conversion_program,
  39. "cpu_to_opencl_opencl",
  40. devid);
  41. if (err != CL_SUCCESS)
  42. STARPU_OPENCL_REPORT_ERROR(err);
  43. err = clSetKernelArg(kernel, 0, sizeof(src), &src);
  44. if (err != CL_SUCCESS)
  45. STARPU_OPENCL_REPORT_ERROR(err);
  46. err = clSetKernelArg(kernel, 1, sizeof(dst), &dst);
  47. if (err != CL_SUCCESS)
  48. STARPU_OPENCL_REPORT_ERROR(err);
  49. err = clSetKernelArg(kernel, 2, sizeof(n), &n);
  50. if (err != CL_SUCCESS)
  51. STARPU_OPENCL_REPORT_ERROR(err);
  52. {
  53. size_t global=n;
  54. size_t local;
  55. size_t s;
  56. cl_device_id device;
  57. starpu_opencl_get_device(devid, &device);
  58. err = clGetKernelWorkGroupInfo (kernel,
  59. device,
  60. CL_KERNEL_WORK_GROUP_SIZE,
  61. sizeof(local),
  62. &local,
  63. &s);
  64. if (err != CL_SUCCESS)
  65. STARPU_OPENCL_REPORT_ERROR(err);
  66. if (local > global)
  67. local = global;
  68. err = clEnqueueNDRangeKernel(queue,
  69. kernel,
  70. 1,
  71. NULL,
  72. &global,
  73. &local,
  74. 0,
  75. NULL,
  76. &event);
  77. if (err != CL_SUCCESS)
  78. STARPU_OPENCL_REPORT_ERROR(err);
  79. }
  80. clFinish(queue);
  81. starpu_opencl_collect_stats(event);
  82. clReleaseEvent(event);
  83. starpu_opencl_release_kernel(kernel);
  84. starpu_opencl_unload_opencl(&opencl_conversion_program);
  85. }