From 2bb176f81373a3050d79740605133e2d2be2db25 Mon Sep 17 00:00:00 2001 From: Paul Irofti Date: Sat, 29 Mar 2025 14:52:36 +0200 Subject: [PATCH] Use redundant pointer. Indent. Outputs now identical with R. --- inst/ccubes.cl | 42 ++++++++++++++++++++++------------- src/CCubes.c | 60 +++++++++++++++++++++++++------------------------- 2 files changed, 57 insertions(+), 45 deletions(-) diff --git a/inst/ccubes.cl b/inst/ccubes.cl index 20e2081..fcd0b15 100755 --- a/inst/ccubes.cl +++ b/inst/ccubes.cl @@ -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 @@ -129,11 +129,15 @@ ccubes_task(int k, /* work-group?: 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 = get_global_offset(0); + // size_t goffset = get_global_offset(0); // 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(); __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 *pichart_values = &g_pichart_values[gid * PICHART_WORDS]; - // coverage[0] = 1; - // printf("task %d, gws %d, goffset %d, gid %d\n", task, gws, goffset, gid); - // return; - redundant = true; + *redundant = true; int prevfoundPI = 0; @@ -153,6 +154,17 @@ ccubes_task(int k, int x = 0; 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 for (int i = 0; i < k; i++) { 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 // bool redundant = false; - redundant = false; + *redundant = false; 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 // - 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++; } - if (redundant) continue; + if (*redundant) continue; // bool coverage[POSROWS]; int covsum = 0; @@ -326,7 +338,7 @@ ccubes_task(int k, // verify row dominance int rd = 0; - while (rd < last_index[covsum - 1] && !redundant) { + while (rd < last_index[covsum - 1] && !*redundant) { bool dominated = true; for (int w = 0; w < PICHART_WORDS; w++) { @@ -336,11 +348,11 @@ ccubes_task(int k, } } - redundant = dominated; + *redundant = dominated; rd++; } - if (redundant) continue; + if (*redundant) continue; } } } diff --git a/src/CCubes.c b/src/CCubes.c index 96e86b5..fa5838b 100755 --- a/src/CCubes.c +++ b/src/CCubes.c @@ -241,38 +241,38 @@ SEXP CCubes(SEXP tt) { int current_batch = n_tasks < n_tasks_batch ? n_tasks : n_tasks_batch; 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; unsigned int *fixed_bits; unsigned int *value_bits; unsigned int *pichart_values; ccubes_do_tasks(ctx, - current_batch, - task, - k, - ninputs, - posrows, - negrows, - implicant_words, - value_bit_width, - value_bit_mask, - pichart_words, - estimPI, - nofvalues, - ON_set, - OFF_set, - p_implicants_pos, - p_implicants_val, - last_index, - p_covered, - p_pichart_pos, - redundant, - coverage, - fixed_bits, - value_bits, - pichart_values + current_batch, + task, + k, + ninputs, + posrows, + negrows, + implicant_words, + value_bit_width, + value_bit_mask, + pichart_words, + estimPI, + nofvalues, + ON_set, + OFF_set, + p_implicants_pos, + p_implicants_val, + last_index, + p_covered, + p_pichart_pos, + redundant, + coverage, + fixed_bits, + value_bits, + pichart_values ); for (int i = 0; i < current_batch; i++) { @@ -283,28 +283,28 @@ SEXP CCubes(SEXP tt) { log_debug_raw("ccubes", "coverage[%d]:", i); for (int j = 0; j < posrows; j++) { 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", "fixed_bits[%d]:", i); for (int j = 0; j < implicant_words; j++) { 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", "value_bits[%d]:", i); for (int j = 0; j < implicant_words; j++) { 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", "pichart_values[%d]:", i); for (int j = 0; j < pichart_words; j++) { 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"); }