Rebuild only when necessary.

This commit is contained in:
Paul Irofti 2025-03-30 16:30:36 +03:00
parent 0c46ec57fe
commit 76c637a64a
4 changed files with 17 additions and 7 deletions

View file

@ -205,7 +205,7 @@ SEXP CCubes(SEXP tt) {
config_set_int("log", LOG_LEVEL_WARN); config_set_int("log", LOG_LEVEL_WARN);
config_set_int("log:clccubes", LOG_LEVEL_DEBUG); config_set_int("log:clccubes", LOG_LEVEL_DEBUG);
config_set_int("log:ccubes", LOG_LEVEL_DEBUG); config_set_int("log:ccubes", LOG_LEVEL_DEBUG);
config_set_int("log:cl", LOG_LEVEL_DEBUG); config_set_int("log:cl", LOG_LEVEL_WARN);
char log[100] = {0}; char log[100] = {0};
sprintf(log, "log-ccubes"); sprintf(log, "log-ccubes");
@ -357,6 +357,7 @@ SEXP CCubes(SEXP tt) {
// when needed, increase allocated memory // when needed, increase allocated memory
if (foundPI / estimPI > 0.9) { if (foundPI / estimPI > 0.9) {
ctx->rebuild = 1;
estimPI += 100000; estimPI += 100000;
p_pichart = R_Realloc(p_pichart, posrows * estimPI, int); p_pichart = R_Realloc(p_pichart, posrows * estimPI, int);
p_pichart_pos = R_Realloc(p_pichart_pos, pichart_words * estimPI, unsigned int); p_pichart_pos = R_Realloc(p_pichart_pos, pichart_words * estimPI, unsigned int);

View file

@ -21,7 +21,10 @@
#include "logging.h" #include "logging.h"
#include "cl_setup.h" #include "cl_setup.h"
#if 0
#define CL_DEBUG #define CL_DEBUG
#endif
cl_int cl_int
cl_init(struct cl_uctx *puctx) cl_init(struct cl_uctx *puctx)

View file

@ -110,6 +110,7 @@ ccubes_create(const char *ccubes_kernel_file,
ccubes_kernel_file); ccubes_kernel_file);
goto err; goto err;
} }
ctx->rebuild = 1;
ctx->ninputs = ninputs; ctx->ninputs = ninputs;
ctx->posrows = posrows; ctx->posrows = posrows;
@ -192,6 +193,14 @@ ccubes_build(struct ccubes_context *ctx)
{ {
int rc = 0; int rc = 0;
if (ctx->rebuild == 0)
return rc;
rc = ccubes_preprocess(ctx);
if (rc != 0) {
log_error("clccubes", "ccubes_preprocess failed (%d)", rc);
goto err;
}
rc = cl_build(*ctx->clctx, CL_DEVICE_TYPE_GPU, rc = cl_build(*ctx->clctx, CL_DEVICE_TYPE_GPU,
ctx->ccubes_kernel_file, &ctx->ccubes_program); ctx->ccubes_kernel_file, &ctx->ccubes_program);
@ -207,6 +216,8 @@ ccubes_build(struct ccubes_context *ctx)
goto err; goto err;
} }
ctx->rebuild = 0;
err: err:
return rc; return rc;
} }
@ -524,12 +535,6 @@ ccubes_do_tasks(struct ccubes_context *ccubesctx,
goto err; goto err;
} }
rc = ccubes_preprocess(ccubesctx);
if (rc != 0) {
log_error("clccubes", "ccubes_preprocess failed (%d)", rc);
goto err;
}
rc = ccubes_build(ccubesctx); rc = ccubes_build(ccubesctx);
if (rc != CL_SUCCESS) { if (rc != CL_SUCCESS) {
log_error("clccubes", "ccubes_build failed (%d)", rc); log_error("clccubes", "ccubes_build failed (%d)", rc);

View file

@ -33,6 +33,7 @@
struct ccubes_context { struct ccubes_context {
struct cl_uctx *clctx; struct cl_uctx *clctx;
int rebuild;
char *ccubes_kernel_file; char *ccubes_kernel_file;
cl_program ccubes_program; cl_program ccubes_program;
cl_kernel ccubes_task; cl_kernel ccubes_task;