# function wrappers and calling sequence for accelerated kernel evaluations in R # with external C code using CPU and GPU # Sergey V. 2022 # preload static object file dyn.load("cuda1R.so") printf <- function(...)print(sprintf(...)) # define R functions for cpu and gpu wrappers kfunc_kernel.cpu <- function(x1, x2, a, b, c, kname) { rst <- .Call("kfunc_kernel_cpu", x1, x2, a, b, c, kname ) return(rst) } kfunc_kernel.gpu <- function(x1, x2, a, b, c, kname, devID=0L) { rst <- .Call("kfunc_kernel_gpu", x1, x2, a, b, c, kname, as.integer(devID) ) return(rst) } printf("Test kfunc_exp\n"); load('xdata1.RData'); x1 = runif(350,min=-5,max=5); x2 = runif(75, min=-4,max=4); printf("len(x1) = %d, len(x2) = %d\n", length(x1), length(x2)); S1 = kfunc_kernel.cpu(x1,x2,1,1,1,'exp'); print(dim(S1)); S2 = kfunc_kernel.cpu(x1,x2,1,1,1,'matern'); print(dim(S2)); printf("Test kfunc_exp gpu\n"); S1g = kfunc_kernel.gpu(x1,x2,1,1,1,'exp'); printf("Print cpu/gpu norms\n"); norm(S1) norm(S1g)