WIP redundant - try 2

This commit is contained in:
Adrian Dusa 2025-03-28 23:28:19 +02:00
parent 105f9d3583
commit e72adb2fa3
4 changed files with 40 additions and 39 deletions

View file

@ -223,7 +223,7 @@ SEXP CCubes(SEXP tt) {
log_debug("ccubes", "Tasks %d - %d out of %d",
task, task + current_batch - 1, n_tasks);
// bool *redundant;
bool *redundant;
bool *coverage;
unsigned int *fixed_bits;
unsigned int *value_bits;
@ -248,7 +248,7 @@ SEXP CCubes(SEXP tt) {
last_index,
p_covered,
p_pichart_pos,
// redundant,
redundant,
coverage,
fixed_bits,
value_bits,
@ -258,7 +258,7 @@ SEXP CCubes(SEXP tt) {
for (int i = 0; i < current_batch; i++) {
log_debug("ccubes", "Task %d", i);
// log_debug_raw("ccubes", "redundant[%d]: %d\n", i, ctx->h_redundant[i]);
log_debug_raw("ccubes", "redundant[%d]: %d\n", i, ctx->h_redundant[i]);
log_debug_raw("ccubes", "coverage[%d]:", i);
for (int j = 0; j < posrows; j++) {
@ -415,10 +415,10 @@ SEXP CCubes(SEXP tt) {
}
// check if the current PI is not redundant
Rboolean redundant = false;
Rboolean redundantOMP = false;
int i = 0;
while (i < prevfoundPI && !redundant) {
while (i < prevfoundPI && !redundantOMP) {
// /*
// - ck contains the complexity level for each of the previously found non-redundant PIs
// - indx is a matrix containing the indexes of the columns where the values were stored
@ -447,12 +447,12 @@ SEXP CCubes(SEXP tt) {
}
}
redundant = is_subset;
redundantOMP = is_subset;
i++;
}
if (redundant) continue;
if (redundantOMP) continue;
Rboolean coverage[posrows];
int covsum = 0;
@ -473,7 +473,7 @@ SEXP CCubes(SEXP tt) {
// verify row dominance
int rd = 0;
while (rd < last_index[covsum - 1] && !redundant) {
while (rd < last_index[covsum - 1] && !redundantOMP) {
bool dominated = true;
for (int w = 0; w < pichart_words; w++) {
@ -483,11 +483,11 @@ SEXP CCubes(SEXP tt) {
}
}
redundant = dominated;
redundantOMP = dominated;
rd++;
}
if (redundant) continue;
if (redundantOMP) continue;
// Rprintf("It is a prime implicant\n");

View file

@ -92,7 +92,7 @@ nchoosek(int n, int k)
*
* OUTPUT:
* covsum - sum of coverage (reproduce on host instead?)
* // redundant (1) - read, write
* redundant (1) - read, write
* coverage (posrows x 1) - read, write
* fixed_bits (implicant_words x 1) - read, write
* value_bits (implicant_words x 1) - read, write
@ -118,7 +118,7 @@ ccubes_task(int k,
__global const int *last_index, /* IN: RC */
__global const int *p_covered, /* IN: RC */
__global const int *p_pichart_pos, /* IN: RC */
// __global bool *g_redundant, /* OUT: RW */
__global bool *g_redundant, /* OUT: RW */
__global bool *g_coverage, /* OUT: RW */
__global unsigned int *g_fixed_bits, /* OUT: RW */
__global unsigned int *g_value_bits, /* OUT: RW */
@ -136,7 +136,7 @@ ccubes_task(int k,
// size_t gid = task - goffset;
size_t gid = get_global_linear_id();
// __global bool *redundant = &g_redundant[gid];
__global bool *redundant = &g_redundant[gid];
__global bool *coverage = &g_coverage[gid * POSROWS];
__global unsigned int *fixed_bits = &g_fixed_bits[gid * IMPLICANT_WORDS];
__global unsigned int *value_bits = &g_value_bits[gid * IMPLICANT_WORDS];
@ -145,6 +145,7 @@ ccubes_task(int k,
// coverage[0] = 1;
// printf("task %d, gws %d, goffset %d, gid %d\n", task, gws, goffset, gid);
// return;
redundant = true;
int prevfoundPI = 0;
@ -266,8 +267,8 @@ ccubes_task(int k,
}
// check if the current PI is not redundant
bool redundant = false;
// redundant = false;
// bool redundant = false;
redundant = false;
int i = 0;
while (i < prevfoundPI && !redundant) {

View file

@ -161,7 +161,7 @@ ccubes_alloc(struct ccubes_context *ctx,
int *last_index, /* IN: RC */
int *p_covered, /* IN: RC */
int *p_pichart_pos, /* IN: RC */
// bool *redundant, /* OUT: RW */
bool *redundant, /* OUT: RW */
bool *coverage, /* OUT: RW */
unsigned int *fixed_bits, /* OUT: RW */
unsigned int *value_bits, /* OUT: RW */
@ -173,7 +173,7 @@ ccubes_alloc(struct ccubes_context *ctx,
/*
* Save outputs for mapping
*/
// ctx->h_redundant = redundant;
ctx->h_redundant = redundant;
ctx->h_coverage = coverage;
ctx->h_fixed_bits = fixed_bits;
ctx->h_value_bits = value_bits;
@ -245,8 +245,8 @@ ccubes_alloc(struct ccubes_context *ctx,
*/
/* __global bool *redundant, OUT: RW */
// ctx->redundant = clCreateBuffer(ctx->clctx->ctx, CL_MEM_READ_WRITE,
// ctx->gws * sizeof(bool), NULL, &rc);
ctx->redundant = clCreateBuffer(ctx->clctx->ctx, CL_MEM_READ_WRITE,
ctx->gws * sizeof(bool), NULL, &rc);
/* __global bool *coverage, OUT: RW */
ctx->coverage = clCreateBuffer(ctx->clctx->ctx, CL_MEM_READ_WRITE,
@ -309,8 +309,8 @@ ccubes_run(struct ccubes_context *ctx)
sizeof(cl_mem), (void *)&ctx->p_pichart_pos);
/* OUTPUTS */
// rc |= clSetKernelArg(ctx->ccubes_task, arg++,
// sizeof(cl_mem), (void *)&ctx->redundant);
rc |= clSetKernelArg(ctx->ccubes_task, arg++,
sizeof(cl_mem), (void *)&ctx->redundant);
rc |= clSetKernelArg(ctx->ccubes_task, arg++,
sizeof(cl_mem), (void *)&ctx->coverage);
rc |= clSetKernelArg(ctx->ccubes_task, arg++,
@ -344,13 +344,13 @@ ccubes_map(struct ccubes_context *ctx)
{
int rc = 0;
// ctx->h_redundant = clEnqueueMapBuffer(ctx->clctx->gpu_queue,
// ctx->redundant, CL_TRUE, CL_MAP_READ, 0,
// ctx->gws * sizeof(bool), 0, NULL, NULL, &rc);
// if (rc != CL_SUCCESS) {
// log_error("clccubes", "redundant mapping failed (%d)", rc);
// goto err;
// }
ctx->h_redundant = clEnqueueMapBuffer(ctx->clctx->gpu_queue,
ctx->redundant, CL_TRUE, CL_MAP_READ, 0,
ctx->gws * sizeof(bool), 0, NULL, NULL, &rc);
if (rc != CL_SUCCESS) {
log_error("clccubes", "redundant mapping failed (%d)", rc);
goto err;
}
ctx->h_coverage = clEnqueueMapBuffer(ctx->clctx->gpu_queue,
ctx->coverage, CL_TRUE, CL_MAP_READ, 0,
ctx->gws * ctx->posrows * sizeof(bool), 0, NULL, NULL, &rc);
@ -395,11 +395,11 @@ ccubes_unmap(struct ccubes_context *ctx)
/*
* UNMAP
*/
// rc = clEnqueueUnmapMemObject(ctx->clctx->gpu_queue, ctx->redundant,
// ctx->h_redundant, 0, NULL, NULL);
// if (rc != CL_SUCCESS) {
// log_error("clccubes", "redundant unmapping failed (%d)", rc);
// }
rc = clEnqueueUnmapMemObject(ctx->clctx->gpu_queue, ctx->redundant,
ctx->h_redundant, 0, NULL, NULL);
if (rc != CL_SUCCESS) {
log_error("clccubes", "redundant unmapping failed (%d)", rc);
}
rc = clEnqueueUnmapMemObject(ctx->clctx->gpu_queue, ctx->coverage,
ctx->h_coverage, 0, NULL, NULL);
if (rc != CL_SUCCESS) {
@ -446,7 +446,7 @@ ccubes_do_tasks(struct ccubes_context *ccubesctx,
int *last_index, /* IN: RC */
int *p_covered, /* IN: RC */
int *p_pichart_pos, /* IN: RC */
// bool *redundant, /* OUT: RW */
bool *redundant, /* OUT: RW */
bool *coverage, /* OUT: RW */
unsigned int *fixed_bits, /* OUT: RW */
unsigned int *value_bits, /* OUT: RW */
@ -493,7 +493,7 @@ ccubes_do_tasks(struct ccubes_context *ccubesctx,
last_index,
p_covered,
p_pichart_pos,
// redundant,
redundant,
coverage,
fixed_bits,
value_bits,
@ -539,7 +539,7 @@ ccubes_clean_up(struct ccubes_context *ctx)
log_debug("clccubes", "clReleaseMemObject INPUTS");
/* OUTPUTS */
// clReleaseMemObject(ctx->redundant);
clReleaseMemObject(ctx->redundant);
clReleaseMemObject(ctx->coverage);
clReleaseMemObject(ctx->fixed_bits);
clReleaseMemObject(ctx->value_bits);

View file

@ -58,14 +58,14 @@ struct ccubes_context {
cl_mem p_pichart_pos;
/* OUTPUTS */
// cl_mem redundant;
cl_mem redundant;
cl_mem coverage;
cl_mem fixed_bits;
cl_mem value_bits;
cl_mem pichart_values;
/* Host outputs */
// bool *h_redundant;
bool *h_redundant;
bool *h_coverage;
unsigned int *h_fixed_bits;
unsigned int *h_value_bits;
@ -100,7 +100,7 @@ ccubes_do_tasks(struct ccubes_context *ccubesctx,
int *last_index, /* IN: RC */
int *p_covered, /* IN: RC */
int *p_pichart_pos, /* IN: RC */
// bool *redundant, /* OUT: RW */
bool *redundant, /* OUT: RW */
bool *coverage, /* OUT: RW */
unsigned int *fixed_bits, /* OUT: RW */
unsigned int *value_bits, /* OUT: RW */