[R-pkg-devel] GPU programming in R packages

Wolfgang Rolke wo||g@ng@ro|ke @end|ng |rom upr@edu
Mon Feb 17 15:55:28 CET 2025


Ivan,

I am working on a package that implements several tests for the multivariate twosample problem. Some of them are based on the distance between the points. Now say the two data sets have 1000 observations each in 10 dimensions. Calculating such a test statistic requires roughly 1000*1000*10=10^7 operations. Now some of them don't come with a p value but one needs to use the permutation methods, say another 1000 times, and we are up to 10^10 operations. Finally one might want to do some power study, and so we need another 10*1000, and are at 10^14. And finally I really want to do 20 or 30 such studies. So it is clear we need something very fast.

Currently I have everything implemented in Rcpp and using parallel programing, but even that is not good enough. So I thought doing the calculation of the pairwise distances using GPU might be worth looking into.

Wolfgang

________________________________
From: Ivan Krylov <ikrylov using disroot.org>
Sent: Monday, February 17, 2025 8:05 AM
To: Wolfgang Rolke via R-package-devel <r-package-devel using r-project.org>
Cc: Wolfgang Rolke <wolfgang.rolke using upr.edu>
Subject: Re: [R-pkg-devel] GPU programming in R packages

� Sun, 16 Feb 2025 13:00:55 +0000
Wolfgang Rolke via R-package-devel <r-package-devel using r-project.org>
�����:

> I am currently working on a project that requires calculations on
> large matrices, for example calculating pairwise distances of points
> in higher dimensions.

How large are the matrices? Are CPU-side calculations (possibly done in
special-purpose parallel code written in C/C++/Fortran/Rust) out of
question? What are your performance goals?

> So my question is, how should I implement a GPU based calculation in
> a package that will eventually be acceptable for CRAN?

How about OpenCL [1]?

Pros:

* The 'OpenCL' package is already on CRAN, making it possible to write
  and run "kernels" straight from R.
* Unlike CUDA, OpenCL is an open standard, relatively portable between
  video card vendors. It is even possible to use a CPU-only
  "installable client driver" that would (probably very slowly) run the
  kernels on the processor when no compatible video card is present.

Cons:

* Additional user setup is required. The OpenCL package will fail to
  load if the OpenCL runtime is not installed; installing it from
  source will also require the OpenCL SDK with headers.
* Your code will also fail to run if OpenCL cannot find a working
  "platform", so any examples and tests will need to check for
  length(oclPlatforms) > 0 [2].

--
Best regards,
Ivan

[1]
https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.khronos.org%2Fopencl%2F&data=05%7C02%7Cwolfgang.rolke%40upr.edu%7Cc85446bf85ee4d7d4e1108dd4f43128b%7C0dfa5dc0036f461599e494af822f2b84%7C0%7C0%7C638753871684927834%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=syu4D2bBFWJPzNKSP1mEE8xua1XZg6MsCOQtILhl%2F9M%3D&reserved=0<https://www.khronos.org/opencl/>

[2]
https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.r-project.org%2Fnosvn%2FR.check%2Fr-release-windows-x86_64%2FOpenCL-00check.html&data=05%7C02%7Cwolfgang.rolke%40upr.edu%7Cc85446bf85ee4d7d4e1108dd4f43128b%7C0dfa5dc0036f461599e494af822f2b84%7C0%7C0%7C638753871684946998%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=YuAKmccy%2Flz8%2Bgcwc5P9ZnDXQscIkVwhstPrxS5v3Ro%3D&reserved=0<https://www.r-project.org/nosvn/R.check/r-release-windows-x86_64/OpenCL-00check.html>

	[[alternative HTML version deleted]]



More information about the R-package-devel mailing list