Use redundant pointer. Indent. Outputs now identical with R.

This commit is contained in:
Paul Irofti 2025-03-29 14:52:36 +02:00
parent 0f47fc569f
commit 2bb176f813
2 changed files with 57 additions and 45 deletions

View file

@ -92,7 +92,7 @@ nchoosek(int n, int k)
* *
* OUTPUT: * OUTPUT:
* covsum - sum of coverage (reproduce on host instead?) * covsum - sum of coverage (reproduce on host instead?)
* redundant (1) - read, write * redundant (1) - read, write
* coverage (posrows x 1) - read, write * coverage (posrows x 1) - read, write
* fixed_bits (implicant_words x 1) - read, write * fixed_bits (implicant_words x 1) - read, write
* value_bits (implicant_words x 1) - read, write * value_bits (implicant_words x 1) - read, write
@ -129,11 +129,15 @@ ccubes_task(int k,
/* work-group?: k in 1 to ninputs */ /* work-group?: k in 1 to ninputs */
/* total work: tasks in nchoosek for k in 1 to ninputs */ /* total work: tasks in nchoosek for k in 1 to ninputs */
size_t task = get_global_id(0); // size_t gws = get_global_size(0);
size_t gws = get_global_size(0);
// size_t goffset = task - gws; // size_t goffset = task - gws;
size_t goffset = get_global_offset(0); // size_t goffset = get_global_offset(0);
// size_t gid = task - goffset; // size_t gid = task - goffset;
// coverage[0] = 1;
// printf("task %d, gws %d, goffset %d, gid %d\n", task, gws, goffset, gid);
// return;
size_t task = get_global_id(0);
size_t gid = get_global_linear_id(); size_t gid = get_global_linear_id();
__global bool *redundant = &g_redundant[gid]; __global bool *redundant = &g_redundant[gid];
@ -142,10 +146,7 @@ ccubes_task(int k,
__global unsigned int *value_bits = &g_value_bits[gid * IMPLICANT_WORDS]; __global unsigned int *value_bits = &g_value_bits[gid * IMPLICANT_WORDS];
__global unsigned int *pichart_values = &g_pichart_values[gid * PICHART_WORDS]; __global unsigned int *pichart_values = &g_pichart_values[gid * PICHART_WORDS];
// coverage[0] = 1; *redundant = true;
// printf("task %d, gws %d, goffset %d, gid %d\n", task, gws, goffset, gid);
// return;
redundant = true;
int prevfoundPI = 0; int prevfoundPI = 0;
@ -153,6 +154,17 @@ ccubes_task(int k,
int x = 0; int x = 0;
int combination = task; int combination = task;
/* INIT */
for (int i = 0; i < POSROWS; i++)
coverage[i] = 0;
for (int i = 0; i < IMPLICANT_WORDS; i++) {
fixed_bits[i] = 0U;
value_bits[i] = 0U;
}
for (int i = 0; i < PICHART_WORDS; i++)
pichart_values[i] = 0U;
// fill the combination for the current task // fill the combination for the current task
for (int i = 0; i < k; i++) { for (int i = 0; i < k; i++) {
while (nchoosek(NINPUTS - (x + 1), k - (i + 1)) <= combination) { while (nchoosek(NINPUTS - (x + 1), k - (i + 1)) <= combination) {
@ -268,10 +280,10 @@ ccubes_task(int k,
// check if the current PI is not redundant // check if the current PI is not redundant
// bool redundant = false; // bool redundant = false;
redundant = false; *redundant = false;
int i = 0; int i = 0;
while (i < prevfoundPI && !redundant) { while (i < prevfoundPI && !*redundant) {
// /* // /*
// - ck contains the complexity level for each of the previously found non-redundant PIs // - 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 // - indx is a matrix containing the indexes of the columns where the values were stored
@ -300,12 +312,12 @@ ccubes_task(int k,
} }
} }
redundant = is_subset; *redundant = is_subset;
i++; i++;
} }
if (redundant) continue; if (*redundant) continue;
// bool coverage[POSROWS]; // bool coverage[POSROWS];
int covsum = 0; int covsum = 0;
@ -326,7 +338,7 @@ ccubes_task(int k,
// verify row dominance // verify row dominance
int rd = 0; int rd = 0;
while (rd < last_index[covsum - 1] && !redundant) { while (rd < last_index[covsum - 1] && !*redundant) {
bool dominated = true; bool dominated = true;
for (int w = 0; w < PICHART_WORDS; w++) { for (int w = 0; w < PICHART_WORDS; w++) {
@ -336,11 +348,11 @@ ccubes_task(int k,
} }
} }
redundant = dominated; *redundant = dominated;
rd++; rd++;
} }
if (redundant) continue; if (*redundant) continue;
} }
} }
} }

