147 lines
3.6 KiB
C
147 lines
3.6 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include "real.h"
|
|
#include "cl_setup.h"
|
|
|
|
#include "clccubes.h"
|
|
|
|
#include "config.h"
|
|
#include "logging.h"
|
|
|
|
|
|
int
|
|
ccubes_build(struct ccubes_context *ctx)
|
|
{
|
|
int rc = 0;
|
|
|
|
ctx->clctx = malloc(sizeof *ctx->clctx);
|
|
|
|
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,
|
|
"ccubes.cl", &ctx->ccubes_program);
|
|
if (rc != CL_SUCCESS) {
|
|
log_warn("test", "Failed building ccubes.cl (%d)", rc);
|
|
goto err;
|
|
}
|
|
|
|
rc = cl_get_kern(ctx->ccubes_program, "ccubes_task",
|
|
&ctx->ccubes_task);
|
|
if (rc != CL_SUCCESS) {
|
|
log_warn("test", "Failed fetching ccubes_task (%d)", rc);
|
|
goto err;
|
|
}
|
|
|
|
/*
|
|
* INPUTS
|
|
*/
|
|
|
|
/* __global const real *nofvalues, IN: RC */
|
|
ctx->nofvalues = clCreateBuffer(ctx->clctx->ctx,
|
|
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
|
NINPUTS * sizeof(real), nofvalues, &rc);
|
|
if (rc != CL_SUCCESS) {
|
|
goto err;
|
|
}
|
|
/* __global const real *ON_set, IN: RC */
|
|
ctx->ON_set = clCreateBuffer(ctx->clctx->ctx,
|
|
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
|
POSROWS * NINPUTS * sizeof(real), ON_set, &rc);
|
|
if (rc != CL_SUCCESS) {
|
|
goto err;
|
|
}
|
|
/* __global const real *OFF_set, IN: RC */
|
|
ctx->OFF_set = clCreateBuffer(ctx->clctx->ctx,
|
|
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
|
NINPUTS * NEGROWS * sizeof(real), OFF_set, &rc);
|
|
if (rc != CL_SUCCESS) {
|
|
goto err;
|
|
}
|
|
/* __global const unsigned int *p_implicants_pos, IN: RC */
|
|
ctx->p_implicants_pos = clCreateBuffer(ctx->clctx->ctx,
|
|
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
|
estimPI * IMPLICANT_WORDS * sizeof(int), p_implicants_pos, &rc);
|
|
if (rc != CL_SUCCESS) {
|
|
goto err;
|
|
}
|
|
/* __global const unsigned int *p_implicants_val, IN: RC */
|
|
ctx->p_implicants_val = clCreateBuffer(ctx->clctx->ctx,
|
|
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
|
estimPI * IMPLICANT_WORDS * sizeof(int), p_implicants_val, &rc);
|
|
if (rc != CL_SUCCESS) {
|
|
goto err;
|
|
}
|
|
/* __global const int *last_index, IN: RC */
|
|
ctx->last_index = clCreateBuffer(ctx->clctx->ctx,
|
|
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
|
POSROWS * sizeof(int), last_index, &rc);
|
|
if (rc != CL_SUCCESS) {
|
|
goto err;
|
|
}
|
|
/* __global const int *p_covered, IN: RC */
|
|
ctx->p_covered = clCreateBuffer(ctx->clctx->ctx,
|
|
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
|
estimPI * sizeof(int), p_covered, &rc);
|
|
if (rc != CL_SUCCESS) {
|
|
goto err;
|
|
}
|
|
/* __global const int *p_pichart_pos, IN: RC */
|
|
ctx->p_pichart_pos = clCreateBuffer(ctx->clctx->ctx,
|
|
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
|
estimPI * PICHART_WORDS * sizeof(int), p_pichart_pos, &rc);
|
|
if (rc != CL_SUCCESS) {
|
|
goto err;
|
|
}
|
|
|
|
|
|
err:
|
|
return rc;
|
|
}
|
|
|
|
void
|
|
ccubes_clean_up(struct ccubes_context *ctx)
|
|
{
|
|
cl_clean_up(*ctx->clctx);
|
|
|
|
clReleaseProgram(ctx->ccubes_program);
|
|
|
|
/* INPUTS */
|
|
clReleaseMemObject(ctx->nofvalues);
|
|
clReleaseMemObject(ON_set);
|
|
clReleaseMemObject(OFF_set);
|
|
clReleaseMemObject(p_implicants_pos);
|
|
clReleaseMemObject(p_implicants_val);
|
|
clReleaseMemObject(last_index);
|
|
clReleaseMemObject(p_covered);
|
|
clReleaseMemObject(p_pichart_pos);
|
|
|
|
/* OUTPUTS */
|
|
clReleaseMemObject(coverage);
|
|
clReleaseMemObject(fixed_bits);
|
|
clReleaseMemObject(value_bits);
|
|
clReleaseMemObject(pichart_values);
|
|
|
|
return;
|
|
}
|
|
|
|
int
|
|
ccubes()
|
|
{
|
|
struct ccubes_context ccubesctx;
|
|
|
|
ccubes_build(&ccubesctx);
|
|
|
|
err:
|
|
ccubes_clean_up(&ccubesctx);
|
|
}
|