device-gpu.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278
  1. /*
  2. * Copyright 2011-2012 Con Kolivas
  3. * Copyright 2011-2012 Luke Dashjr
  4. * Copyright 2010 Jeff Garzik
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the Free
  8. * Software Foundation; either version 2 of the License, or (at your option)
  9. * any later version. See COPYING for more details.
  10. */
  11. #include "config.h"
  12. #include <curses.h>
  13. #include <string.h>
  14. #include <stdbool.h>
  15. #include <stdint.h>
  16. #include <sys/types.h>
  17. #ifndef WIN32
  18. #include <sys/resource.h>
  19. #endif
  20. #include <ccan/opt/opt.h>
  21. #include "compat.h"
  22. #include "miner.h"
  23. #include "device-cpu.h"
  24. #include "findnonce.h"
  25. #include "ocl.h"
  26. #include "adl.h"
  27. /* TODO: cleanup externals ********************/
  28. extern WINDOW *mainwin, *statuswin, *logwin;
  29. extern void enable_curses(void);
  30. extern int mining_threads;
  31. extern double total_secs;
  32. extern int opt_g_threads;
  33. extern bool ping;
  34. extern bool opt_loginput;
  35. extern char *opt_kernel_path;
  36. extern char *opt_kernel;
  37. extern int gpur_thr_id;
  38. extern bool opt_noadl;
  39. extern bool have_opencl;
  40. extern void *miner_thread(void *userdata);
  41. extern int dev_from_id(int thr_id);
  42. extern void tailsprintf(char *f, const char *fmt, ...);
  43. extern void wlog(const char *f, ...);
  44. extern void decay_time(double *f, double fadd);
  45. /**********************************************/
  46. #ifdef HAVE_OPENCL
  47. char *set_vector(const char *arg, int *i)
  48. {
  49. char *err = opt_set_intval(arg, i);
  50. if (err)
  51. return err;
  52. if (*i != 1 && *i != 2 && *i != 4)
  53. return "Valid vectors are 1, 2 or 4";
  54. return NULL;
  55. }
  56. #endif
  57. #ifdef HAVE_ADL
  58. void get_intrange(char *arg, int *val1, int *val2)
  59. {
  60. if (sscanf(arg, "%d-%d", val1, val2) == 1) {
  61. *val2 = *val1;
  62. *val1 = 0;
  63. }
  64. }
  65. char *set_gpu_engine(char *arg)
  66. {
  67. int i, val1 = 0, val2 = 0, device = 0;
  68. char *nextptr;
  69. nextptr = strtok(arg, ",");
  70. if (nextptr == NULL)
  71. return "Invalid parameters for set gpu engine";
  72. get_intrange(nextptr, &val1, &val2);
  73. if (val1 < 0 || val1 > 9999 || val2 < 0 || val2 > 9999)
  74. return "Invalid value passed to set_gpu_engine";
  75. gpus[device].min_engine = val1;
  76. gpus[device].gpu_engine = val2;
  77. device++;
  78. while ((nextptr = strtok(NULL, ",")) != NULL) {
  79. get_intrange(nextptr, &val1, &val2);
  80. if (val1 < 0 || val1 > 9999 || val2 < 0 || val2 > 9999)
  81. return "Invalid value passed to set_gpu_engine";
  82. gpus[device].min_engine = val1;
  83. gpus[device].gpu_engine = val2;
  84. device++;
  85. }
  86. if (device == 1) {
  87. for (i = 1; i < MAX_GPUDEVICES; i++) {
  88. gpus[i].min_engine = gpus[0].min_engine;
  89. gpus[i].gpu_engine = gpus[0].gpu_engine;
  90. }
  91. }
  92. return NULL;
  93. }
  94. char *set_gpu_fan(char *arg)
  95. {
  96. int i, val1 = 0, val2 = 0, device = 0;
  97. char *nextptr;
  98. nextptr = strtok(arg, ",");
  99. if (nextptr == NULL)
  100. return "Invalid parameters for set gpu fan";
  101. get_intrange(nextptr, &val1, &val2);
  102. if (val1 < 0 || val1 > 100 || val2 < 0 || val2 > 100)
  103. return "Invalid value passed to set_gpu_fan";
  104. gpus[device].min_fan = val1;
  105. gpus[device].gpu_fan = val2;
  106. device++;
  107. while ((nextptr = strtok(NULL, ",")) != NULL) {
  108. get_intrange(nextptr, &val1, &val2);
  109. if (val1 < 0 || val1 > 100 || val2 < 0 || val2 > 100)
  110. return "Invalid value passed to set_gpu_fan";
  111. gpus[device].min_fan = val1;
  112. gpus[device].gpu_fan = val2;
  113. device++;
  114. }
  115. if (device == 1) {
  116. for (i = 1; i < MAX_GPUDEVICES; i++) {
  117. gpus[i].min_fan = gpus[0].min_fan;
  118. gpus[i].gpu_fan = gpus[0].gpu_fan;
  119. }
  120. }
  121. return NULL;
  122. }
  123. char *set_gpu_memclock(char *arg)
  124. {
  125. int i, val = 0, device = 0;
  126. char *nextptr;
  127. nextptr = strtok(arg, ",");
  128. if (nextptr == NULL)
  129. return "Invalid parameters for set gpu memclock";
  130. val = atoi(nextptr);
  131. if (val < 0 || val >= 9999)
  132. return "Invalid value passed to set_gpu_memclock";
  133. gpus[device++].gpu_memclock = val;
  134. while ((nextptr = strtok(NULL, ",")) != NULL) {
  135. val = atoi(nextptr);
  136. if (val < 0 || val >= 9999)
  137. return "Invalid value passed to set_gpu_memclock";
  138. gpus[device++].gpu_memclock = val;
  139. }
  140. if (device == 1) {
  141. for (i = device; i < MAX_GPUDEVICES; i++)
  142. gpus[i].gpu_memclock = gpus[0].gpu_memclock;
  143. }
  144. return NULL;
  145. }
  146. char *set_gpu_memdiff(char *arg)
  147. {
  148. int i, val = 0, device = 0;
  149. char *nextptr;
  150. nextptr = strtok(arg, ",");
  151. if (nextptr == NULL)
  152. return "Invalid parameters for set gpu memdiff";
  153. val = atoi(nextptr);
  154. if (val < -9999 || val > 9999)
  155. return "Invalid value passed to set_gpu_memdiff";
  156. gpus[device++].gpu_memdiff = val;
  157. while ((nextptr = strtok(NULL, ",")) != NULL) {
  158. val = atoi(nextptr);
  159. if (val < -9999 || val > 9999)
  160. return "Invalid value passed to set_gpu_memdiff";
  161. gpus[device++].gpu_memdiff = val;
  162. }
  163. if (device == 1) {
  164. for (i = device; i < MAX_GPUDEVICES; i++)
  165. gpus[i].gpu_memdiff = gpus[0].gpu_memdiff;
  166. }
  167. return NULL;
  168. }
  169. char *set_gpu_powertune(char *arg)
  170. {
  171. int i, val = 0, device = 0;
  172. char *nextptr;
  173. nextptr = strtok(arg, ",");
  174. if (nextptr == NULL)
  175. return "Invalid parameters for set gpu powertune";
  176. val = atoi(nextptr);
  177. if (val < -99 || val > 99)
  178. return "Invalid value passed to set_gpu_powertune";
  179. gpus[device++].gpu_powertune = val;
  180. while ((nextptr = strtok(NULL, ",")) != NULL) {
  181. val = atoi(nextptr);
  182. if (val < -99 || val > 99)
  183. return "Invalid value passed to set_gpu_powertune";
  184. gpus[device++].gpu_powertune = val;
  185. }
  186. if (device == 1) {
  187. for (i = device; i < MAX_GPUDEVICES; i++)
  188. gpus[i].gpu_powertune = gpus[0].gpu_powertune;
  189. }
  190. return NULL;
  191. }
  192. char *set_gpu_vddc(char *arg)
  193. {
  194. int i, device = 0;
  195. float val = 0;
  196. char *nextptr;
  197. nextptr = strtok(arg, ",");
  198. if (nextptr == NULL)
  199. return "Invalid parameters for set gpu vddc";
  200. val = atof(nextptr);
  201. if (val < 0 || val >= 9999)
  202. return "Invalid value passed to set_gpu_vddc";
  203. gpus[device++].gpu_vddc = val;
  204. while ((nextptr = strtok(NULL, ",")) != NULL) {
  205. val = atof(nextptr);
  206. if (val < 0 || val >= 9999)
  207. return "Invalid value passed to set_gpu_vddc";
  208. gpus[device++].gpu_vddc = val;
  209. }
  210. if (device == 1) {
  211. for (i = device; i < MAX_GPUDEVICES; i++)
  212. gpus[i].gpu_vddc = gpus[0].gpu_vddc;
  213. }
  214. return NULL;
  215. }
  216. char *set_temp_overheat(char *arg)
  217. {
  218. int i, val = 0, device = 0, *to;
  219. char *nextptr;
  220. nextptr = strtok(arg, ",");
  221. if (nextptr == NULL)
  222. return "Invalid parameters for set temp overheat";
  223. val = atoi(nextptr);
  224. if (val < 0 || val > 200)
  225. return "Invalid value passed to set temp overheat";
  226. to = &gpus[device++].adl.overtemp;
  227. *to = val;
  228. while ((nextptr = strtok(NULL, ",")) != NULL) {
  229. val = atoi(nextptr);
  230. if (val < 0 || val > 200)
  231. return "Invalid value passed to set temp overheat";
  232. to = &gpus[device++].adl.overtemp;
  233. *to = val;
  234. }
  235. if (device == 1) {
  236. for (i = device; i < MAX_GPUDEVICES; i++) {
  237. to = &gpus[i].adl.overtemp;
  238. *to = val;
  239. }
  240. }
  241. return NULL;
  242. }
  243. char *set_temp_target(char *arg)
  244. {
  245. int i, val = 0, device = 0, *tt;
  246. char *nextptr;
  247. nextptr = strtok(arg, ",");
  248. if (nextptr == NULL)
  249. return "Invalid parameters for set temp target";
  250. val = atoi(nextptr);
  251. if (val < 0 || val > 200)
  252. return "Invalid value passed to set temp target";
  253. tt = &gpus[device++].adl.targettemp;
  254. *tt = val;
  255. while ((nextptr = strtok(NULL, ",")) != NULL) {
  256. val = atoi(nextptr);
  257. if (val < 0 || val > 200)
  258. return "Invalid value passed to set temp target";
  259. tt = &gpus[device++].adl.targettemp;
  260. *tt = val;
  261. }
  262. if (device == 1) {
  263. for (i = device; i < MAX_GPUDEVICES; i++) {
  264. tt = &gpus[i].adl.targettemp;
  265. *tt = val;
  266. }
  267. }
  268. return NULL;
  269. }
  270. #endif
  271. #ifdef HAVE_OPENCL
  272. char *set_intensity(char *arg)
  273. {
  274. int i, device = 0, *tt;
  275. char *nextptr, val = 0;
  276. nextptr = strtok(arg, ",");
  277. if (nextptr == NULL)
  278. return "Invalid parameters for set intensity";
  279. if (!strncasecmp(nextptr, "d", 1))
  280. gpus[device].dynamic = true;
  281. else {
  282. gpus[device].dynamic = false;
  283. val = atoi(nextptr);
  284. if (val < MIN_INTENSITY || val > MAX_INTENSITY)
  285. return "Invalid value passed to set intensity";
  286. tt = &gpus[device].intensity;
  287. *tt = val;
  288. }
  289. device++;
  290. while ((nextptr = strtok(NULL, ",")) != NULL) {
  291. if (!strncasecmp(nextptr, "d", 1))
  292. gpus[device].dynamic = true;
  293. else {
  294. gpus[device].dynamic = false;
  295. val = atoi(nextptr);
  296. if (val < MIN_INTENSITY || val > MAX_INTENSITY)
  297. return "Invalid value passed to set intensity";
  298. tt = &gpus[device].intensity;
  299. *tt = val;
  300. }
  301. device++;
  302. }
  303. if (device == 1) {
  304. for (i = device; i < MAX_GPUDEVICES; i++) {
  305. gpus[i].dynamic = gpus[0].dynamic;
  306. gpus[i].intensity = gpus[0].intensity;
  307. }
  308. }
  309. return NULL;
  310. }
  311. #endif
  312. #ifdef HAVE_OPENCL
  313. struct device_api opencl_api;
  314. char *print_ndevs_and_exit(int *ndevs)
  315. {
  316. opt_log_output = true;
  317. opencl_api.api_detect();
  318. clear_adl(*ndevs);
  319. applog(LOG_INFO, "%i GPU devices max detected", *ndevs);
  320. exit(*ndevs);
  321. }
  322. #endif
  323. struct cgpu_info gpus[MAX_GPUDEVICES]; /* Maximum number apparently possible */
  324. struct cgpu_info *cpus;
  325. #ifdef HAVE_OPENCL
  326. /* In dynamic mode, only the first thread of each device will be in use.
  327. * This potentially could start a thread that was stopped with the start-stop
  328. * options if one were to disable dynamic from the menu on a paused GPU */
  329. void pause_dynamic_threads(int gpu)
  330. {
  331. struct cgpu_info *cgpu = &gpus[gpu];
  332. int i, thread_no = 0;
  333. for (i = 0; i < mining_threads; i++) {
  334. struct thr_info *thr = &thr_info[i];
  335. if (thr->cgpu != cgpu)
  336. continue;
  337. if (!thread_no++)
  338. continue;
  339. thr->pause = cgpu->dynamic;
  340. if (!cgpu->dynamic && cgpu->enabled)
  341. tq_push(thr->q, &ping);
  342. }
  343. }
  344. struct device_api opencl_api;
  345. void manage_gpu(void)
  346. {
  347. struct thr_info *thr;
  348. int selected, gpu, i;
  349. char checkin[40];
  350. char input;
  351. if (!opt_g_threads)
  352. return;
  353. opt_loginput = true;
  354. immedok(logwin, true);
  355. clear_logwin();
  356. retry:
  357. for (gpu = 0; gpu < nDevs; gpu++) {
  358. struct cgpu_info *cgpu = &gpus[gpu];
  359. wlog("GPU %d: %.1f / %.1f Mh/s | A:%d R:%d HW:%d U:%.2f/m I:%d\n",
  360. gpu, cgpu->rolling, cgpu->total_mhashes / total_secs,
  361. cgpu->accepted, cgpu->rejected, cgpu->hw_errors,
  362. cgpu->utility, cgpu->intensity);
  363. #ifdef HAVE_ADL
  364. if (gpus[gpu].has_adl) {
  365. int engineclock = 0, memclock = 0, activity = 0, fanspeed = 0, fanpercent = 0, powertune = 0;
  366. float temp = 0, vddc = 0;
  367. if (gpu_stats(gpu, &temp, &engineclock, &memclock, &vddc, &activity, &fanspeed, &fanpercent, &powertune)) {
  368. char logline[255];
  369. strcpy(logline, ""); // In case it has no data
  370. if (temp != -1)
  371. sprintf(logline, "%.1f C ", temp);
  372. if (fanspeed != -1 || fanpercent != -1) {
  373. tailsprintf(logline, "F: ");
  374. if (fanpercent != -1)
  375. tailsprintf(logline, "%d%% ", fanpercent);
  376. if (fanspeed != -1)
  377. tailsprintf(logline, "(%d RPM) ", fanspeed);
  378. tailsprintf(logline, " ");
  379. }
  380. if (engineclock != -1)
  381. tailsprintf(logline, "E: %d MHz ", engineclock);
  382. if (memclock != -1)
  383. tailsprintf(logline, "M: %d Mhz ", memclock);
  384. if (vddc != -1)
  385. tailsprintf(logline, "V: %.3fV ", vddc);
  386. if (activity != -1)
  387. tailsprintf(logline, "A: %d%% ", activity);
  388. if (powertune != -1)
  389. tailsprintf(logline, "P: %d%%", powertune);
  390. tailsprintf(logline, "\n");
  391. wlog(logline);
  392. }
  393. }
  394. #endif
  395. wlog("Last initialised: %s\n", cgpu->init);
  396. wlog("Intensity: ");
  397. if (gpus[gpu].dynamic)
  398. wlog("Dynamic (only one thread in use)\n");
  399. else
  400. wlog("%d\n", gpus[gpu].intensity);
  401. for (i = 0; i < mining_threads; i++) {
  402. thr = &thr_info[i];
  403. if (thr->cgpu != cgpu)
  404. continue;
  405. get_datestamp(checkin, &thr->last);
  406. wlog("Thread %d: %.1f Mh/s %s ", i, thr->rolling, cgpu->enabled ? "Enabled" : "Disabled");
  407. switch (cgpu->status) {
  408. default:
  409. case LIFE_WELL:
  410. wlog("ALIVE");
  411. break;
  412. case LIFE_SICK:
  413. wlog("SICK reported in %s", checkin);
  414. break;
  415. case LIFE_DEAD:
  416. wlog("DEAD reported in %s", checkin);
  417. break;
  418. case LIFE_NOSTART:
  419. wlog("Never started");
  420. break;
  421. }
  422. if (thr->pause)
  423. wlog(" paused");
  424. wlog("\n");
  425. }
  426. wlog("\n");
  427. }
  428. wlogprint("[E]nable [D]isable [I]ntensity [R]estart GPU %s\n",adl_active ? "[C]hange settings" : "");
  429. wlogprint("Or press any other key to continue\n");
  430. input = getch();
  431. if (nDevs == 1)
  432. selected = 0;
  433. else
  434. selected = -1;
  435. if (!strncasecmp(&input, "e", 1)) {
  436. struct cgpu_info *cgpu;
  437. if (selected)
  438. selected = curses_int("Select GPU to enable");
  439. if (selected < 0 || selected >= nDevs) {
  440. wlogprint("Invalid selection\n");
  441. goto retry;
  442. }
  443. if (gpus[selected].enabled) {
  444. wlogprint("Device already enabled\n");
  445. goto retry;
  446. }
  447. gpus[selected].enabled = true;
  448. for (i = 0; i < mining_threads; ++i) {
  449. thr = &thr_info[i];
  450. cgpu = thr->cgpu;
  451. if (cgpu->api != &opencl_api)
  452. continue;
  453. if (dev_from_id(i) != selected)
  454. continue;
  455. if (cgpu->status != LIFE_WELL) {
  456. wlogprint("Must restart device before enabling it");
  457. gpus[selected].enabled = false;
  458. goto retry;
  459. }
  460. if (opt_debug)
  461. applog(LOG_DEBUG, "Pushing ping to thread %d", thr->id);
  462. tq_push(thr->q, &ping);
  463. }
  464. goto retry;
  465. } if (!strncasecmp(&input, "d", 1)) {
  466. if (selected)
  467. selected = curses_int("Select GPU to disable");
  468. if (selected < 0 || selected >= nDevs) {
  469. wlogprint("Invalid selection\n");
  470. goto retry;
  471. }
  472. if (!gpus[selected].enabled) {
  473. wlogprint("Device already disabled\n");
  474. goto retry;
  475. }
  476. gpus[selected].enabled = false;
  477. goto retry;
  478. } else if (!strncasecmp(&input, "i", 1)) {
  479. int intensity;
  480. char *intvar;
  481. if (selected)
  482. selected = curses_int("Select GPU to change intensity on");
  483. if (selected < 0 || selected >= nDevs) {
  484. wlogprint("Invalid selection\n");
  485. goto retry;
  486. }
  487. intvar = curses_input("Set GPU scan intensity (d or " _MIN_INTENSITY_STR " -> " _MAX_INTENSITY_STR ")");
  488. if (!intvar) {
  489. wlogprint("Invalid input\n");
  490. goto retry;
  491. }
  492. if (!strncasecmp(intvar, "d", 1)) {
  493. wlogprint("Dynamic mode enabled on gpu %d\n", selected);
  494. gpus[selected].dynamic = true;
  495. pause_dynamic_threads(selected);
  496. free(intvar);
  497. goto retry;
  498. }
  499. intensity = atoi(intvar);
  500. free(intvar);
  501. if (intensity < MIN_INTENSITY || intensity > MAX_INTENSITY) {
  502. wlogprint("Invalid selection\n");
  503. goto retry;
  504. }
  505. gpus[selected].dynamic = false;
  506. gpus[selected].intensity = intensity;
  507. wlogprint("Intensity on gpu %d set to %d\n", selected, intensity);
  508. pause_dynamic_threads(selected);
  509. goto retry;
  510. } else if (!strncasecmp(&input, "r", 1)) {
  511. if (selected)
  512. selected = curses_int("Select GPU to attempt to restart");
  513. if (selected < 0 || selected >= nDevs) {
  514. wlogprint("Invalid selection\n");
  515. goto retry;
  516. }
  517. wlogprint("Attempting to restart threads of GPU %d\n", selected);
  518. reinit_device(&gpus[selected]);
  519. goto retry;
  520. } else if (adl_active && (!strncasecmp(&input, "c", 1))) {
  521. if (selected)
  522. selected = curses_int("Select GPU to change settings on");
  523. if (selected < 0 || selected >= nDevs) {
  524. wlogprint("Invalid selection\n");
  525. goto retry;
  526. }
  527. change_gpusettings(selected);
  528. goto retry;
  529. } else
  530. clear_logwin();
  531. immedok(logwin, false);
  532. opt_loginput = false;
  533. }
  534. #else
  535. void manage_gpu(void)
  536. {
  537. }
  538. #endif
  539. #ifdef HAVE_OPENCL
  540. static _clState *clStates[MAX_GPUDEVICES];
  541. #define CL_SET_BLKARG(blkvar) status |= clSetKernelArg(*kernel, num++, sizeof(uint), (void *)&blk->blkvar)
  542. #define CL_SET_ARG(var) status |= clSetKernelArg(*kernel, num++, sizeof(var), (void *)&var)
  543. #define CL_SET_VARG(args, var) status |= clSetKernelArg(*kernel, num++, args * sizeof(uint), (void *)var)
  544. static cl_int queue_poclbm_kernel(_clState *clState, dev_blk_ctx *blk)
  545. {
  546. cl_kernel *kernel = &clState->kernel;
  547. cl_int status = 0;
  548. int num = 0;
  549. CL_SET_BLKARG(ctx_a);
  550. CL_SET_BLKARG(ctx_b);
  551. CL_SET_BLKARG(ctx_c);
  552. CL_SET_BLKARG(ctx_d);
  553. CL_SET_BLKARG(ctx_e);
  554. CL_SET_BLKARG(ctx_f);
  555. CL_SET_BLKARG(ctx_g);
  556. CL_SET_BLKARG(ctx_h);
  557. CL_SET_BLKARG(cty_b);
  558. CL_SET_BLKARG(cty_c);
  559. CL_SET_BLKARG(cty_d);
  560. CL_SET_BLKARG(cty_f);
  561. CL_SET_BLKARG(cty_g);
  562. CL_SET_BLKARG(cty_h);
  563. CL_SET_BLKARG(nonce);
  564. CL_SET_BLKARG(fW0);
  565. CL_SET_BLKARG(fW1);
  566. CL_SET_BLKARG(fW2);
  567. CL_SET_BLKARG(fW3);
  568. CL_SET_BLKARG(fW15);
  569. CL_SET_BLKARG(fW01r);
  570. CL_SET_BLKARG(fcty_e);
  571. CL_SET_BLKARG(fcty_e2);
  572. CL_SET_ARG(clState->outputBuffer);
  573. return status;
  574. }
  575. static cl_int queue_phatk_kernel(_clState *clState, dev_blk_ctx *blk)
  576. {
  577. cl_uint vwidth = clState->preferred_vwidth;
  578. cl_kernel *kernel = &clState->kernel;
  579. cl_int status = 0;
  580. int i, num = 0;
  581. uint *nonces;
  582. CL_SET_BLKARG(ctx_a);
  583. CL_SET_BLKARG(ctx_b);
  584. CL_SET_BLKARG(ctx_c);
  585. CL_SET_BLKARG(ctx_d);
  586. CL_SET_BLKARG(ctx_e);
  587. CL_SET_BLKARG(ctx_f);
  588. CL_SET_BLKARG(ctx_g);
  589. CL_SET_BLKARG(ctx_h);
  590. CL_SET_BLKARG(cty_b);
  591. CL_SET_BLKARG(cty_c);
  592. CL_SET_BLKARG(cty_d);
  593. CL_SET_BLKARG(cty_f);
  594. CL_SET_BLKARG(cty_g);
  595. CL_SET_BLKARG(cty_h);
  596. nonces = alloca(sizeof(uint) * vwidth);
  597. for (i = 0; i < vwidth; i++)
  598. nonces[i] = blk->nonce + i;
  599. CL_SET_VARG(vwidth, nonces);
  600. CL_SET_BLKARG(W16);
  601. CL_SET_BLKARG(W17);
  602. CL_SET_BLKARG(PreVal4_2);
  603. CL_SET_BLKARG(PreVal0);
  604. CL_SET_BLKARG(PreW18);
  605. CL_SET_BLKARG(PreW19);
  606. CL_SET_BLKARG(PreW31);
  607. CL_SET_BLKARG(PreW32);
  608. CL_SET_ARG(clState->outputBuffer);
  609. return status;
  610. }
  611. static cl_int queue_diakgcn_kernel(_clState *clState, dev_blk_ctx *blk)
  612. {
  613. cl_uint vwidth = clState->preferred_vwidth;
  614. cl_kernel *kernel = &clState->kernel;
  615. cl_int status = 0;
  616. int i, num = 0;
  617. uint *nonces;
  618. nonces = alloca(sizeof(uint) * vwidth);
  619. for (i = 0; i < vwidth; i++)
  620. nonces[i] = blk->nonce + i;
  621. CL_SET_VARG(vwidth, nonces);
  622. CL_SET_BLKARG(PreVal4_2);
  623. CL_SET_BLKARG(cty_h);
  624. CL_SET_BLKARG(cty_d);
  625. CL_SET_BLKARG(PreVal0);
  626. CL_SET_BLKARG(cty_b);
  627. CL_SET_BLKARG(cty_c);
  628. CL_SET_BLKARG(cty_f);
  629. CL_SET_BLKARG(cty_g);
  630. CL_SET_BLKARG(C1addK5);
  631. CL_SET_BLKARG(B1addK6);
  632. CL_SET_BLKARG(PreVal0addK7);
  633. CL_SET_BLKARG(W16addK16);
  634. CL_SET_BLKARG(W17addK17);
  635. CL_SET_BLKARG(PreW18);
  636. CL_SET_BLKARG(PreW19);
  637. CL_SET_BLKARG(W16);
  638. CL_SET_BLKARG(W17);
  639. CL_SET_BLKARG(PreW31);
  640. CL_SET_BLKARG(PreW32);
  641. CL_SET_BLKARG(ctx_a);
  642. CL_SET_BLKARG(ctx_b);
  643. CL_SET_BLKARG(ctx_c);
  644. CL_SET_BLKARG(ctx_d);
  645. CL_SET_BLKARG(ctx_e);
  646. CL_SET_BLKARG(ctx_f);
  647. CL_SET_BLKARG(ctx_g);
  648. CL_SET_BLKARG(ctx_h);
  649. CL_SET_BLKARG(A0);
  650. CL_SET_BLKARG(B0);
  651. CL_SET_ARG(clState->outputBuffer);
  652. return status;
  653. }
  654. static cl_int queue_diablo_kernel(_clState *clState, dev_blk_ctx *blk)
  655. {
  656. cl_kernel *kernel = &clState->kernel;
  657. cl_int status = 0;
  658. int num = 0;
  659. CL_SET_BLKARG(nonce);
  660. CL_SET_BLKARG(PreVal0);
  661. CL_SET_BLKARG(PreVal4_2);
  662. CL_SET_BLKARG(PreW18);
  663. CL_SET_BLKARG(PreW19);
  664. CL_SET_BLKARG(W16);
  665. CL_SET_BLKARG(W17);
  666. CL_SET_BLKARG(PreW31);
  667. CL_SET_BLKARG(PreW32);
  668. CL_SET_BLKARG(cty_d);
  669. CL_SET_BLKARG(cty_b);
  670. CL_SET_BLKARG(cty_c);
  671. CL_SET_BLKARG(cty_h);
  672. CL_SET_BLKARG(cty_f);
  673. CL_SET_BLKARG(cty_g);
  674. CL_SET_BLKARG(C1addK5);
  675. CL_SET_BLKARG(B1addK6);
  676. CL_SET_BLKARG(ctx_a);
  677. CL_SET_BLKARG(ctx_b);
  678. CL_SET_BLKARG(ctx_c);
  679. CL_SET_BLKARG(ctx_d);
  680. CL_SET_BLKARG(ctx_e);
  681. CL_SET_BLKARG(ctx_f);
  682. CL_SET_BLKARG(ctx_g);
  683. CL_SET_BLKARG(ctx_h);
  684. CL_SET_ARG(clState->outputBuffer);
  685. return status;
  686. }
  687. static void set_threads_hashes(unsigned int vectors, unsigned int *threads,
  688. unsigned int *hashes, size_t *globalThreads,
  689. unsigned int minthreads, int intensity)
  690. {
  691. *threads = 1 << (15 + intensity);
  692. if (*threads < minthreads)
  693. *threads = minthreads;
  694. *globalThreads = *threads;
  695. *hashes = *threads * vectors;
  696. }
  697. #endif /* HAVE_OPENCL */
  698. #ifdef HAVE_OPENCL
  699. /* We have only one thread that ever re-initialises GPUs, thus if any GPU
  700. * init command fails due to a completely wedged GPU, the thread will never
  701. * return, unable to harm other GPUs. If it does return, it means we only had
  702. * a soft failure and then the reinit_gpu thread is ready to tackle another
  703. * GPU */
  704. void *reinit_gpu(void *userdata)
  705. {
  706. struct thr_info *mythr = userdata;
  707. struct cgpu_info *cgpu;
  708. struct thr_info *thr;
  709. struct timeval now;
  710. char name[256];
  711. int thr_id;
  712. int gpu;
  713. pthread_detach(pthread_self());
  714. select_cgpu:
  715. cgpu = tq_pop(mythr->q, NULL);
  716. if (!cgpu)
  717. goto out;
  718. if (clDevicesNum() != nDevs) {
  719. applog(LOG_WARNING, "Hardware not reporting same number of active devices, will not attempt to restart GPU");
  720. goto out;
  721. }
  722. gpu = cgpu->device_id;
  723. cgpu->enabled = false;
  724. for (thr_id = 0; thr_id < mining_threads; ++thr_id) {
  725. thr = &thr_info[thr_id];
  726. cgpu = thr->cgpu;
  727. if (cgpu->api != &opencl_api)
  728. continue;
  729. if (dev_from_id(thr_id) != gpu)
  730. continue;
  731. thr = &thr_info[thr_id];
  732. if (!thr) {
  733. applog(LOG_WARNING, "No reference to thread %d exists", thr_id);
  734. continue;
  735. }
  736. thr->rolling = thr->cgpu->rolling = 0;
  737. /* Reports the last time we tried to revive a sick GPU */
  738. gettimeofday(&thr->sick, NULL);
  739. if (!pthread_cancel(thr->pth)) {
  740. applog(LOG_WARNING, "Thread %d still exists, killing it off", thr_id);
  741. } else
  742. applog(LOG_WARNING, "Thread %d no longer exists", thr_id);
  743. }
  744. cgpu->enabled = true;
  745. for (thr_id = 0; thr_id < mining_threads; ++thr_id) {
  746. int virtual_gpu;
  747. thr = &thr_info[thr_id];
  748. cgpu = thr->cgpu;
  749. if (cgpu->api != &opencl_api)
  750. continue;
  751. if (dev_from_id(thr_id) != gpu)
  752. continue;
  753. virtual_gpu = cgpu->virtual_gpu;
  754. /* Lose this ram cause we may get stuck here! */
  755. //tq_freeze(thr->q);
  756. thr->q = tq_new();
  757. if (!thr->q)
  758. quit(1, "Failed to tq_new in reinit_gpu");
  759. /* Lose this ram cause we may dereference in the dying thread! */
  760. //free(clState);
  761. applog(LOG_INFO, "Reinit GPU thread %d", thr_id);
  762. clStates[thr_id] = initCl(virtual_gpu, name, sizeof(name));
  763. if (!clStates[thr_id]) {
  764. applog(LOG_ERR, "Failed to reinit GPU thread %d", thr_id);
  765. goto select_cgpu;
  766. }
  767. applog(LOG_INFO, "initCl() finished. Found %s", name);
  768. if (unlikely(thr_info_create(thr, NULL, miner_thread, thr))) {
  769. applog(LOG_ERR, "thread %d create failed", thr_id);
  770. return NULL;
  771. }
  772. applog(LOG_WARNING, "Thread %d restarted", thr_id);
  773. }
  774. gettimeofday(&now, NULL);
  775. get_datestamp(cgpu->init, &now);
  776. for (thr_id = 0; thr_id < mining_threads; ++thr_id) {
  777. thr = &thr_info[thr_id];
  778. cgpu = thr->cgpu;
  779. if (cgpu->api != &opencl_api)
  780. continue;
  781. if (dev_from_id(thr_id) != gpu)
  782. continue;
  783. tq_push(thr->q, &ping);
  784. }
  785. goto select_cgpu;
  786. out:
  787. return NULL;
  788. }
  789. #else
  790. void *reinit_gpu(void *userdata)
  791. {
  792. return NULL;
  793. }
  794. #endif
  795. #ifdef HAVE_OPENCL
  796. struct device_api opencl_api;
  797. static void opencl_detect()
  798. {
  799. int i;
  800. nDevs = clDevicesNum();
  801. if (nDevs < 0) {
  802. applog(LOG_ERR, "clDevicesNum returned error, no GPUs usable");
  803. nDevs = 0;
  804. }
  805. if (MAX_DEVICES - total_devices < nDevs)
  806. nDevs = MAX_DEVICES - total_devices;
  807. if (!nDevs)
  808. return;
  809. if (opt_kernel) {
  810. if (strcmp(opt_kernel, "poclbm") &&
  811. strcmp(opt_kernel, "phatk") &&
  812. strcmp(opt_kernel, "diakgcn") &&
  813. strcmp(opt_kernel, "diablo"))
  814. quit(1, "Invalid kernel name specified - must be poclbm or phatk");
  815. if (!strcmp(opt_kernel, "diakgcn"))
  816. chosen_kernel = KL_DIAKGCN;
  817. else if (!strcmp(opt_kernel, "poclbm"))
  818. chosen_kernel = KL_POCLBM;
  819. else if (!strcmp(opt_kernel, "diablo"))
  820. chosen_kernel = KL_DIABLO;
  821. else
  822. chosen_kernel = KL_PHATK;
  823. } else
  824. chosen_kernel = KL_NONE;
  825. for (i = 0; i < nDevs; ++i) {
  826. struct cgpu_info *cgpu;
  827. cgpu = devices[total_devices++] = &gpus[i];
  828. cgpu->enabled = true;
  829. cgpu->api = &opencl_api;
  830. cgpu->device_id = i;
  831. cgpu->threads = opt_g_threads;
  832. cgpu->virtual_gpu = i;
  833. }
  834. if (!opt_noadl)
  835. init_adl(nDevs);
  836. }
  837. static void reinit_opencl_device(struct cgpu_info *gpu)
  838. {
  839. tq_push(thr_info[gpur_thr_id].q, gpu);
  840. }
  841. #ifdef HAVE_ADL
  842. static void get_opencl_statline_before(char *buf, struct cgpu_info *gpu)
  843. {
  844. if (gpu->has_adl) {
  845. int gpuid = gpu->device_id;
  846. float gt = gpu_temp(gpuid);
  847. int gf = gpu_fanspeed(gpuid);
  848. int gp;
  849. if (gt != -1)
  850. tailsprintf(buf, "%5.1fC ", gt);
  851. else
  852. tailsprintf(buf, " ", gt);
  853. if (gf != -1)
  854. tailsprintf(buf, "%4dRPM ", gf);
  855. else if ((gp = gpu_fanpercent(gpuid)) != -1)
  856. tailsprintf(buf, "%3d%% ", gp);
  857. else
  858. tailsprintf(buf, " ");
  859. tailsprintf(buf, "| ");
  860. }
  861. }
  862. #endif
  863. static void get_opencl_statline(char *buf, struct cgpu_info *gpu)
  864. {
  865. tailsprintf(buf, " I:%2d", gpu->intensity);
  866. }
  867. struct opencl_thread_data {
  868. cl_int (*queue_kernel_parameters)(_clState *, dev_blk_ctx *);
  869. uint32_t *res;
  870. struct work *last_work;
  871. struct work _last_work;
  872. };
  873. static uint32_t *blank_res;
  874. static bool opencl_thread_prepare(struct thr_info *thr)
  875. {
  876. char name[256];
  877. struct timeval now;
  878. struct cgpu_info *cgpu = thr->cgpu;
  879. int gpu = cgpu->device_id;
  880. int virtual_gpu = cgpu->virtual_gpu;
  881. int i = thr->id;
  882. static bool failmessage = false;
  883. if (!blank_res)
  884. blank_res = calloc(BUFFERSIZE, 1);
  885. if (!blank_res) {
  886. applog(LOG_ERR, "Failed to calloc in opencl_thread_init");
  887. return false;
  888. }
  889. applog(LOG_INFO, "Init GPU thread %i GPU %i virtual GPU %i", i, gpu, virtual_gpu);
  890. clStates[i] = initCl(virtual_gpu, name, sizeof(name));
  891. if (!clStates[i]) {
  892. if (use_curses)
  893. enable_curses();
  894. applog(LOG_ERR, "Failed to init GPU thread %d, disabling device %d", i, gpu);
  895. if (!failmessage) {
  896. char *buf;
  897. applog(LOG_ERR, "Restarting the GPU from the menu will not fix this.");
  898. applog(LOG_ERR, "Try restarting cgminer.");
  899. failmessage = true;
  900. if (use_curses) {
  901. buf = curses_input("Press enter to continue");
  902. if (buf)
  903. free(buf);
  904. }
  905. }
  906. cgpu->enabled = false;
  907. cgpu->status = LIFE_NOSTART;
  908. return false;
  909. }
  910. applog(LOG_INFO, "initCl() finished. Found %s", name);
  911. gettimeofday(&now, NULL);
  912. get_datestamp(cgpu->init, &now);
  913. have_opencl = true;
  914. return true;
  915. }
  916. static bool opencl_thread_init(struct thr_info *thr)
  917. {
  918. const int thr_id = thr->id;
  919. struct cgpu_info *gpu = thr->cgpu;
  920. struct opencl_thread_data *thrdata;
  921. _clState *clState = clStates[thr_id];
  922. cl_int status;
  923. thrdata = calloc(1, sizeof(*thrdata));
  924. thr->cgpu_data = thrdata;
  925. if (!thrdata) {
  926. applog(LOG_ERR, "Failed to calloc in opencl_thread_init");
  927. return false;
  928. }
  929. switch (clState->chosen_kernel) {
  930. case KL_POCLBM:
  931. thrdata->queue_kernel_parameters = &queue_poclbm_kernel;
  932. break;
  933. case KL_PHATK:
  934. default:
  935. thrdata->queue_kernel_parameters = &queue_phatk_kernel;
  936. break;
  937. case KL_DIAKGCN:
  938. thrdata->queue_kernel_parameters = &queue_diakgcn_kernel;
  939. break;
  940. case KL_DIABLO:
  941. thrdata->queue_kernel_parameters = &queue_diablo_kernel;
  942. break;
  943. }
  944. thrdata->res = calloc(BUFFERSIZE, 1);
  945. if (!thrdata->res) {
  946. free(thrdata);
  947. applog(LOG_ERR, "Failed to calloc in opencl_thread_init");
  948. return false;
  949. }
  950. status = clEnqueueWriteBuffer(clState->commandQueue, clState->outputBuffer, CL_TRUE, 0,
  951. BUFFERSIZE, blank_res, 0, NULL, NULL);
  952. if (unlikely(status != CL_SUCCESS)) {
  953. applog(LOG_ERR, "Error: clEnqueueWriteBuffer failed.");
  954. return false;
  955. }
  956. gpu->status = LIFE_WELL;
  957. return true;
  958. }
  959. static void opencl_free_work(struct thr_info *thr, struct work *work)
  960. {
  961. const int thr_id = thr->id;
  962. struct opencl_thread_data *thrdata = thr->cgpu_data;
  963. _clState *clState = clStates[thr_id];
  964. clFinish(clState->commandQueue);
  965. if (thrdata->res[FOUND]) {
  966. thrdata->last_work = &thrdata->_last_work;
  967. memcpy(thrdata->last_work, work, sizeof(*thrdata->last_work));
  968. }
  969. }
  970. static bool opencl_prepare_work(struct thr_info __maybe_unused *thr, struct work *work)
  971. {
  972. precalc_hash(&work->blk, (uint32_t *)(work->midstate), (uint32_t *)(work->data + 64));
  973. return true;
  974. }
  975. static uint64_t opencl_scanhash(struct thr_info *thr, struct work *work,
  976. uint64_t __maybe_unused max_nonce)
  977. {
  978. const int thr_id = thr->id;
  979. struct opencl_thread_data *thrdata = thr->cgpu_data;
  980. struct cgpu_info *gpu = thr->cgpu;
  981. _clState *clState = clStates[thr_id];
  982. const cl_kernel *kernel = &clState->kernel;
  983. double gpu_ms_average = 7;
  984. cl_int status;
  985. size_t globalThreads[1];
  986. size_t localThreads[1] = { clState->work_size };
  987. unsigned int threads;
  988. unsigned int hashes;
  989. struct timeval tv_gpustart, tv_gpuend, diff;
  990. suseconds_t gpu_us;
  991. gettimeofday(&tv_gpustart, NULL);
  992. timeval_subtract(&diff, &tv_gpustart, &tv_gpuend);
  993. /* This finish flushes the readbuffer set with CL_FALSE later */
  994. clFinish(clState->commandQueue);
  995. gettimeofday(&tv_gpuend, NULL);
  996. timeval_subtract(&diff, &tv_gpuend, &tv_gpustart);
  997. gpu_us = diff.tv_sec * 1000000 + diff.tv_usec;
  998. decay_time(&gpu_ms_average, gpu_us / 1000);
  999. if (gpu->dynamic) {
  1000. /* Try to not let the GPU be out for longer than 6ms, but
  1001. * increase intensity when the system is idle, unless
  1002. * dynamic is disabled. */
  1003. if (gpu_ms_average > 7) {
  1004. if (gpu->intensity > MIN_INTENSITY)
  1005. --gpu->intensity;
  1006. } else if (gpu_ms_average < 3) {
  1007. if (gpu->intensity < MAX_INTENSITY)
  1008. ++gpu->intensity;
  1009. }
  1010. }
  1011. set_threads_hashes(clState->preferred_vwidth, &threads, &hashes, globalThreads,
  1012. localThreads[0], gpu->intensity);
  1013. status = thrdata->queue_kernel_parameters(clState, &work->blk);
  1014. if (unlikely(status != CL_SUCCESS)) {
  1015. applog(LOG_ERR, "Error: clSetKernelArg of all params failed.");
  1016. return 0;
  1017. }
  1018. /* MAXBUFFERS entry is used as a flag to say nonces exist */
  1019. if (thrdata->res[FOUND]) {
  1020. /* Clear the buffer again */
  1021. status = clEnqueueWriteBuffer(clState->commandQueue, clState->outputBuffer, CL_FALSE, 0,
  1022. BUFFERSIZE, blank_res, 0, NULL, NULL);
  1023. if (unlikely(status != CL_SUCCESS)) {
  1024. applog(LOG_ERR, "Error: clEnqueueWriteBuffer failed.");
  1025. return 0;
  1026. }
  1027. if (unlikely(thrdata->last_work)) {
  1028. if (opt_debug)
  1029. applog(LOG_DEBUG, "GPU %d found something in last work?", gpu->device_id);
  1030. postcalc_hash_async(thr, thrdata->last_work, thrdata->res);
  1031. thrdata->last_work = NULL;
  1032. } else {
  1033. if (opt_debug)
  1034. applog(LOG_DEBUG, "GPU %d found something?", gpu->device_id);
  1035. postcalc_hash_async(thr, work, thrdata->res);
  1036. }
  1037. memset(thrdata->res, 0, BUFFERSIZE);
  1038. clFinish(clState->commandQueue);
  1039. }
  1040. status = clEnqueueNDRangeKernel(clState->commandQueue, *kernel, 1, NULL,
  1041. globalThreads, localThreads, 0, NULL, NULL);
  1042. if (unlikely(status != CL_SUCCESS)) {
  1043. applog(LOG_ERR, "Error: Enqueueing kernel onto command queue. (clEnqueueNDRangeKernel)");
  1044. return 0;
  1045. }
  1046. status = clEnqueueReadBuffer(clState->commandQueue, clState->outputBuffer, CL_FALSE, 0,
  1047. BUFFERSIZE, thrdata->res, 0, NULL, NULL);
  1048. if (unlikely(status != CL_SUCCESS)) {
  1049. applog(LOG_ERR, "Error: clEnqueueReadBuffer failed. (clEnqueueReadBuffer)");
  1050. return 0;
  1051. }
  1052. work->blk.nonce += hashes;
  1053. return hashes;
  1054. }
  1055. static void opencl_thread_shutdown(struct thr_info *thr)
  1056. {
  1057. const int thr_id = thr->id;
  1058. _clState *clState = clStates[thr_id];
  1059. clReleaseCommandQueue(clState->commandQueue);
  1060. clReleaseKernel(clState->kernel);
  1061. clReleaseProgram(clState->program);
  1062. clReleaseContext(clState->context);
  1063. }
  1064. struct device_api opencl_api = {
  1065. .name = "GPU",
  1066. .api_detect = opencl_detect,
  1067. .reinit_device = reinit_opencl_device,
  1068. #ifdef HAVE_ADL
  1069. .get_statline_before = get_opencl_statline_before,
  1070. #endif
  1071. .get_statline = get_opencl_statline,
  1072. .thread_prepare = opencl_thread_prepare,
  1073. .thread_init = opencl_thread_init,
  1074. .free_work = opencl_free_work,
  1075. .prepare_work = opencl_prepare_work,
  1076. .scanhash = opencl_scanhash,
  1077. .thread_shutdown = opencl_thread_shutdown,
  1078. };
  1079. #endif