cl_buildprogram.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. clGetProgramBuildInfo(d->program->cl_programs[range], device, CL_PROGRAM_BUILD_LOG, 0, NULL, &len);
  33. char * buffer = malloc(len+1);
  34. buffer[len] = '\0';
  35. clGetProgramBuildInfo(d->program->cl_programs[range], device, CL_PROGRAM_BUILD_LOG, len, buffer, NULL);
  36. DEBUG_CL("clBuildProgram", err);
  37. ERROR_MSG("clBuildProgram: %s\n Aborting.\n", buffer);
  38. free(buffer);
  39. }
  40. DEBUG_MSG("[Worker %d] Done building.\n", wid);
  41. }
  42. CL_API_ENTRY cl_int CL_API_CALL
  43. soclBuildProgram(cl_program program,
  44. cl_uint UNUSED(num_devices),
  45. const cl_device_id * UNUSED(device_list),
  46. const char * options,
  47. void (*pfn_notify)(cl_program program, void * user_data),
  48. void * user_data) CL_API_SUFFIX__VERSION_1_0
  49. {
  50. struct bp_data *data;
  51. program->options = options != NULL ? strdup(options) : NULL;
  52. program->options_size = options != NULL ? strlen(options)+1 : 0;
  53. data = (struct bp_data*)malloc(sizeof(struct bp_data));
  54. gc_entity_store(&data->program, program);
  55. data->options = (char*)options;
  56. /*FIXME: starpu_execute_on_each_worker is synchronous.
  57. * However pfn_notify may be useful only because build is supposed to be asynchronous
  58. */
  59. starpu_execute_on_each_worker(soclBuildProgram_task, data, STARPU_OPENCL);
  60. if (pfn_notify != NULL)
  61. pfn_notify(program, user_data);
  62. gc_entity_unstore(&data->program);
  63. free(data);
  64. return CL_SUCCESS;
  65. }