device-gpu.c 30 KB

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