ocl.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032
  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. char *s;
  344. cl_platform_id* platforms;
  345. cl_uint preferred_vwidth;
  346. cl_device_id *devices;
  347. cl_uint numPlatforms;
  348. cl_uint numDevices;
  349. cl_int status;
  350. status = clGetPlatformIDs(0, NULL, &numPlatforms);
  351. if (status != CL_SUCCESS) {
  352. applog(LOG_ERR, "Error %d: Getting Platforms. (clGetPlatformsIDs)", status);
  353. return NULL;
  354. }
  355. platforms = (cl_platform_id *)alloca(numPlatforms*sizeof(cl_platform_id));
  356. status = clGetPlatformIDs(numPlatforms, platforms, NULL);
  357. if (status != CL_SUCCESS) {
  358. applog(LOG_ERR, "Error %d: Getting Platform Ids. (clGetPlatformsIDs)", status);
  359. return NULL;
  360. }
  361. if (opt_platform_id >= (int)numPlatforms) {
  362. applog(LOG_ERR, "Specified platform that does not exist");
  363. return NULL;
  364. }
  365. status = clGetPlatformInfo(platforms[opt_platform_id], CL_PLATFORM_VENDOR, sizeof(pbuff), pbuff, NULL);
  366. if (status != CL_SUCCESS) {
  367. applog(LOG_ERR, "Error %d: Getting Platform Info. (clGetPlatformInfo)", status);
  368. return NULL;
  369. }
  370. platform = platforms[opt_platform_id];
  371. if (platform == NULL) {
  372. perror("NULL platform found!\n");
  373. return NULL;
  374. }
  375. applog(LOG_INFO, "CL Platform vendor: %s", pbuff);
  376. status = clGetPlatformInfo(platform, CL_PLATFORM_NAME, sizeof(pbuff), pbuff, NULL);
  377. if (status == CL_SUCCESS)
  378. applog(LOG_INFO, "CL Platform name: %s", pbuff);
  379. status = clGetPlatformInfo(platform, CL_PLATFORM_VERSION, sizeof(vbuff), vbuff, NULL);
  380. if (status == CL_SUCCESS)
  381. applog(LOG_INFO, "CL Platform version: %s", vbuff);
  382. status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, &numDevices);
  383. if (status != CL_SUCCESS) {
  384. applog(LOG_ERR, "Error %d: Getting Device IDs (num)", status);
  385. return NULL;
  386. }
  387. if (numDevices > 0 ) {
  388. devices = (cl_device_id *)malloc(numDevices*sizeof(cl_device_id));
  389. /* Now, get the device list data */
  390. status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, numDevices, devices, NULL);
  391. if (status != CL_SUCCESS) {
  392. applog(LOG_ERR, "Error %d: Getting Device IDs (list)", status);
  393. return NULL;
  394. }
  395. applog(LOG_INFO, "List of devices:");
  396. unsigned int i;
  397. for (i = 0; i < numDevices; i++) {
  398. status = clGetDeviceInfo(devices[i], CL_DEVICE_NAME, sizeof(pbuff), pbuff, NULL);
  399. if (status != CL_SUCCESS) {
  400. applog(LOG_ERR, "Error %d: Getting Device Info", status);
  401. return NULL;
  402. }
  403. applog(LOG_INFO, "\t%i\t%s", i, pbuff);
  404. }
  405. if (gpu < numDevices) {
  406. status = clGetDeviceInfo(devices[gpu], CL_DEVICE_NAME, sizeof(pbuff), pbuff, NULL);
  407. if (status != CL_SUCCESS) {
  408. applog(LOG_ERR, "Error %d: Getting Device Info", status);
  409. return NULL;
  410. }
  411. applog(LOG_INFO, "Selected %i: %s", gpu, pbuff);
  412. strncpy(name, pbuff, nameSize);
  413. } else {
  414. applog(LOG_ERR, "Invalid GPU %i", gpu);
  415. return NULL;
  416. }
  417. } else return NULL;
  418. cl_context_properties cps[3] = { CL_CONTEXT_PLATFORM, (cl_context_properties)platform, 0 };
  419. clState->context = clCreateContextFromType(cps, CL_DEVICE_TYPE_GPU, NULL, NULL, &status);
  420. if (status != CL_SUCCESS) {
  421. applog(LOG_ERR, "Error %d: Creating Context. (clCreateContextFromType)", status);
  422. return NULL;
  423. }
  424. /////////////////////////////////////////////////////////////////
  425. // Create an OpenCL command queue
  426. /////////////////////////////////////////////////////////////////
  427. clState->commandQueue = clCreateCommandQueue(clState->context, devices[gpu],
  428. CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, &status);
  429. if (status != CL_SUCCESS) /* Try again without OOE enable */
  430. clState->commandQueue = clCreateCommandQueue(clState->context, devices[gpu], 0 , &status);
  431. if (status != CL_SUCCESS) {
  432. applog(LOG_ERR, "Error %d: Creating Command Queue. (clCreateCommandQueue)", status);
  433. return NULL;
  434. }
  435. /* Check for BFI INT support. Hopefully people don't mix devices with
  436. * and without it! */
  437. char * extensions = malloc(1024);
  438. const char * camo = "cl_amd_media_ops";
  439. char *find;
  440. status = clGetDeviceInfo(devices[gpu], CL_DEVICE_EXTENSIONS, 1024, (void *)extensions, NULL);
  441. if (status != CL_SUCCESS) {
  442. applog(LOG_ERR, "Error %d: Failed to clGetDeviceInfo when trying to get CL_DEVICE_EXTENSIONS", status);
  443. return NULL;
  444. }
  445. find = strstr(extensions, camo);
  446. if (find)
  447. clState->hasBitAlign = true;
  448. /* Check for OpenCL >= 1.0 support, needed for global offset parameter usage. */
  449. char * devoclver = malloc(1024);
  450. const char * ocl10 = "OpenCL 1.0";
  451. status = clGetDeviceInfo(devices[gpu], CL_DEVICE_VERSION, 1024, (void *)devoclver, NULL);
  452. if (status != CL_SUCCESS) {
  453. applog(LOG_ERR, "Error %d: Failed to clGetDeviceInfo when trying to get CL_DEVICE_VERSION", status);
  454. return NULL;
  455. }
  456. find = strstr(devoclver, ocl10);
  457. if (!find)
  458. clState->hasOpenCL11plus = true;
  459. status = clGetDeviceInfo(devices[gpu], CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, sizeof(cl_uint), (void *)&preferred_vwidth, NULL);
  460. if (status != CL_SUCCESS) {
  461. applog(LOG_ERR, "Error %d: Failed to clGetDeviceInfo when trying to get CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT", status);
  462. return NULL;
  463. }
  464. applog(LOG_DEBUG, "Preferred vector width reported %d", preferred_vwidth);
  465. status = clGetDeviceInfo(devices[gpu], CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(size_t), (void *)&clState->max_work_size, NULL);
  466. if (status != CL_SUCCESS) {
  467. applog(LOG_ERR, "Error %d: Failed to clGetDeviceInfo when trying to get CL_DEVICE_MAX_WORK_GROUP_SIZE", status);
  468. return NULL;
  469. }
  470. applog(LOG_DEBUG, "Max work group size reported %"PRId64, (int64_t)clState->max_work_size);
  471. status = clGetDeviceInfo(devices[gpu], CL_DEVICE_MAX_MEM_ALLOC_SIZE , sizeof(cl_ulong), (void *)&cgpu->max_alloc, NULL);
  472. if (status != CL_SUCCESS) {
  473. applog(LOG_ERR, "Error %d: Failed to clGetDeviceInfo when trying to get CL_DEVICE_MAX_MEM_ALLOC_SIZE", status);
  474. return NULL;
  475. }
  476. applog(LOG_DEBUG, "Max mem alloc size is %lu", (unsigned long)cgpu->max_alloc);
  477. /* Create binary filename based on parameters passed to opencl
  478. * compiler to ensure we only load a binary that matches what would
  479. * have otherwise created. The filename is:
  480. * kernelname + name +/- g(offset) + v + vectors + w + work_size + l + sizeof(long) + p + platform version + .bin
  481. * For scrypt the filename is:
  482. * kernelname + name + g + lg + lookup_gap + tc + thread_concurrency + w + work_size + l + sizeof(long) + p + platform version + .bin
  483. */
  484. char binaryfilename[255];
  485. char filename[255];
  486. char numbuf[32];
  487. if (cgpu->kernel == KL_NONE) {
  488. if (opt_scrypt) {
  489. applog(LOG_INFO, "Selecting scrypt kernel");
  490. clState->chosen_kernel = KL_SCRYPT;
  491. } else if (!strstr(name, "Tahiti") &&
  492. /* Detect all 2.6 SDKs not with Tahiti and use diablo kernel */
  493. (strstr(vbuff, "844.4") || // Linux 64 bit ATI 2.6 SDK
  494. strstr(vbuff, "851.4") || // Windows 64 bit ""
  495. strstr(vbuff, "831.4") ||
  496. strstr(vbuff, "898.1") || // 12.2 driver SDK
  497. strstr(vbuff, "923.1") || // 12.4
  498. strstr(vbuff, "938.2"))) { // SDK 2.7
  499. applog(LOG_INFO, "Selecting diablo kernel");
  500. clState->chosen_kernel = KL_DIABLO;
  501. /* Detect all 7970s, older ATI and NVIDIA and use poclbm */
  502. } else if (strstr(name, "Tahiti") || !clState->hasBitAlign) {
  503. applog(LOG_INFO, "Selecting poclbm kernel");
  504. clState->chosen_kernel = KL_POCLBM;
  505. /* Use phatk for the rest R5xxx R6xxx */
  506. } else {
  507. applog(LOG_INFO, "Selecting phatk kernel");
  508. clState->chosen_kernel = KL_PHATK;
  509. }
  510. cgpu->kernel = clState->chosen_kernel;
  511. } else {
  512. clState->chosen_kernel = cgpu->kernel;
  513. if (clState->chosen_kernel == KL_PHATK &&
  514. (strstr(vbuff, "844.4") || strstr(vbuff, "851.4") ||
  515. strstr(vbuff, "831.4") || strstr(vbuff, "898.1") ||
  516. strstr(vbuff, "923.1") || strstr(vbuff, "938.2"))) {
  517. applog(LOG_WARNING, "WARNING: You have selected the phatk kernel.");
  518. applog(LOG_WARNING, "You are running SDK 2.6+ which performs poorly with this kernel.");
  519. applog(LOG_WARNING, "Downgrade your SDK and delete any .bin files before starting again.");
  520. applog(LOG_WARNING, "Or allow BFGMiner to automatically choose a more suitable kernel.");
  521. }
  522. }
  523. /* For some reason 2 vectors is still better even if the card says
  524. * otherwise, and many cards lie about their max so use 256 as max
  525. * unless explicitly set on the command line. Tahiti prefers 1 */
  526. if (strstr(name, "Tahiti"))
  527. preferred_vwidth = 1;
  528. else if (preferred_vwidth > 2)
  529. preferred_vwidth = 2;
  530. switch (clState->chosen_kernel) {
  531. case KL_POCLBM:
  532. strcpy(filename, POCLBM_KERNNAME".cl");
  533. strcpy(binaryfilename, POCLBM_KERNNAME);
  534. break;
  535. case KL_PHATK:
  536. strcpy(filename, PHATK_KERNNAME".cl");
  537. strcpy(binaryfilename, PHATK_KERNNAME);
  538. break;
  539. case KL_DIAKGCN:
  540. strcpy(filename, DIAKGCN_KERNNAME".cl");
  541. strcpy(binaryfilename, DIAKGCN_KERNNAME);
  542. break;
  543. case KL_SCRYPT:
  544. strcpy(filename, SCRYPT_KERNNAME".cl");
  545. strcpy(binaryfilename, SCRYPT_KERNNAME);
  546. /* Scrypt only supports vector 1 */
  547. cgpu->vwidth = 1;
  548. break;
  549. case KL_NONE: /* Shouldn't happen */
  550. case KL_DIABLO:
  551. strcpy(filename, DIABLO_KERNNAME".cl");
  552. strcpy(binaryfilename, DIABLO_KERNNAME);
  553. break;
  554. }
  555. if (cgpu->vwidth)
  556. clState->vwidth = cgpu->vwidth;
  557. else {
  558. clState->vwidth = preferred_vwidth;
  559. cgpu->vwidth = preferred_vwidth;
  560. }
  561. if (((clState->chosen_kernel == KL_POCLBM || clState->chosen_kernel == KL_DIABLO || clState->chosen_kernel == KL_DIAKGCN) &&
  562. clState->vwidth == 1 && clState->hasOpenCL11plus) || opt_scrypt)
  563. clState->goffset = true;
  564. if (cgpu->work_size && cgpu->work_size <= clState->max_work_size)
  565. clState->wsize = cgpu->work_size;
  566. else if (strstr(name, "Tahiti"))
  567. clState->wsize = 64;
  568. else
  569. clState->wsize = (clState->max_work_size <= 256 ? clState->max_work_size : 256) / clState->vwidth;
  570. cgpu->work_size = clState->wsize;
  571. #ifdef USE_SCRYPT
  572. if (opt_scrypt) {
  573. cl_ulong ma = cgpu->max_alloc, mt;
  574. if (!cgpu->opt_lg) {
  575. applog(LOG_DEBUG, "GPU %d: selecting lookup gap of 2", gpu);
  576. cgpu->lookup_gap = 2;
  577. } else
  578. cgpu->lookup_gap = cgpu->opt_lg;
  579. if (!cgpu->opt_tc) {
  580. cgpu->thread_concurrency = ma / 32768 / cgpu->lookup_gap;
  581. if (cgpu->shaders && cgpu->thread_concurrency > cgpu->shaders) {
  582. cgpu->thread_concurrency -= cgpu->thread_concurrency % cgpu->shaders;
  583. if (cgpu->thread_concurrency > cgpu->shaders * 5)
  584. cgpu->thread_concurrency = cgpu->shaders * 5;
  585. }
  586. applog(LOG_DEBUG, "GPU %u: selecting thread concurrency of %lu", gpu, (unsigned long)cgpu->thread_concurrency);
  587. } else
  588. cgpu->thread_concurrency = cgpu->opt_tc;
  589. /* If we have memory to spare, try to find a power of 2 value
  590. * >= required amount to map nicely to an intensity */
  591. mt = cgpu->thread_concurrency * 32768 * cgpu->lookup_gap;
  592. if (ma > mt) {
  593. ma = 1;
  594. while (ma < mt)
  595. ma <<= 1;
  596. if (ma < cgpu->max_alloc) {
  597. cgpu->max_alloc = ma;
  598. applog(LOG_DEBUG, "Max alloc decreased to %lu", (unsigned long)cgpu->max_alloc);
  599. }
  600. }
  601. }
  602. #endif
  603. FILE *binaryfile;
  604. size_t *binary_sizes;
  605. char **binaries;
  606. int pl;
  607. char *source = file_contents(filename, &pl);
  608. size_t sourceSize[] = {(size_t)pl};
  609. cl_uint slot, cpnd;
  610. slot = cpnd = 0;
  611. if (!source)
  612. return NULL;
  613. binary_sizes = calloc(sizeof(size_t) * MAX_GPUDEVICES * 4, 1);
  614. if (unlikely(!binary_sizes)) {
  615. applog(LOG_ERR, "Unable to calloc binary_sizes");
  616. return NULL;
  617. }
  618. binaries = calloc(sizeof(char *) * MAX_GPUDEVICES * 4, 1);
  619. if (unlikely(!binaries)) {
  620. applog(LOG_ERR, "Unable to calloc binaries");
  621. return NULL;
  622. }
  623. strcat(binaryfilename, name);
  624. if (clState->goffset)
  625. strcat(binaryfilename, "g");
  626. if (opt_scrypt) {
  627. #ifdef USE_SCRYPT
  628. sprintf(numbuf, "lg%utc%u", cgpu->lookup_gap, (unsigned int)cgpu->thread_concurrency);
  629. strcat(binaryfilename, numbuf);
  630. #endif
  631. } else {
  632. sprintf(numbuf, "v%d", clState->vwidth);
  633. strcat(binaryfilename, numbuf);
  634. }
  635. sprintf(numbuf, "w%d", (int)clState->wsize);
  636. strcat(binaryfilename, numbuf);
  637. sprintf(numbuf, "l%d", (int)sizeof(long));
  638. strcat(binaryfilename, numbuf);
  639. strcat(binaryfilename, "p");
  640. strcat(binaryfilename, vbuff);
  641. sanestr(binaryfilename, binaryfilename);
  642. strcat(binaryfilename, ".bin");
  643. binaryfile = fopen(binaryfilename, "rb");
  644. if (!binaryfile) {
  645. applog(LOG_DEBUG, "No binary found, generating from source");
  646. } else {
  647. struct stat binary_stat;
  648. if (unlikely(stat(binaryfilename, &binary_stat))) {
  649. applog(LOG_DEBUG, "Unable to stat binary, generating from source");
  650. fclose(binaryfile);
  651. goto build;
  652. }
  653. if (!binary_stat.st_size)
  654. goto build;
  655. binary_sizes[slot] = binary_stat.st_size;
  656. binaries[slot] = (char *)calloc(binary_sizes[slot], 1);
  657. if (unlikely(!binaries[slot])) {
  658. applog(LOG_ERR, "Unable to calloc binaries");
  659. fclose(binaryfile);
  660. return NULL;
  661. }
  662. if (fread(binaries[slot], 1, binary_sizes[slot], binaryfile) != binary_sizes[slot]) {
  663. applog(LOG_ERR, "Unable to fread binaries");
  664. fclose(binaryfile);
  665. free(binaries[slot]);
  666. goto build;
  667. }
  668. clState->program = clCreateProgramWithBinary(clState->context, 1, &devices[gpu], &binary_sizes[slot], (const unsigned char **)binaries, &status, NULL);
  669. if (status != CL_SUCCESS) {
  670. applog(LOG_ERR, "Error %d: Loading Binary into cl_program (clCreateProgramWithBinary)", status);
  671. fclose(binaryfile);
  672. free(binaries[slot]);
  673. goto build;
  674. }
  675. fclose(binaryfile);
  676. applog(LOG_DEBUG, "Loaded binary image %s", binaryfilename);
  677. goto built;
  678. }
  679. /////////////////////////////////////////////////////////////////
  680. // Load CL file, build CL program object, create CL kernel object
  681. /////////////////////////////////////////////////////////////////
  682. build:
  683. clState->program = clCreateProgramWithSource(clState->context, 1, (const char **)&source, sourceSize, &status);
  684. if (status != CL_SUCCESS) {
  685. applog(LOG_ERR, "Error %d: Loading Binary into cl_program (clCreateProgramWithSource)", status);
  686. return NULL;
  687. }
  688. /* create a cl program executable for all the devices specified */
  689. char *CompilerOptions = calloc(1, 256);
  690. #ifdef USE_SCRYPT
  691. if (opt_scrypt)
  692. sprintf(CompilerOptions, "-D LOOKUP_GAP=%d -D CONCURRENT_THREADS=%d -D WORKSIZE=%d",
  693. cgpu->lookup_gap, (unsigned int)cgpu->thread_concurrency, (int)clState->wsize);
  694. else
  695. #endif
  696. {
  697. sprintf(CompilerOptions, "-D WORKSIZE=%d -D VECTORS%d -D WORKVEC=%d",
  698. (int)clState->wsize, clState->vwidth, (int)clState->wsize * clState->vwidth);
  699. }
  700. applog(LOG_DEBUG, "Setting worksize to %"PRId64, (int64_t)clState->wsize);
  701. if (clState->vwidth > 1)
  702. applog(LOG_DEBUG, "Patched source to suit %d vectors", clState->vwidth);
  703. if (clState->hasBitAlign) {
  704. strcat(CompilerOptions, " -D BITALIGN");
  705. applog(LOG_DEBUG, "cl_amd_media_ops found, setting BITALIGN");
  706. if (strstr(name, "Cedar") ||
  707. strstr(name, "Redwood") ||
  708. strstr(name, "Juniper") ||
  709. strstr(name, "Cypress" ) ||
  710. strstr(name, "Hemlock" ) ||
  711. strstr(name, "Caicos" ) ||
  712. strstr(name, "Turks" ) ||
  713. strstr(name, "Barts" ) ||
  714. strstr(name, "Cayman" ) ||
  715. strstr(name, "Antilles" ) ||
  716. strstr(name, "Wrestler" ) ||
  717. strstr(name, "Zacate" ) ||
  718. strstr(name, "WinterPark" ))
  719. {
  720. // BFI_INT patching only works with AMD-APP up to 1084
  721. if (strstr(vbuff, "ATI-Stream"))
  722. patchbfi = true;
  723. else
  724. if ((s = strstr(vbuff, "AMD-APP")) && (s = strchr(s, '(')) && atoi(&s[1]) < 1085)
  725. patchbfi = true;
  726. }
  727. } else
  728. applog(LOG_DEBUG, "cl_amd_media_ops not found, will not set BITALIGN");
  729. if (patchbfi) {
  730. strcat(CompilerOptions, " -D BFI_INT");
  731. applog(LOG_DEBUG, "BFI_INT patch requiring device found, patched source with BFI_INT");
  732. } else
  733. applog(LOG_DEBUG, "BFI_INT patch requiring device not found, will not BFI_INT patch");
  734. if (clState->goffset)
  735. strcat(CompilerOptions, " -D GOFFSET");
  736. if (!clState->hasOpenCL11plus)
  737. strcat(CompilerOptions, " -D OCL1");
  738. applog(LOG_DEBUG, "CompilerOptions: %s", CompilerOptions);
  739. status = clBuildProgram(clState->program, 1, &devices[gpu], CompilerOptions , NULL, NULL);
  740. free(CompilerOptions);
  741. if (status != CL_SUCCESS) {
  742. applog(LOG_ERR, "Error %d: Building Program (clBuildProgram)", status);
  743. size_t logSize;
  744. status = clGetProgramBuildInfo(clState->program, devices[gpu], CL_PROGRAM_BUILD_LOG, 0, NULL, &logSize);
  745. char *log = malloc(logSize);
  746. status = clGetProgramBuildInfo(clState->program, devices[gpu], CL_PROGRAM_BUILD_LOG, logSize, log, NULL);
  747. applog(LOG_ERR, "%s", log);
  748. return NULL;
  749. }
  750. prog_built = true;
  751. status = clGetProgramInfo(clState->program, CL_PROGRAM_NUM_DEVICES, sizeof(cl_uint), &cpnd, NULL);
  752. if (unlikely(status != CL_SUCCESS)) {
  753. applog(LOG_ERR, "Error %d: Getting program info CL_PROGRAM_NUM_DEVICES. (clGetProgramInfo)", status);
  754. return NULL;
  755. }
  756. status = clGetProgramInfo(clState->program, CL_PROGRAM_BINARY_SIZES, sizeof(size_t)*cpnd, binary_sizes, NULL);
  757. if (unlikely(status != CL_SUCCESS)) {
  758. applog(LOG_ERR, "Error %d: Getting program info CL_PROGRAM_BINARY_SIZES. (clGetProgramInfo)", status);
  759. return NULL;
  760. }
  761. /* The actual compiled binary ends up in a RANDOM slot! Grr, so we have
  762. * to iterate over all the binary slots and find where the real program
  763. * is. What the heck is this!? */
  764. for (slot = 0; slot < cpnd; slot++)
  765. if (binary_sizes[slot])
  766. break;
  767. /* copy over all of the generated binaries. */
  768. applog(LOG_DEBUG, "Binary size for gpu %u found in binary slot %u: %"PRId64,
  769. gpu, (unsigned)slot, (int64_t)binary_sizes[slot]);
  770. if (!binary_sizes[slot]) {
  771. applog(LOG_ERR, "OpenCL compiler generated a zero sized binary, FAIL!");
  772. return NULL;
  773. }
  774. binaries[slot] = calloc(sizeof(char) * binary_sizes[slot], 1);
  775. status = clGetProgramInfo(clState->program, CL_PROGRAM_BINARIES, sizeof(char *) * cpnd, binaries, NULL );
  776. if (unlikely(status != CL_SUCCESS)) {
  777. applog(LOG_ERR, "Error %d: Getting program info. CL_PROGRAM_BINARIES (clGetProgramInfo)", status);
  778. return NULL;
  779. }
  780. /* Patch the kernel if the hardware supports BFI_INT but it needs to
  781. * be hacked in */
  782. if (patchbfi) {
  783. unsigned remaining = binary_sizes[slot];
  784. char *w = binaries[slot];
  785. unsigned int start, length;
  786. /* Find 2nd incidence of .text, and copy the program's
  787. * position and length at a fixed offset from that. Then go
  788. * back and find the 2nd incidence of \x7ELF (rewind by one
  789. * from ELF) and then patch the opcocdes */
  790. if (!advance(&w, &remaining, ".text"))
  791. goto build;
  792. w++; remaining--;
  793. if (!advance(&w, &remaining, ".text")) {
  794. /* 32 bit builds only one ELF */
  795. w--; remaining++;
  796. }
  797. memcpy(&start, w + 285, 4);
  798. memcpy(&length, w + 289, 4);
  799. w = binaries[slot]; remaining = binary_sizes[slot];
  800. if (!advance(&w, &remaining, "ELF"))
  801. goto build;
  802. w++; remaining--;
  803. if (!advance(&w, &remaining, "ELF")) {
  804. /* 32 bit builds only one ELF */
  805. w--; remaining++;
  806. }
  807. w--; remaining++;
  808. w += start; remaining -= start;
  809. applog(LOG_DEBUG, "At %p (%u rem. bytes), to begin patching",
  810. w, remaining);
  811. patch_opcodes(w, length);
  812. status = clReleaseProgram(clState->program);
  813. if (status != CL_SUCCESS) {
  814. applog(LOG_ERR, "Error %d: Releasing program. (clReleaseProgram)", status);
  815. return NULL;
  816. }
  817. clState->program = clCreateProgramWithBinary(clState->context, 1, &devices[gpu], &binary_sizes[slot], (const unsigned char **)&binaries[slot], &status, NULL);
  818. if (status != CL_SUCCESS) {
  819. applog(LOG_ERR, "Error %d: Loading Binary into cl_program (clCreateProgramWithBinary)", status);
  820. return NULL;
  821. }
  822. /* Program needs to be rebuilt */
  823. prog_built = false;
  824. }
  825. free(source);
  826. /* Save the binary to be loaded next time */
  827. binaryfile = fopen(binaryfilename, "wb");
  828. if (!binaryfile) {
  829. /* Not a fatal problem, just means we build it again next time */
  830. applog(LOG_DEBUG, "Unable to create file %s", binaryfilename);
  831. } else {
  832. if (unlikely(fwrite(binaries[slot], 1, binary_sizes[slot], binaryfile) != binary_sizes[slot])) {
  833. applog(LOG_ERR, "Unable to fwrite to binaryfile");
  834. return NULL;
  835. }
  836. fclose(binaryfile);
  837. }
  838. built:
  839. if (binaries[slot])
  840. free(binaries[slot]);
  841. free(binaries);
  842. free(binary_sizes);
  843. applog(LOG_INFO, "Initialising kernel %s with%s bitalign, %"PRId64" vectors and worksize %"PRIu64,
  844. filename, clState->hasBitAlign ? "" : "out", (int64_t)clState->vwidth, (uint64_t)clState->wsize);
  845. if (!prog_built) {
  846. /* create a cl program executable for all the devices specified */
  847. status = clBuildProgram(clState->program, 1, &devices[gpu], NULL, NULL, NULL);
  848. if (status != CL_SUCCESS) {
  849. applog(LOG_ERR, "Error %d: Building Program (clBuildProgram)", status);
  850. size_t logSize;
  851. status = clGetProgramBuildInfo(clState->program, devices[gpu], CL_PROGRAM_BUILD_LOG, 0, NULL, &logSize);
  852. char *log = malloc(logSize);
  853. status = clGetProgramBuildInfo(clState->program, devices[gpu], CL_PROGRAM_BUILD_LOG, logSize, log, NULL);
  854. applog(LOG_ERR, "%s", log);
  855. return NULL;
  856. }
  857. }
  858. /* get a kernel object handle for a kernel with the given name */
  859. clState->kernel = clCreateKernel(clState->program, "search", &status);
  860. if (status != CL_SUCCESS) {
  861. applog(LOG_ERR, "Error %d: Creating Kernel from program. (clCreateKernel)", status);
  862. return NULL;
  863. }
  864. #ifdef USE_SCRYPT
  865. if (opt_scrypt) {
  866. size_t ipt = (1024 / cgpu->lookup_gap + (1024 % cgpu->lookup_gap > 0));
  867. size_t bufsize = 128 * ipt * cgpu->thread_concurrency;
  868. /* Use the max alloc value which has been rounded to a power of
  869. * 2 greater >= required amount earlier */
  870. if (bufsize > cgpu->max_alloc) {
  871. applog(LOG_WARNING, "Maximum buffer memory device %d supports says %lu", gpu, (unsigned long)cgpu->max_alloc);
  872. applog(LOG_WARNING, "Your scrypt settings come to %lu", (unsigned long)bufsize);
  873. } else
  874. bufsize = cgpu->max_alloc;
  875. applog(LOG_DEBUG, "Creating scrypt buffer sized %lu", (unsigned long)bufsize);
  876. clState->padbufsize = bufsize;
  877. /* This buffer is weird and might work to some degree even if
  878. * the create buffer call has apparently failed, so check if we
  879. * get anything back before we call it a failure. */
  880. clState->padbuffer8 = NULL;
  881. clState->padbuffer8 = clCreateBuffer(clState->context, CL_MEM_READ_WRITE, bufsize, NULL, &status);
  882. if (status != CL_SUCCESS && !clState->padbuffer8) {
  883. applog(LOG_ERR, "Error %d: clCreateBuffer (padbuffer8), decrease TC or increase LG", status);
  884. return NULL;
  885. }
  886. clState->CLbuffer0 = clCreateBuffer(clState->context, CL_MEM_READ_ONLY, 128, NULL, &status);
  887. if (status != CL_SUCCESS) {
  888. applog(LOG_ERR, "Error %d: clCreateBuffer (CLbuffer0)", status);
  889. return NULL;
  890. }
  891. }
  892. #endif
  893. clState->outputBuffer = clCreateBuffer(clState->context, CL_MEM_WRITE_ONLY, BUFFERSIZE, NULL, &status);
  894. if (status != CL_SUCCESS) {
  895. applog(LOG_ERR, "Error %d: clCreateBuffer (outputBuffer)", status);
  896. return NULL;
  897. }
  898. return clState;
  899. }
  900. #endif /* HAVE_OPENCL */