driver-opencl.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769
  1. /*
  2. * Copyright 2011-2012 Con Kolivas
  3. * Copyright 2011-2013 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 3 of the License, or (at your option)
  9. * any later version. See COPYING for more details.
  10. */
  11. #include "config.h"
  12. #ifdef HAVE_CURSES
  13. // Must be before stdbool, since pdcurses typedefs bool :/
  14. #include <curses.h>
  15. #endif
  16. #ifndef WIN32
  17. #include <dlfcn.h>
  18. #else
  19. #include <windows.h>
  20. #endif
  21. #include <ctype.h>
  22. #include <math.h>
  23. #include <string.h>
  24. #include <stdbool.h>
  25. #include <stdint.h>
  26. #include <stdio.h>
  27. #include <sys/types.h>
  28. #ifndef WIN32
  29. #include <sys/resource.h>
  30. #endif
  31. #define OMIT_OPENCL_API
  32. #include "compat.h"
  33. #include "miner.h"
  34. #include "deviceapi.h"
  35. #include "driver-opencl.h"
  36. #include "findnonce.h"
  37. #include "ocl.h"
  38. #include "adl.h"
  39. #include "util.h"
  40. /* TODO: cleanup externals ********************/
  41. #ifdef HAVE_OPENCL
  42. /* Platform API */
  43. CL_API_ENTRY cl_int CL_API_CALL
  44. (*clGetPlatformIDs)(cl_uint /* num_entries */,
  45. cl_platform_id * /* platforms */,
  46. cl_uint * /* num_platforms */) CL_API_SUFFIX__VERSION_1_0;
  47. CL_API_ENTRY cl_int CL_API_CALL
  48. (*clGetPlatformInfo)(cl_platform_id /* platform */,
  49. cl_platform_info /* param_name */,
  50. size_t /* param_value_size */,
  51. void * /* param_value */,
  52. size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
  53. /* Device APIs */
  54. CL_API_ENTRY cl_int CL_API_CALL
  55. (*clGetDeviceIDs)(cl_platform_id /* platform */,
  56. cl_device_type /* device_type */,
  57. cl_uint /* num_entries */,
  58. cl_device_id * /* devices */,
  59. cl_uint * /* num_devices */) CL_API_SUFFIX__VERSION_1_0;
  60. CL_API_ENTRY cl_int CL_API_CALL
  61. (*clGetDeviceInfo)(cl_device_id /* device */,
  62. cl_device_info /* param_name */,
  63. size_t /* param_value_size */,
  64. void * /* param_value */,
  65. size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
  66. /* Context APIs */
  67. CL_API_ENTRY cl_context CL_API_CALL
  68. (*clCreateContextFromType)(const cl_context_properties * /* properties */,
  69. cl_device_type /* device_type */,
  70. void (CL_CALLBACK * /* pfn_notify*/ )(const char *, const void *, size_t, void *),
  71. void * /* user_data */,
  72. cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
  73. CL_API_ENTRY cl_int CL_API_CALL
  74. (*clReleaseContext)(cl_context /* context */) CL_API_SUFFIX__VERSION_1_0;
  75. /* Command Queue APIs */
  76. CL_API_ENTRY cl_command_queue CL_API_CALL
  77. (*clCreateCommandQueue)(cl_context /* context */,
  78. cl_device_id /* device */,
  79. cl_command_queue_properties /* properties */,
  80. cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
  81. CL_API_ENTRY cl_int CL_API_CALL
  82. (*clReleaseCommandQueue)(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0;
  83. /* Memory Object APIs */
  84. CL_API_ENTRY cl_mem CL_API_CALL
  85. (*clCreateBuffer)(cl_context /* context */,
  86. cl_mem_flags /* flags */,
  87. size_t /* size */,
  88. void * /* host_ptr */,
  89. cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
  90. /* Program Object APIs */
  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. CL_API_ENTRY cl_program CL_API_CALL
  98. (*clCreateProgramWithBinary)(cl_context /* context */,
  99. cl_uint /* num_devices */,
  100. const cl_device_id * /* device_list */,
  101. const size_t * /* lengths */,
  102. const unsigned char ** /* binaries */,
  103. cl_int * /* binary_status */,
  104. cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
  105. CL_API_ENTRY cl_int CL_API_CALL
  106. (*clReleaseProgram)(cl_program /* program */) CL_API_SUFFIX__VERSION_1_0;
  107. CL_API_ENTRY cl_int CL_API_CALL
  108. (*clBuildProgram)(cl_program /* program */,
  109. cl_uint /* num_devices */,
  110. const cl_device_id * /* device_list */,
  111. const char * /* options */,
  112. void (CL_CALLBACK * /* pfn_notify */)(cl_program /* program */, void * /* user_data */),
  113. void * /* user_data */) CL_API_SUFFIX__VERSION_1_0;
  114. CL_API_ENTRY cl_int CL_API_CALL
  115. (*clGetProgramInfo)(cl_program /* program */,
  116. cl_program_info /* param_name */,
  117. size_t /* param_value_size */,
  118. void * /* param_value */,
  119. size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
  120. CL_API_ENTRY cl_int CL_API_CALL
  121. (*clGetProgramBuildInfo)(cl_program /* program */,
  122. cl_device_id /* device */,
  123. cl_program_build_info /* param_name */,
  124. size_t /* param_value_size */,
  125. void * /* param_value */,
  126. size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
  127. /* Kernel Object APIs */
  128. CL_API_ENTRY cl_kernel CL_API_CALL
  129. (*clCreateKernel)(cl_program /* program */,
  130. const char * /* kernel_name */,
  131. cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
  132. CL_API_ENTRY cl_int CL_API_CALL
  133. (*clReleaseKernel)(cl_kernel /* kernel */) CL_API_SUFFIX__VERSION_1_0;
  134. CL_API_ENTRY cl_int CL_API_CALL
  135. (*clSetKernelArg)(cl_kernel /* kernel */,
  136. cl_uint /* arg_index */,
  137. size_t /* arg_size */,
  138. const void * /* arg_value */) CL_API_SUFFIX__VERSION_1_0;
  139. /* Flush and Finish APIs */
  140. CL_API_ENTRY cl_int CL_API_CALL
  141. (*clFinish)(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0;
  142. /* Enqueued Commands APIs */
  143. CL_API_ENTRY cl_int CL_API_CALL
  144. (*clEnqueueReadBuffer)(cl_command_queue /* command_queue */,
  145. cl_mem /* buffer */,
  146. cl_bool /* blocking_read */,
  147. size_t /* offset */,
  148. size_t /* size */,
  149. void * /* ptr */,
  150. cl_uint /* num_events_in_wait_list */,
  151. const cl_event * /* event_wait_list */,
  152. cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0;
  153. CL_API_ENTRY cl_int CL_API_CALL
  154. (*clEnqueueWriteBuffer)(cl_command_queue /* command_queue */,
  155. cl_mem /* buffer */,
  156. cl_bool /* blocking_write */,
  157. size_t /* offset */,
  158. size_t /* size */,
  159. const 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. CL_API_ENTRY cl_int CL_API_CALL
  164. (*clEnqueueNDRangeKernel)(cl_command_queue /* command_queue */,
  165. cl_kernel /* kernel */,
  166. cl_uint /* work_dim */,
  167. const size_t * /* global_work_offset */,
  168. const size_t * /* global_work_size */,
  169. const size_t * /* local_work_size */,
  170. cl_uint /* num_events_in_wait_list */,
  171. const cl_event * /* event_wait_list */,
  172. cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0;
  173. #ifdef WIN32
  174. #define dlsym (void*)GetProcAddress
  175. #define dlclose FreeLibrary
  176. #endif
  177. #define LOAD_OCL_SYM(sym) do { \
  178. if (!(sym = dlsym(cl, #sym))) { \
  179. applog(LOG_ERR, "Failed to load OpenCL symbol " #sym ", no GPUs usable"); \
  180. dlclose(cl); \
  181. return false; \
  182. } \
  183. } while(0)
  184. static bool
  185. load_opencl_symbols() {
  186. #if defined(__APPLE__)
  187. void *cl = dlopen("/System/Library/Frameworks/OpenCL.framework/Versions/Current/OpenCL", RTLD_LAZY);
  188. #elif !defined(WIN32)
  189. void *cl = dlopen("libOpenCL.so", RTLD_LAZY);
  190. #else
  191. HMODULE cl = LoadLibrary("OpenCL.dll");
  192. #endif
  193. if (!cl)
  194. {
  195. applog(LOG_ERR, "Failed to load OpenCL library, no GPUs usable");
  196. return false;
  197. }
  198. LOAD_OCL_SYM(clGetPlatformIDs);
  199. LOAD_OCL_SYM(clGetPlatformInfo);
  200. LOAD_OCL_SYM(clGetDeviceIDs);
  201. LOAD_OCL_SYM(clGetDeviceInfo);
  202. LOAD_OCL_SYM(clCreateContextFromType);
  203. LOAD_OCL_SYM(clReleaseContext);
  204. LOAD_OCL_SYM(clCreateCommandQueue);
  205. LOAD_OCL_SYM(clReleaseCommandQueue);
  206. LOAD_OCL_SYM(clCreateBuffer);
  207. LOAD_OCL_SYM(clCreateProgramWithSource);
  208. LOAD_OCL_SYM(clCreateProgramWithBinary);
  209. LOAD_OCL_SYM(clReleaseProgram);
  210. LOAD_OCL_SYM(clBuildProgram);
  211. LOAD_OCL_SYM(clGetProgramInfo);
  212. LOAD_OCL_SYM(clGetProgramBuildInfo);
  213. LOAD_OCL_SYM(clCreateKernel);
  214. LOAD_OCL_SYM(clReleaseKernel);
  215. LOAD_OCL_SYM(clSetKernelArg);
  216. LOAD_OCL_SYM(clFinish);
  217. LOAD_OCL_SYM(clEnqueueReadBuffer);
  218. LOAD_OCL_SYM(clEnqueueWriteBuffer);
  219. LOAD_OCL_SYM(clEnqueueNDRangeKernel);
  220. return true;
  221. }
  222. #endif
  223. #ifdef HAVE_CURSES
  224. extern WINDOW *mainwin, *statuswin, *logwin;
  225. extern void enable_curses(void);
  226. #endif
  227. extern int mining_threads;
  228. extern int opt_g_threads;
  229. extern bool ping;
  230. extern bool opt_loginput;
  231. extern char *opt_kernel_path;
  232. extern int gpur_thr_id;
  233. extern bool opt_noadl;
  234. extern bool have_opencl;
  235. static _clState *clStates[MAX_GPUDEVICES];
  236. extern void *miner_thread(void *userdata);
  237. extern int dev_from_id(int thr_id);
  238. extern void decay_time(double *f, double fadd);
  239. /**********************************************/
  240. #ifdef HAVE_ADL
  241. extern float gpu_temp(int gpu);
  242. extern int gpu_fanspeed(int gpu);
  243. extern int gpu_fanpercent(int gpu);
  244. #endif
  245. void opencl_early_init()
  246. {
  247. static struct opencl_device_data dataarray[MAX_GPUDEVICES];
  248. for (int i = 0; i < MAX_GPUDEVICES; ++i)
  249. {
  250. struct opencl_device_data * const data = &dataarray[i];
  251. *data = (struct opencl_device_data){
  252. .dynamic = true,
  253. };
  254. gpus[i] = (struct cgpu_info){
  255. .device_data = data,
  256. };
  257. }
  258. }
  259. static
  260. const char *_set_list(char * const arg, const char * const emsg, bool (*set_func)(struct cgpu_info *, const char *))
  261. {
  262. int i, device = 0;
  263. char *nextptr, buf[0x10];
  264. nextptr = strtok(arg, ",");
  265. if (nextptr == NULL)
  266. return emsg;
  267. if (!set_func(&gpus[device++], nextptr))
  268. return emsg;
  269. snprintf(buf, sizeof(buf), "%s", nextptr);
  270. while ((nextptr = strtok(NULL, ",")) != NULL)
  271. if (!set_func(&gpus[device++], nextptr))
  272. return emsg;
  273. if (device == 1) {
  274. for (i = device; i < MAX_GPUDEVICES; i++)
  275. set_func(&gpus[i], buf);
  276. }
  277. return NULL;
  278. }
  279. #define _SET_INTERFACE(PNAME) \
  280. static \
  281. const char *opencl_init_ ## PNAME (struct cgpu_info * const proc, const char * const optname, const char * const newvalue, char * const replybuf, enum bfg_set_device_replytype * const out_success) \
  282. { \
  283. if (!_set_ ## PNAME (proc, newvalue)) \
  284. return "Invalid value for " #PNAME; \
  285. return NULL; \
  286. } \
  287. // END OF _SET_INTERFACE
  288. #define _SET_INT_LIST2(PNAME, VCHECK, FIELD) \
  289. static \
  290. bool _set_ ## PNAME (struct cgpu_info * const cgpu, const char * const _val) \
  291. { \
  292. const int v = atoi(_val); \
  293. if (!(VCHECK)) \
  294. return false; \
  295. FIELD = v; \
  296. return true; \
  297. } \
  298. _SET_INTERFACE(PNAME) \
  299. const char *set_ ## PNAME(char *arg) \
  300. { \
  301. return _set_list(arg, "Invalid value passed to " #PNAME, _set_ ## PNAME); \
  302. } \
  303. // END OF _SET_INT_LIST
  304. #define _SET_INT_LIST(PNAME, VCHECK, FIELD) \
  305. _SET_INT_LIST2(PNAME, VCHECK, ((struct opencl_device_data *)cgpu->device_data)->FIELD)
  306. #ifdef HAVE_OPENCL
  307. _SET_INT_LIST(vector , (v == 1 || v == 2 || v == 4), vwidth )
  308. _SET_INT_LIST(worksize, (v >= 1 && v <= 9999) , work_size)
  309. #ifdef USE_SCRYPT
  310. _SET_INT_LIST(shaders , true, shaders)
  311. _SET_INT_LIST(lookup_gap , true, opt_lg )
  312. _SET_INT_LIST(thread_concurrency, true, opt_tc )
  313. #endif
  314. static
  315. enum cl_kernels select_kernel(const char * const arg)
  316. {
  317. if (!strcmp(arg, "diablo"))
  318. return KL_DIABLO;
  319. if (!strcmp(arg, "diakgcn"))
  320. return KL_DIAKGCN;
  321. if (!strcmp(arg, "poclbm"))
  322. return KL_POCLBM;
  323. if (!strcmp(arg, "phatk"))
  324. return KL_PHATK;
  325. #ifdef USE_SCRYPT
  326. if (!strcmp(arg, "scrypt"))
  327. return KL_SCRYPT;
  328. #endif
  329. return KL_NONE;
  330. }
  331. static
  332. bool _set_kernel(struct cgpu_info * const cgpu, const char * const _val)
  333. {
  334. const enum cl_kernels kern = select_kernel(_val);
  335. if (kern == KL_NONE)
  336. return false;
  337. struct opencl_device_data * const data = cgpu->device_data;
  338. data->kernel = kern;
  339. return true;
  340. }
  341. _SET_INTERFACE(kernel)
  342. const char *set_kernel(char *arg)
  343. {
  344. if (opt_scrypt)
  345. return "Cannot specify a kernel with scrypt";
  346. return _set_list(arg, "Invalid value passed to set_kernel", _set_kernel);
  347. }
  348. #endif
  349. #ifdef HAVE_ADL
  350. /* This function allows us to map an adl device to an opencl device for when
  351. * simple enumeration has failed to match them. */
  352. static
  353. const char *opencl_init_gpu_map(struct cgpu_info * const proc, const char * const optname, const char * const newvalue, char * const replybuf, enum bfg_set_device_replytype * const out_success)
  354. {
  355. struct opencl_device_data * const data = proc->device_data;
  356. data->virtual_adl = atoi(newvalue);
  357. data->mapped = true;
  358. return NULL;
  359. }
  360. char *set_gpu_map(char *arg)
  361. {
  362. struct opencl_device_data *data;
  363. int val1 = 0, val2 = 0;
  364. char *nextptr;
  365. nextptr = strtok(arg, ",");
  366. if (nextptr == NULL)
  367. return "Invalid parameters for set gpu map";
  368. if (sscanf(arg, "%d:%d", &val1, &val2) != 2)
  369. return "Invalid description for map pair";
  370. if (val1 < 0 || val1 > MAX_GPUDEVICES || val2 < 0 || val2 > MAX_GPUDEVICES)
  371. return "Invalid value passed to set_gpu_map";
  372. data = gpus[val1].device_data;
  373. data->virtual_adl = val2;
  374. data->mapped = true;
  375. while ((nextptr = strtok(NULL, ",")) != NULL) {
  376. if (sscanf(nextptr, "%d:%d", &val1, &val2) != 2)
  377. return "Invalid description for map pair";
  378. if (val1 < 0 || val1 > MAX_GPUDEVICES || val2 < 0 || val2 > MAX_GPUDEVICES)
  379. return "Invalid value passed to set_gpu_map";
  380. data = gpus[val1].device_data;
  381. data->virtual_adl = val2;
  382. data->mapped = true;
  383. }
  384. return NULL;
  385. }
  386. static
  387. bool _set_gpu_engine(struct cgpu_info * const cgpu, const char * const _val)
  388. {
  389. int val1, val2;
  390. get_intrange(_val, &val1, &val2);
  391. if (val1 < 0 || val1 > 9999 || val2 < 0 || val2 > 9999)
  392. return false;
  393. struct opencl_device_data * const data = cgpu->device_data;
  394. data->min_engine = val1;
  395. data->gpu_engine = val2;
  396. return true;
  397. }
  398. _SET_INTERFACE(gpu_engine)
  399. const char *set_gpu_engine(char *arg)
  400. {
  401. return _set_list(arg, "Invalid value passed to set_gpu_engine", _set_gpu_engine);
  402. }
  403. static
  404. const char *opencl_set_gpu_engine(struct cgpu_info * const proc, const char * const optname, const char * const newvalue, char * const replybuf, enum bfg_set_device_replytype * const out_success)
  405. {
  406. if (set_engineclock(proc->device_id, atoi(newvalue)))
  407. return "Failed to set gpu_engine";
  408. return NULL;
  409. }
  410. static
  411. bool _set_gpu_fan(struct cgpu_info * const cgpu, const char * const _val)
  412. {
  413. int val1, val2;
  414. get_intrange(_val, &val1, &val2);
  415. if (val1 < 0 || val1 > 100 || val2 < 0 || val2 > 100)
  416. return false;
  417. struct opencl_device_data * const data = cgpu->device_data;
  418. data->min_fan = val1;
  419. data->gpu_fan = val2;
  420. return true;
  421. }
  422. _SET_INTERFACE(gpu_fan)
  423. const char *set_gpu_fan(char *arg)
  424. {
  425. return _set_list(arg, "Invalid value passed to set_gpu_fan", _set_gpu_fan);
  426. }
  427. static
  428. const char *opencl_set_gpu_fan(struct cgpu_info * const proc, const char * const optname, const char * const newvalue, char * const replybuf, enum bfg_set_device_replytype * const out_success)
  429. {
  430. if (set_fanspeed(proc->device_id, atoi(newvalue)))
  431. return "Failed to set gpu_fan";
  432. return NULL;
  433. }
  434. _SET_INT_LIST(gpu_memclock , (v >= 1 && v < 9999), gpu_memclock )
  435. static
  436. const char *opencl_set_gpu_memclock(struct cgpu_info * const proc, const char * const optname, const char * const newvalue, char * const replybuf, enum bfg_set_device_replytype * const out_success)
  437. {
  438. if (set_memoryclock(proc->device_id, atoi(newvalue)))
  439. return "Failed to set gpu_memclock";
  440. return NULL;
  441. }
  442. _SET_INT_LIST(gpu_memdiff , (v >= -9999 && v <= 9999), gpu_memdiff )
  443. static
  444. const char *opencl_set_gpu_memdiff(struct cgpu_info * const proc, const char * const optname, const char * const newvalue, char * const replybuf, enum bfg_set_device_replytype * const out_success)
  445. {
  446. struct opencl_device_data * const data = proc->device_data;
  447. if (!_set_gpu_memdiff(proc, newvalue))
  448. return "Invalid value for gpu_memdiff";
  449. set_engineclock(proc->device_id, data->gpu_engine);
  450. return NULL;
  451. }
  452. _SET_INT_LIST(gpu_powertune, (v >= -99 && v <= 99), gpu_powertune)
  453. _SET_INT_LIST(gpu_vddc , (v >= 0 && v < 9999), gpu_vddc )
  454. static
  455. const char *opencl_set_gpu_vddc(struct cgpu_info * const proc, const char * const optname, const char * const newvalue, char * const replybuf, enum bfg_set_device_replytype * const out_success)
  456. {
  457. if (set_vddc(proc->device_id, atof(newvalue)))
  458. return "Failed to set gpu_vddc";
  459. return NULL;
  460. }
  461. _SET_INT_LIST(temp_overheat, (v >= 0 && v < 200), adl.overtemp )
  462. #endif
  463. #ifdef HAVE_OPENCL
  464. // SHA256d "intensity" has an artificial offset of -15
  465. double oclthreads_to_intensity(const unsigned long oclthreads, const bool is_sha256d)
  466. {
  467. double intensity = log2(oclthreads);
  468. if (is_sha256d)
  469. intensity -= 15.;
  470. return intensity;
  471. }
  472. unsigned long intensity_to_oclthreads(double intensity, const bool is_sha256d)
  473. {
  474. if (is_sha256d)
  475. intensity += 15;
  476. return pow(2, intensity);
  477. }
  478. double oclthreads_to_xintensity(const unsigned long oclthreads, const cl_uint max_compute_units)
  479. {
  480. return (double)oclthreads / (double)max_compute_units / 64.;
  481. }
  482. unsigned long xintensity_to_oclthreads(const double xintensity, const cl_uint max_compute_units)
  483. {
  484. return xintensity * max_compute_units * 0x40;
  485. }
  486. static
  487. bool _set_intensity(struct cgpu_info * const cgpu, const char *_val)
  488. {
  489. struct opencl_device_data * const data = cgpu->device_data;
  490. data->dynamic = false;
  491. data->_init_xintensity = 0;
  492. if (!strncasecmp(_val, "d", 1))
  493. {
  494. data->dynamic = true;
  495. ++_val;
  496. }
  497. if (!strncasecmp(_val, "x", 1))
  498. {
  499. const double v = atof(&_val[1]);
  500. if (v < 1 || v > 9999)
  501. return false;
  502. if (cgpu->thr)
  503. {
  504. struct thr_info * const thr = cgpu->thr[0];
  505. const int thr_id = thr->id;
  506. _clState * const clState = clStates[thr_id];
  507. data->oclthreads = xintensity_to_oclthreads(v, clState->max_compute_units);
  508. }
  509. data->_init_xintensity = v;
  510. }
  511. else
  512. if (isdigit(_val[0]))
  513. {
  514. const double v = atof(_val);
  515. if (v < MIN_INTENSITY || v > MAX_GPU_INTENSITY)
  516. return false;
  517. data->oclthreads = intensity_to_oclthreads(v, !opt_scrypt);
  518. }
  519. pause_dynamic_threads(cgpu->device_id);
  520. return true;
  521. }
  522. _SET_INTERFACE(intensity)
  523. const char *set_intensity(char *arg)
  524. {
  525. return _set_list(arg, "Invalid value passed to intensity", _set_intensity);
  526. }
  527. _SET_INT_LIST2(gpu_threads, (v >= 1 && v <= 10), cgpu->threads)
  528. #endif
  529. void write_config_opencl(FILE * const fcfg)
  530. {
  531. #ifdef HAVE_ADL
  532. if (opt_reorder)
  533. fprintf(fcfg, ",\n\"gpu-reorder\" : true");
  534. #endif
  535. }
  536. #ifdef HAVE_OPENCL
  537. BFG_REGISTER_DRIVER(opencl_api)
  538. static const struct bfg_set_device_definition opencl_set_device_funcs_probe[];
  539. static const struct bfg_set_device_definition opencl_set_device_funcs[];
  540. char *print_ndevs_and_exit(int *ndevs)
  541. {
  542. opt_log_output = true;
  543. opencl_api.drv_detect();
  544. clear_adl(*ndevs);
  545. applog(LOG_INFO, "%i GPU devices max detected", *ndevs);
  546. exit(*ndevs);
  547. }
  548. #endif
  549. struct cgpu_info gpus[MAX_GPUDEVICES]; /* Maximum number apparently possible */
  550. struct cgpu_info *cpus;
  551. #ifdef HAVE_OPENCL
  552. /* In dynamic mode, only the first thread of each device will be in use.
  553. * This potentially could start a thread that was stopped with the start-stop
  554. * options if one were to disable dynamic from the menu on a paused GPU */
  555. void pause_dynamic_threads(int gpu)
  556. {
  557. struct cgpu_info *cgpu = &gpus[gpu];
  558. struct opencl_device_data * const data = cgpu->device_data;
  559. int i;
  560. for (i = 1; i < cgpu->threads; i++) {
  561. struct thr_info *thr;
  562. thr = cgpu->thr[i];
  563. if (!thr->pause && data->dynamic) {
  564. applog(LOG_WARNING, "Disabling extra threads due to dynamic mode.");
  565. applog(LOG_WARNING, "Tune dynamic intensity with --gpu-dyninterval");
  566. }
  567. thr->pause = data->dynamic;
  568. if (!data->dynamic && cgpu->deven != DEV_DISABLED)
  569. mt_enable(thr);
  570. }
  571. }
  572. struct device_drv opencl_api;
  573. #endif /* HAVE_OPENCL */
  574. #if defined(HAVE_OPENCL) && defined(HAVE_CURSES)
  575. static
  576. void opencl_wlogprint_status(struct cgpu_info *cgpu)
  577. {
  578. struct opencl_device_data * const data = cgpu->device_data;
  579. struct thr_info *thr = cgpu->thr[0];
  580. const int thr_id = thr->id;
  581. _clState * const clState = clStates[thr_id];
  582. int i;
  583. char checkin[40];
  584. double displayed_rolling;
  585. bool mhash_base = !(cgpu->rolling < 1);
  586. char logline[255];
  587. strcpy(logline, ""); // In case it has no data
  588. {
  589. double intensity = oclthreads_to_intensity(data->oclthreads, !opt_scrypt);
  590. double xintensity = oclthreads_to_xintensity(data->oclthreads, clState->max_compute_units);
  591. const char *iunit = "";
  592. if (xintensity - (int)xintensity < intensity - (int)intensity)
  593. {
  594. intensity = xintensity;
  595. iunit = "x";
  596. }
  597. tailsprintf(logline, sizeof(logline), "I:%s%s%g ",
  598. (data->dynamic ? "d" : ""),
  599. iunit,
  600. intensity);
  601. }
  602. #ifdef HAVE_ADL
  603. if (data->has_adl) {
  604. int engineclock = 0, memclock = 0, activity = 0, fanspeed = 0, fanpercent = 0, powertune = 0;
  605. float temp = 0, vddc = 0;
  606. if (gpu_stats(cgpu->device_id, &temp, &engineclock, &memclock, &vddc, &activity, &fanspeed, &fanpercent, &powertune)) {
  607. if (fanspeed != -1 || fanpercent != -1) {
  608. tailsprintf(logline, sizeof(logline), "F:");
  609. if (fanspeed > 9999)
  610. fanspeed = 9999;
  611. if (fanpercent != -1)
  612. {
  613. tailsprintf(logline, sizeof(logline), "%d%%", fanpercent);
  614. if (fanspeed != -1)
  615. tailsprintf(logline, sizeof(logline), "(%dRPM)", fanspeed);
  616. }
  617. else
  618. tailsprintf(logline, sizeof(logline), "%dRPM", fanspeed);
  619. tailsprintf(logline, sizeof(logline), " ");
  620. }
  621. if (engineclock != -1)
  622. tailsprintf(logline, sizeof(logline), "E:%dMHz ", engineclock);
  623. if (memclock != -1)
  624. tailsprintf(logline, sizeof(logline), "M:%dMHz ", memclock);
  625. if (vddc != -1)
  626. tailsprintf(logline, sizeof(logline), "V:%.3fV ", vddc);
  627. if (activity != -1)
  628. tailsprintf(logline, sizeof(logline), "A:%d%% ", activity);
  629. if (powertune != -1)
  630. tailsprintf(logline, sizeof(logline), "P:%d%%", powertune);
  631. }
  632. }
  633. #endif
  634. wlogprint("%s\n", logline);
  635. wlogprint("Last initialised: %s\n", cgpu->init);
  636. for (i = 0; i < mining_threads; i++) {
  637. thr = get_thread(i);
  638. if (thr->cgpu != cgpu)
  639. continue;
  640. get_datestamp(checkin, sizeof(checkin), time(NULL) - timer_elapsed(&thr->last, NULL));
  641. displayed_rolling = thr->rolling;
  642. if (!mhash_base)
  643. displayed_rolling *= 1000;
  644. snprintf(logline, sizeof(logline), "Thread %d: %.1f %sh/s %s ", i, displayed_rolling, mhash_base ? "M" : "K" , cgpu->deven != DEV_DISABLED ? "Enabled" : "Disabled");
  645. switch (cgpu->status) {
  646. default:
  647. case LIFE_WELL:
  648. tailsprintf(logline, sizeof(logline), "ALIVE");
  649. break;
  650. case LIFE_SICK:
  651. tailsprintf(logline, sizeof(logline), "SICK reported in %s", checkin);
  652. break;
  653. case LIFE_DEAD:
  654. tailsprintf(logline, sizeof(logline), "DEAD reported in %s", checkin);
  655. break;
  656. case LIFE_INIT:
  657. case LIFE_NOSTART:
  658. tailsprintf(logline, sizeof(logline), "Never started");
  659. break;
  660. }
  661. if (thr->pause)
  662. tailsprintf(logline, sizeof(logline), " paused");
  663. wlogprint("%s\n", logline);
  664. }
  665. }
  666. static
  667. void opencl_tui_wlogprint_choices(struct cgpu_info *cgpu)
  668. {
  669. wlogprint("[I]ntensity [R]estart GPU ");
  670. #ifdef HAVE_ADL
  671. struct opencl_device_data * const data = cgpu->device_data;
  672. if (data->has_adl)
  673. wlogprint("[C]hange settings ");
  674. #endif
  675. }
  676. static
  677. const char *opencl_tui_handle_choice(struct cgpu_info *cgpu, int input)
  678. {
  679. struct opencl_device_data * const data = cgpu->device_data;
  680. switch (input)
  681. {
  682. case 'i': case 'I':
  683. {
  684. char *intvar;
  685. if (opt_scrypt) {
  686. intvar = curses_input("Set GPU scan intensity (d or "
  687. MIN_SCRYPT_INTENSITY_STR " -> "
  688. MAX_SCRYPT_INTENSITY_STR ")");
  689. } else {
  690. intvar = curses_input("Set GPU scan intensity (d or "
  691. MIN_SHA_INTENSITY_STR " -> "
  692. MAX_SHA_INTENSITY_STR ")");
  693. }
  694. if (!intvar)
  695. return "Invalid intensity\n";
  696. if (!strncasecmp(intvar, "d", 1)) {
  697. data->dynamic = true;
  698. pause_dynamic_threads(cgpu->device_id);
  699. free(intvar);
  700. return "Dynamic mode enabled\n";
  701. }
  702. if (!_set_intensity(cgpu, intvar))
  703. return "Invalid intensity (out of range)\n";
  704. free(intvar);
  705. return "Intensity changed\n";
  706. }
  707. case 'r': case 'R':
  708. reinit_device(cgpu);
  709. return "Attempting to restart\n";
  710. case 'c': case 'C':
  711. {
  712. char logline[256];
  713. clear_logwin();
  714. get_statline3(logline, sizeof(logline), cgpu, true, true);
  715. wattron(logwin, A_BOLD);
  716. wlogprint("%s", logline);
  717. wattroff(logwin, A_BOLD);
  718. wlogprint("\n");
  719. change_gpusettings(cgpu->device_id);
  720. return ""; // Force refresh
  721. }
  722. }
  723. return NULL;
  724. }
  725. #endif
  726. #ifdef HAVE_OPENCL
  727. #define CL_SET_BLKARG(blkvar) status |= clSetKernelArg(*kernel, num++, sizeof(uint), (void *)&blk->blkvar)
  728. #define CL_SET_ARG(var) status |= clSetKernelArg(*kernel, num++, sizeof(var), (void *)&var)
  729. #define CL_SET_VARG(args, var) status |= clSetKernelArg(*kernel, num++, args * sizeof(uint), (void *)var)
  730. static
  731. void *_opencl_work_data_dup(struct work * const work)
  732. {
  733. struct opencl_work_data *p = malloc(sizeof(*p));
  734. memcpy(p, work->device_data, sizeof(*p));
  735. #ifdef USE_SCRYPT
  736. p->work = work;
  737. #endif
  738. return p;
  739. }
  740. static
  741. void _opencl_work_data_free(struct work * const work)
  742. {
  743. free(work->device_data);
  744. }
  745. static
  746. struct opencl_work_data *_opencl_work_data(struct work * const work)
  747. {
  748. if (!work->device_data)
  749. {
  750. work->device_data = calloc(1, sizeof(struct opencl_work_data));
  751. work->device_data_dup_func = _opencl_work_data_dup;
  752. work->device_data_free_func = _opencl_work_data_free;
  753. }
  754. return work->device_data;
  755. }
  756. static
  757. cl_int queue_poclbm_kernel(_clState * const clState, struct work * const work, const cl_uint threads)
  758. {
  759. struct opencl_work_data * const blk = _opencl_work_data(work);
  760. cl_kernel *kernel = &clState->kernel;
  761. unsigned int num = 0;
  762. cl_int status = 0;
  763. CL_SET_BLKARG(ctx_a);
  764. CL_SET_BLKARG(ctx_b);
  765. CL_SET_BLKARG(ctx_c);
  766. CL_SET_BLKARG(ctx_d);
  767. CL_SET_BLKARG(ctx_e);
  768. CL_SET_BLKARG(ctx_f);
  769. CL_SET_BLKARG(ctx_g);
  770. CL_SET_BLKARG(ctx_h);
  771. CL_SET_BLKARG(cty_b);
  772. CL_SET_BLKARG(cty_c);
  773. CL_SET_BLKARG(cty_f);
  774. CL_SET_BLKARG(cty_g);
  775. CL_SET_BLKARG(cty_h);
  776. if (!clState->goffset) {
  777. cl_uint vwidth = clState->vwidth;
  778. uint *nonces = alloca(sizeof(uint) * vwidth);
  779. unsigned int i;
  780. for (i = 0; i < vwidth; i++)
  781. nonces[i] = work->blk.nonce + (i * threads);
  782. CL_SET_VARG(vwidth, nonces);
  783. }
  784. CL_SET_BLKARG(fW0);
  785. CL_SET_BLKARG(fW1);
  786. CL_SET_BLKARG(fW2);
  787. CL_SET_BLKARG(fW3);
  788. CL_SET_BLKARG(fW15);
  789. CL_SET_BLKARG(fW01r);
  790. CL_SET_BLKARG(D1A);
  791. CL_SET_BLKARG(C1addK5);
  792. CL_SET_BLKARG(B1addK6);
  793. CL_SET_BLKARG(W16addK16);
  794. CL_SET_BLKARG(W17addK17);
  795. CL_SET_BLKARG(PreVal4addT1);
  796. CL_SET_BLKARG(PreVal0);
  797. CL_SET_ARG(clState->outputBuffer);
  798. return status;
  799. }
  800. static
  801. cl_int queue_phatk_kernel(_clState * const clState, struct work * const work, __maybe_unused const cl_uint threads)
  802. {
  803. struct opencl_work_data * const blk = _opencl_work_data(work);
  804. cl_kernel *kernel = &clState->kernel;
  805. cl_uint vwidth = clState->vwidth;
  806. unsigned int i, num = 0;
  807. cl_int status = 0;
  808. uint *nonces;
  809. CL_SET_BLKARG(ctx_a);
  810. CL_SET_BLKARG(ctx_b);
  811. CL_SET_BLKARG(ctx_c);
  812. CL_SET_BLKARG(ctx_d);
  813. CL_SET_BLKARG(ctx_e);
  814. CL_SET_BLKARG(ctx_f);
  815. CL_SET_BLKARG(ctx_g);
  816. CL_SET_BLKARG(ctx_h);
  817. CL_SET_BLKARG(cty_b);
  818. CL_SET_BLKARG(cty_c);
  819. CL_SET_BLKARG(cty_d);
  820. CL_SET_BLKARG(cty_f);
  821. CL_SET_BLKARG(cty_g);
  822. CL_SET_BLKARG(cty_h);
  823. nonces = alloca(sizeof(uint) * vwidth);
  824. for (i = 0; i < vwidth; i++)
  825. nonces[i] = work->blk.nonce + i;
  826. CL_SET_VARG(vwidth, nonces);
  827. CL_SET_BLKARG(W16);
  828. CL_SET_BLKARG(W17);
  829. CL_SET_BLKARG(PreVal4_2);
  830. CL_SET_BLKARG(PreVal0);
  831. CL_SET_BLKARG(PreW18);
  832. CL_SET_BLKARG(PreW19);
  833. CL_SET_BLKARG(PreW31);
  834. CL_SET_BLKARG(PreW32);
  835. CL_SET_ARG(clState->outputBuffer);
  836. return status;
  837. }
  838. static
  839. cl_int queue_diakgcn_kernel(_clState * const clState, struct work * const work, __maybe_unused const cl_uint threads)
  840. {
  841. struct opencl_work_data * const blk = _opencl_work_data(work);
  842. cl_kernel *kernel = &clState->kernel;
  843. unsigned int num = 0;
  844. cl_int status = 0;
  845. if (!clState->goffset) {
  846. cl_uint vwidth = clState->vwidth;
  847. uint *nonces = alloca(sizeof(uint) * vwidth);
  848. unsigned int i;
  849. for (i = 0; i < vwidth; i++)
  850. nonces[i] = work->blk.nonce + i;
  851. CL_SET_VARG(vwidth, nonces);
  852. }
  853. CL_SET_BLKARG(PreVal0);
  854. CL_SET_BLKARG(PreVal4_2);
  855. CL_SET_BLKARG(cty_h);
  856. CL_SET_BLKARG(D1A);
  857. CL_SET_BLKARG(cty_b);
  858. CL_SET_BLKARG(cty_c);
  859. CL_SET_BLKARG(cty_f);
  860. CL_SET_BLKARG(cty_g);
  861. CL_SET_BLKARG(C1addK5);
  862. CL_SET_BLKARG(B1addK6);
  863. CL_SET_BLKARG(PreVal0addK7);
  864. CL_SET_BLKARG(W16addK16);
  865. CL_SET_BLKARG(W17addK17);
  866. CL_SET_BLKARG(PreW18);
  867. CL_SET_BLKARG(PreW19);
  868. CL_SET_BLKARG(W16);
  869. CL_SET_BLKARG(W17);
  870. CL_SET_BLKARG(PreW31);
  871. CL_SET_BLKARG(PreW32);
  872. CL_SET_BLKARG(ctx_a);
  873. CL_SET_BLKARG(ctx_b);
  874. CL_SET_BLKARG(ctx_c);
  875. CL_SET_BLKARG(ctx_d);
  876. CL_SET_BLKARG(ctx_e);
  877. CL_SET_BLKARG(ctx_f);
  878. CL_SET_BLKARG(ctx_g);
  879. CL_SET_BLKARG(ctx_h);
  880. CL_SET_BLKARG(zeroA);
  881. CL_SET_BLKARG(zeroB);
  882. CL_SET_BLKARG(oneA);
  883. CL_SET_BLKARG(twoA);
  884. CL_SET_BLKARG(threeA);
  885. CL_SET_BLKARG(fourA);
  886. CL_SET_BLKARG(fiveA);
  887. CL_SET_BLKARG(sixA);
  888. CL_SET_BLKARG(sevenA);
  889. CL_SET_ARG(clState->outputBuffer);
  890. return status;
  891. }
  892. static
  893. cl_int queue_diablo_kernel(_clState * const clState, struct work * const work, const cl_uint threads)
  894. {
  895. struct opencl_work_data * const blk = _opencl_work_data(work);
  896. cl_kernel *kernel = &clState->kernel;
  897. unsigned int num = 0;
  898. cl_int status = 0;
  899. if (!clState->goffset) {
  900. cl_uint vwidth = clState->vwidth;
  901. uint *nonces = alloca(sizeof(uint) * vwidth);
  902. unsigned int i;
  903. for (i = 0; i < vwidth; i++)
  904. nonces[i] = work->blk.nonce + (i * threads);
  905. CL_SET_VARG(vwidth, nonces);
  906. }
  907. CL_SET_BLKARG(PreVal0);
  908. CL_SET_BLKARG(PreVal0addK7);
  909. CL_SET_BLKARG(PreVal4addT1);
  910. CL_SET_BLKARG(PreW18);
  911. CL_SET_BLKARG(PreW19);
  912. CL_SET_BLKARG(W16);
  913. CL_SET_BLKARG(W17);
  914. CL_SET_BLKARG(W16addK16);
  915. CL_SET_BLKARG(W17addK17);
  916. CL_SET_BLKARG(PreW31);
  917. CL_SET_BLKARG(PreW32);
  918. CL_SET_BLKARG(D1A);
  919. CL_SET_BLKARG(cty_b);
  920. CL_SET_BLKARG(cty_c);
  921. CL_SET_BLKARG(cty_h);
  922. CL_SET_BLKARG(cty_f);
  923. CL_SET_BLKARG(cty_g);
  924. CL_SET_BLKARG(C1addK5);
  925. CL_SET_BLKARG(B1addK6);
  926. CL_SET_BLKARG(ctx_a);
  927. CL_SET_BLKARG(ctx_b);
  928. CL_SET_BLKARG(ctx_c);
  929. CL_SET_BLKARG(ctx_d);
  930. CL_SET_BLKARG(ctx_e);
  931. CL_SET_BLKARG(ctx_f);
  932. CL_SET_BLKARG(ctx_g);
  933. CL_SET_BLKARG(ctx_h);
  934. CL_SET_ARG(clState->outputBuffer);
  935. return status;
  936. }
  937. #ifdef USE_SCRYPT
  938. static
  939. cl_int queue_scrypt_kernel(_clState * const clState, struct work * const work, __maybe_unused const cl_uint threads)
  940. {
  941. unsigned char *midstate = work->midstate;
  942. cl_kernel *kernel = &clState->kernel;
  943. unsigned int num = 0;
  944. cl_uint le_target;
  945. cl_int status = 0;
  946. le_target = *(cl_uint *)(work->target + 28);
  947. clState->cldata = work->data;
  948. status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL,NULL);
  949. CL_SET_ARG(clState->CLbuffer0);
  950. CL_SET_ARG(clState->outputBuffer);
  951. CL_SET_ARG(clState->padbuffer8);
  952. CL_SET_VARG(4, &midstate[0]);
  953. CL_SET_VARG(4, &midstate[16]);
  954. CL_SET_ARG(le_target);
  955. return status;
  956. }
  957. #endif
  958. #endif /* HAVE_OPENCL */
  959. #ifdef HAVE_OPENCL
  960. /* We have only one thread that ever re-initialises GPUs, thus if any GPU
  961. * init command fails due to a completely wedged GPU, the thread will never
  962. * return, unable to harm other GPUs. If it does return, it means we only had
  963. * a soft failure and then the reinit_gpu thread is ready to tackle another
  964. * GPU */
  965. void *reinit_gpu(void *userdata)
  966. {
  967. struct thr_info *mythr = userdata;
  968. struct cgpu_info *cgpu, *sel_cgpu;
  969. struct thr_info *thr;
  970. char name[256];
  971. int thr_id;
  972. int i;
  973. pthread_detach(pthread_self());
  974. RenameThread("reinit_gpu");
  975. select_cgpu:
  976. sel_cgpu =
  977. cgpu = tq_pop(mythr->q, NULL);
  978. if (!cgpu)
  979. goto out;
  980. struct opencl_device_data * const data = cgpu->device_data;
  981. if (clDevicesNum() != nDevs) {
  982. applog(LOG_WARNING, "Hardware not reporting same number of active devices, will not attempt to restart GPU");
  983. goto out;
  984. }
  985. for (i = 0; i < cgpu->threads; ++i)
  986. {
  987. thr = cgpu->thr[i];
  988. thr_id = thr->id;
  989. thr->rolling = thr->cgpu->rolling = 0;
  990. /* Reports the last time we tried to revive a sick GPU */
  991. cgtime(&thr->sick);
  992. if (!pthread_cancel(thr->pth)) {
  993. applog(LOG_WARNING, "Thread %d still exists, killing it off", thr_id);
  994. } else
  995. applog(LOG_WARNING, "Thread %d no longer exists", thr_id);
  996. }
  997. for (i = 0; i < cgpu->threads; ++i)
  998. {
  999. int virtual_gpu;
  1000. thr = cgpu->thr[i];
  1001. thr_id = thr->id;
  1002. virtual_gpu = data->virtual_gpu;
  1003. /* Lose this ram cause we may get stuck here! */
  1004. //tq_freeze(thr->q);
  1005. thr->q = tq_new();
  1006. if (!thr->q)
  1007. quithere(1, "Failed to tq_new");
  1008. /* Lose this ram cause we may dereference in the dying thread! */
  1009. //free(clState);
  1010. applog(LOG_INFO, "Reinit GPU thread %d", thr_id);
  1011. clStates[thr_id] = initCl(virtual_gpu, name, sizeof(name));
  1012. if (!clStates[thr_id]) {
  1013. applog(LOG_ERR, "Failed to reinit GPU thread %d", thr_id);
  1014. goto select_cgpu;
  1015. }
  1016. applog(LOG_INFO, "initCl() finished. Found %s", name);
  1017. if (unlikely(thr_info_create(thr, NULL, miner_thread, thr))) {
  1018. applog(LOG_ERR, "thread %d create failed", thr_id);
  1019. return NULL;
  1020. }
  1021. applog(LOG_WARNING, "Thread %d restarted", thr_id);
  1022. }
  1023. get_now_datestamp(sel_cgpu->init, sizeof(sel_cgpu->init));
  1024. proc_enable(cgpu);
  1025. goto select_cgpu;
  1026. out:
  1027. return NULL;
  1028. }
  1029. #else
  1030. void *reinit_gpu(__maybe_unused void *userdata)
  1031. {
  1032. return NULL;
  1033. }
  1034. #endif
  1035. #ifdef HAVE_OPENCL
  1036. struct device_drv opencl_api;
  1037. static int opencl_autodetect()
  1038. {
  1039. RUNONCE(0);
  1040. #ifndef WIN32
  1041. if (!getenv("DISPLAY")) {
  1042. applog(LOG_DEBUG, "DISPLAY not set, setting :0 just in case");
  1043. setenv("DISPLAY", ":0", 1);
  1044. }
  1045. #endif
  1046. if (!load_opencl_symbols()) {
  1047. nDevs = 0;
  1048. return 0;
  1049. }
  1050. int i;
  1051. nDevs = clDevicesNum();
  1052. if (nDevs < 0) {
  1053. applog(LOG_ERR, "clDevicesNum returned error, no GPUs usable");
  1054. nDevs = 0;
  1055. }
  1056. if (!nDevs)
  1057. return 0;
  1058. /* If opt_g_threads is not set, use default 1 thread on scrypt and
  1059. * 2 for regular mining */
  1060. if (opt_g_threads == -1) {
  1061. if (opt_scrypt)
  1062. opt_g_threads = 1;
  1063. else
  1064. opt_g_threads = 2;
  1065. }
  1066. #ifdef HAVE_SENSORS
  1067. const sensors_chip_name *cn;
  1068. int c = 0;
  1069. sensors_init(NULL);
  1070. sensors_chip_name cnm;
  1071. if (sensors_parse_chip_name("radeon-*", &cnm))
  1072. c = -1;
  1073. #endif
  1074. for (i = 0; i < nDevs; ++i) {
  1075. struct cgpu_info *cgpu;
  1076. cgpu = &gpus[i];
  1077. struct opencl_device_data * const data = cgpu->device_data;
  1078. cgpu->devtype = "GPU";
  1079. cgpu->deven = DEV_ENABLED;
  1080. cgpu->drv = &opencl_api;
  1081. cgpu->device_id = i;
  1082. if (cgpu->threads == 0)
  1083. cgpu->threads = opt_g_threads;
  1084. data->virtual_gpu = i;
  1085. #ifdef HAVE_SENSORS
  1086. cn = (c == -1) ? NULL : sensors_get_detected_chips(&cnm, &c);
  1087. data->sensor = cn;
  1088. #endif
  1089. cgpu->set_device_funcs = opencl_set_device_funcs_probe;
  1090. cgpu_set_defaults(cgpu);
  1091. cgpu->set_device_funcs = opencl_set_device_funcs;
  1092. add_cgpu(cgpu);
  1093. }
  1094. if (!opt_noadl)
  1095. init_adl(nDevs);
  1096. return nDevs;
  1097. }
  1098. static void opencl_detect()
  1099. {
  1100. int flags = 0;
  1101. if (!opt_scrypt)
  1102. flags |= GDF_DEFAULT_NOAUTO;
  1103. generic_detect(&opencl_api, NULL, opencl_autodetect, flags);
  1104. }
  1105. static void reinit_opencl_device(struct cgpu_info *gpu)
  1106. {
  1107. #ifdef HAVE_ADL
  1108. struct opencl_device_data * const data = gpu->device_data;
  1109. if (adl_active && data->has_adl && gpu_activity(gpu->device_id) > 50)
  1110. {
  1111. applogr(, LOG_ERR, "%s: Still showing activity (suggests a hard hang); cancelling reinitialise.",
  1112. gpu->dev_repr);
  1113. }
  1114. #endif
  1115. tq_push(control_thr[gpur_thr_id].q, gpu);
  1116. }
  1117. // FIXME: Legacy (called by TUI) for side effects
  1118. static
  1119. bool override_opencl_statline_temp(char *buf, size_t bufsz, struct cgpu_info *gpu, __maybe_unused bool per_processor)
  1120. {
  1121. __maybe_unused struct opencl_device_data * const data = gpu->device_data;
  1122. #ifdef HAVE_SENSORS
  1123. if (data->sensor)
  1124. {
  1125. const sensors_chip_name *cn = data->sensor;
  1126. const sensors_feature *feat;
  1127. for (int f = 0; (feat = sensors_get_features(cn, &f)); )
  1128. {
  1129. const sensors_subfeature *subf;
  1130. subf = sensors_get_subfeature(cn, feat, SENSORS_SUBFEATURE_TEMP_INPUT);
  1131. if (!(subf && subf->flags & SENSORS_MODE_R))
  1132. continue;
  1133. double val;
  1134. int rc = sensors_get_value(cn, subf->number, &val);
  1135. if (rc)
  1136. continue;
  1137. gpu->temp = val;
  1138. return false;
  1139. }
  1140. }
  1141. #endif
  1142. #ifdef HAVE_ADL
  1143. if (data->has_adl) {
  1144. int gpuid = gpu->device_id;
  1145. gpu_temp(gpuid);
  1146. gpu_fanspeed(gpuid);
  1147. }
  1148. #endif
  1149. return false;
  1150. }
  1151. static
  1152. void opencl_watchdog(struct cgpu_info * const cgpu, __maybe_unused const struct timeval * const tv_now)
  1153. {
  1154. #ifdef HAVE_ADL
  1155. struct opencl_device_data * const data = cgpu->device_data;
  1156. const int gpu = cgpu->device_id;
  1157. enum dev_enable *denable = &cgpu->deven;
  1158. if (adl_active && data->has_adl)
  1159. gpu_autotune(gpu, denable);
  1160. if (opt_debug && data->has_adl) {
  1161. int engineclock = 0, memclock = 0, activity = 0, fanspeed = 0, fanpercent = 0, powertune = 0;
  1162. float temp = 0, vddc = 0;
  1163. if (gpu_stats(gpu, &temp, &engineclock, &memclock, &vddc, &activity, &fanspeed, &fanpercent, &powertune))
  1164. applog(LOG_DEBUG, "%.1f C F: %d%%(%dRPM) E: %dMHz M: %dMHz V: %.3fV A: %d%% P: %d%%",
  1165. temp, fanpercent, fanspeed, engineclock, memclock, vddc, activity, powertune);
  1166. }
  1167. #endif
  1168. }
  1169. static struct api_data*
  1170. get_opencl_api_extra_device_status(struct cgpu_info *gpu)
  1171. {
  1172. struct opencl_device_data * const data = gpu->device_data;
  1173. struct thr_info * const thr = gpu->thr[0];
  1174. const int thr_id = thr->id;
  1175. _clState * const clState = clStates[thr_id];
  1176. struct api_data*root = NULL;
  1177. float gt, gv;
  1178. int ga, gf, gp, gc, gm, pt;
  1179. #ifdef HAVE_ADL
  1180. if (!gpu_stats(gpu->device_id, &gt, &gc, &gm, &gv, &ga, &gf, &gp, &pt))
  1181. #endif
  1182. gt = gv = gm = gc = ga = gf = gp = pt = 0;
  1183. root = api_add_int(root, "Fan Speed", &gf, true);
  1184. root = api_add_int(root, "Fan Percent", &gp, true);
  1185. root = api_add_int(root, "GPU Clock", &gc, true);
  1186. root = api_add_int(root, "Memory Clock", &gm, true);
  1187. root = api_add_volts(root, "GPU Voltage", &gv, true);
  1188. root = api_add_int(root, "GPU Activity", &ga, true);
  1189. root = api_add_int(root, "Powertune", &pt, true);
  1190. char intensity[20];
  1191. uint32_t oclthreads = data->oclthreads;
  1192. double intensityf = oclthreads_to_intensity(oclthreads, !opt_scrypt);
  1193. double xintensity = oclthreads_to_xintensity(oclthreads, clState->max_compute_units);
  1194. if (data->dynamic)
  1195. strcpy(intensity, "D");
  1196. else
  1197. sprintf(intensity, "%g", intensityf);
  1198. root = api_add_string(root, "Intensity", intensity, true);
  1199. root = api_add_uint32(root, "OCLThreads", &oclthreads, true);
  1200. root = api_add_double(root, "CIntensity", &intensityf, true);
  1201. root = api_add_double(root, "XIntensity", &xintensity, true);
  1202. return root;
  1203. }
  1204. struct opencl_thread_data {
  1205. cl_int (*queue_kernel_parameters)(_clState *, struct work *, cl_uint);
  1206. uint32_t *res;
  1207. };
  1208. static uint32_t *blank_res;
  1209. static bool opencl_thread_prepare(struct thr_info *thr)
  1210. {
  1211. char name[256];
  1212. struct cgpu_info *cgpu = thr->cgpu;
  1213. struct opencl_device_data * const data = cgpu->device_data;
  1214. int gpu = cgpu->device_id;
  1215. int virtual_gpu = data->virtual_gpu;
  1216. int i = thr->id;
  1217. static bool failmessage = false;
  1218. int buffersize = opt_scrypt ? SCRYPT_BUFFERSIZE : BUFFERSIZE;
  1219. if (!blank_res)
  1220. blank_res = calloc(buffersize, 1);
  1221. if (!blank_res) {
  1222. applog(LOG_ERR, "Failed to calloc in opencl_thread_init");
  1223. return false;
  1224. }
  1225. strcpy(name, "");
  1226. applog(LOG_INFO, "Init GPU thread %i GPU %i virtual GPU %i", i, gpu, virtual_gpu);
  1227. clStates[i] = initCl(virtual_gpu, name, sizeof(name));
  1228. if (!clStates[i]) {
  1229. #ifdef HAVE_CURSES
  1230. if (use_curses)
  1231. enable_curses();
  1232. #endif
  1233. applog(LOG_ERR, "Failed to init GPU thread %d, disabling device %d", i, gpu);
  1234. if (!failmessage) {
  1235. applog(LOG_ERR, "Restarting the GPU from the menu will not fix this.");
  1236. applog(LOG_ERR, "Try restarting BFGMiner.");
  1237. failmessage = true;
  1238. #ifdef HAVE_CURSES
  1239. char *buf;
  1240. if (use_curses) {
  1241. buf = curses_input("Press enter to continue");
  1242. if (buf)
  1243. free(buf);
  1244. }
  1245. #endif
  1246. }
  1247. cgpu->deven = DEV_DISABLED;
  1248. cgpu->status = LIFE_NOSTART;
  1249. dev_error(cgpu, REASON_DEV_NOSTART);
  1250. return false;
  1251. }
  1252. if (!cgpu->name)
  1253. cgpu->name = strdup(name);
  1254. if (!cgpu->kname)
  1255. {
  1256. switch (clStates[i]->chosen_kernel) {
  1257. case KL_DIABLO:
  1258. cgpu->kname = "diablo";
  1259. break;
  1260. case KL_DIAKGCN:
  1261. cgpu->kname = "diakgcn";
  1262. break;
  1263. case KL_PHATK:
  1264. cgpu->kname = "phatk";
  1265. break;
  1266. #ifdef USE_SCRYPT
  1267. case KL_SCRYPT:
  1268. cgpu->kname = "scrypt";
  1269. break;
  1270. #endif
  1271. case KL_POCLBM:
  1272. cgpu->kname = "poclbm";
  1273. break;
  1274. default:
  1275. break;
  1276. }
  1277. }
  1278. applog(LOG_INFO, "initCl() finished. Found %s", name);
  1279. get_now_datestamp(cgpu->init, sizeof(cgpu->init));
  1280. have_opencl = true;
  1281. return true;
  1282. }
  1283. static bool opencl_thread_init(struct thr_info *thr)
  1284. {
  1285. const int thr_id = thr->id;
  1286. struct cgpu_info *gpu = thr->cgpu;
  1287. struct opencl_thread_data *thrdata;
  1288. _clState *clState = clStates[thr_id];
  1289. cl_int status = 0;
  1290. thrdata = calloc(1, sizeof(*thrdata));
  1291. thr->cgpu_data = thrdata;
  1292. int buffersize = opt_scrypt ? SCRYPT_BUFFERSIZE : BUFFERSIZE;
  1293. if (!thrdata) {
  1294. applog(LOG_ERR, "Failed to calloc in opencl_thread_init");
  1295. return false;
  1296. }
  1297. switch (clState->chosen_kernel) {
  1298. case KL_POCLBM:
  1299. thrdata->queue_kernel_parameters = &queue_poclbm_kernel;
  1300. break;
  1301. case KL_PHATK:
  1302. thrdata->queue_kernel_parameters = &queue_phatk_kernel;
  1303. break;
  1304. case KL_DIAKGCN:
  1305. thrdata->queue_kernel_parameters = &queue_diakgcn_kernel;
  1306. break;
  1307. #ifdef USE_SCRYPT
  1308. case KL_SCRYPT:
  1309. thrdata->queue_kernel_parameters = &queue_scrypt_kernel;
  1310. gpu->min_nonce_diff = 1./0x10000;
  1311. break;
  1312. #endif
  1313. default:
  1314. case KL_DIABLO:
  1315. thrdata->queue_kernel_parameters = &queue_diablo_kernel;
  1316. break;
  1317. }
  1318. thrdata->res = calloc(buffersize, 1);
  1319. if (!thrdata->res) {
  1320. free(thrdata);
  1321. applog(LOG_ERR, "Failed to calloc in opencl_thread_init");
  1322. return false;
  1323. }
  1324. status |= clEnqueueWriteBuffer(clState->commandQueue, clState->outputBuffer, CL_TRUE, 0,
  1325. buffersize, blank_res, 0, NULL, NULL);
  1326. if (unlikely(status != CL_SUCCESS)) {
  1327. applog(LOG_ERR, "Error: clEnqueueWriteBuffer failed.");
  1328. return false;
  1329. }
  1330. gpu->status = LIFE_WELL;
  1331. gpu->device_last_well = time(NULL);
  1332. return true;
  1333. }
  1334. static bool opencl_prepare_work(struct thr_info __maybe_unused *thr, struct work *work)
  1335. {
  1336. #ifdef USE_SCRYPT
  1337. if (!opt_scrypt)
  1338. #endif
  1339. {
  1340. struct opencl_work_data * const blk = _opencl_work_data(work);
  1341. precalc_hash(blk, (uint32_t *)(work->midstate), (uint32_t *)(work->data + 64));
  1342. }
  1343. return true;
  1344. }
  1345. extern int opt_dynamic_interval;
  1346. static int64_t opencl_scanhash(struct thr_info *thr, struct work *work,
  1347. int64_t __maybe_unused max_nonce)
  1348. {
  1349. const int thr_id = thr->id;
  1350. struct opencl_thread_data *thrdata = thr->cgpu_data;
  1351. struct cgpu_info *gpu = thr->cgpu;
  1352. struct opencl_device_data * const data = gpu->device_data;
  1353. _clState *clState = clStates[thr_id];
  1354. const cl_kernel *kernel = &clState->kernel;
  1355. const int dynamic_us = opt_dynamic_interval * 1000;
  1356. cl_int status;
  1357. size_t globalThreads[1];
  1358. size_t localThreads[1] = { clState->wsize };
  1359. int64_t hashes;
  1360. int found = opt_scrypt ? SCRYPT_FOUND : FOUND;
  1361. int buffersize = opt_scrypt ? SCRYPT_BUFFERSIZE : BUFFERSIZE;
  1362. /* Windows' timer resolution is only 15ms so oversample 5x */
  1363. if (data->dynamic && (++data->intervals * dynamic_us) > 70000) {
  1364. struct timeval tv_gpuend;
  1365. double gpu_us;
  1366. cgtime(&tv_gpuend);
  1367. gpu_us = us_tdiff(&tv_gpuend, &data->tv_gpustart) / data->intervals;
  1368. if (gpu_us > dynamic_us) {
  1369. const unsigned long min_oclthreads = intensity_to_oclthreads(MIN_INTENSITY, !opt_scrypt);
  1370. data->oclthreads /= 2;
  1371. if (data->oclthreads < min_oclthreads)
  1372. data->oclthreads = min_oclthreads;
  1373. } else if (gpu_us < dynamic_us / 2) {
  1374. const unsigned long max_oclthreads = intensity_to_oclthreads(MAX_INTENSITY, !opt_scrypt);
  1375. data->oclthreads *= 2;
  1376. if (data->oclthreads > max_oclthreads)
  1377. data->oclthreads = max_oclthreads;
  1378. }
  1379. memcpy(&(data->tv_gpustart), &tv_gpuend, sizeof(struct timeval));
  1380. data->intervals = 0;
  1381. }
  1382. if (data->oclthreads < localThreads[0])
  1383. data->oclthreads = localThreads[0];
  1384. globalThreads[0] = data->oclthreads;
  1385. hashes = globalThreads[0];
  1386. hashes *= clState->vwidth;
  1387. if (hashes > gpu->max_hashes)
  1388. gpu->max_hashes = hashes;
  1389. status = thrdata->queue_kernel_parameters(clState, work, globalThreads[0]);
  1390. if (unlikely(status != CL_SUCCESS)) {
  1391. applog(LOG_ERR, "Error: clSetKernelArg of all params failed.");
  1392. return -1;
  1393. }
  1394. if (clState->goffset) {
  1395. size_t global_work_offset[1];
  1396. global_work_offset[0] = work->blk.nonce;
  1397. status = clEnqueueNDRangeKernel(clState->commandQueue, *kernel, 1, global_work_offset,
  1398. globalThreads, localThreads, 0, NULL, NULL);
  1399. } else
  1400. status = clEnqueueNDRangeKernel(clState->commandQueue, *kernel, 1, NULL,
  1401. globalThreads, localThreads, 0, NULL, NULL);
  1402. if (unlikely(status != CL_SUCCESS)) {
  1403. applog(LOG_ERR, "Error %d: Enqueueing kernel onto command queue. (clEnqueueNDRangeKernel)", status);
  1404. return -1;
  1405. }
  1406. status = clEnqueueReadBuffer(clState->commandQueue, clState->outputBuffer, CL_FALSE, 0,
  1407. buffersize, thrdata->res, 0, NULL, NULL);
  1408. if (unlikely(status != CL_SUCCESS)) {
  1409. applog(LOG_ERR, "Error: clEnqueueReadBuffer failed error %d. (clEnqueueReadBuffer)", status);
  1410. return -1;
  1411. }
  1412. /* The amount of work scanned can fluctuate when intensity changes
  1413. * and since we do this one cycle behind, we increment the work more
  1414. * than enough to prevent repeating work */
  1415. work->blk.nonce += gpu->max_hashes;
  1416. /* This finish flushes the readbuffer set with CL_FALSE in clEnqueueReadBuffer */
  1417. clFinish(clState->commandQueue);
  1418. /* FOUND entry is used as a counter to say how many nonces exist */
  1419. if (thrdata->res[found]) {
  1420. /* Clear the buffer again */
  1421. status = clEnqueueWriteBuffer(clState->commandQueue, clState->outputBuffer, CL_FALSE, 0,
  1422. buffersize, blank_res, 0, NULL, NULL);
  1423. if (unlikely(status != CL_SUCCESS)) {
  1424. applog(LOG_ERR, "Error: clEnqueueWriteBuffer failed.");
  1425. return -1;
  1426. }
  1427. applog(LOG_DEBUG, "GPU %d found something?", gpu->device_id);
  1428. postcalc_hash_async(thr, work, thrdata->res);
  1429. memset(thrdata->res, 0, buffersize);
  1430. /* This finish flushes the writebuffer set with CL_FALSE in clEnqueueWriteBuffer */
  1431. clFinish(clState->commandQueue);
  1432. }
  1433. return hashes;
  1434. }
  1435. static void opencl_thread_shutdown(struct thr_info *thr)
  1436. {
  1437. const int thr_id = thr->id;
  1438. _clState *clState = clStates[thr_id];
  1439. clReleaseKernel(clState->kernel);
  1440. clReleaseProgram(clState->program);
  1441. clReleaseCommandQueue(clState->commandQueue);
  1442. clReleaseContext(clState->context);
  1443. }
  1444. static
  1445. const char *opencl_cannot_set(struct cgpu_info * const proc, const char * const optname, const char * const newvalue, char * const replybuf, enum bfg_set_device_replytype * const out_success)
  1446. {
  1447. return "Cannot set at runtime (use --set-device on commandline)";
  1448. }
  1449. static const struct bfg_set_device_definition opencl_set_device_funcs_probe[] = {
  1450. {"intensity", opencl_init_intensity},
  1451. {"kernel", opencl_init_kernel},
  1452. {"threads", opencl_init_gpu_threads},
  1453. {"vector", opencl_init_vector},
  1454. {"work_size", opencl_init_worksize},
  1455. #ifdef HAVE_ADL
  1456. {"adl_mapping", opencl_init_gpu_map},
  1457. {"clock", opencl_init_gpu_engine},
  1458. {"fan", opencl_init_gpu_fan},
  1459. {"memclock", opencl_init_gpu_memclock},
  1460. {"memdiff", opencl_init_gpu_memdiff},
  1461. {"powertune", opencl_init_gpu_powertune},
  1462. {"temp_overheat", opencl_init_temp_overheat},
  1463. {"voltage", opencl_init_gpu_vddc},
  1464. #endif
  1465. #ifdef USE_SCRYPT
  1466. {"shaders", opencl_init_shaders},
  1467. {"lookup_gap", opencl_init_lookup_gap},
  1468. {"thread_concurrency", opencl_init_thread_concurrency},
  1469. #endif
  1470. {NULL}
  1471. };
  1472. static const struct bfg_set_device_definition opencl_set_device_funcs[] = {
  1473. {"intensity", opencl_init_intensity, "Intensity of GPU scanning (d, -10 -> 31, or x1 to x9999)"},
  1474. {"kernel", opencl_cannot_set, "Mining kernel code to use"},
  1475. {"threads", opencl_cannot_set, "Number of threads"},
  1476. {"vector", opencl_cannot_set, ""},
  1477. {"work_size", opencl_cannot_set, ""},
  1478. #ifdef HAVE_ADL
  1479. {"adl_mapping", opencl_cannot_set, "Map to ADL device"},
  1480. {"clock", opencl_set_gpu_engine, "GPU engine clock"},
  1481. {"fan", opencl_set_gpu_fan, "GPU fan percentage range"},
  1482. {"memclock", opencl_set_gpu_memclock, "GPU memory clock"},
  1483. {"memdiff", opencl_set_gpu_memdiff, "Clock speed difference between GPU and memory (auto-gpu mode only)"},
  1484. {"powertune", opencl_cannot_set, "GPU powertune percentage"},
  1485. {"temp_overheat", opencl_init_temp_overheat, "Overheat temperature when automatically managing fan and GPU speeds"},
  1486. {"voltage", opencl_set_gpu_vddc, "GPU voltage"},
  1487. #endif
  1488. #ifdef USE_SCRYPT
  1489. {"shaders", opencl_cannot_set, "GPU shaders per card (scrypt only)"},
  1490. {"lookup_gap", opencl_cannot_set, "GPU lookup gap (scrypt only)"},
  1491. {"thread_concurrency", opencl_cannot_set, "GPU thread concurrency (scrypt only)"},
  1492. #endif
  1493. {NULL}
  1494. };
  1495. struct device_drv opencl_api = {
  1496. .dname = "opencl",
  1497. .name = "OCL",
  1498. .probe_priority = 110,
  1499. .supported_algos = POW_SHA256D | POW_SCRYPT,
  1500. .drv_detect = opencl_detect,
  1501. .reinit_device = reinit_opencl_device,
  1502. .watchdog = opencl_watchdog,
  1503. .override_statline_temp2 = override_opencl_statline_temp,
  1504. #ifdef HAVE_CURSES
  1505. .proc_wlogprint_status = opencl_wlogprint_status,
  1506. .proc_tui_wlogprint_choices = opencl_tui_wlogprint_choices,
  1507. .proc_tui_handle_choice = opencl_tui_handle_choice,
  1508. #endif
  1509. .get_api_extra_device_status = get_opencl_api_extra_device_status,
  1510. .thread_prepare = opencl_thread_prepare,
  1511. .thread_init = opencl_thread_init,
  1512. .prepare_work = opencl_prepare_work,
  1513. .scanhash = opencl_scanhash,
  1514. .thread_shutdown = opencl_thread_shutdown,
  1515. };
  1516. #endif