Reuse clccubes context. Makes things go zooom!
This commit is contained in:
parent
f4ad81c8cc
commit
879f44d6a4
3 changed files with 62 additions and 36 deletions
13
src/CCubes.c
13
src/CCubes.c
|
@ -53,6 +53,10 @@ SEXP CCubes(SEXP tt) {
|
||||||
sprintf(log, "log-ccubes");
|
sprintf(log, "log-ccubes");
|
||||||
config_set_string("out", log);
|
config_set_string("out", log);
|
||||||
|
|
||||||
|
struct ccubes_context *ctx = ccubes_create();
|
||||||
|
if (ctx == NULL) {
|
||||||
|
log_error("ccubes", "ccubes_do_tasks failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (PRINT_INFO) {
|
if (PRINT_INFO) {
|
||||||
|
@ -197,7 +201,6 @@ SEXP CCubes(SEXP tt) {
|
||||||
|
|
||||||
int n_tasks = nchoosek(ninputs, k);
|
int n_tasks = nchoosek(ninputs, k);
|
||||||
int n_tasks_batch = 512;
|
int n_tasks_batch = 512;
|
||||||
struct ccubes_context *ctx = NULL;
|
|
||||||
for (int task = 0; task < n_tasks; task+=n_tasks_batch) {
|
for (int task = 0; task < n_tasks; task+=n_tasks_batch) {
|
||||||
/* adjust if batch size is larger than total job size */
|
/* adjust if batch size is larger than total job size */
|
||||||
int current_batch = n_tasks < n_tasks_batch ? n_tasks : n_tasks_batch;
|
int current_batch = n_tasks < n_tasks_batch ? n_tasks : n_tasks_batch;
|
||||||
|
@ -209,7 +212,8 @@ SEXP CCubes(SEXP tt) {
|
||||||
unsigned int *fixed_bits;
|
unsigned int *fixed_bits;
|
||||||
unsigned int *value_bits;
|
unsigned int *value_bits;
|
||||||
unsigned int *pichart_values;
|
unsigned int *pichart_values;
|
||||||
ctx = ccubes_do_tasks(current_batch,
|
ccubes_do_tasks(ctx,
|
||||||
|
current_batch,
|
||||||
task,
|
task,
|
||||||
k,
|
k,
|
||||||
ninputs,
|
ninputs,
|
||||||
|
@ -232,9 +236,6 @@ SEXP CCubes(SEXP tt) {
|
||||||
value_bits,
|
value_bits,
|
||||||
pichart_values
|
pichart_values
|
||||||
);
|
);
|
||||||
if (ctx == NULL) {
|
|
||||||
log_error("ccubes", "ccubes_do_tasks failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < current_batch; i++) {
|
for (int i = 0; i < current_batch; i++) {
|
||||||
log_debug("ccubes", "Task %d", i);
|
log_debug("ccubes", "Task %d", i);
|
||||||
|
@ -664,6 +665,8 @@ SEXP CCubes(SEXP tt) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ccubes_destroy(ctx);
|
||||||
|
|
||||||
R_Free(p_pichart);
|
R_Free(p_pichart);
|
||||||
R_Free(p_implicants_val);
|
R_Free(p_implicants_val);
|
||||||
R_Free(p_implicants_pos);
|
R_Free(p_implicants_pos);
|
||||||
|
|
|
@ -27,20 +27,10 @@
|
||||||
|
|
||||||
|
|
||||||
struct ccubes_context *
|
struct ccubes_context *
|
||||||
ccubes_init(int n_tasks,
|
ccubes_create()
|
||||||
int n_tasks_off,
|
|
||||||
int k,
|
|
||||||
int ninputs,
|
|
||||||
int posrows,
|
|
||||||
int negrows,
|
|
||||||
int implicant_words,
|
|
||||||
int value_bit_width,
|
|
||||||
int pichart_words,
|
|
||||||
int estimPI
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
int rc = 0;
|
|
||||||
struct ccubes_context *ctx = NULL;
|
struct ccubes_context *ctx = NULL;
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
ctx = malloc(sizeof *ctx);
|
ctx = malloc(sizeof *ctx);
|
||||||
if (ctx == NULL) {
|
if (ctx == NULL) {
|
||||||
|
@ -55,6 +45,37 @@ ccubes_init(int n_tasks,
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx->clctx->device_type = CL_DEVICE_TYPE_GPU;
|
||||||
|
strcpy(ctx->clctx->platform_name, "NVIDIA Corporation\0");
|
||||||
|
/* strcpy(ctx->clctx->platform_name, "Advanced Micro Devices, Inc.\0"); */
|
||||||
|
/* strcpy(ctx->clctx->platform_name, "Intel(R) Corporation\0"); */
|
||||||
|
rc = cl_init(ctx->clctx);
|
||||||
|
if (rc != CL_SUCCESS) {
|
||||||
|
log_error("clccubes",
|
||||||
|
"[%d] Failed to initialize the OpenCL framework", rc);
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
err:
|
||||||
|
return ctx;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ccubes_init(struct ccubes_context *ctx,
|
||||||
|
int n_tasks,
|
||||||
|
int n_tasks_off,
|
||||||
|
int k,
|
||||||
|
int ninputs,
|
||||||
|
int posrows,
|
||||||
|
int negrows,
|
||||||
|
int implicant_words,
|
||||||
|
int value_bit_width,
|
||||||
|
int pichart_words,
|
||||||
|
int estimPI
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
ctx->k = k;
|
ctx->k = k;
|
||||||
ctx->ninputs = ninputs;
|
ctx->ninputs = ninputs;
|
||||||
ctx->posrows = posrows;
|
ctx->posrows = posrows;
|
||||||
|
@ -68,7 +89,7 @@ ccubes_init(int n_tasks,
|
||||||
ctx->goff = n_tasks_off;
|
ctx->goff = n_tasks_off;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
return ctx;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -108,17 +129,6 @@ ccubes_build(struct ccubes_context *ctx)
|
||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
ctx->clctx->device_type = CL_DEVICE_TYPE_GPU;
|
|
||||||
strcpy(ctx->clctx->platform_name, "NVIDIA Corporation\0");
|
|
||||||
/* strcpy(ctx->clctx->platform_name, "Advanced Micro Devices, Inc.\0"); */
|
|
||||||
/*strcpy(ctx->clctx->platform_name, "Intel(R) Corporation\0");*/
|
|
||||||
rc = cl_init(ctx->clctx);
|
|
||||||
if (rc != CL_SUCCESS) {
|
|
||||||
printf("[%d] Failed to initialize the OpenCL framework\n",
|
|
||||||
rc);
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
rc = cl_build(*ctx->clctx, CL_DEVICE_TYPE_GPU,
|
rc = cl_build(*ctx->clctx, CL_DEVICE_TYPE_GPU,
|
||||||
"ccubes.cl", &ctx->ccubes_program);
|
"ccubes.cl", &ctx->ccubes_program);
|
||||||
|
@ -392,8 +402,9 @@ err:
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ccubes_context *
|
int
|
||||||
ccubes_do_tasks(int n_tasks,
|
ccubes_do_tasks(struct ccubes_context *ccubesctx,
|
||||||
|
int n_tasks,
|
||||||
int n_tasks_off,
|
int n_tasks_off,
|
||||||
int k,
|
int k,
|
||||||
int ninputs,
|
int ninputs,
|
||||||
|
@ -418,9 +429,9 @@ ccubes_do_tasks(int n_tasks,
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
struct ccubes_context *ccubesctx = NULL;
|
|
||||||
|
|
||||||
ccubesctx = ccubes_init(n_tasks,
|
rc = ccubes_init(ccubesctx,
|
||||||
|
n_tasks,
|
||||||
n_tasks_off,
|
n_tasks_off,
|
||||||
k,
|
k,
|
||||||
ninputs,
|
ninputs,
|
||||||
|
@ -477,7 +488,7 @@ ccubes_do_tasks(int n_tasks,
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
err:
|
err:
|
||||||
return ccubesctx;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -507,6 +518,12 @@ ccubes_clean_up(struct ccubes_context *ctx)
|
||||||
clReleaseMemObject(ctx->pichart_values);
|
clReleaseMemObject(ctx->pichart_values);
|
||||||
log_debug("clccubes", "clReleaseMemObject OUTPUTS");
|
log_debug("clccubes", "clReleaseMemObject OUTPUTS");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ccubes_destroy(struct ccubes_context *ctx)
|
||||||
|
{
|
||||||
cl_clean_up(*ctx->clctx);
|
cl_clean_up(*ctx->clctx);
|
||||||
log_debug("clccubes", "cl_clean_up");
|
log_debug("clccubes", "cl_clean_up");
|
||||||
|
|
||||||
|
@ -514,4 +531,3 @@ ccubes_clean_up(struct ccubes_context *ctx)
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,11 @@ struct ccubes_context {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ccubes_context *
|
struct ccubes_context *
|
||||||
ccubes_do_tasks(int n_tasks,
|
ccubes_create();
|
||||||
|
|
||||||
|
int
|
||||||
|
ccubes_do_tasks(struct ccubes_context *ccubesctx,
|
||||||
|
int n_tasks,
|
||||||
int n_tasks_off,
|
int n_tasks_off,
|
||||||
int k,
|
int k,
|
||||||
int ninputs,
|
int ninputs,
|
||||||
|
@ -101,4 +105,7 @@ ccubes_do_tasks(int n_tasks,
|
||||||
void
|
void
|
||||||
ccubes_clean_up(struct ccubes_context *ctx);
|
ccubes_clean_up(struct ccubes_context *ctx);
|
||||||
|
|
||||||
|
void
|
||||||
|
ccubes_destroy(struct ccubes_context *ctx);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue