cl_buildprogram.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010,2011 University of Bordeaux
  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 "socl.h"
  17. struct bp_data {
  18. cl_program program;
  19. char * options;
  20. };
  21. static void soclBuildProgram_task(void *data) {
  22. struct bp_data *d = (struct bp_data*)data;
  23. cl_device_id device;
  24. cl_int err;
  25. int wid = starpu_worker_get_id();
  26. int range = starpu_worker_get_range();
  27. starpu_opencl_get_device(wid, &device);
  28. DEBUG_MSG("[Worker %d] Building program...\n", wid);
  29. err = clBuildProgram(d->program->cl_programs[range], 1, &device, d->options, NULL, NULL);
  30. if (err != CL_SUCCESS) {
  31. size_t len;
  32. static char buffer[4096];
  33. clGetProgramBuildInfo(d->program->cl_programs[range], device, CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len);
  34. DEBUG_CL("clBuildProgram", err);
  35. ERROR_MSG("clBuildProgram: %s\n Aborting.\n", buffer);
  36. }
  37. DEBUG_MSG("[Worker %d] Done building.\n", wid);
  38. }
  39. CL_API_ENTRY cl_int CL_API_CALL
  40. soclBuildProgram(cl_program program,
  41. cl_uint UNUSED(num_devices),
  42. const cl_device_id * UNUSED(device_list),
  43. const char * options,
  44. void (*pfn_notify)(cl_program program, void * user_data),
  45. void * user_data) CL_API_SUFFIX__VERSION_1_0
  46. {
  47. struct bp_data *data;
  48. program->options = options != NULL ? strdup(options) : NULL;
  49. program->options_size = options != NULL ? strlen(options)+1 : 0;
  50. data = (struct bp_data*)malloc(sizeof(struct bp_data));
  51. gc_entity_store(&data->program, program);
  52. data->options = (char*)options;
  53. /*FIXME: starpu_execute_on_each_worker is synchronous.
  54. * However pfn_notify may be useful only because build is supposed to be asynchronous
  55. */
  56. starpu_execute_on_each_worker(soclBuildProgram_task, data, STARPU_OPENCL);
  57. if (pfn_notify != NULL)
  58. pfn_notify(program, user_data);
  59. gc_entity_unstore(&data->program);
  60. free(data);
  61. return CL_SUCCESS;
  62. }