Browse Source

Merge https://github.com/ycros/cgminer into cgminer

nfactor-troky
Con Kolivas 14 years ago
parent
commit
660aabf7f7
  1. 24
      ocl.c

24
ocl.c

@ -15,7 +15,7 @@
#else #else
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <netdb.h> #include <netdb.h>
#endif #endif
#include <time.h> #include <time.h>
@ -32,7 +32,7 @@ extern int opt_worksize;
char *file_contents(const char *filename, int *length) char *file_contents(const char *filename, int *length)
{ {
FILE *f = fopen(filename, "r"); FILE *f = fopen(filename, "rb");
void *buffer; void *buffer;
if (!f) { if (!f) {
@ -89,7 +89,7 @@ int clDevicesNum() {
if (!strcmp(pbuff, "Advanced Micro Devices, Inc.")) if (!strcmp(pbuff, "Advanced Micro Devices, Inc."))
{ {
break; break;
} }
} }
free(platforms); free(platforms);
} }
@ -385,7 +385,7 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
strcat(binaryfilename, numbuf); strcat(binaryfilename, numbuf);
strcat(binaryfilename, ".bin"); strcat(binaryfilename, ".bin");
binaryfile = fopen(binaryfilename, "r"); binaryfile = fopen(binaryfilename, "rb");
if (!binaryfile) { if (!binaryfile) {
if (opt_debug) if (opt_debug)
applog(LOG_DEBUG, "No binary found, generating from source"); applog(LOG_DEBUG, "No binary found, generating from source");
@ -421,7 +421,7 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
} }
if (opt_debug) if (opt_debug)
applog(LOG_DEBUG, "Loaded binary image %s", binaryfilename); applog(LOG_DEBUG, "Loaded binary image %s", binaryfilename);
free(binaries[gpu]); free(binaries[gpu]);
goto built; goto built;
} }
@ -480,7 +480,7 @@ build:
applog(LOG_DEBUG, "cl_amd_media_ops not found, will not BFI_INT patch"); applog(LOG_DEBUG, "cl_amd_media_ops not found, will not BFI_INT patch");
clState->program = clCreateProgramWithSource(clState->context, 1, (const char **)&source, sourceSize, &status); clState->program = clCreateProgramWithSource(clState->context, 1, (const char **)&source, sourceSize, &status);
if (status != CL_SUCCESS) if (status != CL_SUCCESS)
{ {
applog(LOG_ERR, "Error: Loading Binary into cl_program (clCreateProgramWithSource)"); applog(LOG_ERR, "Error: Loading Binary into cl_program (clCreateProgramWithSource)");
return NULL; return NULL;
@ -488,7 +488,7 @@ build:
/* create a cl program executable for all the devices specified */ /* create a cl program executable for all the devices specified */
status = clBuildProgram(clState->program, 1, &devices[gpu], NULL, NULL, NULL); status = clBuildProgram(clState->program, 1, &devices[gpu], NULL, NULL, NULL);
if (status != CL_SUCCESS) if (status != CL_SUCCESS)
{ {
applog(LOG_ERR, "Error: Building Program (clBuildProgram)"); applog(LOG_ERR, "Error: Building Program (clBuildProgram)");
size_t logSize; size_t logSize;
@ -497,7 +497,7 @@ build:
char *log = malloc(logSize); char *log = malloc(logSize);
status = clGetProgramBuildInfo(clState->program, devices[gpu], CL_PROGRAM_BUILD_LOG, logSize, log, NULL); status = clGetProgramBuildInfo(clState->program, devices[gpu], CL_PROGRAM_BUILD_LOG, logSize, log, NULL);
applog(LOG_INFO, "%s", log); applog(LOG_INFO, "%s", log);
return NULL; return NULL;
} }
status = clGetProgramInfo( clState->program, CL_PROGRAM_BINARY_SIZES, sizeof(size_t)*nDevices, binary_sizes, NULL ); status = clGetProgramInfo( clState->program, CL_PROGRAM_BINARY_SIZES, sizeof(size_t)*nDevices, binary_sizes, NULL );
@ -560,7 +560,7 @@ build:
} }
clState->program = clCreateProgramWithBinary(clState->context, 1, &devices[gpu], &binary_sizes[gpu], (const unsigned char **)&binaries[gpu], &status, NULL); clState->program = clCreateProgramWithBinary(clState->context, 1, &devices[gpu], &binary_sizes[gpu], (const unsigned char **)&binaries[gpu], &status, NULL);
if (status != CL_SUCCESS) if (status != CL_SUCCESS)
{ {
applog(LOG_ERR, "Error: Loading Binary into cl_program (clCreateProgramWithBinary)"); applog(LOG_ERR, "Error: Loading Binary into cl_program (clCreateProgramWithBinary)");
return NULL; return NULL;
@ -571,7 +571,7 @@ build:
free(rawsource); free(rawsource);
/* Save the binary to be loaded next time */ /* Save the binary to be loaded next time */
binaryfile = fopen(binaryfilename, "w"); binaryfile = fopen(binaryfilename, "wb");
if (!binaryfile) { if (!binaryfile) {
/* Not a fatal problem, just means we build it again next time */ /* Not a fatal problem, just means we build it again next time */
if (opt_debug) if (opt_debug)
@ -594,7 +594,7 @@ built:
/* create a cl program executable for all the devices specified */ /* create a cl program executable for all the devices specified */
status = clBuildProgram(clState->program, 1, &devices[gpu], NULL, NULL, NULL); status = clBuildProgram(clState->program, 1, &devices[gpu], NULL, NULL, NULL);
if (status != CL_SUCCESS) if (status != CL_SUCCESS)
{ {
applog(LOG_ERR, "Error: Building Program (clBuildProgram)"); applog(LOG_ERR, "Error: Building Program (clBuildProgram)");
size_t logSize; size_t logSize;
@ -603,7 +603,7 @@ built:
char *log = malloc(logSize); char *log = malloc(logSize);
status = clGetProgramBuildInfo(clState->program, devices[gpu], CL_PROGRAM_BUILD_LOG, logSize, log, NULL); status = clGetProgramBuildInfo(clState->program, devices[gpu], CL_PROGRAM_BUILD_LOG, logSize, log, NULL);
applog(LOG_INFO, "%s", log); applog(LOG_INFO, "%s", log);
return NULL; return NULL;
} }
/* get a kernel object handle for a kernel with the given name */ /* get a kernel object handle for a kernel with the given name */

Loading…
Cancel
Save