View file

@ -241,38 +241,38 @@ SEXP CCubes(SEXP tt) {
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;
log_debug("ccubes", "Tasks %d - %d out of %d", log_debug("ccubes", "Tasks %d - %d out of %d",
task, task + current_batch - 1, n_tasks); task, task + current_batch - 1, n_tasks);
bool *redundant; bool *redundant;
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;
ccubes_do_tasks(ctx, ccubes_do_tasks(ctx,
current_batch, current_batch,
task, task,
k, k,
ninputs, ninputs,
posrows, posrows,
negrows, negrows,
implicant_words, implicant_words,
value_bit_width, value_bit_width,
value_bit_mask, value_bit_mask,
pichart_words, pichart_words,
estimPI, estimPI,
nofvalues, nofvalues,
ON_set, ON_set,
OFF_set, OFF_set,
p_implicants_pos, p_implicants_pos,
p_implicants_val, p_implicants_val,
last_index, last_index,
p_covered, p_covered,
p_pichart_pos, p_pichart_pos,
redundant, redundant,
coverage, coverage,
fixed_bits, fixed_bits,
value_bits, value_bits,
pichart_values pichart_values
); );
for (int i = 0; i < current_batch; i++) { for (int i = 0; i < current_batch; i++) {
@ -283,28 +283,28 @@ SEXP CCubes(SEXP tt) {
log_debug_raw("ccubes", "coverage[%d]:", i); log_debug_raw("ccubes", "coverage[%d]:", i);
for (int j = 0; j < posrows; j++) { for (int j = 0; j < posrows; j++) {
log_debug_raw("ccubes", " %d", log_debug_raw("ccubes", " %d",
ctx->h_coverage[i * posrows + j]); ctx->h_coverage[i * posrows + j]);
} }
log_debug_raw("ccubes", "\n"); log_debug_raw("ccubes", "\n");
log_debug_raw("ccubes", "fixed_bits[%d]:", i); log_debug_raw("ccubes", "fixed_bits[%d]:", i);
for (int j = 0; j < implicant_words; j++) { for (int j = 0; j < implicant_words; j++) {
log_debug_raw("ccubes", " %d", log_debug_raw("ccubes", " %d",
ctx->h_fixed_bits[i * implicant_words + j]); ctx->h_fixed_bits[i * implicant_words + j]);
} }
log_debug_raw("ccubes", "\n"); log_debug_raw("ccubes", "\n");
log_debug_raw("ccubes", "value_bits[%d]:", i); log_debug_raw("ccubes", "value_bits[%d]:", i);
for (int j = 0; j < implicant_words; j++) { for (int j = 0; j < implicant_words; j++) {
log_debug_raw("ccubes", " %d", log_debug_raw("ccubes", " %d",
ctx->h_value_bits[i * implicant_words + j]); ctx->h_value_bits[i * implicant_words + j]);
} }
log_debug_raw("ccubes", "\n"); log_debug_raw("ccubes", "\n");
log_debug_raw("ccubes", "pichart_values[%d]:", i); log_debug_raw("ccubes", "pichart_values[%d]:", i);
for (int j = 0; j < pichart_words; j++) { for (int j = 0; j < pichart_words; j++) {
log_debug_raw("ccubes", " %d", log_debug_raw("ccubes", " %d",
ctx->h_pichart_values[i * pichart_words + j]); ctx->h_pichart_values[i * pichart_words + j]);
} }
log_debug_raw("ccubes", "\n"); log_debug_raw("ccubes", "\n");
} }