├── inst ├── doc │ ├── gpuR.pdf │ ├── custom_ocl_gpuR.pdf │ ├── custom_ocl_gpuR.R │ └── gpuR.R ├── testWithGPU │ ├── testthat.R │ └── testthat │ │ ├── test_utils.R │ │ ├── test_gpuMatrix_cov.R │ │ ├── test_vclMatrix_cov.R │ │ ├── test_gpuMatrix_dist.R │ │ ├── test_vclMatrix_dist.R │ │ ├── test_cpu_gpuMatrix_dist.R │ │ ├── test_cpu_vclMatrix_dist.R │ │ ├── test_cpu_gpuMatrix_cov.R │ │ └── test_cpu_vclMatrix_cov.R ├── CL │ ├── dPermute.cl │ ├── iVecSign.cl │ ├── dVecSign.cl │ ├── fVecSign.cl │ ├── iVec_pmax.cl │ ├── iVec_pmin.cl │ ├── dVec_pmax.cl │ ├── dVec_pmin.cl │ ├── fVec_pmax.cl │ ├── fVec_pmin.cl │ ├── iScalarElemDiv.cl │ ├── fScalarElemDiv.cl │ ├── fset_row_order2.cl │ ├── dScalarElemDiv.cl │ ├── iMatSign.cl │ ├── dMatSign.cl │ ├── iMat_pmin.cl │ ├── fMat_pmax.cl │ ├── fMat_pmin.cl │ ├── iMat_pmax.cl │ ├── dMat_pmax.cl │ ├── dMat_pmin.cl │ ├── dset_row_order.cl │ ├── fMatSign.cl │ ├── iScalarAXPY.cl │ ├── fScalarAXPY.cl │ ├── dScalarAXPY.cl │ ├── fset_row_order.cl │ ├── dset_row_order2.cl │ ├── basic_gemm.cl │ ├── dcholesky.cl │ └── fcholesky.cl ├── include │ ├── gpuR │ │ ├── windows_check.hpp │ │ ├── utils.hpp │ │ └── getVCLptr.hpp │ ├── loader │ │ └── Makefile │ └── CL │ │ └── opencl.h ├── src │ └── base_custom_cuda.cpp └── CITATION ├── include ├── loader │ ├── i386 │ │ └── .gitignore │ ├── x64 │ │ └── .gitignore │ └── Makefile ├── gpuR │ ├── windows_check.hpp │ ├── utils.hpp │ └── getVCLptr.hpp └── CL │ └── opencl.h ├── tests ├── testthat.R └── testthat │ ├── test_cpu_shared_memory.R │ ├── test_cpu_gpuMatrix_cov.R │ ├── test_cpu_order.R │ ├── test_custom.R │ ├── test_cpu_vclMatrix_cov.R │ ├── test_gpuMatrix_cov.R │ ├── test_vclMatrix_cov.R │ ├── test_order.R │ ├── test_cpu_gpuMatrix_chol.R │ ├── test_cpu_vclMatrix_chol.R │ ├── test_switch_gpu_vclMatrix_cov.R │ ├── test_gpuMatrix_chol.R │ ├── test_vclMatrix_chol.R │ ├── test_shared_memory.R │ ├── test_utils.R │ ├── test_vclMatrix_qr.R │ ├── test_cpu_vclMatrix_qr.R │ ├── test_cpu_gpuMatrix_qr.R │ ├── test_gpuMatrix_qr.R │ ├── test_cpu_gpuMatrix_svd.R │ ├── test_cpu_vclMatrix_svd.R │ ├── test_gpuMatrix_svd.R │ └── test_vclMatrix_svd.R ├── vignettes ├── gpuR-concordance.tex ├── custom_ocl_gpuR-concordance.tex └── custom_ocl_gpuR.R ├── cleanup ├── .Rbuildignore ├── cleanup.win ├── R ├── classes.R ├── flags.R ├── zzz.R ├── asserts.R ├── print.R ├── wrappers-vclVector.R ├── hello-gpuR.R ├── extract-gpuVector.R └── typeof.R ├── .gitignore ├── man ├── has_cpu_skip.Rd ├── has_gpu_skip.Rd ├── has_double_skip.Rd ├── currentContext.Rd ├── has_multiple_gpu_skip.Rd ├── pocl_check.Rd ├── setContext.Rd ├── has_multiple_double_skip.Rd ├── detectPlatforms.Rd ├── currentPlatform.Rd ├── currentDevice.Rd ├── set_device_context.Rd ├── igpuVector-class.Rd ├── ivclVector-class.Rd ├── dgpuVector-class.Rd ├── dvclVector-class.Rd ├── fgpuVector-class.Rd ├── fvclVector-class.Rd ├── pmax.Rd ├── print.gpuMatrix.Rd ├── detectGPUs.Rd ├── deviceType.Rd ├── fgpuMatrix-class.Rd ├── fvclMatrix-class.Rd ├── dgpuMatrix-class.Rd ├── dvclMatrix-class.Rd ├── detectCPUs.Rd ├── igpuMatrix-class.Rd ├── ivclMatrix-class.Rd ├── cgpuMatrix-class.Rd ├── cvclMatrix-class.Rd ├── zgpuMatrix-class.Rd ├── zvclMatrix-class.Rd ├── synchronize.Rd ├── grapes-o-grapes-methods.Rd ├── t-methods.Rd ├── custom_opencl.Rd ├── dim-methods.Rd ├── permute-methods.Rd ├── platformInfo.Rd ├── as.gpuMatrix-methods.Rd ├── typeof-gpuR-methods.Rd ├── Compare-methods.Rd ├── listContexts.Rd ├── qr.R-methods.Rd ├── deviceHasDouble.Rd ├── det-methods.Rd ├── gpuMatrix.colSums.Rd ├── vclMatrix.colSums.Rd ├── nrow-gpuR.Rd ├── as.gpuVector-methods.Rd ├── identity_matrix.Rd ├── length-methods.Rd ├── assert_has_double.Rd ├── setup_opencl.Rd ├── solve-methods.Rd ├── Math-methods.Rd ├── Summary-methods.Rd ├── colnames-methods.Rd ├── chol-methods.Rd ├── gpuVector-class.Rd ├── vclVector-class.Rd ├── as.vclVector-methods.Rd ├── svd-methods.Rd ├── diag-methods.Rd ├── log-methods.Rd ├── pmin.vclVector.Rd ├── norm-methods.Rd ├── gpuR-deepcopy.Rd ├── gpuVector-methods.Rd ├── gpuR-slice.Rd ├── gpuMatrix-crossprod.Rd ├── qr-methods.Rd ├── gpuMatrix-methods.Rd ├── deviceInfo.Rd ├── gpuR-block.Rd ├── gpuMatrix-class.Rd ├── vclMatrix-methods.Rd ├── dist-vclMatrix.Rd ├── vclMatrix-class.Rd ├── vclVector-methods.Rd ├── eigen-gpuMatrix.Rd ├── cov-methods.Rd ├── gpuR-package.Rd ├── vclMatrix-crossprod.Rd ├── inplace-methods.Rd └── Arith-methods.Rd ├── gpuR.Rproj ├── cran-comments.md ├── src ├── Makevars.win ├── synchronize.cpp └── trunc_gpuMat.cpp ├── INSTALL ├── DESCRIPTION └── appveyor.yml /inst/doc/gpuR.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdeterman/gpuR/HEAD/inst/doc/gpuR.pdf -------------------------------------------------------------------------------- /inst/testWithGPU/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(gpuR) 3 | 4 | test_check("gpuR") 5 | -------------------------------------------------------------------------------- /inst/doc/custom_ocl_gpuR.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdeterman/gpuR/HEAD/inst/doc/custom_ocl_gpuR.pdf -------------------------------------------------------------------------------- /include/loader/i386/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore -------------------------------------------------------------------------------- /include/loader/x64/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | Sys.setenv("R_TESTS" = "") 2 | library(testthat) 3 | library(gpuR) 4 | 5 | test_check("gpuR") 6 | -------------------------------------------------------------------------------- /vignettes/gpuR-concordance.tex: -------------------------------------------------------------------------------- 1 | \Sconcordance{concordance:gpuR.tex:gpuR.Rnw:% 2 | 1 41 1 48 0 1 6 58 1 4 0 19 1 4 0 56 1 3 0 21 1} 3 | -------------------------------------------------------------------------------- /cleanup: -------------------------------------------------------------------------------- 1 | rm -f src/Makevars 2 | rm -f src/*.o 3 | rm -f src/*.so 4 | rm -f src/*.dylib 5 | rm -f src/loader/*.o 6 | rm -f src/loader/*.a 7 | -------------------------------------------------------------------------------- /vignettes/custom_ocl_gpuR-concordance.tex: -------------------------------------------------------------------------------- 1 | \Sconcordance{concordance:custom_ocl_gpuR.tex:custom_ocl_gpuR.Rnw:% 2 | 1 41 1 49 0 1 6 21 1 4 0 30 1 4 0 8 1 4 0 19 1 3 0 2 1} 3 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^\.httr-oauth$ 4 | ^include 5 | ^\.travis\.yml$ 6 | ^appveyor\.yml$ 7 | ^cran-comments\.md$ 8 | ^\.git$ 9 | ^doc$ 10 | ^Meta$ 11 | -------------------------------------------------------------------------------- /cleanup.win: -------------------------------------------------------------------------------- 1 | rm -f src/*.o 2 | rm -f src/*.dll 3 | rm -f inst/include/loader/i386/*.o 4 | rm -f inst/include/loader/x64/*.o 5 | rm -f inst/include/loader/i386/*.a 6 | rm -f inst/include/loader/x64/*.o 7 | -------------------------------------------------------------------------------- /R/classes.R: -------------------------------------------------------------------------------- 1 | 2 | setClassUnion("gpuRmatrix", c("gpuMatrix", "vclMatrix")) 3 | setClassUnion("numericOrInt", c("numeric", "integer")) 4 | 5 | setClass("gpuQR", 6 | slots = c(qr = "gpuRmatrix", betas = "numeric") 7 | ) -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | src/*.o 5 | src/*.a 6 | inst/include/loader/x64 7 | inst/include/loader/i386 8 | inst/include/loader/*.o 9 | inst/include/loader/*.a 10 | *.so 11 | *.dll 12 | src/Makevars 13 | .httr-oauth 14 | doc 15 | Meta 16 | autom4te.cache 17 | config.log 18 | config.status 19 | -------------------------------------------------------------------------------- /inst/CL/dPermute.cl: -------------------------------------------------------------------------------- 1 | __kernel void dVecPermute( 2 | __global const double *A, 3 | __global double *B, 4 | __global const unsigned int *mask) { 5 | 6 | //*B = shuffle(*A, *mask); 7 | 8 | B[globalRow * MdimPad + globalCol] = A[indices[globalRow] * MdimPad + globalCol]; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /man/has_cpu_skip.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/test_utils.R 3 | \name{has_cpu_skip} 4 | \alias{has_cpu_skip} 5 | \title{Skip test for CPUs} 6 | \usage{ 7 | has_cpu_skip() 8 | } 9 | \description{ 10 | Function to skip testthat tests 11 | if no valid CPU's are detected 12 | } 13 | -------------------------------------------------------------------------------- /man/has_gpu_skip.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/test_utils.R 3 | \name{has_gpu_skip} 4 | \alias{has_gpu_skip} 5 | \title{Skip test for GPUs} 6 | \usage{ 7 | has_gpu_skip() 8 | } 9 | \description{ 10 | Function to skip testthat tests 11 | if no valid GPU's are detected 12 | } 13 | -------------------------------------------------------------------------------- /inst/CL/iVecSign.cl: -------------------------------------------------------------------------------- 1 | __kernel void VecSign( 2 | __global int *A, __global int *B, const unsigned int n) { 3 | 4 | // Get the index of the elements to be processed 5 | const int globalRow = get_global_id(0); // C Row ID 6 | 7 | // Do the operation 8 | if(globalRow < n){ 9 | B[globalRow] = sign(A[globalRow]); 10 | } 11 | } -------------------------------------------------------------------------------- /inst/CL/dVecSign.cl: -------------------------------------------------------------------------------- 1 | __kernel void VecSign( 2 | __global double *A, __global double *B, const unsigned int n) { 3 | 4 | // Get the index of the elements to be processed 5 | const int globalRow = get_global_id(0); // C Row ID 6 | 7 | // Do the operation 8 | if(globalRow < n){ 9 | B[globalRow] = sign(A[globalRow]); 10 | } 11 | } -------------------------------------------------------------------------------- /inst/CL/fVecSign.cl: -------------------------------------------------------------------------------- 1 | __kernel void VecSign( 2 | __global float *A, __global float *B, const unsigned int n) { 3 | 4 | // Get the index of the elements to be processed 5 | const int globalRow = get_global_id(0); // C Row ID 6 | 7 | // Do the operation 8 | if(globalRow < n){ 9 | B[globalRow] = sign(A[globalRow]); 10 | } 11 | } -------------------------------------------------------------------------------- /inst/CL/iVec_pmax.cl: -------------------------------------------------------------------------------- 1 | __kernel void pmax( 2 | __global int *A, __global int *B, const int x, const unsigned int n) { 3 | 4 | // Get the index of the elements to be processed 5 | const int globalRow = get_global_id(0); // C Row ID 6 | 7 | // Do the operation 8 | if(globalRow < n){ 9 | B[globalRow] = max(A[globalRow], x); 10 | } 11 | } -------------------------------------------------------------------------------- /inst/CL/iVec_pmin.cl: -------------------------------------------------------------------------------- 1 | __kernel void pmax( 2 | __global int *A, __global int *B, const int x, const unsigned int n) { 3 | 4 | // Get the index of the elements to be processed 5 | const int globalRow = get_global_id(0); // C Row ID 6 | 7 | // Do the operation 8 | if(globalRow < n){ 9 | B[globalRow] = min(A[globalRow], x); 10 | } 11 | } -------------------------------------------------------------------------------- /inst/CL/dVec_pmax.cl: -------------------------------------------------------------------------------- 1 | __kernel void pmax( 2 | __global double *A, __global double *B, const double x, const unsigned int n) { 3 | 4 | // Get the index of the elements to be processed 5 | const int globalRow = get_global_id(0); // C Row ID 6 | 7 | // Do the operation 8 | if(globalRow < n){ 9 | B[globalRow] = max(A[globalRow], x); 10 | } 11 | } -------------------------------------------------------------------------------- /inst/CL/dVec_pmin.cl: -------------------------------------------------------------------------------- 1 | __kernel void pmax( 2 | __global double *A, __global double *B, const double x, const unsigned int n) { 3 | 4 | // Get the index of the elements to be processed 5 | const int globalRow = get_global_id(0); // C Row ID 6 | 7 | // Do the operation 8 | if(globalRow < n){ 9 | B[globalRow] = min(A[globalRow], x); 10 | } 11 | } -------------------------------------------------------------------------------- /inst/CL/fVec_pmax.cl: -------------------------------------------------------------------------------- 1 | __kernel void pmax( 2 | __global float *A, __global float *B, const float x, const unsigned int n) { 3 | 4 | // Get the index of the elements to be processed 5 | const int globalRow = get_global_id(0); // C Row ID 6 | 7 | // Do the operation 8 | if(globalRow < n){ 9 | B[globalRow] = max(A[globalRow], x); 10 | } 11 | } -------------------------------------------------------------------------------- /inst/CL/fVec_pmin.cl: -------------------------------------------------------------------------------- 1 | __kernel void pmax( 2 | __global float *A, __global float *B, const float x, const unsigned int n) { 3 | 4 | // Get the index of the elements to be processed 5 | const int globalRow = get_global_id(0); // C Row ID 6 | 7 | // Do the operation 8 | if(globalRow < n){ 9 | B[globalRow] = min(A[globalRow], x); 10 | } 11 | } -------------------------------------------------------------------------------- /man/has_double_skip.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/test_utils.R 3 | \name{has_double_skip} 4 | \alias{has_double_skip} 5 | \title{Skip test for GPU double precision} 6 | \usage{ 7 | has_double_skip() 8 | } 9 | \description{ 10 | Function to skip testthat tests 11 | if the detected GPU doesn't support double precision 12 | } 13 | -------------------------------------------------------------------------------- /man/currentContext.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{currentContext} 4 | \alias{currentContext} 5 | \title{Current Context} 6 | \usage{ 7 | currentContext() 8 | } 9 | \value{ 10 | An integer reflecting the context listed in \link{listContexts} 11 | } 12 | \description{ 13 | Get current context index 14 | } 15 | -------------------------------------------------------------------------------- /man/has_multiple_gpu_skip.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/test_utils.R 3 | \name{has_multiple_gpu_skip} 4 | \alias{has_multiple_gpu_skip} 5 | \title{Skip test in less than 2 GPUs} 6 | \usage{ 7 | has_multiple_gpu_skip() 8 | } 9 | \description{ 10 | Function to skip testthat tests 11 | if less than 2 valid GPU's are detected 12 | } 13 | -------------------------------------------------------------------------------- /man/pocl_check.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/test_utils.R 3 | \name{pocl_check} 4 | \alias{pocl_check} 5 | \title{POCL Version Check} 6 | \usage{ 7 | pocl_check() 8 | } 9 | \description{ 10 | Versions of POCL up to 0.15-pre have a bug 11 | which results in values being returned when NA values 12 | should be (e.g. fractional powers of negative values) 13 | } 14 | -------------------------------------------------------------------------------- /man/setContext.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/wrappers-utils.R 3 | \name{setContext} 4 | \alias{setContext} 5 | \title{Set Context} 6 | \usage{ 7 | setContext(id = 1L) 8 | } 9 | \arguments{ 10 | \item{id}{Integer identifying which context to set} 11 | } 12 | \description{ 13 | Change the current context used by default 14 | } 15 | \seealso{ 16 | \link{listContexts} 17 | } 18 | -------------------------------------------------------------------------------- /include/gpuR/windows_check.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef WINDOWS_CHECK_HPP 3 | #define WINDOWS_CHECK_HPP 4 | 5 | // windows deal with clashes 6 | #ifdef _WIN32 7 | //#define R_NO_REMAP 1 8 | #define STRICT_R_HEADERS 9 | //#include 10 | //#include 11 | //#undef Realloc 12 | //#define R_Realloc(p,n,t) (t *) R_chk_realloc( (void *)(p), (size_t)((n) * sizeof(t)) ) 13 | //#include 14 | #endif 15 | 16 | #endif -------------------------------------------------------------------------------- /inst/include/gpuR/windows_check.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef WINDOWS_CHECK_HPP 3 | #define WINDOWS_CHECK_HPP 4 | 5 | // windows deal with clashes 6 | #ifdef _WIN32 7 | //#define R_NO_REMAP 1 8 | #define STRICT_R_HEADERS 9 | //#include 10 | //#include 11 | //#undef Realloc 12 | //#define R_Realloc(p,n,t) (t *) R_chk_realloc( (void *)(p), (size_t)((n) * sizeof(t)) ) 13 | //#include 14 | #endif 15 | 16 | #endif -------------------------------------------------------------------------------- /man/has_multiple_double_skip.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/test_utils.R 3 | \name{has_multiple_double_skip} 4 | \alias{has_multiple_double_skip} 5 | \title{Skip test for multiple GPUs with double precision} 6 | \usage{ 7 | has_multiple_double_skip() 8 | } 9 | \description{ 10 | Function to skip testthat tests 11 | if their aren't multiple detected GPU with double precision 12 | } 13 | -------------------------------------------------------------------------------- /man/detectPlatforms.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{detectPlatforms} 4 | \alias{detectPlatforms} 5 | \title{Detect Number of Platforms} 6 | \usage{ 7 | detectPlatforms() 8 | } 9 | \value{ 10 | An integer value representing the number of platforms available. 11 | } 12 | \description{ 13 | Find out how many OpenCL enabled platforms are available. 14 | } 15 | \seealso{ 16 | \link{detectGPUs} 17 | } 18 | -------------------------------------------------------------------------------- /man/currentPlatform.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{currentPlatform} 4 | \alias{currentPlatform} 5 | \title{Return Current Platform} 6 | \usage{ 7 | currentPlatform() 8 | } 9 | \value{ 10 | \item{platform}{Name of the current platform} 11 | 12 | \item{platform_index}{Index of current platform} 13 | } 14 | \description{ 15 | Find out which platform is currently in use 16 | } 17 | \seealso{ 18 | \link{detectPlatforms} 19 | } 20 | -------------------------------------------------------------------------------- /gpuR.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 4 10 | Encoding: UTF-8 11 | 12 | RnwWeave: knitr 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Package 16 | PackageUseDevtools: Yes 17 | PackageInstallArgs: --with-keep.source --no-multiarch --keep-empty-dirs 18 | PackageCheckArgs: --no-build-vignettes --no-vignettes --no-manual --no-tests 19 | PackageRoxygenize: rd,collate,namespace,vignette 20 | -------------------------------------------------------------------------------- /include/loader/Makefile: -------------------------------------------------------------------------------- 1 | CPPFLAGS = -I../ 2 | 3 | .PHONY: clean 4 | 5 | .$(R_ARCH)/libOpenCL.a: .$(R_ARCH)/icd.o .$(R_ARCH)/icd_dispatch.o .$(R_ARCH)/$(ICD_OS).o 6 | $(RM) $@ 7 | $(AR) rcs $@ $^ 8 | 9 | .$(R_ARCH)/icd.o: icd.c 10 | $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ 11 | 12 | .$(R_ARCH)/icd_dispatch.o: icd_dispatch.c 13 | $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ 14 | 15 | .$(R_ARCH)/$(ICD_OS).o: $(ICD_OS).c 16 | $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ 17 | 18 | clean: 19 | $(RM) .$(R_ARCH)/*.o 20 | $(RM) .$(R_ARCH)/*.a 21 | -------------------------------------------------------------------------------- /inst/CL/iScalarElemDiv.cl: -------------------------------------------------------------------------------- 1 | __kernel void ScalarElemDiv( 2 | __global int *A, const int B, 3 | const int Mdim, const int Pdim, const int MdimPad) { 4 | 5 | // Get the index of the elements to be processed 6 | const int globalRow = get_global_id(0); // C Row ID 7 | const int globalCol = get_global_id(1); // C Col ID 8 | 9 | // Do the operation 10 | if((globalRow <= Mdim) && (globalCol <= Pdim)){ 11 | 12 | A[globalRow * MdimPad + globalCol] = B/A[globalRow * MdimPad + globalCol]; 13 | } 14 | } -------------------------------------------------------------------------------- /man/currentDevice.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{currentDevice} 4 | \alias{currentDevice} 5 | \title{Current Device Information} 6 | \usage{ 7 | currentDevice() 8 | } 9 | \value{ 10 | list containing 11 | 12 | \item{device}{Character string of device name} 13 | 14 | \item{device_index}{Integer identifying device} 15 | 16 | \item{device_type}{Character string identifying device type (e.g. gpu)} 17 | } 18 | \description{ 19 | Check current device information 20 | } 21 | -------------------------------------------------------------------------------- /man/set_device_context.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/test_utils.R 3 | \name{set_device_context} 4 | \alias{set_device_context} 5 | \title{Set Context for Specific Device Type} 6 | \usage{ 7 | set_device_context(type) 8 | } 9 | \arguments{ 10 | \item{type}{A character vector specifying device type} 11 | } 12 | \value{ 13 | An integer indicating previous context index 14 | } 15 | \description{ 16 | This function find the first context 17 | that contains a device of the specified type. 18 | } 19 | -------------------------------------------------------------------------------- /inst/CL/fScalarElemDiv.cl: -------------------------------------------------------------------------------- 1 | __kernel void ScalarElemDiv( 2 | __global float *A, const float B, 3 | const int Mdim, const int Pdim, const int MdimPad) { 4 | 5 | // Get the index of the elements to be processed 6 | const int globalRow = get_global_id(0); // C Row ID 7 | const int globalCol = get_global_id(1); // C Col ID 8 | 9 | // Do the operation 10 | if((globalRow <= Mdim) && (globalCol <= Pdim)){ 11 | 12 | A[globalRow * MdimPad + globalCol] = B/A[globalRow * MdimPad + globalCol]; 13 | } 14 | } -------------------------------------------------------------------------------- /inst/CL/fset_row_order2.cl: -------------------------------------------------------------------------------- 1 | __kernel void set_row_order( 2 | __global const float *A, __global float *B, __global const int *indices, 3 | const int Mdim, const int globalCol, const int MdimPad) { 4 | 5 | // Get the index of the elements to be processed 6 | const int globalRow = get_global_id(0); // C Row ID 7 | //const int globalCol = get_global_id(1); // C Col ID 8 | 9 | // Do the operation 10 | if((globalRow <= Mdim)){ 11 | B[globalRow] = A[indices[globalRow] * MdimPad + globalCol]; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /inst/include/loader/Makefile: -------------------------------------------------------------------------------- 1 | CPPFLAGS = -I../ 2 | 3 | .PHONY: clean 4 | 5 | .$(R_ARCH)/libOpenCL.a: .$(R_ARCH)/icd.o .$(R_ARCH)/icd_dispatch.o .$(R_ARCH)/$(ICD_OS).o 6 | $(RM) $@ 7 | $(AR) rcs $@ $^ 8 | 9 | .$(R_ARCH)/icd.o: icd.c 10 | $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ 11 | 12 | .$(R_ARCH)/icd_dispatch.o: icd_dispatch.c 13 | $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ 14 | 15 | .$(R_ARCH)/$(ICD_OS).o: $(ICD_OS).c 16 | $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ 17 | 18 | clean: 19 | $(RM) .$(R_ARCH)/*.o 20 | $(RM) .$(R_ARCH)/*.a 21 | -------------------------------------------------------------------------------- /man/igpuVector-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-gpuVector.R 3 | \docType{class} 4 | \name{igpuVector-class} 5 | \alias{igpuVector-class} 6 | \title{igpuVector Class} 7 | \description{ 8 | An integer vector in the S4 \code{gpuVector} 9 | representation. 10 | } 11 | \section{Slots}{ 12 | 13 | \describe{ 14 | \item{\code{address}:}{An integer vector object} 15 | } 16 | } 17 | 18 | \seealso{ 19 | \code{\link{gpuVector-class}} 20 | } 21 | \author{ 22 | Charles Determan Jr. 23 | } 24 | -------------------------------------------------------------------------------- /man/ivclVector-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-vclVector.R 3 | \docType{class} 4 | \name{ivclVector-class} 5 | \alias{ivclVector-class} 6 | \title{ivclVector Class} 7 | \description{ 8 | An integer vector in the S4 \code{vclVector} 9 | representation. 10 | } 11 | \section{Slots}{ 12 | 13 | \describe{ 14 | \item{\code{address}:}{An integer vector object} 15 | } 16 | } 17 | 18 | \seealso{ 19 | \code{\link{vclVector-class}} 20 | } 21 | \author{ 22 | Charles Determan Jr. 23 | } 24 | -------------------------------------------------------------------------------- /inst/CL/dScalarElemDiv.cl: -------------------------------------------------------------------------------- 1 | __kernel void ScalarElemDiv( 2 | __global double *A, const double B, 3 | const int Mdim, const int Pdim, const int MdimPad) { 4 | 5 | // Get the index of the elements to be processed 6 | const int globalRow = get_global_id(0); // C Row ID 7 | const int globalCol = get_global_id(1); // C Col ID 8 | 9 | // Do the operation 10 | if((globalRow <= Mdim) && (globalCol <= Pdim)){ 11 | 12 | A[globalRow * MdimPad + globalCol] = B/A[globalRow * MdimPad + globalCol]; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /inst/CL/iMatSign.cl: -------------------------------------------------------------------------------- 1 | __kernel void MatSign( 2 | __global const int *A, __global int *B, 3 | const int Mdim, const int Pdim, const int MdimPad) { 4 | 5 | // Get the index of the elements to be processed 6 | const int globalRow = get_global_id(0); // C Row ID 7 | const int globalCol = get_global_id(1); // C Col ID 8 | 9 | // Do the operation 10 | if((globalRow <= Mdim) && (globalCol <= Pdim)){ 11 | 12 | B[globalRow * MdimPad + globalCol] = sign(A[globalRow * MdimPad + globalCol]); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /man/dgpuVector-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-gpuVector.R 3 | \docType{class} 4 | \name{dgpuVector-class} 5 | \alias{dgpuVector-class} 6 | \title{dgpuVector Class} 7 | \description{ 8 | An double vector in the S4 \code{gpuVector} 9 | representation. 10 | } 11 | \section{Slots}{ 12 | 13 | \describe{ 14 | \item{\code{address}:}{Pointer to a double typed vector} 15 | } 16 | } 17 | 18 | \seealso{ 19 | \code{\link{gpuVector-class}} 20 | } 21 | \author{ 22 | Charles Determan Jr. 23 | } 24 | -------------------------------------------------------------------------------- /man/dvclVector-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-vclVector.R 3 | \docType{class} 4 | \name{dvclVector-class} 5 | \alias{dvclVector-class} 6 | \title{dvclVector Class} 7 | \description{ 8 | An double vector in the S4 \code{vclVector} 9 | representation. 10 | } 11 | \section{Slots}{ 12 | 13 | \describe{ 14 | \item{\code{address}:}{Pointer to a double typed vector} 15 | } 16 | } 17 | 18 | \seealso{ 19 | \code{\link{vclVector-class}} 20 | } 21 | \author{ 22 | Charles Determan Jr. 23 | } 24 | -------------------------------------------------------------------------------- /man/fgpuVector-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-gpuVector.R 3 | \docType{class} 4 | \name{fgpuVector-class} 5 | \alias{fgpuVector-class} 6 | \title{fgpuVector Class} 7 | \description{ 8 | An float vector in the S4 \code{gpuVector} 9 | representation. 10 | } 11 | \section{Slots}{ 12 | 13 | \describe{ 14 | \item{\code{address}:}{Pointer to a float typed vector} 15 | } 16 | } 17 | 18 | \seealso{ 19 | \code{\link{gpuVector-class}} 20 | } 21 | \author{ 22 | Charles Determan Jr. 23 | } 24 | -------------------------------------------------------------------------------- /man/fvclVector-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-vclVector.R 3 | \docType{class} 4 | \name{fvclVector-class} 5 | \alias{fvclVector-class} 6 | \title{fvclVector Class} 7 | \description{ 8 | An float vector in the S4 \code{vclVector} 9 | representation. 10 | } 11 | \section{Slots}{ 12 | 13 | \describe{ 14 | \item{\code{address}:}{Pointer to a float typed vector} 15 | } 16 | } 17 | 18 | \seealso{ 19 | \code{\link{vclVector-class}} 20 | } 21 | \author{ 22 | Charles Determan Jr. 23 | } 24 | -------------------------------------------------------------------------------- /inst/CL/dMatSign.cl: -------------------------------------------------------------------------------- 1 | __kernel void MatSign( 2 | __global const double *A, __global double *B, 3 | const int Mdim, const int Pdim, const int MdimPad) { 4 | 5 | // Get the index of the elements to be processed 6 | const int globalRow = get_global_id(0); // C Row ID 7 | const int globalCol = get_global_id(1); // C Col ID 8 | 9 | // Do the operation 10 | if((globalRow <= Mdim) && (globalCol <= Pdim)){ 11 | 12 | B[globalRow * MdimPad + globalCol] = sign(A[globalRow * MdimPad + globalCol]); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /inst/CL/iMat_pmin.cl: -------------------------------------------------------------------------------- 1 | __kernel void pmax( 2 | __global const int *A, __global int *B, const int x, 3 | const int Mdim, const int Pdim, const int MdimPad) { 4 | 5 | // Get the index of the elements to be processed 6 | const int globalRow = get_global_id(0); // C Row ID 7 | const int globalCol = get_global_id(1); // C Col ID 8 | 9 | // Do the operation 10 | if((globalRow <= Mdim) && (globalCol <= Pdim)){ 11 | 12 | B[globalRow * MdimPad + globalCol] = min(A[globalRow * MdimPad + globalCol], x); 13 | } 14 | } -------------------------------------------------------------------------------- /inst/CL/fMat_pmax.cl: -------------------------------------------------------------------------------- 1 | __kernel void pmax( 2 | __global const float *A, __global float *B, const float x, 3 | const int Mdim, const int Pdim, const int MdimPad) { 4 | 5 | // Get the index of the elements to be processed 6 | const int globalRow = get_global_id(0); // C Row ID 7 | const int globalCol = get_global_id(1); // C Col ID 8 | 9 | // Do the operation 10 | if((globalRow <= Mdim) && (globalCol <= Pdim)){ 11 | 12 | B[globalRow * MdimPad + globalCol] = max(A[globalRow * MdimPad + globalCol], x); 13 | } 14 | } -------------------------------------------------------------------------------- /inst/CL/fMat_pmin.cl: -------------------------------------------------------------------------------- 1 | __kernel void pmax( 2 | __global const float *A, __global float *B, const float x, 3 | const int Mdim, const int Pdim, const int MdimPad) { 4 | 5 | // Get the index of the elements to be processed 6 | const int globalRow = get_global_id(0); // C Row ID 7 | const int globalCol = get_global_id(1); // C Col ID 8 | 9 | // Do the operation 10 | if((globalRow <= Mdim) && (globalCol <= Pdim)){ 11 | 12 | B[globalRow * MdimPad + globalCol] = min(A[globalRow * MdimPad + globalCol], x); 13 | } 14 | } -------------------------------------------------------------------------------- /inst/CL/iMat_pmax.cl: -------------------------------------------------------------------------------- 1 | __kernel void pmax( 2 | __global const int *A, __global int *B, const int x, 3 | const int Mdim, const int Pdim, const int MdimPad) { 4 | 5 | // Get the index of the elements to be processed 6 | const int globalRow = get_global_id(0); // C Row ID 7 | const int globalCol = get_global_id(1); // C Col ID 8 | 9 | // Do the operation 10 | if((globalRow <= Mdim) && (globalCol <= Pdim)){ 11 | 12 | B[globalRow * MdimPad + globalCol] = max(A[globalRow * MdimPad + globalCol], x); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /inst/CL/dMat_pmax.cl: -------------------------------------------------------------------------------- 1 | __kernel void pmax( 2 | __global const double *A, __global double *B, const double x, 3 | const int Mdim, const int Pdim, const int MdimPad) { 4 | 5 | // Get the index of the elements to be processed 6 | const int globalRow = get_global_id(0); // C Row ID 7 | const int globalCol = get_global_id(1); // C Col ID 8 | 9 | // Do the operation 10 | if((globalRow <= Mdim) && (globalCol <= Pdim)){ 11 | 12 | B[globalRow * MdimPad + globalCol] = max(A[globalRow * MdimPad + globalCol], x); 13 | } 14 | } -------------------------------------------------------------------------------- /inst/CL/dMat_pmin.cl: -------------------------------------------------------------------------------- 1 | __kernel void pmax( 2 | __global const double *A, __global double *B, const double x, 3 | const int Mdim, const int Pdim, const int MdimPad) { 4 | 5 | // Get the index of the elements to be processed 6 | const int globalRow = get_global_id(0); // C Row ID 7 | const int globalCol = get_global_id(1); // C Col ID 8 | 9 | // Do the operation 10 | if((globalRow <= Mdim) && (globalCol <= Pdim)){ 11 | 12 | B[globalRow * MdimPad + globalCol] = min(A[globalRow * MdimPad + globalCol], x); 13 | } 14 | } -------------------------------------------------------------------------------- /man/pmax.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pmax.R 3 | \name{pmax} 4 | \alias{pmax} 5 | \alias{pmin} 6 | \title{'Parallel' Maxima and Minima} 7 | \usage{ 8 | pmax(...) 9 | 10 | pmin(...) 11 | } 12 | \arguments{ 13 | \item{...}{gpuR or numeric arguments} 14 | } 15 | \description{ 16 | \code{pmax} and \code{pmin} take one or more 17 | vectors as arguments and return a single vector giving the 'parallel' 18 | maxima (or minima) of the argument vectors 19 | } 20 | \seealso{ 21 | \link[base]{pmax} \link[base]{pmin} 22 | } 23 | -------------------------------------------------------------------------------- /man/print.gpuMatrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/print.R 3 | \name{print.gpuMatrix} 4 | \alias{print.gpuMatrix} 5 | \title{S3 print for gpuMatrix objects} 6 | \usage{ 7 | \method{print}{gpuMatrix}(x, ..., n = NULL, width = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{A gpuMatrix object} 11 | 12 | \item{...}{Additional arguments to print} 13 | 14 | \item{n}{Number of rows to display} 15 | 16 | \item{width}{Number of columns to display} 17 | } 18 | \description{ 19 | prints a gpuMatrix object that is truncated to fit the screen 20 | } 21 | -------------------------------------------------------------------------------- /inst/CL/dset_row_order.cl: -------------------------------------------------------------------------------- 1 | __kernel void set_row_order( 2 | __global const double *A, __global double *B, __global const int *indices, 3 | const int Mdim, const int Pdim, const int MdimPad) { 4 | 5 | // Get the index of the elements to be processed 6 | const int globalRow = get_global_id(0); // C Row ID 7 | const int globalCol = get_global_id(1); // C Col ID 8 | 9 | // Do the operation 10 | if((globalRow <= Mdim) && (globalCol <= Pdim)){ 11 | 12 | B[globalRow * MdimPad + globalCol] = A[indices[globalRow] * MdimPad + globalCol]; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /man/detectGPUs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/wrappers-utils.R 3 | \name{detectGPUs} 4 | \alias{detectGPUs} 5 | \title{Detect Available GPUs} 6 | \usage{ 7 | detectGPUs(platform_idx = NULL) 8 | } 9 | \arguments{ 10 | \item{platform_idx}{An integer value indicating which platform to query. 11 | If NULL it will iterate over all platforms and sum results} 12 | } 13 | \value{ 14 | An integer representing the number of available GPUs 15 | } 16 | \description{ 17 | Find out how many GPUs available 18 | } 19 | \seealso{ 20 | \link{detectPlatforms} 21 | } 22 | -------------------------------------------------------------------------------- /man/deviceType.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/wrappers-utils.R 3 | \name{deviceType} 4 | \alias{deviceType} 5 | \title{Check device type} 6 | \usage{ 7 | deviceType(device_idx = NULL, context_idx = currentContext()) 8 | } 9 | \arguments{ 10 | \item{device_idx}{An integer value indicating which device to query.} 11 | 12 | \item{context_idx}{An integer value indicating which context to query.} 13 | } 14 | \value{ 15 | A character string indicating the device type 16 | } 17 | \description{ 18 | Check what type a device is given platform and device indices 19 | } 20 | -------------------------------------------------------------------------------- /man/fgpuMatrix-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-gpuMatrix.R 3 | \docType{class} 4 | \name{fgpuMatrix-class} 5 | \alias{fgpuMatrix-class} 6 | \title{fgpuMatrix Class} 7 | \description{ 8 | A float type matrix in the S4 \code{gpuMatrix} 9 | representation. 10 | } 11 | \section{Slots}{ 12 | 13 | \describe{ 14 | \item{\code{address}:}{Pointer to a float matrix.} 15 | } 16 | } 17 | 18 | \seealso{ 19 | \code{\link{gpuMatrix-class}}, 20 | \code{\link{igpuMatrix-class}}, 21 | \code{\link{dgpuMatrix-class}} 22 | } 23 | \author{ 24 | Charles Determan Jr. 25 | } 26 | -------------------------------------------------------------------------------- /man/fvclMatrix-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-vclMatrix.R 3 | \docType{class} 4 | \name{fvclMatrix-class} 5 | \alias{fvclMatrix-class} 6 | \title{fvclMatrix Class} 7 | \description{ 8 | An integer type matrix in the S4 \code{vclMatrix} 9 | representation. 10 | } 11 | \section{Slots}{ 12 | 13 | \describe{ 14 | \item{\code{address}:}{Pointer to a float matrix.} 15 | } 16 | } 17 | 18 | \seealso{ 19 | \code{\link{vclMatrix-class}}, 20 | \code{\link{ivclMatrix-class}}, 21 | \code{\link{dvclMatrix-class}} 22 | } 23 | \author{ 24 | Charles Determan Jr. 25 | } 26 | -------------------------------------------------------------------------------- /R/flags.R: -------------------------------------------------------------------------------- 1 | 2 | get_os <- function() 3 | { 4 | os = tolower(Sys.info()["sysname"]) 5 | names(os) = NULL 6 | 7 | os 8 | } 9 | 10 | CxxFlags = function() 11 | { 12 | os = get_os() 13 | 14 | libs_dir_rel = system.file("include", package="gpuR") 15 | libs_dir = tools::file_path_as_absolute(libs_dir_rel) 16 | 17 | if (os == "linux" || os == "freebsd") 18 | flags = libs_dir 19 | else{ 20 | dll.path <- normalizePath(libs_dir) 21 | dll.path <- utils::shortPathName(dll.path) 22 | flags <- gsub("\\\\", "/", dll.path) 23 | } 24 | 25 | cat(flags) 26 | } 27 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ## Test environments 2 | * local Windows install, R 3.4.2 3 | * ubuntu 14.04 (on travis-ci), R 3.4.2 4 | * OS X 10.11.6 (Xcode 7.3.1 on travis-ci), R 3.4.2 5 | 6 | ## R CMD check results 7 | 8 | 0 errors | 0 warnings | 1 note 9 | 10 | * checking installed package size ... NOTE 11 | installed size is 96.4Mb 12 | sub-directories of 1Mb or more: 13 | libs 94.2Mb 14 | 15 | This package depends upon the RViennaCL header only library 16 | and contains lots of C++ code. 17 | 18 | ## Reverse dependencies 19 | 20 | This package is still relatively new and has no reverse dependecies. 21 | 22 | --- 23 | -------------------------------------------------------------------------------- /man/dgpuMatrix-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-gpuMatrix.R 3 | \docType{class} 4 | \name{dgpuMatrix-class} 5 | \alias{dgpuMatrix-class} 6 | \title{dgpuMatrix Class} 7 | \description{ 8 | A double type matrix in the S4 \code{gpuMatrix} 9 | representation. 10 | } 11 | \section{Slots}{ 12 | 13 | \describe{ 14 | \item{\code{address}:}{Pointer to a double type matrix} 15 | } 16 | } 17 | 18 | \seealso{ 19 | \code{\link{gpuMatrix-class}}, 20 | \code{\link{igpuMatrix-class}}, 21 | \code{\link{fgpuMatrix-class}} 22 | } 23 | \author{ 24 | Charles Determan Jr. 25 | } 26 | -------------------------------------------------------------------------------- /man/dvclMatrix-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-vclMatrix.R 3 | \docType{class} 4 | \name{dvclMatrix-class} 5 | \alias{dvclMatrix-class} 6 | \title{dvclMatrix Class} 7 | \description{ 8 | An integer type matrix in the S4 \code{vclMatrix} 9 | representation. 10 | } 11 | \section{Slots}{ 12 | 13 | \describe{ 14 | \item{\code{address}:}{Pointer to a double type matrix} 15 | } 16 | } 17 | 18 | \seealso{ 19 | \code{\link{vclMatrix-class}}, 20 | \code{\link{ivclMatrix-class}}, 21 | \code{\link{fvclMatrix-class}} 22 | } 23 | \author{ 24 | Charles Determan Jr. 25 | } 26 | -------------------------------------------------------------------------------- /man/detectCPUs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/wrappers-utils.R 3 | \name{detectCPUs} 4 | \alias{detectCPUs} 5 | \title{Detect Available OpenCL enabled CPUs} 6 | \usage{ 7 | detectCPUs(platform_idx = NULL) 8 | } 9 | \arguments{ 10 | \item{platform_idx}{An integer value indicating which platform to query. 11 | If NULL it will iterate over all platforms and sum results} 12 | } 13 | \value{ 14 | An integer representing the number of available CPUs 15 | } 16 | \description{ 17 | Find out how many CPUs available 18 | } 19 | \seealso{ 20 | \link{detectPlatforms} \link{detectGPUs} 21 | } 22 | -------------------------------------------------------------------------------- /man/igpuMatrix-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-gpuMatrix.R 3 | \docType{class} 4 | \name{igpuMatrix-class} 5 | \alias{igpuMatrix-class} 6 | \title{igpuMatrix Class} 7 | \description{ 8 | An integer type matrix in the S4 \code{gpuMatrix} 9 | representation. 10 | } 11 | \section{Slots}{ 12 | 13 | \describe{ 14 | \item{\code{address}:}{Pointer to a integer typed matrix} 15 | } 16 | } 17 | 18 | \seealso{ 19 | \code{\link{gpuMatrix-class}}, 20 | \code{\link{igpuMatrix-class}}, 21 | \code{\link{dgpuMatrix-class}} 22 | } 23 | \author{ 24 | Charles Determan Jr. 25 | } 26 | -------------------------------------------------------------------------------- /man/ivclMatrix-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-vclMatrix.R 3 | \docType{class} 4 | \name{ivclMatrix-class} 5 | \alias{ivclMatrix-class} 6 | \title{ivclMatrix Class} 7 | \description{ 8 | An integer type matrix in the S4 \code{vclMatrix} 9 | representation. 10 | } 11 | \section{Slots}{ 12 | 13 | \describe{ 14 | \item{\code{address}:}{Pointer to a integer typed matrix} 15 | } 16 | } 17 | 18 | \seealso{ 19 | \code{\link{vclMatrix-class}}, 20 | \code{\link{ivclMatrix-class}}, 21 | \code{\link{dvclMatrix-class}} 22 | } 23 | \author{ 24 | Charles Determan Jr. 25 | } 26 | -------------------------------------------------------------------------------- /man/cgpuMatrix-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-gpuMatrix.R 3 | \docType{class} 4 | \name{cgpuMatrix-class} 5 | \alias{cgpuMatrix-class} 6 | \title{cgpuMatrix Class} 7 | \description{ 8 | An complex float type matrix in the S4 \code{gpuMatrix} 9 | representation. 10 | } 11 | \section{Slots}{ 12 | 13 | \describe{ 14 | \item{\code{address}:}{Pointer to a complex float matrix.} 15 | } 16 | } 17 | 18 | \seealso{ 19 | \code{\link{gpuMatrix-class}}, 20 | \code{\link{igpuMatrix-class}}, 21 | \code{\link{dgpuMatrix-class}} 22 | } 23 | \author{ 24 | Charles Determan Jr. 25 | } 26 | -------------------------------------------------------------------------------- /man/cvclMatrix-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-vclMatrix.R 3 | \docType{class} 4 | \name{cvclMatrix-class} 5 | \alias{cvclMatrix-class} 6 | \title{cvclMatrix Class} 7 | \description{ 8 | An complex float type matrix in the S4 \code{vclMatrix} 9 | representation. 10 | } 11 | \section{Slots}{ 12 | 13 | \describe{ 14 | \item{\code{address}:}{Pointer to a complex float type matrix} 15 | } 16 | } 17 | 18 | \seealso{ 19 | \code{\link{vclMatrix-class}}, 20 | \code{\link{ivclMatrix-class}}, 21 | \code{\link{fvclMatrix-class}} 22 | } 23 | \author{ 24 | Charles Determan Jr. 25 | } 26 | -------------------------------------------------------------------------------- /man/zgpuMatrix-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-gpuMatrix.R 3 | \docType{class} 4 | \name{zgpuMatrix-class} 5 | \alias{zgpuMatrix-class} 6 | \title{zgpuMatrix Class} 7 | \description{ 8 | An complex double type matrix in the S4 \code{gpuMatrix} 9 | representation. 10 | } 11 | \section{Slots}{ 12 | 13 | \describe{ 14 | \item{\code{address}:}{Pointer to a complex double matrix.} 15 | } 16 | } 17 | 18 | \seealso{ 19 | \code{\link{gpuMatrix-class}}, 20 | \code{\link{igpuMatrix-class}}, 21 | \code{\link{dgpuMatrix-class}} 22 | } 23 | \author{ 24 | Charles Determan Jr. 25 | } 26 | -------------------------------------------------------------------------------- /man/zvclMatrix-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-vclMatrix.R 3 | \docType{class} 4 | \name{zvclMatrix-class} 5 | \alias{zvclMatrix-class} 6 | \title{zvclMatrix Class} 7 | \description{ 8 | An complex double type matrix in the S4 \code{vclMatrix} 9 | representation. 10 | } 11 | \section{Slots}{ 12 | 13 | \describe{ 14 | \item{\code{address}:}{Pointer to a complex double type matrix} 15 | } 16 | } 17 | 18 | \seealso{ 19 | \code{\link{vclMatrix-class}}, 20 | \code{\link{ivclMatrix-class}}, 21 | \code{\link{fvclMatrix-class}} 22 | } 23 | \author{ 24 | Charles Determan Jr. 25 | } 26 | -------------------------------------------------------------------------------- /inst/testWithGPU/testthat/test_utils.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("Utility Functions") 3 | 4 | test_that("detectGPUs() accepts appropriate input", { 5 | 6 | has_gpu_skip() 7 | 8 | expect_error(detectGPUs(0)) 9 | expect_error(detectGPUs(2)) 10 | expect_error(detectGPUs(c(2,3))) 11 | }) 12 | 13 | test_that("gpuInfo() accepts appropriate input", { 14 | 15 | has_gpu_skip() 16 | 17 | expect_error(gpuInfo(0, 0)) 18 | expect_error(gpuInfo(2, 2)) 19 | expect_error(gpuInfo(0, 1)) 20 | expect_error(gpuInfo(1, 0)) 21 | expect_error(gpuInfo(c(2,3), 1)) 22 | 23 | expect_is(gpuInfo(), "list") 24 | }) 25 | -------------------------------------------------------------------------------- /man/synchronize.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{synchronize} 4 | \alias{synchronize} 5 | \title{Synchronize Device Execution} 6 | \usage{ 7 | synchronize() 8 | } 9 | \description{ 10 | This pauses execution until the processing is complete 11 | on the device (CPU/GPU/etc.). This is important especially for 12 | benchmarking applications. 13 | } 14 | \examples{ 15 | \dontrun{ 16 | mat <- vclMatrix(rnorm(500^2), ncol = 500, nrow = 500) 17 | system.time(mat \%*\% mat) 18 | system.time(mat \%*\% mat; synchronize()) 19 | } 20 | } 21 | \author{ 22 | Charles Determan Jr. 23 | } 24 | -------------------------------------------------------------------------------- /man/grapes-o-grapes-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/methods-gpuVector.R, R/methods-vclVector.R 3 | \docType{methods} 4 | \name{\%o\%,gpuVector,gpuVector-method} 5 | \alias{\%o\%,gpuVector,gpuVector-method} 6 | \alias{\%o\%,vclVector,vclVector-method} 7 | \title{Outer Product} 8 | \usage{ 9 | \S4method{\%o\%}{gpuVector,gpuVector}(X, Y) 10 | 11 | \S4method{\%o\%}{vclVector,vclVector}(X, Y) 12 | } 13 | \arguments{ 14 | \item{X}{A gpuR object} 15 | 16 | \item{Y}{A gpuR object} 17 | } 18 | \description{ 19 | The outer product of two gpuR vector objects 20 | } 21 | \author{ 22 | Charles Determan Jr. 23 | } 24 | -------------------------------------------------------------------------------- /man/t-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/methods-vclMatrix.R, R/methods.R 3 | \docType{methods} 4 | \name{t,vclMatrix-method} 5 | \alias{t,vclMatrix-method} 6 | \alias{t,vclMatrix} 7 | \alias{t,gpuMatrix-method} 8 | \alias{t,gpuMatrix} 9 | \title{\code{gpuR} matrix transpose} 10 | \usage{ 11 | \S4method{t}{vclMatrix}(x) 12 | 13 | \S4method{t}{gpuMatrix}(x) 14 | } 15 | \arguments{ 16 | \item{x}{A \code{gpuR} matrix} 17 | } 18 | \value{ 19 | A \code{gpuR} matrix 20 | } 21 | \description{ 22 | Given a \code{gpuR} matrix \code{x}, \code{t} returns the 23 | transpose of \code{x} 24 | } 25 | \author{ 26 | Charles Determan Jr. 27 | } 28 | -------------------------------------------------------------------------------- /man/custom_opencl.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/custom_opencl.R 3 | \name{custom_opencl} 4 | \alias{custom_opencl} 5 | \title{Custom OpenCL Kernels} 6 | \usage{ 7 | custom_opencl(kernel, cl_args, type) 8 | } 9 | \arguments{ 10 | \item{kernel}{path to OpenCL kernel file} 11 | 12 | \item{cl_args}{A \code{data.frame} that contains argument definitions. 13 | Provided by \code{\link{setup_opencl}}} 14 | 15 | \item{type}{The precision on which the kernel is compiled. Options include 16 | \code{"int"}, \code{"float"}, and \code{"double"}} 17 | } 18 | \description{ 19 | Compile a custom function using a user provided OpenCL kernel 20 | } 21 | -------------------------------------------------------------------------------- /man/dim-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/methods-vclMatrix.R, R/methods.R 3 | \docType{methods} 4 | \name{dim,vclMatrix-method} 5 | \alias{dim,vclMatrix-method} 6 | \alias{dim-vclMatrix} 7 | \alias{dim,gpuMatrix-method} 8 | \alias{dim-gpuMatrix} 9 | \title{gpuMatrix/vclMatrix dim method} 10 | \usage{ 11 | \S4method{dim}{vclMatrix}(x) 12 | 13 | \S4method{dim}{gpuMatrix}(x) 14 | } 15 | \arguments{ 16 | \item{x}{A gpuMatrix/vclMatrix object} 17 | } 18 | \value{ 19 | A length 2 vector of the number of rows and columns respectively. 20 | } 21 | \description{ 22 | Retrieve dimension of object 23 | } 24 | \author{ 25 | Charles Determan Jr. 26 | } 27 | -------------------------------------------------------------------------------- /man/permute-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \docType{methods} 4 | \name{permute} 5 | \alias{permute} 6 | \title{Permuting functions for \code{gpuR} objects} 7 | \usage{ 8 | permute(x, MARGIN, order) 9 | } 10 | \arguments{ 11 | \item{x}{A \code{gpuR} matrix object} 12 | 13 | \item{MARGIN}{dimension over which the ordering should be applied, 1 14 | indicates rows, 2 indicates columns} 15 | 16 | \item{order}{An integer vector indicating order of rows to assign} 17 | } 18 | \value{ 19 | A \code{gpuR} object 20 | } 21 | \description{ 22 | Generate a permutation of row or column indices 23 | } 24 | \author{ 25 | Charles Determan Jr. 26 | } 27 | -------------------------------------------------------------------------------- /src/Makevars.win: -------------------------------------------------------------------------------- 1 | CXX_STD = CXX11 2 | PKG_CPPFLAGS = -I. -I../inst/include -DCL_USE_DEPRECATED_OPENCL_1_2_APIS -UNDEBUG 3 | 4 | ifeq "$(WIN)" "64" 5 | PKG_LIBS = -L../inst/include/loader/x64 -lOpenCL 6 | else 7 | PKG_LIBS = -L../inst/include/loader/i386 -lOpenCL 8 | endif 9 | 10 | .PHONY: clean 11 | 12 | $(SHLIB): ../inst/include/loader$(R_ARCH)/libOpenCL.a 13 | 14 | ../inst/include/loader$(R_ARCH)/libOpenCL.a: 15 | cd ../inst/include/loader && mkdir -p .$(R_ARCH) && $(MAKE) .$(R_ARCH)/libOpenCL.a \ 16 | CC="$(CC)" CFLAGS="$(ALL_CFLAGS)" AR="$(AR)" RM="$(RM)" \ 17 | ICD_OS=icd_windows 18 | 19 | clean: 20 | $(RM) *.dll 21 | $(RM) *.so 22 | $(RM) *.dylib 23 | cd ../inst/include/loader && $(MAKE) clean 24 | -------------------------------------------------------------------------------- /inst/CL/fMatSign.cl: -------------------------------------------------------------------------------- 1 | __kernel void MatSign( 2 | __global const float *A, __global float *B, 3 | const int Mdim, const int Pdim, const int MdimPad) { 4 | 5 | // Get the index of the elements to be processed 6 | const int globalRow = get_global_id(0); // C Row ID 7 | const int globalCol = get_global_id(1); // C Col ID 8 | 9 | // Do the operation 10 | if((globalRow <= Mdim) && (globalCol <= Pdim)){ 11 | //printf("globalRow = %d\n", globalRow); 12 | //printf("globalCol = %d\n", globalCol); 13 | //printf("value = %f\n", A[globalRow * MdimPad + globalCol]); 14 | B[globalRow * MdimPad + globalCol] = sign(A[globalRow * MdimPad + globalCol]); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /man/platformInfo.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/wrappers-utils.R 3 | \name{platformInfo} 4 | \alias{platformInfo} 5 | \title{OpenCL Platform Information} 6 | \usage{ 7 | platformInfo(platform_idx = 1L) 8 | } 9 | \arguments{ 10 | \item{platform_idx}{An integer value to specify which platform to check} 11 | } 12 | \value{ 13 | \item{platformName}{Platform Name} 14 | 15 | \item{platformVendor}{Platform Vendor} 16 | 17 | \item{platformVersion}{Platform OpenCL Version} 18 | 19 | \item{platformExtensions}{Available platform extensions} 20 | } 21 | \description{ 22 | Get basic information about the OpenCL platform 23 | } 24 | \author{ 25 | Charles Determan Jr. 26 | } 27 | -------------------------------------------------------------------------------- /man/as.gpuMatrix-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generics.R 3 | \docType{methods} 4 | \name{as.gpuMatrix} 5 | \alias{as.gpuMatrix} 6 | \title{Convert object to a gpuMatrix} 7 | \usage{ 8 | as.gpuMatrix(object, type) 9 | } 10 | \arguments{ 11 | \item{object}{An object that is or can be converted to a 12 | \code{matrix} object} 13 | 14 | \item{type}{A character string specifying the type of gpuMatrix. Default 15 | is NULL where type is inherited from the source data type.} 16 | } 17 | \value{ 18 | A gpuMatrix object 19 | } 20 | \description{ 21 | Construct a gpuMatrix of a class that inherits 22 | from \code{gpuMatrix} 23 | } 24 | \author{ 25 | Charles Determan Jr. 26 | } 27 | -------------------------------------------------------------------------------- /man/typeof-gpuR-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/typeof.R 3 | \docType{methods} 4 | \name{typeof,gpuMatrix-method} 5 | \alias{typeof,gpuMatrix-method} 6 | \alias{typeof,gpuVector-method} 7 | \alias{typeof,vclMatrix-method} 8 | \alias{typeof,vclVector-method} 9 | \title{Get gpuR object type} 10 | \usage{ 11 | \S4method{typeof}{gpuMatrix}(x) 12 | 13 | \S4method{typeof}{gpuVector}(x) 14 | 15 | \S4method{typeof}{vclMatrix}(x) 16 | 17 | \S4method{typeof}{vclVector}(x) 18 | } 19 | \arguments{ 20 | \item{x}{A gpuR object} 21 | } 22 | \description{ 23 | \code{typeof} determines the type (i.e. storage mode) of a 24 | gpuR object 25 | } 26 | \author{ 27 | Charles Determan Jr. 28 | } 29 | -------------------------------------------------------------------------------- /inst/CL/iScalarAXPY.cl: -------------------------------------------------------------------------------- 1 | __kernel void scalar_axpy( 2 | __global int *A, const int scalar, const int alpha, const int order, 3 | const int Mdim, const int Pdim, const int MdimPad) { 4 | 5 | // Get the index of the elements to be processed 6 | const int globalRow = get_global_id(0); // C Row ID 7 | const int globalCol = get_global_id(1); // C Col ID 8 | 9 | // Do the operation 10 | if((globalRow <= Mdim) && (globalCol <= Pdim)){ 11 | 12 | if(order == 0){ 13 | A[globalRow * MdimPad + globalCol] = alpha * A[globalRow * MdimPad + globalCol] + scalar; 14 | }else{ 15 | A[globalRow * MdimPad + globalCol] = A[globalRow * MdimPad + globalCol] + alpha * scalar; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /inst/CL/fScalarAXPY.cl: -------------------------------------------------------------------------------- 1 | __kernel void scalar_axpy( 2 | __global float *A, const float scalar, const float alpha, const int order, 3 | const int Mdim, const int Pdim, const int MdimPad) { 4 | 5 | // Get the index of the elements to be processed 6 | const int globalRow = get_global_id(0); // C Row ID 7 | const int globalCol = get_global_id(1); // C Col ID 8 | 9 | // Do the operation 10 | if((globalRow <= Mdim) && (globalCol <= Pdim)){ 11 | 12 | if(order == 0){ 13 | A[globalRow * MdimPad + globalCol] = alpha * A[globalRow * MdimPad + globalCol] + scalar; 14 | }else{ 15 | A[globalRow * MdimPad + globalCol] = A[globalRow * MdimPad + globalCol] + alpha * scalar; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /man/Compare-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/methods-gpuVector.R 3 | \docType{methods} 4 | \name{Compare,vector,gpuVector-method} 5 | \alias{Compare,vector,gpuVector-method} 6 | \alias{Compare-vector-gpuVector} 7 | \alias{Compare,gpuVector,vector-method} 8 | \alias{Compare-gpuVector-vector} 9 | \title{Compare vector and gpuVector elements} 10 | \usage{ 11 | \S4method{Compare}{vector,gpuVector}(e1, e2) 12 | 13 | \S4method{Compare}{gpuVector,vector}(e1, e2) 14 | } 15 | \arguments{ 16 | \item{e1}{A vector/gpuVector object} 17 | 18 | \item{e2}{A vector/gpuVector object} 19 | } 20 | \value{ 21 | A logical vector 22 | } 23 | \description{ 24 | Methods for comparison operators 25 | } 26 | \author{ 27 | Charles Determan Jr. 28 | } 29 | -------------------------------------------------------------------------------- /inst/CL/dScalarAXPY.cl: -------------------------------------------------------------------------------- 1 | __kernel void scalar_axpy( 2 | __global double *A, const double scalar, const double alpha, const int order, 3 | const int Mdim, const int Pdim, const int MdimPad) { 4 | 5 | // Get the index of the elements to be processed 6 | const int globalRow = get_global_id(0); // C Row ID 7 | const int globalCol = get_global_id(1); // C Col ID 8 | 9 | // Do the operation 10 | if((globalRow <= Mdim) && (globalCol <= Pdim)){ 11 | 12 | if(order == 0){ 13 | A[globalRow * MdimPad + globalCol] = alpha * A[globalRow * MdimPad + globalCol] + scalar; 14 | }else{ 15 | A[globalRow * MdimPad + globalCol] = A[globalRow * MdimPad + globalCol] + alpha * scalar; 16 | } 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /man/listContexts.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{listContexts} 4 | \alias{listContexts} 5 | \title{Available OpenCL Contexts} 6 | \usage{ 7 | listContexts() 8 | } 9 | \value{ 10 | data.frame containing the following fields 11 | 12 | \item{context}{Integer identifying context} 13 | 14 | \item{platform}{Character string listing OpenCL platform} 15 | 16 | \item{platform_index}{Integer identifying platform} 17 | 18 | \item{device}{Character string listing device name} 19 | 20 | \item{device_index}{Integer identifying device} 21 | 22 | \item{device_type}{Character string labeling device (e.g. gpu)} 23 | } 24 | \description{ 25 | Provide a data.frame of available OpenCL contexts and 26 | associated information. 27 | } 28 | -------------------------------------------------------------------------------- /man/qr.R-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/qr.R 3 | \docType{methods} 4 | \name{qr.R,gpuQR-method} 5 | \alias{qr.R,gpuQR-method} 6 | \alias{qr.Q,gpuQR-method} 7 | \title{Reconstruct the Q or R Matrices from a gpuQR Object} 8 | \usage{ 9 | \S4method{qr.R}{gpuQR}(qr, complete = FALSE) 10 | 11 | \S4method{qr.Q}{gpuQR}(qr, complete = FALSE) 12 | } 13 | \arguments{ 14 | \item{qr}{\code{gpuQR} object} 15 | 16 | \item{complete}{not currently used} 17 | } 18 | \value{ 19 | \code{qr.Q} returns all of \code{Q} 20 | \code{qr.R} returns all of \code{R} 21 | } 22 | \description{ 23 | Returns the components of the QR decomposition. 24 | } 25 | \seealso{ 26 | \link[base]{qr.R}, \link[base]{qr.Q} 27 | } 28 | \author{ 29 | Charles Determan Jr. 30 | } 31 | -------------------------------------------------------------------------------- /man/deviceHasDouble.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/wrappers-utils.R 3 | \name{deviceHasDouble} 4 | \alias{deviceHasDouble} 5 | \title{Check GPU double precision support} 6 | \usage{ 7 | deviceHasDouble(gpu_idx = currentDevice()$device_index, 8 | context_idx = currentContext()) 9 | } 10 | \arguments{ 11 | \item{gpu_idx}{An integer value indicating which gpu to query.} 12 | 13 | \item{context_idx}{An integer value indicating which context to query.} 14 | } 15 | \value{ 16 | A boolean designating whether the device supports double precision 17 | } 18 | \description{ 19 | This function checks the GPU device extensions for the 20 | variable cl_khr_fp64 which means the device supports double precision. 21 | } 22 | \seealso{ 23 | \link{gpuInfo} 24 | } 25 | -------------------------------------------------------------------------------- /man/det-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/methods-vclMatrix.R, R/methods.R 3 | \docType{methods} 4 | \name{det,vclMatrix-method} 5 | \alias{det,vclMatrix-method} 6 | \alias{det,vclMatrix} 7 | \alias{det,gpuMatrix-method} 8 | \title{Calculate Determinant of a Matrix on GPU} 9 | \usage{ 10 | \S4method{det}{vclMatrix}(x) 11 | 12 | \S4method{det}{gpuMatrix}(x) 13 | } 14 | \arguments{ 15 | \item{x}{A gpuR matrix object} 16 | } 17 | \value{ 18 | The determine of \code{x} 19 | } 20 | \description{ 21 | \code{det} calculates the determinant of a matrix. 22 | } 23 | \note{ 24 | This function uses an LU decomposition and the \code{det} 25 | function is simply a wrapper returning the determinant product 26 | } 27 | \author{ 28 | Charles Determan Jr. 29 | } 30 | -------------------------------------------------------------------------------- /man/gpuMatrix.colSums.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/methods.R 3 | \docType{methods} 4 | \name{colSums,gpuMatrix-method} 5 | \alias{colSums,gpuMatrix-method} 6 | \alias{colSums,gpuMatrix} 7 | \alias{rowSums,gpuMatrix-method} 8 | \alias{colMeans,gpuMatrix-method} 9 | \alias{rowMeans,gpuMatrix-method} 10 | \title{Row and Column Sums and Means of gpuMatrix} 11 | \usage{ 12 | \S4method{colSums}{gpuMatrix}(x) 13 | 14 | \S4method{rowSums}{gpuMatrix}(x) 15 | 16 | \S4method{colMeans}{gpuMatrix}(x) 17 | 18 | \S4method{rowMeans}{gpuMatrix}(x) 19 | } 20 | \arguments{ 21 | \item{x}{A gpuMatrix object} 22 | } 23 | \value{ 24 | A gpuVector object 25 | } 26 | \description{ 27 | Row and column sums and of gpuMatrix objects 28 | } 29 | \author{ 30 | Charles Determan Jr. 31 | } 32 | -------------------------------------------------------------------------------- /man/vclMatrix.colSums.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/methods-vclMatrix.R 3 | \docType{methods} 4 | \name{colSums,vclMatrix-method} 5 | \alias{colSums,vclMatrix-method} 6 | \alias{colSums,vclMatrix} 7 | \alias{rowSums,vclMatrix-method} 8 | \alias{colMeans,vclMatrix-method} 9 | \alias{rowMeans,vclMatrix-method} 10 | \title{Row and Column Sums and Means of vclMatrix} 11 | \usage{ 12 | \S4method{colSums}{vclMatrix}(x) 13 | 14 | \S4method{rowSums}{vclMatrix}(x) 15 | 16 | \S4method{colMeans}{vclMatrix}(x) 17 | 18 | \S4method{rowMeans}{vclMatrix}(x) 19 | } 20 | \arguments{ 21 | \item{x}{A vclMatrix object} 22 | } 23 | \value{ 24 | A gpuVector object 25 | } 26 | \description{ 27 | Row and column sums and of vclMatrix objects 28 | } 29 | \author{ 30 | Charles Determan Jr. 31 | } 32 | -------------------------------------------------------------------------------- /inst/CL/fset_row_order.cl: -------------------------------------------------------------------------------- 1 | __kernel void set_row_order( 2 | __global const float *A, __global float *B, __global const int *indices, 3 | const int Mdim, const int Pdim, const int MdimPad) { 4 | 5 | // Get the index of the elements to be processed 6 | const int globalRow = get_global_id(0); // C Row ID 7 | const int globalCol = get_global_id(1); // C Col ID 8 | 9 | // Do the operation 10 | if((globalRow <= Mdim) && (globalCol <= Pdim)){ 11 | 12 | //printf("index = %i\n", indices[globalRow]); 13 | //printf("globalRow = %i\n", globalRow); 14 | 15 | //if(globalRow == 0 && globalCol == 0){ 16 | // prinf("new index") 17 | //} 18 | 19 | B[globalRow * MdimPad + globalCol] = A[indices[globalRow] * MdimPad + globalCol]; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /man/nrow-gpuR.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/methods-vclMatrix.R, R/methods.R 3 | \docType{methods} 4 | \name{nrow,vclMatrix-method} 5 | \alias{nrow,vclMatrix-method} 6 | \alias{ncol,vclMatrix-method} 7 | \alias{nrow,gpuMatrix-method} 8 | \alias{ncol,gpuMatrix-method} 9 | \title{The Number of Rows/Columns of a gpuR matrix} 10 | \usage{ 11 | \S4method{nrow}{vclMatrix}(x) 12 | 13 | \S4method{ncol}{vclMatrix}(x) 14 | 15 | \S4method{nrow}{gpuMatrix}(x) 16 | 17 | \S4method{ncol}{gpuMatrix}(x) 18 | } 19 | \arguments{ 20 | \item{x}{A gpuMatrix/vclMatrix object} 21 | } 22 | \value{ 23 | An integer of length 1 24 | } 25 | \description{ 26 | \code{nrow} and \code{ncol} return the number of rows or columns 27 | present in \code{x} respectively. 28 | } 29 | \author{ 30 | Charles Determan Jr. 31 | } 32 | -------------------------------------------------------------------------------- /man/as.gpuVector-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generics.R, R/methods-gpuVector.R 3 | \docType{methods} 4 | \name{as.gpuVector} 5 | \alias{as.gpuVector} 6 | \alias{as.gpuVector,vector-method} 7 | \alias{as.gpuVector,vector} 8 | \title{Convert object to a gpuVector} 9 | \usage{ 10 | as.gpuVector(object, type) 11 | 12 | \S4method{as.gpuVector}{vector}(object, type = NULL) 13 | } 14 | \arguments{ 15 | \item{object}{An object that is or can be converted to a 16 | \code{vector} object} 17 | 18 | \item{type}{A character string specifying the type of gpuVector. Default 19 | is NULL where type is inherited from the source data type.} 20 | } 21 | \value{ 22 | A gpuVector object 23 | } 24 | \description{ 25 | Construct a gpuVector of a class that inherits 26 | from \code{gpuVector} 27 | } 28 | \author{ 29 | Charles Determan Jr. 30 | } 31 | -------------------------------------------------------------------------------- /man/identity_matrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/methods-vclMatrix.R 3 | \name{identity_matrix} 4 | \alias{identity_matrix} 5 | \title{Identity Matrix on Device} 6 | \usage{ 7 | identity_matrix(x, type = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{A numeric value indicating the order of the identity matrix} 11 | 12 | \item{type}{A character string specifying the type of gpuMatrix. Default 13 | is derived from \code{getOption("gpuR.default.type")}.} 14 | } 15 | \value{ 16 | A \code{vclMatrix} object 17 | } 18 | \description{ 19 | Creates an identity matrix directly on the current device 20 | (e.g. GPU) 21 | } 22 | \note{ 23 | This function was only created for \code{vclMatrix} objects as 24 | the copy from CPU to \code{gpuMatrix} is trivial using the base 25 | \link[base]{diag} function. 26 | } 27 | \author{ 28 | Charles Determan Jr. 29 | } 30 | -------------------------------------------------------------------------------- /man/length-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/methods-gpuVector.R, R/methods-vclMatrix.R, 3 | % R/methods-vclVector.R, R/methods.R 4 | \docType{methods} 5 | \name{length,gpuVector-method} 6 | \alias{length,gpuVector-method} 7 | \alias{length,vclMatrix-method} 8 | \alias{length-vclMatrix} 9 | \alias{length,vclVector-method} 10 | \alias{length,gpuMatrix-method} 11 | \alias{length-gpuMatrix} 12 | \title{gpuMatrix/vclMatrix length method} 13 | \usage{ 14 | \S4method{length}{gpuVector}(x) 15 | 16 | \S4method{length}{vclMatrix}(x) 17 | 18 | \S4method{length}{vclVector}(x) 19 | 20 | \S4method{length}{gpuMatrix}(x) 21 | } 22 | \arguments{ 23 | \item{x}{A gpuMatrix/vclMatrix object} 24 | } 25 | \value{ 26 | A numeric value 27 | } 28 | \description{ 29 | Retrieve number of elements in object 30 | } 31 | \author{ 32 | Charles Determan Jr. 33 | } 34 | -------------------------------------------------------------------------------- /inst/CL/dset_row_order2.cl: -------------------------------------------------------------------------------- 1 | __kernel void set_row_order( 2 | __global const double *A, __global double *B, __global const int *indices, 3 | const int Mdim, const int globalCol, const int MdimPad) { 4 | 5 | // Get the index of the elements to be processed 6 | const int globalRow = get_global_id(0); // C Row ID 7 | //const int globalCol = get_global_id(1); // C Col ID 8 | 9 | // Do the operation 10 | if(globalRow < Mdim){ 11 | 12 | //printf("Mdim: %d\n", Mdim); 13 | //printf("globalRow: %d\n", globalRow); 14 | 15 | //printf("index: %d\n", indices[globalRow]); 16 | //printf("final index: %d\n", indices[globalRow] * MdimPad + globalCol); 17 | //printf("A index: %f\n", A[indices[globalRow] * MdimPad + globalCol]); 18 | 19 | B[globalRow] = A[indices[globalRow] * MdimPad + globalCol]; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /man/assert_has_double.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/asserts.R 3 | \name{assert_has_double} 4 | \alias{assert_has_double} 5 | \title{Does device have 'double' support?} 6 | \usage{ 7 | assert_has_double(device_idx, context_idx, 8 | severity = getOption("assertive.severity", "stop")) 9 | } 10 | \arguments{ 11 | \item{device_idx}{An integer indicating which device to query} 12 | 13 | \item{context_idx}{An integer indicating which context to query} 14 | 15 | \item{severity}{How severe should the consequences of the assertion be?} 16 | } 17 | \value{ 18 | Returns nothing but throws an error if device does not support 19 | double precision 20 | } 21 | \description{ 22 | Function to query if device (identified by index) supports 23 | double precision 24 | } 25 | \seealso{ 26 | \link{deviceHasDouble} 27 | } 28 | \author{ 29 | Charles Determan Jr. 30 | } 31 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | gpuR 2 | 3 | ======== 4 | 5 | This package is functional for all OS systems (to my knowledge). 6 | If installation fails, after consulting the wiki mentioned below, 7 | please feel free to submit an issue on the project github 8 | (https://github.com/cdeterman/gpuR/issues) 9 | 10 | In order for it to work you will need some form of OpenCL installed 11 | on your machine. Windows systems often have a simple Intel OpenCL 12 | installed by default and OSX have OpenCL installed by default 13 | for their graphics processors. For most Linux systems, you 14 | will likely need to install either a vendor specific SDK 15 | or look in to installing a non-vendor specification implementation 16 | like 'pocl'. Follow your vendor specific instructions to install. 17 | 18 | The installation of this package is OS specific. For detailed 19 | instructions please see my github wiki (https://github.com/cdeterman/gpuR/wiki). -------------------------------------------------------------------------------- /src/synchronize.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "gpuR/windows_check.hpp" 4 | 5 | // Use OpenCL with ViennaCL 6 | #define VIENNACL_WITH_OPENCL 1 7 | 8 | // Use ViennaCL algorithms on Eigen objects 9 | #define VIENNACL_WITH_EIGEN 1 10 | 11 | // ViennaCL headers 12 | #include "viennacl/backend/memory.hpp" 13 | 14 | #include 15 | 16 | 17 | //' @title Synchronize Device Execution 18 | //' @description This pauses execution until the processing is complete 19 | //' on the device (CPU/GPU/etc.). This is important especially for 20 | //' benchmarking applications. 21 | //' @return NULL 22 | //' @author Charles Determan Jr. 23 | //' @examples \dontrun{ 24 | //' mat <- vclMatrix(rnorm(500^2), ncol = 500, nrow = 500) 25 | //' system.time(mat %*% mat) 26 | //' system.time(mat %*% mat; synchronize()) 27 | //' } 28 | //' @export 29 | // [[Rcpp::export]] 30 | void synchronize(){ 31 | viennacl::backend::finish(); 32 | return; 33 | } 34 | -------------------------------------------------------------------------------- /R/zzz.R: -------------------------------------------------------------------------------- 1 | #' @importFrom utils strOptions packageVersion tail 2 | 3 | .onLoad <- function(libname, pkgname) { 4 | options(gpuR.print.warning=TRUE) 5 | options(gpuR.default.type = "float") 6 | # options(gpuR.default.device.type = "gpu") 7 | } 8 | 9 | .onAttach <- function(libname, pkgname) { 10 | # Initialize all possible contexts 11 | if (!identical(Sys.getenv("APPVEYOR"), "True")) { 12 | # initialize contexts 13 | # default_device <- initContexts() 14 | initContexts() 15 | # print("context initialization successful") 16 | # packageStartupMessage(paste0("gpuR ", packageVersion('gpuR'), "\nDefault device: ", default_device)) 17 | packageStartupMessage(paste0("gpuR ", packageVersion('gpuR'))) 18 | # print("startup message not problem") 19 | } 20 | } 21 | 22 | .onUnload <- function(libpath) { 23 | options(gpuR.print.warning=NULL) 24 | options(gpuR.default.type = NULL) 25 | # options(gpuR.default.device.type = NULL) 26 | } 27 | -------------------------------------------------------------------------------- /man/setup_opencl.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/custom_opencl.R 3 | \name{setup_opencl} 4 | \alias{setup_opencl} 5 | \title{Setup OpenCL Arguments} 6 | \usage{ 7 | setup_opencl(objects, intents, queues, kernel_maps = NULL) 8 | } 9 | \arguments{ 10 | \item{objects}{character vector of gpuR objects to be passed} 11 | 12 | \item{intents}{character vector specifying 'intent' of gpuR objects. 13 | options include \code{"IN"},\code{"OUT"},\code{"INOUT"}} 14 | 15 | \item{queues}{list of character vectors reflecting equal length to \code{"objects"} 16 | where each element reflects a kernel function defined in an OpenCL kernel file.} 17 | 18 | \item{kernel_maps}{The corresponding arguments names in the provided OpenCL kernel 19 | corresponds to the gpuR objects passed and contains a character vector of 20 | which kernels the object will be enqueued.} 21 | } 22 | \description{ 23 | Generates a \code{data.frame} of argument definitions 24 | for use in \code{\link{custom_opencl}} 25 | } 26 | -------------------------------------------------------------------------------- /man/solve-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/solve.R 3 | \docType{methods} 4 | \name{solve,vclMatrix,vclMatrix-method} 5 | \alias{solve,vclMatrix,vclMatrix-method} 6 | \alias{solve,vclMatrix,missing-method} 7 | \alias{solve,gpuMatrix,gpuMatrix-method} 8 | \alias{solve,gpuMatrix,missing-method} 9 | \title{Solve a System of Equations for gpuR objects} 10 | \usage{ 11 | \S4method{solve}{vclMatrix,vclMatrix}(a, b, ...) 12 | 13 | \S4method{solve}{vclMatrix,missing}(a, b, ...) 14 | 15 | \S4method{solve}{gpuMatrix,gpuMatrix}(a, b, ...) 16 | 17 | \S4method{solve}{gpuMatrix,missing}(a, b, ...) 18 | } 19 | \arguments{ 20 | \item{a}{A gpuR object} 21 | 22 | \item{b}{A gpuR object} 23 | 24 | \item{...}{further arguments passed to or from other methods} 25 | } 26 | \value{ 27 | A gpuR object 28 | } 29 | \description{ 30 | This function solves the equation \code{a \%*\% x = b} for 31 | \code{x}, where \code{b} can be either a vector or a matrix. 32 | } 33 | \author{ 34 | Charles Determan Jr. 35 | } 36 | -------------------------------------------------------------------------------- /man/Math-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/methods-gpuVector.R, R/methods-vclMatrix.R, 3 | % R/methods-vclVector.R, R/methods.R 4 | \docType{methods} 5 | \name{Math,gpuVector-method} 6 | \alias{Math,gpuVector-method} 7 | \alias{Math,vclMatrix-method} 8 | \alias{Math,vclVector-method} 9 | \alias{Math,gpuMatrix-method} 10 | \alias{Math-gpuR-method} 11 | \title{gpuR Math methods} 12 | \usage{ 13 | \S4method{Math}{gpuVector}(x) 14 | 15 | \S4method{Math}{vclMatrix}(x) 16 | 17 | \S4method{Math}{vclVector}(x) 18 | 19 | \S4method{Math}{gpuMatrix}(x) 20 | } 21 | \arguments{ 22 | \item{x}{A gpuR object} 23 | } 24 | \value{ 25 | A gpuR object 26 | } 27 | \description{ 28 | Methods for the base Math methods \link[methods]{S4groupGeneric} 29 | } 30 | \details{ 31 | Currently implemented methods include: 32 | \itemize{ 33 | \item{"sin", "cos", "tan", "asin", "acos", "atan", "sinh", "cosh", "tanh", 34 | "log10", "exp", "abs", "sqrt", "sign"} 35 | } 36 | } 37 | \author{ 38 | Charles Determan Jr. 39 | } 40 | -------------------------------------------------------------------------------- /inst/testWithGPU/testthat/test_gpuMatrix_cov.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("gpuMatrix Correlations") 3 | 4 | # set seed 5 | set.seed(123) 6 | 7 | ORDER_X <- 4 8 | ORDER_Y <- 5 9 | 10 | # Base R objects 11 | A <- matrix(rnorm(ORDER_X*ORDER_Y), nrow=ORDER_X, ncol=ORDER_Y) 12 | 13 | C <- cov(A) 14 | 15 | 16 | test_that("gpuMatrix Single Precision Pearson Covariance", 17 | { 18 | has_gpu_skip() 19 | 20 | fgpuX <- gpuMatrix(A, type="float") 21 | 22 | gpuC <- cov(fgpuX) 23 | 24 | expect_is(gpuC, "fgpuMatrix") 25 | expect_equal(gpuC[], C, tolerance=1e-06, 26 | info="float covariance values not equivalent") 27 | }) 28 | 29 | test_that("gpuMatrix Double Precision Pearson Covariance", 30 | { 31 | 32 | has_gpu_skip() 33 | has_double_skip() 34 | 35 | dgpuX <- gpuMatrix(A, type="double") 36 | 37 | gpuC <- cov(dgpuX) 38 | 39 | expect_is(gpuC, "dgpuMatrix") 40 | expect_equal(gpuC[], C, tolerance=.Machine$double.eps ^ 0.5, 41 | info="double colSums not equivalent") 42 | }) 43 | -------------------------------------------------------------------------------- /inst/testWithGPU/testthat/test_vclMatrix_cov.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("vclMatrix Correlations") 3 | 4 | # set seed 5 | set.seed(123) 6 | 7 | ORDER_X <- 4 8 | ORDER_Y <- 5 9 | 10 | # Base R objects 11 | A <- matrix(rnorm(ORDER_X*ORDER_Y), nrow=ORDER_X, ncol=ORDER_Y) 12 | 13 | C <- cov(A) 14 | 15 | 16 | test_that("vclMatrix Single Precision Pearson Covariance", 17 | { 18 | has_gpu_skip() 19 | 20 | fgpuX <- vclMatrix(A, type="float") 21 | 22 | gpuC <- cov(fgpuX) 23 | 24 | expect_is(gpuC, "fvclMatrix") 25 | expect_equal(gpuC[], C, tolerance=1e-06, 26 | info="float covariance values not equivalent") 27 | }) 28 | 29 | test_that("vclMatrix Double Precision Pearson Covariance", 30 | { 31 | 32 | has_gpu_skip() 33 | has_double_skip() 34 | 35 | dgpuX <- vclMatrix(A, type="double") 36 | 37 | gpuC <- cov(dgpuX) 38 | 39 | expect_is(gpuC, "dvclMatrix") 40 | expect_equal(gpuC[], C, tolerance=.Machine$double.eps ^ 0.5, 41 | info="double colSums not equivalent") 42 | }) 43 | -------------------------------------------------------------------------------- /inst/testWithGPU/testthat/test_gpuMatrix_dist.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("gpuMatrix Distance Computations") 3 | 4 | # set seed 5 | set.seed(123) 6 | 7 | ORDER <- 4 8 | 9 | # Base R objects 10 | A <- matrix(rnorm(ORDER^2), nrow=ORDER, ncol=ORDER) 11 | 12 | D <- as.matrix(dist(A)) 13 | 14 | test_that("gpuMatrix Single Precision Euclidean Distance", 15 | { 16 | 17 | has_gpu_skip() 18 | 19 | fgpuX <- gpuMatrix(A, type="float") 20 | 21 | E <- dist(fgpuX) 22 | 23 | expect_equal(E[], D, tolerance=1e-06, 24 | info="float euclidean distances not equivalent", 25 | check.attributes=FALSE) 26 | }) 27 | 28 | test_that("gpuMatrix Double Precision Euclidean Distance", 29 | { 30 | 31 | has_gpu_skip() 32 | has_double_skip() 33 | 34 | fgpuX <- gpuMatrix(A, type="double") 35 | 36 | E <- dist(fgpuX) 37 | 38 | expect_equal(E[], D, tolerance=.Machine$double.eps ^ 0.5, 39 | info="double euclidean distances not equivalent", 40 | check.attributes=FALSE) 41 | }) 42 | -------------------------------------------------------------------------------- /inst/testWithGPU/testthat/test_vclMatrix_dist.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("vclMatrix Distance Computations") 3 | 4 | # set seed 5 | set.seed(123) 6 | 7 | ORDER <- 4 8 | 9 | # Base R objects 10 | A <- matrix(rnorm(ORDER^2), nrow=ORDER, ncol=ORDER) 11 | 12 | D <- as.matrix(dist(A)) 13 | 14 | test_that("vclMatrix Single Precision Euclidean Distance", 15 | { 16 | 17 | has_gpu_skip() 18 | 19 | fgpuX <- vclMatrix(A, type="float") 20 | 21 | E <- dist(fgpuX) 22 | 23 | expect_equal(E[], D, tolerance=1e-06, 24 | info="float euclidean distances not equivalent", 25 | check.attributes=FALSE) 26 | }) 27 | 28 | test_that("vclMatrix Double Precision Euclidean Distance", 29 | { 30 | 31 | has_gpu_skip() 32 | has_double_skip() 33 | 34 | fgpuX <- vclMatrix(A, type="double") 35 | 36 | E <- dist(fgpuX) 37 | 38 | expect_equal(E[], D, tolerance=.Machine$double.eps ^ 0.5, 39 | info="double euclidean distances not equivalent", 40 | check.attributes=FALSE) 41 | }) 42 | -------------------------------------------------------------------------------- /tests/testthat/test_cpu_shared_memory.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("CPU vclVector shared memory") 3 | 4 | current_context <- set_device_context("cpu") 5 | 6 | # set seed 7 | set.seed(123) 8 | 9 | ORDER <- 4 10 | 11 | # Base R objects 12 | A <- matrix(rnorm(ORDER^2), nrow=ORDER, ncol=ORDER) 13 | 14 | test_that("Share memory between vclMatrix & vclVector", { 15 | 16 | has_cpu_skip() 17 | 18 | gpuA <- vclMatrix(A, type = "float") 19 | 20 | # convert to vector 21 | gpuB <- as.vclVector(gpuA, shared = TRUE) 22 | 23 | expect_is(gpuB, "fvclVector") 24 | expect_equal(gpuA[1], gpuB[1], tolerance=1e-07, 25 | info="float elements not equivalent") 26 | 27 | gpuA <- vclMatrix(A, type = "double") 28 | 29 | # convert to vector 30 | gpuB <- as.vclVector(gpuA, shared = TRUE) 31 | 32 | gpuB[1] <- 42 33 | 34 | expect_is(gpuB, "dvclVector") 35 | expect_equal(gpuA[1], gpuB[1], tolerance=.Machine$double.eps^0.5, 36 | info="double elements not equivalent") 37 | }) 38 | 39 | setContext(current_context) 40 | -------------------------------------------------------------------------------- /inst/CL/basic_gemm.cl: -------------------------------------------------------------------------------- 1 | __kernel void iMatMult(const int A_size1, 2 | const int A_internal_size1, 3 | const int B_size1, 4 | const int B_size2, 5 | const int B_internal_size2, 6 | const int C_internal_size2, 7 | __global const int *A, __global const int *B, __global int *C) { 8 | 9 | // Get the index of the elements to be processed 10 | const int globalRow = get_global_id(0); // C Row ID 11 | const int globalCol = get_global_id(1); // C Col ID 12 | int tmp = 0; 13 | 14 | // Do the operation 15 | if((globalRow < A_size1) && (globalCol < B_size2)){ 16 | //if((globalRow == 1) && (globalCol < 1)){ 17 | 18 | // for each row in B column 19 | // multiply the A element 20 | for(int k=0; k < B_size1; k++){ 21 | 22 | tmp += A[globalRow * A_internal_size1 + k] * B[globalCol+B_internal_size2*k]; 23 | } 24 | 25 | C[globalCol+C_internal_size2*globalRow] = tmp; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/testthat/test_cpu_gpuMatrix_cov.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("CPU gpuMatrix Correlations") 3 | 4 | current_context <- set_device_context("cpu") 5 | 6 | # set seed 7 | set.seed(123) 8 | 9 | ORDER_X <- 4 10 | ORDER_Y <- 5 11 | 12 | # Base R objects 13 | A <- matrix(rnorm(ORDER_X*ORDER_Y), nrow=ORDER_X, ncol=ORDER_Y) 14 | 15 | C <- cov(A) 16 | 17 | 18 | test_that("CPU gpuMatrix Single Precision Pearson Covariance", 19 | { 20 | has_cpu_skip() 21 | 22 | fgpuX <- gpuMatrix(A, type="float") 23 | 24 | gpuC <- cov(fgpuX) 25 | 26 | expect_is(gpuC, "fgpuMatrix") 27 | expect_equal(gpuC[], C, tolerance=1e-06, 28 | info="float covariance values not equivalent") 29 | }) 30 | 31 | test_that("CPU gpuMatrix Double Precision Pearson Covariance", 32 | { 33 | has_cpu_skip() 34 | 35 | dgpuX <- gpuMatrix(A, type="double") 36 | 37 | gpuC <- cov(dgpuX) 38 | 39 | expect_is(gpuC, "dgpuMatrix") 40 | expect_equal(gpuC[], C, tolerance=.Machine$double.eps ^ 0.5, 41 | info="double colSums not equivalent") 42 | }) 43 | 44 | setContext(current_context) -------------------------------------------------------------------------------- /man/Summary-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/methods-gpuVector.R, R/methods-vclMatrix.R, 3 | % R/methods-vclVector.R, R/methods.R 4 | \docType{methods} 5 | \name{Summary,gpuVector-method} 6 | \alias{Summary,gpuVector-method} 7 | \alias{Summary,vclMatrix-method} 8 | \alias{Summary,vclVector-method} 9 | \alias{Summary,gpuMatrix-method} 10 | \alias{Summary-gpuR-method} 11 | \title{gpuR Summary methods} 12 | \usage{ 13 | \S4method{Summary}{gpuVector}(x, ..., na.rm = FALSE) 14 | 15 | \S4method{Summary}{vclMatrix}(x, ..., na.rm = FALSE) 16 | 17 | \S4method{Summary}{vclVector}(x, ..., na.rm = FALSE) 18 | 19 | \S4method{Summary}{gpuMatrix}(x, ..., na.rm = FALSE) 20 | } 21 | \arguments{ 22 | \item{x}{A gpuR object} 23 | 24 | \item{...}{Additional arguments passed to method (not currently used)} 25 | 26 | \item{na.rm}{a logical indicating whether missing values should be removed ( 27 | not currently used)} 28 | } 29 | \value{ 30 | For \code{min} or \code{max}, a length-one vector 31 | } 32 | \description{ 33 | Methods for the base Summary methods \link[methods]{S4groupGeneric} 34 | } 35 | -------------------------------------------------------------------------------- /include/gpuR/utils.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GPUR_UTILS 2 | #define GPUR_UTILS 3 | 4 | #include 5 | 6 | inline 7 | std::vector 8 | split(const std::string &s, char delim) { 9 | std::stringstream ss(s); 10 | std::string item; 11 | std::vector tokens; 12 | while (getline(ss, item, delim)) { 13 | tokens.push_back(item); 14 | } 15 | return tokens; 16 | } 17 | 18 | 19 | // Function to round down a valid to nearest 'multiple' (e.g. 16) 20 | inline 21 | int 22 | roundDown(int numToRound, int multiple) 23 | { 24 | if (multiple == 0) 25 | return numToRound; 26 | 27 | int remainder = numToRound % multiple; 28 | if (remainder == 0 || remainder == numToRound) 29 | return numToRound; 30 | 31 | return numToRound - remainder; 32 | } 33 | 34 | inline 35 | int 36 | roundUp(int numToRound, int multiple) 37 | { 38 | if (multiple == 0) 39 | return numToRound; 40 | 41 | int remainder = numToRound % multiple; 42 | if (remainder == 0 || multiple == numToRound) 43 | return numToRound; 44 | 45 | return numToRound + multiple - remainder; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /man/colnames-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \docType{methods} 4 | \name{colnames} 5 | \alias{colnames} 6 | \alias{colnames.default} 7 | \alias{colnames.gpuMatrix} 8 | \alias{colnames<-,gpuMatrix-method} 9 | \alias{colnames.vclMatrix} 10 | \alias{colnames<-,vclMatrix-method} 11 | \title{Row and Column Names} 12 | \usage{ 13 | colnames(x, do.NULL, prefix) 14 | 15 | \method{colnames}{default}(x, do.NULL = TRUE, prefix = "col") 16 | 17 | \method{colnames}{gpuMatrix}(x, ...) 18 | 19 | \S4method{colnames}{gpuMatrix}(x) <- value 20 | 21 | \method{colnames}{vclMatrix}(x, ...) 22 | 23 | \S4method{colnames}{vclMatrix}(x) <- value 24 | } 25 | \arguments{ 26 | \item{x}{A gpuR matrix object} 27 | 28 | \item{do.NULL}{logical. If \code{FALSE} names are NULL, names are created. 29 | (not currently used)} 30 | 31 | \item{prefix}{for create names. (not currently used)} 32 | 33 | \item{...}{Additional arguments} 34 | 35 | \item{value}{A character vector to assign as row/column names} 36 | } 37 | \description{ 38 | Retrieve or set the row or column names of a gpuR matrix object 39 | } 40 | -------------------------------------------------------------------------------- /inst/include/gpuR/utils.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GPUR_UTILS 2 | #define GPUR_UTILS 3 | 4 | #include 5 | 6 | inline 7 | std::vector 8 | split(const std::string &s, char delim) { 9 | std::stringstream ss(s); 10 | std::string item; 11 | std::vector tokens; 12 | while (getline(ss, item, delim)) { 13 | tokens.push_back(item); 14 | } 15 | return tokens; 16 | } 17 | 18 | 19 | // Function to round down a valid to nearest 'multiple' (e.g. 16) 20 | inline 21 | int 22 | roundDown(int numToRound, int multiple) 23 | { 24 | if (multiple == 0) 25 | return numToRound; 26 | 27 | int remainder = numToRound % multiple; 28 | if (remainder == 0 || remainder == numToRound) 29 | return numToRound; 30 | 31 | return numToRound - remainder; 32 | } 33 | 34 | inline 35 | int 36 | roundUp(int numToRound, int multiple) 37 | { 38 | if (multiple == 0) 39 | return numToRound; 40 | 41 | int remainder = numToRound % multiple; 42 | if (remainder == 0 || multiple == numToRound) 43 | return numToRound; 44 | 45 | return numToRound + multiple - remainder; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /man/chol-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/chol.R 3 | \name{chol.vclMatrix} 4 | \alias{chol.vclMatrix} 5 | \alias{chol.gpuMatrix} 6 | \title{Cholesky Decomposition of a gpuR matrix} 7 | \usage{ 8 | \method{chol}{vclMatrix}(x, ...) 9 | 10 | \method{chol}{gpuMatrix}(x, ...) 11 | } 12 | \arguments{ 13 | \item{x}{A symmetric, positive-definite gpuR matrix object.} 14 | 15 | \item{...}{arguments to be passed to or from methods} 16 | } 17 | \value{ 18 | Default - the upper triangular factor of the Choleski decomposition, 19 | i.e. the matrix \emph{R} such that \emph{R'R} = x. 20 | } 21 | \description{ 22 | Compute the Choleski factorization of a real symmetric 23 | positive-definite square matrix. 24 | } 25 | \note{ 26 | This an S3 generic of \link[base]{chol}. The default continues 27 | to point to the default base function. 28 | 29 | No pivoting is used. 30 | 31 | The argument \code{upper} is additionally accepted representing a boolean 32 | which will indicate if the upper or lower (\code{FALSE}) triangle 33 | should be solved. 34 | } 35 | \seealso{ 36 | \link[base]{chol} 37 | } 38 | \author{ 39 | Charles Determan Jr. 40 | } 41 | -------------------------------------------------------------------------------- /man/gpuVector-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-gpuVector.R 3 | \docType{class} 4 | \name{gpuVector-class} 5 | \alias{gpuVector-class} 6 | \title{gpuVector Class} 7 | \description{ 8 | This is the 'mother' class for all 9 | gpuVector objects. All other gpuVector classes 10 | inherit from this class but there are no current 11 | circumstances where this class is used directly. 12 | 13 | There are multiple child classes that correspond 14 | to the particular data type contained. These include 15 | \code{igpuVector}. 16 | } 17 | \section{Slots}{ 18 | 19 | Common to all vclMatrix objects in the package 20 | \describe{ 21 | \item{\code{address}:}{Pointer to data matrix} 22 | \item{\code{.context_index}:}{Integer index of OpenCL contexts} 23 | \item{\code{.platform_index}:}{Integer index of OpenCL platforms} 24 | \item{\code{.platform}:}{Name of OpenCL platform} 25 | \item{\code{.device_index}:}{Integer index of active device} 26 | \item{\code{.device}:}{Name of active device} 27 | } 28 | } 29 | 30 | \seealso{ 31 | \code{\link{igpuVector-class}} 32 | } 33 | \author{ 34 | Charles Determan Jr. 35 | } 36 | -------------------------------------------------------------------------------- /man/vclVector-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-vclVector.R 3 | \docType{class} 4 | \name{vclVector-class} 5 | \alias{vclVector-class} 6 | \title{vclVector Class} 7 | \description{ 8 | This is the 'mother' class for all 9 | vclVector objects. All other vclVector classes 10 | inherit from this class but there are no current 11 | circumstances where this class is used directly. 12 | 13 | There are multiple child classes that correspond 14 | to the particular data type contained. These include 15 | \code{ivclVector}. 16 | } 17 | \section{Slots}{ 18 | 19 | Common to all vclMatrix objects in the package 20 | \describe{ 21 | \item{\code{address}:}{Pointer to data matrix} 22 | \item{\code{.context_index}:}{Integer index of OpenCL contexts} 23 | \item{\code{.platform_index}:}{Integer index of OpenCL platforms} 24 | \item{\code{.platform}:}{Name of OpenCL platform} 25 | \item{\code{.device_index}:}{Integer index of active device} 26 | \item{\code{.device}:}{Name of active device} 27 | } 28 | } 29 | 30 | \seealso{ 31 | \code{\link{ivclVector-class}} 32 | } 33 | \author{ 34 | Charles Determan Jr. 35 | } 36 | -------------------------------------------------------------------------------- /tests/testthat/test_cpu_order.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("CPU Ordering Methods") 3 | 4 | current_context <- set_device_context("cpu") 5 | 6 | # set seed 7 | set.seed(123) 8 | 9 | ORDER <- 4 10 | 11 | # Base R objects 12 | A <- matrix(rnorm(ORDER^2), nrow=ORDER) 13 | idx <- sample(seq.int(ORDER), ORDER) 14 | 15 | C <- A[idx,] 16 | 17 | test_that("CPU vclMatrix permute", 18 | { 19 | has_cpu_skip() 20 | 21 | fgpuX <- vclMatrix(A, type="float") 22 | 23 | gpuC <- permute(fgpuX, order = idx) 24 | 25 | expect_is(gpuC, "fvclMatrix") 26 | expect_equal(gpuC[], C, tolerance=1e-06, 27 | info="float row permutations not equivalent") 28 | 29 | fgpuX <- vclMatrix(A, type="double") 30 | 31 | gpuC <- permute(fgpuX, order = idx) 32 | 33 | expect_is(gpuC, "dvclMatrix") 34 | expect_equal(gpuC[], C, tolerance=.Machine$double.eps^0.5, 35 | info="double row permutations not equivalent") 36 | }) 37 | 38 | setContext(current_context) 39 | -------------------------------------------------------------------------------- /man/as.vclVector-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generics.R, R/methods-vclVector.R 3 | \docType{methods} 4 | \name{as.vclVector} 5 | \alias{as.vclVector} 6 | \alias{as.vclVector,vector-method} 7 | \alias{as.vclVector,vector} 8 | \alias{as.vclVector,vclMatrix-method} 9 | \alias{as.vclVector,vclMatrix} 10 | \title{Convert object to a vclVector} 11 | \usage{ 12 | as.vclVector(object, type = NULL, ...) 13 | 14 | \S4method{as.vclVector}{vector}(object, type = NULL) 15 | 16 | \S4method{as.vclVector}{vclMatrix}(object, type = NULL, shared = FALSE) 17 | } 18 | \arguments{ 19 | \item{object}{An object that is or can be converted to a 20 | \code{vector} object} 21 | 22 | \item{type}{A character string specifying the type of vclVector. Default 23 | is NULL where type is inherited from the source data type.} 24 | 25 | \item{...}{Additional arguments to as.vclVector methods} 26 | 27 | \item{shared}{Logical indicating if memory should be shared with \code{x}} 28 | } 29 | \value{ 30 | A vclVector object 31 | } 32 | \description{ 33 | Construct a vclVector of a class that inherits 34 | from \code{vclVector} 35 | } 36 | \author{ 37 | Charles Determan Jr. 38 | } 39 | -------------------------------------------------------------------------------- /inst/testWithGPU/testthat/test_cpu_gpuMatrix_dist.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("CPU gpuMatrix Distance Computations") 3 | 4 | # set option to use CPU instead of GPU 5 | options(gpuR.default.device.type = "cpu") 6 | 7 | # set seed 8 | set.seed(123) 9 | 10 | ORDER <- 4 11 | 12 | # Base R objects 13 | A <- matrix(rnorm(ORDER^2), nrow=ORDER, ncol=ORDER) 14 | 15 | D <- as.matrix(dist(A)) 16 | 17 | test_that("gpuMatrix Single Precision Euclidean Distance", 18 | { 19 | 20 | has_cpu_skip() 21 | 22 | fgpuX <- gpuMatrix(A, type="float") 23 | 24 | E <- dist(fgpuX) 25 | 26 | expect_equal(E[], D, tolerance=1e-06, 27 | info="float euclidean distances not equivalent", 28 | check.attributes=FALSE) 29 | }) 30 | 31 | test_that("gpuMatrix Double Precision Euclidean Distance", 32 | { 33 | 34 | has_cpu_skip() 35 | 36 | fgpuX <- gpuMatrix(A, type="double") 37 | 38 | E <- dist(fgpuX) 39 | 40 | expect_equal(E[], D, tolerance=.Machine$double.eps ^ 0.5, 41 | info="double euclidean distances not equivalent", 42 | check.attributes=FALSE) 43 | }) 44 | 45 | options(gpuR.default.device.type = "gpu") 46 | -------------------------------------------------------------------------------- /inst/testWithGPU/testthat/test_cpu_vclMatrix_dist.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("CPU vclMatrix Distance Computations") 3 | 4 | # set option to use CPU instead of GPU 5 | options(gpuR.default.device.type = "cpu") 6 | 7 | # set seed 8 | set.seed(123) 9 | 10 | ORDER <- 4 11 | 12 | # Base R objects 13 | A <- matrix(rnorm(ORDER^2), nrow=ORDER, ncol=ORDER) 14 | 15 | D <- as.matrix(dist(A)) 16 | 17 | test_that("vclMatrix Single Precision Euclidean Distance", 18 | { 19 | 20 | has_cpu_skip() 21 | 22 | fgpuX <- vclMatrix(A, type="float") 23 | 24 | E <- dist(fgpuX) 25 | 26 | expect_equal(E[], D, tolerance=1e-06, 27 | info="float euclidean distances not equivalent", 28 | check.attributes=FALSE) 29 | }) 30 | 31 | test_that("vclMatrix Double Precision Euclidean Distance", 32 | { 33 | 34 | has_cpu_skip() 35 | 36 | fgpuX <- vclMatrix(A, type="double") 37 | 38 | E <- dist(fgpuX) 39 | 40 | expect_equal(E[], D, tolerance=.Machine$double.eps ^ 0.5, 41 | info="double euclidean distances not equivalent", 42 | check.attributes=FALSE) 43 | }) 44 | 45 | options(gpuR.default.device.type = "gpu") 46 | 47 | -------------------------------------------------------------------------------- /man/svd-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/svd.R 3 | \name{svd} 4 | \alias{svd} 5 | \alias{svd.vclMatrix} 6 | \alias{svd.gpuMatrix} 7 | \title{Singular Value Decomposition of a gpuR matrix} 8 | \usage{ 9 | svd(x, nu, nv, LINPACK) 10 | 11 | \method{svd}{vclMatrix}(x, nu, nv, LINPACK) 12 | 13 | \method{svd}{gpuMatrix}(x, nu, nv, LINPACK) 14 | } 15 | \arguments{ 16 | \item{x}{A gpuR matrix} 17 | 18 | \item{nu}{ignored} 19 | 20 | \item{nv}{ignored} 21 | 22 | \item{LINPACK}{ignored} 23 | } 24 | \value{ 25 | The SVD decomposition of the matrix. The returned value is a list 26 | with the following components: 27 | \itemize{ 28 | \item{d} a vector containing the singular values of \code{x} 29 | \item{u} a matrix whose columns contain the left singular vectors of 30 | \code{x}. 31 | \item{v} a matrix whose columns contain the right singular vectors of 32 | \code{x}. 33 | } 34 | } 35 | \description{ 36 | Compute the singular-value decomposition of a gpuR matrix 37 | } 38 | \note{ 39 | This an S3 generic of \link[base]{svd}. The default continues 40 | to point to the default base function. 41 | } 42 | \seealso{ 43 | \link[base]{svd} 44 | } 45 | \author{ 46 | Charles Determan Jr. 47 | } 48 | -------------------------------------------------------------------------------- /inst/testWithGPU/testthat/test_cpu_gpuMatrix_cov.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("CPU gpuMatrix Correlations") 3 | 4 | # set option to use CPU instead of GPU 5 | options(gpuR.default.device.type = "cpu") 6 | 7 | # set seed 8 | set.seed(123) 9 | 10 | ORDER_X <- 4 11 | ORDER_Y <- 5 12 | 13 | # Base R objects 14 | A <- matrix(rnorm(ORDER_X*ORDER_Y), nrow=ORDER_X, ncol=ORDER_Y) 15 | 16 | C <- cov(A) 17 | 18 | 19 | test_that("CPU gpuMatrix Single Precision Pearson Covariance", 20 | { 21 | has_cpu_skip() 22 | 23 | fgpuX <- gpuMatrix(A, type="float") 24 | 25 | gpuC <- cov(fgpuX) 26 | 27 | expect_is(gpuC, "fgpuMatrix") 28 | expect_equal(gpuC[], C, tolerance=1e-06, 29 | info="float covariance values not equivalent") 30 | }) 31 | 32 | test_that("CPU gpuMatrix Double Precision Pearson Covariance", 33 | { 34 | has_cpu_skip() 35 | 36 | dgpuX <- gpuMatrix(A, type="double") 37 | 38 | gpuC <- cov(dgpuX) 39 | 40 | expect_is(gpuC, "dgpuMatrix") 41 | expect_equal(gpuC[], C, tolerance=.Machine$double.eps ^ 0.5, 42 | info="double colSums not equivalent") 43 | }) 44 | 45 | # set option to use CPU instead of GPU 46 | options(gpuR.default.device.type = "gpu") 47 | -------------------------------------------------------------------------------- /inst/testWithGPU/testthat/test_cpu_vclMatrix_cov.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("CPU vclMatrix Correlations") 3 | 4 | # set option to use CPU instead of GPU 5 | options(gpuR.default.device.type = "cpu") 6 | 7 | # set seed 8 | set.seed(123) 9 | 10 | ORDER_X <- 4 11 | ORDER_Y <- 5 12 | 13 | # Base R objects 14 | A <- matrix(rnorm(ORDER_X*ORDER_Y), nrow=ORDER_X, ncol=ORDER_Y) 15 | 16 | C <- cov(A) 17 | 18 | 19 | test_that("CPU vclMatrix Single Precision Pearson Covariance", 20 | { 21 | has_cpu_skip() 22 | 23 | fgpuX <- vclMatrix(A, type="float") 24 | 25 | gpuC <- cov(fgpuX) 26 | 27 | expect_is(gpuC, "fvclMatrix") 28 | expect_equal(gpuC[], C, tolerance=1e-06, 29 | info="float covariance values not equivalent") 30 | }) 31 | 32 | test_that("CPU vclMatrix Double Precision Pearson Covariance", 33 | { 34 | has_cpu_skip() 35 | 36 | dgpuX <- vclMatrix(A, type="double") 37 | 38 | gpuC <- cov(dgpuX) 39 | 40 | expect_is(gpuC, "dvclMatrix") 41 | expect_equal(gpuC[], C, tolerance=.Machine$double.eps ^ 0.5, 42 | info="double colSums not equivalent") 43 | }) 44 | 45 | # set option to use CPU instead of GPU 46 | options(gpuR.default.device.type = "gpu") 47 | -------------------------------------------------------------------------------- /man/diag-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/methods-vclMatrix.R, R/methods.R 3 | \docType{methods} 4 | \name{diag,vclMatrix-method} 5 | \alias{diag,vclMatrix-method} 6 | \alias{diag,vclMatrix} 7 | \alias{diag<-,vclMatrix,vclVector-method} 8 | \alias{diag<-,vclMatrix,vclVector} 9 | \alias{diag,gpuMatrix-method} 10 | \alias{diag,gpuMatrix} 11 | \alias{diag<-,gpuMatrix,gpuVector-method} 12 | \alias{diag<-,gpuMatrix,gpuVector} 13 | \title{gpuR Matrix Diagonals} 14 | \usage{ 15 | \S4method{diag}{vclMatrix}(x) 16 | 17 | \S4method{diag}{vclMatrix,vclVector}(x) <- value 18 | 19 | \S4method{diag}{gpuMatrix}(x) 20 | 21 | \S4method{diag}{gpuMatrix,gpuVector}(x) <- value 22 | } 23 | \arguments{ 24 | \item{x}{A gpuR matrix object} 25 | 26 | \item{value}{A vector object (gpuR)} 27 | } 28 | \value{ 29 | A gpuR vector object of the matrix diagonal of \code{x}. The 30 | replacement form returns nothing as it replaces the diagonal of \code{x}. 31 | } 32 | \description{ 33 | Extract or replace the diagonal of a matrix 34 | } 35 | \note{ 36 | If an identity matrix is desired, please see \link{identity_matrix}. 37 | } 38 | \seealso{ 39 | \link{identity_matrix} 40 | } 41 | \author{ 42 | Charles Determan Jr. 43 | } 44 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: gpuR 2 | Type: Package 3 | Title: GPU Functions for R Objects 4 | Description: Provides GPU enabled functions for R objects in a simple and 5 | approachable manner. New gpu* and vcl* classes have been provided to 6 | wrap typical R objects (e.g. vector, matrix), in both host and device 7 | spaces, to mirror typical R syntax without the need to know OpenCL. 8 | Version: 2.0.3 9 | Date: 2019-05-29 10 | Author: Charles Determan Jr. 11 | Maintainer: Charles Determan Jr. 12 | VignetteBuilder: knitr 13 | License: GPL (>= 2) 14 | Encoding: UTF-8 15 | Depends: 16 | R (>= 3.0.2), 17 | methods, 18 | utils 19 | Imports: 20 | Rcpp (>= 0.12.15), 21 | assertive 22 | LinkingTo: Rcpp (>= 0.12.15), 23 | RcppEigen (>= 0.3.3.4.0), 24 | RViennaCL (>= 1.7.1.7), 25 | BH 26 | NeedsCompilation: yes 27 | Suggests: 28 | testthat, 29 | knitr 30 | URL: http://github.com/cdeterman/gpuR 31 | BugReports: http://github.com/cdeterman/gpuR/issues/new 32 | SystemRequirements: C++11 (supporting at least std=c++0x), OpenCL shared 33 | library (provided by an SDK such as AMD/NVIDIA) and OpenCL headers including 34 | the C++ header file (provided by Khronos if not by SDK) 35 | RoxygenNote: 6.1.1 36 | -------------------------------------------------------------------------------- /man/log-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/methods-gpuVector.R, R/methods-vclMatrix.R, 3 | % R/methods-vclVector.R, R/methods.R 4 | \docType{methods} 5 | \name{log,gpuVector-method} 6 | \alias{log,gpuVector-method} 7 | \alias{log,vclMatrix-method} 8 | \alias{log,vclVector-method} 9 | \alias{log,gpuMatrix-method} 10 | \alias{log-gpuR-method} 11 | \title{gpuR Logarithms and Exponentials} 12 | \usage{ 13 | \S4method{log}{gpuVector}(x, base = NULL) 14 | 15 | \S4method{log}{vclMatrix}(x, base = NULL) 16 | 17 | \S4method{log}{vclVector}(x, base = NULL) 18 | 19 | \S4method{log}{gpuMatrix}(x, base = NULL) 20 | } 21 | \arguments{ 22 | \item{x}{A gpuR object} 23 | 24 | \item{base}{A positive number (complex not currently supported by OpenCL): 25 | the base with respect to which logarithms are computed. Defaults to the 26 | natural log.} 27 | } 28 | \value{ 29 | A gpuR object of the same class as \code{x} 30 | } 31 | \description{ 32 | \code{log} computes logarithms, by default natural logarithms 33 | and \code{log10} computes common (i.e. base 10) logarithms. The general form 34 | \code{log(x, base)} computes logarithms with base \code{base}. 35 | 36 | \code{exp} computes the exponential function. 37 | } 38 | -------------------------------------------------------------------------------- /R/asserts.R: -------------------------------------------------------------------------------- 1 | 2 | #' @title Does device have 'double' support? 3 | #' @description Function to query if device (identified by index) supports 4 | #' double precision 5 | #' @param device_idx An integer indicating which device to query 6 | #' @param context_idx An integer indicating which context to query 7 | #' @param severity How severe should the consequences of the assertion be? 8 | #' @return Returns nothing but throws an error if device does not support 9 | #' double precision 10 | #' @seealso \link{deviceHasDouble} 11 | #' @author Charles Determan Jr. 12 | #' @export 13 | assert_has_double <- 14 | function(device_idx, context_idx, 15 | severity = getOption("assertive.severity", "stop")) 16 | { 17 | msg <- gettextf( 18 | "The device %s on context %s does not support double. 19 | Try setting type = 'float' or change device if multiple available.", 20 | get_name_in_parent(device_idx), 21 | get_name_in_parent(context_idx), 22 | domain = "R-assertive.base" 23 | ) 24 | assert_engine( 25 | deviceHasDouble, 26 | device_idx, 27 | context_idx, 28 | msg = msg, 29 | severity = severity 30 | ) 31 | } 32 | -------------------------------------------------------------------------------- /man/pmin.vclVector.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pmax.R 3 | \name{pmin.vclVector} 4 | \alias{pmin.vclVector} 5 | \title{# @rdname 6 | setGeneric("pmax", signature = "...")} 7 | \usage{ 8 | \method{pmin}{vclVector}(..., na.rm = FALSE) 9 | } 10 | \arguments{ 11 | \item{...}{a vclVector object} 12 | 13 | \item{na.rm}{a logical indicating whether missing values should be removed.} 14 | } 15 | \description{ 16 | # @rdname 17 | #' @method pmax vclVector 18 | #' @export 19 | setMethod("pmax", 20 | "vclVector", 21 | function(..., na.rm = FALSE){ 22 | print("called correctly") 23 | gpuVecpmax(..., order = 1L) 24 | }) 25 | } 26 | \details{ 27 | #' @export 28 | setMethod("pmax", 29 | "vclMatrix", 30 | function(..., na.rm = FALSE){ 31 | gpuMatpmax(..., order = 1L) 32 | }) 33 | 34 | #' @export 35 | setMethod("pmax", 36 | "gpuVector", 37 | function(..., na.rm = FALSE){ 38 | gpuVecpmax(..., order = 1L) 39 | }) 40 | 41 | #' @export 42 | setMethod("pmax", 43 | "gpuMatrix", 44 | function(..., na.rm = FALSE){ 45 | gpuMatpmax(..., order = 1L) 46 | }) 47 | } 48 | -------------------------------------------------------------------------------- /inst/doc/custom_ocl_gpuR.R: -------------------------------------------------------------------------------- 1 | ## ----setup, include=FALSE, cache=FALSE----------------------------------- 2 | library(knitr) 3 | opts_chunk$set( 4 | concordance=TRUE 5 | ) 6 | 7 | ## ----kernel_example, eval = FALSE---------------------------------------- 8 | # "__kernel void SAXPY(__global float* x, __global float* y, float a) 9 | # { 10 | # const int i = get_global_id(0); 11 | # 12 | # y [i] += a * x [i]; 13 | # } 14 | # " 15 | 16 | ## ----cl_setup, eval=FALSE------------------------------------------------ 17 | # cl_args <- setup_opencl(objects = c("vclVector", "vclVector", "scalar"), 18 | # intents = c("IN", "OUT", "IN"), 19 | # queues = list("SAXPY", "SAXPY", "SAXPY"), 20 | # kernel_maps = c("x", "y", "a")) 21 | 22 | ## ----compile, eval=FALSE------------------------------------------------- 23 | # custom_opencl("saxpy.cl", cl_args, "float") 24 | 25 | ## ----example, eval=FALSE------------------------------------------------- 26 | # 27 | # a <- rnorm(16) 28 | # b <- rnorm(16) 29 | # gpuA <- vclVector(a, type = "float") 30 | # gpuB <- vclVector(b, type = "float") 31 | # scalar <- 2 32 | # 33 | # # apply custom function 34 | # # equivalent to - scalar*a + b 35 | # saxpy(gpuA, gpuB, scalar) 36 | 37 | -------------------------------------------------------------------------------- /src/trunc_gpuMat.cpp: -------------------------------------------------------------------------------- 1 | /* Truncating a gpuMatrix object 2 | * The point here is to simply return the top-left corner of 3 | * a given matrix. This way we avoid overflow in the console 4 | * and the user is still able to view their data. The option 5 | * to return the full matrix is possible by converting back 6 | * to an R matrix object with the '[' method. 7 | */ 8 | 9 | #include "gpuR/windows_check.hpp" 10 | #include "gpuR/dynEigenMat.hpp" 11 | 12 | #include 13 | 14 | using namespace Rcpp; 15 | 16 | template 17 | SEXP 18 | trunc_mat(SEXP ptrA_, int nr, int nc) 19 | { 20 | XPtr > ptrA(ptrA_); 21 | 22 | Eigen::Map, 0, Eigen::OuterStride<> > Am = ptrA->data(); 23 | 24 | return wrap(Am.topLeftCorner(nr, nc)); 25 | } 26 | 27 | // [[Rcpp::export]] 28 | SEXP 29 | truncIntgpuMat(SEXP ptrA_, int nr, int nc) 30 | { 31 | return trunc_mat(ptrA_, nr, nc); 32 | } 33 | 34 | // [[Rcpp::export]] 35 | SEXP 36 | truncFloatgpuMat(SEXP ptrA_, int nr, int nc) 37 | { 38 | return trunc_mat(ptrA_, nr, nc); 39 | } 40 | 41 | // [[Rcpp::export]] 42 | SEXP 43 | truncDoublegpuMat(SEXP ptrA_, int nr, int nc) 44 | { 45 | return trunc_mat(ptrA_, nr, nc); 46 | } 47 | -------------------------------------------------------------------------------- /vignettes/custom_ocl_gpuR.R: -------------------------------------------------------------------------------- 1 | ## ----setup, include=FALSE, cache=FALSE----------------------------------- 2 | library(knitr) 3 | opts_chunk$set( 4 | concordance=TRUE 5 | ) 6 | 7 | ## ----kernel_example, eval = FALSE---------------------------------------- 8 | # "__kernel void SAXPY(__global float* x, __global float* y, float a) 9 | # { 10 | # const int i = get_global_id(0); 11 | # 12 | # y [i] += a * x [i]; 13 | # } 14 | # " 15 | 16 | ## ----cl_setup, eval=FALSE------------------------------------------------ 17 | # cl_args <- setup_opencl(objects = c("vclVector", "vclVector", "scalar"), 18 | # intents = c("IN", "OUT", "IN"), 19 | # queues = list("SAXPY", "SAXPY", "SAXPY"), 20 | # kernel_maps = c("x", "y", "a")) 21 | 22 | ## ----compile, eval=FALSE------------------------------------------------- 23 | # custom_opencl("saxpy.cl", cl_args, "float") 24 | 25 | ## ----example, eval=FALSE------------------------------------------------- 26 | # 27 | # a <- rnorm(16) 28 | # b <- rnorm(16) 29 | # gpuA <- vclVector(a, type = "float") 30 | # gpuB <- vclVector(b, type = "float") 31 | # scalar <- 2 32 | # 33 | # # apply custom function 34 | # # equivalent to - scalar*a + b 35 | # saxpy(gpuA, gpuB, scalar) 36 | 37 | -------------------------------------------------------------------------------- /tests/testthat/test_custom.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("Custom OpenCL") 3 | 4 | current_context <- set_device_context("cpu") 5 | 6 | library(Rcpp) 7 | 8 | set.seed(123) 9 | 10 | ORDER <- 4 11 | 12 | # Base R objects 13 | Aint <- matrix(sample(seq(10), ORDER^2, replace=TRUE), nrow=ORDER, ncol=ORDER) 14 | Bint <- matrix(sample(seq(10), ORDER^2, replace=TRUE), nrow=ORDER, ncol=ORDER) 15 | 16 | igpuA <- vclMatrix(Aint, type="integer") 17 | igpuB <- vclMatrix(Bint, type="integer") 18 | igpuC <- vclMatrix(0L, 4, 4, type="integer") 19 | 20 | # Integer tests 21 | 22 | test_that("Custom OpenCL GEMM Kernel", { 23 | 24 | has_cpu_skip() 25 | 26 | Cint <- Aint %*% Bint 27 | 28 | kernel <- system.file("CL", "basic_gemm.cl", package = "gpuR") 29 | 30 | cl_args <- setup_opencl(c("vclMatrix", "vclMatrix", "vclMatrix"), 31 | toupper(c("in", "in", "inout")), 32 | list("iMatMult","iMatMult","iMatMult"), 33 | list("A", "B", "C")) 34 | 35 | custom_opencl(kernel, cl_args, type = "integer") 36 | 37 | basic_gemm(igpuA, igpuB, igpuC) 38 | 39 | expect_equivalent(igpuC[,], Cint, 40 | info="integer matrix elements not equivalent") 41 | 42 | }) 43 | 44 | setContext(current_context) 45 | -------------------------------------------------------------------------------- /include/gpuR/getVCLptr.hpp: -------------------------------------------------------------------------------- 1 | 2 | #ifndef GET_VCL_PTR_HPP 3 | #define GET_VCL_PTR_HPP 4 | 5 | #include "gpuR/dynVCLMat.hpp" 6 | #include "gpuR/dynVCLVec.hpp" 7 | #include "gpuR/dynEigenMat.hpp" 8 | #include "gpuR/dynEigenVec.hpp" 9 | 10 | template 11 | std::shared_ptr > 12 | getVCLptr( 13 | SEXP ptr_, 14 | const bool isVCL, 15 | const int ctx_id 16 | ){ 17 | std::shared_ptr > vclptr; 18 | 19 | if(isVCL){ 20 | Rcpp::XPtr > ptr(ptr_); 21 | vclptr = ptr->sharedPtr(); 22 | }else{ 23 | Rcpp::XPtr > ptr(ptr_); 24 | ptr->to_device(ctx_id); 25 | vclptr = ptr->getDevicePtr(); 26 | } 27 | 28 | return vclptr; 29 | } 30 | 31 | template 32 | std::shared_ptr > 33 | getVCLVecptr( 34 | SEXP ptr_, 35 | const bool isVCL, 36 | const int ctx_id 37 | ){ 38 | std::shared_ptr > vclptr; 39 | 40 | if(isVCL){ 41 | Rcpp::XPtr > ptr(ptr_); 42 | vclptr = ptr->sharedPtr(); 43 | }else{ 44 | Rcpp::XPtr > ptr(ptr_); 45 | 46 | ptr->to_device(ctx_id); 47 | vclptr = ptr->getDevicePtr(); 48 | } 49 | 50 | return vclptr; 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /inst/doc/gpuR.R: -------------------------------------------------------------------------------- 1 | ## ----setup, include=FALSE, cache=FALSE----------------------------------- 2 | library(knitr) 3 | opts_chunk$set( 4 | concordance=TRUE 5 | ) 6 | 7 | ## ----install, eval = FALSE----------------------------------------------- 8 | # # Stable version 9 | # install.packages("gpuR") 10 | 11 | ## ----installDev, eval = FALSE-------------------------------------------- 12 | # # Dev version 13 | # devtools::install_github("cdeterman/gpuR", ref = "develop") 14 | # 15 | # # Note this may require install of the RViennaCL from my github 16 | # # if updates have been made 17 | # #devtools::install_github("cdeterman/RViennaCL") 18 | 19 | ## ----matMult, eval=FALSE------------------------------------------------- 20 | # library("gpuR") 21 | # 22 | # # verify you have valid GPUs 23 | # detectGPUs() 24 | # 25 | # # create gpuMatrix and multiply 26 | # set.seed(123) 27 | # gpuA <- gpuMatrix(rnorm(16), nrow=4, ncol=4) 28 | # gpuB <- gpuA %*% gpuA 29 | 30 | ## ----matBlock, eval=FALSE------------------------------------------------ 31 | # 32 | # # create gpuMatrix 33 | # set.seed(123) 34 | # gpuA <- gpuMatrix(rnorm(16), nrow=4, ncol=4) 35 | # 36 | # # create block omitting the 1st row 37 | # gpuB <- block(gpuA, 38 | # rowStart = 2L, rowEnd = 4L, 39 | # colStart = 1L, colEnd = 4L) 40 | 41 | -------------------------------------------------------------------------------- /man/norm-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/norm.R 3 | \docType{methods} 4 | \name{norm,vclMatrix,character-method} 5 | \alias{norm,vclMatrix,character-method} 6 | \alias{norm,vclMatrix,missing-method} 7 | \alias{norm,gpuMatrix,character-method} 8 | \alias{norm,gpuMatrix,missing-method} 9 | \alias{norm,ANY,missing-method} 10 | \alias{norm,ANY,character-method} 11 | \title{Compute the Norm of a Matrix} 12 | \usage{ 13 | \S4method{norm}{vclMatrix,character}(x, type) 14 | 15 | \S4method{norm}{vclMatrix,missing}(x, type) 16 | 17 | \S4method{norm}{gpuMatrix,character}(x, type) 18 | 19 | \S4method{norm}{gpuMatrix,missing}(x, type) 20 | 21 | \S4method{norm}{ANY,missing}(x, type) 22 | 23 | \S4method{norm}{ANY,character}(x, type) 24 | } 25 | \arguments{ 26 | \item{x}{A gpuR matrix object} 27 | 28 | \item{type}{character string, specifying the type of matrix norm to be computed.} 29 | } 30 | \value{ 31 | The matrix norm, a non-negative number 32 | } 33 | \description{ 34 | Computes a matrix norm of x. The norm can be the one \("O"\) norm, 35 | the infinity \("I"\) norm, the Frobenius \("F"\) norm, the maximum modulus \("M"\) 36 | among elements of a matrix, or the “spectral” or "2"-norm, as determined by 37 | the value of type. 38 | } 39 | \seealso{ 40 | \link[base]{norm} 41 | } 42 | \author{ 43 | Charles Determan Jr. 44 | } 45 | -------------------------------------------------------------------------------- /man/gpuR-deepcopy.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generics.R, R/methods-gpuVector.R, 3 | % R/methods-vclMatrix.R, R/methods-vclVector.R, R/methods.R 4 | \docType{methods} 5 | \name{deepcopy} 6 | \alias{deepcopy} 7 | \alias{deepcopy,gpuVector-method} 8 | \alias{deepcopy,vclMatrix-method} 9 | \alias{deepcopy,vclVector-method} 10 | \alias{deepcopy,gpuMatrix-method} 11 | \title{Copy a "gpuR" object} 12 | \usage{ 13 | deepcopy(object, ...) 14 | 15 | \S4method{deepcopy}{gpuVector}(object) 16 | 17 | \S4method{deepcopy}{vclMatrix}(object, source = FALSE) 18 | 19 | \S4method{deepcopy}{vclVector}(object) 20 | 21 | \S4method{deepcopy}{gpuMatrix}(object) 22 | } 23 | \arguments{ 24 | \item{object}{A gpuR object} 25 | 26 | \item{...}{Additional arguments} 27 | 28 | \item{source}{A boolean indicating if source matrix should be copied (only 29 | relevant for 'block' and 'slice' objects).} 30 | } 31 | \value{ 32 | A gpuR object 33 | } 34 | \description{ 35 | This is needed to make a duplicate of a gpuR object 36 | } 37 | \details{ 38 | This is needed to make a duplicate of a gpuR object 39 | (i.e. \code{\link{gpuMatrix}}, \code{\link{gpuVector}}, 40 | \code{\link{vclMatrix}}, \code{\link{vclVector}} because 41 | the traditional syntax would only copy the pointer of the object. 42 | } 43 | \seealso{ 44 | \code{\link{block}} 45 | } 46 | \author{ 47 | Charles Determan Jr. 48 | } 49 | -------------------------------------------------------------------------------- /man/gpuVector-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gpuVector.R 3 | \docType{methods} 4 | \name{gpuVector} 5 | \alias{gpuVector} 6 | \alias{gpuVector,vector,missing-method} 7 | \alias{gpuVector,vector} 8 | \alias{gpuVector,missingOrNULL,ANY-method} 9 | \alias{gpuVector,missingOrNULL} 10 | \alias{gpuVector,numeric,numericOrInt-method} 11 | \title{Construct a gpuVector} 12 | \usage{ 13 | gpuVector(data, length, type = NULL, ...) 14 | 15 | \S4method{gpuVector}{vector,missing}(data, type = NULL, ctx_id = NULL) 16 | 17 | \S4method{gpuVector}{missingOrNULL,ANY}(data, length, type = NULL, 18 | ctx_id = NULL) 19 | 20 | \S4method{gpuVector}{numeric,numericOrInt}(data, length, type = NULL, 21 | ctx_id = NULL) 22 | } 23 | \arguments{ 24 | \item{data}{An object that is or can be converted to a 25 | \code{vector}} 26 | 27 | \item{length}{A non-negative integer specifying the desired length.} 28 | 29 | \item{type}{A character string specifying the type of gpuVector. Default 30 | is NULL where type is inherited from the source data type.} 31 | 32 | \item{...}{Additional method to pass to gpuVector methods} 33 | 34 | \item{ctx_id}{An integer specifying the object's context} 35 | } 36 | \value{ 37 | A gpuVector object 38 | } 39 | \description{ 40 | Construct a gpuVector of a class that inherits 41 | from \code{gpuVector} 42 | } 43 | \author{ 44 | Charles Determan Jr. 45 | } 46 | -------------------------------------------------------------------------------- /man/gpuR-slice.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generics.R, R/methods-gpuVector.R, 3 | % R/methods-vclVector.R 4 | \docType{methods} 5 | \name{slice} 6 | \alias{slice} 7 | \alias{slice,gpuVector,integer,integer-method} 8 | \alias{slice,vclVector,integer,integer-method} 9 | \title{Vector Slices} 10 | \usage{ 11 | slice(object, start, end) 12 | 13 | \S4method{slice}{gpuVector,integer,integer}(object, start, end) 14 | 15 | \S4method{slice}{vclVector,integer,integer}(object, start, end) 16 | } 17 | \arguments{ 18 | \item{object}{A \code{gpuVector} or \code{vclVector} object} 19 | 20 | \item{start}{An integer indicating the start of slice} 21 | 22 | \item{end}{An integer indicating the end of slice} 23 | } 24 | \value{ 25 | A \code{gpuVectorSlice} or \code{vclVectorSlice} object 26 | } 27 | \description{ 28 | This doesn't create a copy, it provides a child class that 29 | points to a contiguous subvector of a \code{\link{gpuVector}} or 30 | \code{\link{vclVector}}. Non-contiguous slices are currently not supported. 31 | } 32 | \details{ 33 | This function allows a user to create a gpuR vector object that 34 | references a continuous subset of columns and rows of another gpuR vector 35 | object without a copy. 36 | 37 | NOTE - this means that altering values in a vector slice object will alter 38 | values in the source vector. 39 | } 40 | \author{ 41 | Charles Determan Jr. 42 | } 43 | -------------------------------------------------------------------------------- /tests/testthat/test_cpu_vclMatrix_cov.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("CPU vclMatrix Correlations") 3 | 4 | current_context <- set_device_context("cpu") 5 | 6 | # set seed 7 | set.seed(123) 8 | 9 | ORDER_X <- 4 10 | ORDER_Y <- 5 11 | 12 | # Base R objects 13 | A <- matrix(rnorm(ORDER_X*ORDER_Y), nrow=ORDER_X, ncol=ORDER_Y) 14 | 15 | C <- cov(A) 16 | 17 | 18 | test_that("CPU vclMatrix Single Precision Pearson Covariance", 19 | { 20 | has_cpu_skip() 21 | 22 | fgpuX <- vclMatrix(A, type="float") 23 | 24 | gpuC <- cov(fgpuX) 25 | gpuCp <- cov(fgpuX, method = "pearson") 26 | 27 | expect_is(gpuC, "fvclMatrix") 28 | expect_equal(gpuC[], C, tolerance=1e-06, 29 | info="float covariance values not equivalent") 30 | expect_equal(gpuCp[], C, tolerance=1e-06, 31 | info="float covariance values not equivalent") 32 | expect_error(cov(fgpuX, method = "unimplemented"), 33 | info = "no error thrown for unknown method") 34 | }) 35 | 36 | test_that("CPU vclMatrix Double Precision Pearson Covariance", 37 | { 38 | has_cpu_skip() 39 | 40 | dgpuX <- vclMatrix(A, type="double") 41 | 42 | gpuC <- cov(dgpuX) 43 | 44 | expect_is(gpuC, "dvclMatrix") 45 | expect_equal(gpuC[], C, tolerance=.Machine$double.eps ^ 0.5, 46 | info="double colSums not equivalent") 47 | }) 48 | 49 | setContext(current_context) 50 | -------------------------------------------------------------------------------- /inst/src/base_custom_cuda.cpp: -------------------------------------------------------------------------------- 1 | // [[Rcpp::depends(BH, RcppEigen, RViennaCL, gpuR)]] 2 | // [[Rcpp::plugins(cpp11)]] 3 | 4 | #include "gpuR/windows_check.hpp" 5 | 6 | #include 7 | 8 | #include "viennacl/ocl/backend.hpp" 9 | 10 | #include "gpuR/utils.hpp" 11 | #include "gpuR/getVCLptr.hpp" 12 | 13 | using namespace Rcpp; 14 | 15 | template 16 | __global__ void MY_KERNEL 17 | 18 | 19 | // [[Rcpp::export]] 20 | void 21 | CPP_NAME( 22 | MY_ARGS) 23 | { 24 | 25 | MY_KERNEL_NAMES 26 | 27 | MY_S4 28 | 29 | MY_CTX_ID 30 | 31 | MY_DEFINES 32 | 33 | MY_CONTEXT 34 | 35 | MY_DIMS 36 | 37 | // add kernel to program 38 | viennacl::ocl::program & my_prog = ctx.add_program(my_kernel, "my_kernel"); 39 | 40 | // get compiled kernel function 41 | MY_KERNELS 42 | 43 | viennacl::ocl::device working_device = ctx.current_device(); 44 | 45 | // set global work sizes 46 | MY_GLOBALS 47 | 48 | // set local work sizes 49 | MY_LOCALS 50 | // pmax.local_work_size(0, max_local_size); 51 | // pmax.local_work_size(1, max_local_size); 52 | 53 | // execute kernels 54 | MY_QUEUES 55 | // viennacl::ocl::enqueue(my_kernel(*vcl_A, *vcl_B, value, M, P, M_internal)); 56 | 57 | // device to host if needed 58 | MY_OUT 59 | } 60 | 61 | -------------------------------------------------------------------------------- /man/gpuMatrix-crossprod.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/methods.R 3 | \docType{methods} 4 | \name{crossprod,gpuMatrix,missing-method} 5 | \alias{crossprod,gpuMatrix,missing-method} 6 | \alias{crossprod,gpuMatrix} 7 | \alias{crossprod,gpuMatrix,gpuMatrix-method} 8 | \alias{crossprod,gpuMatrix,matrix-method} 9 | \alias{crossprod,matrix,gpuMatrix-method} 10 | \alias{tcrossprod,gpuMatrix,missing-method} 11 | \alias{tcrossprod,gpuMatrix,gpuMatrix-method} 12 | \alias{tcrossprod,matrix,gpuMatrix-method} 13 | \alias{tcrossprod,gpuMatrix,matrix-method} 14 | \title{gpuMatrix Crossproduct} 15 | \usage{ 16 | \S4method{crossprod}{gpuMatrix,missing}(x, y) 17 | 18 | \S4method{crossprod}{gpuMatrix,gpuMatrix}(x, y) 19 | 20 | \S4method{crossprod}{gpuMatrix,matrix}(x, y) 21 | 22 | \S4method{crossprod}{matrix,gpuMatrix}(x, y) 23 | 24 | \S4method{tcrossprod}{gpuMatrix,missing}(x, y) 25 | 26 | \S4method{tcrossprod}{gpuMatrix,gpuMatrix}(x, y) 27 | 28 | \S4method{tcrossprod}{matrix,gpuMatrix}(x, y) 29 | 30 | \S4method{tcrossprod}{gpuMatrix,matrix}(x, y) 31 | } 32 | \arguments{ 33 | \item{x}{A gpuMatrix} 34 | 35 | \item{y}{A gpuMatrix} 36 | } 37 | \value{ 38 | A gpuMatrix 39 | } 40 | \description{ 41 | Return the matrix cross-product of two conformable 42 | matrices using a GPU. This is equivalent to t(x) %*% y (crossprod) 43 | or x %*% t(t) (tcrossprod) but faster as no data transfer between 44 | device and host is required. 45 | } 46 | \author{ 47 | Charles Determan Jr. 48 | } 49 | -------------------------------------------------------------------------------- /tests/testthat/test_gpuMatrix_cov.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("gpuMatrix Correlations") 3 | 4 | if(detectGPUs() >= 1){ 5 | current_context <- set_device_context("gpu") 6 | }else{ 7 | current_context <- currentContext() 8 | } 9 | 10 | # set seed 11 | set.seed(123) 12 | 13 | ORDER_X <- 4 14 | ORDER_Y <- 5 15 | 16 | # Base R objects 17 | A <- matrix(rnorm(ORDER_X*ORDER_Y), nrow=ORDER_X, ncol=ORDER_Y) 18 | 19 | C <- cov(A) 20 | 21 | 22 | test_that("gpuMatrix Single Precision Pearson Covariance", 23 | { 24 | has_gpu_skip() 25 | 26 | fgpuX <- gpuMatrix(A, type="float") 27 | 28 | gpuC <- cov(fgpuX) 29 | gpuCp <- cov(fgpuX, method = "pearson") 30 | 31 | expect_is(gpuC, "fgpuMatrix") 32 | expect_equal(gpuC[], C, tolerance=1e-06, 33 | info="float covariance values not equivalent") 34 | expect_equal(gpuCp[], C, tolerance=1e-06, 35 | info="float covariance values not equivalent") 36 | expect_error(cov(fgpuX, method = "unimplemented"), 37 | info = "no error thrown for unknown method") 38 | }) 39 | 40 | test_that("gpuMatrix Double Precision Pearson Covariance", 41 | { 42 | 43 | has_gpu_skip() 44 | has_double_skip() 45 | 46 | dgpuX <- gpuMatrix(A, type="double") 47 | 48 | gpuC <- cov(dgpuX) 49 | 50 | expect_is(gpuC, "dgpuMatrix") 51 | expect_equal(gpuC[], C, tolerance=.Machine$double.eps ^ 0.5, 52 | info="double colSums not equivalent") 53 | }) 54 | 55 | setContext(current_context) 56 | -------------------------------------------------------------------------------- /tests/testthat/test_vclMatrix_cov.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("vclMatrix Correlations") 3 | 4 | if(detectGPUs() >= 1){ 5 | current_context <- set_device_context("gpu") 6 | }else{ 7 | current_context <- currentContext() 8 | } 9 | 10 | # set seed 11 | set.seed(123) 12 | 13 | ORDER_X <- 4 14 | ORDER_Y <- 5 15 | 16 | # Base R objects 17 | A <- matrix(rnorm(ORDER_X*ORDER_Y), nrow=ORDER_X, ncol=ORDER_Y) 18 | 19 | C <- cov(A) 20 | 21 | 22 | test_that("vclMatrix Single Precision Pearson Covariance", 23 | { 24 | has_gpu_skip() 25 | 26 | fgpuX <- vclMatrix(A, type="float") 27 | 28 | gpuC <- cov(fgpuX) 29 | gpuCp <- cov(fgpuX, method = "pearson") 30 | 31 | expect_is(gpuC, "fvclMatrix") 32 | expect_equal(gpuC[], C, tolerance=1e-06, 33 | info="float covariance values not equivalent") 34 | expect_equal(gpuCp[], C, tolerance=1e-06, 35 | info="float covariance values not equivalent") 36 | expect_error(cov(fgpuX, method = "unimplemented"), 37 | info = "no error thrown for unknown method") 38 | }) 39 | 40 | test_that("vclMatrix Double Precision Pearson Covariance", 41 | { 42 | 43 | has_gpu_skip() 44 | has_double_skip() 45 | 46 | dgpuX <- vclMatrix(A, type="double") 47 | 48 | gpuC <- cov(dgpuX) 49 | 50 | expect_is(gpuC, "dvclMatrix") 51 | expect_equal(gpuC[], C, tolerance=.Machine$double.eps ^ 0.5, 52 | info="double colSums not equivalent") 53 | }) 54 | 55 | setContext(current_context) 56 | -------------------------------------------------------------------------------- /man/qr-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/qr.R 3 | \name{qr.gpuMatrix} 4 | \alias{qr.gpuMatrix} 5 | \alias{qr.gpuR} 6 | \alias{qr.vclMatrix} 7 | \title{The QR Decomposition of a gpuR matrix} 8 | \usage{ 9 | \method{qr}{gpuMatrix}(x, ..., inplace = FALSE) 10 | 11 | \method{qr}{vclMatrix}(x, ..., inplace = FALSE) 12 | } 13 | \arguments{ 14 | \item{x}{A gpuR matrix} 15 | 16 | \item{...}{further arguments passed to or from other methods} 17 | 18 | \item{inplace}{Logical indicating if operations performed inplace} 19 | } 20 | \value{ 21 | A \code{list} containing the QR decomposition of the matrix of class 22 | \code{gpuQR}. The returned value is a list with the following components: 23 | \itemize{ 24 | \item{qr} a matrix with the same dimensions as \code{x}. 25 | \item{betas} vector of numeric values containing additional information of 26 | \code{qr} for extracting \code{Q} and \code{R} matrices. 27 | } 28 | } 29 | \description{ 30 | \code{qr} computes the QR decomposition of a gpuR matrix 31 | } 32 | \note{ 33 | This an S3 generic of \link[base]{qr}. The default continues 34 | to point to the default base function. 35 | 36 | Furthermore, the list returned does not contain the exact same elements 37 | as \link[base]{qr}. The matrix storage format applied herein doesn't match 38 | the base compact form. The method also doesn't return \code{qraux}, 39 | \code{rank}, or \code{pivot} but instead returns \code{betas} 40 | } 41 | \seealso{ 42 | \link[base]{qr} 43 | } 44 | \author{ 45 | Charles Determan Jr. 46 | } 47 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | 2 | branches: 3 | only: 4 | - master 5 | - develop 6 | 7 | shallow_clone: true 8 | 9 | environment: 10 | global: 11 | R_BUILD_ARGS: "--no-manual --keep-empty-dirs --no-build-vignettes" 12 | R_CHECK_ARGS: "--no-multiarch --no-build-vignettes --no-manual --no-tests" 13 | 14 | # $ErrActionPreference = "Stop" when we tighten this up. 15 | # DO NOT CHANGE the "init" and "install" sections below 16 | # Download script file from GitHub 17 | init: 18 | - ps: | 19 | $ErrorActionPreference = "Continue" 20 | Invoke-WebRequest http://raw.github.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1" 21 | Import-Module '..\appveyor-tool.ps1' 22 | 23 | install: 24 | - ps: Bootstrap 25 | 26 | # Adapt as necessary starting from here 27 | 28 | build_script: 29 | - travis-tool.sh install_github cdeterman/RViennaCL 30 | - travis-tool.sh install_deps 31 | 32 | test_script: 33 | - travis-tool.sh run_tests 34 | 35 | on_failure: 36 | - travis-tool.sh dump_logs 37 | 38 | #on_finish: 39 | # - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) 40 | 41 | artifacts: 42 | - path: '*.Rcheck\**\*.log' 43 | name: Logs 44 | 45 | - path: '*.Rcheck\**\*.out' 46 | name: Logs 47 | 48 | - path: '*.Rcheck\**\*.fail' 49 | name: Logs 50 | 51 | - path: '*.Rcheck\**\*.Rout' 52 | name: Logs 53 | 54 | - path: '\*_*.tar.gz' 55 | name: Bits 56 | 57 | - path: '\*_*.zip' 58 | name: Bits 59 | 60 | -------------------------------------------------------------------------------- /R/print.R: -------------------------------------------------------------------------------- 1 | #' @title S3 print for gpuMatrix objects 2 | #' @description prints a gpuMatrix object that is truncated to fit the screen 3 | #' @param x A gpuMatrix object 4 | #' @param ... Additional arguments to print 5 | #' @param n Number of rows to display 6 | #' @param width Number of columns to display 7 | #' @export 8 | print.gpuMatrix <- function(x, ..., n = NULL, width = NULL) { 9 | cat("Source: gpuR Matrix ", dim_desc(x), "\n", sep = "") 10 | cat("\n") 11 | 12 | if(!is.null(n)){ 13 | assert_is_integer(n) 14 | }else{ 15 | n <- ifelse(nrow(x) >= 5, 5L, nrow(x)) 16 | } 17 | if(!is.null(width)){ 18 | assert_is_integer(width) 19 | }else{ 20 | width <- ifelse(ncol(x) >= 5, 5L, ncol(x)) 21 | } 22 | 23 | if(width > ncol(x)) stop("width greater than number of columns") 24 | 25 | tab <- switch(typeof(x), 26 | "integer" = truncIntgpuMat(x@address, n, width), 27 | "float" = truncFloatgpuMat(x@address, n, width), 28 | "double" = truncDoublegpuMat(x@address, n, width) 29 | ) 30 | 31 | block = structure( 32 | list(table = tab, extra = ncol(x)-width), 33 | class = "trunc_gpuTable") 34 | 35 | print(block) 36 | 37 | invisible(x) 38 | } 39 | 40 | 41 | print.trunc_gpuTable <- function(x, ...) { 42 | if (!is.null(x$table)) { 43 | print(x$table) 44 | } 45 | 46 | if (x$extra > 0) { 47 | nvars <- x$extra 48 | cat("\n", paste0(nvars, " variables not shown"), "\n", sep = "") 49 | } 50 | 51 | invisible() 52 | } 53 | -------------------------------------------------------------------------------- /man/gpuMatrix-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gpuMatrix.R 3 | \docType{methods} 4 | \name{gpuMatrix} 5 | \alias{gpuMatrix} 6 | \alias{gpuMatrix,matrix-method} 7 | \alias{gpuMatrix,matrix} 8 | \alias{gpuMatrix,missing-method} 9 | \alias{gpuMatrix,missing} 10 | \alias{gpuMatrix,numeric-method} 11 | \alias{gpuMatrix,numeric} 12 | \alias{gpuMatrix,integer-method} 13 | \alias{gpuMatrix,integer} 14 | \title{Construct a gpuMatrix} 15 | \usage{ 16 | gpuMatrix(data = NA, nrow = NA, ncol = NA, type = NULL, ...) 17 | 18 | \S4method{gpuMatrix}{matrix}(data, type = NULL, ctx_id = NULL) 19 | 20 | \S4method{gpuMatrix}{missing}(data, nrow = NA, ncol = NA, 21 | type = NULL, ctx_id = NULL) 22 | 23 | \S4method{gpuMatrix}{numeric}(data, nrow, ncol, type = NULL, 24 | ctx_id = NULL) 25 | 26 | \S4method{gpuMatrix}{integer}(data, nrow, ncol, type = NULL, 27 | ctx_id = NULL) 28 | } 29 | \arguments{ 30 | \item{data}{An object that is or can be converted to a 31 | \code{matrix} object} 32 | 33 | \item{nrow}{An integer specifying the number of rows} 34 | 35 | \item{ncol}{An integer specifying the number of columns} 36 | 37 | \item{type}{A character string specifying the type of gpuMatrix. Default 38 | is NULL where type is inherited from the source data type.} 39 | 40 | \item{...}{Additional method to pass to gpuMatrix methods} 41 | 42 | \item{ctx_id}{An integer specifying the object's context} 43 | } 44 | \value{ 45 | A gpuMatrix object 46 | } 47 | \description{ 48 | Construct a gpuMatrix of a class that inherits 49 | from \code{gpuMatrix} 50 | } 51 | \author{ 52 | Charles Determan Jr. 53 | } 54 | -------------------------------------------------------------------------------- /tests/testthat/test_order.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("Ordering Methods") 3 | 4 | # set seed 5 | set.seed(123) 6 | 7 | ORDER <- 4 8 | 9 | # Base R objects 10 | A <- matrix(rnorm(ORDER^2), nrow=ORDER) 11 | idx <- sample(seq.int(ORDER), ORDER) 12 | 13 | C <- A[idx,] 14 | 15 | test_that("vclMatrix permute", 16 | { 17 | has_gpu_skip() 18 | 19 | fgpuX <- vclMatrix(A, type="float") 20 | 21 | gpuC <- permute(fgpuX, order = idx) 22 | 23 | expect_is(gpuC, "fvclMatrix") 24 | expect_equal(gpuC[], C, tolerance=1e-06, 25 | info="float row permutations not equivalent") 26 | 27 | has_double_skip() 28 | 29 | fgpuX <- vclMatrix(A, type="double") 30 | 31 | gpuC <- permute(fgpuX, order = idx) 32 | 33 | expect_is(gpuC, "dvclMatrix") 34 | expect_equal(gpuC[], C, tolerance=.Machine$double.eps^0.5, 35 | info="double row permutations not equivalent") 36 | }) 37 | 38 | test_that("vclBlockMatrix permute", 39 | { 40 | has_gpu_skip() 41 | 42 | fgpuX <- vclMatrix(A, type="float") 43 | blockX <- block(fgpuX, 1L, 4L, 1L, 3L) 44 | 45 | gpuC <- permute(blockX, order = idx) 46 | 47 | expect_is(gpuC, "fvclMatrixBlock") 48 | expect_equal(gpuC[], C[,1:3], tolerance=1e-06, 49 | info="float block row permutations not equivalent") 50 | 51 | has_double_skip() 52 | 53 | fgpuX <- vclMatrix(A, type="double") 54 | blockX <- block(fgpuX, 1L, nrow(A), 1L, 3L) 55 | 56 | gpuC <- permute(blockX, order = idx) 57 | 58 | expect_is(gpuC, "dvclMatrixBlock") 59 | expect_equal(gpuC[], C[,1:3], tolerance=.Machine$double.eps^0.5, 60 | info="double block row permutations not equivalent") 61 | }) 62 | 63 | -------------------------------------------------------------------------------- /man/deviceInfo.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/wrappers-utils.R 3 | \name{gpuInfo} 4 | \alias{gpuInfo} 5 | \alias{cpuInfo} 6 | \title{Device Information} 7 | \usage{ 8 | gpuInfo(device_idx = NULL, context_idx = currentContext()) 9 | 10 | cpuInfo(device_idx = NULL, context_idx = currentContext()) 11 | } 12 | \arguments{ 13 | \item{device_idx}{An integer value indicating which device to query.} 14 | 15 | \item{context_idx}{An integer value indicating which context to query.} 16 | } 17 | \value{ 18 | \item{deviceName}{Device Name} 19 | 20 | \item{deviceVendor}{Device Vendor} 21 | 22 | \item{numberOfCores}{Number of Computing Units 23 | (which execute the work groups)} 24 | 25 | \item{maxWorkGroupSize}{Maximum number of work items 26 | per group} 27 | 28 | \item{maxWorkItemDim}{Number of dimensions} 29 | 30 | \item{maxWorkItemSizes}{Maximum number of works items 31 | per dimension} 32 | 33 | \item{deviceMemory}{Global amount of memory (bytes)} 34 | 35 | \item{clockFreq}{Maximum configured clock frequency of the 36 | device in MHz} 37 | 38 | \item{localMem}{Maximum amount of local memory for each work 39 | group (bytes)} 40 | 41 | \item{maxAllocatableMem}{Maximum amount of memory in a single 42 | piece (bytes)} 43 | 44 | \item{available}{Whether the device is available} 45 | 46 | \item{deviceExtensions}{OpenCL device extensions available} 47 | 48 | \item{double_support}{Logical value if double type supported} 49 | } 50 | \description{ 51 | Get basic information about selected device (e.g. GPU) 52 | } 53 | \seealso{ 54 | \link{detectPlatforms} \link{detectGPUs} \link{detectCPUs} \link{cpuInfo} 55 | } 56 | \author{ 57 | Charles Determan Jr. 58 | } 59 | -------------------------------------------------------------------------------- /man/gpuR-block.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generics.R, R/methods-vclMatrix.R, R/methods.R 3 | \docType{methods} 4 | \name{block} 5 | \alias{block} 6 | \alias{block,vclMatrix,integer,integer,integer,integer-method} 7 | \alias{block,gpuMatrix,integer,integer,integer,integer-method} 8 | \title{Matrix Blocks} 9 | \usage{ 10 | block(object, rowStart, rowEnd, colStart, colEnd) 11 | 12 | \S4method{block}{vclMatrix,integer,integer,integer,integer}(object, 13 | rowStart, rowEnd, colStart, colEnd) 14 | 15 | \S4method{block}{gpuMatrix,integer,integer,integer,integer}(object, 16 | rowStart, rowEnd, colStart, colEnd) 17 | } 18 | \arguments{ 19 | \item{object}{A \code{gpuMatrix} or \code{vclMatrix} object} 20 | 21 | \item{rowStart}{An integer indicating the first row of block} 22 | 23 | \item{rowEnd}{An integer indicating the last row of block} 24 | 25 | \item{colStart}{An integer indicating the first column of block} 26 | 27 | \item{colEnd}{An integer indicating the last column of block} 28 | } 29 | \value{ 30 | A \code{gpuMatrixBlock} or \code{vclMatrixBlock} object 31 | } 32 | \description{ 33 | This doesn't create a copy, it provides a child class that 34 | points to a contiguous submatrix of a \code{\link{gpuMatrix}} or 35 | \code{\link{vclMatrix}}. Non-contiguous blocks are currently not supported. 36 | } 37 | \details{ 38 | This function allows a user to create a gpuR matrix object that 39 | references a continuous subset of columns and rows of another gpuR matrix 40 | object without a copy. 41 | 42 | NOTE - this means that altering values in a matrix block object will alter 43 | values in the source matrix. 44 | } 45 | \author{ 46 | Charles Determan Jr. 47 | } 48 | -------------------------------------------------------------------------------- /man/gpuMatrix-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-gpuMatrix.R 3 | \docType{class} 4 | \name{gpuMatrix-class} 5 | \alias{gpuMatrix-class} 6 | \title{gpuMatrix Class} 7 | \description{ 8 | This is the 'mother' class for all 9 | gpuMatrix objects. It is essentially a wrapper for 10 | a basic R matrix (possibly to be improved). All other 11 | gpuMatrix classes inherit from this class but 12 | there are no current circumstances where this class 13 | is used directly. 14 | 15 | There are multiple child classes that correspond 16 | to the particular data type contained. These include 17 | \code{igpuMatrix}, \code{fgpuMatrix}, and 18 | \code{dgpuMatrix} corresponding to integer, float, and 19 | double data types respectively. 20 | } 21 | \note{ 22 | R does not contain a native float type. As such, 23 | the matrix data within a \code{\link{fgpuMatrix-class}} 24 | will be represented as double but downcast when any 25 | gpuMatrix methods are used. 26 | 27 | May also remove the type slot 28 | } 29 | \section{Slots}{ 30 | 31 | Common to all gpuMatrix objects in the package 32 | \describe{ 33 | \item{\code{address}:}{Pointer to data matrix} 34 | \item{\code{.context_index}:}{Integer index of OpenCL contexts} 35 | \item{\code{.platform_index}:}{Integer index of OpenCL platforms} 36 | \item{\code{.platform}:}{Name of OpenCL platform} 37 | \item{\code{.device_index}:}{Integer index of active device} 38 | \item{\code{.device}:}{Name of active device} 39 | } 40 | } 41 | 42 | \seealso{ 43 | \code{\link{igpuMatrix-class}}, 44 | \code{\link{fgpuMatrix-class}}, 45 | \code{\link{dgpuMatrix-class}} 46 | } 47 | \author{ 48 | Charles Determan Jr. 49 | } 50 | -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | citHeader("To cite the 'gpuR' package in publications please use both:") 2 | 3 | year <- sub(".*(2[[:digit:]]{3})-.*", "\\1", meta$Date, perl = TRUE) 4 | vers <- paste("R package version", meta$Version) 5 | 6 | bibentry(bibtype="Manual", 7 | title = "gpuR: GPU Functions for R Objects", 8 | author = personList(as.person("Charles Determan Jr.")), 9 | year = year, 10 | note = vers, 11 | url="http://github.com/cdeterman/gpuR", 12 | 13 | textVersion = paste0('Charles Determan Jr. (', year, '). gpuR: ', 14 | meta$Title, '. ', vers, '. ', 15 | 'http://github.com/cdeterman/gpuR', 16 | sep = '') 17 | 18 | ) 19 | 20 | bibentry( 21 | bibtype = "Article", 22 | title = "ViennaCL-Linear Algebra Library for Multi- and Many-Core Architectures", 23 | author = personList(as.person("Karl Rupp"), 24 | as.person("Phillippe Tillet"), 25 | as.person("Florian Rudolf"), 26 | as.person("Josef Weinbub"), 27 | as.person("Tibor Grasser"), 28 | as.person("Ansgar Jüngel")), 29 | year = "2016-10-27", 30 | url = "http://dx.doi.org/10.1137/15m1026419", 31 | doi = "10.1137/15m1026419", 32 | journal = "SIAM Journal on Scientific Computing", 33 | 34 | textVersion = 'Rupp, Karl, et al. "ViennaCL - Linear Algebra Library for 35 | Multi-and Many-Core Architectures." SIAM Journal on Scientific 36 | Computing 38.5 (2016): S412-S439. ISSN: 1064-8275. 37 | DOI: 10.1137/15m1026419.' 38 | ) 39 | -------------------------------------------------------------------------------- /man/vclMatrix-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/vclMatrix.R 3 | \docType{methods} 4 | \name{vclMatrix} 5 | \alias{vclMatrix} 6 | \alias{vclMatrix,matrix-method} 7 | \alias{vclMatrix,matrix} 8 | \alias{vclMatrix,missing-method} 9 | \alias{vclMatrix,missing} 10 | \alias{vclMatrix,numeric-method} 11 | \alias{vclMatrix,vector} 12 | \alias{vclMatrix,integer-method} 13 | \alias{vclMatrix,integer} 14 | \title{Construct a vclMatrix} 15 | \usage{ 16 | vclMatrix(data = NA, nrow = NA, ncol = NA, type = NULL, ...) 17 | 18 | \S4method{vclMatrix}{matrix}(data, type = NULL, ctx_id = NULL) 19 | 20 | \S4method{vclMatrix}{missing}(data, nrow = NA, ncol = NA, 21 | type = NULL, ctx_id = NULL) 22 | 23 | \S4method{vclMatrix}{numeric}(data, nrow, ncol, type = NULL, 24 | ctx_id = NULL) 25 | 26 | \S4method{vclMatrix}{integer}(data, nrow, ncol, type = NULL, 27 | ctx_id = NULL) 28 | } 29 | \arguments{ 30 | \item{data}{An object that is or can be converted to a 31 | \code{matrix} object} 32 | 33 | \item{nrow}{An integer specifying the number of rows} 34 | 35 | \item{ncol}{An integer specifying the number of columns} 36 | 37 | \item{type}{A character string specifying the type of vclMatrix. Default 38 | is NULL where type is inherited from the source data type.} 39 | 40 | \item{...}{Additional method to pass to vclMatrix methods} 41 | 42 | \item{ctx_id}{An integer specifying the object's context} 43 | } 44 | \value{ 45 | A vclMatrix object 46 | } 47 | \description{ 48 | Construct a vclMatrix of a class that inherits 49 | from \code{vclMatrix}. This class points to memory directly on 50 | the GPU to avoid the cost of data transfer between host and device. 51 | } 52 | \author{ 53 | Charles Determan Jr. 54 | } 55 | -------------------------------------------------------------------------------- /man/dist-vclMatrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generics.R, R/methods-vclMatrix.R, R/methods.R 3 | \docType{methods} 4 | \name{distance} 5 | \alias{distance} 6 | \alias{dist,vclMatrix-method} 7 | \alias{dist,vclMatrix} 8 | \alias{distance,vclMatrix,vclMatrix-method} 9 | \alias{distance,vclMatrix} 10 | \alias{dist,gpuMatrix-method} 11 | \alias{dist,gpuMatrix} 12 | \alias{distance,gpuMatrix,gpuMatrix-method} 13 | \alias{distance,gpuMatrix} 14 | \title{GPU Distance Matrix Computations} 15 | \usage{ 16 | distance(x, y, method = "euclidean") 17 | 18 | \S4method{dist}{vclMatrix}(x, method = "euclidean", diag = FALSE, 19 | upper = FALSE, p = 2) 20 | 21 | \S4method{distance}{vclMatrix,vclMatrix}(x, y, method = "euclidean") 22 | 23 | \S4method{dist}{gpuMatrix}(x, method = "euclidean", diag = FALSE, 24 | upper = FALSE, p = 2) 25 | 26 | \S4method{distance}{gpuMatrix,gpuMatrix}(x, y, method = "euclidean") 27 | } 28 | \arguments{ 29 | \item{x}{A gpuMatrix or vclMatrix object} 30 | 31 | \item{y}{A gpuMatrix or vclMatrix object} 32 | 33 | \item{method}{the distance measure to be used. This must be one of 34 | "euclidean" or "sqEuclidean".} 35 | 36 | \item{diag}{logical value indicating whether the diagonal of the distance 37 | matrix should be printed} 38 | 39 | \item{upper}{logical value indicating whether the upper triangle of the 40 | distance matrix} 41 | 42 | \item{p}{The power of the Minkowski distance (not currently used)} 43 | } 44 | \value{ 45 | a gpuMatrix/vclMatrix containing the corresponding distances 46 | } 47 | \description{ 48 | This function computes and returns the distance matrix 49 | computed by using the specified distance measure to compute the distances 50 | between the rows of a data matrix. 51 | } 52 | -------------------------------------------------------------------------------- /inst/CL/dcholesky.cl: -------------------------------------------------------------------------------- 1 | 2 | 3 | __kernel void update_kk(__global double *A, unsigned int N, unsigned int k) 4 | { 5 | A[k * N + k] = sqrt(A[k * N + k]); 6 | } 7 | 8 | __kernel void update_k(__global double *A, const int upper, unsigned int N, unsigned int Npad, unsigned int k) 9 | { 10 | int i = get_global_id(0); 11 | 12 | if(i > k && i < N) { 13 | double Akk = A[k * Npad + k]; 14 | 15 | if(upper == 0){ 16 | // lower 17 | A[i * Npad + k] = A[i * Npad + k] / Akk; 18 | 19 | // zero out the top too - only if in-place 20 | A[k * Npad + i] = 0; 21 | }else if(upper == 1){ 22 | // upper??? 23 | A[k * Npad + i] = A[k * Npad + i] / Akk; 24 | 25 | // zero out the top too - only if in-place 26 | A[i * Npad + k] = 0; 27 | }else{ 28 | return; 29 | } 30 | } 31 | } 32 | 33 | __kernel void update_block(__global double *A, const int upper, unsigned int N, unsigned int Npad, unsigned int k) 34 | { 35 | int i = get_global_id(0); 36 | int j = get_global_id(1); 37 | 38 | if(i <= k || j <= k) return; 39 | if(i >= N || j > i) return; 40 | 41 | if(upper == 0){ 42 | // lower 43 | double Aik = A[i * Npad + k]; 44 | double Ajk = A[j * Npad + k]; 45 | double Aij = A[i * Npad + j]; 46 | 47 | A[i * Npad + j] = Aij - Aik * Ajk; 48 | 49 | }else if(upper ==1 ){ 50 | // upper 51 | double Aik = A[k * Npad + i]; 52 | double Ajk = A[k * Npad + j]; 53 | double Aij = A[j * Npad + i]; 54 | 55 | A[j * Npad + i] = Aij - Aik * Ajk; 56 | }else{ 57 | return; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /man/vclMatrix-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-vclMatrix.R 3 | \docType{class} 4 | \name{vclMatrix-class} 5 | \alias{vclMatrix-class} 6 | \title{vclMatrix Class} 7 | \description{ 8 | This is the 'mother' class for all 9 | vclMatrix objects. These objects are pointers 10 | to viennacl matrices directly on the GPU. This will 11 | avoid the overhead of passing data back and forth 12 | between the host and device. 13 | 14 | As such, any changes made 15 | to normal R 'copies' (e.g. A <- B) will be propogated to 16 | the parent object. 17 | 18 | There are multiple child classes that correspond 19 | to the particular data type contained. These include 20 | \code{ivclMatrix}, \code{fvclMatrix}, and 21 | \code{dvclMatrix} corresponding to integer, float, and 22 | double data types respectively. 23 | } 24 | \note{ 25 | R does not contain a native float type. As such, 26 | the matrix data within a \code{\link{fvclMatrix-class}} 27 | will be represented as double but downcast when any 28 | vclMatrix methods are used. 29 | 30 | May also remove the type slot 31 | } 32 | \section{Slots}{ 33 | 34 | Common to all vclMatrix objects in the package 35 | \describe{ 36 | \item{\code{address}:}{Pointer to data matrix} 37 | \item{\code{.context_index}:}{Integer index of OpenCL contexts} 38 | \item{\code{.platform_index}:}{Integer index of OpenCL platforms} 39 | \item{\code{.platform}:}{Name of OpenCL platform} 40 | \item{\code{.device_index}:}{Integer index of active device} 41 | \item{\code{.device}:}{Name of active device} 42 | } 43 | } 44 | 45 | \seealso{ 46 | \code{\link{ivclMatrix-class}}, 47 | \code{\link{fvclMatrix-class}}, 48 | \code{\link{dvclMatrix-class}} 49 | } 50 | \author{ 51 | Charles Determan Jr. 52 | } 53 | -------------------------------------------------------------------------------- /R/wrappers-vclVector.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | # GPU Element-Wise Absolute Value 4 | vclVecElemMaxAbs <- function(A){ 5 | 6 | type <- typeof(A) 7 | 8 | out <- switch(type, 9 | integer = { 10 | stop("integer not currently implemented") 11 | }, 12 | float = {cpp_vclVector_elem_max_abs(A@address, 13 | 6L) 14 | }, 15 | double = { 16 | cpp_vclVector_elem_max_abs(A@address, 17 | 8L) 18 | }, 19 | stop("type not recognized") 20 | ) 21 | return(out) 22 | } 23 | 24 | # GPU Vector maximum 25 | vclVecMax <- function(A){ 26 | 27 | type <- typeof(A) 28 | 29 | C <- switch(type, 30 | integer = { 31 | stop("integer not currently implemented") 32 | }, 33 | float = {cpp_vclVector_max(A@address, 6L) 34 | }, 35 | double = { 36 | cpp_vclVector_max(A@address, 8L) 37 | }, 38 | stop("type not recognized") 39 | ) 40 | return(C) 41 | } 42 | 43 | 44 | # GPU Vector minimum 45 | vclVecMin <- function(A){ 46 | 47 | type <- typeof(A) 48 | 49 | C <- switch(type, 50 | integer = { 51 | stop("integer not currently implemented") 52 | }, 53 | float = {cpp_vclVector_min(A@address, 6L) 54 | }, 55 | double = { 56 | cpp_vclVector_min(A@address, 8L) 57 | }, 58 | stop("type not recognized") 59 | ) 60 | return(C) 61 | } 62 | 63 | 64 | -------------------------------------------------------------------------------- /inst/CL/fcholesky.cl: -------------------------------------------------------------------------------- 1 | 2 | 3 | __kernel void update_kk(__global float *A, unsigned int N, unsigned int k) 4 | { 5 | A[k * N + k] = sqrt(A[k * N + k]); 6 | } 7 | 8 | __kernel void update_k(__global float *A, const int upper, unsigned int N, unsigned int Npad, unsigned int k) 9 | { 10 | int i = get_global_id(0); 11 | 12 | if(i > k && i < N) { 13 | float Akk = A[k * Npad + k]; 14 | 15 | if(upper == 0){ 16 | // lower 17 | A[i * Npad + k] = A[i * Npad + k] / Akk; 18 | 19 | // zero out the top too - only if in-place 20 | A[k * Npad + i] = 0; 21 | 22 | }else if(upper == 1){ 23 | // upper??? 24 | A[k * Npad + i] = A[k * Npad + i] / Akk; 25 | 26 | // zero out the top too - only if in-place 27 | A[i * Npad + k] = 0; 28 | }else{ 29 | return; 30 | } 31 | } 32 | } 33 | 34 | __kernel void update_block(__global float *A, const int upper, unsigned int N, unsigned int Npad, unsigned int k) 35 | { 36 | int i = get_global_id(0); 37 | int j = get_global_id(1); 38 | 39 | if(i <= k || j <= k) return; 40 | if(i >= N || j > i) return; 41 | 42 | if(upper == 0){ 43 | // lower 44 | float Aik = A[i * Npad + k]; 45 | float Ajk = A[j * Npad + k]; 46 | float Aij = A[i * Npad + j]; 47 | 48 | A[i * Npad + j] = Aij - Aik * Ajk; 49 | 50 | }else if(upper ==1 ){ 51 | // upper??? 52 | float Aik = A[k * Npad + i]; //2 53 | float Ajk = A[k * Npad + j]; //2 54 | float Aij = A[j * Npad + i]; //258 55 | 56 | A[j * Npad + i] = Aij - Aik * Ajk; 57 | 58 | }else{ 59 | return; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /man/vclVector-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/vclVector.R 3 | \docType{methods} 4 | \name{vclVector} 5 | \alias{vclVector} 6 | \alias{vclVector,vector,missing-method} 7 | \alias{vclVector,vector} 8 | \alias{vclVector,missing,ANY-method} 9 | \alias{vclVector,missing} 10 | \alias{vclVector,numeric,numericOrInt-method} 11 | \alias{vclVector,vclMatrix,missing-method} 12 | \title{Construct a vclVector} 13 | \usage{ 14 | vclVector(data, length, type = NULL, ...) 15 | 16 | \S4method{vclVector}{vector,missing}(data, length, type = NULL, 17 | ctx_id = NULL) 18 | 19 | \S4method{vclVector}{missing,ANY}(data, length, type = NULL, 20 | ctx_id = NULL) 21 | 22 | \S4method{vclVector}{numeric,numericOrInt}(data, length, type = NULL, 23 | ctx_id = NULL) 24 | 25 | \S4method{vclVector}{vclMatrix,missing}(data, length = NULL, 26 | type = NULL, ctx_id = NULL, col = NULL, row = NULL) 27 | } 28 | \arguments{ 29 | \item{data}{An object that is or can be converted to a 30 | \code{vector}} 31 | 32 | \item{length}{A non-negative integer specifying the desired length.} 33 | 34 | \item{type}{A character string specifying the type of vclVector. Default 35 | is NULL where type is inherited from the source data type.} 36 | 37 | \item{...}{Additional method to pass to vclVector methods} 38 | 39 | \item{ctx_id}{An integer specifying the object's context} 40 | 41 | \item{col}{index of column to extract from \code{vclMatrix}} 42 | 43 | \item{row}{index of row to extract from \code{vclMatrix}} 44 | } 45 | \value{ 46 | A vclVector object 47 | } 48 | \description{ 49 | Construct a vclVector of a class that inherits 50 | from \code{vclVector}. This class points to memory directly on 51 | the GPU to avoid the cost of data transfer between host and device. 52 | } 53 | \author{ 54 | Charles Determan Jr. 55 | } 56 | -------------------------------------------------------------------------------- /tests/testthat/test_cpu_gpuMatrix_chol.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("CPU gpuMatrix chol decomposition") 3 | 4 | current_context <- set_device_context("cpu") 5 | 6 | # set seed 7 | set.seed(123) 8 | 9 | ORDER <- 10 10 | 11 | # Base R objects 12 | X <- matrix(rnorm(ORDER^2), nrow=ORDER, ncol=ORDER) 13 | X <- X %*% t(X) 14 | # X <- matrix(c(5,1,1,3),2,2) 15 | nsqA <- matrix(rnorm(20), nrow = 4) 16 | 17 | D <- chol(X) 18 | 19 | test_that("CPU gpuMatrix Single Precision Matrix Cholesky Decomposition", 20 | { 21 | 22 | has_cpu_skip() 23 | 24 | fgpuX <- gpuMatrix(X, type="float") 25 | fgpuA <- gpuMatrix(nsqA, type = "float") 26 | 27 | C <- chol(fgpuX) 28 | 29 | expect_is(C, "fgpuMatrix") 30 | expect_equal(C[], D, tolerance=1e-05, 31 | info="float cholesky decomposition not equivalent") 32 | expect_error(chol(fgpuA), "'x' must be a square matrix", 33 | info = "chol shouldn't accept non-square matrices") 34 | }) 35 | 36 | test_that("CPU gpuMatrix Double Precision Matrix Cholesky Decomposition", 37 | { 38 | 39 | has_cpu_skip() 40 | 41 | fgpuX <- gpuMatrix(X, type="double") 42 | fgpuA <- gpuMatrix(nsqA, type = "double") 43 | 44 | C <- chol(fgpuX) 45 | 46 | expect_is(C, "dgpuMatrix") 47 | expect_equal(C[], D, tolerance=.Machine$double.eps^0.5, 48 | info="double cholesky decomposition not equivalent") 49 | expect_error(chol(fgpuA), "'x' must be a square matrix", 50 | info = "chol shouldn't accept non-square matrices") 51 | }) 52 | 53 | setContext(current_context) -------------------------------------------------------------------------------- /tests/testthat/test_cpu_vclMatrix_chol.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("CPU vclMatrix chol decomposition") 3 | 4 | current_context <- set_device_context("cpu") 5 | 6 | # set seed 7 | set.seed(123) 8 | 9 | ORDER <- 10 10 | 11 | # Base R objects 12 | X <- matrix(rnorm(ORDER^2), nrow=ORDER, ncol=ORDER) 13 | X <- X %*% t(X) 14 | # X <- matrix(c(5,1,1,3),2,2) 15 | nsqA <- matrix(rnorm(20), nrow = 4) 16 | 17 | D <- chol(X) 18 | 19 | test_that("CPU vclMatrix Single Precision Matrix Cholesky Decomposition", 20 | { 21 | 22 | has_cpu_skip() 23 | 24 | fgpuX <- vclMatrix(X, type="float") 25 | fgpuA <- vclMatrix(nsqA, type = "float") 26 | 27 | C <- chol(fgpuX) 28 | 29 | expect_is(C, "fvclMatrix") 30 | expect_equal(C[], D, tolerance=1e-05, 31 | info="float cholesky decomposition not equivalent") 32 | expect_error(chol(fgpuA), "'x' must be a square matrix", 33 | info = "chol shouldn't accept non-square matrices") 34 | }) 35 | 36 | test_that("CPU vclMatrix Double Precision Matrix Cholesky Decomposition", 37 | { 38 | 39 | has_cpu_skip() 40 | 41 | fgpuX <- vclMatrix(X, type="double") 42 | fgpuA <- vclMatrix(nsqA, type = "double") 43 | 44 | C <- chol(fgpuX) 45 | 46 | expect_is(C, "dvclMatrix") 47 | expect_equal(C[], D, tolerance=.Machine$double.eps^0.5, 48 | info="double cholesky decomposition not equivalent") 49 | expect_error(chol(fgpuA), "'x' must be a square matrix", 50 | info = "chol shouldn't accept non-square matrices") 51 | }) 52 | 53 | setContext(current_context) 54 | -------------------------------------------------------------------------------- /inst/include/gpuR/getVCLptr.hpp: -------------------------------------------------------------------------------- 1 | 2 | #ifndef GET_VCL_PTR_HPP 3 | #define GET_VCL_PTR_HPP 4 | 5 | #include "gpuR/dynVCLMat.hpp" 6 | #include "gpuR/dynVCLVec.hpp" 7 | #include "gpuR/dynEigenMat.hpp" 8 | #include "gpuR/dynEigenVec.hpp" 9 | 10 | template 11 | std::shared_ptr > 12 | getVCLptr( 13 | SEXP ptr_, 14 | const bool isVCL, 15 | const int ctx_id 16 | ){ 17 | std::shared_ptr > vclptr; 18 | 19 | if(isVCL){ 20 | Rcpp::XPtr > ptr(ptr_); 21 | vclptr = ptr->sharedPtr(); 22 | }else{ 23 | Rcpp::XPtr > ptr(ptr_); 24 | ptr->to_device(ctx_id); 25 | vclptr = ptr->getDevicePtr(); 26 | } 27 | 28 | return vclptr; 29 | } 30 | 31 | template 32 | std::shared_ptr > > 33 | getVCLBlockptr( 34 | SEXP ptr_, 35 | const bool isVCL, 36 | const int ctx_id 37 | ){ 38 | std::shared_ptr > > vclptr; 39 | 40 | if(isVCL){ 41 | Rcpp::XPtr > ptr(ptr_); 42 | vclptr = ptr->sharedBlockPtr(); 43 | }else{ 44 | Rcpp::XPtr > ptr(ptr_); 45 | ptr->to_device(ctx_id); 46 | vclptr = ptr->getDeviceBlockPtr(); 47 | } 48 | 49 | return vclptr; 50 | } 51 | 52 | template 53 | std::shared_ptr > 54 | getVCLVecptr( 55 | SEXP ptr_, 56 | const bool isVCL, 57 | const int ctx_id 58 | ){ 59 | std::shared_ptr > vclptr; 60 | 61 | if(isVCL){ 62 | Rcpp::XPtr > ptr(ptr_); 63 | vclptr = ptr->sharedPtr(); 64 | }else{ 65 | Rcpp::XPtr > ptr(ptr_); 66 | 67 | ptr->to_device(ctx_id); 68 | vclptr = ptr->getDevicePtr(); 69 | } 70 | 71 | return vclptr; 72 | } 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /man/eigen-gpuMatrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/eigen.R 3 | \docType{methods} 4 | \name{eigen,gpuMatrix-method} 5 | \alias{eigen,gpuMatrix-method} 6 | \alias{eigen,vclMatrix} 7 | \alias{eigen,vclMatrix-method} 8 | \title{gpuMatrix Eigen Decomposition} 9 | \usage{ 10 | \S4method{eigen}{gpuMatrix}(x, symmetric, only.values = FALSE, 11 | EISPACK = FALSE) 12 | 13 | \S4method{eigen}{vclMatrix}(x, symmetric, only.values = FALSE, 14 | EISPACK = FALSE) 15 | } 16 | \arguments{ 17 | \item{x}{A gpuMatrix object} 18 | 19 | \item{symmetric}{logical indication if matrix is assumed to be symmetric. 20 | If not specified or FALSE, the matrix is inspected for symmetry} 21 | 22 | \item{only.values}{if TRUE, returns only eigenvalues (internals still 23 | currently calculate both regardless)} 24 | 25 | \item{EISPACK}{logical. Defunct and ignored} 26 | } 27 | \value{ 28 | \item{values}{A \code{gpuVector} containing the unsorted eigenvalues 29 | of x.} 30 | 31 | \item{vectors}{A \code{gpuMatrix} containing the unsorted 32 | eigenvectors of x} 33 | } 34 | \description{ 35 | Computes the eigenvalues and eigenvectors for gpuMatrix objects. 36 | } 37 | \details{ 38 | This function currently implements the \code{qr_method} function 39 | from the ViennaCL library. As such, non-symmetric matrices are not 40 | supported given that OpenCL does not have a 'complex' data type. 41 | 42 | Neither the eigenvalues nor the eigenvectors are sorted as done in the 43 | base R eigen method. 44 | } 45 | \note{ 46 | The sign's may be different on some of the eigenvector elements. 47 | As noted in the base eigen documentation: 48 | 49 | Recall that the eigenvectors are only defined up to a 50 | constant: even when the length is specified they are still 51 | only defined up to a scalar of modulus one (the sign for real 52 | matrices). 53 | 54 | Therefore, although the signs may be different, the results are 55 | functionally equivalent 56 | } 57 | -------------------------------------------------------------------------------- /tests/testthat/test_switch_gpu_vclMatrix_cov.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("Switching GPUs vclMatrix Correlations") 3 | 4 | if(detectGPUs() >= 1){ 5 | current_context <- set_device_context("gpu") 6 | }else{ 7 | current_context <- currentContext() 8 | } 9 | 10 | # set seed 11 | set.seed(123) 12 | 13 | ORDER_X <- 4 14 | ORDER_Y <- 5 15 | 16 | # Base R objects 17 | A <- matrix(rnorm(ORDER_X*ORDER_Y), nrow=ORDER_X, ncol=ORDER_Y) 18 | 19 | C <- cov(A) 20 | 21 | 22 | test_that("Switching GPUs vclMatrix Single Precision Pearson Covariance", 23 | { 24 | has_multiple_gpu_skip() 25 | 26 | setContext(2L) 27 | 28 | fgpuX <- vclMatrix(A, type="float") 29 | 30 | setContext(1L) 31 | 32 | gpuC <- cov(fgpuX) 33 | 34 | expect_is(gpuC, "fvclMatrix") 35 | expect_equal(gpuC[], C, tolerance=1e-06, 36 | info="float covariance values not equivalent") 37 | expect_equal(gpuC@.context_index, 2L, 38 | info = "context index hasn't been assigned correctly") 39 | expect_equal(currentContext(), 1L, 40 | info = "context index has been change unintentionally") 41 | }) 42 | 43 | test_that("Switching GPUs vclMatrix Double Precision Pearson Covariance", 44 | { 45 | 46 | has_multiple_gpu_skip() 47 | has_multiple_double_skip() 48 | 49 | setContext(2L) 50 | 51 | dgpuX <- vclMatrix(A, type="double") 52 | 53 | setContext(1L) 54 | 55 | gpuC <- cov(dgpuX) 56 | 57 | expect_is(gpuC, "dvclMatrix") 58 | expect_equal(gpuC[], C, tolerance=.Machine$double.eps ^ 0.5, 59 | info="double covariance values not equivalent") 60 | expect_equal(gpuC@.context_index, 2L, 61 | info = "context index hasn't been assigned correctly") 62 | expect_equal(currentContext(), 1L, 63 | info = "context index has been change unintentionally") 64 | }) 65 | 66 | setContext(current_context) 67 | -------------------------------------------------------------------------------- /R/hello-gpuR.R: -------------------------------------------------------------------------------- 1 | #' @title GPU functions for R Objects 2 | #' 3 | #' @description This package was developed to provide simple to use R functions 4 | #' that leverage the power of GPU's but also retain a format familiar to the 5 | #' R user. There are a hand full of other R packages that provide some 6 | #' GPU functionality but nearly all rely on a CUDA backend thereby restricting 7 | #' the user to NVIDIA GPU hardware. In the spirit of being as broadly 8 | #' applicable as possible, this GPU code herein relies upon OpenCL via the 9 | #' ViennaCL library. 10 | #' 11 | #' OpenCL, in contrast to CUDA, is open source and can be used across 12 | #' different graphics cards (e.g. NVIDIA, AMD, Intel). This package removes 13 | #' the complex code needed for GPU computing and provides easier to use 14 | #' functions to apply on R objects. 15 | #' 16 | #' \tabular{ll}{ Package: \tab gpuR\cr Type: \tab Package\cr 17 | #' Version: \tab 1.0.0\cr Date: \tab 2015-03-31\cr License: \tab GPL-3\cr 18 | #' Copyright: \tab (c) 2015 Charles E. Determan Jr.\cr URL: \tab 19 | #' \url{http://www.github.com/cdeterman/gpuR}\cr LazyLoad: \tab yes\cr 20 | #' } 21 | #' 22 | #' 23 | #' @note There are other packages that also provide wrappers for OpenCL 24 | #' programming including \pkg{OpenCL} by Simon Urbanek and \bold{ROpenCL} at 25 | #' Open Analytics by Willem Ligtenberg. Both of these packages provide 26 | #' the R user an interface to directly call OpenCL functions. This package, 27 | #' however, hides these functions so the user does not require any knowledge 28 | #' of OpenCL to begin using their GPU. The idea behind this package is to 29 | #' provide a means to begin using existing algorithms without the need 30 | #' to write extensive amounts of C/C++/OpenCL code. 31 | #' @author 32 | #' Charles Determan \email{cdetermanjr@@gmail.com} 33 | #' 34 | #' Maintainer: Charles Determan \email{cdetermanjr@@gmail.com} 35 | #' @docType package 36 | #' @name gpuR-package 37 | #' @aliases gpuR-package gpuR 38 | NULL -------------------------------------------------------------------------------- /man/cov-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/methods-vclMatrix.R, R/methods.R 3 | \docType{methods} 4 | \name{cov,vclMatrix,missing,missing,missing-method} 5 | \alias{cov,vclMatrix,missing,missing,missing-method} 6 | \alias{cov,vclMatrix,vclMatrix,missing,missing-method} 7 | \alias{cov,vclMatrix,missing,missing,character-method} 8 | \alias{cov,vclMatrix,vclMatrix,missing,character-method} 9 | \alias{cov,gpuMatrix,missing,missing,missing-method} 10 | \alias{cov,gpuMatrix,gpuMatrix,missing,missing-method} 11 | \alias{cov,gpuMatrix,missing,missing,character-method} 12 | \alias{cov,gpuMatrix,gpuMatrix,missing,character-method} 13 | \title{Covariance (gpuR)} 14 | \usage{ 15 | \S4method{cov}{vclMatrix,missing,missing,missing}(x, y = NULL, 16 | use = NULL, method = "pearson") 17 | 18 | \S4method{cov}{vclMatrix,vclMatrix,missing,missing}(x, y = NULL, 19 | use = NULL, method = "pearson") 20 | 21 | \S4method{cov}{vclMatrix,missing,missing,character}(x, y = NULL, 22 | use = NULL, method = "pearson") 23 | 24 | \S4method{cov}{vclMatrix,vclMatrix,missing,character}(x, y = NULL, 25 | use = NULL, method = "pearson") 26 | 27 | \S4method{cov}{gpuMatrix,missing,missing,missing}(x, y = NULL, 28 | use = NULL, method = "pearson") 29 | 30 | \S4method{cov}{gpuMatrix,gpuMatrix,missing,missing}(x, y = NULL, 31 | use = NULL, method = "pearson") 32 | 33 | \S4method{cov}{gpuMatrix,missing,missing,character}(x, y = NULL, 34 | use = NULL, method = "pearson") 35 | 36 | \S4method{cov}{gpuMatrix,gpuMatrix,missing,character}(x, y = NULL, 37 | use = NULL, method = "pearson") 38 | } 39 | \arguments{ 40 | \item{x}{A gpuR object} 41 | 42 | \item{y}{A gpuR object} 43 | 44 | \item{use}{Not used} 45 | 46 | \item{method}{Character string indicating with covariance to be computed.} 47 | } 48 | \value{ 49 | A gpuMatrix/vclMatrix containing the symmetric covariance values. 50 | } 51 | \description{ 52 | Compute covariance values 53 | } 54 | \author{ 55 | Charles Determan Jr. 56 | } 57 | -------------------------------------------------------------------------------- /man/gpuR-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/hello-gpuR.R 3 | \docType{package} 4 | \name{gpuR-package} 5 | \alias{gpuR-package} 6 | \alias{gpuR} 7 | \title{GPU functions for R Objects} 8 | \description{ 9 | This package was developed to provide simple to use R functions 10 | that leverage the power of GPU's but also retain a format familiar to the 11 | R user. There are a hand full of other R packages that provide some 12 | GPU functionality but nearly all rely on a CUDA backend thereby restricting 13 | the user to NVIDIA GPU hardware. In the spirit of being as broadly 14 | applicable as possible, this GPU code herein relies upon OpenCL via the 15 | ViennaCL library. 16 | 17 | OpenCL, in contrast to CUDA, is open source and can be used across 18 | different graphics cards (e.g. NVIDIA, AMD, Intel). This package removes 19 | the complex code needed for GPU computing and provides easier to use 20 | functions to apply on R objects. 21 | 22 | \tabular{ll}{ Package: \tab gpuR\cr Type: \tab Package\cr 23 | Version: \tab 1.0.0\cr Date: \tab 2015-03-31\cr License: \tab GPL-3\cr 24 | Copyright: \tab (c) 2015 Charles E. Determan Jr.\cr URL: \tab 25 | \url{http://www.github.com/cdeterman/gpuR}\cr LazyLoad: \tab yes\cr 26 | } 27 | } 28 | \note{ 29 | There are other packages that also provide wrappers for OpenCL 30 | programming including \pkg{OpenCL} by Simon Urbanek and \bold{ROpenCL} at 31 | Open Analytics by Willem Ligtenberg. Both of these packages provide 32 | the R user an interface to directly call OpenCL functions. This package, 33 | however, hides these functions so the user does not require any knowledge 34 | of OpenCL to begin using their GPU. The idea behind this package is to 35 | provide a means to begin using existing algorithms without the need 36 | to write extensive amounts of C/C++/OpenCL code. 37 | } 38 | \author{ 39 | Charles Determan \email{cdetermanjr@gmail.com} 40 | 41 | Maintainer: Charles Determan \email{cdetermanjr@gmail.com} 42 | } 43 | -------------------------------------------------------------------------------- /tests/testthat/test_gpuMatrix_chol.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("gpuMatrix chol decomposition") 3 | 4 | if(detectGPUs() >= 1){ 5 | current_context <- set_device_context("gpu") 6 | }else{ 7 | current_context <- currentContext() 8 | } 9 | 10 | # set seed 11 | set.seed(123) 12 | 13 | ORDER <- 10 14 | 15 | # Base R objects 16 | X <- matrix(rnorm(ORDER^2), nrow=ORDER, ncol=ORDER) 17 | X <- X %*% t(X) 18 | # X <- matrix(c(5,1,1,3),2,2) 19 | nsqA <- matrix(rnorm(20), nrow = 4) 20 | 21 | D <- chol(X) 22 | 23 | test_that("gpuMatrix Single Precision Matrix Cholesky Decomposition", 24 | { 25 | 26 | has_gpu_skip() 27 | 28 | fgpuX <- gpuMatrix(X, type="float") 29 | fgpuA <- gpuMatrix(nsqA, type = "float") 30 | 31 | C <- chol(fgpuX) 32 | 33 | expect_is(C, "fgpuMatrix") 34 | expect_equal(C[], D, tolerance=1e-05, 35 | info="float cholesky decomposition not equivalent") 36 | expect_error(chol(fgpuA), "'x' must be a square matrix", 37 | info = "chol shouldn't accept non-square matrices") 38 | }) 39 | 40 | test_that("gpuMatrix Double Precision Matrix Cholesky Decomposition", 41 | { 42 | 43 | has_gpu_skip() 44 | has_double_skip() 45 | 46 | fgpuX <- gpuMatrix(X, type="double") 47 | fgpuA <- gpuMatrix(nsqA, type = "double") 48 | 49 | C <- chol(fgpuX) 50 | 51 | expect_is(C, "dgpuMatrix") 52 | expect_equal(C[], D, tolerance=.Machine$double.eps^0.5, 53 | info="double cholesky decomposition not equivalent") 54 | expect_error(chol(fgpuA), "'x' must be a square matrix", 55 | info = "chol shouldn't accept non-square matrices") 56 | }) 57 | 58 | setContext(current_context) 59 | -------------------------------------------------------------------------------- /tests/testthat/test_vclMatrix_chol.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("vclMatrix chol decomposition") 3 | 4 | if(detectGPUs() >= 1){ 5 | current_context <- set_device_context("gpu") 6 | }else{ 7 | current_context <- currentContext() 8 | } 9 | 10 | # set seed 11 | set.seed(123) 12 | 13 | ORDER <- 10 14 | 15 | # Base R objects 16 | X <- matrix(rnorm(ORDER^2), nrow=ORDER, ncol=ORDER) 17 | X <- X %*% t(X) 18 | # X <- matrix(c(5,1,1,3),2,2) 19 | nsqA <- matrix(rnorm(20), nrow = 4) 20 | 21 | D <- chol(X) 22 | 23 | test_that("vclMatrix Single Precision Matrix Cholesky Decomposition", 24 | { 25 | 26 | has_gpu_skip() 27 | 28 | fgpuX <- vclMatrix(X, type="float") 29 | fgpuA <- vclMatrix(nsqA, type = "float") 30 | 31 | C <- chol(fgpuX) 32 | 33 | # print(C[]) 34 | 35 | expect_is(C, "fvclMatrix") 36 | expect_equal(C[], D, tolerance=1e-05, 37 | info="float cholesky decomposition not equivalent") 38 | expect_error(chol(fgpuA), "'x' must be a square matrix", 39 | info = "chol shouldn't accept non-square matrices") 40 | }) 41 | 42 | test_that("vclMatrix Double Precision Matrix Cholesky Decomposition", 43 | { 44 | 45 | has_gpu_skip() 46 | has_double_skip() 47 | 48 | fgpuX <- vclMatrix(X, type="double") 49 | fgpuA <- gpuMatrix(nsqA, type = "double") 50 | 51 | C <- chol(fgpuX) 52 | 53 | expect_is(C, "dvclMatrix") 54 | expect_equal(C[], D, tolerance=.Machine$double.eps^0.5, 55 | info="double cholesky decomposition not equivalent") 56 | expect_error(chol(fgpuA), "'x' must be a square matrix", 57 | info = "chol shouldn't accept non-square matrices") 58 | }) 59 | 60 | setContext(current_context) 61 | -------------------------------------------------------------------------------- /tests/testthat/test_shared_memory.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("vclVector shared memory") 3 | 4 | if(detectGPUs() >= 1){ 5 | current_context <- set_device_context("gpu") 6 | }else{ 7 | current_context <- currentContext() 8 | } 9 | 10 | # set seed 11 | set.seed(123) 12 | 13 | ORDER <- 4 14 | 15 | # Base R objects 16 | A <- matrix(rnorm(ORDER^2), nrow=ORDER, ncol=ORDER) 17 | 18 | test_that("Share memory between vclMatrix & vclVector", { 19 | 20 | has_gpu_skip() 21 | 22 | gpuA <- vclMatrix(A, type = "float") 23 | 24 | # convert to vector 25 | gpuB <- as.vclVector(gpuA, shared = TRUE) 26 | 27 | expect_is(gpuB, "fvclVector") 28 | expect_equal(gpuA[1], gpuB[1], tolerance=1e-07, 29 | info="float elements not equivalent") 30 | 31 | has_double_skip() 32 | 33 | gpuA <- vclMatrix(A, type = "double") 34 | 35 | # convert to vector 36 | gpuB <- as.vclVector(gpuA, shared = TRUE) 37 | 38 | gpuB[1] <- 42 39 | 40 | expect_is(gpuB, "dvclVector") 41 | expect_equal(gpuA[1], gpuB[1], tolerance=.Machine$double.eps^0.5, 42 | info="double elements not equivalent") 43 | }) 44 | 45 | 46 | test_that("Non-Shared memory between vclMatrix & vclVector", { 47 | 48 | has_gpu_skip() 49 | 50 | gpuA <- vclMatrix(A, type = "float") 51 | 52 | # convert to vector 53 | gpuB <- as.vclVector(gpuA) 54 | 55 | expect_is(gpuB, "fvclVector") 56 | expect_equal(gpuA[1], gpuB[1], tolerance=1e-07, 57 | info="float elements not equivalent") 58 | expect_equivalent(length(gpuB), length(gpuA)) 59 | 60 | has_double_skip() 61 | 62 | gpuA <- vclMatrix(A) 63 | 64 | # convert to vector 65 | gpuB <- as.vclVector(gpuA) 66 | 67 | # gpuB[1] <- 42 68 | 69 | expect_is(gpuB, "dvclVector") 70 | expect_equal(gpuA[1], gpuB[1], tolerance=.Machine$double.eps^0.5, 71 | info="double elements not equivalent") 72 | expect_equivalent(length(gpuB), length(gpuA)) 73 | }) 74 | 75 | setContext(current_context) 76 | -------------------------------------------------------------------------------- /tests/testthat/test_utils.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("Utility Functions") 3 | 4 | 5 | if(detectGPUs() >= 1){ 6 | current_context <- set_device_context("gpu") 7 | }else{ 8 | current_context <- currentContext() 9 | } 10 | 11 | test_that("detectGPUs() accepts appropriate input", { 12 | 13 | # should function regardless of GPUs 14 | expect_gte(detectGPUs(NULL), 0) 15 | expect_gte(detectGPUs(1L), 0) 16 | 17 | has_gpu_skip() 18 | 19 | expect_error(detectGPUs(0)) 20 | expect_error(detectGPUs(2)) 21 | expect_error(detectGPUs(c(2,3))) 22 | expect_error(detectGPUs(7)) 23 | }) 24 | 25 | test_that("gpuInfo() accepts appropriate input", { 26 | 27 | has_gpu_skip() 28 | 29 | expect_error(gpuInfo(0, 0)) 30 | expect_error(gpuInfo(2, 2)) 31 | expect_error(gpuInfo(0, 1)) 32 | expect_error(gpuInfo(1, 0)) 33 | expect_error(gpuInfo(c(2,3), 1)) 34 | expect_error(gpuInfo(1, detectGPUs() + 1)) 35 | 36 | expect_is(gpuInfo(), "list") 37 | }) 38 | 39 | setContext(current_context) 40 | 41 | current_context <- set_device_context("cpu") 42 | 43 | test_that("cpuInfo() accepts appropriate input", { 44 | 45 | has_cpu_skip() 46 | 47 | expect_error(cpuInfo(0, 0)) 48 | expect_error(cpuInfo(2, 2)) 49 | expect_error(cpuInfo(0, 1)) 50 | expect_error(cpuInfo(1, 0)) 51 | expect_error(cpuInfo(c(2,3), 1)) 52 | expect_error(cpuInfo(1, detectCPUs() + 1)) 53 | 54 | expect_is(cpuInfo(), "list") 55 | }) 56 | 57 | setContext(current_context) 58 | 59 | test_that("detectCPUs() accepts correct input", { 60 | 61 | # should function regardless of CPUs 62 | expect_gte(detectCPUs(NULL), 0) 63 | expect_gte(detectCPUs(1L), 0) 64 | 65 | has_cpu_skip() 66 | 67 | expect_error(detectCPUs(0)) 68 | expect_error(detectCPUs(2)) 69 | expect_error(detectCPUs(c(2,3))) 70 | expect_error(detectCPUs(7)) 71 | }) 72 | 73 | test_that("contexts behave correctly", { 74 | expect_error(setContext(100), 75 | info = "should through error on out-of-bounds context") 76 | }) 77 | 78 | -------------------------------------------------------------------------------- /include/CL/opencl.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2008-2015 The Khronos Group Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and/or associated documentation files (the 6 | * "Materials"), to deal in the Materials without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Materials, and to 9 | * permit persons to whom the Materials are furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Materials. 14 | * 15 | * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS 16 | * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS 17 | * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT 18 | * https://www.khronos.org/registry/ 19 | * 20 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 27 | ******************************************************************************/ 28 | 29 | /* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ 30 | 31 | #ifndef __OPENCL_H 32 | #define __OPENCL_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #ifdef __APPLE__ 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #else 46 | 47 | #include 48 | #include 49 | #include 50 | #include 51 | 52 | #endif 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif /* __OPENCL_H */ 59 | 60 | -------------------------------------------------------------------------------- /inst/include/CL/opencl.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2008-2015 The Khronos Group Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and/or associated documentation files (the 6 | * "Materials"), to deal in the Materials without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Materials, and to 9 | * permit persons to whom the Materials are furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Materials. 14 | * 15 | * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS 16 | * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS 17 | * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT 18 | * https://www.khronos.org/registry/ 19 | * 20 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 27 | ******************************************************************************/ 28 | 29 | /* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ 30 | 31 | #ifndef __OPENCL_H 32 | #define __OPENCL_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #ifdef __APPLE__ 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #else 46 | 47 | #include 48 | #include 49 | #include 50 | #include 51 | 52 | #endif 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif /* __OPENCL_H */ 59 | 60 | -------------------------------------------------------------------------------- /man/vclMatrix-crossprod.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/methods-gpuVector.R, R/methods-vclMatrix.R, 3 | % R/methods-vclVector.R 4 | \docType{methods} 5 | \name{tcrossprod,gpuVector,gpuVector-method} 6 | \alias{tcrossprod,gpuVector,gpuVector-method} 7 | \alias{tcrossprod,gpuVector,missing-method} 8 | \alias{crossprod,vclMatrix,missing-method} 9 | \alias{crossprod,vclMatrix} 10 | \alias{crossprod,vclMatrix,vclMatrix-method} 11 | \alias{crossprod,vclMatrix,matrix-method} 12 | \alias{crossprod,matrix,vclMatrix-method} 13 | \alias{crossprod,vclMatrix,vclVector-method} 14 | \alias{crossprod,vclVector,vclMatrix-method} 15 | \alias{tcrossprod,vclMatrix,missing-method} 16 | \alias{tcrossprod,vclMatrix,vclMatrix-method} 17 | \alias{tcrossprod,matrix,vclMatrix-method} 18 | \alias{tcrossprod,vclMatrix,matrix-method} 19 | \alias{tcrossprod,vclMatrix,vclVector-method} 20 | \alias{tcrossprod,vclVector,vclMatrix-method} 21 | \alias{tcrossprod,vclVector,vclVector-method} 22 | \alias{tcrossprod,vclVector,missing-method} 23 | \title{vclMatrix Crossproduct} 24 | \usage{ 25 | \S4method{tcrossprod}{gpuVector,gpuVector}(x, y) 26 | 27 | \S4method{tcrossprod}{gpuVector,missing}(x, y) 28 | 29 | \S4method{crossprod}{vclMatrix,missing}(x, y) 30 | 31 | \S4method{crossprod}{vclMatrix,vclMatrix}(x, y) 32 | 33 | \S4method{crossprod}{vclMatrix,matrix}(x, y) 34 | 35 | \S4method{crossprod}{matrix,vclMatrix}(x, y) 36 | 37 | \S4method{crossprod}{vclMatrix,vclVector}(x, y) 38 | 39 | \S4method{crossprod}{vclVector,vclMatrix}(x, y) 40 | 41 | \S4method{tcrossprod}{vclMatrix,missing}(x, y) 42 | 43 | \S4method{tcrossprod}{vclMatrix,vclMatrix}(x, y) 44 | 45 | \S4method{tcrossprod}{matrix,vclMatrix}(x, y) 46 | 47 | \S4method{tcrossprod}{vclMatrix,matrix}(x, y) 48 | 49 | \S4method{tcrossprod}{vclMatrix,vclVector}(x, y) 50 | 51 | \S4method{tcrossprod}{vclVector,vclMatrix}(x, y) 52 | 53 | \S4method{tcrossprod}{vclVector,vclVector}(x, y) 54 | 55 | \S4method{tcrossprod}{vclVector,missing}(x, y) 56 | } 57 | \arguments{ 58 | \item{x}{A vclMatrix} 59 | 60 | \item{y}{A vclMatrix} 61 | } 62 | \value{ 63 | A vclMatrix 64 | } 65 | \description{ 66 | Return the matrix cross-product of two conformable 67 | matrices using a GPU. This is equivalent to t(x) %*% y (crossprod) 68 | or x %*% t(y) (tcrossprod) but faster as no data transfer between 69 | device and host is required. 70 | } 71 | \author{ 72 | Charles Determan Jr. 73 | } 74 | -------------------------------------------------------------------------------- /R/extract-gpuVector.R: -------------------------------------------------------------------------------- 1 | 2 | #' @rdname extract-methods 3 | #' @export 4 | setMethod("[", 5 | signature(x = "gpuVector", i = "missing", j = "missing", drop = "missing"), 6 | function(x, i, j, drop) { 7 | switch(typeof(x), 8 | "integer" = return(getEigenMatrix(x@address, 4L)), 9 | "float" = return(getEigenMatrix(x@address, 6L)), 10 | "double" = return(getEigenMatrix(x@address, 8L)) 11 | ) 12 | }) 13 | 14 | #' @rdname extract-methods 15 | #' @export 16 | setMethod("[", 17 | signature(x = "gpuVector", i = "numeric", j = "missing", drop = "missing"), 18 | function(x, i, j, drop) { 19 | 20 | assert_all_are_in_closed_range(i, lower = 1, upper = length(x)) 21 | 22 | switch(typeof(x), 23 | "integer" = return(GetVecElement(x@address, i, 4L)), 24 | "float" = return(GetVecElement(x@address, i, 6L)), 25 | "double" = return(GetVecElement(x@address, i, 8L)) 26 | ) 27 | }) 28 | 29 | #' @rdname extract-methods 30 | #' @export 31 | setMethod("[<-", 32 | signature(x = "gpuVector", i = "numeric", j = "missing", value = "numeric"), 33 | function(x, i, j, value) { 34 | 35 | assert_all_are_in_closed_range(i, lower = 1, upper = length(x)) 36 | 37 | if(length(value) != length(i)){ 38 | value <- rep(value, length(i)) 39 | } 40 | 41 | switch(typeof(x), 42 | "float" = SetVecElement(x@address, i, value, 6L), 43 | "double" = SetVecElement(x@address, i, value, 8L), 44 | stop("type not recongized") 45 | ) 46 | return(x) 47 | }) 48 | 49 | #' @rdname extract-methods 50 | #' @export 51 | setMethod("[<-", 52 | signature(x = "gpuVector", i = "numeric", j = "missing", value = "integer"), 53 | function(x, i, j, value) { 54 | 55 | assert_all_are_in_closed_range(i, lower = 1, upper = length(x)) 56 | 57 | switch(typeof(x), 58 | "integer" = SetVecElement(x@address, i, value, 4L), 59 | stop("type not recongized") 60 | ) 61 | return(x) 62 | }) 63 | -------------------------------------------------------------------------------- /tests/testthat/test_vclMatrix_qr.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("vclMatrix qr decomposition") 3 | 4 | if(detectGPUs() >= 1){ 5 | current_context <- set_device_context("gpu") 6 | }else{ 7 | current_context <- currentContext() 8 | } 9 | 10 | # set seed 11 | set.seed(123) 12 | 13 | ORDER <- 10 14 | 15 | # Base R objects 16 | X <- matrix(rnorm(ORDER^2), nrow=ORDER, ncol=ORDER) 17 | nsqA <- matrix(rnorm(20), nrow = 4) 18 | 19 | qrX <- qr(X) 20 | Q <- qr.Q(qrX) 21 | R <- qr.R(qrX) 22 | 23 | test_that("vclMatrix Single Precision Matrix QR Decomposition", 24 | { 25 | 26 | has_gpu_skip() 27 | 28 | fgpuX <- vclMatrix(X, type="float") 29 | fgpuA <- vclMatrix(nsqA, type = "float") 30 | 31 | E <- qr(fgpuX) 32 | gpuQ <- qr.Q(E) 33 | gpuR <- qr.R(E) 34 | 35 | expect_is(E, "gpuQR") 36 | # need abs as some signs are opposite (not important with eigenvectors) 37 | expect_equal(abs(gpuQ[]), abs(Q), tolerance=1e-05, 38 | info="Q matrices not equivalent") 39 | 40 | # make sure X not overwritten 41 | expect_equal(abs(gpuR[]), abs(R), tolerance=1e-05, 42 | info="R matrices not equivalent") 43 | expect_error(qr(fgpuA), "non-square matrix not currently supported for 'qr'", 44 | info = "qr shouldn't accept non-square matrices") 45 | }) 46 | 47 | test_that("vclMatrix Double Precision Matrix QR Decomposition", 48 | { 49 | 50 | has_gpu_skip() 51 | has_double_skip() 52 | 53 | fgpuX <- vclMatrix(X, type="double") 54 | fgpuA <- vclMatrix(nsqA, type = "double") 55 | 56 | E <- qr(fgpuX) 57 | gpuQ <- qr.Q(E) 58 | gpuR <- qr.R(E) 59 | 60 | expect_is(E, "gpuQR") 61 | expect_equal(abs(gpuQ[]), abs(Q), tolerance=.Machine$double.eps ^ 0.5, 62 | info="Q matrices not equivalent") 63 | expect_equal(abs(gpuR[]), abs(R), tolerance=.Machine$double.eps ^ 0.5, 64 | info="R matrices not equivalent") 65 | 66 | expect_error(qr(fgpuA), "non-square matrix not currently supported for 'qr'", 67 | info = "qr shouldn't accept non-square matrices") 68 | }) 69 | 70 | setContext(current_context) 71 | -------------------------------------------------------------------------------- /tests/testthat/test_cpu_vclMatrix_qr.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("CPU vclMatrix qr decomposition") 3 | 4 | current_context <- set_device_context("cpu") 5 | 6 | # set seed 7 | set.seed(123) 8 | 9 | ORDER <- 10 10 | 11 | # Base R objects 12 | X <- matrix(rnorm(ORDER^2), nrow=ORDER, ncol=ORDER) 13 | nsqA <- matrix(rnorm(20), nrow = 4) 14 | 15 | qrX <- qr(X) 16 | Q <- qr.Q(qrX) 17 | R <- qr.R(qrX) 18 | 19 | test_that("CPU vclMatrix Single Precision Matrix QR Decomposition", 20 | { 21 | 22 | has_cpu_skip() 23 | 24 | fgpuX <- vclMatrix(X, type="float") 25 | fgpuA <- vclMatrix(nsqA, type = "float") 26 | 27 | E <- qr(fgpuX) 28 | gpuQ <- qr.Q(E) 29 | gpuR <- qr.R(E) 30 | 31 | expect_is(E, "gpuQR") 32 | # need abs as some signs are opposite (not important with eigenvectors) 33 | expect_equal(abs(gpuQ[]), abs(Q), tolerance=1e-05, 34 | info="Q matrices not equivalent") 35 | 36 | # make sure X not overwritten 37 | expect_equal(abs(gpuR[]), abs(R), tolerance=1e-05, 38 | info="R matrices not equivalent") 39 | expect_error(qr(fgpuA), "non-square matrix not currently supported for 'qr'", 40 | info = "qr shouldn't accept non-square matrices") 41 | }) 42 | 43 | test_that("CPU vclMatrix Double Precision Matrix QR Decomposition", 44 | { 45 | 46 | has_cpu_skip() 47 | 48 | fgpuX <- vclMatrix(X, type="double") 49 | fgpuA <- vclMatrix(nsqA, type = "double") 50 | 51 | E <- qr(fgpuX) 52 | gpuQ <- qr.Q(E) 53 | gpuR <- qr.R(E) 54 | 55 | expect_is(E, "gpuQR") 56 | expect_equal(abs(gpuQ[]), abs(Q), tolerance=.Machine$double.eps ^ 0.5, 57 | info="Q matrices not equivalent") 58 | expect_equal(abs(gpuR[]), abs(R), tolerance=.Machine$double.eps ^ 0.5, 59 | info="R matrices not equivalent") 60 | 61 | expect_error(qr(fgpuA), "non-square matrix not currently supported for 'qr'", 62 | info = "qr shouldn't accept non-square matrices") 63 | }) 64 | 65 | setContext(current_context) 66 | -------------------------------------------------------------------------------- /tests/testthat/test_cpu_gpuMatrix_qr.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("CPU gpuMatrix qr decomposition") 3 | 4 | current_context <- set_device_context("cpu") 5 | 6 | # set seed 7 | set.seed(123) 8 | 9 | ORDER <- 10 10 | 11 | # Base R objects 12 | X <- matrix(rnorm(ORDER^2), nrow=ORDER, ncol=ORDER) 13 | nsqA <- matrix(rnorm(20), nrow = 4) 14 | 15 | qrX <- qr(X) 16 | Q <- qr.Q(qrX) 17 | R <- qr.R(qrX) 18 | 19 | test_that("CPU gpuMatrix Single Precision Matrix QR Decomposition", 20 | { 21 | 22 | has_cpu_skip() 23 | 24 | fgpuX <- gpuMatrix(X, type="float") 25 | fgpuA <- gpuMatrix(nsqA, type = "float") 26 | 27 | E <- qr(fgpuX) 28 | 29 | gpuQ <- qr.Q(E) 30 | gpuR <- qr.R(E) 31 | 32 | expect_is(E, "gpuQR") 33 | # need abs as some signs are opposite (not important with eigenvectors) 34 | expect_equal(abs(gpuQ[]), abs(Q), tolerance=1e-05, 35 | info="Q matrices not equivalent") 36 | 37 | # make sure X not overwritten 38 | expect_equal(abs(gpuR[]), abs(R), tolerance=1e-05, 39 | info="R matrices not equivalent") 40 | expect_error(qr(fgpuA), "non-square matrix not currently supported for 'qr'", 41 | info = "qr shouldn't accept non-square matrices") 42 | }) 43 | 44 | test_that("CPU gpuMatrix Double Precision Matrix QR Decomposition", 45 | { 46 | 47 | has_cpu_skip() 48 | 49 | fgpuX <- gpuMatrix(X, type="double") 50 | fgpuA <- gpuMatrix(nsqA, type = "double") 51 | 52 | E <- qr(fgpuX) 53 | gpuQ <- qr.Q(E) 54 | gpuR <- qr.R(E) 55 | 56 | expect_is(E, "gpuQR") 57 | expect_equal(abs(gpuQ[]), abs(Q), tolerance=.Machine$double.eps ^ 0.5, 58 | info="Q matrices not equivalent") 59 | expect_equal(abs(gpuR[]), abs(R), tolerance=.Machine$double.eps ^ 0.5, 60 | info="R matrices not equivalent") 61 | 62 | expect_error(qr(fgpuA), "non-square matrix not currently supported for 'qr'", 63 | info = "qr shouldn't accept non-square matrices") 64 | }) 65 | 66 | setContext(current_context) -------------------------------------------------------------------------------- /man/inplace-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/inplace.R 3 | \docType{methods} 4 | \name{inplace} 5 | \alias{inplace} 6 | \alias{inplace,function,vclMatrix,vclMatrix-method} 7 | \alias{inplace,function,vclMatrix,missing-method} 8 | \alias{inplace,function,numeric,vclMatrix-method} 9 | \alias{inplace,function,vclMatrix,numeric-method} 10 | \alias{inplace,function,gpuMatrix,gpuMatrix-method} 11 | \alias{inplace,function,gpuMatrix,missing-method} 12 | \alias{inplace,function,numeric,gpuMatrix-method} 13 | \alias{inplace,function,gpuMatrix,numeric-method} 14 | \alias{inplace,function,vclVector,vclVector-method} 15 | \alias{inplace,function,vclVector,missing-method} 16 | \alias{inplace,function,vclVector,numeric-method} 17 | \alias{inplace,function,numeric,vclVector-method} 18 | \alias{inplace,function,gpuVector,gpuVector-method} 19 | \alias{inplace,function,gpuVector,missing-method} 20 | \alias{inplace,function,gpuVector,numeric-method} 21 | \alias{inplace,function,numeric,gpuVector-method} 22 | \title{Inplace Function Wrapper} 23 | \usage{ 24 | inplace(f, x, y) 25 | 26 | \S4method{inplace}{`function`,vclMatrix,vclMatrix}(f, x, y) 27 | 28 | \S4method{inplace}{`function`,vclMatrix,missing}(f, x, y) 29 | 30 | \S4method{inplace}{`function`,numeric,vclMatrix}(f, x, y) 31 | 32 | \S4method{inplace}{`function`,vclMatrix,numeric}(f, x, y) 33 | 34 | \S4method{inplace}{`function`,gpuMatrix,gpuMatrix}(f, x, y) 35 | 36 | \S4method{inplace}{`function`,gpuMatrix,missing}(f, x, y) 37 | 38 | \S4method{inplace}{`function`,numeric,gpuMatrix}(f, x, y) 39 | 40 | \S4method{inplace}{`function`,gpuMatrix,numeric}(f, x, y) 41 | 42 | \S4method{inplace}{`function`,vclVector,vclVector}(f, x, y) 43 | 44 | \S4method{inplace}{`function`,vclVector,missing}(f, x, y) 45 | 46 | \S4method{inplace}{`function`,vclVector,numeric}(f, x, y) 47 | 48 | \S4method{inplace}{`function`,numeric,vclVector}(f, x, y) 49 | 50 | \S4method{inplace}{`function`,gpuVector,gpuVector}(f, x, y) 51 | 52 | \S4method{inplace}{`function`,gpuVector,missing}(f, x, y) 53 | 54 | \S4method{inplace}{`function`,gpuVector,numeric}(f, x, y) 55 | 56 | \S4method{inplace}{`function`,numeric,gpuVector}(f, x, y) 57 | } 58 | \arguments{ 59 | \item{f}{A function} 60 | 61 | \item{x}{A gpuR object} 62 | 63 | \item{y}{A gpuR object} 64 | } 65 | \value{ 66 | No return, result applied in-place 67 | } 68 | \description{ 69 | Applies the provided function in-place on the 70 | first object passed 71 | } 72 | \author{ 73 | Charles Determan Jr. 74 | } 75 | -------------------------------------------------------------------------------- /tests/testthat/test_gpuMatrix_qr.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("gpuMatrix qr decomposition") 3 | 4 | if(detectGPUs() >= 1){ 5 | current_context <- set_device_context("gpu") 6 | }else{ 7 | current_context <- currentContext() 8 | } 9 | 10 | # set seed 11 | set.seed(123) 12 | 13 | ORDER <- 10 14 | 15 | # Base R objects 16 | X <- matrix(rnorm(ORDER^2), nrow=ORDER, ncol=ORDER) 17 | nsqA <- matrix(rnorm(20), nrow = 4) 18 | 19 | qrX <- qr(X) 20 | Q <- qr.Q(qrX) 21 | R <- qr.R(qrX) 22 | 23 | test_that("gpuMatrix Single Precision Matrix QR Decomposition", 24 | { 25 | 26 | has_gpu_skip() 27 | 28 | fgpuX <- gpuMatrix(X, type="float") 29 | fgpuA <- gpuMatrix(nsqA, type = "float") 30 | 31 | E <- qr(fgpuX) 32 | 33 | gpuQ <- qr.Q(E) 34 | gpuR <- qr.R(E) 35 | 36 | expect_is(E, "gpuQR") 37 | # need abs as some signs are opposite (not important with eigenvectors) 38 | expect_equal(abs(gpuQ[]), abs(Q), tolerance=1e-05, 39 | info="Q matrices not equivalent") 40 | 41 | # make sure X not overwritten 42 | expect_equal(abs(gpuR[]), abs(R), tolerance=1e-05, 43 | info="R matrices not equivalent") 44 | expect_error(qr(fgpuA), "non-square matrix not currently supported for 'qr'", 45 | info = "qr shouldn't accept non-square matrices") 46 | }) 47 | 48 | test_that("gpuMatrix Double Precision Matrix QR Decomposition", 49 | { 50 | 51 | has_gpu_skip() 52 | has_double_skip() 53 | 54 | fgpuX <- gpuMatrix(X, type="double") 55 | fgpuA <- gpuMatrix(nsqA, type = "double") 56 | 57 | E <- qr(fgpuX) 58 | gpuQ <- qr.Q(E) 59 | gpuR <- qr.R(E) 60 | 61 | expect_is(E, "gpuQR") 62 | expect_equal(abs(gpuQ[]), abs(Q), tolerance=.Machine$double.eps ^ 0.5, 63 | info="Q matrices not equivalent") 64 | expect_equal(abs(gpuR[]), abs(R), tolerance=.Machine$double.eps ^ 0.5, 65 | info="R matrices not equivalent") 66 | 67 | expect_error(qr(fgpuA), "non-square matrix not currently supported for 'qr'", 68 | info = "qr shouldn't accept non-square matrices") 69 | }) 70 | 71 | setContext(current_context) 72 | -------------------------------------------------------------------------------- /R/typeof.R: -------------------------------------------------------------------------------- 1 | #' @title Get gpuR object type 2 | #' @description \code{typeof} determines the type (i.e. storage mode) of a 3 | #' gpuR object 4 | #' @param x A gpuR object 5 | #' @rdname typeof-gpuR-methods 6 | #' @author Charles Determan Jr. 7 | #' @export 8 | setMethod('typeof', signature(x="gpuMatrix"), 9 | function(x) { 10 | switch(class(x), 11 | "igpuMatrix" = "integer", 12 | "fgpuMatrix" = "float", 13 | "dgpuMatrix" = "double", 14 | "cgpuMatrix" = "fcomplex", 15 | "zgpuMatrix" = "dcomplex", 16 | "igpuMatrixBlock" = "integer", 17 | "fgpuMatrixBlock" = "float", 18 | "dgpuMatrixBlock" = "double", 19 | stop("unrecognized class")) 20 | }) 21 | 22 | #' @rdname typeof-gpuR-methods 23 | #' @export 24 | setMethod('typeof', signature(x="gpuVector"), 25 | function(x) { 26 | switch(class(x), 27 | "igpuVector" = "integer", 28 | "fgpuVector" = "float", 29 | "dgpuVector" = "double", 30 | "cgpuVector" = "fcomplex", 31 | "zgpuVector" = "dcomplex", 32 | "igpuVectorSlice" = "integer", 33 | "fgpuVectorSlice" = "float", 34 | "dgpuVectorSlice" = "double", 35 | stop("unrecognized gpuVector class")) 36 | }) 37 | 38 | #' @rdname typeof-gpuR-methods 39 | #' @export 40 | setMethod('typeof', signature(x="vclMatrix"), 41 | function(x) { 42 | switch(class(x), 43 | "ivclMatrix" = "integer", 44 | "fvclMatrix" = "float", 45 | "dvclMatrix" = "double", 46 | "cvclMatrix" = "fcomplex", 47 | "zvclMatrix" = "dcomplex", 48 | "ivclMatrixBlock" = "integer", 49 | "fvclMatrixBlock" = "float", 50 | "dvclMatrixBlock" = "double", 51 | stop("unrecognized class")) 52 | }) 53 | 54 | 55 | #' @rdname typeof-gpuR-methods 56 | #' @export 57 | setMethod('typeof', signature(x="vclVector"), 58 | function(x) { 59 | switch(class(x), 60 | "ivclVector" = "integer", 61 | "fvclVector" = "float", 62 | "dvclVector" = "double", 63 | "ivclVectorSlice" = "integer", 64 | "fvclVectorSlice" = "float", 65 | "dvclVectorSlice" = "double", 66 | stop("unrecognized vclVector class")) 67 | }) 68 | 69 | 70 | -------------------------------------------------------------------------------- /tests/testthat/test_cpu_gpuMatrix_svd.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("CPU gpuMatrix svd decomposition") 3 | 4 | current_context <- set_device_context("cpu") 5 | 6 | # set seed 7 | set.seed(123) 8 | 9 | ORDER <- 10 10 | 11 | # Base R objects 12 | X <- matrix(rnorm(ORDER^2), nrow=ORDER, ncol=ORDER) 13 | nsqA <- matrix(rnorm(20), nrow = 4) 14 | 15 | rE <- svd(X) 16 | U <- rE$u 17 | V <- rE$v 18 | D <- rE$d 19 | 20 | test_that("CPU gpuMatrix Single Precision Matrix SVD Decomposition", 21 | { 22 | 23 | has_cpu_skip() 24 | 25 | fgpuX <- gpuMatrix(X, type="float") 26 | fgpuA <- gpuMatrix(nsqA, type = "float") 27 | 28 | E <- svd(fgpuX) 29 | 30 | 31 | # need to reorder so it matches R output 32 | ord <- order(-E$d[]) 33 | 34 | expect_is(E, "list") 35 | expect_equal(E$d[][ord], D, tolerance=1e-05, 36 | info="float singular values not equivalent") 37 | 38 | # need abs as some signs are opposite (not important with eigenvectors) 39 | expect_equal(abs(E$u[][,ord]), abs(U), tolerance=1e-05, 40 | info="float left singular vectors not equivalent") 41 | 42 | # make sure X not overwritten 43 | expect_equal(abs(E$v[][,ord]), abs(V), tolerance=1e-05, 44 | info="float right singular vectors not equivalent") 45 | expect_error(svd(fgpuA), "non-square matrix not currently supported for 'svd'", 46 | info = "svd shouldn't accept non-square matrices") 47 | }) 48 | 49 | test_that("CPU gpuMatrix Double Precision Matrix SVD Decomposition", 50 | { 51 | 52 | has_cpu_skip() 53 | 54 | fgpuX <- gpuMatrix(X, type="double") 55 | fgpuA <- gpuMatrix(nsqA, type = "double") 56 | 57 | E <- svd(fgpuX) 58 | 59 | # need to reorder so it matches R output 60 | ord <- order(-E$d[]) 61 | 62 | expect_is(E, "list") 63 | expect_equal(E$d[][ord], D, tolerance=.Machine$double.eps ^ 0.5, 64 | info="double singular values not equivalent") 65 | expect_equal(abs(E$u[][,ord]), abs(U), tolerance=.Machine$double.eps ^ 0.5, 66 | info="double left singular vectors not equivalent") 67 | expect_equal(abs(E$v[][,ord]), abs(V), tolerance=.Machine$double.eps ^ 0.5, 68 | info="double right singular vectors not equivalent") 69 | 70 | expect_error(svd(fgpuA), "non-square matrix not currently supported for 'svd'", 71 | info = "svd shouldn't accept non-square matrices") 72 | }) 73 | 74 | setContext(current_context) 75 | -------------------------------------------------------------------------------- /tests/testthat/test_cpu_vclMatrix_svd.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("CPU vclMatrix svd decomposition") 3 | 4 | current_context <- set_device_context("cpu") 5 | 6 | # set seed 7 | set.seed(123) 8 | 9 | ORDER <- 10 10 | 11 | # Base R objects 12 | X <- matrix(rnorm(ORDER^2), nrow=ORDER, ncol=ORDER) 13 | nsqA <- matrix(rnorm(20), nrow = 4) 14 | 15 | rE <- svd(X) 16 | U <- rE$u 17 | V <- rE$v 18 | D <- rE$d 19 | 20 | test_that("CPU vclMatrix Single Precision Matrix SVD Decomposition", 21 | { 22 | 23 | has_cpu_skip() 24 | 25 | fgpuX <- vclMatrix(X, type="float") 26 | fgpuA <- vclMatrix(nsqA, type = "float") 27 | 28 | E <- svd(fgpuX) 29 | 30 | 31 | # need to reorder so it matches R output 32 | ord <- order(-E$d[]) 33 | 34 | expect_is(E, "list") 35 | expect_equal(E$d[][ord], D, tolerance=1e-05, 36 | info="float singular values not equivalent") 37 | 38 | # need abs as some signs are opposite (not important with eigenvectors) 39 | expect_equal(abs(E$u[][,ord]), abs(U), tolerance=1e-05, 40 | info="float left singular vectors not equivalent") 41 | 42 | # make sure X not overwritten 43 | expect_equal(abs(E$v[][,ord]), abs(V), tolerance=1e-05, 44 | info="float right singular vectors not equivalent") 45 | expect_error(svd(fgpuA), "non-square matrix not currently supported for 'svd'", 46 | info = "svd shouldn't accept non-square matrices") 47 | }) 48 | 49 | test_that("CPU vclMatrix Double Precision Matrix SVD Decomposition", 50 | { 51 | 52 | has_cpu_skip() 53 | 54 | fgpuX <- vclMatrix(X, type="double") 55 | fgpuA <- vclMatrix(nsqA, type = "double") 56 | 57 | E <- svd(fgpuX) 58 | 59 | # need to reorder so it matches R output 60 | ord <- order(-E$d[]) 61 | 62 | expect_is(E, "list") 63 | expect_equal(E$d[][ord], D, tolerance=.Machine$double.eps ^ 0.5, 64 | info="double singular values not equivalent") 65 | expect_equal(abs(E$u[][,ord]), abs(U), tolerance=.Machine$double.eps ^ 0.5, 66 | info="double left singular vectors not equivalent") 67 | expect_equal(abs(E$v[][,ord]), abs(V), tolerance=.Machine$double.eps ^ 0.5, 68 | info="double right singular vectors not equivalent") 69 | 70 | expect_error(svd(fgpuA), "non-square matrix not currently supported for 'svd'", 71 | info = "svd shouldn't accept non-square matrices") 72 | }) 73 | 74 | setContext(current_context) 75 | -------------------------------------------------------------------------------- /man/Arith-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/methods-gpuVector.R, R/methods-vclMatrix.R, 3 | % R/methods-vclVector.R, R/methods.R 4 | \docType{methods} 5 | \name{Arith,gpuVector,gpuVector-method} 6 | \alias{Arith,gpuVector,gpuVector-method} 7 | \alias{Arith-gpuVector-gpuVector-method} 8 | \alias{Arith,numeric,gpuVector-method} 9 | \alias{Arith-numeric-gpuVector-method} 10 | \alias{Arith,gpuVector,numeric-method} 11 | \alias{Arith-gpuVector-numeric-method} 12 | \alias{Arith,gpuVector,missing-method} 13 | \alias{Arith-gpuVector-missing-method} 14 | \alias{Arith,gpuVector,gpuMatrix-method} 15 | \alias{Arith,vclMatrix,vclMatrix-method} 16 | \alias{Arith,vclMatrix,matrix-method} 17 | \alias{Arith,matrix,vclMatrix-method} 18 | \alias{Arith,vclMatrix,numeric-method} 19 | \alias{Arith,numeric,vclMatrix-method} 20 | \alias{Arith,vclMatrix,missing-method} 21 | \alias{Arith,vclMatrix,vclVector-method} 22 | \alias{Arith,vclVector,vclVector-method} 23 | \alias{Arith,numeric,vclVector-method} 24 | \alias{Arith,vclVector,numeric-method} 25 | \alias{Arith,vclVector,missing-method} 26 | \alias{Arith,vclVector,vclMatrix-method} 27 | \alias{Arith,gpuMatrix,gpuMatrix-method} 28 | \alias{Arith-gpuR-method} 29 | \alias{Arith,gpuMatrix,matrix-method} 30 | \alias{Arith,matrix,gpuMatrix-method} 31 | \alias{Arith,gpuMatrix,numeric-method} 32 | \alias{Arith,numeric,gpuMatrix-method} 33 | \alias{Arith,gpuMatrix,missing-method} 34 | \alias{Arith,gpuMatrix,gpuVector-method} 35 | \title{Arith methods} 36 | \usage{ 37 | \S4method{Arith}{gpuVector,gpuVector}(e1, e2) 38 | 39 | \S4method{Arith}{numeric,gpuVector}(e1, e2) 40 | 41 | \S4method{Arith}{gpuVector,numeric}(e1, e2) 42 | 43 | \S4method{Arith}{gpuVector,missing}(e1, e2) 44 | 45 | \S4method{Arith}{gpuVector,gpuMatrix}(e1, e2) 46 | 47 | \S4method{Arith}{vclMatrix,vclMatrix}(e1, e2) 48 | 49 | \S4method{Arith}{vclMatrix,matrix}(e1, e2) 50 | 51 | \S4method{Arith}{matrix,vclMatrix}(e1, e2) 52 | 53 | \S4method{Arith}{vclMatrix,numeric}(e1, e2) 54 | 55 | \S4method{Arith}{numeric,vclMatrix}(e1, e2) 56 | 57 | \S4method{Arith}{vclMatrix,missing}(e1, e2) 58 | 59 | \S4method{Arith}{vclMatrix,vclVector}(e1, e2) 60 | 61 | \S4method{Arith}{vclVector,vclVector}(e1, e2) 62 | 63 | \S4method{Arith}{numeric,vclVector}(e1, e2) 64 | 65 | \S4method{Arith}{vclVector,numeric}(e1, e2) 66 | 67 | \S4method{Arith}{vclVector,missing}(e1, e2) 68 | 69 | \S4method{Arith}{vclVector,vclMatrix}(e1, e2) 70 | 71 | \S4method{Arith}{gpuMatrix,gpuMatrix}(e1, e2) 72 | 73 | \S4method{Arith}{gpuMatrix,matrix}(e1, e2) 74 | 75 | \S4method{Arith}{matrix,gpuMatrix}(e1, e2) 76 | 77 | \S4method{Arith}{gpuMatrix,numeric}(e1, e2) 78 | 79 | \S4method{Arith}{numeric,gpuMatrix}(e1, e2) 80 | 81 | \S4method{Arith}{gpuMatrix,missing}(e1, e2) 82 | 83 | \S4method{Arith}{gpuMatrix,gpuVector}(e1, e2) 84 | } 85 | \arguments{ 86 | \item{e1}{A gpuR object} 87 | 88 | \item{e2}{A gpuR object} 89 | } 90 | \value{ 91 | A gpuR object 92 | } 93 | \description{ 94 | Methods for the base Arith methods \link[methods]{S4groupGeneric} 95 | } 96 | \author{ 97 | Charles Determan Jr. 98 | } 99 | -------------------------------------------------------------------------------- /tests/testthat/test_gpuMatrix_svd.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("gpuMatrix svd decomposition") 3 | 4 | if(detectGPUs() >= 1){ 5 | current_context <- set_device_context("gpu") 6 | }else{ 7 | current_context <- currentContext() 8 | } 9 | 10 | # set seed 11 | set.seed(123) 12 | 13 | ORDER <- 10 14 | 15 | # Base R objects 16 | X <- matrix(rnorm(ORDER^2), nrow=ORDER, ncol=ORDER) 17 | nsqA <- matrix(rnorm(20), nrow = 4) 18 | 19 | rE <- svd(X) 20 | U <- rE$u 21 | V <- rE$v 22 | D <- rE$d 23 | 24 | test_that("gpuMatrix Single Precision Matrix SVD Decomposition", 25 | { 26 | 27 | has_gpu_skip() 28 | 29 | fgpuX <- gpuMatrix(X, type="float") 30 | fgpuA <- gpuMatrix(nsqA, type = "float") 31 | 32 | E <- svd(fgpuX) 33 | 34 | 35 | # need to reorder so it matches R output 36 | ord <- order(-E$d[]) 37 | 38 | expect_is(E, "list") 39 | expect_equal(E$d[][ord], D, tolerance=1e-05, 40 | info="float singular values not equivalent") 41 | 42 | # need abs as some signs are opposite (not important with eigenvectors) 43 | expect_equal(abs(E$u[][,ord]), abs(U), tolerance=1e-05, 44 | info="float left singular vectors not equivalent") 45 | 46 | # make sure X not overwritten 47 | expect_equal(abs(E$v[][,ord]), abs(V), tolerance=1e-05, 48 | info="float right singular vectors not equivalent") 49 | expect_error(svd(fgpuA), "non-square matrix not currently supported for 'svd'", 50 | info = "svd shouldn't accept non-square matrices") 51 | }) 52 | 53 | test_that("gpuMatrix Double Precision Matrix SVD Decomposition", 54 | { 55 | 56 | has_gpu_skip() 57 | has_double_skip() 58 | 59 | fgpuX <- gpuMatrix(X, type="double") 60 | fgpuA <- gpuMatrix(nsqA, type = "double") 61 | 62 | E <- svd(fgpuX) 63 | 64 | # need to reorder so it matches R output 65 | ord <- order(-E$d[]) 66 | 67 | expect_is(E, "list") 68 | expect_equal(E$d[][ord], D, tolerance=.Machine$double.eps ^ 0.5, 69 | info="double singular values not equivalent") 70 | expect_equal(abs(E$u[][,ord]), abs(U), tolerance=.Machine$double.eps ^ 0.5, 71 | info="double left singular vectors not equivalent") 72 | expect_equal(abs(E$v[][,ord]), abs(V), tolerance=.Machine$double.eps ^ 0.5, 73 | info="double right singular vectors not equivalent") 74 | 75 | expect_error(svd(fgpuA), "non-square matrix not currently supported for 'svd'", 76 | info = "svd shouldn't accept non-square matrices") 77 | }) 78 | 79 | setContext(current_context) 80 | -------------------------------------------------------------------------------- /tests/testthat/test_vclMatrix_svd.R: -------------------------------------------------------------------------------- 1 | library(gpuR) 2 | context("vclMatrix svd decomposition") 3 | 4 | 5 | if(detectGPUs() >= 1){ 6 | current_context <- set_device_context("gpu") 7 | }else{ 8 | current_context <- currentContext() 9 | } 10 | 11 | # set seed 12 | set.seed(123) 13 | 14 | ORDER <- 10 15 | 16 | # Base R objects 17 | X <- matrix(rnorm(ORDER^2), nrow=ORDER, ncol=ORDER) 18 | nsqA <- matrix(rnorm(20), nrow = 4) 19 | 20 | rE <- svd(X) 21 | U <- rE$u 22 | V <- rE$v 23 | D <- rE$d 24 | 25 | test_that("vclMatrix Single Precision Matrix SVD Decomposition", 26 | { 27 | 28 | has_gpu_skip() 29 | 30 | fgpuX <- vclMatrix(X, type="float") 31 | fgpuA <- vclMatrix(nsqA, type = "float") 32 | 33 | E <- svd(fgpuX) 34 | 35 | 36 | # need to reorder so it matches R output 37 | ord <- order(-E$d[]) 38 | 39 | expect_is(E, "list") 40 | expect_equal(E$d[][ord], D, tolerance=1e-05, 41 | info="float singular values not equivalent") 42 | 43 | # need abs as some signs are opposite (not important with eigenvectors) 44 | expect_equal(abs(E$u[][,ord]), abs(U), tolerance=1e-05, 45 | info="float left singular vectors not equivalent") 46 | 47 | # make sure X not overwritten 48 | expect_equal(abs(E$v[][,ord]), abs(V), tolerance=1e-05, 49 | info="float right singular vectors not equivalent") 50 | expect_error(svd(fgpuA), "non-square matrix not currently supported for 'svd'", 51 | info = "svd shouldn't accept non-square matrices") 52 | }) 53 | 54 | test_that("vclMatrix Double Precision Matrix SVD Decomposition", 55 | { 56 | 57 | has_gpu_skip() 58 | has_double_skip() 59 | 60 | fgpuX <- vclMatrix(X, type="double") 61 | fgpuA <- vclMatrix(nsqA, type = "double") 62 | 63 | E <- svd(fgpuX) 64 | 65 | # need to reorder so it matches R output 66 | ord <- order(-E$d[]) 67 | 68 | expect_is(E, "list") 69 | expect_equal(E$d[][ord], D, tolerance=.Machine$double.eps ^ 0.5, 70 | info="double singular values not equivalent") 71 | expect_equal(abs(E$u[][,ord]), abs(U), tolerance=.Machine$double.eps ^ 0.5, 72 | info="double left singular vectors not equivalent") 73 | expect_equal(abs(E$v[][,ord]), abs(V), tolerance=.Machine$double.eps ^ 0.5, 74 | info="double right singular vectors not equivalent") 75 | 76 | expect_error(svd(fgpuA), "non-square matrix not currently supported for 'svd'", 77 | info = "svd shouldn't accept non-square matrices") 78 | }) 79 | 80 | setContext(current_context) 81 | --------------------------------------------------------------------------------