Compare commits
3 commits
aa54de39b6
...
879f44d6a4
Author | SHA1 | Date | |
---|---|---|---|
879f44d6a4 | |||
f4ad81c8cc | |||
95ca0c519b |
4 changed files with 87 additions and 43 deletions
32
src/CCubes.c
32
src/CCubes.c
|
@ -45,7 +45,7 @@ SEXP CCubes(SEXP tt) {
|
||||||
double elapsed_time;
|
double elapsed_time;
|
||||||
|
|
||||||
config_set_int("log", LOG_LEVEL_WARN);
|
config_set_int("log", LOG_LEVEL_WARN);
|
||||||
config_set_int("log:clccubes", LOG_LEVEL_WARN);
|
config_set_int("log:clccubes", LOG_LEVEL_DEBUG);
|
||||||
config_set_int("log:ccubes", LOG_LEVEL_DEBUG);
|
config_set_int("log:ccubes", LOG_LEVEL_DEBUG);
|
||||||
config_set_int("log:cl", LOG_LEVEL_DEBUG);
|
config_set_int("log:cl", LOG_LEVEL_DEBUG);
|
||||||
|
|
||||||
|
@ -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) {
|
||||||
|
@ -195,16 +199,21 @@ SEXP CCubes(SEXP tt) {
|
||||||
Rprintf("---k: %d\n", k);
|
Rprintf("---k: %d\n", k);
|
||||||
}
|
}
|
||||||
|
|
||||||
int n_tasks = 512;
|
int n_tasks = nchoosek(ninputs, k);
|
||||||
struct ccubes_context *ctx = NULL;
|
int n_tasks_batch = 512;
|
||||||
for (int task = 0; task < nchoosek(ninputs, k); task+=n_tasks) {
|
for (int task = 0; task < n_tasks; task+=n_tasks_batch) {
|
||||||
|
/* adjust if batch size is larger than total job size */
|
||||||
|
int current_batch = n_tasks < n_tasks_batch ? n_tasks : n_tasks_batch;
|
||||||
|
|
||||||
log_debug("ccubes", "Tasks %d - %d out of %d",
|
log_debug("ccubes", "Tasks %d - %d out of %d",
|
||||||
task, task + n_tasks, nchoosek(ninputs, k));
|
task, task + current_batch - 1, n_tasks);
|
||||||
|
|
||||||
bool *coverage;
|
bool *coverage;
|
||||||
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(n_tasks,
|
ccubes_do_tasks(ctx,
|
||||||
|
current_batch,
|
||||||
task,
|
task,
|
||||||
k,
|
k,
|
||||||
ninputs,
|
ninputs,
|
||||||
|
@ -227,11 +236,8 @@ 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 < n_tasks; i++) {
|
for (int i = 0; i < current_batch; i++) {
|
||||||
log_debug("ccubes", "Task %d", i);
|
log_debug("ccubes", "Task %d", i);
|
||||||
|
|
||||||
log_debug_raw("ccubes", "coverage[%d]:", i);
|
log_debug_raw("ccubes", "coverage[%d]:", i);
|
||||||
|
@ -262,7 +268,9 @@ SEXP CCubes(SEXP tt) {
|
||||||
}
|
}
|
||||||
log_debug_raw("ccubes", "\n");
|
log_debug_raw("ccubes", "\n");
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
/* change to something less aggresive for reuse */
|
||||||
|
ccubes_clean_up(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
|
@ -657,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);
|
||||||
|
|
|
@ -225,6 +225,7 @@ cl_init(struct cl_uctx *puctx)
|
||||||
/*
|
/*
|
||||||
* CPU
|
* CPU
|
||||||
*/
|
*/
|
||||||
|
puctx->cpu_queue = NULL;
|
||||||
#if 0
|
#if 0
|
||||||
puctx->cpu_queue = clCreateCommandQueue(ctx, devices[1], 0,
|
puctx->cpu_queue = clCreateCommandQueue(ctx, devices[1], 0,
|
||||||
&result);
|
&result);
|
||||||
|
|
|
@ -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,15 +488,17 @@ ccubes_do_tasks(int n_tasks,
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
err:
|
err:
|
||||||
return ccubesctx;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ccubes_clean_up(struct ccubes_context *ctx)
|
ccubes_clean_up(struct ccubes_context *ctx)
|
||||||
{
|
{
|
||||||
clReleaseProgram(ctx->ccubes_program);
|
clReleaseProgram(ctx->ccubes_program);
|
||||||
|
log_debug("clccubes", "clReleaseProgram ccubes_program");
|
||||||
|
|
||||||
ccubes_unmap(ctx);
|
ccubes_unmap(ctx);
|
||||||
|
log_debug("clccubes", "ccubes_unmap");
|
||||||
|
|
||||||
/* INPUTS */
|
/* INPUTS */
|
||||||
clReleaseMemObject(ctx->nofvalues);
|
clReleaseMemObject(ctx->nofvalues);
|
||||||
|
@ -496,15 +509,25 @@ ccubes_clean_up(struct ccubes_context *ctx)
|
||||||
clReleaseMemObject(ctx->last_index);
|
clReleaseMemObject(ctx->last_index);
|
||||||
clReleaseMemObject(ctx->p_covered);
|
clReleaseMemObject(ctx->p_covered);
|
||||||
clReleaseMemObject(ctx->p_pichart_pos);
|
clReleaseMemObject(ctx->p_pichart_pos);
|
||||||
|
log_debug("clccubes", "clReleaseMemObject INPUTS");
|
||||||
|
|
||||||
/* OUTPUTS */
|
/* OUTPUTS */
|
||||||
clReleaseMemObject(ctx->coverage);
|
clReleaseMemObject(ctx->coverage);
|
||||||
clReleaseMemObject(ctx->fixed_bits);
|
clReleaseMemObject(ctx->fixed_bits);
|
||||||
clReleaseMemObject(ctx->value_bits);
|
clReleaseMemObject(ctx->value_bits);
|
||||||
clReleaseMemObject(ctx->pichart_values);
|
clReleaseMemObject(ctx->pichart_values);
|
||||||
|
log_debug("clccubes", "clReleaseMemObject OUTPUTS");
|
||||||
cl_clean_up(*ctx->clctx);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ccubes_destroy(struct ccubes_context *ctx)
|
||||||
|
{
|
||||||
|
cl_clean_up(*ctx->clctx);
|
||||||
|
log_debug("clccubes", "cl_clean_up");
|
||||||
|
|
||||||
|
free(ctx);
|
||||||
|
|
||||||
|
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,
|
||||||
|
@ -98,4 +102,10 @@ ccubes_do_tasks(int n_tasks,
|
||||||
unsigned int *pichart_values /* OUT: RW */
|
unsigned int *pichart_values /* OUT: RW */
|
||||||
);
|
);
|
||||||
|
|
||||||
|
void
|
||||||
|
ccubes_clean_up(struct ccubes_context *ctx);
|
||||||
|
|
||||||
|
void
|
||||||
|
ccubes_destroy(struct ccubes_context *ctx);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue