mirror of
https://github.com/GOSTSec/sgminer
synced 2025-01-09 06:18:06 +00:00
Remove fragile source patching for bitalign, vectors et. al and simply pass it with the compiler options.
This commit is contained in:
parent
e81a362b5f
commit
3567b69e5e
82
ocl.c
82
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,54 +450,6 @@ _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");
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/* Patch the source file defining BITALIGN */
|
||||
if (clState->hasBitAlign) {
|
||||
char *find = strstr(source, "BITALIGNX");
|
||||
|
||||
if (unlikely(!find)) {
|
||||
applog(LOG_ERR, "Unable to find BITALIGNX in source");
|
||||
return NULL;
|
||||
}
|
||||
find += 8; // "BITALIGN"
|
||||
strncpy(find, " ", 1);
|
||||
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);
|
||||
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)");
|
||||
@ -518,7 +464,28 @@ build:
|
||||
|
||||
/* create a cl program executable for all the devices specified */
|
||||
char CompilerOptions[256];
|
||||
sprintf(CompilerOptions, "%s%i", "-DWORKSIZE=", (int)clState->work_size);
|
||||
|
||||
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) {
|
||||
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");
|
||||
|
||||
//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");
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user