Browse Source

Remove fragile source patching for bitalign, vectors et. al and simply pass it with the compiler options.

nfactor-troky
Con Kolivas 13 years ago
parent
commit
3567b69e5e
  1. 80
      ocl.c
  2. 4
      phatk110817.cl
  3. 6
      poclbm110817.cl

80
ocl.c

@ -372,18 +372,12 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize) @@ -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) @@ -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: @@ -610,7 +577,6 @@ build:
}
free(source);
free(rawsource);
/* Save the binary to be loaded next time */
binaryfile = fopen(binaryfilename, "wb");

4
phatk110817.cl

@ -2,10 +2,6 @@ @@ -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

6
poclbm110817.cl

@ -5,9 +5,6 @@ @@ -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] = { @@ -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

Loading…
Cancel
Save