Browse Source

Only try to patch GPU referenced.

nfactor-troky
Con Kolivas 14 years ago
parent
commit
401586f92a
  1. 63
      ocl.c

63
ocl.c

@ -379,44 +379,35 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
/* copy over all of the generated binaries. */ /* copy over all of the generated binaries. */
binaries = (char **)malloc( sizeof(char *)*nDevices ); binaries = (char **)malloc( sizeof(char *)*nDevices );
for( i = 0; i < nDevices; i++ ) { if (opt_debug)
if (opt_debug) applog(LOG_DEBUG, "binary size %d : %d", gpu, binary_sizes[gpu]);
applog(LOG_DEBUG, "binary size %d : %d", i, binary_sizes[i]); binaries[gpu] = (char *)malloc( sizeof(char)*binary_sizes[i] );
if( binary_sizes[i] != 0 )
binaries[i] = (char *)malloc( sizeof(char)*binary_sizes[i] );
else
binaries[i] = NULL;
}
err = clGetProgramInfo( clState->program, CL_PROGRAM_BINARIES, sizeof(char *)*nDevices, binaries, NULL ); err = clGetProgramInfo( clState->program, CL_PROGRAM_BINARIES, sizeof(char *)*nDevices, binaries, NULL );
for (i = 0; i < nDevices; i++) { unsigned remaining = binary_sizes[gpu];
if (!binaries[i]) char *w = binaries[gpu];
continue; unsigned int start, length;
unsigned remaining = binary_sizes[i]; /* Find 2nd incidence of .text, and copy the program's
char *w = binaries[i]; * position and length at a fixed offset from that. Then go
unsigned int start, length; * back and find the 2nd incidence of \x7ELF (rewind by one
* from ELF) and then patch the opcocdes */
/* Find 2nd incidence of .text, and copy the program's advance(&w, &remaining, ".text");
* position and length at a fixed offset from that. Then go w++; remaining--;
* back and find the 2nd incidence of \x7ELF (rewind by one advance(&w, &remaining, ".text");
* from ELF) and then patch the opcocdes */ memcpy(&start, w + 285, 4);
advance(&w, &remaining, ".text"); memcpy(&length, w + 289, 4);
w++; remaining--; w = binaries[gpu]; remaining = binary_sizes[gpu];
advance(&w, &remaining, ".text"); advance(&w, &remaining, "ELF");
memcpy(&start, w + 285, 4); w++; remaining--;
memcpy(&length, w + 289, 4); advance(&w, &remaining, "ELF");
w = binaries[i]; remaining = binary_sizes[i]; w--; remaining++;
advance(&w, &remaining, "ELF"); w += start; remaining -= start;
w++; remaining--; if (opt_debug)
advance(&w, &remaining, "ELF"); applog(LOG_DEBUG, "At %p (%u rem. bytes), to begin patching",
w--; remaining++; w, remaining);
w += start; remaining -= start; patch_opcodes(w, length);
if (opt_debug)
applog(LOG_DEBUG, "At %p (%u rem. bytes), to begin patching",
w, remaining);
patch_opcodes(w, length);
}
status = clReleaseProgram(clState->program); status = clReleaseProgram(clState->program);
if(status != CL_SUCCESS) if(status != CL_SUCCESS)
{ {

Loading…
Cancel
Save