|
|
@@ -9,9 +9,9 @@
|
|
|
*/
|
|
|
|
|
|
#include "config.h"
|
|
|
-#ifdef HAVE_OPENCL
|
|
|
|
|
|
#include <ctype.h>
|
|
|
+#include <limits.h>
|
|
|
#include <signal.h>
|
|
|
#include <stdbool.h>
|
|
|
#include <stdint.h>
|
|
|
@@ -258,6 +258,48 @@ char *file_contents(const char *filename, int *length)
|
|
|
return (char*)buffer;
|
|
|
}
|
|
|
|
|
|
+static
|
|
|
+void extract_word(char * const buf, const size_t bufsz, const char ** const endptr, const char *s)
|
|
|
+{
|
|
|
+ const char *q;
|
|
|
+ for ( ; s[0] && isspace(s[0]); ++s)
|
|
|
+ if (s[0] == '\n' || s[0] == '\r')
|
|
|
+ break;
|
|
|
+ for (q = s; q[0] && !isspace(q[0]); ++q)
|
|
|
+ {} // Find end of string
|
|
|
+ size_t len = q - s;
|
|
|
+ if (len >= bufsz)
|
|
|
+ len = bufsz - 1;
|
|
|
+ memcpy(buf, s, len);
|
|
|
+ buf[len] = '\0';
|
|
|
+ if (endptr)
|
|
|
+ *endptr = q;
|
|
|
+}
|
|
|
+
|
|
|
+char *opencl_kernel_source(const char * const filename, int * const out_sourcelen, enum cl_kernels * const out_kinterface, struct mining_algorithm ** const out_malgo)
|
|
|
+{
|
|
|
+ char *source = file_contents(filename, out_sourcelen);
|
|
|
+ if (!source)
|
|
|
+ return NULL;
|
|
|
+ char *s = strstr(source, "kernel-interface:");
|
|
|
+ if (s)
|
|
|
+ {
|
|
|
+ const char *q;
|
|
|
+ char buf[0x20];
|
|
|
+ extract_word(buf, sizeof(buf), &q, &s[17]);
|
|
|
+ *out_kinterface = select_kernel(buf);
|
|
|
+
|
|
|
+ if (out_malgo && (q[0] == '\t' || q[0] == ' '))
|
|
|
+ {
|
|
|
+ extract_word(buf, sizeof(buf), &q, q);
|
|
|
+ *out_malgo = mining_algorithm_by_alias(buf);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ *out_kinterface = KL_NONE;
|
|
|
+ return source;
|
|
|
+}
|
|
|
+
|
|
|
extern int opt_g_threads;
|
|
|
|
|
|
int clDevicesNum(void) {
|
|
|
@@ -339,20 +381,20 @@ int clDevicesNum(void) {
|
|
|
return most_devices;
|
|
|
}
|
|
|
|
|
|
-cl_int bfg_clBuildProgram(_clState * const clState, const cl_device_id devid, const char * const CompilerOptions)
|
|
|
+cl_int bfg_clBuildProgram(cl_program * const program, const cl_device_id devid, const char * const CompilerOptions)
|
|
|
{
|
|
|
cl_int status;
|
|
|
|
|
|
- status = clBuildProgram(clState->program, 1, &devid, CompilerOptions, NULL, NULL);
|
|
|
+ status = clBuildProgram(*program, 1, &devid, CompilerOptions, NULL, NULL);
|
|
|
|
|
|
if (status != CL_SUCCESS)
|
|
|
{
|
|
|
applog(LOG_ERR, "Error %d: Building Program (clBuildProgram)", status);
|
|
|
size_t logSize;
|
|
|
- status = clGetProgramBuildInfo(clState->program, devid, CL_PROGRAM_BUILD_LOG, 0, NULL, &logSize);
|
|
|
+ status = clGetProgramBuildInfo(*program, devid, CL_PROGRAM_BUILD_LOG, 0, NULL, &logSize);
|
|
|
|
|
|
char *log = malloc(logSize ?: 1);
|
|
|
- status = clGetProgramBuildInfo(clState->program, devid, CL_PROGRAM_BUILD_LOG, logSize, log, NULL);
|
|
|
+ status = clGetProgramBuildInfo(*program, devid, CL_PROGRAM_BUILD_LOG, logSize, log, NULL);
|
|
|
if (logSize > 0 && log[0])
|
|
|
applog(LOG_ERR, "%s", log);
|
|
|
free(log);
|
|
|
@@ -418,18 +460,15 @@ void patch_opcodes(char *w, unsigned remaining)
|
|
|
applog(LOG_DEBUG, "Patched a total of %i BFI_INT instructions", patched);
|
|
|
}
|
|
|
|
|
|
-_clState *initCl(unsigned int gpu, char *name, size_t nameSize)
|
|
|
+_clState *opencl_create_clState(unsigned int gpu, char *name, size_t nameSize)
|
|
|
{
|
|
|
_clState *clState = calloc(1, sizeof(_clState));
|
|
|
- bool patchbfi = false, prog_built = false;
|
|
|
- bool ismesa = false;
|
|
|
struct cgpu_info *cgpu = &gpus[gpu];
|
|
|
struct opencl_device_data * const data = cgpu->device_data;
|
|
|
cl_platform_id platform = NULL;
|
|
|
char pbuff[256], vbuff[255];
|
|
|
- char *s, *q;
|
|
|
+ char *s;
|
|
|
cl_platform_id* platforms;
|
|
|
- cl_uint preferred_vwidth;
|
|
|
cl_device_id *devices;
|
|
|
cl_uint numPlatforms;
|
|
|
cl_uint numDevices;
|
|
|
@@ -438,6 +477,8 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
|
|
|
status = clGetPlatformIDs(0, NULL, &numPlatforms);
|
|
|
if (status != CL_SUCCESS) {
|
|
|
applog(LOG_ERR, "Error %d: Getting Platforms. (clGetPlatformsIDs)", status);
|
|
|
+err:
|
|
|
+ free(clState);
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
@@ -445,24 +486,24 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
|
|
|
status = clGetPlatformIDs(numPlatforms, platforms, NULL);
|
|
|
if (status != CL_SUCCESS) {
|
|
|
applog(LOG_ERR, "Error %d: Getting Platform Ids. (clGetPlatformsIDs)", status);
|
|
|
- return NULL;
|
|
|
+ goto err;
|
|
|
}
|
|
|
|
|
|
if (opt_platform_id >= (int)numPlatforms) {
|
|
|
applog(LOG_ERR, "Specified platform that does not exist");
|
|
|
- return NULL;
|
|
|
+ goto err;
|
|
|
}
|
|
|
|
|
|
status = clGetPlatformInfo(platforms[opt_platform_id], CL_PLATFORM_VENDOR, sizeof(pbuff), pbuff, NULL);
|
|
|
if (status != CL_SUCCESS) {
|
|
|
applog(LOG_ERR, "Error %d: Getting Platform Info. (clGetPlatformInfo)", status);
|
|
|
- return NULL;
|
|
|
+ goto err;
|
|
|
}
|
|
|
platform = platforms[opt_platform_id];
|
|
|
|
|
|
if (platform == NULL) {
|
|
|
perror("NULL platform found!\n");
|
|
|
- return NULL;
|
|
|
+ goto err;
|
|
|
}
|
|
|
|
|
|
applog(LOG_INFO, "CL Platform vendor: %s", pbuff);
|
|
|
@@ -472,14 +513,18 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
|
|
|
status = clGetPlatformInfo(platform, CL_PLATFORM_VERSION, sizeof(vbuff), vbuff, NULL);
|
|
|
if (status == CL_SUCCESS)
|
|
|
applog(LOG_INFO, "CL Platform version: %s", vbuff);
|
|
|
+ clState->platform_ver_str = strdup(vbuff);
|
|
|
|
|
|
status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, NULL, &numDevices);
|
|
|
if (status != CL_SUCCESS) {
|
|
|
applog(LOG_ERR, "Error %d: Getting Device IDs (num)", status);
|
|
|
- return NULL;
|
|
|
+ goto err;
|
|
|
}
|
|
|
|
|
|
- if (numDevices > 0 ) {
|
|
|
+ if (numDevices <= 0)
|
|
|
+ goto err;
|
|
|
+
|
|
|
+ {
|
|
|
devices = (cl_device_id *)malloc(numDevices*sizeof(cl_device_id));
|
|
|
|
|
|
/* Now, get the device list data */
|
|
|
@@ -487,7 +532,9 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
|
|
|
status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, numDevices, devices, NULL);
|
|
|
if (status != CL_SUCCESS) {
|
|
|
applog(LOG_ERR, "Error %d: Getting Device IDs (list)", status);
|
|
|
- return NULL;
|
|
|
+err2:
|
|
|
+ free(devices);
|
|
|
+ goto err;
|
|
|
}
|
|
|
|
|
|
applog(LOG_INFO, "List of devices:");
|
|
|
@@ -497,7 +544,7 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
|
|
|
status = clGetDeviceInfo(devices[i], CL_DEVICE_NAME, sizeof(pbuff), pbuff, NULL);
|
|
|
if (status != CL_SUCCESS) {
|
|
|
applog(LOG_ERR, "Error %d: Getting Device Info", status);
|
|
|
- return NULL;
|
|
|
+ goto err2;
|
|
|
}
|
|
|
|
|
|
applog(LOG_INFO, "\t%i\t%s", i, pbuff);
|
|
|
@@ -507,24 +554,23 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
|
|
|
status = clGetDeviceInfo(devices[gpu], CL_DEVICE_NAME, sizeof(pbuff), pbuff, NULL);
|
|
|
if (status != CL_SUCCESS) {
|
|
|
applog(LOG_ERR, "Error %d: Getting Device Info", status);
|
|
|
- return NULL;
|
|
|
+ goto err2;
|
|
|
}
|
|
|
|
|
|
applog(LOG_INFO, "Selected %i: %s", gpu, pbuff);
|
|
|
strncpy(name, pbuff, nameSize);
|
|
|
} else {
|
|
|
applog(LOG_ERR, "Invalid GPU %i", gpu);
|
|
|
- return NULL;
|
|
|
+ goto err2;
|
|
|
}
|
|
|
-
|
|
|
- } else return NULL;
|
|
|
+ }
|
|
|
|
|
|
cl_context_properties cps[3] = { CL_CONTEXT_PLATFORM, (cl_context_properties)platform, 0 };
|
|
|
|
|
|
clState->context = clCreateContextFromType(cps, CL_DEVICE_TYPE_GPU, NULL, NULL, &status);
|
|
|
if (status != CL_SUCCESS) {
|
|
|
applog(LOG_ERR, "Error %d: Creating Context. (clCreateContextFromType)", status);
|
|
|
- return NULL;
|
|
|
+ goto err2;
|
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
@@ -536,7 +582,7 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
|
|
|
clState->commandQueue = clCreateCommandQueue(clState->context, devices[gpu], 0 , &status);
|
|
|
if (status != CL_SUCCESS) {
|
|
|
applog(LOG_ERR, "Error %d: Creating Command Queue. (clCreateCommandQueue)", status);
|
|
|
- return NULL;
|
|
|
+ goto err2;
|
|
|
}
|
|
|
|
|
|
/* Check for BFI INT support. Hopefully people don't mix devices with
|
|
|
@@ -548,45 +594,32 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
|
|
|
status = clGetDeviceInfo(devices[gpu], CL_DEVICE_EXTENSIONS, 1024, (void *)extensions, NULL);
|
|
|
if (status != CL_SUCCESS) {
|
|
|
applog(LOG_ERR, "Error %d: Failed to clGetDeviceInfo when trying to get CL_DEVICE_EXTENSIONS", status);
|
|
|
- return NULL;
|
|
|
+ free(extensions);
|
|
|
+ goto err2;
|
|
|
}
|
|
|
find = strstr(extensions, camo);
|
|
|
if (find)
|
|
|
clState->hasBitAlign = true;
|
|
|
free(extensions);
|
|
|
|
|
|
- /* Check for OpenCL >= 1.0 support, needed for global offset parameter usage. */
|
|
|
- char * devoclver = malloc(1024);
|
|
|
- const char * ocl10 = "OpenCL 1.0";
|
|
|
-
|
|
|
- status = clGetDeviceInfo(devices[gpu], CL_DEVICE_VERSION, 1024, (void *)devoclver, NULL);
|
|
|
- if (status != CL_SUCCESS) {
|
|
|
- applog(LOG_ERR, "Error %d: Failed to clGetDeviceInfo when trying to get CL_DEVICE_VERSION", status);
|
|
|
- return NULL;
|
|
|
- }
|
|
|
- find = strstr(devoclver, ocl10);
|
|
|
- if (!find)
|
|
|
- clState->hasOpenCL11plus = true;
|
|
|
- free(devoclver);
|
|
|
-
|
|
|
- status = clGetDeviceInfo(devices[gpu], CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, sizeof(cl_uint), (void *)&preferred_vwidth, NULL);
|
|
|
+ status = clGetDeviceInfo(devices[gpu], CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, sizeof(cl_uint), (void *)&clState->preferred_vwidth, NULL);
|
|
|
if (status != CL_SUCCESS) {
|
|
|
applog(LOG_ERR, "Error %d: Failed to clGetDeviceInfo when trying to get CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT", status);
|
|
|
- return NULL;
|
|
|
+ goto err2;
|
|
|
}
|
|
|
- applog(LOG_DEBUG, "Preferred vector width reported %d", preferred_vwidth);
|
|
|
+ applog(LOG_DEBUG, "Preferred vector width reported %d", clState->preferred_vwidth);
|
|
|
|
|
|
status = clGetDeviceInfo(devices[gpu], CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(size_t), (void *)&clState->max_work_size, NULL);
|
|
|
if (status != CL_SUCCESS) {
|
|
|
applog(LOG_ERR, "Error %d: Failed to clGetDeviceInfo when trying to get CL_DEVICE_MAX_WORK_GROUP_SIZE", status);
|
|
|
- return NULL;
|
|
|
+ goto err2;
|
|
|
}
|
|
|
applog(LOG_DEBUG, "Max work group size reported %"PRId64, (int64_t)clState->max_work_size);
|
|
|
|
|
|
status = clGetDeviceInfo(devices[gpu], CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(clState->max_compute_units), (void *)&clState->max_compute_units, NULL);
|
|
|
if (status != CL_SUCCESS) {
|
|
|
applog(LOG_ERR, "Error %d: Failed to clGetDeviceInfo when trying to get CL_DEVICE_MAX_COMPUTE_UNITS", status);
|
|
|
- return NULL;
|
|
|
+ goto err2;
|
|
|
}
|
|
|
if (data->_init_intensity)
|
|
|
{
|
|
|
@@ -594,13 +627,16 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
|
|
|
opencl_set_intensity_from_str(cgpu, data->_init_intensity);
|
|
|
}
|
|
|
else
|
|
|
- data->oclthreads = intensity_to_oclthreads(MIN_INTENSITY, !opt_scrypt);
|
|
|
+ {
|
|
|
+ data->oclthreads = 1;
|
|
|
+ data->intensity = INT_MIN;
|
|
|
+ }
|
|
|
applog(LOG_DEBUG, "Max compute units reported %u", (unsigned)clState->max_compute_units);
|
|
|
|
|
|
status = clGetDeviceInfo(devices[gpu], CL_DEVICE_MAX_MEM_ALLOC_SIZE , sizeof(cl_ulong), (void *)&data->max_alloc, NULL);
|
|
|
if (status != CL_SUCCESS) {
|
|
|
applog(LOG_ERR, "Error %d: Failed to clGetDeviceInfo when trying to get CL_DEVICE_MAX_MEM_ALLOC_SIZE", status);
|
|
|
- return NULL;
|
|
|
+ goto err2;
|
|
|
}
|
|
|
applog(LOG_DEBUG, "Max mem alloc size is %lu", (unsigned long)data->max_alloc);
|
|
|
|
|
|
@@ -626,7 +662,7 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
|
|
|
}
|
|
|
else
|
|
|
applog(LOG_DEBUG, "Mesa OpenCL platform detected (v%ld.%ld)", major, minor);
|
|
|
- ismesa = true;
|
|
|
+ clState->is_mesa = true;
|
|
|
}
|
|
|
|
|
|
if (data->opt_opencl_binaries == OBU_DEFAULT)
|
|
|
@@ -638,7 +674,372 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
|
|
|
data->opt_opencl_binaries = OBU_LOADSAVE;
|
|
|
#endif
|
|
|
}
|
|
|
+
|
|
|
+ clState->devid = devices[gpu];
|
|
|
+ free(devices);
|
|
|
+
|
|
|
+ /* For some reason 2 vectors is still better even if the card says
|
|
|
+ * otherwise, and many cards lie about their max so use 256 as max
|
|
|
+ * unless explicitly set on the command line. Tahiti prefers 1 */
|
|
|
+ if (strstr(name, "Tahiti"))
|
|
|
+ clState->preferred_vwidth = 1;
|
|
|
+ else
|
|
|
+ if (clState->preferred_vwidth > 2)
|
|
|
+ clState->preferred_vwidth = 2;
|
|
|
+
|
|
|
+ if (data->vwidth)
|
|
|
+ clState->vwidth = data->vwidth;
|
|
|
+ else {
|
|
|
+ clState->vwidth = clState->preferred_vwidth;
|
|
|
+ data->vwidth = clState->preferred_vwidth;
|
|
|
+ }
|
|
|
+
|
|
|
+ clState->outputBuffer = clCreateBuffer(clState->context, 0, OPENCL_MAX_BUFFERSIZE, NULL, &status);
|
|
|
+ if (status != CL_SUCCESS) {
|
|
|
+ applog(LOG_ERR, "Error %d: clCreateBuffer (outputBuffer)", status);
|
|
|
+ // NOTE: devices is freed here, but still assigned
|
|
|
+ goto err;
|
|
|
+ }
|
|
|
+
|
|
|
+ return clState;
|
|
|
+}
|
|
|
+
|
|
|
+static
|
|
|
+bool opencl_load_kernel_binary(struct cgpu_info * const cgpu, _clState * const clState, struct opencl_kernel_info * const kernelinfo, const char * const binaryfilename, bytes_t * const b)
|
|
|
+{
|
|
|
+ cl_int status;
|
|
|
+
|
|
|
+ FILE * const binaryfile = fopen(binaryfilename, "rb");
|
|
|
+ if (!binaryfile)
|
|
|
+ return false;
|
|
|
+
|
|
|
+ struct stat binary_stat;
|
|
|
+ if (unlikely(stat(binaryfilename, &binary_stat)))
|
|
|
+ {
|
|
|
+ applog(LOG_DEBUG, "Unable to stat binary, generating from source");
|
|
|
+ fclose(binaryfile);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (!binary_stat.st_size)
|
|
|
+ {
|
|
|
+ fclose(binaryfile);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ const size_t binsz = binary_stat.st_size;
|
|
|
+ bytes_resize(b, binsz);
|
|
|
+ if (fread(bytes_buf(b), 1, binsz, binaryfile) != binsz)
|
|
|
+ {
|
|
|
+ applog(LOG_ERR, "Unable to fread binaries");
|
|
|
+ fclose(binaryfile);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ fclose(binaryfile);
|
|
|
+
|
|
|
+ kernelinfo->program = clCreateProgramWithBinary(clState->context, 1, &clState->devid, &binsz, (void*)&bytes_buf(b), &status, NULL);
|
|
|
+ if (status != CL_SUCCESS)
|
|
|
+ applogr(false, LOG_ERR, "Error %d: Loading Binary into cl_program (clCreateProgramWithBinary)", status);
|
|
|
+
|
|
|
+ status = bfg_clBuildProgram(&kernelinfo->program, clState->devid, NULL);
|
|
|
+ if (status != CL_SUCCESS)
|
|
|
+ return false;
|
|
|
+
|
|
|
+ applog(LOG_DEBUG, "Loaded binary image %s", binaryfilename);
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+static
|
|
|
+bool opencl_should_patch_bfi_int(struct cgpu_info * const cgpu, _clState * const clState, struct opencl_kernel_info * const kernelinfo)
|
|
|
+{
|
|
|
+#ifdef USE_SHA256D
|
|
|
+ struct opencl_device_data * const data = cgpu->device_data;
|
|
|
+ const char * const name = cgpu->name;
|
|
|
+ const char * const vbuff = clState->platform_ver_str;
|
|
|
+ char *s;
|
|
|
+
|
|
|
+ if (!clState->hasBitAlign)
|
|
|
+ return false;
|
|
|
+
|
|
|
+ if (!(strstr(name, "Cedar") ||
|
|
|
+ strstr(name, "Redwood") ||
|
|
|
+ strstr(name, "Juniper") ||
|
|
|
+ strstr(name, "Cypress" ) ||
|
|
|
+ strstr(name, "Hemlock" ) ||
|
|
|
+ strstr(name, "Caicos" ) ||
|
|
|
+ strstr(name, "Turks" ) ||
|
|
|
+ strstr(name, "Barts" ) ||
|
|
|
+ strstr(name, "Cayman" ) ||
|
|
|
+ strstr(name, "Antilles" ) ||
|
|
|
+ strstr(name, "Wrestler" ) ||
|
|
|
+ strstr(name, "Zacate" ) ||
|
|
|
+ strstr(name, "WinterPark" )))
|
|
|
+ return false;
|
|
|
+
|
|
|
+ // BFI_INT patching only works with AMD-APP up to 1084
|
|
|
+ if (strstr(vbuff, "ATI-Stream"))
|
|
|
+ {}
|
|
|
+ else
|
|
|
+ if ((s = strstr(vbuff, "AMD-APP")) && (s = strchr(s, '(')) && atoi(&s[1]) < 1085)
|
|
|
+ {}
|
|
|
+ else
|
|
|
+ return false;
|
|
|
+
|
|
|
+ switch (kernelinfo->interface)
|
|
|
+ {
|
|
|
+ case KL_DIABLO: case KL_DIAKGCN: case KL_PHATK: case KL_POCLBM:
|
|
|
+ // Okay, these actually use BFI_INT hacking
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ // Anything else has never needed it
|
|
|
+ return false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (data->opt_opencl_binaries != OBU_LOADSAVE)
|
|
|
+ applogr(false, LOG_WARNING, "BFI_INT patch requiring device found, but OpenCL binary usage disabled; cannot BFI_INT patch");
|
|
|
+
|
|
|
+ applog(LOG_DEBUG, "BFI_INT patch requiring device found, will patch source with BFI_INT");
|
|
|
+ return true;
|
|
|
+#else
|
|
|
+ return false;
|
|
|
+#endif
|
|
|
+}
|
|
|
|
|
|
+static
|
|
|
+bool opencl_build_kernel(struct cgpu_info * const cgpu, _clState * const clState, struct opencl_kernel_info * const kernelinfo, const char *source, const size_t source_len, const bool patchbfi)
|
|
|
+{
|
|
|
+ struct opencl_device_data * const data = cgpu->device_data;
|
|
|
+ cl_int status;
|
|
|
+
|
|
|
+ kernelinfo->program = clCreateProgramWithSource(clState->context, 1, &source, &source_len, &status);
|
|
|
+ if (status != CL_SUCCESS)
|
|
|
+ applogr(false, LOG_ERR, "Error %d: Loading Binary into cl_program (clCreateProgramWithSource)", status);
|
|
|
+
|
|
|
+ /* create a cl program executable for all the devices specified */
|
|
|
+ char *CompilerOptions = calloc(1, 256);
|
|
|
+
|
|
|
+#ifdef USE_SCRYPT
|
|
|
+ if (kernelinfo->interface == KL_SCRYPT)
|
|
|
+ sprintf(CompilerOptions, "-D LOOKUP_GAP=%d -D CONCURRENT_THREADS=%d -D WORKSIZE=%d",
|
|
|
+ data->lookup_gap, (unsigned int)data->thread_concurrency, (int)kernelinfo->wsize);
|
|
|
+ else
|
|
|
+#endif
|
|
|
+ {
|
|
|
+ sprintf(CompilerOptions, "-D WORKSIZE=%d -D VECTORS%d -D WORKVEC=%d",
|
|
|
+ (int)kernelinfo->wsize, clState->vwidth, (int)kernelinfo->wsize * clState->vwidth);
|
|
|
+ }
|
|
|
+ applog(LOG_DEBUG, "Setting worksize to %"PRId64, (int64_t)kernelinfo->wsize);
|
|
|
+ if (clState->vwidth > 1)
|
|
|
+ applog(LOG_DEBUG, "Patched source to suit %d vectors", clState->vwidth);
|
|
|
+
|
|
|
+ if (clState->hasBitAlign)
|
|
|
+ {
|
|
|
+ strcat(CompilerOptions, " -D BITALIGN");
|
|
|
+ applog(LOG_DEBUG, "cl_amd_media_ops found, setting BITALIGN");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ applog(LOG_DEBUG, "cl_amd_media_ops not found, will not set BITALIGN");
|
|
|
+
|
|
|
+#ifdef USE_SHA256D
|
|
|
+ if (patchbfi)
|
|
|
+ strcat(CompilerOptions, " -D BFI_INT");
|
|
|
+#endif
|
|
|
+
|
|
|
+ if (kernelinfo->goffset)
|
|
|
+ strcat(CompilerOptions, " -D GOFFSET");
|
|
|
+
|
|
|
+ applog(LOG_DEBUG, "CompilerOptions: %s", CompilerOptions);
|
|
|
+ status = bfg_clBuildProgram(&kernelinfo->program, clState->devid, CompilerOptions);
|
|
|
+ free(CompilerOptions);
|
|
|
+
|
|
|
+ if (status != CL_SUCCESS)
|
|
|
+ return false;
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+static
|
|
|
+bool opencl_get_kernel_binary(struct cgpu_info * const cgpu, _clState * const clState, struct opencl_kernel_info * const kernelinfo, bytes_t * const b)
|
|
|
+{
|
|
|
+ cl_int status;
|
|
|
+ cl_uint slot, cpnd;
|
|
|
+
|
|
|
+ status = clGetProgramInfo(kernelinfo->program, CL_PROGRAM_NUM_DEVICES, sizeof(cl_uint), &cpnd, NULL);
|
|
|
+ if (unlikely(status != CL_SUCCESS))
|
|
|
+ applogr(false, LOG_ERR, "Error %d: Getting program info CL_PROGRAM_NUM_DEVICES. (clGetProgramInfo)", status);
|
|
|
+
|
|
|
+ if (!cpnd)
|
|
|
+ return false;
|
|
|
+
|
|
|
+ size_t binary_sizes[cpnd];
|
|
|
+ status = clGetProgramInfo(kernelinfo->program, CL_PROGRAM_BINARY_SIZES, sizeof(binary_sizes), binary_sizes, NULL);
|
|
|
+ if (unlikely(status != CL_SUCCESS))
|
|
|
+ applogr(false, LOG_ERR, "Error %d: Getting program info CL_PROGRAM_BINARY_SIZES. (clGetProgramInfo)", status);
|
|
|
+
|
|
|
+ uint8_t **binaries = malloc(sizeof(*binaries) * cpnd);
|
|
|
+ for (slot = 0; slot < cpnd; ++slot)
|
|
|
+ binaries[slot] = malloc(binary_sizes[slot] + 1);
|
|
|
+
|
|
|
+ /* The actual compiled binary ends up in a RANDOM slot! Grr, so we have
|
|
|
+ * to iterate over all the binary slots and find where the real program
|
|
|
+ * is. What the heck is this!? */
|
|
|
+ for (slot = 0; slot < cpnd; slot++)
|
|
|
+ if (binary_sizes[slot])
|
|
|
+ break;
|
|
|
+
|
|
|
+ /* copy over all of the generated binaries. */
|
|
|
+ applog(LOG_DEBUG, "%s: Binary size found in binary slot %u: %"PRId64, cgpu->dev_repr, (unsigned)slot, (int64_t)binary_sizes[slot]);
|
|
|
+ if (!binary_sizes[slot])
|
|
|
+ applogr(false, LOG_ERR, "OpenCL compiler generated a zero sized binary, FAIL!");
|
|
|
+ status = clGetProgramInfo(kernelinfo->program, CL_PROGRAM_BINARIES, sizeof(binaries), binaries, NULL);
|
|
|
+ if (unlikely(status != CL_SUCCESS))
|
|
|
+ applogr(false, LOG_ERR, "Error %d: Getting program info. CL_PROGRAM_BINARIES (clGetProgramInfo)", status);
|
|
|
+
|
|
|
+ bytes_resize(b, binary_sizes[slot]);
|
|
|
+ memcpy(bytes_buf(b), binaries[slot], bytes_len(b));
|
|
|
+
|
|
|
+ for (slot = 0; slot < cpnd; ++slot)
|
|
|
+ free(binaries[slot]);
|
|
|
+ free(binaries);
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+#ifdef USE_SHA256D
|
|
|
+ /* Patch the kernel if the hardware supports BFI_INT but it needs to
|
|
|
+ * be hacked in */
|
|
|
+static
|
|
|
+bool opencl_patch_kernel_binary(bytes_t * const b)
|
|
|
+{
|
|
|
+ unsigned remaining = bytes_len(b);
|
|
|
+ char *w = (void*)bytes_buf(b);
|
|
|
+ unsigned int start, length;
|
|
|
+
|
|
|
+ /* Find 2nd incidence of .text, and copy the program's
|
|
|
+ * position and length at a fixed offset from that. Then go
|
|
|
+ * back and find the 2nd incidence of \x7ELF (rewind by one
|
|
|
+ * from ELF) and then patch the opcocdes */
|
|
|
+ if (!advance(&w, &remaining, ".text"))
|
|
|
+ return false;
|
|
|
+ w++; remaining--;
|
|
|
+ if (!advance(&w, &remaining, ".text")) {
|
|
|
+ /* 32 bit builds only one ELF */
|
|
|
+ w--; remaining++;
|
|
|
+ }
|
|
|
+ memcpy(&start, w + 285, 4);
|
|
|
+ memcpy(&length, w + 289, 4);
|
|
|
+ w = (void*)bytes_buf(b);
|
|
|
+ remaining = bytes_len(b);
|
|
|
+ if (!advance(&w, &remaining, "ELF"))
|
|
|
+ return false;
|
|
|
+ w++; remaining--;
|
|
|
+ if (!advance(&w, &remaining, "ELF")) {
|
|
|
+ /* 32 bit builds only one ELF */
|
|
|
+ w--; remaining++;
|
|
|
+ }
|
|
|
+ w--; remaining++;
|
|
|
+ w += start; remaining -= start;
|
|
|
+ applog(LOG_DEBUG, "At %p (%u rem. bytes), to begin patching", w, remaining);
|
|
|
+ patch_opcodes(w, length);
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+static
|
|
|
+bool opencl_replace_binary_kernel(struct cgpu_info * const cgpu, _clState * const clState, struct opencl_kernel_info * const kernelinfo, bytes_t * const b)
|
|
|
+{
|
|
|
+ cl_int status;
|
|
|
+
|
|
|
+ status = clReleaseProgram(kernelinfo->program);
|
|
|
+ if (status != CL_SUCCESS)
|
|
|
+ applogr(false, LOG_ERR, "Error %d: Releasing program. (clReleaseProgram)", status);
|
|
|
+
|
|
|
+ const size_t binsz = bytes_len(b);
|
|
|
+ kernelinfo->program = clCreateProgramWithBinary(clState->context, 1, &clState->devid, &binsz, (void*)&bytes_buf(b), &status, NULL);
|
|
|
+ if (status != CL_SUCCESS)
|
|
|
+ applogr(false, LOG_ERR, "Error %d: Loading Binary into cl_program (clCreateProgramWithBinary)", status);
|
|
|
+
|
|
|
+ status = bfg_clBuildProgram(&kernelinfo->program, clState->devid, NULL);
|
|
|
+ if (status != CL_SUCCESS)
|
|
|
+ return false;
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
+static
|
|
|
+bool opencl_save_kernel_binary(const char * const binaryfilename, bytes_t * const b)
|
|
|
+{
|
|
|
+ FILE *binaryfile;
|
|
|
+
|
|
|
+ /* Save the binary to be loaded next time */
|
|
|
+ binaryfile = fopen(binaryfilename, "wb");
|
|
|
+ if (!binaryfile)
|
|
|
+ return false;
|
|
|
+
|
|
|
+ // FIXME: Failure here results in a bad file; better to write and move-replace (but unlink before replacing for Windows)
|
|
|
+ if (unlikely(fwrite(bytes_buf(b), 1, bytes_len(b), binaryfile) != bytes_len(b)))
|
|
|
+ {
|
|
|
+ fclose(binaryfile);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ fclose(binaryfile);
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+static
|
|
|
+bool opencl_test_goffset(_clState * const clState)
|
|
|
+{
|
|
|
+ if (sizeof(size_t) < sizeof(uint32_t))
|
|
|
+ return false;
|
|
|
+
|
|
|
+ const char *source = "__kernel __attribute__((reqd_work_group_size(64, 1, 1))) void runtest(volatile __global uint *out) { *out = get_global_id(0); }";
|
|
|
+ const size_t source_len = strlen(source);
|
|
|
+ cl_int status;
|
|
|
+ cl_program program = clCreateProgramWithSource(clState->context, 1, &source, &source_len, &status);
|
|
|
+ if (status != CL_SUCCESS)
|
|
|
+ applogr(false, LOG_ERR, "Error %d: Loading %s code into cl_program (clCreateProgramWithSource)", status, "goffset test");
|
|
|
+ status = bfg_clBuildProgram(&program, clState->devid, "");
|
|
|
+ if (status != CL_SUCCESS)
|
|
|
+ {
|
|
|
+fail:
|
|
|
+ clReleaseProgram(program);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ cl_kernel kernel = clCreateKernel(program, "runtest", &status);
|
|
|
+ if (status != CL_SUCCESS)
|
|
|
+ return_via_applog(fail, , LOG_ERR, "Error %d: Creating kernel from %s program (clCreateKernel)", status, "goffset test");
|
|
|
+ static const uint32_t cleardata = 0;
|
|
|
+ status = clEnqueueWriteBuffer(clState->commandQueue, clState->outputBuffer, CL_FALSE, 0, sizeof(cleardata), &cleardata, 0, NULL, NULL);
|
|
|
+ if (status != CL_SUCCESS)
|
|
|
+ {
|
|
|
+ applog(LOG_ERR, "Error %d: Clearing output buffer for %s kernel (clEnqueueWriteBuffer)", status, "goffset test");
|
|
|
+fail2:
|
|
|
+ clReleaseKernel(kernel);
|
|
|
+ goto fail;
|
|
|
+ }
|
|
|
+ status = clSetKernelArg(kernel, 0, sizeof(clState->outputBuffer), &clState->outputBuffer);
|
|
|
+ if (status != CL_SUCCESS)
|
|
|
+ return_via_applog(fail2, , LOG_ERR, "Error %d: Setting kernel argument for %s kernel (clSetKernelArg)", status, "goffset test");
|
|
|
+ const size_t size_t_one = 1, test_goffset = 0xfabd0bf9;
|
|
|
+ status = clEnqueueNDRangeKernel(clState->commandQueue, kernel, 1, &test_goffset, &size_t_one, &size_t_one, 0, NULL, NULL);
|
|
|
+ if (status != CL_SUCCESS)
|
|
|
+ return_via_applog(fail2, , LOG_DEBUG, "Error %d: Running %s kernel (clEnqueueNDRangeKernel)", status, "goffset test");
|
|
|
+ uint32_t resultdata;
|
|
|
+ status = clEnqueueReadBuffer(clState->commandQueue, clState->outputBuffer, CL_TRUE, 0, sizeof(resultdata), &resultdata, 0, NULL, NULL);
|
|
|
+ if (status != CL_SUCCESS)
|
|
|
+ return_via_applog(fail2, , LOG_DEBUG, "Error %d: Reading result from %s kernel (clEnqueueReadBuffer)", status, "goffset test");
|
|
|
+ applog(LOG_DEBUG, "%s kernel returned 0x%08lx for goffset 0x%08lx", "goffset test", (unsigned long)resultdata, (unsigned long)test_goffset);
|
|
|
+ return (resultdata == test_goffset);
|
|
|
+}
|
|
|
+
|
|
|
+bool opencl_load_kernel(struct cgpu_info * const cgpu, _clState * const clState, const char * const name, struct opencl_kernel_info * const kernelinfo, const char * const kernel_file, __maybe_unused const struct mining_algorithm * const malgo)
|
|
|
+{
|
|
|
+ const int gpu = cgpu->device_id;
|
|
|
+ struct opencl_device_data * const data = cgpu->device_data;
|
|
|
+ const char * const vbuff = clState->platform_ver_str;
|
|
|
+ cl_int status;
|
|
|
+
|
|
|
/* Create binary filename based on parameters passed to opencl
|
|
|
* compiler to ensure we only load a binary that matches what would
|
|
|
* have otherwise created. The filename is:
|
|
|
@@ -650,45 +1051,12 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
|
|
|
char filename[255];
|
|
|
char numbuf[32];
|
|
|
|
|
|
- if (!data->kernel_file)
|
|
|
- {
|
|
|
- if (opt_scrypt) {
|
|
|
- applog(LOG_INFO, "Selecting scrypt kernel");
|
|
|
- clState->chosen_kernel = KL_SCRYPT;
|
|
|
- }
|
|
|
- else if (ismesa)
|
|
|
- {
|
|
|
- applog(LOG_INFO, "Selecting phatk kernel for Mesa");
|
|
|
- clState->chosen_kernel = KL_PHATK;
|
|
|
- } else if (!strstr(name, "Tahiti") &&
|
|
|
- /* Detect all 2.6 SDKs not with Tahiti and use diablo kernel */
|
|
|
- (strstr(vbuff, "844.4") || // Linux 64 bit ATI 2.6 SDK
|
|
|
- strstr(vbuff, "851.4") || // Windows 64 bit ""
|
|
|
- strstr(vbuff, "831.4") ||
|
|
|
- strstr(vbuff, "898.1") || // 12.2 driver SDK
|
|
|
- strstr(vbuff, "923.1") || // 12.4
|
|
|
- strstr(vbuff, "938.2") || // SDK 2.7
|
|
|
- strstr(vbuff, "1113.2"))) {// SDK 2.8
|
|
|
- applog(LOG_INFO, "Selecting diablo kernel");
|
|
|
- clState->chosen_kernel = KL_DIABLO;
|
|
|
- /* Detect all 7970s, older ATI and NVIDIA and use poclbm */
|
|
|
- } else if (strstr(name, "Tahiti") || !clState->hasBitAlign) {
|
|
|
- applog(LOG_INFO, "Selecting poclbm kernel");
|
|
|
- clState->chosen_kernel = KL_POCLBM;
|
|
|
- /* Use phatk for the rest R5xxx R6xxx */
|
|
|
- } else {
|
|
|
- applog(LOG_INFO, "Selecting phatk kernel");
|
|
|
- clState->chosen_kernel = KL_PHATK;
|
|
|
- }
|
|
|
- data->kernel_file = strdup(opencl_get_kernel_interface_name(clState->chosen_kernel));
|
|
|
- }
|
|
|
-
|
|
|
- snprintf(filename, sizeof(filename), "%s.cl", data->kernel_file);
|
|
|
- snprintf(binaryfilename, sizeof(filename), "%s", data->kernel_file);
|
|
|
+ snprintf(filename, sizeof(filename), "%s.cl", kernel_file);
|
|
|
+ snprintf(binaryfilename, sizeof(filename), "%s", kernel_file);
|
|
|
int pl;
|
|
|
- char *source = file_contents(filename, &pl);
|
|
|
+ char *source = opencl_kernel_source(filename, &pl, &kernelinfo->interface, NULL);
|
|
|
if (!source)
|
|
|
- return NULL;
|
|
|
+ return false;
|
|
|
{
|
|
|
uint8_t hash[0x20];
|
|
|
char hashhex[7];
|
|
|
@@ -696,29 +1064,14 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
|
|
|
bin2hex(hashhex, hash, 3);
|
|
|
tailsprintf(binaryfilename, sizeof(binaryfilename), "-%s", hashhex);
|
|
|
}
|
|
|
- s = strstr(source, "kernel-interface:");
|
|
|
- if (s)
|
|
|
+ switch (kernelinfo->interface)
|
|
|
{
|
|
|
- for (s = &s[17]; s[0] && isspace(s[0]); ++s)
|
|
|
- if (s[0] == '\n' || s[0] == '\r')
|
|
|
- break;
|
|
|
- for (q = s; q[0] && !isspace(q[0]); ++q)
|
|
|
- {} // Find end of string
|
|
|
- const size_t kinamelen = q - s;
|
|
|
- char kiname[kinamelen + 1];
|
|
|
- memcpy(kiname, s, kinamelen);
|
|
|
- kiname[kinamelen] = '\0';
|
|
|
- clState->chosen_kernel = select_kernel(kiname);
|
|
|
- }
|
|
|
- else
|
|
|
- if (opt_scrypt)
|
|
|
- clState->chosen_kernel = KL_SCRYPT;
|
|
|
- switch (clState->chosen_kernel) {
|
|
|
case KL_NONE:
|
|
|
applog(LOG_ERR, "%s: Failed to identify kernel interface for %s",
|
|
|
- cgpu->dev_repr, data->kernel_file);
|
|
|
+ cgpu->dev_repr, kernel_file);
|
|
|
free(source);
|
|
|
- return NULL;
|
|
|
+ return false;
|
|
|
+#ifdef USE_SHA256D
|
|
|
case KL_PHATK:
|
|
|
if ((strstr(vbuff, "844.4") || strstr(vbuff, "851.4") ||
|
|
|
strstr(vbuff, "831.4") || strstr(vbuff, "898.1") ||
|
|
|
@@ -729,51 +1082,76 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
|
|
|
applog(LOG_WARNING, "Downgrade your SDK and delete any .bin files before starting again.");
|
|
|
applog(LOG_WARNING, "Or allow BFGMiner to automatically choose a more suitable kernel.");
|
|
|
}
|
|
|
+#endif
|
|
|
default:
|
|
|
;
|
|
|
}
|
|
|
applog(LOG_DEBUG, "%s: Using kernel %s with interface %s",
|
|
|
- cgpu->dev_repr, data->kernel_file,
|
|
|
- opencl_get_kernel_interface_name(clState->chosen_kernel));
|
|
|
+ cgpu->dev_repr, kernel_file,
|
|
|
+ opencl_get_kernel_interface_name(kernelinfo->interface));
|
|
|
|
|
|
- /* For some reason 2 vectors is still better even if the card says
|
|
|
- * otherwise, and many cards lie about their max so use 256 as max
|
|
|
- * unless explicitly set on the command line. Tahiti prefers 1 */
|
|
|
- if (strstr(name, "Tahiti"))
|
|
|
- preferred_vwidth = 1;
|
|
|
- else if (preferred_vwidth > 2)
|
|
|
- preferred_vwidth = 2;
|
|
|
-
|
|
|
- if (data->vwidth)
|
|
|
- clState->vwidth = data->vwidth;
|
|
|
- else {
|
|
|
- clState->vwidth = preferred_vwidth;
|
|
|
- data->vwidth = preferred_vwidth;
|
|
|
+ {
|
|
|
+ int kernel_goffset_support = 0; // 0 = none; 1 = optional; 2 = required
|
|
|
+ if (strstr(source, "def GOFFSET"))
|
|
|
+ kernel_goffset_support = 1;
|
|
|
+ else
|
|
|
+ if (strstr(source, " base,"))
|
|
|
+ kernel_goffset_support = 0;
|
|
|
+ else
|
|
|
+ kernel_goffset_support = 2;
|
|
|
+ bool device_goffset_support = false;
|
|
|
+ switch (data->use_goffset)
|
|
|
+ {
|
|
|
+ case BTS_TRUE:
|
|
|
+ device_goffset_support = true;
|
|
|
+ break;
|
|
|
+ case BTS_FALSE:
|
|
|
+ // if the kernel requires goffset, don't allow the user to disable it
|
|
|
+ if (kernel_goffset_support == 2)
|
|
|
+ {
|
|
|
+ if (opencl_test_goffset(clState))
|
|
|
+ device_goffset_support = true;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case BTS_UNKNOWN:
|
|
|
+ data->use_goffset = opencl_test_goffset(clState);
|
|
|
+ if (data->use_goffset)
|
|
|
+ device_goffset_support = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ applog(LOG_DEBUG, "%s: goffset support: device=%s kernel=%s", cgpu->dev_repr, device_goffset_support ? "yes" : "no", (kernel_goffset_support == 2) ? "required" : ((kernel_goffset_support == 1) ? "optional" : "none"));
|
|
|
+ if (device_goffset_support)
|
|
|
+ {
|
|
|
+ if (kernel_goffset_support)
|
|
|
+ kernelinfo->goffset = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ if (kernel_goffset_support == 2)
|
|
|
+ {
|
|
|
+ // FIXME: Determine this before min_nonce_diff returns positive
|
|
|
+ applog(LOG_ERR, "%s: Need goffset support!", cgpu->dev_repr);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- if (((clState->chosen_kernel == KL_POCLBM || clState->chosen_kernel == KL_DIABLO || clState->chosen_kernel == KL_DIAKGCN) &&
|
|
|
- clState->vwidth == 1 && clState->hasOpenCL11plus) || opt_scrypt)
|
|
|
- clState->goffset = true;
|
|
|
-
|
|
|
if (data->work_size && data->work_size <= clState->max_work_size)
|
|
|
- clState->wsize = data->work_size;
|
|
|
- else if (opt_scrypt)
|
|
|
- clState->wsize = 256;
|
|
|
- else if (strstr(name, "Tahiti"))
|
|
|
- clState->wsize = 64;
|
|
|
+ kernelinfo->wsize = data->work_size;
|
|
|
+ else
|
|
|
+#ifdef USE_SCRYPT
|
|
|
+ if (malgo->algo == POW_SCRYPT)
|
|
|
+ kernelinfo->wsize = 256;
|
|
|
else
|
|
|
- clState->wsize = (clState->max_work_size <= 256 ? clState->max_work_size : 256) / clState->vwidth;
|
|
|
- data->work_size = clState->wsize;
|
|
|
+#endif
|
|
|
+ if (strstr(name, "Tahiti"))
|
|
|
+ kernelinfo->wsize = 64;
|
|
|
+ else
|
|
|
+ kernelinfo->wsize = (clState->max_work_size <= 256 ? clState->max_work_size : 256) / clState->vwidth;
|
|
|
|
|
|
#ifdef USE_SCRYPT
|
|
|
- if (opt_scrypt) {
|
|
|
- if (!data->opt_lg) {
|
|
|
- applog(LOG_DEBUG, "GPU %d: selecting lookup gap of 2", gpu);
|
|
|
- data->lookup_gap = 2;
|
|
|
- } else
|
|
|
- data->lookup_gap = data->opt_lg;
|
|
|
-
|
|
|
- if (!data->opt_tc) {
|
|
|
+ if (kernelinfo->interface == KL_SCRYPT)
|
|
|
+ {
|
|
|
+ if (!data->thread_concurrency)
|
|
|
+ {
|
|
|
unsigned int sixtyfours;
|
|
|
|
|
|
sixtyfours = data->max_alloc / 131072 / 64 - 1;
|
|
|
@@ -784,43 +1162,26 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
|
|
|
data->thread_concurrency = data->shaders * 5;
|
|
|
}
|
|
|
applog(LOG_DEBUG, "GPU %u: selecting thread concurrency of %lu", gpu, (unsigned long)data->thread_concurrency);
|
|
|
- } else
|
|
|
- data->thread_concurrency = data->opt_tc;
|
|
|
+ }
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
- FILE *binaryfile;
|
|
|
- size_t *binary_sizes;
|
|
|
- char **binaries;
|
|
|
- size_t sourceSize[] = {(size_t)pl};
|
|
|
- cl_uint slot, cpnd;
|
|
|
-
|
|
|
- slot = cpnd = 0;
|
|
|
-
|
|
|
- binary_sizes = calloc(sizeof(size_t) * MAX_GPUDEVICES * 4, 1);
|
|
|
- if (unlikely(!binary_sizes)) {
|
|
|
- applog(LOG_ERR, "Unable to calloc binary_sizes");
|
|
|
- return NULL;
|
|
|
- }
|
|
|
- binaries = calloc(sizeof(char *) * MAX_GPUDEVICES * 4, 1);
|
|
|
- if (unlikely(!binaries)) {
|
|
|
- applog(LOG_ERR, "Unable to calloc binaries");
|
|
|
- return NULL;
|
|
|
- }
|
|
|
-
|
|
|
strcat(binaryfilename, name);
|
|
|
- if (clState->goffset)
|
|
|
+ if (kernelinfo->goffset)
|
|
|
strcat(binaryfilename, "g");
|
|
|
- if (opt_scrypt) {
|
|
|
#ifdef USE_SCRYPT
|
|
|
+ if (kernelinfo->interface == KL_SCRYPT)
|
|
|
+ {
|
|
|
sprintf(numbuf, "lg%utc%u", data->lookup_gap, (unsigned int)data->thread_concurrency);
|
|
|
strcat(binaryfilename, numbuf);
|
|
|
+ }
|
|
|
+ else
|
|
|
#endif
|
|
|
- } else {
|
|
|
+ {
|
|
|
sprintf(numbuf, "v%d", clState->vwidth);
|
|
|
strcat(binaryfilename, numbuf);
|
|
|
}
|
|
|
- sprintf(numbuf, "w%d", (int)clState->wsize);
|
|
|
+ sprintf(numbuf, "w%d", (int)kernelinfo->wsize);
|
|
|
strcat(binaryfilename, numbuf);
|
|
|
sprintf(numbuf, "l%d", (int)sizeof(long));
|
|
|
strcat(binaryfilename, numbuf);
|
|
|
@@ -830,301 +1191,124 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
|
|
|
applog(LOG_DEBUG, "OCL%2u: Configured OpenCL kernel name: %s", gpu, binaryfilename);
|
|
|
strcat(binaryfilename, ".bin");
|
|
|
|
|
|
- if (!(data->opt_opencl_binaries & OBU_LOAD))
|
|
|
- goto build;
|
|
|
-
|
|
|
- binaryfile = fopen(binaryfilename, "rb");
|
|
|
- if (!binaryfile) {
|
|
|
- applog(LOG_DEBUG, "No binary found, generating from source");
|
|
|
- } else {
|
|
|
- struct stat binary_stat;
|
|
|
-
|
|
|
- if (unlikely(stat(binaryfilename, &binary_stat))) {
|
|
|
- applog(LOG_DEBUG, "Unable to stat binary, generating from source");
|
|
|
- fclose(binaryfile);
|
|
|
- goto build;
|
|
|
- }
|
|
|
- if (!binary_stat.st_size)
|
|
|
- goto build;
|
|
|
-
|
|
|
- binary_sizes[slot] = binary_stat.st_size;
|
|
|
- binaries[slot] = (char *)calloc(binary_sizes[slot], 1);
|
|
|
- if (unlikely(!binaries[slot])) {
|
|
|
- applog(LOG_ERR, "Unable to calloc binaries");
|
|
|
- fclose(binaryfile);
|
|
|
- return NULL;
|
|
|
- }
|
|
|
-
|
|
|
- if (fread(binaries[slot], 1, binary_sizes[slot], binaryfile) != binary_sizes[slot]) {
|
|
|
- applog(LOG_ERR, "Unable to fread binaries");
|
|
|
- fclose(binaryfile);
|
|
|
- free(binaries[slot]);
|
|
|
- goto build;
|
|
|
- }
|
|
|
-
|
|
|
- clState->program = clCreateProgramWithBinary(clState->context, 1, &devices[gpu], &binary_sizes[slot], (const unsigned char **)binaries, &status, NULL);
|
|
|
- if (status != CL_SUCCESS) {
|
|
|
- applog(LOG_ERR, "Error %d: Loading Binary into cl_program (clCreateProgramWithBinary)", status);
|
|
|
- fclose(binaryfile);
|
|
|
- free(binaries[slot]);
|
|
|
- goto build;
|
|
|
+ bool patchbfi = opencl_should_patch_bfi_int(cgpu, clState, kernelinfo);
|
|
|
+
|
|
|
+ bytes_t binary_bytes = BYTES_INIT;
|
|
|
+ bool loaded_kernel = false;
|
|
|
+ if (data->opt_opencl_binaries & OBU_LOAD)
|
|
|
+ {
|
|
|
+ if (opencl_load_kernel_binary(cgpu, clState, kernelinfo, binaryfilename, &binary_bytes))
|
|
|
+ loaded_kernel = true;
|
|
|
+ else
|
|
|
+ {
|
|
|
+ bytes_free(&binary_bytes);
|
|
|
+ applog(LOG_DEBUG, "No usable binary found, generating from source");
|
|
|
}
|
|
|
-
|
|
|
- fclose(binaryfile);
|
|
|
- applog(LOG_DEBUG, "Loaded binary image %s", binaryfilename);
|
|
|
-
|
|
|
- goto built;
|
|
|
- }
|
|
|
-
|
|
|
- /////////////////////////////////////////////////////////////////
|
|
|
- // Load CL file, build CL program object, create CL kernel object
|
|
|
- /////////////////////////////////////////////////////////////////
|
|
|
-
|
|
|
-build:
|
|
|
- clState->program = clCreateProgramWithSource(clState->context, 1, (const char **)&source, sourceSize, &status);
|
|
|
- if (status != CL_SUCCESS) {
|
|
|
- applog(LOG_ERR, "Error %d: Loading Binary into cl_program (clCreateProgramWithSource)", status);
|
|
|
- return NULL;
|
|
|
}
|
|
|
-
|
|
|
- /* create a cl program executable for all the devices specified */
|
|
|
- char *CompilerOptions = calloc(1, 256);
|
|
|
-
|
|
|
-#ifdef USE_SCRYPT
|
|
|
- if (opt_scrypt)
|
|
|
- sprintf(CompilerOptions, "-D LOOKUP_GAP=%d -D CONCURRENT_THREADS=%d -D WORKSIZE=%d",
|
|
|
- data->lookup_gap, (unsigned int)data->thread_concurrency, (int)clState->wsize);
|
|
|
- else
|
|
|
-#endif
|
|
|
+
|
|
|
+ if (!loaded_kernel)
|
|
|
{
|
|
|
- sprintf(CompilerOptions, "-D WORKSIZE=%d -D VECTORS%d -D WORKVEC=%d",
|
|
|
- (int)clState->wsize, clState->vwidth, (int)clState->wsize * clState->vwidth);
|
|
|
- }
|
|
|
- applog(LOG_DEBUG, "Setting worksize to %"PRId64, (int64_t)clState->wsize);
|
|
|
- if (clState->vwidth > 1)
|
|
|
- applog(LOG_DEBUG, "Patched source to suit %d vectors", clState->vwidth);
|
|
|
-
|
|
|
- if (clState->hasBitAlign) {
|
|
|
- strcat(CompilerOptions, " -D BITALIGN");
|
|
|
- applog(LOG_DEBUG, "cl_amd_media_ops found, setting BITALIGN");
|
|
|
- if (strstr(name, "Cedar") ||
|
|
|
- strstr(name, "Redwood") ||
|
|
|
- strstr(name, "Juniper") ||
|
|
|
- strstr(name, "Cypress" ) ||
|
|
|
- strstr(name, "Hemlock" ) ||
|
|
|
- strstr(name, "Caicos" ) ||
|
|
|
- strstr(name, "Turks" ) ||
|
|
|
- strstr(name, "Barts" ) ||
|
|
|
- strstr(name, "Cayman" ) ||
|
|
|
- strstr(name, "Antilles" ) ||
|
|
|
- strstr(name, "Wrestler" ) ||
|
|
|
- strstr(name, "Zacate" ) ||
|
|
|
- strstr(name, "WinterPark" ))
|
|
|
+build:
|
|
|
+ if (!opencl_build_kernel(cgpu, clState, kernelinfo, source, pl, patchbfi))
|
|
|
{
|
|
|
- // BFI_INT patching only works with AMD-APP up to 1084
|
|
|
- if (strstr(vbuff, "ATI-Stream"))
|
|
|
- patchbfi = true;
|
|
|
- else
|
|
|
- if ((s = strstr(vbuff, "AMD-APP")) && (s = strchr(s, '(')) && atoi(&s[1]) < 1085)
|
|
|
- patchbfi = true;
|
|
|
+ free(source);
|
|
|
+ return false;
|
|
|
}
|
|
|
- } else
|
|
|
- applog(LOG_DEBUG, "cl_amd_media_ops not found, will not set BITALIGN");
|
|
|
-
|
|
|
- if (patchbfi) {
|
|
|
- if (data->opt_opencl_binaries == OBU_LOADSAVE)
|
|
|
+
|
|
|
+ if ((patchbfi || (data->opt_opencl_binaries & OBU_SAVE)) && !bytes_len(&binary_bytes))
|
|
|
{
|
|
|
- strcat(CompilerOptions, " -D BFI_INT");
|
|
|
- applog(LOG_DEBUG, "BFI_INT patch requiring device found, patched source with BFI_INT");
|
|
|
+ if (!opencl_get_kernel_binary(cgpu, clState, kernelinfo, &binary_bytes))
|
|
|
+ {
|
|
|
+ bytes_free(&binary_bytes);
|
|
|
+ applog(LOG_DEBUG, "%s: Failed to get compiled kernel binary from OpenCL (cannot save it)", cgpu->dev_repr);
|
|
|
+ // NOTE: empty binary_bytes will fail BFI_INT patch on its own
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
+
|
|
|
+#ifdef USE_SHA256D
|
|
|
+ if (patchbfi)
|
|
|
{
|
|
|
- patchbfi = false;
|
|
|
- applog(LOG_WARNING, "BFI_INT patch requiring device found, but OpenCL binary usage disabled; cannot BFI_INT patch");
|
|
|
- }
|
|
|
- } else
|
|
|
- applog(LOG_DEBUG, "BFI_INT patch requiring device not found, will not BFI_INT patch");
|
|
|
-
|
|
|
- if (clState->goffset)
|
|
|
- strcat(CompilerOptions, " -D GOFFSET");
|
|
|
-
|
|
|
- if (!clState->hasOpenCL11plus)
|
|
|
- strcat(CompilerOptions, " -D OCL1");
|
|
|
-
|
|
|
- applog(LOG_DEBUG, "CompilerOptions: %s", CompilerOptions);
|
|
|
- status = bfg_clBuildProgram(clState, devices[gpu], CompilerOptions);
|
|
|
- free(CompilerOptions);
|
|
|
-
|
|
|
- if (status != CL_SUCCESS)
|
|
|
- return NULL;
|
|
|
-
|
|
|
- prog_built = true;
|
|
|
-
|
|
|
- if (!(data->opt_opencl_binaries & OBU_SAVE))
|
|
|
- goto built;
|
|
|
-
|
|
|
- status = clGetProgramInfo(clState->program, CL_PROGRAM_NUM_DEVICES, sizeof(cl_uint), &cpnd, NULL);
|
|
|
- if (unlikely(status != CL_SUCCESS)) {
|
|
|
- applog(LOG_ERR, "Error %d: Getting program info CL_PROGRAM_NUM_DEVICES. (clGetProgramInfo)", status);
|
|
|
- return NULL;
|
|
|
- }
|
|
|
-
|
|
|
- status = clGetProgramInfo(clState->program, CL_PROGRAM_BINARY_SIZES, sizeof(size_t)*cpnd, binary_sizes, NULL);
|
|
|
- if (unlikely(status != CL_SUCCESS)) {
|
|
|
- applog(LOG_ERR, "Error %d: Getting program info CL_PROGRAM_BINARY_SIZES. (clGetProgramInfo)", status);
|
|
|
- return NULL;
|
|
|
- }
|
|
|
-
|
|
|
- /* The actual compiled binary ends up in a RANDOM slot! Grr, so we have
|
|
|
- * to iterate over all the binary slots and find where the real program
|
|
|
- * is. What the heck is this!? */
|
|
|
- for (slot = 0; slot < cpnd; slot++)
|
|
|
- if (binary_sizes[slot])
|
|
|
- break;
|
|
|
-
|
|
|
- /* copy over all of the generated binaries. */
|
|
|
- applog(LOG_DEBUG, "Binary size for gpu %u found in binary slot %u: %"PRId64,
|
|
|
- gpu, (unsigned)slot, (int64_t)binary_sizes[slot]);
|
|
|
- if (!binary_sizes[slot]) {
|
|
|
- applog(LOG_ERR, "OpenCL compiler generated a zero sized binary, FAIL!");
|
|
|
- return NULL;
|
|
|
- }
|
|
|
- binaries[slot] = calloc(sizeof(char) * binary_sizes[slot], 1);
|
|
|
- status = clGetProgramInfo(clState->program, CL_PROGRAM_BINARIES, sizeof(char *) * cpnd, binaries, NULL );
|
|
|
- if (unlikely(status != CL_SUCCESS)) {
|
|
|
- applog(LOG_ERR, "Error %d: Getting program info. CL_PROGRAM_BINARIES (clGetProgramInfo)", status);
|
|
|
- return NULL;
|
|
|
- }
|
|
|
-
|
|
|
- /* Patch the kernel if the hardware supports BFI_INT but it needs to
|
|
|
- * be hacked in */
|
|
|
- if (patchbfi) {
|
|
|
- unsigned remaining = binary_sizes[slot];
|
|
|
- char *w = binaries[slot];
|
|
|
- unsigned int start, length;
|
|
|
-
|
|
|
- /* Find 2nd incidence of .text, and copy the program's
|
|
|
- * position and length at a fixed offset from that. Then go
|
|
|
- * back and find the 2nd incidence of \x7ELF (rewind by one
|
|
|
- * from ELF) and then patch the opcocdes */
|
|
|
- if (!advance(&w, &remaining, ".text"))
|
|
|
- goto build;
|
|
|
- w++; remaining--;
|
|
|
- if (!advance(&w, &remaining, ".text")) {
|
|
|
- /* 32 bit builds only one ELF */
|
|
|
- w--; remaining++;
|
|
|
- }
|
|
|
- memcpy(&start, w + 285, 4);
|
|
|
- memcpy(&length, w + 289, 4);
|
|
|
- w = binaries[slot]; remaining = binary_sizes[slot];
|
|
|
- if (!advance(&w, &remaining, "ELF"))
|
|
|
- goto build;
|
|
|
- w++; remaining--;
|
|
|
- if (!advance(&w, &remaining, "ELF")) {
|
|
|
- /* 32 bit builds only one ELF */
|
|
|
- w--; remaining++;
|
|
|
- }
|
|
|
- w--; remaining++;
|
|
|
- w += start; remaining -= start;
|
|
|
- applog(LOG_DEBUG, "At %p (%u rem. bytes), to begin patching",
|
|
|
- w, remaining);
|
|
|
- patch_opcodes(w, length);
|
|
|
-
|
|
|
- status = clReleaseProgram(clState->program);
|
|
|
- if (status != CL_SUCCESS) {
|
|
|
- applog(LOG_ERR, "Error %d: Releasing program. (clReleaseProgram)", status);
|
|
|
- return NULL;
|
|
|
+ if (!(opencl_patch_kernel_binary(&binary_bytes)) && opencl_replace_binary_kernel(cgpu, clState, kernelinfo, &binary_bytes))
|
|
|
+ {
|
|
|
+ applog(LOG_DEBUG, "%s: BFI_INT patching failed, rebuilding without it", cgpu->dev_repr);
|
|
|
+ patchbfi = false;
|
|
|
+ bytes_free(&binary_bytes);
|
|
|
+ goto build;
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- clState->program = clCreateProgramWithBinary(clState->context, 1, &devices[gpu], &binary_sizes[slot], (const unsigned char **)&binaries[slot], &status, NULL);
|
|
|
- if (status != CL_SUCCESS) {
|
|
|
- applog(LOG_ERR, "Error %d: Loading Binary into cl_program (clCreateProgramWithBinary)", status);
|
|
|
- return NULL;
|
|
|
+#endif
|
|
|
+
|
|
|
+ if (data->opt_opencl_binaries & OBU_SAVE)
|
|
|
+ {
|
|
|
+ if (!opencl_save_kernel_binary(binaryfilename, &binary_bytes))
|
|
|
+ applog(LOG_DEBUG, "Unable to save file %s", binaryfilename);
|
|
|
}
|
|
|
-
|
|
|
- /* Program needs to be rebuilt */
|
|
|
- prog_built = false;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
free(source);
|
|
|
-
|
|
|
- /* Save the binary to be loaded next time */
|
|
|
- binaryfile = fopen(binaryfilename, "wb");
|
|
|
- if (!binaryfile) {
|
|
|
- /* Not a fatal problem, just means we build it again next time */
|
|
|
- applog(LOG_DEBUG, "Unable to create file %s", binaryfilename);
|
|
|
- } else {
|
|
|
- if (unlikely(fwrite(binaries[slot], 1, binary_sizes[slot], binaryfile) != binary_sizes[slot])) {
|
|
|
- applog(LOG_ERR, "Unable to fwrite to binaryfile");
|
|
|
- return NULL;
|
|
|
- }
|
|
|
- fclose(binaryfile);
|
|
|
- }
|
|
|
-built:
|
|
|
- if (binaries[slot])
|
|
|
- free(binaries[slot]);
|
|
|
- free(binaries);
|
|
|
- free(binary_sizes);
|
|
|
-
|
|
|
+ bytes_free(&binary_bytes);
|
|
|
+
|
|
|
applog(LOG_INFO, "Initialising kernel %s with%s bitalign, %"PRId64" vectors and worksize %"PRIu64,
|
|
|
- filename, clState->hasBitAlign ? "" : "out", (int64_t)clState->vwidth, (uint64_t)clState->wsize);
|
|
|
-
|
|
|
- if (!prog_built) {
|
|
|
- /* create a cl program executable for all the devices specified */
|
|
|
- status = bfg_clBuildProgram(clState, devices[gpu], NULL);
|
|
|
- if (status != CL_SUCCESS)
|
|
|
- return NULL;
|
|
|
- }
|
|
|
+ filename, clState->hasBitAlign ? "" : "out", (int64_t)clState->vwidth, (uint64_t)kernelinfo->wsize);
|
|
|
|
|
|
/* get a kernel object handle for a kernel with the given name */
|
|
|
- clState->kernel = clCreateKernel(clState->program, "search", &status);
|
|
|
+ kernelinfo->kernel = clCreateKernel(kernelinfo->program, "search", &status);
|
|
|
if (status != CL_SUCCESS) {
|
|
|
applog(LOG_ERR, "Error %d: Creating Kernel from program. (clCreateKernel)", status);
|
|
|
- return NULL;
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
free((void*)cgpu->kname);
|
|
|
- cgpu->kname = strdup(data->kernel_file);
|
|
|
+ cgpu->kname = strdup(kernel_file);
|
|
|
|
|
|
+#ifdef MAX_CLBUFFER0_SZ
|
|
|
+ switch (kernelinfo->interface)
|
|
|
+ {
|
|
|
#ifdef USE_SCRYPT
|
|
|
- if (opt_scrypt) {
|
|
|
- size_t ipt = (1024 / data->lookup_gap + (1024 % data->lookup_gap > 0));
|
|
|
- size_t bufsize = 128 * ipt * data->thread_concurrency;
|
|
|
-
|
|
|
- /* Use the max alloc value which has been rounded to a power of
|
|
|
- * 2 greater >= required amount earlier */
|
|
|
- if (bufsize > data->max_alloc) {
|
|
|
- applog(LOG_WARNING, "Maximum buffer memory device %d supports says %lu", gpu, (unsigned long)data->max_alloc);
|
|
|
- applog(LOG_WARNING, "Your scrypt settings come to %lu", (unsigned long)bufsize);
|
|
|
- }
|
|
|
- applog(LOG_DEBUG, "Creating scrypt buffer sized %lu", (unsigned long)bufsize);
|
|
|
- clState->padbufsize = bufsize;
|
|
|
-
|
|
|
- /* This buffer is weird and might work to some degree even if
|
|
|
- * the create buffer call has apparently failed, so check if we
|
|
|
- * get anything back before we call it a failure. */
|
|
|
- clState->padbuffer8 = NULL;
|
|
|
- clState->padbuffer8 = clCreateBuffer(clState->context, CL_MEM_READ_WRITE, bufsize, NULL, &status);
|
|
|
- if (status != CL_SUCCESS && !clState->padbuffer8) {
|
|
|
- applog(LOG_ERR, "Error %d: clCreateBuffer (padbuffer8), decrease TC or increase LG", status);
|
|
|
- return NULL;
|
|
|
- }
|
|
|
-
|
|
|
- clState->CLbuffer0 = clCreateBuffer(clState->context, CL_MEM_READ_ONLY, 128, NULL, &status);
|
|
|
- if (status != CL_SUCCESS) {
|
|
|
- applog(LOG_ERR, "Error %d: clCreateBuffer (CLbuffer0)", status);
|
|
|
- return NULL;
|
|
|
- }
|
|
|
- clState->outputBuffer = clCreateBuffer(clState->context, CL_MEM_WRITE_ONLY, SCRYPT_BUFFERSIZE, NULL, &status);
|
|
|
- } else
|
|
|
+ case KL_SCRYPT:
|
|
|
+ if (!clState->padbufsize)
|
|
|
+ {
|
|
|
+ size_t ipt = (1024 / data->lookup_gap + (1024 % data->lookup_gap > 0));
|
|
|
+ size_t bufsize = 128 * ipt * data->thread_concurrency;
|
|
|
+
|
|
|
+ /* Use the max alloc value which has been rounded to a power of
|
|
|
+ * 2 greater >= required amount earlier */
|
|
|
+ if (bufsize > data->max_alloc) {
|
|
|
+ applog(LOG_WARNING, "Maximum buffer memory device %d supports says %lu", gpu, (unsigned long)data->max_alloc);
|
|
|
+ applog(LOG_WARNING, "Your scrypt settings come to %lu", (unsigned long)bufsize);
|
|
|
+ }
|
|
|
+ applog(LOG_DEBUG, "Creating scrypt buffer sized %lu", (unsigned long)bufsize);
|
|
|
+ clState->padbufsize = bufsize;
|
|
|
+
|
|
|
+ /* This buffer is weird and might work to some degree even if
|
|
|
+ * the create buffer call has apparently failed, so check if we
|
|
|
+ * get anything back before we call it a failure. */
|
|
|
+ clState->padbuffer8 = NULL;
|
|
|
+ clState->padbuffer8 = clCreateBuffer(clState->context, CL_MEM_READ_WRITE, bufsize, NULL, &status);
|
|
|
+ if (status != CL_SUCCESS && !clState->padbuffer8) {
|
|
|
+ applog(LOG_ERR, "Error %d: clCreateBuffer (padbuffer8), decrease TC or increase LG", status);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // NOTE: fallthru
|
|
|
#endif
|
|
|
- clState->outputBuffer = clCreateBuffer(clState->context, CL_MEM_WRITE_ONLY, BUFFERSIZE, NULL, &status);
|
|
|
- if (status != CL_SUCCESS) {
|
|
|
- applog(LOG_ERR, "Error %d: clCreateBuffer (outputBuffer)", status);
|
|
|
- return NULL;
|
|
|
+#ifdef USE_OPENCL_FULLHEADER
|
|
|
+ case KL_FULLHEADER:
|
|
|
+#endif
|
|
|
+ if (!clState->CLbuffer0)
|
|
|
+ {
|
|
|
+ clState->CLbuffer0 = clCreateBuffer(clState->context, CL_MEM_READ_ONLY, MAX_CLBUFFER0_SZ, NULL, &status);
|
|
|
+ if (status != CL_SUCCESS) {
|
|
|
+ applog(LOG_ERR, "Error %d: clCreateBuffer (CLbuffer0)", status);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
- return clState;
|
|
|
+ kernelinfo->loaded = true;
|
|
|
+ return true;
|
|
|
}
|
|
|
-#endif /* HAVE_OPENCL */
|
|
|
-
|