Skip to content

Commit

Permalink
Removed bitalign/opcode patching code. It's dead, and no one else is …
Browse files Browse the repository at this point in the history
…gonna do it.
  • Loading branch information
Wolf committed Apr 7, 2015
1 parent c536243 commit 55da7b5
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 190 deletions.
1 change: 0 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ sgminer_SOURCES += pool.c pool.h
sgminer_SOURCES += algorithm.c algorithm.h
sgminer_SOURCES += config_parser.c config_parser.h
sgminer_SOURCES += events.c events.h
sgminer_SOURCES += ocl/patch_kernel.c ocl/patch_kernel.h
sgminer_SOURCES += ocl/build_kernel.c ocl/build_kernel.h
sgminer_SOURCES += ocl/binary_kernel.c ocl/binary_kernel.h

Expand Down
38 changes: 4 additions & 34 deletions ocl.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,21 +168,6 @@ static float get_opencl_version(cl_device_id device)
return version;
}

static bool get_opencl_bit_align_support(cl_device_id *device)
{
char extensions[1024];
const char * camo = "cl_amd_media_ops";
char *find;
cl_int status;

status = clGetDeviceInfo(*device, CL_DEVICE_EXTENSIONS, 1024, (void *)extensions, NULL);
if (status != CL_SUCCESS) {
return false;
}
find = strstr(extensions, camo);
return !!find;
}

static cl_int create_opencl_command_queue(cl_command_queue *command_queue, cl_context *context, cl_device_id *device, cl_command_queue_properties cq_properties)
{
cl_int status;
Expand Down Expand Up @@ -262,8 +247,6 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize, algorithm_t *alg
return NULL;
}

clState->hasBitAlign = get_opencl_bit_align_support(&devices[gpu]);

status = clGetDeviceInfo(devices[gpu], CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, sizeof(cl_uint), (void *)&preferred_vwidth, NULL);
if (status != CL_SUCCESS) {
applog(LOG_ERR, "Error %d: Failed to clGetDeviceInfo when trying to get CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT", status);
Expand Down Expand Up @@ -544,9 +527,7 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize, algorithm_t *alg

build_data->kernel_path = (*opt_kernel_path) ? opt_kernel_path : NULL;
build_data->work_size = clState->wsize;
build_data->has_bit_align = clState->hasBitAlign;
build_data->opencl_version = get_opencl_version(devices[gpu]);
build_data->patch_bfi = needs_bfi_patch(build_data);

strcpy(build_data->binary_filename, filename);
build_data->binary_filename[strlen(filename) - 3] = 0x00; // And one NULL terminator, cutting off the .cl suffix.
Expand All @@ -572,23 +553,13 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize, algorithm_t *alg
return NULL;
}

if (save_opencl_kernel(build_data, clState->program)) {
/* Program needs to be rebuilt, because the binary was patched */
if (build_data->patch_bfi) {
clReleaseProgram(clState->program);
clState->program = load_opencl_binary_kernel(build_data);
}
}
else {
if (build_data->patch_bfi)
quit(1, "Could not save kernel to file, but it is necessary to apply BFI patch");
}
// If it doesn't work, oh well, build it again next run
save_opencl_kernel(build_data, clState->program);
}

// Load kernels
applog(LOG_NOTICE, "Initialising kernel %s with%s bitalign, %spatched BFI, nfactor %d, n %d",
filename, clState->hasBitAlign ? "" : "out", build_data->patch_bfi ? "" : "un",
algorithm->nfactor, algorithm->n);
applog(LOG_NOTICE, "Initialising kernel %s with nfactor %d, n %d",
filename, algorithm->nfactor, algorithm->n);

/* get a kernel object handle for a kernel with the given name */
clState->kernel = clCreateKernel(clState->program, "search", &status);
Expand All @@ -597,7 +568,6 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize, algorithm_t *alg
return NULL;
}


