starpu_opencl.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2012 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 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. #ifndef __STARPU_OPENCL_H__
  18. #define __STARPU_OPENCL_H__
  19. #include <starpu_config.h>
  20. #ifdef STARPU_USE_OPENCL
  21. #ifdef __APPLE__
  22. #include <OpenCL/cl.h>
  23. #else
  24. #include <CL/cl.h>
  25. #endif
  26. #include <assert.h>
  27. #ifdef __cplusplus
  28. extern "C"
  29. {
  30. #endif
  31. const char *starpu_opencl_error_string(cl_int status);
  32. void starpu_opencl_display_error(const char *func, const char *file, int line, const char *msg, cl_int status);
  33. #define STARPU_OPENCL_DISPLAY_ERROR(status) \
  34. starpu_opencl_display_error(__starpu_func__, __FILE__, __LINE__, NULL, status)
  35. static inline void starpu_opencl_report_error(const char *func, const char *file, int line, const char *msg, cl_int status)
  36. {
  37. starpu_opencl_display_error(func, file, line, msg, status);
  38. assert(0);
  39. }
  40. #define STARPU_OPENCL_REPORT_ERROR(status) \
  41. starpu_opencl_report_error(__starpu_func__, __FILE__, __LINE__, NULL, status)
  42. #define STARPU_OPENCL_REPORT_ERROR_WITH_MSG(msg, status) \
  43. starpu_opencl_report_error(__starpu_func__, __FILE__, __LINE__, msg, status)
  44. struct starpu_opencl_program
  45. {
  46. cl_program programs[STARPU_MAXOPENCLDEVS];
  47. };
  48. size_t starpu_opencl_get_global_mem_size(int devid);
  49. void starpu_opencl_get_context(int devid, cl_context *context);
  50. void starpu_opencl_get_device(int devid, cl_device_id *device);
  51. void starpu_opencl_get_queue(int devid, cl_command_queue *queue);
  52. void starpu_opencl_get_current_context(cl_context *context);
  53. void starpu_opencl_get_current_queue(cl_command_queue *queue);
  54. void starpu_opencl_load_program_source(const char *source_file_name, char *located_file_name, char *located_dir_name, char *opencl_program_source);
  55. int starpu_opencl_compile_opencl_from_file(const char *source_file_name, const char *build_options);
  56. int starpu_opencl_compile_opencl_from_string(const char *opencl_program_source, const char *file_name, const char* build_options);
  57. int starpu_opencl_load_binary_opencl(const char *kernel_id, struct starpu_opencl_program *opencl_programs);
  58. int starpu_opencl_load_opencl_from_file(const char *source_file_name, struct starpu_opencl_program *opencl_programs, const char* build_options);
  59. int starpu_opencl_load_opencl_from_string(const char *opencl_program_source, struct starpu_opencl_program *opencl_programs, const char* build_options);
  60. int starpu_opencl_unload_opencl(struct starpu_opencl_program *opencl_programs);
  61. int starpu_opencl_load_kernel(cl_kernel *kernel, cl_command_queue *queue, struct starpu_opencl_program *opencl_programs, const char *kernel_name, int devid);
  62. int starpu_opencl_release_kernel(cl_kernel kernel);
  63. int starpu_opencl_collect_stats(cl_event event);
  64. /*
  65. * Sets the arguments of an OpenCL kernel.
  66. * Arguments to pass to the kernel should be given as follows :
  67. *
  68. * size of the argument, pointer to the argument
  69. *
  70. * 0 must be passed to this function after the kernel arguments.
  71. *
  72. * In case of failure, returns the id of the argument that could not be set,
  73. * and sets "error" to the error returned. Otherwise, returns the number of
  74. * arguments that were set.
  75. *
  76. * Example :
  77. * int n;
  78. * cl_int err;
  79. * cl_kernel kernel;
  80. * n = starpu_opencl_set_kernel_args(&err, 2, &kernel,
  81. * sizeof(foo), &foo,
  82. * sizeof(bar), &bar,
  83. * 0);
  84. * if (n != 2)
  85. * fprintf(stderr, "Error : %d\n", err);
  86. */
  87. int starpu_opencl_set_kernel_args(cl_int *err, cl_kernel *kernel, ...);
  88. cl_int starpu_opencl_allocate_memory(cl_mem *addr, size_t size, cl_mem_flags flags);
  89. cl_int starpu_opencl_copy_ram_to_opencl(void *ptr, unsigned src_node, cl_mem buffer, unsigned dst_node, size_t size, size_t offset, cl_event *event, int *ret);
  90. cl_int starpu_opencl_copy_opencl_to_ram(cl_mem buffer, unsigned src_node, void *ptr, unsigned dst_node, size_t size, size_t offset, cl_event *event, int *ret);
  91. #ifdef __cplusplus
  92. }
  93. #endif
  94. #endif /* STARPU_USE_OPENCL */
  95. #endif /* __STARPU_OPENCL_H__ */