From 9fa5f520b55930ec11b40d0fcc2ce45c09a4eefc Mon Sep 17 00:00:00 2001 From: Paul Irofti Date: Sat, 29 Mar 2025 16:43:15 +0200 Subject: [PATCH] Get the kernel from R path --- src/CCubes.c | 4 +++- src/clccubes.c | 19 +++++++++++++++++-- src/clccubes.h | 1 + 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/CCubes.c b/src/CCubes.c index 75da440..a55cded 100755 --- a/src/CCubes.c +++ b/src/CCubes.c @@ -26,6 +26,7 @@ SEXP CCubes(SEXP tt) { // simulate the R command: // system.file("ccubes.cl", package = "IEEE") + const char *kernel_file = NULL; SEXP args = PROTECT(allocVector(VECSXP, 2)); SET_VECTOR_ELT(args, 0, mkString("ccubes.cl")); SET_VECTOR_ELT(args, 1, mkString("IEEE")); @@ -41,6 +42,7 @@ SEXP CCubes(SEXP tt) { )); Rprintf("Kernel file: '%s'\n", CHAR(STRING_ELT(r_result, 0))); + kernel_file = CHAR(STRING_ELT(r_result, 0)); UNPROTECT(3); // 32 bits per word, in bit shifting representation @@ -73,7 +75,7 @@ SEXP CCubes(SEXP tt) { sprintf(log, "log-ccubes"); config_set_string("out", log); - struct ccubes_context *ctx = ccubes_create(); + struct ccubes_context *ctx = ccubes_create(kernel_file); if (ctx == NULL) { log_error("ccubes", "ccubes_do_tasks failed"); } diff --git a/src/clccubes.c b/src/clccubes.c index c016a92..f161b6d 100755 --- a/src/clccubes.c +++ b/src/clccubes.c @@ -27,7 +27,7 @@ struct ccubes_context * -ccubes_create() +ccubes_create(char *ccubes_kernel_file) { struct ccubes_context *ctx = NULL; int rc = 0; @@ -56,6 +56,19 @@ ccubes_create() goto err; } + 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; + } + err: return ctx; } @@ -134,7 +147,7 @@ ccubes_build(struct ccubes_context *ctx) rc = cl_build(*ctx->clctx, CL_DEVICE_TYPE_GPU, - "ccubes.cl", &ctx->ccubes_program); + ctx->ccubes_kernel_file, &ctx->ccubes_program); if (rc != CL_SUCCESS) { log_warn("clccubes", "Failed building ccubes.cl (%d)", rc); goto err; @@ -555,6 +568,8 @@ ccubes_destroy(struct ccubes_context *ctx) cl_clean_up(*ctx->clctx); log_debug("clccubes", "cl_clean_up"); + free(ctx->ccubes_kernel_file); + free(ctx); return; diff --git a/src/clccubes.h b/src/clccubes.h index dfda26d..9296c58 100755 --- a/src/clccubes.h +++ b/src/clccubes.h @@ -33,6 +33,7 @@ struct ccubes_context { struct cl_uctx *clctx; + char *ccubes_kernel_file; cl_program ccubes_program; cl_kernel ccubes_task;