Separate constant buffers at create and destroy.
This commit is contained in:
parent
5c34ae92de
commit
0c46ec57fe
3 changed files with 91 additions and 76 deletions
42
src/CCubes.c
42
src/CCubes.c
|
@ -66,20 +66,6 @@ SEXP CCubes(SEXP tt) {
|
||||||
struct timeval start, end;
|
struct timeval start, end;
|
||||||
double elapsed_time;
|
double elapsed_time;
|
||||||
|
|
||||||
config_set_int("log", LOG_LEVEL_WARN);
|
|
||||||
config_set_int("log:clccubes", LOG_LEVEL_DEBUG);
|
|
||||||
config_set_int("log:ccubes", LOG_LEVEL_DEBUG);
|
|
||||||
config_set_int("log:cl", LOG_LEVEL_DEBUG);
|
|
||||||
|
|
||||||
char log[100] = {0};
|
|
||||||
sprintf(log, "log-ccubes");
|
|
||||||
config_set_string("out", log);
|
|
||||||
|
|
||||||
struct ccubes_context *ctx = ccubes_create(kernel_file);
|
|
||||||
if (ctx == NULL) {
|
|
||||||
log_error("ccubes", "ccubes_do_tasks failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (PRINT_INFO) {
|
if (PRINT_INFO) {
|
||||||
Rprintf("--- START ---\n");
|
Rprintf("--- START ---\n");
|
||||||
|
@ -215,6 +201,28 @@ SEXP CCubes(SEXP tt) {
|
||||||
Rprintf("ON-set minterms: %d\n", posrows);
|
Rprintf("ON-set minterms: %d\n", posrows);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* OPENCL SETUP */
|
||||||
|
config_set_int("log", LOG_LEVEL_WARN);
|
||||||
|
config_set_int("log:clccubes", LOG_LEVEL_DEBUG);
|
||||||
|
config_set_int("log:ccubes", LOG_LEVEL_DEBUG);
|
||||||
|
config_set_int("log:cl", LOG_LEVEL_DEBUG);
|
||||||
|
|
||||||
|
char log[100] = {0};
|
||||||
|
sprintf(log, "log-ccubes");
|
||||||
|
config_set_string("out", log);
|
||||||
|
|
||||||
|
struct ccubes_context *ctx = ccubes_create(
|
||||||
|
kernel_file,
|
||||||
|
ninputs,
|
||||||
|
posrows,
|
||||||
|
negrows,
|
||||||
|
nofvalues,
|
||||||
|
ON_set,
|
||||||
|
OFF_set
|
||||||
|
);
|
||||||
|
if (ctx == NULL) {
|
||||||
|
log_error("ccubes", "ccubes_do_tasks failed");
|
||||||
|
}
|
||||||
|
|
||||||
int stop_counter = 0; // to stop if two consecutive levels of complexity yield no PIs
|
int stop_counter = 0; // to stop if two consecutive levels of complexity yield no PIs
|
||||||
int k;
|
int k;
|
||||||
|
@ -255,17 +263,11 @@ SEXP CCubes(SEXP tt) {
|
||||||
task,
|
task,
|
||||||
k,
|
k,
|
||||||
prevfoundPI,
|
prevfoundPI,
|
||||||
ninputs,
|
|
||||||
posrows,
|
|
||||||
negrows,
|
|
||||||
implicant_words,
|
implicant_words,
|
||||||
value_bit_width,
|
value_bit_width,
|
||||||
value_bit_mask,
|
value_bit_mask,
|
||||||
pichart_words,
|
pichart_words,
|
||||||
estimPI,
|
estimPI,
|
||||||
nofvalues,
|
|
||||||
ON_set,
|
|
||||||
OFF_set,
|
|
||||||
p_implicants_pos,
|
p_implicants_pos,
|
||||||
p_implicants_val,
|
p_implicants_val,
|
||||||
last_index,
|
last_index,
|
||||||
|
|
104
src/clccubes.c
104
src/clccubes.c
|
@ -26,8 +26,50 @@
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
ccubes_create_alloc(struct ccubes_context *ctx,
|
||||||
|
int *nofvalues, /* IN: RC */
|
||||||
|
int *ON_set, /* IN: RC */
|
||||||
|
int *OFF_set /* IN: RC */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
|
/* __global const int *nofvalues, IN: RC */
|
||||||
|
ctx->nofvalues = clCreateBuffer(ctx->clctx->ctx,
|
||||||
|
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
||||||
|
ctx->ninputs * sizeof(int), nofvalues, &rc);
|
||||||
|
if (rc != CL_SUCCESS) {
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
/* __global const int *ON_set, IN: RC */
|
||||||
|
ctx->ON_set = clCreateBuffer(ctx->clctx->ctx,
|
||||||
|
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
||||||
|
ctx->posrows * ctx->ninputs * sizeof(int), ON_set, &rc);
|
||||||
|
if (rc != CL_SUCCESS) {
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
/* __global const int *OFF_set, IN: RC */
|
||||||
|
ctx->OFF_set = clCreateBuffer(ctx->clctx->ctx,
|
||||||
|
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
||||||
|
ctx->ninputs * ctx->negrows * sizeof(int), OFF_set, &rc);
|
||||||
|
if (rc != CL_SUCCESS) {
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
err:
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
struct ccubes_context *
|
struct ccubes_context *
|
||||||
ccubes_create(const char *ccubes_kernel_file)
|
ccubes_create(const char *ccubes_kernel_file,
|
||||||
|
int ninputs,
|
||||||
|
int posrows,
|
||||||
|
int negrows,
|
||||||
|
int *nofvalues, /* IN: RC */
|
||||||
|
int *ON_set, /* IN: RC */
|
||||||
|
int *OFF_set /* IN: RC */
|
||||||
|
)
|
||||||
{
|
{
|
||||||
struct ccubes_context *ctx = NULL;
|
struct ccubes_context *ctx = NULL;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
@ -69,6 +111,16 @@ ccubes_create(const char *ccubes_kernel_file)
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx->ninputs = ninputs;
|
||||||
|
ctx->posrows = posrows;
|
||||||
|
ctx->negrows = negrows;
|
||||||
|
rc = ccubes_create_alloc(ctx, nofvalues, ON_set, OFF_set);
|
||||||
|
if (rc != CL_SUCCESS) {
|
||||||
|
log_error("clccubes",
|
||||||
|
"Failed to allocate initial buffers");
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
err:
|
err:
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
@ -79,9 +131,6 @@ ccubes_init(struct ccubes_context *ctx,
|
||||||
int n_tasks_off,
|
int n_tasks_off,
|
||||||
int k,
|
int k,
|
||||||
int prevfoundPI,
|
int prevfoundPI,
|
||||||
int ninputs,
|
|
||||||
int posrows,
|
|
||||||
int negrows,
|
|
||||||
int implicant_words,
|
int implicant_words,
|
||||||
int value_bit_width,
|
int value_bit_width,
|
||||||
int value_bit_mask,
|
int value_bit_mask,
|
||||||
|
@ -93,9 +142,6 @@ ccubes_init(struct ccubes_context *ctx,
|
||||||
|
|
||||||
ctx->k = k;
|
ctx->k = k;
|
||||||
ctx->prevfoundPI = prevfoundPI;
|
ctx->prevfoundPI = prevfoundPI;
|
||||||
ctx->ninputs = ninputs;
|
|
||||||
ctx->posrows = posrows;
|
|
||||||
ctx->negrows = negrows;
|
|
||||||
ctx->implicant_words = implicant_words;
|
ctx->implicant_words = implicant_words;
|
||||||
ctx->value_bit_width = value_bit_width;
|
ctx->value_bit_width = value_bit_width;
|
||||||
ctx->value_bit_mask = value_bit_mask;
|
ctx->value_bit_mask = value_bit_mask;
|
||||||
|
@ -104,7 +150,6 @@ ccubes_init(struct ccubes_context *ctx,
|
||||||
|
|
||||||
ctx->gws = n_tasks;
|
ctx->gws = n_tasks;
|
||||||
ctx->goff = n_tasks_off;
|
ctx->goff = n_tasks_off;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
@ -168,9 +213,6 @@ err:
|
||||||
|
|
||||||
int
|
int
|
||||||
ccubes_alloc(struct ccubes_context *ctx,
|
ccubes_alloc(struct ccubes_context *ctx,
|
||||||
int *nofvalues, /* IN: RC */
|
|
||||||
int *ON_set, /* IN: RC */
|
|
||||||
int *OFF_set, /* IN: RC */
|
|
||||||
unsigned int *p_implicants_pos, /* IN: RC */
|
unsigned int *p_implicants_pos, /* IN: RC */
|
||||||
unsigned int *p_implicants_val, /* IN: RC */
|
unsigned int *p_implicants_val, /* IN: RC */
|
||||||
int *last_index, /* IN: RC */
|
int *last_index, /* IN: RC */
|
||||||
|
@ -200,27 +242,6 @@ ccubes_alloc(struct ccubes_context *ctx,
|
||||||
* INPUTS
|
* INPUTS
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* __global const int *nofvalues, IN: RC */
|
|
||||||
ctx->nofvalues = clCreateBuffer(ctx->clctx->ctx,
|
|
||||||
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
|
||||||
ctx->ninputs * sizeof(int), nofvalues, &rc);
|
|
||||||
if (rc != CL_SUCCESS) {
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
/* __global const int *ON_set, IN: RC */
|
|
||||||
ctx->ON_set = clCreateBuffer(ctx->clctx->ctx,
|
|
||||||
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
|
||||||
ctx->posrows * ctx->ninputs * sizeof(int), ON_set, &rc);
|
|
||||||
if (rc != CL_SUCCESS) {
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
/* __global const int *OFF_set, IN: RC */
|
|
||||||
ctx->OFF_set = clCreateBuffer(ctx->clctx->ctx,
|
|
||||||
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
|
||||||
ctx->ninputs * ctx->negrows * sizeof(int), OFF_set, &rc);
|
|
||||||
if (rc != CL_SUCCESS) {
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
/* __global const unsigned int *p_implicants_pos, IN: RC */
|
/* __global const unsigned int *p_implicants_pos, IN: RC */
|
||||||
ctx->p_implicants_pos = clCreateBuffer(ctx->clctx->ctx,
|
ctx->p_implicants_pos = clCreateBuffer(ctx->clctx->ctx,
|
||||||
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
||||||
|
@ -468,17 +489,11 @@ ccubes_do_tasks(struct ccubes_context *ccubesctx,
|
||||||
int n_tasks_off,
|
int n_tasks_off,
|
||||||
int k,
|
int k,
|
||||||
int prevfoundPI,
|
int prevfoundPI,
|
||||||
int ninputs,
|
|
||||||
int posrows,
|
|
||||||
int negrows,
|
|
||||||
int implicant_words,
|
int implicant_words,
|
||||||
int value_bit_width,
|
int value_bit_width,
|
||||||
int value_bit_mask,
|
int value_bit_mask,
|
||||||
int pichart_words,
|
int pichart_words,
|
||||||
int estimPI,
|
int estimPI,
|
||||||
int *nofvalues, /* IN: RC */
|
|
||||||
int *ON_set, /* IN: RC */
|
|
||||||
int *OFF_set, /* IN: RC */
|
|
||||||
unsigned int *p_implicants_pos, /* IN: RC */
|
unsigned int *p_implicants_pos, /* IN: RC */
|
||||||
unsigned int *p_implicants_val, /* IN: RC */
|
unsigned int *p_implicants_val, /* IN: RC */
|
||||||
int *last_index, /* IN: RC */
|
int *last_index, /* IN: RC */
|
||||||
|
@ -499,9 +514,6 @@ ccubes_do_tasks(struct ccubes_context *ccubesctx,
|
||||||
n_tasks_off,
|
n_tasks_off,
|
||||||
k,
|
k,
|
||||||
prevfoundPI,
|
prevfoundPI,
|
||||||
ninputs,
|
|
||||||
posrows,
|
|
||||||
negrows,
|
|
||||||
implicant_words,
|
implicant_words,
|
||||||
value_bit_width,
|
value_bit_width,
|
||||||
value_bit_mask,
|
value_bit_mask,
|
||||||
|
@ -525,9 +537,6 @@ ccubes_do_tasks(struct ccubes_context *ccubesctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = ccubes_alloc(ccubesctx,
|
rc = ccubes_alloc(ccubesctx,
|
||||||
nofvalues,
|
|
||||||
ON_set,
|
|
||||||
OFF_set,
|
|
||||||
p_implicants_pos,
|
p_implicants_pos,
|
||||||
p_implicants_val,
|
p_implicants_val,
|
||||||
last_index,
|
last_index,
|
||||||
|
@ -569,9 +578,6 @@ ccubes_clean_up(struct ccubes_context *ctx)
|
||||||
log_debug("clccubes", "ccubes_unmap");
|
log_debug("clccubes", "ccubes_unmap");
|
||||||
|
|
||||||
/* INPUTS */
|
/* INPUTS */
|
||||||
clReleaseMemObject(ctx->nofvalues);
|
|
||||||
clReleaseMemObject(ctx->ON_set);
|
|
||||||
clReleaseMemObject(ctx->OFF_set);
|
|
||||||
clReleaseMemObject(ctx->p_implicants_pos);
|
clReleaseMemObject(ctx->p_implicants_pos);
|
||||||
clReleaseMemObject(ctx->p_implicants_val);
|
clReleaseMemObject(ctx->p_implicants_val);
|
||||||
clReleaseMemObject(ctx->last_index);
|
clReleaseMemObject(ctx->last_index);
|
||||||
|
@ -594,6 +600,10 @@ ccubes_clean_up(struct ccubes_context *ctx)
|
||||||
void
|
void
|
||||||
ccubes_destroy(struct ccubes_context *ctx)
|
ccubes_destroy(struct ccubes_context *ctx)
|
||||||
{
|
{
|
||||||
|
clReleaseMemObject(ctx->nofvalues);
|
||||||
|
clReleaseMemObject(ctx->ON_set);
|
||||||
|
clReleaseMemObject(ctx->OFF_set);
|
||||||
|
|
||||||
cl_clean_up(*ctx->clctx);
|
cl_clean_up(*ctx->clctx);
|
||||||
log_debug("clccubes", "cl_clean_up");
|
log_debug("clccubes", "cl_clean_up");
|
||||||
|
|
||||||
|
|
|
@ -49,10 +49,12 @@ struct ccubes_context {
|
||||||
int pichart_words;
|
int pichart_words;
|
||||||
int estimPI;
|
int estimPI;
|
||||||
|
|
||||||
/* INPUTS */
|
/* CONSTANT INPUTS */
|
||||||
cl_mem nofvalues;
|
cl_mem nofvalues;
|
||||||
cl_mem ON_set;
|
cl_mem ON_set;
|
||||||
cl_mem OFF_set;
|
cl_mem OFF_set;
|
||||||
|
|
||||||
|
/* INPUTS */
|
||||||
cl_mem p_implicants_pos;
|
cl_mem p_implicants_pos;
|
||||||
cl_mem p_implicants_val;
|
cl_mem p_implicants_val;
|
||||||
cl_mem last_index;
|
cl_mem last_index;
|
||||||
|
@ -81,7 +83,14 @@ struct ccubes_context {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ccubes_context *
|
struct ccubes_context *
|
||||||
ccubes_create(const char *ccubes_kernel_file);
|
ccubes_create(const char *ccubes_kernel_file,
|
||||||
|
int ninputs,
|
||||||
|
int posrows,
|
||||||
|
int negrows,
|
||||||
|
int *nofvalues, /* IN: RC */
|
||||||
|
int *ON_set, /* IN: RC */
|
||||||
|
int *OFF_set /* IN: RC */
|
||||||
|
);
|
||||||
|
|
||||||
int
|
int
|
||||||
ccubes_do_tasks(struct ccubes_context *ccubesctx,
|
ccubes_do_tasks(struct ccubes_context *ccubesctx,
|
||||||
|
@ -89,17 +98,11 @@ ccubes_do_tasks(struct ccubes_context *ccubesctx,
|
||||||
int n_tasks_off,
|
int n_tasks_off,
|
||||||
int k,
|
int k,
|
||||||
int prevfoundPI,
|
int prevfoundPI,
|
||||||
int ninputs,
|
|
||||||
int posrows,
|
|
||||||
int negrows,
|
|
||||||
int implicant_words,
|
int implicant_words,
|
||||||
int value_bit_width,
|
int value_bit_width,
|
||||||
int value_bit_mask,
|
int value_bit_mask,
|
||||||
int pichart_words,
|
int pichart_words,
|
||||||
int estimPI,
|
int estimPI,
|
||||||
int *nofvalues, /* IN: RC */
|
|
||||||
int *ON_set, /* IN: RC */
|
|
||||||
int *OFF_set, /* IN: RC */
|
|
||||||
unsigned int *p_implicants_pos, /* IN: RC */
|
unsigned int *p_implicants_pos, /* IN: RC */
|
||||||
unsigned int *p_implicants_val, /* IN: RC */
|
unsigned int *p_implicants_val, /* IN: RC */
|
||||||
int *last_index, /* IN: RC */
|
int *last_index, /* IN: RC */
|
||||||
|
|
Loading…
Add table
Reference in a new issue