ocl.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  1. /*
  2. * Copyright 2011-2012 Con Kolivas
  3. * Copyright 2012-2013 Luke Dashjr
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the Free
  7. * Software Foundation; either version 3 of the License, or (at your option)
  8. * any later version. See COPYING for more details.
  9. */
  10. #include "config.h"
  11. #ifdef HAVE_OPENCL
  12. #include <signal.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <stdio.h>
  16. #include <sys/types.h>
  17. #ifdef WIN32
  18. #include <winsock2.h>
  19. #else
  20. #include <sys/socket.h>
  21. #include <netinet/in.h>
  22. #include <netdb.h>
  23. #endif
  24. #include <time.h>
  25. #include <sys/time.h>
  26. #include <pthread.h>
  27. #include <sys/stat.h>
  28. #include <unistd.h>
  29. #define OMIT_OPENCL_API
  30. #include "findnonce.h"
  31. #include "ocl.h"
  32. /* Platform API */
  33. extern
  34. CL_API_ENTRY cl_int CL_API_CALL
  35. (*clGetPlatformIDs)(cl_uint /* num_entries */,
  36. cl_platform_id * /* platforms */,
  37. cl_uint * /* num_platforms */) CL_API_SUFFIX__VERSION_1_0;
  38. extern
  39. CL_API_ENTRY cl_int CL_API_CALL
  40. (*clGetPlatformInfo)(cl_platform_id /* platform */,
  41. cl_platform_info /* param_name */,
  42. size_t /* param_value_size */,
  43. void * /* param_value */,
  44. size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
  45. /* Device APIs */
  46. extern
  47. CL_API_ENTRY cl_int CL_API_CALL
  48. (*clGetDeviceIDs)(cl_platform_id /* platform */,
  49. cl_device_type /* device_type */,
  50. cl_uint /* num_entries */,
  51. cl_device_id * /* devices */,
  52. cl_uint * /* num_devices */) CL_API_SUFFIX__VERSION_1_0;
  53. extern
  54. CL_API_ENTRY cl_int CL_API_CALL
  55. (*clGetDeviceInfo)(cl_device_id /* device */,
  56. cl_device_info /* param_name */,
  57. size_t /* param_value_size */,
  58. void * /* param_value */,
  59. size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
  60. /* Context APIs */
  61. extern
  62. CL_API_ENTRY cl_context CL_API_CALL
  63. (*clCreateContextFromType)(const cl_context_properties * /* properties */,
  64. cl_device_type /* device_type */,
  65. void (CL_CALLBACK * /* pfn_notify*/ )(const char *, const void *, size_t, void *),
  66. void * /* user_data */,
  67. cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
  68. extern
  69. CL_API_ENTRY cl_int CL_API_CALL
  70. (*clReleaseContext)(cl_context /* context */) CL_API_SUFFIX__VERSION_1_0;
  71. /* Command Queue APIs */
  72. extern
  73. CL_API_ENTRY cl_command_queue CL_API_CALL
  74. (*clCreateCommandQueue)(cl_context /* context */,
  75. cl_device_id /* device */,
  76. cl_command_queue_properties /* properties */,
  77. cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
  78. extern
  79. CL_API_ENTRY cl_int CL_API_CALL
  80. (*clReleaseCommandQueue)(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0;
  81. /* Memory Object APIs */
  82. extern
  83. CL_API_ENTRY cl_mem CL_API_CALL
  84. (*clCreateBuffer)(cl_context /* context */,
  85. cl_mem_flags /* flags */,
  86. size_t /* size */,
  87. void * /* host_ptr */,
  88. cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
  89. /* Program Object APIs */
  90. extern
  91. CL_API_ENTRY cl_program CL_API_CALL
  92. (*clCreateProgramWithSource)(cl_context /* context */,
  93. cl_uint /* count */,
  94. const char ** /* strings */,
  95. const size_t * /* lengths */,
  96. cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
  97. extern
  98. CL_API_ENTRY cl_program CL_API_CALL
  99. (*clCreateProgramWithBinary)(cl_context /* context */,
  100. cl_uint /* num_devices */,
  101. const cl_device_id * /* device_list */,
  102. const size_t * /* lengths */,
  103. const unsigned char ** /* binaries */,
  104. cl_int * /* binary_status */,
  105. cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
  106. extern
  107. CL_API_ENTRY cl_int CL_API_CALL
  108. (*clReleaseProgram)(cl_program /* program */) CL_API_SUFFIX__VERSION_1_0;
  109. extern
  110. CL_API_ENTRY cl_int CL_API_CALL
  111. (*clBuildProgram)(cl_program /* program */,
  112. cl_uint /* num_devices */,
  113. const cl_device_id * /* device_list */,
  114. const char * /* options */,
  115. void (CL_CALLBACK * /* pfn_notify */)(cl_program /* program */, void * /* user_data */),
  116. void * /* user_data */) CL_API_SUFFIX__VERSION_1_0;
  117. extern
  118. CL_API_ENTRY cl_int CL_API_CALL
  119. (*clGetProgramInfo)(cl_program /* program */,
  120. cl_program_info /* param_name */,
  121. size_t /* param_value_size */,
  122. void * /* param_value */,
  123. size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
  124. extern
  125. CL_API_ENTRY cl_int CL_API_CALL
  126. (*clGetProgramBuildInfo)(cl_program /* program */,
  127. cl_device_id /* device */,
  128. cl_program_build_info /* param_name */,
  129. size_t /* param_value_size */,
  130. void * /* param_value */,
  131. size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
  132. /* Kernel Object APIs */
  133. extern
  134. CL_API_ENTRY cl_kernel CL_API_CALL
  135. (*clCreateKernel)(cl_program /* program */,
  136. const char * /* kernel_name */,
  137. cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
  138. extern
  139. CL_API_ENTRY cl_int CL_API_CALL
  140. (*clReleaseKernel)(cl_kernel /* kernel */) CL_API_SUFFIX__VERSION_1_0;
  141. extern
  142. CL_API_ENTRY cl_int CL_API_CALL
  143. (*clSetKernelArg)(cl_kernel /* kernel */,
  144. cl_uint /* arg_index */,
  145. size_t /* arg_size */,
  146. const void * /* arg_value */) CL_API_SUFFIX__VERSION_1_0;
  147. /* Flush and Finish APIs */
  148. extern
  149. CL_API_ENTRY cl_int CL_API_CALL
  150. (*clFinish)(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0;
  151. /* Enqueued Commands APIs */
  152. extern
  153. CL_API_ENTRY cl_int CL_API_CALL
  154. (*clEnqueueReadBuffer)(cl_command_queue /* command_queue */,
  155. cl_mem /* buffer */,
  156. cl_bool /* blocking_read */,
  157. size_t /* offset */,
  158. size_t /* size */,
  159. void * /* ptr */,
  160. cl_uint /* num_events_in_wait_list */,
  161. const cl_event * /* event_wait_list */,
  162. cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0;
  163. extern
  164. CL_API_ENTRY cl_int CL_API_CALL
  165. (*clEnqueueWriteBuffer)(cl_command_queue /* command_queue */,
  166. cl_mem /* buffer */,
  167. cl_bool /* blocking_write */,
  168. size_t /* offset */,
  169. size_t /* size */,
  170. const void * /* ptr */,
  171. cl_uint /* num_events_in_wait_list */,
  172. const cl_event * /* event_wait_list */,
  173. cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0;
  174. extern
  175. CL_API_ENTRY cl_int CL_API_CALL
  176. (*clEnqueueNDRangeKernel)(cl_command_queue /* command_queue */,
  177. cl_kernel /* kernel */,
  178. cl_uint /* work_dim */,
  179. const size_t * /* global_work_offset */,
  180. const size_t * /* global_work_size */,
  181. const size_t * /* local_work_size */,
  182. cl_uint /* num_events_in_wait_list */,
  183. const cl_event * /* event_wait_list */,
  184. cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0;
  185. int opt_platform_id = -1;
  186. char *file_contents(const char *filename, int *length)
  187. {
  188. char *fullpath = alloca(PATH_MAX);
  189. void *buffer;
  190. FILE *f;
  191. strcpy(fullpath, opt_kernel_path);
  192. strcat(fullpath, filename);
  193. /* Try in the optional kernel path or installed prefix first */
  194. f = fopen(fullpath, "rb");
  195. if (!f) {
  196. /* Then try from the path BFGMiner was called */
  197. strcpy(fullpath, cgminer_path);
  198. strcat(fullpath, filename);
  199. f = fopen(fullpath, "rb");
  200. }
  201. /* Finally try opening it directly */
  202. if (!f)
  203. f = fopen(filename, "rb");
  204. if (!f) {
  205. applog(LOG_ERR, "Unable to open %s or %s for reading", filename, fullpath);
  206. return NULL;
  207. }
  208. fseek(f, 0, SEEK_END);
  209. *length = ftell(f);
  210. fseek(f, 0, SEEK_SET);
  211. buffer = malloc(*length+1);
  212. *length = fread(buffer, 1, *length, f);
  213. fclose(f);
  214. ((char*)buffer)[*length] = '\0';
  215. return (char*)buffer;
  216. }
  217. int clDevicesNum(void) {
  218. cl_int status;
  219. char pbuff[256];
  220. cl_uint numDevices;
  221. cl_uint numPlatforms;
  222. cl_platform_id *platforms;
  223. cl_platform_id platform = NULL;
  224. unsigned int most_devices = 0, i, mdplatform = 0;
  225. status = clGetPlatformIDs(0, NULL, &numPlatforms);
  226. /* If this fails, assume no GPUs. */
  227. if (status != CL_SUCCESS) {
  228. applog(LOG_ERR, "Error %d: clGetPlatformsIDs failed (no OpenCL SDK installed?)", status);
  229. return -1;
  230. }
  231. if (numPlatforms == 0) {
  232. applog(LOG_ERR, "clGetPlatformsIDs returned no platforms (no OpenCL SDK installed?)");
  233. return -1;
  234. }
  235. platforms = (cl_platform_id *)alloca(numPlatforms*sizeof(cl_platform_id));
  236. status = clGetPlatformIDs(numPlatforms, platforms, NULL);
  237. if (status != CL_SUCCESS) {
  238. applog(LOG_ERR, "Error %d: Getting Platform Ids. (clGetPlatformsIDs)", status);
  239. return -1;
  240. }
  241. for (i = 0; i < numPlatforms; i++) {
  242. status = clGetPlatformInfo( platforms[i], CL_PLATFORM_VENDOR, sizeof(pbuff), pbuff, NULL);
  243. if (status != CL_SUCCESS) {
  244. applog(LOG_ERR, "Error %d: Getting Platform Info. (clGetPlatformInfo)", status);
  245. return -1;
  246. }
  247. platform = platforms[i];
  248. applog(LOG_INFO, "CL Platform %d vendor: %s", i, pbuff);
  249. status = clGetPlatformInfo(platform, CL_PLATFORM_NAME, sizeof(pbuff), pbuff, NULL);
  250. if (status == CL_SUCCESS)
  251. applog(LOG_INFO, "CL Platform %d name: %s", i, pbuff);
  252. status = clGetPlatformInfo(platform, CL_PLATFORM_VERSION, sizeof(pbuff), pbuff, NULL);
  253. if (status == CL_SUCCESS)
  254. applog(LOG_INFO, "CL Platform %d version: %s", i, pbuff);
  255. status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, &numDevices);
  256. if (status != CL_SUCCESS) {
  257. applog(LOG_ERR, "Error %d: Getting Device IDs (num)", status);
  258. if ((int)i != opt_platform_id)
  259. continue;
  260. return -1;
  261. }
  262. applog(LOG_INFO, "Platform %d devices: %d", i, numDevices);
  263. if (numDevices > most_devices) {
  264. most_devices = numDevices;
  265. mdplatform = i;
  266. }
  267. if (numDevices) {
  268. unsigned int j;
  269. char pbuff[256];
  270. cl_device_id *devices = (cl_device_id *)malloc(numDevices*sizeof(cl_device_id));
  271. clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, numDevices, devices, NULL);
  272. for (j = 0; j < numDevices; j++) {
  273. clGetDeviceInfo(devices[j], CL_DEVICE_NAME, sizeof(pbuff), pbuff, NULL);
  274. applog(LOG_INFO, "\t%i\t%s", j, pbuff);
  275. }
  276. free(devices);
  277. }
  278. }
  279. if (opt_platform_id < 0)
  280. opt_platform_id = mdplatform;;
  281. return most_devices;
  282. }
  283. static int advance(char **area, unsigned *remaining, const char *marker)
  284. {
  285. char *find = memmem(*area, *remaining, marker, strlen(marker));
  286. if (!find) {
  287. applog(LOG_DEBUG, "Marker \"%s\" not found", marker);
  288. return 0;
  289. }
  290. *remaining -= find - *area;
  291. *area = find;
  292. return 1;
  293. }
  294. #define OP3_INST_BFE_UINT 4ULL
  295. #define OP3_INST_BFE_INT 5ULL
  296. #define OP3_INST_BFI_INT 6ULL
  297. #define OP3_INST_BIT_ALIGN_INT 12ULL
  298. #define OP3_INST_BYTE_ALIGN_INT 13ULL
  299. void patch_opcodes(char *w, unsigned remaining)
  300. {
  301. uint64_t *opcode = (uint64_t *)w;
  302. int patched = 0;
  303. int count_bfe_int = 0;
  304. int count_bfe_uint = 0;
  305. int count_byte_align = 0;
  306. while (42) {
  307. int clamp = (*opcode >> (32 + 31)) & 0x1;
  308. int dest_rel = (*opcode >> (32 + 28)) & 0x1;
  309. int alu_inst = (*opcode >> (32 + 13)) & 0x1f;
  310. int s2_neg = (*opcode >> (32 + 12)) & 0x1;
  311. int s2_rel = (*opcode >> (32 + 9)) & 0x1;
  312. int pred_sel = (*opcode >> 29) & 0x3;
  313. if (!clamp && !dest_rel && !s2_neg && !s2_rel && !pred_sel) {
  314. if (alu_inst == OP3_INST_BFE_INT) {
  315. count_bfe_int++;
  316. } else if (alu_inst == OP3_INST_BFE_UINT) {
  317. count_bfe_uint++;
  318. } else if (alu_inst == OP3_INST_BYTE_ALIGN_INT) {
  319. count_byte_align++;
  320. // patch this instruction to BFI_INT
  321. *opcode &= 0xfffc1fffffffffffULL;
  322. *opcode |= OP3_INST_BFI_INT << (32 + 13);
  323. patched++;
  324. }
  325. }
  326. if (remaining <= 8)
  327. break;
  328. opcode++;
  329. remaining -= 8;
  330. }
  331. applog(LOG_DEBUG, "Potential OP3 instructions identified: "
  332. "%i BFE_INT, %i BFE_UINT, %i BYTE_ALIGN",
  333. count_bfe_int, count_bfe_uint, count_byte_align);
  334. applog(LOG_DEBUG, "Patched a total of %i BFI_INT instructions", patched);
  335. }
  336. _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
  337. {
  338. _clState *clState = calloc(1, sizeof(_clState));
  339. bool patchbfi = false, prog_built = false;
  340. struct cgpu_info *cgpu = &gpus[gpu];
  341. cl_platform_id platform = NULL;
  342. char pbuff[256], vbuff[255];
  343. cl_platform_id* platforms;
  344. cl_uint preferred_vwidth;
  345. cl_device_id *devices;
  346. cl_uint numPlatforms;
  347. cl_uint numDevices;
  348. cl_int status;
  349. status = clGetPlatformIDs(0, NULL, &numPlatforms);
  350. if (status != CL_SUCCESS) {
  351. applog(LOG_ERR, "Error %d: Getting Platforms. (clGetPlatformsIDs)", status);
  352. return NULL;
  353. }
  354. platforms = (cl_platform_id *)alloca(numPlatforms*sizeof(cl_platform_id));
  355. status = clGetPlatformIDs(numPlatforms, platforms, NULL);
  356. if (status != CL_SUCCESS) {
  357. applog(LOG_ERR, "Error %d: Getting Platform Ids. (clGetPlatformsIDs)", status);
  358. return NULL;
  359. }
  360. if (opt_platform_id >= (int)numPlatforms) {
  361. applog(LOG_ERR, "Specified platform that does not exist");
  362. return NULL;
  363. }
  364. status = clGetPlatformInfo(platforms[opt_platform_id], CL_PLATFORM_VENDOR, sizeof(pbuff), pbuff, NULL);
  365. if (status != CL_SUCCESS) {
  366. applog(LOG_ERR, "Error %d: Getting Platform Info. (clGetPlatformInfo)", status);
  367. return NULL;
  368. }
  369. platform = platforms[opt_platform_id];
  370. if (platform == NULL) {
  371. perror("NULL platform found!\n");
  372. return NULL;
  373. }
  374. applog(LOG_INFO, "CL Platform vendor: %s", pbuff);
  375. status = clGetPlatformInfo(platform, CL_PLATFORM_NAME, sizeof(pbuff), pbuff, NULL);
  376. if (status == CL_SUCCESS)
  377. applog(LOG_INFO, "CL Platform name: %s", pbuff);
  378. status = clGetPlatformInfo(platform, CL_PLATFORM_VERSION, sizeof(vbuff), vbuff, NULL);
  379. if (status == CL_SUCCESS)
  380. applog(LOG_INFO, "CL Platform version: %s", vbuff);
  381. status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, &numDevices);
  382. if (status != CL_SUCCESS) {
  383. applog(LOG_ERR, "Error %d: Getting Device IDs (num)", status);
  384. return NULL;
  385. }
  386. if (numDevices > 0 ) {
  387. devices = (cl_device_id *)malloc(numDevices*sizeof(cl_device_id));
  388. /* Now, get the device list data */
  389. status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, numDevices, devices, NULL);
  390. if (status != CL_SUCCESS) {
  391. applog(LOG_ERR, "Error %d: Getting Device IDs (list)", status);
  392. return NULL;
  393. }
  394. applog(LOG_INFO, "List of devices:");
  395. unsigned int i;
  396. for (i = 0; i < numDevices; i++) {
  397. status = clGetDeviceInfo(devices[i], CL_DEVICE_NAME, sizeof(pbuff), pbuff, NULL);
  398. if (status != CL_SUCCESS) {
  399. applog(LOG_ERR, "Error %d: Getting Device Info", status);
  400. return NULL;
  401. }
  402. applog(LOG_INFO, "\t%i\t%s", i, pbuff);
  403. }
  404. if (gpu < numDevices) {
  405. status = clGetDeviceInfo(devices[gpu], CL_DEVICE_NAME, sizeof(pbuff), pbuff, NULL);
  406. if (status != CL_SUCCESS) {
  407. applog(LOG_ERR, "Error %d: Getting Device Info", status);
  408. return NULL;
  409. }
  410. applog(LOG_INFO, "Selected %i: %s", gpu, pbuff);
  411. strncpy(name, pbuff, nameSize);
  412. } else {
  413. applog(LOG_ERR, "Invalid GPU %i", gpu);
  414. return NULL;
  415. }
  416. } else return NULL;
  417. cl_context_properties cps[3] = { CL_CONTEXT_PLATFORM, (cl_context_properties)platform, 0 };
  418. clState->context = clCreateContextFromType(cps, CL_DEVICE_TYPE_GPU, NULL, NULL, &status);
  419. if (status != CL_SUCCESS) {
  420. applog(LOG_ERR, "Error %d: Creating Context. (clCreateContextFromType)", status);
  421. return NULL;
  422. }
  423. /////////////////////////////////////////////////////////////////
  424. // Create an OpenCL command queue
  425. /////////////////////////////////////////////////////////////////
  426. clState->commandQueue = clCreateCommandQueue(clState->context, devices[gpu],
  427. CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, &status);
  428. if (status != CL_SUCCESS) /* Try again without OOE enable */
  429. clState->commandQueue = clCreateCommandQueue(clState->context, devices[gpu], 0 , &status);
  430. if (status != CL_SUCCESS) {
  431. applog(LOG_ERR, "Error %d: Creating Command Queue. (clCreateCommandQueue)", status);
  432. return NULL;
  433. }
  434. /* Check for BFI INT support. Hopefully people don't mix devices with
  435. * and without it! */
  436. char * extensions = malloc(1024);
  437. const char * camo = "cl_amd_media_ops";
  438. char *find;
  439. status = clGetDeviceInfo(devices[gpu], CL_DEVICE_EXTENSIONS, 1024, (void *)extensions, NULL);
  440. if (status != CL_SUCCESS) {
  441. applog(LOG_ERR, "Error %d: Failed to clGetDeviceInfo when trying to get CL_DEVICE_EXTENSIONS", status);
  442. return NULL;
  443. }
  444. find = strstr(extensions, camo);
  445. if (find)
  446. clState->hasBitAlign = true;
  447. /* Check for OpenCL >= 1.0 support, needed for global offset parameter usage. */
  448. char * devoclver = malloc(1024);
  449. const char * ocl10 = "OpenCL 1.0";
  450. status = clGetDeviceInfo(devices[gpu], CL_DEVICE_VERSION, 1024, (void *)devoclver, NULL);
  451. if (status != CL_SUCCESS) {
  452. applog(LOG_ERR, "Error %d: Failed to clGetDeviceInfo when trying to get CL_DEVICE_VERSION", status);
  453. return NULL;
  454. }
  455. find = strstr(devoclver, ocl10);
  456. if (!find)
  457. clState->hasOpenCL11plus = true;
  458. status = clGetDeviceInfo(devices[gpu], CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, sizeof(cl_uint), (void *)&preferred_vwidth, NULL);
  459. if (status != CL_SUCCESS) {
  460. applog(LOG_ERR, "Error %d: Failed to clGetDeviceInfo when trying to get CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT", status);
  461. return NULL;
  462. }
  463. applog(LOG_DEBUG, "Preferred vector width reported %d", preferred_vwidth);
  464. status = clGetDeviceInfo(devices[gpu], CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(size_t), (void *)&clState->max_work_size, NULL);
  465. if (status != CL_SUCCESS) {
  466. applog(LOG_ERR, "Error %d: Failed to clGetDeviceInfo when trying to get CL_DEVICE_MAX_WORK_GROUP_SIZE", status);
  467. return NULL;
  468. }
  469. applog(LOG_DEBUG, "Max work group size reported %"PRId64, (int64_t)clState->max_work_size);
  470. status = clGetDeviceInfo(devices[gpu], CL_DEVICE_MAX_MEM_ALLOC_SIZE , sizeof(cl_ulong), (void *)&cgpu->max_alloc, NULL);
  471. if (status != CL_SUCCESS) {
  472. applog(LOG_ERR, "Error %d: Failed to clGetDeviceInfo when trying to get CL_DEVICE_MAX_MEM_ALLOC_SIZE", status);
  473. return NULL;
  474. }
  475. applog(LOG_DEBUG, "Max mem alloc size is %lu", (unsigned long)cgpu->max_alloc);
  476. /* Create binary filename based on parameters passed to opencl
  477. * compiler to ensure we only load a binary that matches what would
  478. * have otherwise created. The filename is:
  479. * name + kernelname +/- g(offset) + v + vectors + w + work_size + l + sizeof(long) + .bin
  480. * For scrypt the filename is:
  481. * name + kernelname + g + lg + lookup_gap + tc + thread_concurrency + w + work_size + l + sizeof(long) + .bin
  482. */
  483. char binaryfilename[255];
  484. char filename[255];
  485. char numbuf[32];
  486. if (cgpu->kernel == KL_NONE) {
  487. if (opt_scrypt) {
  488. applog(LOG_INFO, "Selecting scrypt kernel");
  489. clState->chosen_kernel = KL_SCRYPT;
  490. } else if (!strstr(name, "Tahiti") &&
  491. /* Detect all 2.6 SDKs not with Tahiti and use diablo kernel */
  492. (strstr(vbuff, "844.4") || // Linux 64 bit ATI 2.6 SDK
  493. strstr(vbuff, "851.4") || // Windows 64 bit ""
  494. strstr(vbuff, "831.4") ||
  495. strstr(vbuff, "898.1") || // 12.2 driver SDK
  496. strstr(vbuff, "923.1") || // 12.4
  497. strstr(vbuff, "938.2"))) { // SDK 2.7
  498. applog(LOG_INFO, "Selecting diablo kernel");
  499. clState->chosen_kernel = KL_DIABLO;
  500. /* Detect all 7970s, older ATI and NVIDIA and use poclbm */
  501. } else if (strstr(name, "Tahiti") || !clState->hasBitAlign) {
  502. applog(LOG_INFO, "Selecting poclbm kernel");
  503. clState->chosen_kernel = KL_POCLBM;
  504. /* Use phatk for the rest R5xxx R6xxx */
  505. } else {
  506. applog(LOG_INFO, "Selecting phatk kernel");
  507. clState->chosen_kernel = KL_PHATK;
  508. }
  509. cgpu->kernel = clState->chosen_kernel;
  510. } else {
  511. clState->chosen_kernel = cgpu->kernel;
  512. if (clState->chosen_kernel == KL_PHATK &&
  513. (strstr(vbuff, "844.4") || strstr(vbuff, "851.4") ||
  514. strstr(vbuff, "831.4") || strstr(vbuff, "898.1") ||
  515. strstr(vbuff, "923.1") || strstr(vbuff, "938.2"))) {
  516. applog(LOG_WARNING, "WARNING: You have selected the phatk kernel.");
  517. applog(LOG_WARNING, "You are running SDK 2.6+ which performs poorly with this kernel.");
  518. applog(LOG_WARNING, "Downgrade your SDK and delete any .bin files before starting again.");
  519. applog(LOG_WARNING, "Or allow BFGMiner to automatically choose a more suitable kernel.");
  520. }
  521. }
  522. /* For some reason 2 vectors is still better even if the card says
  523. * otherwise, and many cards lie about their max so use 256 as max
  524. * unless explicitly set on the command line. Tahiti prefers 1 */
  525. if (strstr(name, "Tahiti"))
  526. preferred_vwidth = 1;
  527. else if (preferred_vwidth > 2)
  528. preferred_vwidth = 2;
  529. switch (clState->chosen_kernel) {
  530. case KL_POCLBM:
  531. strcpy(filename, POCLBM_KERNNAME".cl");
  532. strcpy(binaryfilename, POCLBM_KERNNAME);
  533. break;
  534. case KL_PHATK:
  535. strcpy(filename, PHATK_KERNNAME".cl");
  536. strcpy(binaryfilename, PHATK_KERNNAME);
  537. break;
  538. case KL_DIAKGCN:
  539. strcpy(filename, DIAKGCN_KERNNAME".cl");
  540. strcpy(binaryfilename, DIAKGCN_KERNNAME);
  541. break;
  542. case KL_SCRYPT:
  543. strcpy(filename, SCRYPT_KERNNAME".cl");
  544. strcpy(binaryfilename, SCRYPT_KERNNAME);
  545. /* Scrypt only supports vector 1 */
  546. cgpu->vwidth = 1;
  547. break;
  548. case KL_NONE: /* Shouldn't happen */
  549. case KL_DIABLO:
  550. strcpy(filename, DIABLO_KERNNAME".cl");
  551. strcpy(binaryfilename, DIABLO_KERNNAME);
  552. break;
  553. }
  554. if (cgpu->vwidth)
  555. clState->vwidth = cgpu->vwidth;
  556. else {
  557. clState->vwidth = preferred_vwidth;
  558. cgpu->vwidth = preferred_vwidth;
  559. }
  560. if (((clState->chosen_kernel == KL_POCLBM || clState->chosen_kernel == KL_DIABLO || clState->chosen_kernel == KL_DIAKGCN) &&
  561. clState->vwidth == 1 && clState->hasOpenCL11plus) || opt_scrypt)
  562. clState->goffset = true;
  563. if (cgpu->work_size && cgpu->work_size <= clState->max_work_size)
  564. clState->wsize = cgpu->work_size;
  565. else if (strstr(name, "Tahiti"))
  566. clState->wsize = 64;
  567. else
  568. clState->wsize = (clState->max_work_size <= 256 ? clState->max_work_size : 256) / clState->vwidth;
  569. cgpu->work_size = clState->wsize;
  570. #ifdef USE_SCRYPT
  571. if (opt_scrypt) {
  572. cl_ulong ma = cgpu->max_alloc, mt;
  573. if (!cgpu->opt_lg) {
  574. applog(LOG_DEBUG, "GPU %d: selecting lookup gap of 2", gpu);
  575. cgpu->lookup_gap = 2;
  576. } else
  577. cgpu->lookup_gap = cgpu->opt_lg;
  578. if (!cgpu->opt_tc) {
  579. cgpu->thread_concurrency = ma / 32768 / cgpu->lookup_gap;
  580. if (cgpu->shaders && cgpu->thread_concurrency > cgpu->shaders) {
  581. cgpu->thread_concurrency -= cgpu->thread_concurrency % cgpu->shaders;
  582. if (cgpu->thread_concurrency > cgpu->shaders * 5)
  583. cgpu->thread_concurrency = cgpu->shaders * 5;
  584. }
  585. applog(LOG_DEBUG, "GPU %u: selecting thread concurrency of %lu", gpu, (unsigned long)cgpu->thread_concurrency);
  586. } else
  587. cgpu->thread_concurrency = cgpu->opt_tc;
  588. /* If we have memory to spare, try to find a power of 2 value
  589. * >= required amount to map nicely to an intensity */
  590. mt = cgpu->thread_concurrency * 32768 * cgpu->lookup_gap;
  591. if (ma > mt) {
  592. ma = 1;
  593. while (ma < mt)
  594. ma <<= 1;
  595. if (ma < cgpu->max_alloc) {
  596. cgpu->max_alloc = ma;
  597. applog(LOG_DEBUG, "Max alloc decreased to %lu", (unsigned long)cgpu->max_alloc);
  598. }
  599. }
  600. }
  601. #endif
  602. FILE *binaryfile;
  603. size_t *binary_sizes;
  604. char **binaries;
  605. int pl;
  606. char *source = file_contents(filename, &pl);
  607. size_t sourceSize[] = {(size_t)pl};
  608. cl_uint slot, cpnd;
  609. slot = cpnd = 0;
  610. if (!source)
  611. return NULL;
  612. binary_sizes = calloc(sizeof(size_t) * MAX_GPUDEVICES * 4, 1);
  613. if (unlikely(!binary_sizes)) {
  614. applog(LOG_ERR, "Unable to calloc binary_sizes");
  615. return NULL;
  616. }
  617. binaries = calloc(sizeof(char *) * MAX_GPUDEVICES * 4, 1);
  618. if (unlikely(!binaries)) {
  619. applog(LOG_ERR, "Unable to calloc binaries");
  620. return NULL;
  621. }
  622. strcat(binaryfilename, name);
  623. if (clState->goffset)
  624. strcat(binaryfilename, "g");
  625. if (opt_scrypt) {
  626. #ifdef USE_SCRYPT
  627. sprintf(numbuf, "lg%utc%u", cgpu->lookup_gap, (unsigned int)cgpu->thread_concurrency);
  628. strcat(binaryfilename, numbuf);
  629. #endif
  630. } else {
  631. sprintf(numbuf, "v%d", clState->vwidth);
  632. strcat(binaryfilename, numbuf);
  633. }
  634. sprintf(numbuf, "w%d", (int)clState->wsize);
  635. strcat(binaryfilename, numbuf);
  636. sprintf(numbuf, "l%d", (int)sizeof(long));
  637. strcat(binaryfilename, numbuf);
  638. strcat(binaryfilename, ".bin");
  639. binaryfile = fopen(binaryfilename, "rb");
  640. if (!binaryfile) {
  641. applog(LOG_DEBUG, "No binary found, generating from source");
  642. } else {
  643. struct stat binary_stat;
  644. if (unlikely(stat(binaryfilename, &binary_stat))) {
  645. applog(LOG_DEBUG, "Unable to stat binary, generating from source");
  646. fclose(binaryfile);
  647. goto build;
  648. }
  649. if (!binary_stat.st_size)
  650. goto build;
  651. binary_sizes[slot] = binary_stat.st_size;
  652. binaries[slot] = (char *)calloc(binary_sizes[slot], 1);
  653. if (unlikely(!binaries[slot])) {
  654. applog(LOG_ERR, "Unable to calloc binaries");
  655. fclose(binaryfile);
  656. return NULL;
  657. }
  658. if (fread(binaries[slot], 1, binary_sizes[slot], binaryfile) != binary_sizes[slot]) {
  659. applog(LOG_ERR, "Unable to fread binaries");
  660. fclose(binaryfile);
  661. free(binaries[slot]);
  662. goto build;
  663. }
  664. clState->program = clCreateProgramWithBinary(clState->context, 1, &devices[gpu], &binary_sizes[slot], (const unsigned char **)binaries, &status, NULL);
  665. if (status != CL_SUCCESS) {
  666. applog(LOG_ERR, "Error %d: Loading Binary into cl_program (clCreateProgramWithBinary)", status);
  667. fclose(binaryfile);
  668. free(binaries[slot]);
  669. goto build;
  670. }
  671. fclose(binaryfile);
  672. applog(LOG_DEBUG, "Loaded binary image %s", binaryfilename);
  673. goto built;
  674. }
  675. /////////////////////////////////////////////////////////////////
  676. // Load CL file, build CL program object, create CL kernel object
  677. /////////////////////////////////////////////////////////////////
  678. build:
  679. clState->program = clCreateProgramWithSource(clState->context, 1, (const char **)&source, sourceSize, &status);
  680. if (status != CL_SUCCESS) {
  681. applog(LOG_ERR, "Error %d: Loading Binary into cl_program (clCreateProgramWithSource)", status);
  682. return NULL;
  683. }
  684. /* create a cl program executable for all the devices specified */
  685. char *CompilerOptions = calloc(1, 256);
  686. #ifdef USE_SCRYPT
  687. if (opt_scrypt)
  688. sprintf(CompilerOptions, "-D LOOKUP_GAP=%d -D CONCURRENT_THREADS=%d -D WORKSIZE=%d",
  689. cgpu->lookup_gap, (unsigned int)cgpu->thread_concurrency, (int)clState->wsize);
  690. else
  691. #endif
  692. {
  693. sprintf(CompilerOptions, "-D WORKSIZE=%d -D VECTORS%d -D WORKVEC=%d",
  694. (int)clState->wsize, clState->vwidth, (int)clState->wsize * clState->vwidth);
  695. }
  696. applog(LOG_DEBUG, "Setting worksize to %"PRId64, (int64_t)clState->wsize);
  697. if (clState->vwidth > 1)
  698. applog(LOG_DEBUG, "Patched source to suit %d vectors", clState->vwidth);
  699. if (clState->hasBitAlign) {
  700. strcat(CompilerOptions, " -D BITALIGN");
  701. applog(LOG_DEBUG, "cl_amd_media_ops found, setting BITALIGN");
  702. if (strstr(name, "Cedar") ||
  703. strstr(name, "Redwood") ||
  704. strstr(name, "Juniper") ||
  705. strstr(name, "Cypress" ) ||
  706. strstr(name, "Hemlock" ) ||
  707. strstr(name, "Caicos" ) ||
  708. strstr(name, "Turks" ) ||
  709. strstr(name, "Barts" ) ||
  710. strstr(name, "Cayman" ) ||
  711. strstr(name, "Antilles" ) ||
  712. strstr(name, "Wrestler" ) ||
  713. strstr(name, "Zacate" ) ||
  714. strstr(name, "WinterPark" ) ||
  715. strstr(name, "BeaverCreek" ))
  716. patchbfi = true;
  717. } else
  718. applog(LOG_DEBUG, "cl_amd_media_ops not found, will not set BITALIGN");
  719. if (patchbfi) {
  720. strcat(CompilerOptions, " -D BFI_INT");
  721. applog(LOG_DEBUG, "BFI_INT patch requiring device found, patched source with BFI_INT");
  722. } else
  723. applog(LOG_DEBUG, "BFI_INT patch requiring device not found, will not BFI_INT patch");
  724. if (clState->goffset)
  725. strcat(CompilerOptions, " -D GOFFSET");
  726. if (!clState->hasOpenCL11plus)
  727. strcat(CompilerOptions, " -D OCL1");
  728. applog(LOG_DEBUG, "CompilerOptions: %s", CompilerOptions);
  729. status = clBuildProgram(clState->program, 1, &devices[gpu], CompilerOptions , NULL, NULL);
  730. free(CompilerOptions);
  731. if (status != CL_SUCCESS) {
  732. applog(LOG_ERR, "Error %d: Building Program (clBuildProgram)", status);
  733. size_t logSize;
  734. status = clGetProgramBuildInfo(clState->program, devices[gpu], CL_PROGRAM_BUILD_LOG, 0, NULL, &logSize);
  735. char *log = malloc(logSize);
  736. status = clGetProgramBuildInfo(clState->program, devices[gpu], CL_PROGRAM_BUILD_LOG, logSize, log, NULL);
  737. applog(LOG_ERR, "%s", log);
  738. return NULL;
  739. }
  740. prog_built = true;
  741. status = clGetProgramInfo(clState->program, CL_PROGRAM_NUM_DEVICES, sizeof(cl_uint), &cpnd, NULL);
  742. if (unlikely(status != CL_SUCCESS)) {
  743. applog(LOG_ERR, "Error %d: Getting program info CL_PROGRAM_NUM_DEVICES. (clGetProgramInfo)", status);
  744. return NULL;
  745. }
  746. status = clGetProgramInfo(clState->program, CL_PROGRAM_BINARY_SIZES, sizeof(size_t)*cpnd, binary_sizes, NULL);
  747. if (unlikely(status != CL_SUCCESS)) {
  748. applog(LOG_ERR, "Error %d: Getting program info CL_PROGRAM_BINARY_SIZES. (clGetProgramInfo)", status);
  749. return NULL;
  750. }
  751. /* The actual compiled binary ends up in a RANDOM slot! Grr, so we have
  752. * to iterate over all the binary slots and find where the real program
  753. * is. What the heck is this!? */
  754. for (slot = 0; slot < cpnd; slot++)
  755. if (binary_sizes[slot])
  756. break;
  757. /* copy over all of the generated binaries. */
  758. applog(LOG_DEBUG, "Binary size for gpu %u found in binary slot %u: %"PRId64,
  759. gpu, (unsigned)slot, (int64_t)binary_sizes[slot]);
  760. if (!binary_sizes[slot]) {
  761. applog(LOG_ERR, "OpenCL compiler generated a zero sized binary, FAIL!");
  762. return NULL;
  763. }
  764. binaries[slot] = calloc(sizeof(char) * binary_sizes[slot], 1);
  765. status = clGetProgramInfo(clState->program, CL_PROGRAM_BINARIES, sizeof(char *) * cpnd, binaries, NULL );
  766. if (unlikely(status != CL_SUCCESS)) {
  767. applog(LOG_ERR, "Error %d: Getting program info. CL_PROGRAM_BINARIES (clGetProgramInfo)", status);
  768. return NULL;
  769. }
  770. /* Patch the kernel if the hardware supports BFI_INT but it needs to
  771. * be hacked in */
  772. if (patchbfi) {
  773. unsigned remaining = binary_sizes[slot];
  774. char *w = binaries[slot];
  775. unsigned int start, length;
  776. /* Find 2nd incidence of .text, and copy the program's
  777. * position and length at a fixed offset from that. Then go
  778. * back and find the 2nd incidence of \x7ELF (rewind by one
  779. * from ELF) and then patch the opcocdes */
  780. if (!advance(&w, &remaining, ".text"))
  781. goto build;
  782. w++; remaining--;
  783. if (!advance(&w, &remaining, ".text")) {
  784. /* 32 bit builds only one ELF */
  785. w--; remaining++;
  786. }
  787. memcpy(&start, w + 285, 4);
  788. memcpy(&length, w + 289, 4);
  789. w = binaries[slot]; remaining = binary_sizes[slot];
  790. if (!advance(&w, &remaining, "ELF"))
  791. goto build;
  792. w++; remaining--;
  793. if (!advance(&w, &remaining, "ELF")) {
  794. /* 32 bit builds only one ELF */
  795. w--; remaining++;
  796. }
  797. w--; remaining++;
  798. w += start; remaining -= start;
  799. applog(LOG_DEBUG, "At %p (%u rem. bytes), to begin patching",
  800. w, remaining);
  801. patch_opcodes(w, length);
  802. status = clReleaseProgram(clState->program);
  803. if (status != CL_SUCCESS) {
  804. applog(LOG_ERR, "Error %d: Releasing program. (clReleaseProgram)", status);
  805. return NULL;
  806. }
  807. clState->program = clCreateProgramWithBinary(clState->context, 1, &devices[gpu], &binary_sizes[slot], (const unsigned char **)&binaries[slot], &status, NULL);
  808. if (status != CL_SUCCESS) {
  809. applog(LOG_ERR, "Error %d: Loading Binary into cl_program (clCreateProgramWithBinary)", status);
  810. return NULL;
  811. }
  812. /* Program needs to be rebuilt */
  813. prog_built = false;
  814. }
  815. free(source);
  816. /* Save the binary to be loaded next time */
  817. binaryfile = fopen(binaryfilename, "wb");
  818. if (!binaryfile) {
  819. /* Not a fatal problem, just means we build it again next time */
  820. applog(LOG_DEBUG, "Unable to create file %s", binaryfilename);
  821. } else {
  822. if (unlikely(fwrite(binaries[slot], 1, binary_sizes[slot], binaryfile) != binary_sizes[slot])) {
  823. applog(LOG_ERR, "Unable to fwrite to binaryfile");
  824. return NULL;
  825. }
  826. fclose(binaryfile);
  827. }
  828. built:
  829. if (binaries[slot])
  830. free(binaries[slot]);
  831. free(binaries);
  832. free(binary_sizes);
  833. applog(LOG_INFO, "Initialising kernel %s with%s bitalign, %"PRId64" vectors and worksize %"PRIu64,
  834. filename, clState->hasBitAlign ? "" : "out", (int64_t)clState->vwidth, (uint64_t)clState->wsize);
  835. if (!prog_built) {
  836. /* create a cl program executable for all the devices specified */
  837. status = clBuildProgram(clState->program, 1, &devices[gpu], NULL, NULL, NULL);
  838. if (status != CL_SUCCESS) {
  839. applog(LOG_ERR, "Error %d: Building Program (clBuildProgram)", status);
  840. size_t logSize;
  841. status = clGetProgramBuildInfo(clState->program, devices[gpu], CL_PROGRAM_BUILD_LOG, 0, NULL, &logSize);
  842. char *log = malloc(logSize);
  843. status = clGetProgramBuildInfo(clState->program, devices[gpu], CL_PROGRAM_BUILD_LOG, logSize, log, NULL);
  844. applog(LOG_ERR, "%s", log);
  845. return NULL;
  846. }
  847. }
  848. /* get a kernel object handle for a kernel with the given name */
  849. clState->kernel = clCreateKernel(clState->program, "search", &status);
  850. if (status != CL_SUCCESS) {
  851. applog(LOG_ERR, "Error %d: Creating Kernel from program. (clCreateKernel)", status);
  852. return NULL;
  853. }
  854. #ifdef USE_SCRYPT
  855. if (opt_scrypt) {
  856. size_t ipt = (1024 / cgpu->lookup_gap + (1024 % cgpu->lookup_gap > 0));
  857. size_t bufsize = 128 * ipt * cgpu->thread_concurrency;
  858. /* Use the max alloc value which has been rounded to a power of
  859. * 2 greater >= required amount earlier */
  860. if (bufsize > cgpu->max_alloc) {
  861. applog(LOG_WARNING, "Maximum buffer memory device %d supports says %lu", gpu, (unsigned long)cgpu->max_alloc);
  862. applog(LOG_WARNING, "Your scrypt settings come to %lu", (unsigned long)bufsize);
  863. } else
  864. bufsize = cgpu->max_alloc;
  865. applog(LOG_DEBUG, "Creating scrypt buffer sized %ld", (unsigned long)bufsize);
  866. clState->padbufsize = bufsize;
  867. /* This buffer is weird and might work to some degree even if
  868. * the create buffer call has apparently failed, so check if we
  869. * get anything back before we call it a failure. */
  870. clState->padbuffer8 = NULL;
  871. clState->padbuffer8 = clCreateBuffer(clState->context, CL_MEM_READ_WRITE, bufsize, NULL, &status);
  872. if (status != CL_SUCCESS && !clState->padbuffer8) {
  873. applog(LOG_ERR, "Error %d: clCreateBuffer (padbuffer8), decrease CT or increase LG", status);
  874. return NULL;
  875. }
  876. clState->CLbuffer0 = clCreateBuffer(clState->context, CL_MEM_READ_ONLY, 128, NULL, &status);
  877. if (status != CL_SUCCESS) {
  878. applog(LOG_ERR, "Error %d: clCreateBuffer (CLbuffer0)", status);
  879. return NULL;
  880. }
  881. }
  882. #endif
  883. clState->outputBuffer = clCreateBuffer(clState->context, CL_MEM_WRITE_ONLY, BUFFERSIZE, NULL, &status);
  884. if (status != CL_SUCCESS) {
  885. applog(LOG_ERR, "Error %d: clCreateBuffer (outputBuffer)", status);
  886. return NULL;
  887. }
  888. return clState;
  889. }
  890. #endif /* HAVE_OPENCL */