Browse Source

Merge branch 'mesa' into bfgminer

Luke Dashjr 13 years ago
parent
commit
30b1ff7c24
3 changed files with 31 additions and 1 deletions
  1. 3 0
      driver-opencl.c
  2. 1 1
      miner.c
  3. 27 0
      ocl.c

+ 3 - 0
driver-opencl.c

@@ -1433,6 +1433,9 @@ static void opencl_detect()
 	if (!nDevs)
 	if (!nDevs)
 		return;
 		return;
 
 
+	if (opt_g_threads == -1)
+		opt_g_threads = 2;
+
 	for (i = 0; i < nDevs; ++i) {
 	for (i = 0; i < nDevs; ++i) {
 		struct cgpu_info *cgpu;
 		struct cgpu_info *cgpu;
 
 

+ 1 - 1
miner.c

@@ -138,7 +138,7 @@ unsigned long long global_hashrate;
 #ifdef HAVE_OPENCL
 #ifdef HAVE_OPENCL
 int opt_dynamic_interval = 7;
 int opt_dynamic_interval = 7;
 int nDevs;
 int nDevs;
-int opt_g_threads = 2;
+int opt_g_threads = -1;
 int gpu_threads;
 int gpu_threads;
 #endif
 #endif
 #ifdef USE_SCRYPT
 #ifdef USE_SCRYPT

+ 27 - 0
ocl.c

@@ -251,6 +251,8 @@ char *file_contents(const char *filename, int *length)
 	return (char*)buffer;
 	return (char*)buffer;
 }
 }
 
 
+extern int opt_g_threads;
+
 int clDevicesNum(void) {
 int clDevicesNum(void) {
 	cl_int status;
 	cl_int status;
 	char pbuff[256];
 	char pbuff[256];
@@ -259,6 +261,7 @@ int clDevicesNum(void) {
 	cl_platform_id *platforms;
 	cl_platform_id *platforms;
 	cl_platform_id platform = NULL;
 	cl_platform_id platform = NULL;
 	unsigned int most_devices = 0, i, mdplatform = 0;
 	unsigned int most_devices = 0, i, mdplatform = 0;
+	bool mdmesa = false;
 
 
 	status = clGetPlatformIDs(0, NULL, &numPlatforms);
 	status = clGetPlatformIDs(0, NULL, &numPlatforms);
 	/* If this fails, assume no GPUs. */
 	/* If this fails, assume no GPUs. */
@@ -307,6 +310,7 @@ int clDevicesNum(void) {
 		if (numDevices > most_devices) {
 		if (numDevices > most_devices) {
 			most_devices = numDevices;
 			most_devices = numDevices;
 			mdplatform = i;
 			mdplatform = i;
+			mdmesa = strstr(pbuff, "MESA");
 		}
 		}
 		if (numDevices) {
 		if (numDevices) {
 			unsigned int j;
 			unsigned int j;
@@ -324,6 +328,8 @@ int clDevicesNum(void) {
 
 
 	if (opt_platform_id < 0)
 	if (opt_platform_id < 0)
 		opt_platform_id = mdplatform;;
 		opt_platform_id = mdplatform;;
+	if (mdmesa && opt_g_threads == -1)
+		opt_g_threads = 1;
 
 
 	return most_devices;
 	return most_devices;
 }
 }
@@ -389,6 +395,7 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
 {
 {
 	_clState *clState = calloc(1, sizeof(_clState));
 	_clState *clState = calloc(1, sizeof(_clState));
 	bool patchbfi = false, prog_built = false;
 	bool patchbfi = false, prog_built = false;
+	bool usebinary = true, ismesa = false;
 	struct cgpu_info *cgpu = &gpus[gpu];
 	struct cgpu_info *cgpu = &gpus[gpu];
 	cl_platform_id platform = NULL;
 	cl_platform_id platform = NULL;
 	char pbuff[256], vbuff[255];
 	char pbuff[256], vbuff[255];
@@ -551,6 +558,14 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
 		return NULL;
 		return NULL;
 	}
 	}
 	applog(LOG_DEBUG, "Max mem alloc size is %lu", (unsigned long)cgpu->max_alloc);
 	applog(LOG_DEBUG, "Max mem alloc size is %lu", (unsigned long)cgpu->max_alloc);
+	
+	if (strstr(vbuff, "MESA"))
+	{
+		applog(LOG_DEBUG, "Mesa OpenCL platform detected, disabling OpenCL kernel binaries and bitalign");
+		clState->hasBitAlign = false;
+		usebinary = false;
+		ismesa = true;
+	}
 
 
 	/* Create binary filename based on parameters passed to opencl
 	/* Create binary filename based on parameters passed to opencl
 	 * compiler to ensure we only load a binary that matches what would
 	 * compiler to ensure we only load a binary that matches what would
@@ -567,6 +582,11 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
 		if (opt_scrypt) {
 		if (opt_scrypt) {
 			applog(LOG_INFO, "Selecting scrypt kernel");
 			applog(LOG_INFO, "Selecting scrypt kernel");
 			clState->chosen_kernel = KL_SCRYPT;
 			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") &&
 		} else if (!strstr(name, "Tahiti") &&
 			/* Detect all 2.6 SDKs not with Tahiti and use diablo kernel */
 			/* 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, "844.4") ||  // Linux 64 bit ATI 2.6 SDK
@@ -735,7 +755,11 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
 	strcat(binaryfilename, "p");
 	strcat(binaryfilename, "p");
 	strcat(binaryfilename, vbuff);
 	strcat(binaryfilename, vbuff);
 	sanestr(binaryfilename, binaryfilename);
 	sanestr(binaryfilename, binaryfilename);
+	applog(LOG_DEBUG, "OCL%2u: Configured OpenCL kernel name: %s", gpu, binaryfilename);
 	strcat(binaryfilename, ".bin");
 	strcat(binaryfilename, ".bin");
+	
+	if (!usebinary)
+		goto build;
 
 
 	binaryfile = fopen(binaryfilename, "rb");
 	binaryfile = fopen(binaryfilename, "rb");
 	if (!binaryfile) {
 	if (!binaryfile) {
@@ -856,6 +880,9 @@ build:
 	}
 	}
 
 
 	prog_built = true;
 	prog_built = true;
+	
+	if (!usebinary)
+		goto built;
 
 
 	status = clGetProgramInfo(clState->program, CL_PROGRAM_NUM_DEVICES, sizeof(cl_uint), &cpnd, NULL);
 	status = clGetProgramInfo(clState->program, CL_PROGRAM_NUM_DEVICES, sizeof(cl_uint), &cpnd, NULL);
 	if (unlikely(status != CL_SUCCESS)) {
 	if (unlikely(status != CL_SUCCESS)) {