2025-03-26 11:50:07 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2025 Paul Irofti <paul@irofti.net>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2025-03-21 18:52:41 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "real.h"
|
|
|
|
#include "cl_setup.h"
|
|
|
|
|
|
|
|
#include "clccubes.h"
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "logging.h"
|
|
|
|
|
|
|
|
|
2025-03-27 10:46:18 +02:00
|
|
|
struct ccubes_context *
|
2025-03-29 16:51:06 +02:00
|
|
|
ccubes_create(const char *ccubes_kernel_file)
|
2025-03-21 18:52:41 +02:00
|
|
|
{
|
2025-03-27 10:46:18 +02:00
|
|
|
struct ccubes_context *ctx = NULL;
|
2025-03-27 20:42:49 +02:00
|
|
|
int rc = 0;
|
2025-03-27 10:46:18 +02:00
|
|
|
|
|
|
|
ctx = malloc(sizeof *ctx);
|
|
|
|
if (ctx == NULL) {
|
|
|
|
log_error("clccubes", "ctx malloc failed");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2025-03-21 18:52:41 +02:00
|
|
|
|
|
|
|
ctx->clctx = malloc(sizeof *ctx->clctx);
|
2025-03-26 11:34:01 +02:00
|
|
|
if (ctx->clctx == NULL) {
|
2025-03-27 10:46:18 +02:00
|
|
|
log_error("clccubes", "clctx malloc failed");
|
2025-03-26 11:34:01 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2025-03-27 20:42:49 +02:00
|
|
|
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",
|
2025-03-28 19:05:33 +02:00
|
|
|
"[%d] Failed to initialize the OpenCL framework", rc);
|
2025-03-27 20:42:49 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2025-03-29 16:43:15 +02:00
|
|
|
if (ccubes_kernel_file == NULL) {
|
|
|
|
log_error("clccubes",
|
|
|
|
"Kernel file pointer is NULL", ccubes_kernel_file);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
ctx->ccubes_kernel_file = strdup(ccubes_kernel_file);
|
|
|
|
if (ctx->ccubes_kernel_file == NULL) {
|
|
|
|
log_error("clccubes",
|
|
|
|
"Failed to copy kernel file path %s",
|
|
|
|
ccubes_kernel_file);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2025-03-27 20:42:49 +02:00
|
|
|
err:
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ccubes_init(struct ccubes_context *ctx,
|
|
|
|
int n_tasks,
|
|
|
|
int n_tasks_off,
|
|
|
|
int k,
|
2025-03-30 00:04:12 +02:00
|
|
|
int prevfoundPI,
|
2025-03-27 20:42:49 +02:00
|
|
|
int ninputs,
|
|
|
|
int posrows,
|
|
|
|
int negrows,
|
|
|
|
int implicant_words,
|
|
|
|
int value_bit_width,
|
2025-03-28 02:23:36 +02:00
|
|
|
int value_bit_mask,
|
2025-03-27 20:42:49 +02:00
|
|
|
int pichart_words,
|
|
|
|
int estimPI
|
|
|
|
)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
2025-03-26 11:34:01 +02:00
|
|
|
ctx->k = k;
|
2025-03-30 00:04:12 +02:00
|
|
|
ctx->prevfoundPI = prevfoundPI;
|
2025-03-26 11:34:01 +02:00
|
|
|
ctx->ninputs = ninputs;
|
|
|
|
ctx->posrows = posrows;
|
|
|
|
ctx->negrows = negrows;
|
|
|
|
ctx->implicant_words = implicant_words;
|
|
|
|
ctx->value_bit_width = value_bit_width;
|
2025-03-28 02:23:36 +02:00
|
|
|
ctx->value_bit_mask = value_bit_mask;
|
2025-03-26 11:34:01 +02:00
|
|
|
ctx->pichart_words = pichart_words;
|
|
|
|
ctx->estimPI = estimPI;
|
|
|
|
|
2025-03-26 12:59:48 +02:00
|
|
|
ctx->gws = n_tasks;
|
|
|
|
ctx->goff = n_tasks_off;
|
2025-03-26 11:34:01 +02:00
|
|
|
|
|
|
|
err:
|
2025-03-27 20:42:49 +02:00
|
|
|
return rc;
|
2025-03-26 11:34:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ccubes_preprocess(struct ccubes_context *ctx)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
fp = fopen("ccubes_generated.h", "w");
|
|
|
|
if (fp == NULL) {
|
|
|
|
rc = -1;
|
|
|
|
log_error("clccubes", "preprocess fopen failed (%d)", rc);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fp, "#ifndef CCUBES_GENERATED_H__\n");
|
|
|
|
fprintf(fp, "#define CCUBES_GENERATED_H__\n");
|
|
|
|
|
|
|
|
fprintf(fp, "#define NINPUTS %d\n", ctx->ninputs);
|
|
|
|
fprintf(fp, "#define POSROWS %d\n", ctx->posrows);
|
|
|
|
fprintf(fp, "#define NEGROWS %d\n", ctx->negrows);
|
|
|
|
fprintf(fp, "#define IMPLICANT_WORDS %d\n", ctx->implicant_words);
|
|
|
|
fprintf(fp, "#define VALUE_BIT_WIDTH %d\n", ctx->value_bit_width);
|
2025-03-28 02:23:36 +02:00
|
|
|
fprintf(fp, "#define VALUE_BIT_MASK %d\n", ctx->value_bit_mask);
|
2025-03-26 11:34:01 +02:00
|
|
|
fprintf(fp, "#define PICHART_WORDS %d\n", ctx->pichart_words);
|
|
|
|
|
2025-03-26 15:42:34 +02:00
|
|
|
fprintf(fp, "#endif\n");
|
2025-03-26 11:34:01 +02:00
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
err:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
ccubes_build(struct ccubes_context *ctx)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
2025-03-21 18:52:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
rc = cl_build(*ctx->clctx, CL_DEVICE_TYPE_GPU,
|
2025-03-29 16:43:15 +02:00
|
|
|
ctx->ccubes_kernel_file, &ctx->ccubes_program);
|
2025-03-21 18:52:41 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
2025-03-26 11:34:01 +02:00
|
|
|
log_warn("clccubes", "Failed building ccubes.cl (%d)", rc);
|
2025-03-21 18:52:41 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = cl_get_kern(ctx->ccubes_program, "ccubes_task",
|
2025-03-28 19:05:33 +02:00
|
|
|
&ctx->ccubes_task);
|
2025-03-21 18:52:41 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
2025-03-26 11:34:01 +02:00
|
|
|
log_warn("clccubes", "Failed fetching ccubes_task (%d)", rc);
|
2025-03-21 18:52:41 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2025-03-26 11:34:01 +02:00
|
|
|
err:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ccubes_alloc(struct ccubes_context *ctx,
|
2025-03-26 15:15:57 +02:00
|
|
|
int *nofvalues, /* IN: RC */
|
|
|
|
int *ON_set, /* IN: RC */
|
|
|
|
int *OFF_set, /* IN: RC */
|
2025-03-26 11:41:28 +02:00
|
|
|
unsigned int *p_implicants_pos, /* IN: RC */
|
|
|
|
unsigned int *p_implicants_val, /* IN: RC */
|
|
|
|
int *last_index, /* IN: RC */
|
|
|
|
int *p_covered, /* IN: RC */
|
|
|
|
int *p_pichart_pos, /* IN: RC */
|
2025-03-28 23:28:19 +02:00
|
|
|
bool *redundant, /* OUT: RW */
|
2025-03-26 11:34:01 +02:00
|
|
|
bool *coverage, /* OUT: RW */
|
2025-03-30 00:04:12 +02:00
|
|
|
int *taskpis, /* OUT: RW */
|
2025-03-26 11:34:01 +02:00
|
|
|
unsigned int *fixed_bits, /* OUT: RW */
|
|
|
|
unsigned int *value_bits, /* OUT: RW */
|
|
|
|
unsigned int *pichart_values /* OUT: RW */
|
|
|
|
)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Save outputs for mapping
|
|
|
|
*/
|
2025-03-28 23:28:19 +02:00
|
|
|
ctx->h_redundant = redundant;
|
2025-03-26 11:34:01 +02:00
|
|
|
ctx->h_coverage = coverage;
|
2025-03-30 00:04:12 +02:00
|
|
|
ctx->h_taskpis = taskpis;
|
2025-03-26 11:34:01 +02:00
|
|
|
ctx->h_fixed_bits = fixed_bits;
|
|
|
|
ctx->h_value_bits = value_bits;
|
|
|
|
ctx->h_pichart_values = pichart_values;
|
|
|
|
|
2025-03-25 23:03:40 +02:00
|
|
|
/*
|
|
|
|
* INPUTS
|
|
|
|
*/
|
|
|
|
|
2025-03-26 15:15:57 +02:00
|
|
|
/* __global const int *nofvalues, IN: RC */
|
2025-03-25 23:03:40 +02:00
|
|
|
ctx->nofvalues = clCreateBuffer(ctx->clctx->ctx,
|
2025-03-28 19:05:33 +02:00
|
|
|
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
|
|
|
ctx->ninputs * sizeof(int), nofvalues, &rc);
|
2025-03-25 23:03:40 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
goto err;
|
|
|
|
}
|
2025-03-26 15:15:57 +02:00
|
|
|
/* __global const int *ON_set, IN: RC */
|
2025-03-25 23:03:40 +02:00
|
|
|
ctx->ON_set = clCreateBuffer(ctx->clctx->ctx,
|
2025-03-28 19:05:33 +02:00
|
|
|
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
|
|
|
ctx->posrows * ctx->ninputs * sizeof(int), ON_set, &rc);
|
2025-03-25 23:03:40 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
goto err;
|
|
|
|
}
|
2025-03-26 15:15:57 +02:00
|
|
|
/* __global const int *OFF_set, IN: RC */
|
2025-03-25 23:03:40 +02:00
|
|
|
ctx->OFF_set = clCreateBuffer(ctx->clctx->ctx,
|
2025-03-28 19:05:33 +02:00
|
|
|
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
|
|
|
ctx->ninputs * ctx->negrows * sizeof(int), OFF_set, &rc);
|
2025-03-25 23:03:40 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
/* __global const unsigned int *p_implicants_pos, IN: RC */
|
|
|
|
ctx->p_implicants_pos = clCreateBuffer(ctx->clctx->ctx,
|
2025-03-28 19:05:33 +02:00
|
|
|
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
|
|
|
ctx->estimPI * ctx->implicant_words * sizeof(int), p_implicants_pos, &rc);
|
2025-03-25 23:03:40 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
/* __global const unsigned int *p_implicants_val, IN: RC */
|
|
|
|
ctx->p_implicants_val = clCreateBuffer(ctx->clctx->ctx,
|
2025-03-28 19:05:33 +02:00
|
|
|
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
|
|
|
ctx->estimPI * ctx->implicant_words * sizeof(int), p_implicants_val, &rc);
|
2025-03-25 23:03:40 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
/* __global const int *last_index, IN: RC */
|
|
|
|
ctx->last_index = clCreateBuffer(ctx->clctx->ctx,
|
2025-03-28 19:05:33 +02:00
|
|
|
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
|
|
|
ctx->posrows * sizeof(int), last_index, &rc);
|
2025-03-25 23:03:40 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
/* __global const int *p_covered, IN: RC */
|
|
|
|
ctx->p_covered = clCreateBuffer(ctx->clctx->ctx,
|
2025-03-28 19:05:33 +02:00
|
|
|
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
|
|
|
ctx->estimPI * sizeof(int), p_covered, &rc);
|
2025-03-25 23:03:40 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
/* __global const int *p_pichart_pos, IN: RC */
|
|
|
|
ctx->p_pichart_pos = clCreateBuffer(ctx->clctx->ctx,
|
2025-03-28 19:05:33 +02:00
|
|
|
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
|
|
|
ctx->estimPI * ctx->pichart_words * sizeof(int), p_pichart_pos, &rc);
|
2025-03-26 11:34:01 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* OUTPUTS
|
|
|
|
*/
|
|
|
|
|
2025-03-28 19:05:33 +02:00
|
|
|
/* __global bool *redundant, OUT: RW */
|
2025-03-28 23:28:19 +02:00
|
|
|
ctx->redundant = clCreateBuffer(ctx->clctx->ctx, CL_MEM_READ_WRITE,
|
2025-03-30 00:04:12 +02:00
|
|
|
ctx->gws * ctx->posrows * sizeof(bool), NULL, &rc);
|
2025-03-28 19:05:33 +02:00
|
|
|
|
2025-03-26 11:34:01 +02:00
|
|
|
/* __global bool *coverage, OUT: RW */
|
|
|
|
ctx->coverage = clCreateBuffer(ctx->clctx->ctx, CL_MEM_READ_WRITE,
|
2025-03-30 00:04:12 +02:00
|
|
|
ctx->gws * ctx->posrows * ctx->posrows * sizeof(bool), NULL, &rc);
|
2025-03-26 11:34:01 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2025-03-30 00:04:12 +02:00
|
|
|
/* __global int *taskpis, OUT: RW */
|
|
|
|
ctx->taskpis = clCreateBuffer(ctx->clctx->ctx, CL_MEM_READ_WRITE,
|
|
|
|
ctx->gws * sizeof(int), NULL, &rc);
|
|
|
|
|
2025-03-26 11:34:01 +02:00
|
|
|
/* __global unsigned int *fixed_bits, OUT: RW */
|
|
|
|
ctx->fixed_bits = clCreateBuffer(ctx->clctx->ctx, CL_MEM_READ_WRITE,
|
2025-03-30 00:04:12 +02:00
|
|
|
ctx->gws * ctx->posrows * ctx->implicant_words * sizeof(unsigned int), NULL, &rc);
|
2025-03-26 11:34:01 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* __global unsigned int *value_bits, OUT: RW */
|
|
|
|
ctx->value_bits = clCreateBuffer(ctx->clctx->ctx, CL_MEM_READ_WRITE,
|
2025-03-30 00:04:12 +02:00
|
|
|
ctx->gws * ctx->posrows * ctx->implicant_words * sizeof(unsigned int), NULL, &rc);
|
2025-03-25 23:03:40 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2025-03-26 11:34:01 +02:00
|
|
|
/* __global unsigned int *pichart_values, OUT: RW */
|
|
|
|
ctx->pichart_values = clCreateBuffer(ctx->clctx->ctx, CL_MEM_READ_WRITE,
|
2025-03-30 00:04:12 +02:00
|
|
|
ctx->gws * ctx->posrows * ctx->pichart_words * sizeof(unsigned int), NULL, &rc);
|
2025-03-26 11:34:01 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
goto err;
|
|
|
|
}
|
2025-03-25 23:03:40 +02:00
|
|
|
|
2025-03-21 18:52:41 +02:00
|
|
|
err:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2025-03-26 11:34:01 +02:00
|
|
|
int
|
|
|
|
ccubes_run(struct ccubes_context *ctx)
|
2025-03-21 18:52:41 +02:00
|
|
|
{
|
2025-03-26 11:34:01 +02:00
|
|
|
int rc = 0;
|
|
|
|
int arg = 0;
|
2025-03-21 18:52:41 +02:00
|
|
|
|
2025-03-25 23:03:40 +02:00
|
|
|
/* INPUTS */
|
2025-03-26 11:34:01 +02:00
|
|
|
arg = 0;
|
|
|
|
rc |= clSetKernelArg(ctx->ccubes_task, arg++,
|
2025-03-28 19:05:33 +02:00
|
|
|
sizeof(int), (void *)&ctx->k);
|
2025-03-30 00:04:12 +02:00
|
|
|
rc |= clSetKernelArg(ctx->ccubes_task, arg++,
|
|
|
|
sizeof(int), (void *)&ctx->prevfoundPI);
|
2025-03-26 11:34:01 +02:00
|
|
|
|
2025-03-26 15:51:20 +02:00
|
|
|
rc |= clSetKernelArg(ctx->ccubes_task, arg++,
|
2025-03-28 19:05:33 +02:00
|
|
|
sizeof(cl_mem), (void *)&ctx->nofvalues);
|
2025-03-26 11:34:01 +02:00
|
|
|
rc |= clSetKernelArg(ctx->ccubes_task, arg++,
|
2025-03-28 19:05:33 +02:00
|
|
|
sizeof(cl_mem), (void *)&ctx->ON_set);
|
2025-03-26 11:34:01 +02:00
|
|
|
rc |= clSetKernelArg(ctx->ccubes_task, arg++,
|
2025-03-28 19:05:33 +02:00
|
|
|
sizeof(cl_mem), (void *)&ctx->OFF_set);
|
2025-03-26 11:34:01 +02:00
|
|
|
rc |= clSetKernelArg(ctx->ccubes_task, arg++,
|
2025-03-28 19:05:33 +02:00
|
|
|
sizeof(cl_mem), (void *)&ctx->p_implicants_pos);
|
2025-03-26 11:34:01 +02:00
|
|
|
rc |= clSetKernelArg(ctx->ccubes_task, arg++,
|
2025-03-28 19:05:33 +02:00
|
|
|
sizeof(cl_mem), (void *)&ctx->p_implicants_val);
|
2025-03-26 11:34:01 +02:00
|
|
|
rc |= clSetKernelArg(ctx->ccubes_task, arg++,
|
2025-03-28 19:05:33 +02:00
|
|
|
sizeof(cl_mem), (void *)&ctx->last_index);
|
2025-03-26 11:34:01 +02:00
|
|
|
rc |= clSetKernelArg(ctx->ccubes_task, arg++,
|
2025-03-28 19:05:33 +02:00
|
|
|
sizeof(cl_mem), (void *)&ctx->p_covered);
|
2025-03-26 11:34:01 +02:00
|
|
|
rc |= clSetKernelArg(ctx->ccubes_task, arg++,
|
2025-03-28 19:05:33 +02:00
|
|
|
sizeof(cl_mem), (void *)&ctx->p_pichart_pos);
|
2025-03-25 23:03:40 +02:00
|
|
|
|
|
|
|
/* OUTPUTS */
|
2025-03-28 23:28:19 +02:00
|
|
|
rc |= clSetKernelArg(ctx->ccubes_task, arg++,
|
|
|
|
sizeof(cl_mem), (void *)&ctx->redundant);
|
2025-03-26 11:34:01 +02:00
|
|
|
rc |= clSetKernelArg(ctx->ccubes_task, arg++,
|
2025-03-28 19:05:33 +02:00
|
|
|
sizeof(cl_mem), (void *)&ctx->coverage);
|
2025-03-30 00:04:12 +02:00
|
|
|
rc |= clSetKernelArg(ctx->ccubes_task, arg++,
|
|
|
|
sizeof(cl_mem), (void *)&ctx->taskpis);
|
2025-03-26 11:34:01 +02:00
|
|
|
rc |= clSetKernelArg(ctx->ccubes_task, arg++,
|
2025-03-28 19:05:33 +02:00
|
|
|
sizeof(cl_mem), (void *)&ctx->fixed_bits);
|
2025-03-26 11:34:01 +02:00
|
|
|
rc |= clSetKernelArg(ctx->ccubes_task, arg++,
|
2025-03-28 19:05:33 +02:00
|
|
|
sizeof(cl_mem), (void *)&ctx->value_bits);
|
2025-03-26 11:34:01 +02:00
|
|
|
rc |= clSetKernelArg(ctx->ccubes_task, arg++,
|
2025-03-28 19:05:33 +02:00
|
|
|
sizeof(cl_mem), (void *)&ctx->pichart_values);
|
2025-03-26 11:34:01 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
log_error("clccubes", "Kernel arguments failed (%d)", rc);
|
|
|
|
goto err;
|
|
|
|
}
|
2025-03-25 23:03:40 +02:00
|
|
|
|
2025-03-27 19:57:16 +02:00
|
|
|
cl_event event;
|
|
|
|
log_debug("clccubes", "NDRange gws %d, goff %d", ctx->gws, ctx-> goff);
|
2025-03-26 11:34:01 +02:00
|
|
|
rc = clEnqueueNDRangeKernel(ctx->clctx->gpu_queue, ctx->ccubes_task,
|
2025-03-28 19:05:33 +02:00
|
|
|
1, &ctx->goff, &ctx->gws, NULL,
|
|
|
|
0, NULL, &event);
|
2025-03-26 11:34:01 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
log_error("clccubes", "NDRange failed (%d)", rc);
|
|
|
|
goto err;
|
|
|
|
}
|
2025-03-27 19:57:16 +02:00
|
|
|
clWaitForEvents(1, &event);
|
2025-03-26 11:34:01 +02:00
|
|
|
|
|
|
|
err:
|
|
|
|
return rc;
|
2025-03-21 18:52:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2025-03-26 11:34:01 +02:00
|
|
|
ccubes_map(struct ccubes_context *ctx)
|
2025-03-21 18:52:41 +02:00
|
|
|
{
|
2025-03-26 11:34:01 +02:00
|
|
|
int rc = 0;
|
|
|
|
|
2025-03-28 23:28:19 +02:00
|
|
|
ctx->h_redundant = clEnqueueMapBuffer(ctx->clctx->gpu_queue,
|
|
|
|
ctx->redundant, CL_TRUE, CL_MAP_READ, 0,
|
2025-03-30 00:04:12 +02:00
|
|
|
ctx->gws * ctx->posrows * sizeof(bool), 0, NULL, NULL, &rc);
|
2025-03-28 23:28:19 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
log_error("clccubes", "redundant mapping failed (%d)", rc);
|
|
|
|
goto err;
|
|
|
|
}
|
2025-03-26 11:34:01 +02:00
|
|
|
ctx->h_coverage = clEnqueueMapBuffer(ctx->clctx->gpu_queue,
|
2025-03-28 19:05:33 +02:00
|
|
|
ctx->coverage, CL_TRUE, CL_MAP_READ, 0,
|
2025-03-30 00:04:12 +02:00
|
|
|
ctx->gws * ctx->posrows * ctx->posrows * sizeof(bool), 0, NULL, NULL, &rc);
|
2025-03-26 11:34:01 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
log_error("clccubes", "coverage mapping failed (%d)", rc);
|
|
|
|
goto err;
|
|
|
|
}
|
2025-03-30 00:04:12 +02:00
|
|
|
ctx->h_taskpis = clEnqueueMapBuffer(ctx->clctx->gpu_queue,
|
|
|
|
ctx->taskpis, CL_TRUE, CL_MAP_READ, 0,
|
|
|
|
ctx->gws * sizeof(int), 0, NULL, NULL, &rc);
|
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
log_error("clccubes", "taskpis mapping failed (%d)", rc);
|
|
|
|
goto err;
|
|
|
|
}
|
2025-03-26 11:34:01 +02:00
|
|
|
ctx->h_fixed_bits = clEnqueueMapBuffer(ctx->clctx->gpu_queue,
|
2025-03-28 19:05:33 +02:00
|
|
|
ctx->fixed_bits, CL_TRUE, CL_MAP_READ, 0,
|
2025-03-30 00:04:12 +02:00
|
|
|
ctx->gws * ctx->posrows * ctx->implicant_words * sizeof(unsigned int),
|
2025-03-28 19:05:33 +02:00
|
|
|
0, NULL, NULL, &rc);
|
2025-03-26 11:34:01 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
log_error("clccubes", "fixed_bits mapping failed (%d)", rc);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
ctx->h_value_bits = clEnqueueMapBuffer(ctx->clctx->gpu_queue,
|
2025-03-28 19:05:33 +02:00
|
|
|
ctx->value_bits, CL_TRUE, CL_MAP_READ, 0,
|
2025-03-30 00:04:12 +02:00
|
|
|
ctx->gws * ctx->posrows * ctx->implicant_words * sizeof(unsigned int),
|
2025-03-28 19:05:33 +02:00
|
|
|
0, NULL, NULL, &rc);
|
2025-03-26 11:34:01 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
log_error("clccubes", "value_bits mapping failed (%d)", rc);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
ctx->h_pichart_values = clEnqueueMapBuffer(ctx->clctx->gpu_queue,
|
2025-03-28 19:05:33 +02:00
|
|
|
ctx->pichart_values, CL_TRUE, CL_MAP_READ, 0,
|
2025-03-30 00:04:12 +02:00
|
|
|
ctx->gws * ctx->posrows * ctx->pichart_words * sizeof(unsigned int),
|
2025-03-28 19:05:33 +02:00
|
|
|
0, NULL, NULL, &rc);
|
2025-03-26 11:34:01 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
log_error("clccubes", "pichart_values mapping failed (%d)", rc);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
err:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2025-03-26 11:41:28 +02:00
|
|
|
int
|
2025-03-26 11:34:01 +02:00
|
|
|
ccubes_unmap(struct ccubes_context *ctx)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* UNMAP
|
|
|
|
*/
|
2025-03-28 23:28:19 +02:00
|
|
|
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);
|
|
|
|
}
|
2025-03-26 11:34:01 +02:00
|
|
|
rc = clEnqueueUnmapMemObject(ctx->clctx->gpu_queue, ctx->coverage,
|
2025-03-28 19:05:33 +02:00
|
|
|
ctx->h_coverage, 0, NULL, NULL);
|
2025-03-26 11:34:01 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
log_error("clccubes", "coverage unmapping failed (%d)", rc);
|
|
|
|
}
|
2025-03-30 00:04:12 +02:00
|
|
|
rc = clEnqueueUnmapMemObject(ctx->clctx->gpu_queue, ctx->taskpis,
|
|
|
|
ctx->h_taskpis, 0, NULL, NULL);
|
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
log_error("clccubes", "taskpis unmapping failed (%d)", rc);
|
|
|
|
}
|
2025-03-26 11:34:01 +02:00
|
|
|
rc = clEnqueueUnmapMemObject(ctx->clctx->gpu_queue, ctx->fixed_bits,
|
2025-03-28 19:05:33 +02:00
|
|
|
ctx->h_fixed_bits, 0, NULL, NULL);
|
2025-03-26 11:34:01 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
log_error("clccubes", "fixed_bits unmapping failed (%d)", rc);
|
|
|
|
}
|
|
|
|
rc = clEnqueueUnmapMemObject(ctx->clctx->gpu_queue, ctx->value_bits,
|
2025-03-28 19:05:33 +02:00
|
|
|
ctx->h_value_bits, 0, NULL, NULL);
|
2025-03-26 11:34:01 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
log_error("clccubes", "value_bits unmapping failed (%d)", rc);
|
|
|
|
}
|
|
|
|
rc = clEnqueueUnmapMemObject(ctx->clctx->gpu_queue, ctx->pichart_values,
|
2025-03-28 19:05:33 +02:00
|
|
|
ctx->h_pichart_values, 0, NULL, NULL);
|
2025-03-26 11:34:01 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
log_error("clccubes", "pichart_values unmapping failed (%d)", rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
err:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2025-03-27 20:42:49 +02:00
|
|
|
int
|
|
|
|
ccubes_do_tasks(struct ccubes_context *ccubesctx,
|
|
|
|
int n_tasks,
|
2025-03-26 12:59:48 +02:00
|
|
|
int n_tasks_off,
|
|
|
|
int k,
|
2025-03-30 00:04:12 +02:00
|
|
|
int prevfoundPI,
|
2025-03-26 11:34:01 +02:00
|
|
|
int ninputs,
|
|
|
|
int posrows,
|
|
|
|
int negrows,
|
|
|
|
int implicant_words,
|
|
|
|
int value_bit_width,
|
2025-03-28 02:23:36 +02:00
|
|
|
int value_bit_mask,
|
2025-03-26 11:34:01 +02:00
|
|
|
int pichart_words,
|
|
|
|
int estimPI,
|
2025-03-26 15:15:57 +02:00
|
|
|
int *nofvalues, /* IN: RC */
|
|
|
|
int *ON_set, /* IN: RC */
|
|
|
|
int *OFF_set, /* IN: RC */
|
2025-03-26 11:41:28 +02:00
|
|
|
unsigned int *p_implicants_pos, /* IN: RC */
|
|
|
|
unsigned int *p_implicants_val, /* IN: RC */
|
|
|
|
int *last_index, /* IN: RC */
|
|
|
|
int *p_covered, /* IN: RC */
|
|
|
|
int *p_pichart_pos, /* IN: RC */
|
2025-03-28 23:28:19 +02:00
|
|
|
bool *redundant, /* OUT: RW */
|
2025-03-26 11:41:28 +02:00
|
|
|
bool *coverage, /* OUT: RW */
|
2025-03-30 00:04:12 +02:00
|
|
|
int *taskpis, /* OUT: RW */
|
2025-03-26 11:41:28 +02:00
|
|
|
unsigned int *fixed_bits, /* OUT: RW */
|
|
|
|
unsigned int *value_bits, /* OUT: RW */
|
|
|
|
unsigned int *pichart_values /* OUT: RW */
|
2025-03-26 11:34:01 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
2025-03-21 18:52:41 +02:00
|
|
|
|
2025-03-27 20:42:49 +02:00
|
|
|
rc = ccubes_init(ccubesctx,
|
2025-03-28 19:05:33 +02:00
|
|
|
n_tasks,
|
|
|
|
n_tasks_off,
|
|
|
|
k,
|
2025-03-30 00:04:12 +02:00
|
|
|
prevfoundPI,
|
2025-03-28 19:05:33 +02:00
|
|
|
ninputs,
|
|
|
|
posrows,
|
|
|
|
negrows,
|
|
|
|
implicant_words,
|
|
|
|
value_bit_width,
|
|
|
|
value_bit_mask,
|
|
|
|
pichart_words,
|
|
|
|
estimPI);
|
2025-03-27 10:46:18 +02:00
|
|
|
if (ccubesctx == NULL) {
|
2025-03-26 11:34:01 +02:00
|
|
|
log_error("clccubes", "ccubes_init failed (%d)", rc);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2025-03-27 10:46:18 +02:00
|
|
|
rc = ccubes_preprocess(ccubesctx);
|
2025-03-26 11:34:01 +02:00
|
|
|
if (rc != 0) {
|
|
|
|
log_error("clccubes", "ccubes_preprocess failed (%d)", rc);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2025-03-27 10:46:18 +02:00
|
|
|
rc = ccubes_build(ccubesctx);
|
2025-03-26 11:34:01 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
log_error("clccubes", "ccubes_build failed (%d)", rc);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2025-03-27 10:46:18 +02:00
|
|
|
rc = ccubes_alloc(ccubesctx,
|
2025-03-28 19:05:33 +02:00
|
|
|
nofvalues,
|
|
|
|
ON_set,
|
|
|
|
OFF_set,
|
|
|
|
p_implicants_pos,
|
|
|
|
p_implicants_val,
|
|
|
|
last_index,
|
|
|
|
p_covered,
|
|
|
|
p_pichart_pos,
|
2025-03-28 23:28:19 +02:00
|
|
|
redundant,
|
2025-03-28 19:05:33 +02:00
|
|
|
coverage,
|
2025-03-30 00:04:12 +02:00
|
|
|
taskpis,
|
2025-03-28 19:05:33 +02:00
|
|
|
fixed_bits,
|
|
|
|
value_bits,
|
|
|
|
pichart_values);
|
2025-03-26 11:34:01 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
log_error("clccubes", "ccubes_alloc failed (%d)", rc);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2025-03-27 10:46:18 +02:00
|
|
|
rc = ccubes_run(ccubesctx);
|
2025-03-26 11:34:01 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
log_error("clccubes", "ccubes_run failed (%d)", rc);
|
|
|
|
goto err;
|
|
|
|
}
|
2025-03-21 18:52:41 +02:00
|
|
|
|
2025-03-27 10:46:18 +02:00
|
|
|
rc = ccubes_map(ccubesctx);
|
2025-03-26 11:34:01 +02:00
|
|
|
if (rc != CL_SUCCESS) {
|
|
|
|
log_error("clccubes", "ccubes_map failed (%d)", rc);
|
|
|
|
goto err;
|
|
|
|
}
|
2025-03-21 18:52:41 +02:00
|
|
|
err:
|
2025-03-27 20:42:49 +02:00
|
|
|
return rc;
|
2025-03-21 18:52:41 +02:00
|
|
|
}
|
2025-03-26 11:34:01 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
ccubes_clean_up(struct ccubes_context *ctx)
|
|
|
|
{
|
|
|
|
clReleaseProgram(ctx->ccubes_program);
|
2025-03-27 20:24:32 +02:00
|
|
|
log_debug("clccubes", "clReleaseProgram ccubes_program");
|
2025-03-26 11:34:01 +02:00
|
|
|
|
|
|
|
ccubes_unmap(ctx);
|
2025-03-27 20:24:32 +02:00
|
|
|
log_debug("clccubes", "ccubes_unmap");
|
2025-03-26 11:34:01 +02:00
|
|
|
|
|
|
|
/* INPUTS */
|
|
|
|
clReleaseMemObject(ctx->nofvalues);
|
|
|
|
clReleaseMemObject(ctx->ON_set);
|
|
|
|
clReleaseMemObject(ctx->OFF_set);
|
|
|
|
clReleaseMemObject(ctx->p_implicants_pos);
|
|
|
|
clReleaseMemObject(ctx->p_implicants_val);
|
|
|
|
clReleaseMemObject(ctx->last_index);
|
|
|
|
clReleaseMemObject(ctx->p_covered);
|
|
|
|
clReleaseMemObject(ctx->p_pichart_pos);
|
2025-03-27 20:24:32 +02:00
|
|
|
log_debug("clccubes", "clReleaseMemObject INPUTS");
|
2025-03-26 11:34:01 +02:00
|
|
|
|
|
|
|
/* OUTPUTS */
|
2025-03-28 23:28:19 +02:00
|
|
|
clReleaseMemObject(ctx->redundant);
|
2025-03-26 11:34:01 +02:00
|
|
|
clReleaseMemObject(ctx->coverage);
|
2025-03-30 00:04:12 +02:00
|
|
|
clReleaseMemObject(ctx->taskpis);
|
2025-03-26 11:34:01 +02:00
|
|
|
clReleaseMemObject(ctx->fixed_bits);
|
|
|
|
clReleaseMemObject(ctx->value_bits);
|
|
|
|
clReleaseMemObject(ctx->pichart_values);
|
2025-03-27 20:24:32 +02:00
|
|
|
log_debug("clccubes", "clReleaseMemObject OUTPUTS");
|
2025-03-26 11:34:01 +02:00
|
|
|
|
2025-03-27 20:42:49 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ccubes_destroy(struct ccubes_context *ctx)
|
|
|
|
{
|
2025-03-26 11:34:01 +02:00
|
|
|
cl_clean_up(*ctx->clctx);
|
2025-03-27 20:24:32 +02:00
|
|
|
log_debug("clccubes", "cl_clean_up");
|
|
|
|
|
2025-03-29 16:43:15 +02:00
|
|
|
free(ctx->ccubes_kernel_file);
|
|
|
|
|
2025-03-27 20:24:32 +02:00
|
|
|
free(ctx);
|
2025-03-26 11:34:01 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|