From 5fc7e0034190c64dc1ab7dd43a9093b1a5438ece Mon Sep 17 00:00:00 2001 From: Paul Irofti Date: Fri, 21 Mar 2025 18:52:41 +0200 Subject: [PATCH] move to clccubes --- clccubes.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++ clccubes.h | 3 +++ test_ccubes.c | 31 +---------------------- 3 files changed, 73 insertions(+), 30 deletions(-) create mode 100644 clccubes.c diff --git a/clccubes.c b/clccubes.c new file mode 100644 index 0000000..ed3a2f4 --- /dev/null +++ b/clccubes.c @@ -0,0 +1,69 @@ +#include +#include + +#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; + } + +err: + return rc; +} + +void +ccubes_clean_up(struct ccubes_context *ctx) +{ + cl_clean_up(*ctx->clctx); + + clReleaseProgram(ctx->ccubes_program); + + return; +} + +int +ccubes() +{ + struct ccubes_context ccubesctx; + + ccubes_build(&ccubesctx); + +err: + ccubes_clean_up(&ccubesctx); +} diff --git a/clccubes.h b/clccubes.h index 9234044..abb7ac3 100644 --- a/clccubes.h +++ b/clccubes.h @@ -15,9 +15,12 @@ struct ccubes_context { struct cl_uctx *clctx; + cl_program ccubes_program; cl_kernel ccubes_task; }; +int ccubes(void); + int clccubes(struct ccubes_context *ccubesctx, cl_mem alpha0, cl_mem G, size_t signals, size_t atoms, uint32_t sparsity, uint32_t pcoding, cl_mem gamma, cl_uint diff --git a/test_ccubes.c b/test_ccubes.c index 66f8d22..11f7c78 100644 --- a/test_ccubes.c +++ b/test_ccubes.c @@ -99,36 +99,7 @@ int main(int argc, char *argv[]) log_debug("test", "Starting ccubes..."); - /* - * CCubes - */ - ccubesctx.clctx = malloc(sizeof *ccubesctx.clctx); - - ccubesctx.clctx->device_type = CL_DEVICE_TYPE_GPU; - strcpy(ccubesctx.clctx->platform_name, "NVIDIA Corporation\0"); - /* strcpy(ccubesctx.clctx->platform_name, "Advanced Micro Devices, Inc.\0"); */ - /*strcpy(ccubesctx.clctx->platform_name, "Intel(R) Corporation\0");*/ - rc = cl_init(ccubesctx.clctx); - if (rc != CL_SUCCESS) { - printf("[%d] Failed to initialize the OpenCL framework\n", - rc); - goto err; - } - - - rc = cl_build(*ccubesctx.clctx, CL_DEVICE_TYPE_GPU, - "ccubes.cl", &ccubes_program); - if (rc != CL_SUCCESS) { - log_warn("test", "Failed building ccubes.cl (%d)", rc); - goto err; - } - - rc = cl_get_kern(ccubes_program, "ccubes_task", - &ccubesctx.ccubes_task); - if (rc != CL_SUCCESS) { - log_warn("test", "Failed fetching ccubes_task (%d)", rc); - goto err; - } + ccubes(); fflush(stdout); err: