From 3567b69e5eaae571948205be00a3996c4b86b6a0 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 26 Aug 2011 10:20:02 +1000 Subject: [PATCH] Remove fragile source patching for bitalign, vectors et. al and simply pass it with the compiler options. --- ocl.c | 80 ++++++++++++++----------------------------------- phatk110817.cl | 4 --- poclbm110817.cl | 6 ---- 3 files changed, 23 insertions(+), 67 deletions(-) diff --git a/ocl.c b/ocl.c index 6ababb64..60375a26 100644 --- a/ocl.c +++ b/ocl.c @@ -372,18 +372,12 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize) size_t *binary_sizes; char **binaries; int pl; - char *source, *rawsource = file_contents(filename, &pl); + char *source = file_contents(filename, &pl); size_t sourceSize[] = {(size_t)pl}; - if (!rawsource) + if (!source) return NULL; - source = malloc(pl); - if (!source) { - applog(LOG_ERR, "Unable to malloc source"); - return NULL; - } - binary_sizes = (size_t *)malloc(sizeof(size_t)*nDevices); if (unlikely(!binary_sizes)) { applog(LOG_ERR, "Unable to malloc binary_sizes"); @@ -456,69 +450,42 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize) ///////////////////////////////////////////////////////////////// build: - memcpy(source, rawsource, pl); - - /* Patch the source file with the preferred_vwidth */ - if (clState->preferred_vwidth > 1) { - char *find = strstr(source, "VECTORSX"); + clState->program = clCreateProgramWithSource(clState->context, 1, (const char **)&source, sourceSize, &status); + if (status != CL_SUCCESS) { + applog(LOG_ERR, "Error: Loading Binary into cl_program (clCreateProgramWithSource)"); + return NULL; + } - if (unlikely(!find)) { - applog(LOG_ERR, "Unable to find VECTORSX in source"); - return NULL; - } - find += 7; // "VECTORS" - if (clState->preferred_vwidth == 2) - strncpy(find, "2", 1); - else - strncpy(find, "4", 1); - if (opt_debug) - applog(LOG_DEBUG, "Patched source to suit %d vectors", clState->preferred_vwidth); + clRetainProgram(clState->program); + if (status != CL_SUCCESS) { + applog(LOG_ERR, "Error: Retaining Program (clRetainProgram)"); + return NULL; } - /* Patch the source file defining BITALIGN */ - if (clState->hasBitAlign) { - char *find = strstr(source, "BITALIGNX"); + /* create a cl program executable for all the devices specified */ + char CompilerOptions[256]; - if (unlikely(!find)) { - applog(LOG_ERR, "Unable to find BITALIGNX in source"); - return NULL; - } - find += 8; // "BITALIGN" - strncpy(find, " ", 1); + sprintf(CompilerOptions, "-DWORKSIZE=%d -DVECTORS%d", + (int)clState->work_size, clState->preferred_vwidth); + if (opt_debug) + applog(LOG_DEBUG, "Setting worksize to %d", clState->work_size); + if (clState->preferred_vwidth > 1 && opt_debug) + applog(LOG_DEBUG, "Patched source to suit %d vectors", clState->preferred_vwidth); + + if (clState->hasBitAlign) { + strcat(CompilerOptions, " -DBITALIGN"); if (opt_debug) applog(LOG_DEBUG, "cl_amd_media_ops found, patched source with BITALIGN"); } else if (opt_debug) applog(LOG_DEBUG, "cl_amd_media_ops not found, will not BITALIGN patch"); if (patchbfi) { - char *find = strstr(source, "BFI_INTX"); - - if (unlikely(!find)) { - applog(LOG_ERR, "Unable to find BFI_INTX in source"); - return NULL; - } - find += 7; // "BFI_INT" - strncpy(find, " ", 1); + strcat(CompilerOptions, " -DBFI_INT"); if (opt_debug) applog(LOG_DEBUG, "cl_amd_media_ops found, patched source with BFI_INT"); } else if (opt_debug) 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); - if (status != CL_SUCCESS) { - applog(LOG_ERR, "Error: Loading Binary into cl_program (clCreateProgramWithSource)"); - return NULL; - } - - clRetainProgram(clState->program); - if (status != CL_SUCCESS) { - applog(LOG_ERR, "Error: Retaining Program (clRetainProgram)"); - return NULL; - } - - /* create a cl program executable for all the devices specified */ - char CompilerOptions[256]; - sprintf(CompilerOptions, "%s%i", "-DWORKSIZE=", (int)clState->work_size); //int n = 1000; //while(n--) // printf("%s", CompilerOptions); @@ -610,7 +577,6 @@ build: } free(source); - free(rawsource); /* Save the binary to be loaded next time */ binaryfile = fopen(binaryfilename, "wb"); diff --git a/phatk110817.cl b/phatk110817.cl index 1bc30b01..20da40ae 100644 --- a/phatk110817.cl +++ b/phatk110817.cl @@ -2,10 +2,6 @@ // I have therefore decided to keep it public-domain. -#define VECTORSX -#define BFI_INTX -#define BITALIGNX - #ifdef VECTORS4 typedef uint4 u; #else diff --git a/poclbm110817.cl b/poclbm110817.cl index 693be63b..0db94584 100644 --- a/poclbm110817.cl +++ b/poclbm110817.cl @@ -5,9 +5,6 @@ // This file is taken and modified from the public-domain poclbm project, and // we have therefore decided to keep it public-domain in Phoenix. -// The X is a placeholder for patching to suit hardware -#define VECTORSX - #ifdef VECTORS4 typedef uint4 u; #elif defined VECTORS2 @@ -36,9 +33,6 @@ __constant uint K[64] = { // detected, use it for ch. Otherwise, construct ch out of simpler logical // primitives. -#define BFI_INTX -#define BITALIGNX - #ifdef BFI_INT // Well, slight problem... It turns out BFI_INT isn't actually exposed to // OpenCL (or CAL IL for that matter) in any way. However, there is