clState->n_extra_kernels = algorithm->n_extra_kernels;
if (clState->n_extra_kernels > 0) {
unsigned int i;
Expand Down
1 change: 0 additions & 1 deletion ocl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ typedef struct __clState {
cl_mem MidstateBuf;
cl_mem padbuffer8;
unsigned char cldata[80];
bool hasBitAlign;
bool goffset;
cl_uint vwidth;
size_t max_work_size;
Expand Down
46 changes: 2 additions & 44 deletions ocl/build_kernel.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <stdio.h>
#include "build_kernel.h"
#include "patch_kernel.h"
#include "miner.h"

static char *file_contents(const char *filename, int *length)
Expand Down Expand Up @@ -52,6 +51,7 @@ static char *file_contents(const char *filename, int *length)
return (char*)buffer;
}

// This should NOT be in here! -- Wolf9466
void set_base_compiler_options(build_kernel_data *data)
{
char buf[255];
Expand All @@ -61,51 +61,17 @@ void set_base_compiler_options(build_kernel_data *data)

sprintf(buf, "w%dl%d", (int)data->work_size, (int)sizeof(long));
strcat(data->binary_filename, buf);

if (data->has_bit_align) {
strcat(data->compiler_options, " -D BITALIGN");
applog(LOG_DEBUG, "cl_amd_media_ops found, setting BITALIGN");
} else
applog(LOG_DEBUG, "cl_amd_media_ops not found, will not set BITALIGN");

if (data->kernel_path) {
strcat(data->compiler_options, " -I \"");
strcat(data->compiler_options, data->kernel_path);
strcat(data->compiler_options, "\"");
}

if (data->patch_bfi) {
strcat(data->compiler_options, " -D BFI_INT");
applog(LOG_DEBUG, "BFI_INT patch requiring device found, patched source with BFI_INT");
} else
applog(LOG_DEBUG, "BFI_INT patch requiring device not found, will not BFI_INT patch");

if (data->opencl_version < 1.1)
strcat(data->compiler_options, " -D OCL1");
}

bool needs_bfi_patch(build_kernel_data *data)
{
if (data->has_bit_align &&
(data->opencl_version < 1.2) &&
(strstr(data->platform, "Cedar") ||
strstr(data->platform, "Redwood") ||
strstr(data->platform, "Juniper") ||
strstr(data->platform, "Cypress" ) ||
strstr(data->platform, "Hemlock" ) ||
strstr(data->platform, "Caicos" ) ||
strstr(data->platform, "Turks" ) ||
strstr(data->platform, "Barts" ) ||
strstr(data->platform, "Cayman" ) ||
strstr(data->platform, "Antilles" ) ||
strstr(data->platform, "Wrestler" ) ||
strstr(data->platform, "Zacate" ) ||
strstr(data->platform, "WinterPark" )))
return true;
else
return false;
}

cl_program build_opencl_kernel(build_kernel_data *data, const char *filename)
{
int pl;
Expand Down Expand Up @@ -198,18 +164,10 @@ bool save_opencl_kernel(build_kernel_data *data, cl_program program)
goto out;
}

/* Patch the kernel if the hardware supports BFI_INT but it needs to
* be hacked in */
if (data->patch_bfi) {
if (kernel_bfi_patch(binaries[slot], binary_sizes[slot]) != 0) {
quit(1, "Could not patch BFI_INT, please report this issue.");
}
}

/* Save the binary to be loaded next time */
binaryfile = fopen(data->binary_filename, "wb");
if (!binaryfile) {
/* Not fatal, just means we build it again next time, unless BFI patch is needed */
/* Not fatal, just means we build it again next time */
applog(LOG_DEBUG, "Unable to create file %s", data->binary_filename);
goto out;
} else {
Expand Down
3 changes: 0 additions & 3 deletions ocl/build_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ typedef struct _build_kernel_data {
char sgminer_path[255];
const char *kernel_path;
size_t work_size;
bool has_bit_align;
bool patch_bfi;
float opencl_version;
} build_kernel_data;

bool needs_bfi_patch(build_kernel_data *data);
cl_program build_opencl_kernel(build_kernel_data *data, const char *filename);
bool save_opencl_kernel(build_kernel_data *data, cl_program program);
void set_base_compiler_options(build_kernel_data *data);
Expand Down
97 changes: 0 additions & 97 deletions ocl/patch_kernel.c

This file was deleted.

10 changes: 0 additions & 10 deletions ocl/patch_kernel.h

This file was deleted.

0 comments on commit 55da7b5

Please sign in to comment.