├── cleanup ├── .Rbuildignore ├── tests ├── testthat.R └── testthat │ ├── test_nvVector.R │ ├── test_cudaVector.R │ ├── test_cudaMatrix_row_col.R │ ├── test_nvMatrix.R │ └── test_cudaMatrix.R ├── R ├── zzz.R ├── methods-vector.R ├── methods-nvVector.R ├── methods-cudaVector.R ├── typeof.R ├── hello-gpuRcuda.R ├── class-nvVector.R ├── class.R ├── RcppExports.R ├── class-cudaVector.R ├── class-nvMatrix.R ├── nvVector.R ├── cudaVector.R ├── nvMatrix.R ├── cudaMatrix.R ├── class-cudaMatrix.R ├── wrappers.R └── methods.R ├── .gitignore ├── gpuRcuda.Rproj ├── man ├── length-methods.Rd ├── dim-methods.Rd ├── grapes-times-grapes-cudaMatrix-cudaMatrix-method.Rd ├── invVector-class.Rd ├── dnvVector-class.Rd ├── fnvVector-class.Rd ├── icudaVector-class.Rd ├── fcudaVector-class.Rd ├── dcudaVector-class.Rd ├── Arith-dcudaMatrix-dcudaMatrix-method.Rd ├── Arith-fcudaMatrix-fcudaMatrix-method.Rd ├── dnvMatrix-class.Rd ├── fnvMatrix-class.Rd ├── invMatrix-class.Rd ├── dcudaMatrix-class.Rd ├── fcudaMatrix-class.Rd ├── icudaMatrix-class.Rd ├── typeof.Rd ├── nvVector-class.Rd ├── cudaVector-class.Rd ├── nrow-gpuRcudaMatrix.Rd ├── nvMatrix-class.Rd ├── extract-methods.Rd ├── gpuRcudaMatrix-class.Rd ├── gpuRcudaVector-class.Rd ├── cudaMatrix-colSums.Rd ├── nvVector-methods.Rd ├── cudaVector-methods.Rd ├── nvMatrix-methods.Rd ├── cudaMatrix-class.Rd ├── cudaMatrix-methods.Rd └── gpuRcuda-package.Rd ├── inst ├── include │ └── gpuRcuda │ │ ├── thrust_vector.hpp │ │ ├── thrust_matrix.hpp │ │ ├── host_vector.hpp │ │ ├── host_matrix.hpp │ │ ├── device_matrix.hpp │ │ └── device_vector.hpp └── NEWS.Rd ├── src ├── Makevars.win ├── Makevars.in ├── utils.cpp ├── host_vector.cpp ├── host_matrix.cpp ├── device_matrix.cpp ├── device_vector.cpp └── RcppExports.cpp ├── NAMESPACE ├── DESCRIPTION ├── Dockerfile ├── .travis.yml ├── README.md └── configure.ac /cleanup: -------------------------------------------------------------------------------- 1 | #rm -f src/Makevars 2 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(gpuRcuda) 3 | 4 | test_check("gpuRcuda") 5 | -------------------------------------------------------------------------------- /R/zzz.R: -------------------------------------------------------------------------------- 1 | .onLoad <- function(libname, pkgname) { 2 | options(gpuRcuda.print.warning=TRUE) 3 | options(gpuRcuda.default.type = "double") 4 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | src/*.o 5 | src/*.so 6 | src/*.dll 7 | autom4te.cache/* 8 | config.log 9 | config.status 10 | #src/Makevars 11 | -------------------------------------------------------------------------------- /gpuRcuda.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: No 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Package 16 | PackageUseDevtools: Yes 17 | PackageInstallArgs: --no-multiarch --with-keep.source 18 | PackageRoxygenize: rd,collate,namespace 19 | -------------------------------------------------------------------------------- /man/length-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/methods-vector.R 3 | \docType{methods} 4 | \name{length,gpuRcudaVector-method} 5 | \alias{length,gpuRcudaVector-method} 6 | \alias{length,nvVector} 7 | \title{Length of gpuRcudaVector} 8 | \usage{ 9 | \S4method{length}{gpuRcudaVector}(x) 10 | } 11 | \arguments{ 12 | \item{x}{A gpuRcudaVector object} 13 | } 14 | \author{ 15 | Charles Determan Jr. 16 | } 17 | -------------------------------------------------------------------------------- /inst/include/gpuRcuda/thrust_vector.hpp: -------------------------------------------------------------------------------- 1 | #ifndef THRUST_VECTOR_HPP 2 | #define THRUST_VECTOR_HPP 3 | 4 | // Thrust headers 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | template 14 | class thrust_vector { 15 | 16 | public: 17 | virtual ~thrust_vector() {} 18 | virtual int size(){ 19 | return (int)(0); 20 | } 21 | }; 22 | 23 | #endif -------------------------------------------------------------------------------- /man/dim-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/methods.R 3 | \docType{methods} 4 | \name{dim,gpuRcudaMatrix-method} 5 | \alias{dim,gpuRcudaMatrix-method} 6 | \alias{dim,cudaMatrix} 7 | \title{gpuRcuda dim method} 8 | \usage{ 9 | \S4method{dim}{gpuRcudaMatrix}(x) 10 | } 11 | \arguments{ 12 | \item{x}{A gpuRcuda matrix object} 13 | } 14 | \value{ 15 | A length 2 vector of the number of rows and columns respectively. 16 | } 17 | \author{ 18 | Charles Determan Jr. 19 | } 20 | -------------------------------------------------------------------------------- /man/grapes-times-grapes-cudaMatrix-cudaMatrix-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/methods.R 3 | \docType{methods} 4 | \name{\%*\%,cudaMatrix,cudaMatrix-method} 5 | \alias{\%*\%,cudaMatrix,cudaMatrix-method} 6 | \title{CUDA Matrix Multiplication} 7 | \usage{ 8 | \S4method{\%*\%}{cudaMatrix,cudaMatrix}(x, y) 9 | } 10 | \arguments{ 11 | \item{x}{An fcudaMatrix object} 12 | 13 | \item{y}{An fcudaMatrix object} 14 | } 15 | \description{ 16 | CUDA Matrix Multiplication 17 | } 18 | -------------------------------------------------------------------------------- /man/invVector-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-nvVector.R 3 | \docType{class} 4 | \name{invVector-class} 5 | \alias{invVector-class} 6 | \title{invVector Class} 7 | \description{ 8 | An integer vector in the S4 \code{nvVector} 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{nvVector-class}} 20 | } 21 | \author{ 22 | Charles Determan Jr. 23 | } 24 | -------------------------------------------------------------------------------- /man/dnvVector-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-nvVector.R 3 | \docType{class} 4 | \name{dnvVector-class} 5 | \alias{dnvVector-class} 6 | \title{dnvVector Class} 7 | \description{ 8 | An double vector in the S4 \code{nvVector} 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{nvVector-class}} 20 | } 21 | \author{ 22 | Charles Determan Jr. 23 | } 24 | -------------------------------------------------------------------------------- /man/fnvVector-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-nvVector.R 3 | \docType{class} 4 | \name{fnvVector-class} 5 | \alias{fnvVector-class} 6 | \title{fnvVector Class} 7 | \description{ 8 | An float vector in the S4 \code{nvVector} 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{nvVector-class}} 20 | } 21 | \author{ 22 | Charles Determan Jr. 23 | } 24 | -------------------------------------------------------------------------------- /man/icudaVector-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-cudaVector.R 3 | \docType{class} 4 | \name{icudaVector-class} 5 | \alias{icudaVector-class} 6 | \title{icudaVector Class} 7 | \description{ 8 | An integer vector in the S4 \code{cudaVector} 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{cudaVector-class}} 20 | } 21 | \author{ 22 | Charles Determan Jr. 23 | } 24 | -------------------------------------------------------------------------------- /man/fcudaVector-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-cudaVector.R 3 | \docType{class} 4 | \name{fcudaVector-class} 5 | \alias{fcudaVector-class} 6 | \title{fcudaVector Class} 7 | \description{ 8 | An float vector in the S4 \code{cudaVector} 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{cudaVector-class}} 20 | } 21 | \author{ 22 | Charles Determan Jr. 23 | } 24 | -------------------------------------------------------------------------------- /inst/include/gpuRcuda/thrust_matrix.hpp: -------------------------------------------------------------------------------- 1 | #ifndef THRUST_MATRIX_HPP 2 | #define THRUST_MATRIX_HPP 3 | 4 | // Thrust headers 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | template 14 | class thrust_matrix { 15 | 16 | protected: 17 | int nr, nc; 18 | thrust_matrix(int nr, int nc): nr(nr), nc(nc){}; 19 | 20 | public: 21 | int nrow() { return nr; } 22 | int ncol() { return nc; } 23 | 24 | }; 25 | 26 | #endif -------------------------------------------------------------------------------- /man/dcudaVector-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-cudaVector.R 3 | \docType{class} 4 | \name{dcudaVector-class} 5 | \alias{dcudaVector-class} 6 | \title{dcudaVector Class} 7 | \description{ 8 | An double vector in the S4 \code{cudaVector} 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{cudaVector-class}} 20 | } 21 | \author{ 22 | Charles Determan Jr. 23 | } 24 | -------------------------------------------------------------------------------- /man/Arith-dcudaMatrix-dcudaMatrix-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/methods.R 3 | \docType{methods} 4 | \name{Arith,dcudaMatrix,dcudaMatrix-method} 5 | \alias{Arith,dcudaMatrix,dcudaMatrix-method} 6 | \title{Double Precision CUDA Matrix Addition/Subtraction} 7 | \usage{ 8 | \S4method{Arith}{dcudaMatrix,dcudaMatrix}(e1, e2) 9 | } 10 | \arguments{ 11 | \item{e1}{An dcudaMatrix object} 12 | 13 | \item{e2}{An dcudaMatrix object} 14 | } 15 | \description{ 16 | Double Precision CUDA Matrix Addition/Subtraction 17 | } 18 | -------------------------------------------------------------------------------- /man/Arith-fcudaMatrix-fcudaMatrix-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/methods.R 3 | \docType{methods} 4 | \name{Arith,fcudaMatrix,fcudaMatrix-method} 5 | \alias{Arith,fcudaMatrix,fcudaMatrix-method} 6 | \title{Single Precision CUDA Matrix Addition/Subtraction} 7 | \usage{ 8 | \S4method{Arith}{fcudaMatrix,fcudaMatrix}(e1, e2) 9 | } 10 | \arguments{ 11 | \item{e1}{An fcudaMatrix object} 12 | 13 | \item{e2}{An fcudaMatrix object} 14 | } 15 | \description{ 16 | Single Precision CUDA Matrix Addition/Subtraction 17 | } 18 | -------------------------------------------------------------------------------- /R/methods-vector.R: -------------------------------------------------------------------------------- 1 | 2 | #' @title Length of gpuRcudaVector 3 | #' @param x A gpuRcudaVector object 4 | #' @docType methods 5 | #' @rdname length-methods 6 | #' @aliases length,nvVector 7 | #' @aliases length,cudaVector 8 | #' @author Charles Determan Jr. 9 | #' @export 10 | setMethod('length', signature(x = "gpuRcudaVector"), 11 | function(x) { 12 | switch(typeof(x), 13 | "integer" = return(cpp_length(x@address, 4L)), 14 | "float" = return(cpp_length(x@address, 6L)), 15 | "double" = return(cpp_length(x@address, 8L)) 16 | ) 17 | 18 | } 19 | ) -------------------------------------------------------------------------------- /man/dnvMatrix-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-nvMatrix.R 3 | \docType{class} 4 | \name{dnvMatrix-class} 5 | \alias{dnvMatrix-class} 6 | \title{dnvMatrix Class} 7 | \description{ 8 | An integer type matrix in the S4 \code{nvMatrix} 9 | representation. 10 | } 11 | \section{Slots}{ 12 | 13 | \describe{ 14 | \item{\code{address}:}{A numeric R matrix} 15 | } 16 | } 17 | 18 | \seealso{ 19 | \code{\link{nvMatrix-class}}, 20 | \code{\link{invMatrix-class}}, 21 | \code{\link{fnvMatrix-class}} 22 | } 23 | \author{ 24 | Charles Determan Jr. 25 | } 26 | -------------------------------------------------------------------------------- /man/fnvMatrix-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-nvMatrix.R 3 | \docType{class} 4 | \name{fnvMatrix-class} 5 | \alias{fnvMatrix-class} 6 | \title{fnvMatrix Class} 7 | \description{ 8 | An integer type matrix in the S4 \code{nvMatrix} 9 | representation. 10 | } 11 | \section{Slots}{ 12 | 13 | \describe{ 14 | \item{\code{address}:}{A numeric R matrix.} 15 | } 16 | } 17 | 18 | \seealso{ 19 | \code{\link{nvMatrix-class}}, 20 | \code{\link{invMatrix-class}}, 21 | \code{\link{dnvMatrix-class}} 22 | } 23 | \author{ 24 | Charles Determan Jr. 25 | } 26 | -------------------------------------------------------------------------------- /man/invMatrix-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-nvMatrix.R 3 | \docType{class} 4 | \name{invMatrix-class} 5 | \alias{invMatrix-class} 6 | \title{invMatrix Class} 7 | \description{ 8 | An integer type matrix in the S4 \code{nvMatrix} 9 | representation. 10 | } 11 | \section{Slots}{ 12 | 13 | \describe{ 14 | \item{\code{address}:}{A integer typed R matrix} 15 | } 16 | } 17 | 18 | \seealso{ 19 | \code{\link{nvMatrix-class}}, 20 | \code{\link{invMatrix-class}}, 21 | \code{\link{dnvMatrix-class}} 22 | } 23 | \author{ 24 | Charles Determan Jr. 25 | } 26 | -------------------------------------------------------------------------------- /man/dcudaMatrix-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-cudaMatrix.R 3 | \docType{class} 4 | \name{dcudaMatrix-class} 5 | \alias{dcudaMatrix-class} 6 | \title{dcudaMatrix Class} 7 | \description{ 8 | An integer type matrix in the S4 \code{cudaMatrix} 9 | representation. 10 | } 11 | \section{Slots}{ 12 | 13 | \describe{ 14 | \item{\code{address}:}{A numeric R matrix} 15 | } 16 | } 17 | 18 | \seealso{ 19 | \code{\link{cudaMatrix-class}}, 20 | \code{\link{icudaMatrix-class}}, 21 | \code{\link{fcudaMatrix-class}} 22 | } 23 | \author{ 24 | Charles Determan Jr. 25 | } 26 | -------------------------------------------------------------------------------- /man/fcudaMatrix-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-cudaMatrix.R 3 | \docType{class} 4 | \name{fcudaMatrix-class} 5 | \alias{fcudaMatrix-class} 6 | \title{fcudaMatrix Class} 7 | \description{ 8 | An integer type matrix in the S4 \code{cudaMatrix} 9 | representation. 10 | } 11 | \section{Slots}{ 12 | 13 | \describe{ 14 | \item{\code{address}:}{A numeric R matrix.} 15 | } 16 | } 17 | 18 | \seealso{ 19 | \code{\link{cudaMatrix-class}}, 20 | \code{\link{icudaMatrix-class}}, 21 | \code{\link{dcudaMatrix-class}} 22 | } 23 | \author{ 24 | Charles Determan Jr. 25 | } 26 | -------------------------------------------------------------------------------- /man/icudaMatrix-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-cudaMatrix.R 3 | \docType{class} 4 | \name{icudaMatrix-class} 5 | \alias{icudaMatrix-class} 6 | \title{icudaMatrix Class} 7 | \description{ 8 | An integer type matrix in the S4 \code{cudaMatrix} 9 | representation. 10 | } 11 | \section{Slots}{ 12 | 13 | \describe{ 14 | \item{\code{address}:}{A integer typed R matrix} 15 | } 16 | } 17 | 18 | \seealso{ 19 | \code{\link{cudaMatrix-class}}, 20 | \code{\link{icudaMatrix-class}}, 21 | \code{\link{dcudaMatrix-class}} 22 | } 23 | \author{ 24 | Charles Determan Jr. 25 | } 26 | -------------------------------------------------------------------------------- /man/typeof.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/typeof.R 3 | \docType{methods} 4 | \name{typeof,gpuRcudaMatrix-method} 5 | \alias{typeof,gpuRcudaMatrix-method} 6 | \alias{typeof,cudaMatrix} 7 | \alias{typeof,gpuRcudaVector-method} 8 | \alias{typeof,cudaVector} 9 | \title{Get gpuRcudaMatrix type} 10 | \usage{ 11 | \S4method{typeof}{gpuRcudaMatrix}(x) 12 | 13 | \S4method{typeof}{gpuRcudaVector}(x) 14 | } 15 | \arguments{ 16 | \item{x}{A gpuRcudaMatrix object} 17 | 18 | \item{x}{A gpuRcudaVector object} 19 | } 20 | \author{ 21 | Charles Determan Jr. 22 | 23 | Charles Determan Jr. 24 | } 25 | -------------------------------------------------------------------------------- /src/Makevars.win: -------------------------------------------------------------------------------- 1 | CXX_STD = CXX11 2 | 3 | #SLAPACK_LIBS = `${R_HOME}/bin${R_ARCH_BIN}/Rscript -e "float:::ldflags()"` 4 | 5 | PKG_CPPFLAGS = -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_OMP $(SHLIB_OPENMP_CFLAGS) 6 | PKG_CXXFLAGS = -I. -I../inst/include $(SHLIB_OPENMP_CXXFLAGS) 7 | #PKG_LIBS = $(SHLIB_OPENMP_CFLAGS) "$(SLAPACK_LIBS)" 8 | PKG_LIBS = $(SHLIB_OPENMP_CFLAGS) 9 | 10 | CXX_SOURCES = $(wildcard *.cpp) 11 | C_SOURCES = $(wildcard *.c) 12 | OBJECTS = $(C_SOURCES:.c=.o) $(CXX_SOURCES:.cpp=.o) 13 | 14 | all: $(SHLIB) 15 | 16 | $(SHLIB): $(OBJECTS) 17 | 18 | clean: 19 | @rm -rf *.o *.so *.dll \ 20 | Makevars $(USER_CONF) $(SHLIB) $(OBJECTS) -------------------------------------------------------------------------------- /man/nvVector-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-nvVector.R 3 | \docType{class} 4 | \name{nvVector-class} 5 | \alias{nvVector-class} 6 | \title{nvVector Class} 7 | \description{ 8 | This is the 'mother' class for all 9 | nvVector objects. All other nvVector 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{invVector}. 16 | } 17 | \seealso{ 18 | \code{\link{invVector-class}} 19 | } 20 | \author{ 21 | Charles Determan Jr. 22 | } 23 | -------------------------------------------------------------------------------- /man/cudaVector-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-cudaVector.R 3 | \docType{class} 4 | \name{cudaVector-class} 5 | \alias{cudaVector-class} 6 | \title{cudaVector Class} 7 | \description{ 8 | This is the 'mother' class for all 9 | cudaVector objects. All other cudaVector 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{icudaVector}. 16 | } 17 | \seealso{ 18 | \code{\link{icudaVector-class}} 19 | } 20 | \author{ 21 | Charles Determan Jr. 22 | } 23 | -------------------------------------------------------------------------------- /man/nrow-gpuRcudaMatrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/methods.R 3 | \docType{methods} 4 | \name{nrow,gpuRcudaMatrix-method} 5 | \alias{nrow,gpuRcudaMatrix-method} 6 | \alias{nrow,cudaMatrix} 7 | \alias{ncol,gpuRcudaMatrix-method} 8 | \title{The Number of Rows/Columns of a gpuRcudaMatrix} 9 | \usage{ 10 | \S4method{nrow}{gpuRcudaMatrix}(x) 11 | 12 | \S4method{ncol}{gpuRcudaMatrix}(x) 13 | } 14 | \arguments{ 15 | \item{x}{A gpuRcudaMatrix object} 16 | } 17 | \value{ 18 | An integer of length 1 19 | } 20 | \description{ 21 | \code{nrow} and \code{ncol} return the number of rows 22 | or columns present in \code{x}. 23 | } 24 | \author{ 25 | Charles Determan Jr. 26 | } 27 | -------------------------------------------------------------------------------- /inst/NEWS.Rd: -------------------------------------------------------------------------------- 1 | \name{NEWS} 2 | \title{News for Package 'gpuRcuda'} 3 | 4 | \section{Initial Release version 1.0.0 (Unreleased)}{ 5 | \itemize{ 6 | \item Implemented Features: 7 | \itemize{ 8 | \item cuda* classes for matrix objects 9 | \item Back compatible with gpuR objects - if method 10 | method exists in gpuR but not in gpuRcuda, uses gpuR method 11 | \item CUDA support for 'float' and 'double' data types 12 | \item gpuMatrix functions (multiplication, addition, subtraction) 13 | } 14 | \item Features in Progress: 15 | \itemize{ 16 | \item Additional matrix functions (QR-decompsition, SVD) 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /R/methods-nvVector.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #' @rdname extract-methods 5 | #' @export 6 | setMethod("[", 7 | signature(x = "nvVector", i = "missing", j = "missing", drop = "missing"), 8 | function(x, i, j, drop) { 9 | 10 | init <- ifelse(typeof(x) == "double", 0, 0L) 11 | out <- rep(init, length(x)) 12 | 13 | switch(typeof(x), 14 | "integer" = { 15 | nvMatToSEXP(x@address, out, 4L) 16 | return(out) 17 | }, 18 | "float" = { 19 | nvMatToSEXP(x@address, out, 6L) 20 | return(out) 21 | }, 22 | "double" = { 23 | nvMatToSEXP(x@address, out, 8L) 24 | return(out) 25 | } 26 | ) 27 | }) 28 | -------------------------------------------------------------------------------- /R/methods-cudaVector.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #' @rdname extract-methods 5 | #' @export 6 | setMethod("[", 7 | signature(x = "cudaVector", i = "missing", j = "missing", drop = "missing"), 8 | function(x, i, j, drop) { 9 | 10 | init <- ifelse(typeof(x) == "double", 0, 0L) 11 | out <- rep(init, length(x)) 12 | 13 | switch(typeof(x), 14 | "integer" = { 15 | cudaMatToSEXP(x@address, out, 4L) 16 | return(out) 17 | }, 18 | "float" = { 19 | cudaMatToSEXP(x@address, out, 6L) 20 | return(out) 21 | }, 22 | "double" = { 23 | cudaMatToSEXP(x@address, out, 8L) 24 | return(out) 25 | } 26 | ) 27 | }) 28 | -------------------------------------------------------------------------------- /man/nvMatrix-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-nvMatrix.R 3 | \docType{class} 4 | \name{nvMatrix-class} 5 | \alias{nvMatrix-class} 6 | \title{nvMatrix Class} 7 | \description{ 8 | This class refers to gpuRcuda matrix 9 | objects that are on the host. 10 | 11 | There are multiple child classes that correspond 12 | to the particular data type contained. These include 13 | \code{invMatrix}, \code{fnvMatrix}, and 14 | \code{dnvMatrix} corresponding to integer, float, and 15 | double data types respectively. 16 | } 17 | \section{Slots}{ 18 | 19 | Common to all nvMatrix objects in the package 20 | \describe{ 21 | \item{\code{address}:}{An R matrix object} 22 | } 23 | } 24 | 25 | \seealso{ 26 | \code{\link{invMatrix-class}}, 27 | \code{\link{fnvMatrix-class}}, 28 | \code{\link{dnvMatrix-class}} 29 | } 30 | \author{ 31 | Charles Determan Jr. 32 | } 33 | -------------------------------------------------------------------------------- /man/extract-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/methods-cudaVector.R, R/methods-nvVector.R, 3 | % R/methods.R 4 | \docType{methods} 5 | \name{[,cudaVector,missing,missing,missing-method} 6 | \alias{[,cudaVector,missing,missing,missing-method} 7 | \alias{[,nvVector,missing,missing,missing-method} 8 | \alias{[,cudaMatrix,missing,missing,missing-method} 9 | \alias{[,nvMatrix,missing,missing,missing-method} 10 | \title{Extract gpuRcuda elements} 11 | \usage{ 12 | \S4method{[}{cudaVector,missing,missing,missing}(x, i, j, drop) 13 | 14 | \S4method{[}{nvVector,missing,missing,missing}(x, i, j, drop) 15 | 16 | \S4method{[}{cudaMatrix,missing,missing,missing}(x, i, j, drop) 17 | 18 | \S4method{[}{nvMatrix,missing,missing,missing}(x, i, j, drop) 19 | } 20 | \arguments{ 21 | \item{x}{A gpuRcuda object} 22 | 23 | \item{i}{missing} 24 | 25 | \item{j}{missing} 26 | 27 | \item{drop}{missing} 28 | } 29 | \author{ 30 | Charles Determan Jr. 31 | } 32 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(cudaMatrix) 4 | export(cudaVector) 5 | export(nvMatrix) 6 | export(nvVector) 7 | exportClasses(cudaMatrix) 8 | exportClasses(cudaVector) 9 | exportClasses(dcudaMatrix) 10 | exportClasses(dcudaVector) 11 | exportClasses(dnvMatrix) 12 | exportClasses(dnvVector) 13 | exportClasses(fcudaMatrix) 14 | exportClasses(fcudaVector) 15 | exportClasses(fnvMatrix) 16 | exportClasses(fnvVector) 17 | exportClasses(gpuRcudaMatrix) 18 | exportClasses(gpuRcudaVector) 19 | exportClasses(icudaMatrix) 20 | exportClasses(icudaVector) 21 | exportClasses(invMatrix) 22 | exportClasses(invVector) 23 | exportClasses(nvMatrix) 24 | exportClasses(nvVector) 25 | exportMethods("%*%") 26 | exportMethods("[") 27 | exportMethods(Arith) 28 | exportMethods(colMeans) 29 | exportMethods(colSums) 30 | exportMethods(dim) 31 | exportMethods(length) 32 | exportMethods(ncol) 33 | exportMethods(nrow) 34 | exportMethods(rowMeans) 35 | exportMethods(rowSums) 36 | exportMethods(typeof) 37 | import(methods) 38 | importFrom(Rcpp,evalCpp) 39 | useDynLib(gpuRcuda) 40 | -------------------------------------------------------------------------------- /man/gpuRcudaMatrix-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class.R 3 | \docType{class} 4 | \name{gpuRcudaMatrix-class} 5 | \alias{gpuRcudaMatrix-class} 6 | \title{gpuRcudaMatrix Class} 7 | \description{ 8 | This is the 'mother' class for all 9 | gpuRcudaMatrix objects. It is essentially a wrapper for 10 | a basic R matrix (possibly to be improved). All other 11 | gpuRcuda classes inherit from this class but 12 | there are no current circumstances where this class 13 | is used directly. 14 | } 15 | \note{ 16 | R does not contain a native float type. As such, 17 | the matrix data within a such an object 18 | will be represented as double but downcast when any 19 | gpuRcuda methods are used. 20 | 21 | May also remove the type slot 22 | } 23 | \section{Slots}{ 24 | 25 | Common to all gpuRcuda objects in the package 26 | \describe{ 27 | \item{\code{address}:}{An R matrix object} 28 | } 29 | } 30 | 31 | \seealso{ 32 | \code{\link{nvMatrix-class}}, 33 | \code{\link{cudaMatrix-class}} 34 | } 35 | \author{ 36 | Charles Determan Jr. 37 | } 38 | -------------------------------------------------------------------------------- /man/gpuRcudaVector-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class.R 3 | \docType{class} 4 | \name{gpuRcudaVector-class} 5 | \alias{gpuRcudaVector-class} 6 | \title{gpuRcudaVector Class} 7 | \description{ 8 | This is the 'mother' class for all 9 | gpuRcudaVector objects. It is essentially a wrapper for 10 | a basic R vector (possibly to be improved). All other 11 | gpuRcuda classes inherit from this class but 12 | there are no current circumstances where this class 13 | is used directly. 14 | } 15 | \note{ 16 | R does not contain a native float type. As such, 17 | the vector data within a such an object 18 | will be represented as double but downcast when any 19 | gpuRcuda methods are used. 20 | 21 | May also remove the type slot 22 | } 23 | \section{Slots}{ 24 | 25 | Common to all gpuRcuda objects in the package 26 | \describe{ 27 | \item{\code{address}:}{An R vector object} 28 | } 29 | } 30 | 31 | \seealso{ 32 | \code{\link{nvVector-class}}, 33 | \code{\link{cudaVector-class}} 34 | } 35 | \author{ 36 | Charles Determan Jr. 37 | } 38 | -------------------------------------------------------------------------------- /tests/testthat/test_nvVector.R: -------------------------------------------------------------------------------- 1 | library(gpuRcuda) 2 | context("nvVector class") 3 | 4 | # set seed 5 | set.seed(123) 6 | 7 | ORDER <- 10 8 | 9 | # Base R objects 10 | Aint <- seq.int(ORDER) 11 | Bint <- sample(seq.int(ORDER), ORDER) 12 | A <- rnorm(ORDER) 13 | B <- rnorm(ORDER) 14 | 15 | 16 | test_that("typeof not working correctly", { 17 | fgpuA <- nvVector(A, type="double") 18 | expect_equal(typeof(fgpuA), "double") 19 | }) 20 | 21 | 22 | test_that("length not working correctly", { 23 | fgpuA <- nvVector(A, type="double") 24 | expect_equal(length(fgpuA), length(A)) 25 | }) 26 | 27 | test_that("empty initialization failed", { 28 | fgpuA <- nvVector(length = 4, type = "double") 29 | expect_equivalent(fgpuA[], rep(0, 4), 30 | tolerance = .Machine$double.eps ^ 0.5, 31 | info = "double vector elements not equivalent") 32 | }) 33 | 34 | test_that("double vector values not returned correctly",{ 35 | fgpuA <- nvVector(A, type = "double") 36 | expect_equivalent(fgpuA[], A, tolerance=.Machine$double.eps ^ 0.5, 37 | info="double vector elements not equivalent") 38 | }) -------------------------------------------------------------------------------- /man/cudaMatrix-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,cudaMatrix,missing,missing-method} 5 | \alias{colSums,cudaMatrix,missing,missing-method} 6 | \alias{colSums,cudaMatrix} 7 | \alias{rowSums,cudaMatrix,missing,missing-method} 8 | \alias{colMeans,cudaMatrix,missing,missing-method} 9 | \alias{rowMeans,cudaMatrix,missing,missing-method} 10 | \title{Row and Column Sums and Means of cudaMatrix} 11 | \usage{ 12 | \S4method{colSums}{cudaMatrix,missing,missing}(x, na.rm, dims) 13 | 14 | \S4method{rowSums}{cudaMatrix,missing,missing}(x, na.rm, dims) 15 | 16 | \S4method{colMeans}{cudaMatrix,missing,missing}(x, na.rm, dims) 17 | 18 | \S4method{rowMeans}{cudaMatrix,missing,missing}(x, na.rm, dims) 19 | } 20 | \arguments{ 21 | \item{x}{A cudaMatrix object} 22 | 23 | \item{na.rm}{Not currently used} 24 | 25 | \item{dims}{Not currently used} 26 | } 27 | \value{ 28 | A cudaVector object 29 | } 30 | \description{ 31 | Row and column sums and of cudaMatrix objects 32 | } 33 | \author{ 34 | Charles Determan Jr. 35 | } 36 | -------------------------------------------------------------------------------- /tests/testthat/test_cudaVector.R: -------------------------------------------------------------------------------- 1 | library(gpuRcuda) 2 | context("cudaVector class") 3 | 4 | # set seed 5 | set.seed(123) 6 | 7 | ORDER <- 10 8 | 9 | # Base R objects 10 | Aint <- seq.int(ORDER) 11 | Bint <- sample(seq.int(ORDER), ORDER) 12 | A <- rnorm(ORDER) 13 | B <- rnorm(ORDER) 14 | 15 | 16 | test_that("typeof not working correctly", { 17 | fgpuA <- cudaVector(A, type="double") 18 | expect_equal(typeof(fgpuA), "double") 19 | }) 20 | 21 | 22 | test_that("length not working correctly", { 23 | fgpuA <- cudaVector(A, type="double") 24 | expect_equal(length(fgpuA), length(A)) 25 | }) 26 | 27 | test_that("empty initialization failed", { 28 | fgpuA <- cudaVector(length = 4, type = "double") 29 | expect_equivalent(fgpuA[], rep(0, 4), 30 | tolerance = .Machine$double.eps ^ 0.5, 31 | info = "double vector elements not equivalent") 32 | }) 33 | 34 | test_that("double vector values not returned correctly",{ 35 | fgpuA <- cudaVector(A, type = "double") 36 | expect_equivalent(fgpuA[], A, tolerance=.Machine$double.eps ^ 0.5, 37 | info="double vector elements not equivalent") 38 | }) 39 | -------------------------------------------------------------------------------- /man/nvVector-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/nvVector.R 3 | \docType{methods} 4 | \name{nvVector} 5 | \alias{nvVector} 6 | \alias{nvVector,vector,missing-method} 7 | \alias{nvVector,vector} 8 | \alias{nvVector,missing,ANY-method} 9 | \alias{nvVector,missing} 10 | \title{Construct a nvVector} 11 | \usage{ 12 | nvVector(data, length, type = NULL, ...) 13 | 14 | \S4method{nvVector}{vector,missing}(data, type = NULL) 15 | 16 | \S4method{nvVector}{missing,ANY}(data, length, type = NULL) 17 | } 18 | \arguments{ 19 | \item{data}{An object that is or can be converted to a 20 | \code{vector}} 21 | 22 | \item{length}{A non-negative integer specifying the desired length.} 23 | 24 | \item{type}{A character string specifying the type of nvVector. Default 25 | is NULL where type is inherited from the source data type.} 26 | 27 | \item{...}{Additional method to pass to nvVector methods} 28 | } 29 | \value{ 30 | A nvVector object 31 | } 32 | \description{ 33 | Construct a nvVector of a class that inherits 34 | from \code{nvVector} 35 | } 36 | \author{ 37 | Charles Determan Jr. 38 | } 39 | -------------------------------------------------------------------------------- /R/typeof.R: -------------------------------------------------------------------------------- 1 | 2 | #' @title Get gpuRcudaMatrix type 3 | #' @param x A gpuRcudaMatrix object 4 | #' @aliases typeof,cudaMatrix 5 | #' @aliases typeof,nvMatrix 6 | #' @author Charles Determan Jr. 7 | #' @rdname typeof 8 | #' @export 9 | setMethod('typeof', signature(x="gpuRcudaMatrix"), 10 | function(x) { 11 | switch(class(x), 12 | "icudaMatrix" = "integer", 13 | "fcudaMatrix" = "float", 14 | "dcudaMatrix" = "double", 15 | "invMatrix" = "integer", 16 | "fnvMatrix" = "float", 17 | "dnvMatrix" = "double") 18 | }) 19 | 20 | #' @title Get gpuRcudaVector type 21 | #' @param x A gpuRcudaVector object 22 | #' @aliases typeof,cudaVector 23 | #' @aliases typeof,nvVector 24 | #' @author Charles Determan Jr. 25 | #' @rdname typeof 26 | #' @export 27 | setMethod('typeof', signature(x="gpuRcudaVector"), 28 | function(x) { 29 | switch(class(x), 30 | "icudaVector" = "integer", 31 | "fcudaVector" = "float", 32 | "dcudaVector" = "double", 33 | "invVector" = "integer", 34 | "fnvVector" = "float", 35 | "dnvVector" = "double") 36 | }) 37 | 38 | -------------------------------------------------------------------------------- /man/cudaVector-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cudaVector.R 3 | \docType{methods} 4 | \name{cudaVector} 5 | \alias{cudaVector} 6 | \alias{cudaVector,vector,missing-method} 7 | \alias{cudaVector,vector} 8 | \alias{cudaVector,missing,ANY-method} 9 | \alias{cudaVector,missing} 10 | \title{Construct a cudaVector} 11 | \usage{ 12 | cudaVector(data, length, type = NULL, ...) 13 | 14 | \S4method{cudaVector}{vector,missing}(data, length = NULL, type = NULL) 15 | 16 | \S4method{cudaVector}{missing,ANY}(data, length, type = NULL) 17 | } 18 | \arguments{ 19 | \item{data}{An object that is or can be converted to a 20 | \code{vector}} 21 | 22 | \item{length}{A non-negative integer specifying the desired length.} 23 | 24 | \item{type}{A character string specifying the type of cudaVector. Default 25 | is NULL where type is inherited from the source data type.} 26 | 27 | \item{...}{Additional method to pass to cudaVector methods} 28 | } 29 | \value{ 30 | A cudaVector object 31 | } 32 | \description{ 33 | Construct a cudaVector of a class that inherits 34 | from \code{cudaVector} 35 | } 36 | \author{ 37 | Charles Determan Jr. 38 | } 39 | -------------------------------------------------------------------------------- /man/nvMatrix-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/nvMatrix.R 3 | \docType{methods} 4 | \name{nvMatrix} 5 | \alias{nvMatrix} 6 | \alias{nvMatrix,matrix-method} 7 | \alias{nvMatrix,matrix} 8 | \alias{nvMatrix,missing-method} 9 | \alias{nvMatrix,missing} 10 | \title{Construct a nvMatrix} 11 | \usage{ 12 | nvMatrix(data = NA, ncol = NA, nrow = NA, type = NULL, ...) 13 | 14 | \S4method{nvMatrix}{matrix}(data, type = NULL) 15 | 16 | \S4method{nvMatrix}{missing}(data, ncol = NA, nrow = NA, type = NULL) 17 | } 18 | \arguments{ 19 | \item{data}{An object that is or can be converted to a 20 | \code{matrix} object} 21 | 22 | \item{ncol}{An integer specifying the number of columns} 23 | 24 | \item{nrow}{An integer specifying the number of rows} 25 | 26 | \item{type}{A character string specifying the type of nvMatrix. Default 27 | is NULL where type is inherited from the source data type.} 28 | 29 | \item{...}{Additional method to pass to nvMatrix methods} 30 | } 31 | \value{ 32 | A nvMatrix object 33 | } 34 | \description{ 35 | Construct a nvMatrix of a class that inherits 36 | from \code{nvMatrix} 37 | } 38 | \author{ 39 | Charles Determan Jr. 40 | } 41 | -------------------------------------------------------------------------------- /man/cudaMatrix-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/class-cudaMatrix.R 3 | \docType{class} 4 | \name{cudaMatrix-class} 5 | \alias{cudaMatrix-class} 6 | \title{cudaMatrix Class} 7 | \description{ 8 | This class refers to gpuRcuda matrix 9 | objects that are on the device. 10 | 11 | There are multiple child classes that correspond 12 | to the particular data type contained. These include 13 | \code{icudaMatrix}, \code{fcudaMatrix}, and 14 | \code{dcudaMatrix} corresponding to integer, float, and 15 | double data types respectively. 16 | } 17 | \note{ 18 | R does not contain a native float type. As such, 19 | the matrix data within a \code{\link{fcudaMatrix-class}} 20 | will be represented as double but downcast when any 21 | cudaMatrix methods are used. 22 | 23 | May also remove the type slot 24 | } 25 | \section{Slots}{ 26 | 27 | Common to all cudaMatrix objects in the package 28 | \describe{ 29 | \item{\code{address}:}{An R matrix object} 30 | } 31 | } 32 | 33 | \seealso{ 34 | \code{\link{icudaMatrix-class}}, 35 | \code{\link{fcudaMatrix-class}}, 36 | \code{\link{dcudaMatrix-class}} 37 | } 38 | \author{ 39 | Charles Determan Jr. 40 | } 41 | -------------------------------------------------------------------------------- /src/Makevars.in: -------------------------------------------------------------------------------- 1 | CXX_STD = CXX11 2 | 3 | PKG_CPPFLAGS = @GPURCUDA_CPPFLAGS@ 4 | PKG_CXXFLAGS = @GPURCUDA_CXXFLAGS@ 5 | 6 | PKG_LIBS = @GPURCUDA_LIBS@ 7 | R_LIBS = @R_LIBS@ 8 | 9 | cpp_sources = $(wildcard *.cpp) 10 | cpp_sharedlibs = $(patsubst %.cpp, %.o, $(cpp_sources)) 11 | 12 | OBJECTS = $(cpp_sharedlibs) 13 | 14 | R_INC = -I/../inst/include @R_INCL@ @RCPP_INCL@ @THRUST_INCL@ @CU_INCL@ 15 | CXX_ARGS = @R_CPIC@ 16 | 17 | CU_ARGS = -Xcompiler -fPIC -Xcudafe --diag_suppress=code_is_unreachable 18 | CU_INCL = -I../inst/include @R_INCL@ @RCPP_INCL@ @THRUST_INCL@ 19 | CU_ARCH = -arch=sm_30 20 | 21 | CXX=@CXX@ 22 | NVCC=@NVCC@ 23 | 24 | all: gpuRcuda.so 25 | 26 | gpuRcuda.so: $(OBJECTS) 27 | 28 | BACKEND = @BACKEND@ 29 | ifeq "$(BACKEND)" "CUDA" 30 | %.o: %.cpp $(cpp_sources) 31 | $(NVCC) -gencode arch=compute_30,code=sm_30 -std=c++11 -DGPU -x cu -c $(CU_ARGS) $(CU_INCL) $< -o $@ 32 | 33 | else 34 | gpuRcuda.so: $(OBJECTS) 35 | endif 36 | 37 | 38 | clean: 39 | @rm -rf *.o *.so *.dll 40 | 41 | 42 | #%.o: %.cpp $(cpp_sources) 43 | # $(CXX) $(CXX_ARGS) $(R_INC) $< -c 44 | 45 | #%.o: %.cu $(cu_sources) 46 | # $(NVCC) $(CU_ARCH) $(CU_ARGS) $(CU_INCL) $< -c 47 | 48 | #clean: 49 | # rm -rf *.o Makevars 50 | 51 | -------------------------------------------------------------------------------- /man/cudaMatrix-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cudaMatrix.R 3 | \docType{methods} 4 | \name{cudaMatrix} 5 | \alias{cudaMatrix} 6 | \alias{cudaMatrix,matrix-method} 7 | \alias{cudaMatrix,matrix} 8 | \alias{cudaMatrix,missing-method} 9 | \alias{cudaMatrix,missing} 10 | \title{Construct a cudaMatrix} 11 | \usage{ 12 | cudaMatrix(data = NA, ncol = NA, nrow = NA, type = NULL, ...) 13 | 14 | \S4method{cudaMatrix}{matrix}(data, type = NULL) 15 | 16 | \S4method{cudaMatrix}{missing}(data, ncol = NA, nrow = NA, type = NULL) 17 | } 18 | \arguments{ 19 | \item{data}{An object that is or can be converted to a 20 | \code{matrix} object} 21 | 22 | \item{ncol}{An integer specifying the number of columns} 23 | 24 | \item{nrow}{An integer specifying the number of rows} 25 | 26 | \item{type}{A character string specifying the type of cudaMatrix. Default 27 | is NULL where type is inherited from the source data type.} 28 | 29 | \item{...}{Additional method to pass to cudaMatrix methods} 30 | } 31 | \value{ 32 | A cudaMatrix object 33 | } 34 | \description{ 35 | Construct a cudaMatrix of a class that inherits 36 | from \code{cudaMatrix} 37 | } 38 | \author{ 39 | Charles Determan Jr. 40 | } 41 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: gpuRcuda 2 | Type: Package 3 | Title: CUDA GPU functions for R Objects 4 | Version: 1.0.0 5 | Date: 2018-01-02 6 | Author: Charles Determan Jr. 7 | Maintainer: Charles Determan Jr. 8 | Description: This package is designed to be a companion to the gpuR 9 | package. The classes herein leverage the thrust c++ template 10 | library to facilitate simple use of CUDA/OPENMP backends. This 11 | package allows the user to easily use the same 'base' functions 12 | while leveraging potential NVIDIA technology. 13 | License: GPL (>= 2) 14 | Encoding: UTF-8 15 | Imports: 16 | Rcpp, 17 | methods 18 | LinkingTo: 19 | Rcpp, 20 | thrust 21 | Suggests: testthat 22 | URL: http://github.com/gpuRcore/gpuRcuda 23 | BugReports: http://github.com/gpuRcore/gpuRcuda/issues/new 24 | SystemRequirements: C++11 25 | Collate: 26 | 'RcppExports.R' 27 | 'class.R' 28 | 'class-cudaMatrix.R' 29 | 'class-cudaVector.R' 30 | 'class-nvMatrix.R' 31 | 'class-nvVector.R' 32 | 'cudaMatrix.R' 33 | 'cudaVector.R' 34 | 'hello-gpuRcuda.R' 35 | 'methods-cudaVector.R' 36 | 'methods-nvVector.R' 37 | 'methods-vector.R' 38 | 'methods.R' 39 | 'nvMatrix.R' 40 | 'nvVector.R' 41 | 'typeof.R' 42 | 'wrappers.R' 43 | 'zzz.R' 44 | RoxygenNote: 6.0.1 45 | -------------------------------------------------------------------------------- /R/hello-gpuRcuda.R: -------------------------------------------------------------------------------- 1 | #' @title CUDA GPU functions for R Objects 2 | #' 3 | #' @description This package was developed to provide an extension to the 4 | #' \pkg{gpuR} to allow use of NVIDIA GPU's. As with the predecessor, this 5 | #' package removes the complex code needed for GPU computing and provide 6 | #' easier to use functions to apply on R objects. 7 | #' 8 | #' \tabular{ll}{ Package: \tab gpuRcuda\cr Type: \tab Package\cr 9 | #' Version: \tab 1.0.0\cr Date: \tab 2015-03-31\cr License: \tab GPL-3\cr 10 | #' Copyright: \tab (c) 2015 Charles E. Determan Jr.\cr URL: \tab 11 | #' \url{http://www.github.com/cdeterman/gpuRcuda}\cr LazyLoad: \tab yes\cr 12 | #' } 13 | #' 14 | #' 15 | #' @note This package is entirely dependently upon \pkg{gpuR}. This decision 16 | #' was made for the following reasons: \preformatted{ 17 | #' 18 | #' 1. Avoid repetition of code that would be duplicated from \pkg{gpuR}. 19 | #' 20 | #' 2. This will allow any updates in the parent package to immediately be 21 | #' available within this package (using the OpenCL backend) until corresponding 22 | #' CUDA functions are made available. 23 | #' 24 | #' } 25 | #' @author 26 | #' Charles Determan \email{cdetermanjr@@gmail.com} 27 | #' 28 | #' Maintainer: Charles Determan \email{cdetermanjr@@gmail.com} 29 | #' @docType package 30 | #' @name gpuRcuda-package 31 | #' @aliases gpuRcuda-package gpuRcuda 32 | NULL -------------------------------------------------------------------------------- /inst/include/gpuRcuda/host_vector.hpp: -------------------------------------------------------------------------------- 1 | #ifndef HOST_VECTOR_HPP 2 | #define HOST_VECTOR_HPP 3 | 4 | #define R_NO_REMAP 5 | 6 | // R headers 7 | #include 8 | #include 9 | 10 | // Thrust headers 11 | #include "gpuRcuda/thrust_vector.hpp" 12 | 13 | #include 14 | 15 | #include 16 | 17 | template 18 | class host_vector: public thrust_vector { 19 | 20 | private: 21 | std::shared_ptr > ptr; 22 | 23 | public: 24 | 25 | // initializers 26 | host_vector() { }; // private default constructor 27 | host_vector(int size){ 28 | // initialize vector of zeros 29 | thrust::host_vector vec(size); 30 | thrust::fill(vec.begin(), vec.end(), (T)(0)); 31 | ptr = std::make_shared >(vec); 32 | } 33 | host_vector(T init, int size){ 34 | // initialize vector of init 35 | thrust::host_vector vec(size); 36 | thrust::fill(vec.begin(), vec.end(), init); 37 | ptr = std::make_shared >(vec); 38 | } 39 | host_vector(T *x, int size){ 40 | 41 | // initialize from SEXP pointer 42 | thrust::host_vector vec(x, x + size); 43 | ptr = std::make_shared >(vec); 44 | } 45 | 46 | virtual int size(){ 47 | return ptr->size(); 48 | } 49 | 50 | // return shared_ptr 51 | std::shared_ptr > getPtr(){ 52 | return ptr; 53 | } 54 | 55 | }; 56 | 57 | #endif -------------------------------------------------------------------------------- /man/gpuRcuda-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/hello-gpuRcuda.R 3 | \docType{package} 4 | \name{gpuRcuda-package} 5 | \alias{gpuRcuda-package} 6 | \alias{gpuRcuda} 7 | \title{CUDA GPU functions for R Objects} 8 | \description{ 9 | This package was developed to provide an extension to the 10 | \pkg{gpuR} to allow use of NVIDIA GPU's. As with the predecessor, this 11 | package removes the complex code needed for GPU computing and provide 12 | easier to use functions to apply on R objects. 13 | 14 | \tabular{ll}{ Package: \tab gpuRcuda\cr Type: \tab Package\cr 15 | Version: \tab 1.0.0\cr Date: \tab 2015-03-31\cr License: \tab GPL-3\cr 16 | Copyright: \tab (c) 2015 Charles E. Determan Jr.\cr URL: \tab 17 | \url{http://www.github.com/cdeterman/gpuRcuda}\cr LazyLoad: \tab yes\cr 18 | } 19 | } 20 | \note{ 21 | This package is entirely dependently upon \pkg{gpuR}. This decision 22 | was made for the following reasons: \preformatted{ 23 | 24 | 1. Avoid repetition of code that would be duplicated from \pkg{gpuR}. 25 | 26 | 2. This will allow any updates in the parent package to immediately be 27 | available within this package (using the OpenCL backend) until corresponding 28 | CUDA functions are made available. 29 | 30 | } 31 | } 32 | \author{ 33 | Charles Determan \email{cdetermanjr@gmail.com} 34 | 35 | Maintainer: Charles Determan \email{cdetermanjr@gmail.com} 36 | } 37 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | 2 | # Using pocl_ubuntu build 3 | FROM nvidia/cuda:8.0-devel-ubuntu14.04 4 | 5 | # Make port 80 available to the world outside this container 6 | EXPOSE 80 7 | 8 | ENV BACKEND=CUDA 9 | 10 | RUN apt-get update 11 | RUN apt-get install -y --force-yes apt-transport-https libcurl4-openssl-dev libssl-dev libxml2-dev git 12 | 13 | #apt-key adv --recv-key --keyserver keyserver.ubuntu.com E084DAB9 14 | 15 | RUN echo "deb https://cloud.r-project.org/bin/linux/ubuntu/ trusty/" >> /etc/apt/sources.list; \ 16 | apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key E084DAB9 17 | 18 | RUN apt-get install -y --force-yes software-properties-common 19 | RUN add-apt-repository ppa:marutter/rrutter 20 | RUN apt-get update 21 | 22 | RUN apt-get install -y --force-yes r-base r-base-dev 23 | 24 | 25 | RUN git config --global user.email "cdetermanjr@gmail.com"; \ 26 | git config --global user.name "Charles Determan" 27 | 28 | # setup R configuration and install packages 29 | RUN echo "r <- getOption('repos'); r['CRAN'] <- 'https://cran.rstudio.com'; options(repos = r);" > ~/.Rprofile 30 | RUN Rscript -e "install.packages(c('devtools', 'testthat', 'roxygen2', 'stringi'))" 31 | RUN Rscript -e "devtools::install_github('RcppCore/Rcpp')" 32 | RUN Rscript -e "devtools::install_github('wrathematics/thrust')" 33 | 34 | RUN git clone https://github.com/gpuRcore/gpuRcuda.git 35 | RUN chmod 777 gpuRcuda/configure 36 | 37 | RUN R CMD INSTALL gpuRcuda/ 38 | 39 | 40 | -------------------------------------------------------------------------------- /inst/include/gpuRcuda/host_matrix.hpp: -------------------------------------------------------------------------------- 1 | #ifndef HOST_MATRIX_HPP 2 | #define HOST_MATRIX_HPP 3 | 4 | #define R_NO_REMAP 5 | 6 | // R headers 7 | #include 8 | #include 9 | 10 | // Thrust headers 11 | #include "gpuRcuda/thrust_matrix.hpp" 12 | 13 | #include 14 | 15 | #include 16 | 17 | template 18 | class host_matrix: public thrust_matrix { 19 | 20 | private: 21 | std::shared_ptr > h_ptr; 22 | 23 | public: 24 | 25 | // initializers 26 | host_matrix() { }; // private default constructor 27 | host_matrix(int nr, int nc): thrust_matrix(nr, nc){ 28 | // initialize vector of zeros 29 | thrust::host_vector vec(nr*nc); 30 | thrust::fill(vec.begin(), vec.end(), (T)(0)); 31 | h_ptr = std::make_shared >(vec); 32 | } 33 | host_matrix(T init, int nr, int nc): thrust_matrix(nr, nc){ 34 | // initialize vector of init 35 | thrust::host_vector vec(nr*nc); 36 | thrust::fill(vec.begin(), vec.end(), init); 37 | h_ptr = std::make_shared >(vec); 38 | } 39 | host_matrix(T *x, int nr, int nc): thrust_matrix(nr, nc){ 40 | 41 | // initialize from SEXP pointer 42 | thrust::host_vector vec(x, x + nr*nc); 43 | h_ptr = std::make_shared >(vec); 44 | } 45 | 46 | // return shared_ptr 47 | std::shared_ptr > getPtr(){ 48 | return h_ptr; 49 | } 50 | 51 | }; 52 | 53 | #endif -------------------------------------------------------------------------------- /inst/include/gpuRcuda/device_matrix.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DEVICE_MATRIX_HPP 2 | #define DEVICE_MATRIX_HPP 3 | 4 | #define R_NO_REMAP 5 | 6 | // R headers 7 | #include 8 | #include 9 | 10 | // Thrust headers 11 | #include "gpuRcuda/thrust_matrix.hpp" 12 | 13 | #include 14 | 15 | #include 16 | 17 | template 18 | class device_matrix: public thrust_matrix { 19 | 20 | private: 21 | std::shared_ptr > h_ptr; 22 | 23 | public: 24 | 25 | // initializers 26 | device_matrix() { }; // private default constructor 27 | device_matrix(int nr, int nc): thrust_matrix(nr, nc){ 28 | // initialize vector of zeros 29 | thrust::device_vector vec(nr*nc); 30 | thrust::fill(vec.begin(), vec.end(), (T)(0)); 31 | h_ptr = std::make_shared >(vec); 32 | } 33 | device_matrix(T init, int nr, int nc): thrust_matrix(nr, nc){ 34 | // initialize vector of init 35 | thrust::device_vector vec(nr*nc); 36 | thrust::fill(vec.begin(), vec.end(), init); 37 | h_ptr = std::make_shared >(vec); 38 | } 39 | device_matrix(T *x, int nr, int nc): thrust_matrix(nr, nc){ 40 | 41 | // initialize from SEXP pointer 42 | thrust::device_vector vec(x, x + nr*nc); 43 | h_ptr = std::make_shared >(vec); 44 | } 45 | 46 | // return shared_ptr 47 | std::shared_ptr > getPtr(){ 48 | return h_ptr; 49 | } 50 | 51 | }; 52 | 53 | #endif -------------------------------------------------------------------------------- /inst/include/gpuRcuda/device_vector.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DEVICE_VECTOR_HPP 2 | #define DEVICE_VECTOR_HPP 3 | 4 | #define R_NO_REMAP 5 | 6 | // R headers 7 | #include 8 | #include 9 | 10 | // Thrust headers 11 | #include "gpuRcuda/thrust_vector.hpp" 12 | 13 | #include 14 | 15 | #include 16 | 17 | template 18 | class device_vector: public thrust_vector { 19 | 20 | private: 21 | std::shared_ptr > ptr; 22 | 23 | public: 24 | 25 | // initializers 26 | device_vector() { }; // private default constructor 27 | device_vector(int size){ 28 | // initialize vector of zeros 29 | thrust::device_vector vec(size); 30 | thrust::fill(vec.begin(), vec.end(), (T)(0)); 31 | ptr = std::make_shared >(vec); 32 | } 33 | device_vector(T init, int size){ 34 | // initialize vector of init 35 | thrust::device_vector vec(size); 36 | thrust::fill(vec.begin(), vec.end(), init); 37 | ptr = std::make_shared >(vec); 38 | } 39 | device_vector(T *x, int size){ 40 | 41 | // initialize from SEXP pointer 42 | thrust::device_vector vec(x, x + size); 43 | ptr = std::make_shared >(vec); 44 | } 45 | 46 | device_vector(thrust::host_vector h_vec){ 47 | thrust::device_vector vec = h_vec; 48 | ptr = std::make_shared >(vec); 49 | } 50 | 51 | virtual int size(){ 52 | return ptr->size(); 53 | } 54 | 55 | // return shared_ptr 56 | std::shared_ptr > getPtr(){ 57 | return ptr; 58 | } 59 | 60 | }; 61 | 62 | #endif -------------------------------------------------------------------------------- /src/utils.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "gpuRcuda/thrust_matrix.hpp" 3 | #include "gpuRcuda/thrust_vector.hpp" 4 | 5 | using namespace Rcpp; 6 | 7 | template 8 | int cpp_length(SEXP ptrA_) 9 | { 10 | Rcpp::XPtr > ptrA(ptrA_); 11 | return ptrA->size(); 12 | } 13 | 14 | template 15 | int cpp_ncol(SEXP ptrA_) 16 | { 17 | Rcpp::XPtr > ptrA(ptrA_); 18 | return ptrA->ncol(); 19 | } 20 | 21 | template 22 | int cpp_nrow(SEXP ptrA_) 23 | { 24 | Rcpp::XPtr > ptrA(ptrA_); 25 | return ptrA->nrow(); 26 | } 27 | 28 | // [[Rcpp::export]] 29 | int cpp_length(SEXP ptrA, const int type_flag) 30 | { 31 | switch(type_flag){ 32 | case 4: 33 | return cpp_length(ptrA); 34 | case 6: 35 | // return cpp_length(ptrA); 36 | case 8: 37 | return cpp_length(ptrA); 38 | default: 39 | throw Rcpp::exception("unknown type detected for gpuRcuda object!"); 40 | } 41 | } 42 | 43 | // [[Rcpp::export]] 44 | int cpp_ncol(SEXP ptrA, const int type_flag) 45 | { 46 | switch(type_flag){ 47 | case 4: 48 | return cpp_ncol(ptrA); 49 | case 6: 50 | // return cpp_ncol(ptrA); 51 | case 8: 52 | return cpp_ncol(ptrA); 53 | default: 54 | throw Rcpp::exception("unknown type detected for gpuRcuda object!"); 55 | } 56 | } 57 | 58 | // [[Rcpp::export]] 59 | int cpp_nrow(SEXP ptrA, const int type_flag) 60 | { 61 | switch(type_flag){ 62 | case 4: 63 | return cpp_nrow(ptrA); 64 | case 6: 65 | // return cpp_nrow(ptrA); 66 | case 8: 67 | return cpp_nrow(ptrA); 68 | default: 69 | throw Rcpp::exception("unknown type detected for gpuRcuda object!"); 70 | } 71 | } 72 | 73 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | branches: 2 | only: 3 | - master 4 | 5 | language: r 6 | 7 | compiler: 8 | - g++ 9 | 10 | dist: trusty 11 | sudo: required 12 | warnings_are_errors: false 13 | 14 | env: 15 | global: 16 | - CRAN: http://cran.rstudio.com 17 | 18 | r_binary_packages: 19 | - devtools 20 | - Rcpp 21 | - stringi 22 | - roxygen2 23 | 24 | r_github_packages: 25 | - wrathematics/thrust 26 | - jimhester/covr 27 | 28 | before_install: 29 | #- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test 30 | #- sudo apt-get update -qq 31 | #- sudo apt-get install -qq opencl-headers libboost-program-options-dev 32 | #- cd .. 33 | #- echo "Installing CUDA" 34 | #- wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64/cuda-repo-ubuntu1404_8.0.61-1_amd64.deb 35 | #- sudo dpkg -i cuda-repo-ubuntu1404_8.0.61-1_amd64.deb 36 | #- cd ${TRAVIS_BUILD_DIR} 37 | #- sudo apt-get update 38 | #- sudo apt-get install cuda-drivers cuda-core-8-0 cuda-cudart-dev-8-0 39 | #- echo "Creating symbolic link to OpenCL because 12.04 CUDA doesn't do it." 40 | #- ls /usr/local/ 41 | #- ls /usr/local/cuda-8.0 42 | #- ls /usr/local/cuda-8.0/lib64/ 43 | #- sudo ln -s /usr/local/cuda-8.0/lib64/libOpenCL.so /usr/lib/x86_64-linux-gnu/libOpenCL.so 44 | #- sudo apt-get install -qq g++-4.8 45 | #- export CXX="g++-4.8" 46 | #- sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 90 47 | #- sudo ln -s /usr/lib/x86_64-linux-gnu/libgfortran.so.3 /usr/lib/libgfortran.so 48 | 49 | # test CUDA build 50 | after_script: 51 | - docker build -t gpurcore/gpurcuda . 52 | 53 | after_success: 54 | - Rscript -e 'devtools::install();library(gpuRcuda);library(methods);devtools::test()' 55 | - Rscript -e 'options(covr.gcov = "gcov-4.8");library(covr);coveralls();codecov()' 56 | 57 | notifications: 58 | email: 59 | on_success: change 60 | on_failure: change 61 | -------------------------------------------------------------------------------- /R/class-nvVector.R: -------------------------------------------------------------------------------- 1 | # The primary class for all nvVector objects 2 | 3 | #' @title nvVector Class 4 | #' @description This is the 'mother' class for all 5 | #' nvVector objects. All other nvVector classes 6 | #' inherit from this class but there are no current 7 | #' circumstances where this class is used directly. 8 | #' 9 | #' There are multiple child classes that correspond 10 | #' to the particular data type contained. These include 11 | #' \code{invVector}. 12 | #' @name nvVector-class 13 | #' @rdname nvVector-class 14 | #' @author Charles Determan Jr. 15 | #' @seealso \code{\link{invVector-class}} 16 | #' @include class.R 17 | #' @export 18 | setClass('nvVector', 19 | contains = 'gpuRcudaVector') 20 | 21 | 22 | #' @title invVector Class 23 | #' @description An integer vector in the S4 \code{nvVector} 24 | #' representation. 25 | #' @section Slots: 26 | #' \describe{ 27 | #' \item{\code{address}:}{An integer vector object} 28 | #' } 29 | #' @name invVector-class 30 | #' @rdname invVector-class 31 | #' @author Charles Determan Jr. 32 | #' @seealso \code{\link{nvVector-class}} 33 | #' @export 34 | setClass("invVector", 35 | contains = "nvVector") 36 | 37 | 38 | #' @title fnvVector Class 39 | #' @description An float vector in the S4 \code{nvVector} 40 | #' representation. 41 | #' @section Slots: 42 | #' \describe{ 43 | #' \item{\code{address}:}{Pointer to a float typed vector} 44 | #' } 45 | #' @name fnvVector-class 46 | #' @rdname fnvVector-class 47 | #' @author Charles Determan Jr. 48 | #' @seealso \code{\link{nvVector-class}} 49 | #' @export 50 | setClass("fnvVector", 51 | contains = "nvVector") 52 | 53 | 54 | #' @title dnvVector Class 55 | #' @description An double vector in the S4 \code{nvVector} 56 | #' representation. 57 | #' @section Slots: 58 | #' \describe{ 59 | #' \item{\code{address}:}{Pointer to a double typed vector} 60 | #' } 61 | #' @name dnvVector-class 62 | #' @rdname dnvVector-class 63 | #' @author Charles Determan Jr. 64 | #' @seealso \code{\link{nvVector-class}} 65 | #' @export 66 | setClass("dnvVector", 67 | contains = "nvVector") 68 | -------------------------------------------------------------------------------- /R/class.R: -------------------------------------------------------------------------------- 1 | #' @title gpuRcudaMatrix Class 2 | #' @description This is the 'mother' class for all 3 | #' gpuRcudaMatrix objects. It is essentially a wrapper for 4 | #' a basic R matrix (possibly to be improved). All other 5 | #' gpuRcuda classes inherit from this class but 6 | #' there are no current circumstances where this class 7 | #' is used directly. 8 | #' 9 | #' @section Slots: 10 | #' Common to all gpuRcuda objects in the package 11 | #' \describe{ 12 | #' \item{\code{address}:}{An R matrix object} 13 | #' } 14 | #' @note R does not contain a native float type. As such, 15 | #' the matrix data within a such an object 16 | #' will be represented as double but downcast when any 17 | #' gpuRcuda methods are used. 18 | #' 19 | #' May also remove the type slot 20 | #' 21 | #' @name gpuRcudaMatrix-class 22 | #' @rdname gpuRcudaMatrix-class 23 | #' @author Charles Determan Jr. 24 | #' @seealso \code{\link{nvMatrix-class}}, 25 | #' \code{\link{cudaMatrix-class}} 26 | #' @export 27 | setClass('gpuRcudaMatrix', 28 | slots = c(address = "externalptr")) 29 | 30 | 31 | #' @title gpuRcudaVector Class 32 | #' @description This is the 'mother' class for all 33 | #' gpuRcudaVector objects. It is essentially a wrapper for 34 | #' a basic R vector (possibly to be improved). All other 35 | #' gpuRcuda classes inherit from this class but 36 | #' there are no current circumstances where this class 37 | #' is used directly. 38 | #' 39 | #' @section Slots: 40 | #' Common to all gpuRcuda objects in the package 41 | #' \describe{ 42 | #' \item{\code{address}:}{An R vector object} 43 | #' } 44 | #' @note R does not contain a native float type. As such, 45 | #' the vector data within a such an object 46 | #' will be represented as double but downcast when any 47 | #' gpuRcuda methods are used. 48 | #' 49 | #' May also remove the type slot 50 | #' 51 | #' @name gpuRcudaVector-class 52 | #' @rdname gpuRcudaVector-class 53 | #' @author Charles Determan Jr. 54 | #' @seealso \code{\link{nvVector-class}}, 55 | #' \code{\link{cudaVector-class}} 56 | #' @export 57 | setClass('gpuRcudaVector', 58 | slots = c(address = "externalptr")) 59 | -------------------------------------------------------------------------------- /src/host_vector.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "gpuRcuda/host_vector.hpp" 4 | 5 | // empty host_vector 6 | template 7 | SEXP nvVecEmpty(int size){ 8 | host_vector *vec = new host_vector(size); 9 | Rcpp::XPtr > pVec(vec); 10 | return pVec; 11 | } 12 | 13 | // convert SEXP to thrust vector 14 | template 15 | SEXP sexpToHostVector(T *x, int size){ 16 | host_vector *vec = new host_vector(x, size); 17 | Rcpp::XPtr > pVec(vec); 18 | return pVec; 19 | } 20 | 21 | // convert thrust vector to SEXP 22 | template 23 | void nvVecToSEXP(SEXP mat, T* x){ 24 | 25 | Rcpp::XPtr > pVec(mat); 26 | 27 | thrust::copy(pVec->getPtr()->begin(), pVec->getPtr()->end(), x); 28 | } 29 | 30 | 31 | // [[Rcpp::export]] 32 | SEXP 33 | sexpToHostVector(SEXP x, 34 | int size, 35 | const int type_flag) 36 | { 37 | switch(type_flag) { 38 | case 4: 39 | return sexpToHostVector(INTEGER(x), size); 40 | case 6: 41 | Rcpp::exception("float not yet implemented"); 42 | // return sexpToHostVector(FLOAT(ptrA_, nr, nc); 43 | case 8: 44 | return sexpToHostVector(REAL(x), size); 45 | default: 46 | throw Rcpp::exception("unknown type detected for gpuRcuda object!"); 47 | } 48 | } 49 | 50 | // [[Rcpp::export]] 51 | void 52 | nvVecToSEXP(SEXP ptrA, 53 | SEXP x, 54 | const int type_flag) 55 | { 56 | switch(type_flag) { 57 | case 4: 58 | nvVecToSEXP(ptrA, INTEGER(x)); 59 | return; 60 | case 6: 61 | Rcpp::exception("float not yet implemented"); 62 | // nvVecToSEXP(ptrA, FLOAT(ptrA_)); 63 | // return; 64 | case 8: 65 | nvVecToSEXP(ptrA, REAL(x)); 66 | return; 67 | default: 68 | throw Rcpp::exception("unknown type detected for gpuRcuda object!"); 69 | } 70 | } 71 | 72 | 73 | // [[Rcpp::export]] 74 | SEXP 75 | nvVecEmpty(int size, 76 | const int type_flag) 77 | { 78 | switch(type_flag) { 79 | case 4: 80 | return nvVecEmpty(size); 81 | case 6: 82 | Rcpp::exception("float not yet implemented"); 83 | // return nvVecEmpty(size); 84 | case 8: 85 | return nvVecEmpty(size); 86 | default: 87 | throw Rcpp::exception("unknown type detected for gpuRcuda object!"); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /R/RcppExports.R: -------------------------------------------------------------------------------- 1 | # Generated by using Rcpp::compileAttributes() -> do not edit by hand 2 | # Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 3 | 4 | sexpToDeviceMatrix <- function(x, nr, nc, type_flag) { 5 | .Call('_gpuRcuda_sexpToDeviceMatrix', PACKAGE = 'gpuRcuda', x, nr, nc, type_flag) 6 | } 7 | 8 | cudaMatToSEXP <- function(ptrA, x, type_flag) { 9 | invisible(.Call('_gpuRcuda_cudaMatToSEXP', PACKAGE = 'gpuRcuda', ptrA, x, type_flag)) 10 | } 11 | 12 | cudaMatEmtpy <- function(nr, nc, type_flag) { 13 | .Call('_gpuRcuda_cudaMatEmtpy', PACKAGE = 'gpuRcuda', nr, nc, type_flag) 14 | } 15 | 16 | sexpToDeviceVector <- function(x, size, type_flag) { 17 | .Call('_gpuRcuda_sexpToDeviceVector', PACKAGE = 'gpuRcuda', x, size, type_flag) 18 | } 19 | 20 | cudaVecToSEXP <- function(ptrA, x, type_flag) { 21 | invisible(.Call('_gpuRcuda_cudaVecToSEXP', PACKAGE = 'gpuRcuda', ptrA, x, type_flag)) 22 | } 23 | 24 | cudaVecEmpty <- function(size, type_flag) { 25 | .Call('_gpuRcuda_cudaVecEmpty', PACKAGE = 'gpuRcuda', size, type_flag) 26 | } 27 | 28 | sexpToHostMatrix <- function(x, nr, nc, type_flag) { 29 | .Call('_gpuRcuda_sexpToHostMatrix', PACKAGE = 'gpuRcuda', x, nr, nc, type_flag) 30 | } 31 | 32 | nvMatToSEXP <- function(ptrA, x, type_flag) { 33 | invisible(.Call('_gpuRcuda_nvMatToSEXP', PACKAGE = 'gpuRcuda', ptrA, x, type_flag)) 34 | } 35 | 36 | nvMatEmtpy <- function(nr, nc, type_flag) { 37 | .Call('_gpuRcuda_nvMatEmtpy', PACKAGE = 'gpuRcuda', nr, nc, type_flag) 38 | } 39 | 40 | sexpToHostVector <- function(x, size, type_flag) { 41 | .Call('_gpuRcuda_sexpToHostVector', PACKAGE = 'gpuRcuda', x, size, type_flag) 42 | } 43 | 44 | nvVecToSEXP <- function(ptrA, x, type_flag) { 45 | invisible(.Call('_gpuRcuda_nvVecToSEXP', PACKAGE = 'gpuRcuda', ptrA, x, type_flag)) 46 | } 47 | 48 | nvVecEmpty <- function(size, type_flag) { 49 | .Call('_gpuRcuda_nvVecEmpty', PACKAGE = 'gpuRcuda', size, type_flag) 50 | } 51 | 52 | cpp_length <- function(ptrA, type_flag) { 53 | .Call('_gpuRcuda_cpp_length', PACKAGE = 'gpuRcuda', ptrA, type_flag) 54 | } 55 | 56 | cpp_ncol <- function(ptrA, type_flag) { 57 | .Call('_gpuRcuda_cpp_ncol', PACKAGE = 'gpuRcuda', ptrA, type_flag) 58 | } 59 | 60 | cpp_nrow <- function(ptrA, type_flag) { 61 | .Call('_gpuRcuda_cpp_nrow', PACKAGE = 'gpuRcuda', ptrA, type_flag) 62 | } 63 | 64 | -------------------------------------------------------------------------------- /src/host_matrix.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "gpuRcuda/host_matrix.hpp" 4 | 5 | // empty host_matrix 6 | template 7 | SEXP nvMatEmpty(int nr, int nc){ 8 | host_matrix *mat = new host_matrix(nr, nc); 9 | Rcpp::XPtr > pMat(mat); 10 | return pMat; 11 | } 12 | 13 | // convert SEXP to thrust matrix 14 | template 15 | SEXP sexpToHostMatrix(T *x, int nr, int nc){ 16 | host_matrix *mat = new host_matrix(x, nr, nc); 17 | Rcpp::XPtr > pMat(mat); 18 | return pMat; 19 | } 20 | 21 | // convert thrust matrix to SEXP 22 | template 23 | void nvMatToSEXP(SEXP mat, T* x){ 24 | 25 | Rcpp::XPtr > pMat(mat); 26 | 27 | thrust::copy(pMat->getPtr()->begin(), pMat->getPtr()->end(), x); 28 | } 29 | 30 | 31 | // [[Rcpp::export]] 32 | SEXP 33 | sexpToHostMatrix(SEXP x, 34 | int nr, 35 | int nc, 36 | const int type_flag) 37 | { 38 | switch(type_flag) { 39 | case 4: 40 | return sexpToHostMatrix(INTEGER(x), nr, nc); 41 | case 6: 42 | Rcpp::exception("float not yet implemented"); 43 | // return sexpToHostMatrix(FLOAT(ptrA_, nr, nc); 44 | case 8: 45 | return sexpToHostMatrix(REAL(x), nr, nc); 46 | default: 47 | throw Rcpp::exception("unknown type detected for gpuRcuda object!"); 48 | } 49 | } 50 | 51 | // [[Rcpp::export]] 52 | void 53 | nvMatToSEXP(SEXP ptrA, 54 | SEXP x, 55 | const int type_flag) 56 | { 57 | switch(type_flag) { 58 | case 4: 59 | nvMatToSEXP(ptrA, INTEGER(x)); 60 | return; 61 | case 6: 62 | Rcpp::exception("float not yet implemented"); 63 | // nvMatToSEXP(FLOAT(ptrA_, nr, nc); 64 | // return; 65 | case 8: 66 | nvMatToSEXP(ptrA, REAL(x)); 67 | return; 68 | default: 69 | throw Rcpp::exception("unknown type detected for gpuRcuda object!"); 70 | } 71 | } 72 | 73 | 74 | // [[Rcpp::export]] 75 | SEXP 76 | nvMatEmtpy(int nr, 77 | int nc, 78 | const int type_flag) 79 | { 80 | switch(type_flag) { 81 | case 4: 82 | return nvMatEmpty(nr, nc); 83 | case 6: 84 | Rcpp::exception("float not yet implemented"); 85 | // return nvMatEmpty(nr, nc); 86 | case 8: 87 | return nvMatEmpty(nr, nc); 88 | default: 89 | throw Rcpp::exception("unknown type detected for gpuRcuda object!"); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/device_matrix.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "gpuRcuda/device_matrix.hpp" 4 | 5 | // empty device_matrix 6 | template 7 | SEXP cudaMatEmpty(int nr, int nc){ 8 | device_matrix *mat = new device_matrix(nr, nc); 9 | Rcpp::XPtr > pMat(mat); 10 | return pMat; 11 | } 12 | 13 | // convert SEXP to thrust matrix 14 | template 15 | SEXP sexpToDeviceMatrix(T *x, int nr, int nc){ 16 | device_matrix *mat = new device_matrix(x, nr, nc); 17 | Rcpp::XPtr > pMat(mat); 18 | return pMat; 19 | } 20 | 21 | // convert thrust matrix to SEXP 22 | template 23 | void cudaMatToSEXP(SEXP mat, T* x){ 24 | 25 | Rcpp::XPtr > pMat(mat); 26 | 27 | thrust::copy(pMat->getPtr()->begin(), pMat->getPtr()->end(), x); 28 | } 29 | 30 | 31 | // [[Rcpp::export]] 32 | SEXP 33 | sexpToDeviceMatrix(SEXP x, 34 | int nr, 35 | int nc, 36 | const int type_flag) 37 | { 38 | switch(type_flag) { 39 | case 4: 40 | return sexpToDeviceMatrix(INTEGER(x), nr, nc); 41 | case 6: 42 | Rcpp::exception("float not yet implemented"); 43 | // return sexpToDeviceMatrix(FLOAT(ptrA_, nr, nc); 44 | case 8: 45 | return sexpToDeviceMatrix(REAL(x), nr, nc); 46 | default: 47 | throw Rcpp::exception("unknown type detected for gpuRcuda object!"); 48 | } 49 | } 50 | 51 | // [[Rcpp::export]] 52 | void 53 | cudaMatToSEXP(SEXP ptrA, 54 | SEXP x, 55 | const int type_flag) 56 | { 57 | switch(type_flag) { 58 | case 4: 59 | cudaMatToSEXP(ptrA, INTEGER(x)); 60 | return; 61 | case 6: 62 | Rcpp::exception("float not yet implemented"); 63 | // cudaMatToSEXP(FLOAT(ptrA_, nr, nc); 64 | // return; 65 | case 8: 66 | cudaMatToSEXP(ptrA, REAL(x)); 67 | return; 68 | default: 69 | throw Rcpp::exception("unknown type detected for gpuRcuda object!"); 70 | } 71 | } 72 | 73 | 74 | // [[Rcpp::export]] 75 | SEXP 76 | cudaMatEmtpy(int nr, 77 | int nc, 78 | const int type_flag) 79 | { 80 | switch(type_flag) { 81 | case 4: 82 | return cudaMatEmpty(nr, nc); 83 | case 6: 84 | Rcpp::exception("float not yet implemented"); 85 | // return cudaMatEmpty(nr, nc); 86 | case 8: 87 | return cudaMatEmpty(nr, nc); 88 | default: 89 | throw Rcpp::exception("unknown type detected for gpuRcuda object!"); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/device_vector.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "gpuRcuda/device_vector.hpp" 4 | 5 | // empty device_vector 6 | template 7 | SEXP cudaVecEmpty(int size){ 8 | 9 | #ifdef __CUDACC__ 10 | cudaSetDevice(0); 11 | #endif 12 | 13 | device_vector *vec = new device_vector(size); 14 | Rcpp::XPtr > pVec(vec); 15 | return pVec; 16 | } 17 | 18 | // convert SEXP to thrust vector 19 | template 20 | SEXP sexpToDeviceVector(T *x, int size){ 21 | device_vector *vec = new device_vector(x, size); 22 | Rcpp::XPtr > pVec(vec); 23 | return pVec; 24 | } 25 | 26 | // convert thrust vector to SEXP 27 | template 28 | void cudaVecToSEXP(SEXP mat, T* x){ 29 | 30 | Rcpp::XPtr > pVec(mat); 31 | 32 | thrust::copy(pVec->getPtr()->begin(), pVec->getPtr()->end(), x); 33 | } 34 | 35 | 36 | // [[Rcpp::export]] 37 | SEXP 38 | sexpToDeviceVector(SEXP x, 39 | int size, 40 | const int type_flag) 41 | { 42 | switch(type_flag) { 43 | case 4: 44 | return sexpToDeviceVector(INTEGER(x), size); 45 | case 6: 46 | Rcpp::exception("float not yet implemented"); 47 | // return sexpToDeviceVector(FLOAT(ptrA_, nr, nc); 48 | case 8: 49 | return sexpToDeviceVector(REAL(x), size); 50 | default: 51 | throw Rcpp::exception("unknown type detected for gpuRcuda object!"); 52 | } 53 | } 54 | 55 | // [[Rcpp::export]] 56 | void 57 | cudaVecToSEXP(SEXP ptrA, 58 | SEXP x, 59 | const int type_flag) 60 | { 61 | switch(type_flag) { 62 | case 4: 63 | cudaVecToSEXP(ptrA, INTEGER(x)); 64 | return; 65 | case 6: 66 | Rcpp::exception("float not yet implemented"); 67 | // cudaVecToSEXP(ptrA, FLOAT(ptrA_)); 68 | // return; 69 | case 8: 70 | cudaVecToSEXP(ptrA, REAL(x)); 71 | return; 72 | default: 73 | throw Rcpp::exception("unknown type detected for gpuRcuda object!"); 74 | } 75 | } 76 | 77 | 78 | // [[Rcpp::export]] 79 | SEXP 80 | cudaVecEmpty(int size, 81 | const int type_flag) 82 | { 83 | switch(type_flag) { 84 | case 4: 85 | return cudaVecEmpty(size); 86 | case 6: 87 | Rcpp::exception("float not yet implemented"); 88 | // return cudaVecEmpty(size); 89 | case 8: 90 | return cudaVecEmpty(size); 91 | default: 92 | throw Rcpp::exception("unknown type detected for gpuRcuda object!"); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /R/class-cudaVector.R: -------------------------------------------------------------------------------- 1 | # The primary class for all cudaVector objects 2 | 3 | #' @title cudaVector Class 4 | #' @description This is the 'mother' class for all 5 | #' cudaVector objects. All other cudaVector classes 6 | #' inherit from this class but there are no current 7 | #' circumstances where this class is used directly. 8 | #' 9 | #' There are multiple child classes that correspond 10 | #' to the particular data type contained. These include 11 | #' \code{icudaVector}. 12 | #' @name cudaVector-class 13 | #' @rdname cudaVector-class 14 | #' @author Charles Determan Jr. 15 | #' @seealso \code{\link{icudaVector-class}} 16 | #' @include class.R 17 | #' @export 18 | setClass('cudaVector', 19 | contains = 'gpuRcudaVector') 20 | # setClass('cudaVector', 21 | # slots = c(address="externalptr")) 22 | 23 | # setClass('cudaVector', 24 | # representation("VIRTUAL"), 25 | # validity = function(object) { 26 | # if( !length(object@object) > 0 ){ 27 | # return("cudaVector must be a length greater than 0") 28 | # } 29 | # TRUE 30 | # }) 31 | 32 | 33 | #' @title icudaVector Class 34 | #' @description An integer vector in the S4 \code{cudaVector} 35 | #' representation. 36 | #' @section Slots: 37 | #' \describe{ 38 | #' \item{\code{address}:}{An integer vector object} 39 | #' } 40 | #' @name icudaVector-class 41 | #' @rdname icudaVector-class 42 | #' @author Charles Determan Jr. 43 | #' @seealso \code{\link{cudaVector-class}} 44 | #' @export 45 | setClass("icudaVector", 46 | contains = "cudaVector") 47 | 48 | 49 | #' @title fcudaVector Class 50 | #' @description An float vector in the S4 \code{cudaVector} 51 | #' representation. 52 | #' @section Slots: 53 | #' \describe{ 54 | #' \item{\code{address}:}{Pointer to a float typed vector} 55 | #' } 56 | #' @name fcudaVector-class 57 | #' @rdname fcudaVector-class 58 | #' @author Charles Determan Jr. 59 | #' @seealso \code{\link{cudaVector-class}} 60 | #' @export 61 | setClass("fcudaVector", 62 | contains = "cudaVector") 63 | 64 | 65 | #' @title dcudaVector Class 66 | #' @description An double vector in the S4 \code{cudaVector} 67 | #' representation. 68 | #' @section Slots: 69 | #' \describe{ 70 | #' \item{\code{address}:}{Pointer to a double typed vector} 71 | #' } 72 | #' @name dcudaVector-class 73 | #' @rdname dcudaVector-class 74 | #' @author Charles Determan Jr. 75 | #' @seealso \code{\link{cudaVector-class}} 76 | #' @export 77 | setClass("dcudaVector", 78 | contains = "cudaVector") 79 | -------------------------------------------------------------------------------- /R/class-nvMatrix.R: -------------------------------------------------------------------------------- 1 | #' @title nvMatrix Class 2 | #' @description This class refers to gpuRcuda matrix 3 | #' objects that are on the host. 4 | #' 5 | #' There are multiple child classes that correspond 6 | #' to the particular data type contained. These include 7 | #' \code{invMatrix}, \code{fnvMatrix}, and 8 | #' \code{dnvMatrix} corresponding to integer, float, and 9 | #' double data types respectively. 10 | #' @section Slots: 11 | #' Common to all nvMatrix objects in the package 12 | #' \describe{ 13 | #' \item{\code{address}:}{An R matrix object} 14 | #' } 15 | #' 16 | #' @name nvMatrix-class 17 | #' @rdname nvMatrix-class 18 | #' @author Charles Determan Jr. 19 | #' @seealso \code{\link{invMatrix-class}}, 20 | #' \code{\link{fnvMatrix-class}}, 21 | #' \code{\link{dnvMatrix-class}} 22 | #' @include class.R 23 | #' @export 24 | setClass('nvMatrix', 25 | contains = "gpuRcudaMatrix") 26 | 27 | 28 | # setClass('nvMatrix', 29 | # slots = c(address="externalptr")) 30 | 31 | 32 | #' @title invMatrix Class 33 | #' @description An integer type matrix in the S4 \code{nvMatrix} 34 | #' representation. 35 | #' @section Slots: 36 | #' \describe{ 37 | #' \item{\code{address}:}{A integer typed R matrix} 38 | #' } 39 | #' @name invMatrix-class 40 | #' @rdname invMatrix-class 41 | #' @author Charles Determan Jr. 42 | #' @seealso \code{\link{nvMatrix-class}}, 43 | #' \code{\link{invMatrix-class}}, 44 | #' \code{\link{dnvMatrix-class}} 45 | #' @export 46 | setClass("invMatrix", 47 | contains = "nvMatrix", 48 | validity = function(object) { 49 | if( typeof(object) != "integer"){ 50 | return("invMatrix must be of type 'integer'") 51 | } 52 | TRUE 53 | }) 54 | 55 | #' @title fnvMatrix Class 56 | #' @description An integer type matrix in the S4 \code{nvMatrix} 57 | #' representation. 58 | #' @section Slots: 59 | #' \describe{ 60 | #' \item{\code{address}:}{A numeric R matrix.} 61 | #' } 62 | #' @name fnvMatrix-class 63 | #' @rdname fnvMatrix-class 64 | #' @author Charles Determan Jr. 65 | #' @seealso \code{\link{nvMatrix-class}}, 66 | #' \code{\link{invMatrix-class}}, 67 | #' \code{\link{dnvMatrix-class}} 68 | #' @export 69 | setClass("fnvMatrix", 70 | contains = "nvMatrix") 71 | 72 | 73 | #' @title dnvMatrix Class 74 | #' @description An integer type matrix in the S4 \code{nvMatrix} 75 | #' representation. 76 | #' @section Slots: 77 | #' \describe{ 78 | #' \item{\code{address}:}{A numeric R matrix} 79 | #' } 80 | #' @name dnvMatrix-class 81 | #' @rdname dnvMatrix-class 82 | #' @author Charles Determan Jr. 83 | #' @seealso \code{\link{nvMatrix-class}}, 84 | #' \code{\link{invMatrix-class}}, 85 | #' \code{\link{fnvMatrix-class}} 86 | #' @export 87 | setClass("dnvMatrix", 88 | contains = "nvMatrix" 89 | ) 90 | -------------------------------------------------------------------------------- /R/nvVector.R: -------------------------------------------------------------------------------- 1 | #' @title Construct a nvVector 2 | #' @description Construct a nvVector of a class that inherits 3 | #' from \code{nvVector} 4 | #' @param data An object that is or can be converted to a 5 | #' \code{vector} 6 | #' @param length A non-negative integer specifying the desired length. 7 | #' @param type A character string specifying the type of nvVector. Default 8 | #' is NULL where type is inherited from the source data type. 9 | #' @param ... Additional method to pass to nvVector methods 10 | #' @return A nvVector object 11 | #' @docType methods 12 | #' @rdname nvVector-methods 13 | #' @author Charles Determan Jr. 14 | #' @export 15 | setGeneric("nvVector", function(data, length, type=NULL, ...){ 16 | standardGeneric("nvVector") 17 | }) 18 | 19 | #' @rdname nvVector-methods 20 | #' @aliases nvVector,vector 21 | setMethod('nvVector', 22 | signature(data = 'vector', length = 'missing'), 23 | function(data, type=NULL){ 24 | 25 | if (is.null(type)) type <- typeof(data) 26 | size <- length(data) 27 | 28 | data = switch(type, 29 | integer = { 30 | new("invVector", 31 | address=sexpToHostVector(data, size, 4L)) 32 | }, 33 | float = { 34 | new("fnvVector", 35 | address=sexpToHostVector(data, size, 6L)) 36 | }, 37 | double = { 38 | new("dnvVector", 39 | address = sexpToHostVector(data, size, 8L)) 40 | }, 41 | stop("this is an unrecognized 42 | or unimplemented data type") 43 | ) 44 | 45 | return(data) 46 | }, 47 | valueClass = "nvVector") 48 | 49 | 50 | #' @rdname nvVector-methods 51 | #' @aliases nvVector,missing 52 | setMethod('nvVector', 53 | signature(data = 'missing'), 54 | function(data, length, type=NULL){ 55 | 56 | if (is.null(type)) type <- getOption("gpuRcuda.default.type") 57 | if (length <= 0) stop("length must be a positive integer") 58 | if (length != as.integer(length)) stop("length must be a positive integer") 59 | 60 | data = switch(type, 61 | integer = { 62 | new("invVector", 63 | address=nvVecEmpty(length, 4L)) 64 | }, 65 | float = { 66 | new("fnvVector", 67 | address=nvVecEmpty(length, 6L)) 68 | }, 69 | double = { 70 | new("dnvVector", 71 | address = nvVecEmpty(length, 8L)) 72 | }, 73 | stop("this is an unrecognized 74 | or unimplemented data type") 75 | ) 76 | 77 | return(data) 78 | }, 79 | valueClass = "nvVector") 80 | -------------------------------------------------------------------------------- /R/cudaVector.R: -------------------------------------------------------------------------------- 1 | #' @title Construct a cudaVector 2 | #' @description Construct a cudaVector of a class that inherits 3 | #' from \code{cudaVector} 4 | #' @param data An object that is or can be converted to a 5 | #' \code{vector} 6 | #' @param length A non-negative integer specifying the desired length. 7 | #' @param type A character string specifying the type of cudaVector. Default 8 | #' is NULL where type is inherited from the source data type. 9 | #' @param ... Additional method to pass to cudaVector methods 10 | #' @return A cudaVector object 11 | #' @docType methods 12 | #' @rdname cudaVector-methods 13 | #' @author Charles Determan Jr. 14 | #' @export 15 | setGeneric("cudaVector", function(data, length, type=NULL, ...){ 16 | standardGeneric("cudaVector") 17 | }) 18 | 19 | #' @rdname cudaVector-methods 20 | #' @aliases cudaVector,vector 21 | setMethod('cudaVector', 22 | signature(data = 'vector', length = 'missing'), 23 | function(data, length=NULL, type=NULL){ 24 | 25 | if (is.null(type)) type <- typeof(data) 26 | 27 | data = switch(type, 28 | integer = { 29 | new("icudaVector", 30 | address = sexpToDeviceVector(data, length(data), 4L)) 31 | }, 32 | float = { 33 | new("fcudaVector", 34 | address = sexpToDeviceVector(data, length(data), 6L)) 35 | }, 36 | double = { 37 | new("dcudaVector", 38 | address = sexpToDeviceVector(data, length(data), 8L)) 39 | }, 40 | stop("this is an unrecognized 41 | or unimplemented data type") 42 | ) 43 | 44 | return(data) 45 | }, 46 | valueClass = "cudaVector") 47 | 48 | 49 | #' @rdname cudaVector-methods 50 | #' @aliases cudaVector,missing 51 | setMethod('cudaVector', 52 | signature(data = 'missing'), 53 | function(data, length, type=NULL){ 54 | 55 | if (is.null(type)) type <- getOption("gpuRcuda.default.type") 56 | if (length <= 0) stop("length must be a positive integer") 57 | if (length != as.integer(length)) stop("length must be a positive integer") 58 | 59 | data = switch(type, 60 | integer = { 61 | new("icudaVector", 62 | address = cudaVecEmpty(length, 4L)) 63 | }, 64 | float = { 65 | new("fcudaVector", 66 | address = cudaVecEmpty(length, 6L)) 67 | }, 68 | double = { 69 | new("dcudaVector", 70 | address = cudaVecEmpty(length, 8L)) 71 | }, 72 | stop("this is an unrecognized 73 | or unimplemented data type") 74 | ) 75 | 76 | return(data) 77 | }, 78 | valueClass = "cudaVector") 79 | -------------------------------------------------------------------------------- /R/nvMatrix.R: -------------------------------------------------------------------------------- 1 | 2 | # need code to reshape if dimensions differ from input 3 | 4 | #' @title Construct a nvMatrix 5 | #' @description Construct a nvMatrix of a class that inherits 6 | #' from \code{nvMatrix} 7 | #' @param data An object that is or can be converted to a 8 | #' \code{matrix} object 9 | #' @param ncol An integer specifying the number of columns 10 | #' @param nrow An integer specifying the number of rows 11 | #' @param type A character string specifying the type of nvMatrix. Default 12 | #' is NULL where type is inherited from the source data type. 13 | #' @param ... Additional method to pass to nvMatrix methods 14 | #' @return A nvMatrix object 15 | #' @docType methods 16 | #' @rdname nvMatrix-methods 17 | #' @author Charles Determan Jr. 18 | #' @export 19 | setGeneric("nvMatrix", function(data = NA, ncol=NA, nrow=NA, type=NULL, ...){ 20 | standardGeneric("nvMatrix") 21 | }) 22 | 23 | #' @rdname nvMatrix-methods 24 | #' @aliases nvMatrix,matrix 25 | setMethod('nvMatrix', 26 | signature(data = 'matrix'), 27 | function(data, type=NULL){ 28 | 29 | if (is.null(type)) type <- typeof(data) 30 | 31 | nrow <- nrow(data) 32 | ncol <- ncol(data) 33 | 34 | data = switch(type, 35 | integer = { 36 | new("invMatrix", 37 | address=sexpToHostMatrix(data, nrow, ncol, type = 4L)) 38 | }, 39 | float = { 40 | stop("float not yet implemented") 41 | # new("fnvMatrix", 42 | # address=sexpToHostMatrix(data)) 43 | }, 44 | double = { 45 | new("dnvMatrix", 46 | address = sexpToHostMatrix(data, nrow, ncol, type = 8L)) 47 | }, 48 | stop("this is an unrecognized 49 | or unimplemented data type") 50 | ) 51 | 52 | return(data) 53 | }, 54 | valueClass = "nvMatrix" 55 | ) 56 | 57 | 58 | #' @rdname nvMatrix-methods 59 | #' @aliases nvMatrix,missing 60 | setMethod('nvMatrix', 61 | signature(data = 'missing'), 62 | function(data, ncol=NA, nrow=NA, type=NULL){ 63 | 64 | if (is.null(type)) type <- getOption("gpuRcuda.default.type") 65 | 66 | data = switch(type, 67 | integer = { 68 | new("invMatrix", 69 | address=nvMatEmtpy(nrow, ncol, 4L)) 70 | }, 71 | float = { 72 | new("fnvMatrix", 73 | address=nvMatEmtpy(nrow, ncol, 6L)) 74 | }, 75 | double = { 76 | new("dnvMatrix", 77 | address = nvMatEmtpy(nrow, ncol, 8L)) 78 | }, 79 | stop("this is an unrecognized 80 | or unimplemented data type") 81 | ) 82 | 83 | return(data) 84 | }, 85 | valueClass = "nvMatrix" 86 | ) 87 | -------------------------------------------------------------------------------- /R/cudaMatrix.R: -------------------------------------------------------------------------------- 1 | 2 | # need code to reshape if dimensions differ from input 3 | 4 | #' @title Construct a cudaMatrix 5 | #' @description Construct a cudaMatrix of a class that inherits 6 | #' from \code{cudaMatrix} 7 | #' @param data An object that is or can be converted to a 8 | #' \code{matrix} object 9 | #' @param ncol An integer specifying the number of columns 10 | #' @param nrow An integer specifying the number of rows 11 | #' @param type A character string specifying the type of cudaMatrix. Default 12 | #' is NULL where type is inherited from the source data type. 13 | #' @param ... Additional method to pass to cudaMatrix methods 14 | #' @return A cudaMatrix object 15 | #' @docType methods 16 | #' @rdname cudaMatrix-methods 17 | #' @author Charles Determan Jr. 18 | #' @export 19 | setGeneric("cudaMatrix", function(data = NA, ncol=NA, nrow=NA, type=NULL, ...){ 20 | standardGeneric("cudaMatrix") 21 | }) 22 | 23 | #' @rdname cudaMatrix-methods 24 | #' @aliases cudaMatrix,matrix 25 | setMethod('cudaMatrix', 26 | signature(data = 'matrix'), 27 | function(data, type=NULL){ 28 | 29 | if (is.null(type)) type <- typeof(data) 30 | 31 | data = switch(type, 32 | integer = { 33 | new("icudaMatrix", 34 | address = sexpToDeviceMatrix(data, nrow(data), ncol(data), type = 4L)) 35 | }, 36 | float = { 37 | new("fcudaMatrix", 38 | address = sexpToDeviceMatrix(data, nrow(data), ncol(data), type = 6L)) 39 | }, 40 | double = { 41 | new("dcudaMatrix", 42 | address = sexpToDeviceMatrix(data, nrow(data), ncol(data), type = 8L)) 43 | }, 44 | stop("this is an unrecognized 45 | or unimplemented data type") 46 | ) 47 | 48 | return(data) 49 | }, 50 | valueClass = "cudaMatrix" 51 | ) 52 | 53 | 54 | #' @rdname cudaMatrix-methods 55 | #' @aliases cudaMatrix,missing 56 | setMethod('cudaMatrix', 57 | signature(data = 'missing'), 58 | function(data, ncol=NA, nrow=NA, type=NULL){ 59 | 60 | if (is.null(type)) type <- getOption("gpuRcuda.default.type") 61 | 62 | data = switch(type, 63 | integer = { 64 | new("icudaMatrix", 65 | address = cudaMatEmtpy(nrow, ncol, 4L)) 66 | }, 67 | float = { 68 | new("fcudaMatrix", 69 | address = cudaMatEmtpy(nrow, ncol, 6L)) 70 | }, 71 | double = { 72 | new("dcudaMatrix", 73 | address = cudaMatEmtpy(nrow, ncol, 8L)) 74 | }, 75 | stop("this is an unrecognized 76 | or unimplemented data type") 77 | ) 78 | 79 | return(data) 80 | }, 81 | valueClass = "cudaMatrix" 82 | ) 83 | 84 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gpuRcuda: The Simple CUDA GPU Interface for R 2 | [![Travis-CI Build Status](https://travis-ci.org/gpuRcore/gpuRcuda.png?branch=master)](https://travis-ci.org/gpuRcore/gpuRcuda) 3 | 4 | Test coverage: [![Coverage Status](https://coveralls.io/repos/github/gpuRcore/gpuRcuda/badge.svg?branch=master)](https://coveralls.io/github/gpuRcore/gpuRcuda?branch=master) 5 | 6 | Welcome to gpuRcuda! This package is designed to be an extension upon the 7 | more general [gpuR](https://github.com/cdeterman/gpuR) package. Essentially, 8 | this package creates a new series of classes that mirror those from 9 | gpuR classes. The key aspect of this 10 | package is to allow the user to use a CUDA backend where the NVIDIA specific 11 | language will improve overall performance. 12 | 13 | The syntax is designed to be identical to [gpuR](https://github.com/cdeterman/gpuR) 14 | 15 | ```r 16 | ORDER <- 1024 17 | A <- matrix(rnorm(ORDER^2), nrow=ORDER) 18 | B <- matrix(rnorm(ORDER^2), nrow=ORDER) 19 | gpuA <- cudaMatrix(A, type="double") 20 | gpuB <- cudaMatrix(B, type="double") 21 | 22 | C <- A %*% B 23 | gpuC <- gpuA %*% gpuB 24 | 25 | all(C == gpuC) 26 | [1] TRUE 27 | ``` 28 | 29 | ### Dependencies 30 | 1. opencl-headers (shared library) 31 | 2. NVIDIA Drivers & SDK 32 | 33 | ### NVIDIA Driver and CUDA/OpenCL 34 | #### Up-to-date Card 35 | If you are fortunate enough to have a very recent card that you can 36 | use the most recent drivers. THis install is much more simple 37 | ``` 38 | # Install Boost & OpenCL headers 39 | sudo apt-get install opencl-headers 40 | 41 | # Install NVIDIA Drivers and CUDA 42 | sudo add-apt-repository -y ppa:xorg-edgers/ppa 43 | sudo apt-get update 44 | sudo apt-get install nvidia-346 nvidia-settings 45 | sudo apt-get install cuda 46 | ``` 47 | 48 | #### Older Card 49 | If you have an older card that doesn't support the newest drivers: 50 | 51 | 1. Purge any existing nvidia and cuda implementations 52 | (`sudo apt-get purge cuda* nvidia-*`) 53 | 2. Download appropriate CUDA toolkit for the specific card. You can figure 54 | this out by first checking which NVIDIA driver is compatible with your card 55 | by searching for it in [NVIDIA's Driver Downloads](http://www.nvidia.com/Download/index.aspx?lang=en-us). 56 | Then check which cuda toolkit is compatible with the driver from this 57 | [Backward Compatibility Table](http://docs.roguewave.com/totalview/8.14.1/html/index.html#page/User_Guides/totalviewug-about-cuda.31.4.html) 58 | Let's say the cuda-6.5 toolkit was appropriate, which you can download from the 59 | [CUDA toolkit archive](https://developer.nvidia.com/cuda-toolkit-archive). 60 | Once downloaded, run the .run file. 61 | 3. Reboot computer 62 | 4. Switch to ttyl (Ctrl-Alt-F1) 63 | 5. Stop the X server (sudo stop lightdm) 64 | 6. Run the cuda run file (`sh cuda_6.5.14_linux_64.run`) 65 | 7. Select 'yes' and accept all defaults 66 | 8. Required reboot 67 | 9. Switch to ttyl, stop X server and run the cuda run file again and select 68 | 'yes' and default for everything (including the driver again) 69 | 10. Update `PATH` to include `/usr/local/cuda-6.5/bin` and `LD_LIBRARY_PATH` 70 | to include `/usr/local/cuda-6.5/lib64` 71 | 11. Reboot again 72 | -------------------------------------------------------------------------------- /R/class-cudaMatrix.R: -------------------------------------------------------------------------------- 1 | #' @title cudaMatrix Class 2 | #' @description This class refers to gpuRcuda matrix 3 | #' objects that are on the device. 4 | #' 5 | #' There are multiple child classes that correspond 6 | #' to the particular data type contained. These include 7 | #' \code{icudaMatrix}, \code{fcudaMatrix}, and 8 | #' \code{dcudaMatrix} corresponding to integer, float, and 9 | #' double data types respectively. 10 | #' @section Slots: 11 | #' Common to all cudaMatrix objects in the package 12 | #' \describe{ 13 | #' \item{\code{address}:}{An R matrix object} 14 | #' } 15 | #' @note R does not contain a native float type. As such, 16 | #' the matrix data within a \code{\link{fcudaMatrix-class}} 17 | #' will be represented as double but downcast when any 18 | #' cudaMatrix methods are used. 19 | #' 20 | #' May also remove the type slot 21 | #' 22 | #' @name cudaMatrix-class 23 | #' @rdname cudaMatrix-class 24 | #' @author Charles Determan Jr. 25 | #' @seealso \code{\link{icudaMatrix-class}}, 26 | #' \code{\link{fcudaMatrix-class}}, 27 | #' \code{\link{dcudaMatrix-class}} 28 | #' @include class.R 29 | #' @export 30 | setClass('cudaMatrix', 31 | contains = "gpuRcudaMatrix") 32 | 33 | 34 | # setClass('cudaMatrix', 35 | # slots = c(address="externalptr")) 36 | 37 | 38 | #' @title icudaMatrix Class 39 | #' @description An integer type matrix in the S4 \code{cudaMatrix} 40 | #' representation. 41 | #' @section Slots: 42 | #' \describe{ 43 | #' \item{\code{address}:}{A integer typed R matrix} 44 | #' } 45 | #' @name icudaMatrix-class 46 | #' @rdname icudaMatrix-class 47 | #' @author Charles Determan Jr. 48 | #' @seealso \code{\link{cudaMatrix-class}}, 49 | #' \code{\link{icudaMatrix-class}}, 50 | #' \code{\link{dcudaMatrix-class}} 51 | #' @export 52 | setClass("icudaMatrix", 53 | contains = "cudaMatrix", 54 | validity = function(object) { 55 | if( typeof(object) != "integer"){ 56 | return("icudaMatrix must be of type 'integer'") 57 | } 58 | TRUE 59 | }) 60 | 61 | #' @title fcudaMatrix Class 62 | #' @description An integer type matrix in the S4 \code{cudaMatrix} 63 | #' representation. 64 | #' @section Slots: 65 | #' \describe{ 66 | #' \item{\code{address}:}{A numeric R matrix.} 67 | #' } 68 | #' @name fcudaMatrix-class 69 | #' @rdname fcudaMatrix-class 70 | #' @author Charles Determan Jr. 71 | #' @seealso \code{\link{cudaMatrix-class}}, 72 | #' \code{\link{icudaMatrix-class}}, 73 | #' \code{\link{dcudaMatrix-class}} 74 | #' @export 75 | setClass("fcudaMatrix", 76 | contains = "cudaMatrix") 77 | 78 | 79 | #' @title dcudaMatrix Class 80 | #' @description An integer type matrix in the S4 \code{cudaMatrix} 81 | #' representation. 82 | #' @section Slots: 83 | #' \describe{ 84 | #' \item{\code{address}:}{A numeric R matrix} 85 | #' } 86 | #' @name dcudaMatrix-class 87 | #' @rdname dcudaMatrix-class 88 | #' @author Charles Determan Jr. 89 | #' @seealso \code{\link{cudaMatrix-class}}, 90 | #' \code{\link{icudaMatrix-class}}, 91 | #' \code{\link{fcudaMatrix-class}} 92 | #' @export 93 | setClass("dcudaMatrix", 94 | contains = "cudaMatrix" 95 | ) 96 | -------------------------------------------------------------------------------- /R/wrappers.R: -------------------------------------------------------------------------------- 1 | #' @useDynLib gpuRcuda 2 | #' @importFrom Rcpp evalCpp 3 | #' @import methods 4 | NULL 5 | 6 | # cuda_colSums <- function(A){ 7 | # 8 | # type <- typeof(A) 9 | # 10 | # if(type == "integer"){ 11 | # stop("integer type not currently implemented") 12 | # } 13 | # 14 | # sums <- cudaVector(length = ncol(A), type = type) 15 | # 16 | # switch(type, 17 | # "integer" = stop("integer type not currently implemented"), 18 | # "float" = cpp_vienna_cudaMatrix_scolsum(A@address, sums@address), 19 | # "double" = cpp_vienna_cudaMatrix_dcolsum(A@address, sums@address) 20 | # ) 21 | # 22 | # return(sums) 23 | # } 24 | # 25 | # cuda_rowSums <- function(A){ 26 | # 27 | # type <- typeof(A) 28 | # 29 | # if(type == "integer"){ 30 | # stop("integer type not currently implemented") 31 | # } 32 | # 33 | # sums <- cudaVector(length = nrow(A), type = type) 34 | # 35 | # switch(type, 36 | # "integer" = stop("integer type not currently implemented"), 37 | # "float" = cpp_vienna_cudaMatrix_sRowSum(A@address, sums@address), 38 | # "double" = cpp_vienna_cudaMatrix_dRowSum(A@address, sums@address) 39 | # ) 40 | # 41 | # return(sums) 42 | # } 43 | # 44 | # 45 | # cuda_colMeans <- function(A){ 46 | # 47 | # type <- typeof(A) 48 | # 49 | # if(type == "integer"){ 50 | # stop("integer type not currently implemented") 51 | # } 52 | # 53 | # means <- cudaVector(length = ncol(A), type = type) 54 | # 55 | # switch(type, 56 | # "integer" = stop("integer type not currently implemented"), 57 | # "float" = cpp_vienna_cudaMatrix_sColMean(A@address, means@address), 58 | # "double" = cpp_vienna_cudaMatrix_dColMean(A@address, means@address) 59 | # ) 60 | # 61 | # return(means) 62 | # } 63 | # 64 | # cuda_rowMeans <- function(A){ 65 | # 66 | # type <- typeof(A) 67 | # 68 | # if(type == "integer"){ 69 | # stop("integer type not currently implemented") 70 | # } 71 | # 72 | # means <- cudaVector(length = nrow(A), type = type) 73 | # 74 | # switch(type, 75 | # "integer" = stop("integer type not currently implemented"), 76 | # "float" = cpp_vienna_cudaMatrix_sRowMean(A@address, means@address), 77 | # "double" = cpp_vienna_cudaMatrix_dRowMean(A@address, means@address) 78 | # ) 79 | # 80 | # return(means) 81 | # } 82 | # 83 | # # Matrix Multiplication 84 | # gpu_Mat_mult <- function(A, B){ 85 | # 86 | # type <- typeof(A) 87 | # 88 | # C <- cudaMatrix(nrow=nrow(A), ncol=ncol(B), type=type) 89 | # 90 | # switch(type, 91 | # integer = {stop("integer not currently implemented")}, 92 | # float = {cpp_vienna_cudaMatrix_sgemm(A@address, 93 | # B@address, 94 | # C@address) 95 | # }, 96 | # double = { 97 | # if(!deviceHasDouble()){ 98 | # stop("Selected GPU does not support double precision") 99 | # }else{cpp_vienna_cudaMatrix_dgemm(A@address, 100 | # B@address, 101 | # C@address) 102 | # } 103 | # }, 104 | # { 105 | # stop("type not recognized") 106 | # }) 107 | # 108 | # return(C) 109 | # } 110 | -------------------------------------------------------------------------------- /tests/testthat/test_cudaMatrix_row_col.R: -------------------------------------------------------------------------------- 1 | # library(gpuRcuda) 2 | # context("cudaMatrix Row and Column Methods") 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 | # R <- rowSums(A) 14 | # C <- colSums(A) 15 | # RM <- rowMeans(A) 16 | # CM <- colMeans(A) 17 | # 18 | # 19 | # test_that("cudaMatrix Single Precision Column Sums", 20 | # { 21 | # 22 | # has_gpu_skip() 23 | # 24 | # fgpuX <- cudaMatrix(A, type="float") 25 | # 26 | # gpuC <- colSums(fgpuX) 27 | # 28 | # expect_is(gpuC, "fcudaVector") 29 | # expect_equal(gpuC[], C, tolerance=1e-06, 30 | # info="float colSums not equivalent") 31 | # }) 32 | # 33 | # test_that("cudaMatrix Double Precision Column Sums", 34 | # { 35 | # 36 | # has_gpu_skip() 37 | # has_double_skip() 38 | # 39 | # dgpuX <- cudaMatrix(A, type="double") 40 | # 41 | # gpuC <- colSums(dgpuX) 42 | # 43 | # expect_is(gpuC, "dcudaVector") 44 | # expect_equal(gpuC[], C, tolerance=.Machine$double.eps ^ 0.5, 45 | # info="double colSums not equivalent") 46 | # }) 47 | # 48 | # 49 | # test_that("cudaMatrix Single Precision Row Sums", 50 | # { 51 | # 52 | # has_gpu_skip() 53 | # 54 | # fgpuX <- cudaMatrix(A, type="float") 55 | # 56 | # gpuC <- rowSums(fgpuX) 57 | # 58 | # expect_is(gpuC, "fcudaVector") 59 | # expect_equal(gpuC[], R, tolerance=1e-06, 60 | # info="float rowSums values not equivalent") 61 | # }) 62 | # 63 | # test_that("cudaMatrix Double Precision Row Sums", 64 | # { 65 | # 66 | # has_gpu_skip() 67 | # has_double_skip() 68 | # 69 | # dgpuX <- cudaMatrix(A, type="double") 70 | # 71 | # gpuC <- rowSums(dgpuX) 72 | # 73 | # expect_is(gpuC, "dcudaVector") 74 | # expect_equal(gpuC[], R, tolerance=.Machine$double.eps ^ 0.5, 75 | # info="double rowSums not equivalent") 76 | # }) 77 | # 78 | # test_that("cudaMatrix Single Precision Column Means", 79 | # { 80 | # 81 | # has_gpu_skip() 82 | # 83 | # fgpuX <- cudaMatrix(A, type="float") 84 | # 85 | # gpuC <- colMeans(fgpuX) 86 | # 87 | # expect_is(gpuC, "fcudaVector") 88 | # expect_equal(gpuC[], CM, tolerance=1e-06, 89 | # info="float colMeans values not equivalent") 90 | # }) 91 | # 92 | # test_that("cudaMatrix Double Precision Column Means", 93 | # { 94 | # 95 | # has_gpu_skip() 96 | # has_double_skip() 97 | # 98 | # dgpuX <- cudaMatrix(A, type="double") 99 | # 100 | # gpuC <- colMeans(dgpuX) 101 | # 102 | # expect_is(gpuC, "dcudaVector") 103 | # expect_equal(gpuC[], CM, tolerance=.Machine$double.eps ^ 0.5, 104 | # info="double colMeans not equivalent") 105 | # }) 106 | # 107 | # 108 | # test_that("cudaMatrix Single Precision Row Means", 109 | # { 110 | # 111 | # has_gpu_skip() 112 | # 113 | # fgpuX <- cudaMatrix(A, type="float") 114 | # 115 | # gpuC <- rowMeans(fgpuX) 116 | # 117 | # expect_is(gpuC, "fcudaVector") 118 | # expect_equal(gpuC[], RM, tolerance=1e-06, 119 | # info="float rowMeans not equivalent") 120 | # }) 121 | # 122 | # test_that("cudaMatrix Double Precision Row Means", 123 | # { 124 | # 125 | # has_gpu_skip() 126 | # has_double_skip() 127 | # 128 | # dgpuX <- cudaMatrix(A, type="double") 129 | # 130 | # gpuC <- rowMeans(dgpuX) 131 | # 132 | # expect_is(gpuC, "dcudaVector") 133 | # expect_equal(gpuC[], RM, tolerance=.Machine$double.eps ^ 0.5, 134 | # info="double rowMeans not equivalent") 135 | # }) 136 | -------------------------------------------------------------------------------- /tests/testthat/test_nvMatrix.R: -------------------------------------------------------------------------------- 1 | library(gpuRcuda) 2 | context("nvMatrix class") 3 | 4 | # set seed 5 | set.seed(123) 6 | 7 | ORDER <- 4 8 | 9 | # Base R objects 10 | Aint <- matrix(sample(seq(10), ORDER^2, replace=TRUE), nrow=ORDER, ncol=ORDER) 11 | Bint <- matrix(sample(seq(10), ORDER^2, replace=TRUE), nrow=ORDER, ncol=ORDER) 12 | A <- matrix(rnorm(ORDER^2), nrow=ORDER, ncol=ORDER) 13 | B <- matrix(rnorm(ORDER^2), nrow=ORDER, ncol=ORDER) 14 | 15 | 16 | test_that("typeof not working correctly", { 17 | fgpuA <- nvMatrix(A, type="double") 18 | expect_equal(typeof(fgpuA), "double") 19 | }) 20 | 21 | 22 | test_that("dim not working correctly", { 23 | fgpuA <- nvMatrix(A, type="double") 24 | expect_equal(dim(fgpuA), dim(A)) 25 | }) 26 | 27 | test_that("empty initialization failed", { 28 | fgpuA <- nvMatrix(nrow = 4, ncol = 4, type = "double") 29 | expect_equivalent(fgpuA[], matrix(0, nrow = 4, ncol = 4), 30 | tolerance = .Machine$double.eps ^ 0.5, 31 | info = "double matrix elements not equivalent") 32 | }) 33 | 34 | test_that("double matrix values not returned correctly",{ 35 | fgpuA <- nvMatrix(A, type = "double") 36 | expect_equivalent(fgpuA[], A, tolerance=.Machine$double.eps ^ 0.5, 37 | info="double matrix elements not equivalent") 38 | }) 39 | 40 | # test_that("nvMatrix Single Precision Matrix multiplication successful", { 41 | # 42 | # has_gpu_skip() 43 | # 44 | # C <- A %*% B 45 | # 46 | # fgpuA <- nvMatrix(A, type="float") 47 | # fgpuB <- nvMatrix(B, type="float") 48 | # 49 | # fgpuC <- fgpuA %*% fgpuB 50 | # 51 | # expect_is(fgpuC, "fnvMatrix") 52 | # expect_equal(fgpuC[,], C, tolerance=1e-07, 53 | # info="double matrix elements not equivalent") 54 | # }) 55 | # 56 | # test_that("nvMatrix Double Precision Matrix multiplication successful", { 57 | # 58 | # has_gpu_skip() 59 | # has_double_skip() 60 | # 61 | # C <- A %*% B 62 | # 63 | # dgpuA <- nvMatrix(A, type="double") 64 | # dgpuB <- nvMatrix(B, type="double") 65 | # 66 | # dgpuC <- dgpuA %*% dgpuB 67 | # 68 | # expect_is(dgpuC, "dnvMatrix") 69 | # expect_equal(dgpuC[,], C, tolerance=.Machine$double.eps ^ 0.5, 70 | # info="double matrix elements not equivalent") 71 | # }) 72 | # 73 | # 74 | # test_that("nvMatrix Single Precision Matrix Subtraction successful", { 75 | # 76 | # has_gpu_skip() 77 | # 78 | # C <- A - B 79 | # 80 | # fgpuA <- nvMatrix(A, type="float") 81 | # fgpuB <- nvMatrix(B, type="float") 82 | # 83 | # fgpuC <- fgpuA - fgpuB 84 | # 85 | # expect_is(fgpuC, "fnvMatrix") 86 | # expect_equal(fgpuC[,], C, tolerance=1e-07, 87 | # info="float matrix elements not equivalent") 88 | # }) 89 | # 90 | # test_that("nvMatrix Single Precision Matrix Addition successful", { 91 | # 92 | # has_gpu_skip() 93 | # 94 | # C <- A + B 95 | # 96 | # fgpuA <- nvMatrix(A, type="float") 97 | # fgpuB <- nvMatrix(B, type="float") 98 | # 99 | # fgpuC <- fgpuA + fgpuB 100 | # 101 | # expect_is(fgpuC, "fnvMatrix") 102 | # expect_equal(fgpuC[,], C, tolerance=1e-07, 103 | # info="float matrix elements not equivalent") 104 | # }) 105 | # 106 | # 107 | # test_that("CUDA nvMatrix Double Precision Matrix Subtraction successful", { 108 | # 109 | # has_gpu_skip() 110 | # has_double_skip() 111 | # 112 | # C <- A - B 113 | # 114 | # dgpuA <- nvMatrix(A, type="double") 115 | # dgpuB <- nvMatrix(B, type="double") 116 | # 117 | # dgpuC <- dgpuA - dgpuB 118 | # 119 | # expect_is(dgpuC, "dnvMatrix") 120 | # expect_equal(dgpuC[,], C, tolerance=.Machine$double.eps ^ 0.5, 121 | # info="double matrix elements not equivalent") 122 | # }) 123 | # 124 | # test_that("CUDA nvMatrix Double Precision Matrix Addition successful", { 125 | # 126 | # has_gpu_skip() 127 | # has_double_skip() 128 | # 129 | # C <- A + B 130 | # 131 | # dgpuA <- nvMatrix(A, type="double") 132 | # dgpuB <- nvMatrix(B, type="double") 133 | # 134 | # dgpuC <- dgpuA + dgpuB 135 | # 136 | # expect_is(dgpuC, "dnvMatrix") 137 | # expect_equal(dgpuC[,], C, tolerance=.Machine$double.eps ^ 0.5, 138 | # info="double matrix elements not equivalent") 139 | # }) 140 | -------------------------------------------------------------------------------- /tests/testthat/test_cudaMatrix.R: -------------------------------------------------------------------------------- 1 | library(gpuRcuda) 2 | context("cudaMatrix class") 3 | 4 | # set seed 5 | set.seed(123) 6 | 7 | ORDER <- 4 8 | 9 | # Base R objects 10 | Aint <- matrix(sample(seq(10), ORDER^2, replace=TRUE), nrow=ORDER, ncol=ORDER) 11 | Bint <- matrix(sample(seq(10), ORDER^2, replace=TRUE), nrow=ORDER, ncol=ORDER) 12 | A <- matrix(rnorm(ORDER^2), nrow=ORDER, ncol=ORDER) 13 | B <- matrix(rnorm(ORDER^2), nrow=ORDER, ncol=ORDER) 14 | 15 | 16 | test_that("typeof not working correctly", { 17 | fgpuA <- cudaMatrix(A, type="double") 18 | expect_equal(typeof(fgpuA), "double") 19 | }) 20 | 21 | 22 | test_that("dim not working correctly", { 23 | fgpuA <- cudaMatrix(A, type="double") 24 | expect_equal(dim(fgpuA), dim(A)) 25 | }) 26 | 27 | test_that("empty initialization failed", { 28 | fgpuA <- cudaMatrix(nrow = 4, ncol = 4, type = "double") 29 | expect_equivalent(fgpuA[], matrix(0, nrow = 4, ncol = 4), 30 | tolerance = .Machine$double.eps ^ 0.5, 31 | info = "double matrix elements not equivalent") 32 | }) 33 | 34 | test_that("double matrix values not returned correctly",{ 35 | fgpuA <- cudaMatrix(A, type = "double") 36 | expect_equivalent(fgpuA[], A, tolerance=.Machine$double.eps ^ 0.5, 37 | info="double matrix elements not equivalent") 38 | }) 39 | 40 | # 41 | # test_that("cudaMatrix Single Precision Matrix multiplication successful", { 42 | # 43 | # has_gpu_skip() 44 | # 45 | # C <- A %*% B 46 | # 47 | # fgpuA <- cudaMatrix(A, type="float") 48 | # fgpuB <- cudaMatrix(B, type="float") 49 | # 50 | # fgpuC <- fgpuA %*% fgpuB 51 | # 52 | # expect_is(fgpuC, "fcudaMatrix") 53 | # expect_equal(fgpuC[,], C, tolerance=1e-07, 54 | # info="double matrix elements not equivalent") 55 | # }) 56 | # 57 | # test_that("cudaMatrix Double Precision Matrix multiplication successful", { 58 | # 59 | # has_gpu_skip() 60 | # has_double_skip() 61 | # 62 | # C <- A %*% B 63 | # 64 | # dgpuA <- cudaMatrix(A, type="double") 65 | # dgpuB <- cudaMatrix(B, type="double") 66 | # 67 | # dgpuC <- dgpuA %*% dgpuB 68 | # 69 | # expect_is(dgpuC, "dcudaMatrix") 70 | # expect_equal(dgpuC[,], C, tolerance=.Machine$double.eps ^ 0.5, 71 | # info="double matrix elements not equivalent") 72 | # }) 73 | # 74 | # 75 | # test_that("cudaMatrix Single Precision Matrix Subtraction successful", { 76 | # 77 | # has_gpu_skip() 78 | # 79 | # C <- A - B 80 | # 81 | # fgpuA <- cudaMatrix(A, type="float") 82 | # fgpuB <- cudaMatrix(B, type="float") 83 | # 84 | # fgpuC <- fgpuA - fgpuB 85 | # 86 | # expect_is(fgpuC, "fcudaMatrix") 87 | # expect_equal(fgpuC[,], C, tolerance=1e-07, 88 | # info="float matrix elements not equivalent") 89 | # }) 90 | # 91 | # test_that("cudaMatrix Single Precision Matrix Addition successful", { 92 | # 93 | # has_gpu_skip() 94 | # 95 | # C <- A + B 96 | # 97 | # fgpuA <- cudaMatrix(A, type="float") 98 | # fgpuB <- cudaMatrix(B, type="float") 99 | # 100 | # fgpuC <- fgpuA + fgpuB 101 | # 102 | # expect_is(fgpuC, "fcudaMatrix") 103 | # expect_equal(fgpuC[,], C, tolerance=1e-07, 104 | # info="float matrix elements not equivalent") 105 | # }) 106 | # 107 | # 108 | # test_that("CUDA cudaMatrix Double Precision Matrix Subtraction successful", { 109 | # 110 | # has_gpu_skip() 111 | # has_double_skip() 112 | # 113 | # C <- A - B 114 | # 115 | # dgpuA <- cudaMatrix(A, type="double") 116 | # dgpuB <- cudaMatrix(B, type="double") 117 | # 118 | # dgpuC <- dgpuA - dgpuB 119 | # 120 | # expect_is(dgpuC, "dcudaMatrix") 121 | # expect_equal(dgpuC[,], C, tolerance=.Machine$double.eps ^ 0.5, 122 | # info="double matrix elements not equivalent") 123 | # }) 124 | # 125 | # test_that("CUDA cudaMatrix Double Precision Matrix Addition successful", { 126 | # 127 | # has_gpu_skip() 128 | # has_double_skip() 129 | # 130 | # C <- A + B 131 | # 132 | # dgpuA <- cudaMatrix(A, type="double") 133 | # dgpuB <- cudaMatrix(B, type="double") 134 | # 135 | # dgpuC <- dgpuA + dgpuB 136 | # 137 | # expect_is(dgpuC, "dcudaMatrix") 138 | # expect_equal(dgpuC[,], C, tolerance=.Machine$double.eps ^ 0.5, 139 | # info="double matrix elements not equivalent") 140 | # }) 141 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | AC_INIT([gpuRcuda], 1.0.0) 2 | 3 | AC_LANG(C++) 4 | AC_REQUIRE_CPP 5 | 6 | echo "Checking for C++ Compiler" 7 | AC_PROG_CXX 8 | 9 | GPURCUDA_CPPFLAGS="-I. -I../inst/include" 10 | GPURCUDA_CXXFLAGS="" 11 | GPURCUDA_LIBS="" 12 | 13 | if test "$BACKEND" = "OPENMP"; then 14 | 15 | AC_MSG_NOTICE("BACKEND = OPENMP") 16 | GPURCUDA_CPPFLAGS="${GPURCUDA_CPPFLAGS} -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_OMP" 17 | GPURCUDA_CXXFLAGS="${GPURCUDA_CXXFLAGS} -fopenmp" 18 | 19 | BACKEND="OPENMP" 20 | AC_SUBST(BACKEND) 21 | 22 | elif test "$BACKEND" = "CUDA"; then 23 | 24 | AC_MSG_NOTICE("BACKEND = CUDA") 25 | GPURCUDA_CPPFLAGS="${GPURCUDA_CPPFLAGS} -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CUDA" 26 | 27 | AC_MSG_CHECKING("Checking environment variable CUDA_HOME") 28 | if test -z "${CUDA_HOME}"; then 29 | CUDA_HOME=`find /usr/local/ -maxdepth 1 -type d -name "cuda*" | sort -V | tail -1` 30 | AC_MSG_RESULT("CUDA_HOME not set; using highest version found ${CUDA_HOME}") 31 | else 32 | AC_MSG_RESULT("using CUDA_HOME=${CUDA_HOME}") 33 | fi 34 | 35 | AC_CHECK_FILE([${CUDA_HOME}/bin/nvcc], [HAS_NVCC="yes"]) 36 | if test -z "${HAS_NVCC}"; then 37 | AC_MSG_ERROR("NVCC not found; check CUDA install") 38 | else 39 | AC_MSG_RESULT("NVCC found") 40 | fi 41 | 42 | AC_MSG_CHECKING("whether this is the 64 bit linux version of CUDA") 43 | AC_CHECK_FILE([${CUDA_HOME}/lib64/libcudart.so], [BIT64="yes"]) 44 | if test -z "${BIT64}"; then 45 | AC_MSG_RESULT("no -- using ${CUDA_HOME}/lib for CUDA libs") 46 | cu_libdir="${CUDA_HOME}/lib" 47 | #AC_SUBST(CUDA_LIBDIR,["$cu_libdir"]) 48 | else 49 | AC_MSG_RESULT("yes -- using ${CUDA_HOME}/lib64 for CUDA libs") 50 | cu_libdir="${CUDA_HOME}/lib64" 51 | #AC_SUBST(CUDA_LIBDIR,["$cu_libdir"]) 52 | fi 53 | 54 | GPURCUDA_LIBS="${GPURCUDA_LIBS} -L${cu_libdir} -Wl,-rpath,${cu_libdir} -lcudart" 55 | BACKEND="CUDA" 56 | AC_SUBST(BACKEND) 57 | else 58 | 59 | AC_MSG_NOTICE("No recognized BACKEND defined so trying CUDA first") 60 | 61 | AC_MSG_CHECKING("Checking environment variable CUDA_HOME") 62 | if test -z "${CUDA_HOME}"; then 63 | CUDA_HOME=`find /usr/local/ -maxdepth 1 -type d -name "cuda*" | sort -V | tail -1` 64 | fi 65 | 66 | #else 67 | # AC_MSG_RESULT("using CUDA_HOME=${CUDA_HOME}") 68 | #fi 69 | 70 | if test -z "${CUDA_HOME}"; then 71 | AC_MSG_RESULT("No CUDA installation found, attempting OPENMP install") 72 | GPURCUDA_CPPFLAGS="${GPURCUDA_CPPFLAGS} -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_OMP" 73 | GPURCUDA_CXXFLAGS="${CXXFLAGS} -fopenmp" 74 | BACKEND="OPENMP" 75 | AC_SUBST(BACKEND) 76 | 77 | else 78 | AC_MSG_RESULT("using CUDA_HOME=${CUDA_HOME}") 79 | #AC_MSG_RESULT("CUDA_HOME not set; using highest version found ${CUDA_HOME}") 80 | 81 | AC_CHECK_FILE([${CUDA_HOME}/bin/nvcc], [HAS_NVCC="yes"]) 82 | if test -z "${HAS_NVCC}"; then 83 | AC_MSG_ERROR("NVCC not found; check CUDA install") 84 | else 85 | AC_MSG_RESULT("NVCC found") 86 | fi 87 | 88 | AC_MSG_CHECKING("whether this is the 64 bit linux version of CUDA") 89 | AC_CHECK_FILE([${CUDA_HOME}/lib64/libcudart.so], [BIT64="yes"]) 90 | if test -z "${BIT64}"; then 91 | AC_MSG_RESULT("no -- using ${CUDA_HOME}/lib for CUDA libs") 92 | cu_libdir="${CUDA_HOME}/lib" 93 | #AC_SUBST(CUDA_LIBDIR,["$cu_libdir"]) 94 | else 95 | AC_MSG_RESULT("yes -- using ${CUDA_HOME}/lib64 for CUDA libs") 96 | cu_libdir="${CUDA_HOME}/lib64" 97 | #AC_SUBST(CUDA_LIBDIR,["$cu_libdir"]) 98 | fi 99 | 100 | GPURCUDA_LIBS="${GPURCUDA_LIBS} -L${cu_libdir} -Wl,-rpath,${cu_libdir} -lcudart" 101 | BACKEND="CUDA" 102 | AC_SUBST(BACKEND) 103 | 104 | fi 105 | 106 | fi 107 | 108 | ## look for Rscript, but use the one found via R_HOME to allow for multiple installations 109 | AC_DEFUN([AC_PROG_RSCRIPT], [AC_CHECK_PROG(RSCRIPT,Rscript,yes)]) 110 | AC_PROG_RSCRIPT 111 | 112 | if test x"${RSCRIPT}" == x"yes" ; then 113 | 114 | R_HOME=`Rscript -e 'cat(R.home())'` 115 | 116 | rcpp_incl=`${R_HOME}/bin/Rscript -e 'Rcpp:::CxxFlags()'` 117 | thrust_incl=`${R_HOME}/bin/Rscript -e 'cat(paste("-I", system.file("include", package = "thrust"), sep = ""))'` 118 | AC_SUBST(RCPP_INCL,["$rcpp_incl"]) 119 | AC_SUBST(THRUST_INCL,["$thrust_incl"]) 120 | else 121 | echo " 122 | Your installation does not appear to have Rscript installed. 123 | 124 | Please make sure that you have a working and complete R installation. 125 | " 126 | exit 1 127 | fi 128 | 129 | R_INCL=`"${R_HOME}/bin/R" CMD config --cppflags` 130 | R_LIBS=`"${R_HOME}/bin/R" CMD config --ldflags` 131 | R_CPIC=`"${R_HOME}/bin/R" CMD config CPICFLAGS` 132 | 133 | 134 | 135 | 136 | AC_MSG_CHECKING("building the nvcc command line") 137 | NVCC="${CUDA_HOME}/bin/nvcc" 138 | 139 | AC_MSG_NOTICE([Building Makevars]) 140 | AC_SUBST(GPURCUDA_CPPFLAGS) 141 | AC_SUBST(GPURCUDA_CXXFLAGS) 142 | AC_SUBST(CU_INCL) 143 | AC_SUBST(NVCC) 144 | AC_SUBST(R_INCL) 145 | AC_SUBST(R_CPIC) 146 | AC_SUBST(R_LIBS) 147 | AC_SUBST(GPURCUDA_LIBS) 148 | AC_OUTPUT(src/Makevars) 149 | -------------------------------------------------------------------------------- /R/methods.R: -------------------------------------------------------------------------------- 1 | 2 | # Currently separate methods until integer methods 3 | # written in CUDA, then will consolidate 4 | # This separate allows for using the parent gpuR methods 5 | # Note - when consolidating will need to make sure to import typeof from gpuR 6 | 7 | 8 | 9 | 10 | #' Single Precision CUDA Matrix Addition/Subtraction 11 | #' @param e1 An fcudaMatrix object 12 | #' @param e2 An fcudaMatrix object 13 | #' @export 14 | setMethod("Arith", c(e1="fcudaMatrix", e2="fcudaMatrix"), 15 | function(e1, e2) 16 | { 17 | Z <- cudaMatrix(nrow=nrow(e1), ncol=ncol(e2), type="float") 18 | if(length(e2[]) != length(e1[])) stop("Lengths of matrices must match") 19 | Z@address <- e1@address 20 | 21 | op = .Generic[[1]] 22 | 23 | switch(op, 24 | `+` = cpp_vienna_cudaMatrix_saxpy(1, 25 | Z@address, 26 | e2@address), 27 | `-` = cpp_vienna_cudaMatrix_saxpy(-1, 28 | Z@address, 29 | e2@address), 30 | { 31 | stop("undefined operation") 32 | } 33 | ) 34 | 35 | return(Z) 36 | }, 37 | valueClass = "fcudaMatrix" 38 | ) 39 | 40 | #' Double Precision CUDA Matrix Addition/Subtraction 41 | #' @param e1 An dcudaMatrix object 42 | #' @param e2 An dcudaMatrix object 43 | #' @export 44 | setMethod("Arith", c(e1="dcudaMatrix", e2="dcudaMatrix"), 45 | function(e1, e2) 46 | { 47 | if(!deviceHasDouble()){ 48 | stop("Selected GPU does not support double precision") 49 | }else{ 50 | op = .Generic[[1]] 51 | 52 | Z <- cudaMatrix(nrow=nrow(e1), ncol=ncol(e2), type="double") 53 | 54 | if(length(e2[]) != length(e1[])) stop("Lengths of matrices must match") 55 | Z@address <- e1@address 56 | 57 | op = .Generic[[1]] 58 | 59 | switch(op, 60 | `+` = cpp_vienna_cudaMatrix_daxpy(1, 61 | Z@address, 62 | e2@address), 63 | `-` = cpp_vienna_cudaMatrix_daxpy(-1, 64 | Z@address, 65 | e2@address), 66 | { 67 | stop("undefined operation") 68 | } 69 | ) 70 | return(Z) 71 | } 72 | }, 73 | valueClass = "dcudaMatrix" 74 | ) 75 | 76 | 77 | #' CUDA Matrix Multiplication 78 | #' @param x An fcudaMatrix object 79 | #' @param y An fcudaMatrix object 80 | #' @export 81 | setMethod("%*%", signature(x="cudaMatrix", y = "cudaMatrix"), 82 | function(x,y) 83 | { 84 | if( dim(x)[2] != dim(y)[1]){ 85 | stop("Non-conformant matrices") 86 | } 87 | return(gpu_Mat_mult(x, y)) 88 | }, 89 | valueClass = "cudaMatrix" 90 | ) 91 | 92 | 93 | #' @title Row and Column Sums and Means of cudaMatrix 94 | #' @description Row and column sums and of cudaMatrix objects 95 | #' @param x A cudaMatrix object 96 | #' @param na.rm Not currently used 97 | #' @param dims Not currently used 98 | #' @return A cudaVector object 99 | #' @author Charles Determan Jr. 100 | #' @docType methods 101 | #' @rdname cudaMatrix-colSums 102 | #' @aliases colSums,cudaMatrix 103 | #' @export 104 | setMethod("colSums", 105 | signature(x = "cudaMatrix", na.rm = "missing", dims = "missing"), 106 | function(x, na.rm, dims){ 107 | cuda_colSums(x) 108 | }) 109 | 110 | #' @rdname cudaMatrix-colSums 111 | #' @export 112 | setMethod("rowSums", 113 | signature(x = "cudaMatrix", na.rm = "missing", dims = "missing"), 114 | function(x, na.rm, dims){ 115 | cuda_rowSums(x) 116 | }) 117 | 118 | #' @rdname cudaMatrix-colSums 119 | #' @export 120 | setMethod("colMeans", 121 | signature(x = "cudaMatrix", na.rm = "missing", dims = "missing"), 122 | function(x, na.rm, dims){ 123 | cuda_colMeans(x) 124 | }) 125 | 126 | #' @rdname cudaMatrix-colSums 127 | #' @export 128 | setMethod("rowMeans", 129 | signature(x = "cudaMatrix", na.rm = "missing", dims = "missing"), 130 | function(x, na.rm, dims){ 131 | cuda_rowMeans(x) 132 | }) 133 | 134 | #' @title The Number of Rows/Columns of a gpuRcudaMatrix 135 | #' @description \code{nrow} and \code{ncol} return the number of rows 136 | #' or columns present in \code{x}. 137 | #' @param x A gpuRcudaMatrix object 138 | #' @return An integer of length 1 139 | #' @docType methods 140 | #' @rdname nrow-gpuRcudaMatrix 141 | #' @aliases nrow,cudaMatrix 142 | #' @aliases nrow,nvMatrix 143 | #' @aliases ncol,cudaMatrix 144 | #' @aliases ncol,nvMatrix 145 | #' @author Charles Determan Jr. 146 | #' @export 147 | setMethod('nrow', signature(x="gpuRcudaMatrix"), 148 | function(x) { 149 | switch(typeof(x), 150 | "integer" = return(cpp_nrow(x@address, 4L)), 151 | "float" = return(cpp_nrow(x@address, 6L)), 152 | "double" = return(cpp_nrow(x@address, 8L)) 153 | ) 154 | } 155 | ) 156 | 157 | #' @rdname nrow-gpuRcudaMatrix 158 | #' @export 159 | setMethod('ncol', signature(x="gpuRcudaMatrix"), 160 | function(x) { 161 | switch(typeof(x), 162 | "integer" = return(cpp_ncol(x@address, 4L)), 163 | "float" = return(cpp_ncol(x@address, 6L)), 164 | "double" = return(cpp_ncol(x@address, 8L)) 165 | ) 166 | } 167 | ) 168 | 169 | 170 | #' @title gpuRcuda dim method 171 | #' @param x A gpuRcuda matrix object 172 | #' @return A length 2 vector of the number of rows and columns respectively. 173 | #' @docType methods 174 | #' @rdname dim-methods 175 | #' @author Charles Determan Jr. 176 | #' @aliases dim,cudaMatrix 177 | #' @aliases dim,nvMatrix 178 | #' @export 179 | setMethod('dim', signature(x="gpuRcudaMatrix"), 180 | function(x) return(c(nrow(x), ncol(x)))) 181 | 182 | #' @title Extract gpuRcuda elements 183 | #' @param x A gpuRcuda object 184 | #' @param i missing 185 | #' @param j missing 186 | #' @param drop missing 187 | #' @docType methods 188 | #' @rdname extract-methods 189 | #' @author Charles Determan Jr. 190 | #' @export 191 | setMethod("[", 192 | signature(x = "cudaMatrix", i = "missing", j = "missing", drop = "missing"), 193 | function(x, i, j, drop) { 194 | 195 | init <- ifelse(typeof(x) == "double", 0, 0L) 196 | out <- matrix(init, nrow = nrow(x), ncol = ncol(x)) 197 | 198 | switch(typeof(x), 199 | "integer" = { 200 | cudaMatToSEXP(x@address, out, 4L) 201 | return(out) 202 | }, 203 | "float" = { 204 | cudaMatToSEXP(x@address, out, 6L) 205 | return(out) 206 | }, 207 | "double" = { 208 | cudaMatToSEXP(x@address, out, 8L) 209 | return(out) 210 | } 211 | ) 212 | }) 213 | 214 | #' @rdname extract-methods 215 | #' @export 216 | setMethod("[", 217 | signature(x = "nvMatrix", i = "missing", j = "missing", drop = "missing"), 218 | function(x, i, j, drop) { 219 | 220 | init <- ifelse(typeof(x) == "double", 0, 0L) 221 | out <- matrix(init, nrow = nrow(x), ncol = ncol(x)) 222 | 223 | switch(typeof(x), 224 | "integer" = { 225 | nvMatToSEXP(x@address, out, 4L) 226 | return(out) 227 | }, 228 | "float" = { 229 | nvMatToSEXP(x@address, out, 6L) 230 | return(out) 231 | }, 232 | "double" = { 233 | nvMatToSEXP(x@address, out, 8L) 234 | return(out) 235 | } 236 | ) 237 | }) 238 | 239 | # #' Single Precision CUDA Matrix Multiplication 240 | # #' @param x An fcudaMatrix object 241 | # #' @param y An fcudaMatrix object 242 | # #' @export 243 | # setMethod("%*%", signature(x="fcudaMatrix", y = "fcudaMatrix"), 244 | # function(x,y) 245 | # { 246 | # if( dim(x)[2] != dim(y)[1]){ 247 | # stop("Non-conformant matrices") 248 | # } 249 | # 250 | # C <- cudaMatrix(nrow=nrow(x), ncol=ncol(y), type="float") 251 | # 252 | # cpp_vienna_cudaMatrix_sgemm(x@address, 253 | # y@address, 254 | # C@address) 255 | # 256 | # return(C) 257 | # }, 258 | # valueClass = "fcudaMatrix" 259 | # ) 260 | # 261 | # #' Double Precision CUDA Matrix Multiplication 262 | # #' @param x An fcudaMatrix object 263 | # #' @param y An fcudaMatrix object 264 | # #' @export 265 | # setMethod("%*%", signature(x="cudaMatrix", y = "cudaMatrix"), 266 | # function(x,y) 267 | # { 268 | # if( dim(x)[2] != dim(y)[1]){ 269 | # stop("Non-conformant matrices") 270 | # } 271 | # 272 | # if(!deviceHasDouble()){ 273 | # stop("Selected GPU does not support double precision") 274 | # }else{ 275 | # C <- cudaMatrix(nrow=nrow(x), ncol=ncol(y), type="double") 276 | # 277 | # cpp_vienna_cudaMatrix_dgemm(x@address, 278 | # y@address, 279 | # C@address) 280 | # } 281 | # 282 | # return(C) 283 | # }, 284 | # valueClass = "dcudaMatrix" 285 | # ) -------------------------------------------------------------------------------- /src/RcppExports.cpp: -------------------------------------------------------------------------------- 1 | // Generated by using Rcpp::compileAttributes() -> do not edit by hand 2 | // Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 3 | 4 | #include 5 | 6 | using namespace Rcpp; 7 | 8 | // sexpToDeviceMatrix 9 | SEXP sexpToDeviceMatrix(SEXP x, int nr, int nc, const int type_flag); 10 | RcppExport SEXP _gpuRcuda_sexpToDeviceMatrix(SEXP xSEXP, SEXP nrSEXP, SEXP ncSEXP, SEXP type_flagSEXP) { 11 | BEGIN_RCPP 12 | Rcpp::RObject rcpp_result_gen; 13 | Rcpp::RNGScope rcpp_rngScope_gen; 14 | Rcpp::traits::input_parameter< SEXP >::type x(xSEXP); 15 | Rcpp::traits::input_parameter< int >::type nr(nrSEXP); 16 | Rcpp::traits::input_parameter< int >::type nc(ncSEXP); 17 | Rcpp::traits::input_parameter< const int >::type type_flag(type_flagSEXP); 18 | rcpp_result_gen = Rcpp::wrap(sexpToDeviceMatrix(x, nr, nc, type_flag)); 19 | return rcpp_result_gen; 20 | END_RCPP 21 | } 22 | // cudaMatToSEXP 23 | void cudaMatToSEXP(SEXP ptrA, SEXP x, const int type_flag); 24 | RcppExport SEXP _gpuRcuda_cudaMatToSEXP(SEXP ptrASEXP, SEXP xSEXP, SEXP type_flagSEXP) { 25 | BEGIN_RCPP 26 | Rcpp::RNGScope rcpp_rngScope_gen; 27 | Rcpp::traits::input_parameter< SEXP >::type ptrA(ptrASEXP); 28 | Rcpp::traits::input_parameter< SEXP >::type x(xSEXP); 29 | Rcpp::traits::input_parameter< const int >::type type_flag(type_flagSEXP); 30 | cudaMatToSEXP(ptrA, x, type_flag); 31 | return R_NilValue; 32 | END_RCPP 33 | } 34 | // cudaMatEmtpy 35 | SEXP cudaMatEmtpy(int nr, int nc, const int type_flag); 36 | RcppExport SEXP _gpuRcuda_cudaMatEmtpy(SEXP nrSEXP, SEXP ncSEXP, SEXP type_flagSEXP) { 37 | BEGIN_RCPP 38 | Rcpp::RObject rcpp_result_gen; 39 | Rcpp::RNGScope rcpp_rngScope_gen; 40 | Rcpp::traits::input_parameter< int >::type nr(nrSEXP); 41 | Rcpp::traits::input_parameter< int >::type nc(ncSEXP); 42 | Rcpp::traits::input_parameter< const int >::type type_flag(type_flagSEXP); 43 | rcpp_result_gen = Rcpp::wrap(cudaMatEmtpy(nr, nc, type_flag)); 44 | return rcpp_result_gen; 45 | END_RCPP 46 | } 47 | // sexpToDeviceVector 48 | SEXP sexpToDeviceVector(SEXP x, int size, const int type_flag); 49 | RcppExport SEXP _gpuRcuda_sexpToDeviceVector(SEXP xSEXP, SEXP sizeSEXP, SEXP type_flagSEXP) { 50 | BEGIN_RCPP 51 | Rcpp::RObject rcpp_result_gen; 52 | Rcpp::RNGScope rcpp_rngScope_gen; 53 | Rcpp::traits::input_parameter< SEXP >::type x(xSEXP); 54 | Rcpp::traits::input_parameter< int >::type size(sizeSEXP); 55 | Rcpp::traits::input_parameter< const int >::type type_flag(type_flagSEXP); 56 | rcpp_result_gen = Rcpp::wrap(sexpToDeviceVector(x, size, type_flag)); 57 | return rcpp_result_gen; 58 | END_RCPP 59 | } 60 | // cudaVecToSEXP 61 | void cudaVecToSEXP(SEXP ptrA, SEXP x, const int type_flag); 62 | RcppExport SEXP _gpuRcuda_cudaVecToSEXP(SEXP ptrASEXP, SEXP xSEXP, SEXP type_flagSEXP) { 63 | BEGIN_RCPP 64 | Rcpp::RNGScope rcpp_rngScope_gen; 65 | Rcpp::traits::input_parameter< SEXP >::type ptrA(ptrASEXP); 66 | Rcpp::traits::input_parameter< SEXP >::type x(xSEXP); 67 | Rcpp::traits::input_parameter< const int >::type type_flag(type_flagSEXP); 68 | cudaVecToSEXP(ptrA, x, type_flag); 69 | return R_NilValue; 70 | END_RCPP 71 | } 72 | // cudaVecEmpty 73 | SEXP cudaVecEmpty(int size, const int type_flag); 74 | RcppExport SEXP _gpuRcuda_cudaVecEmpty(SEXP sizeSEXP, SEXP type_flagSEXP) { 75 | BEGIN_RCPP 76 | Rcpp::RObject rcpp_result_gen; 77 | Rcpp::RNGScope rcpp_rngScope_gen; 78 | Rcpp::traits::input_parameter< int >::type size(sizeSEXP); 79 | Rcpp::traits::input_parameter< const int >::type type_flag(type_flagSEXP); 80 | rcpp_result_gen = Rcpp::wrap(cudaVecEmpty(size, type_flag)); 81 | return rcpp_result_gen; 82 | END_RCPP 83 | } 84 | // sexpToHostMatrix 85 | SEXP sexpToHostMatrix(SEXP x, int nr, int nc, const int type_flag); 86 | RcppExport SEXP _gpuRcuda_sexpToHostMatrix(SEXP xSEXP, SEXP nrSEXP, SEXP ncSEXP, SEXP type_flagSEXP) { 87 | BEGIN_RCPP 88 | Rcpp::RObject rcpp_result_gen; 89 | Rcpp::RNGScope rcpp_rngScope_gen; 90 | Rcpp::traits::input_parameter< SEXP >::type x(xSEXP); 91 | Rcpp::traits::input_parameter< int >::type nr(nrSEXP); 92 | Rcpp::traits::input_parameter< int >::type nc(ncSEXP); 93 | Rcpp::traits::input_parameter< const int >::type type_flag(type_flagSEXP); 94 | rcpp_result_gen = Rcpp::wrap(sexpToHostMatrix(x, nr, nc, type_flag)); 95 | return rcpp_result_gen; 96 | END_RCPP 97 | } 98 | // nvMatToSEXP 99 | void nvMatToSEXP(SEXP ptrA, SEXP x, const int type_flag); 100 | RcppExport SEXP _gpuRcuda_nvMatToSEXP(SEXP ptrASEXP, SEXP xSEXP, SEXP type_flagSEXP) { 101 | BEGIN_RCPP 102 | Rcpp::RNGScope rcpp_rngScope_gen; 103 | Rcpp::traits::input_parameter< SEXP >::type ptrA(ptrASEXP); 104 | Rcpp::traits::input_parameter< SEXP >::type x(xSEXP); 105 | Rcpp::traits::input_parameter< const int >::type type_flag(type_flagSEXP); 106 | nvMatToSEXP(ptrA, x, type_flag); 107 | return R_NilValue; 108 | END_RCPP 109 | } 110 | // nvMatEmtpy 111 | SEXP nvMatEmtpy(int nr, int nc, const int type_flag); 112 | RcppExport SEXP _gpuRcuda_nvMatEmtpy(SEXP nrSEXP, SEXP ncSEXP, SEXP type_flagSEXP) { 113 | BEGIN_RCPP 114 | Rcpp::RObject rcpp_result_gen; 115 | Rcpp::RNGScope rcpp_rngScope_gen; 116 | Rcpp::traits::input_parameter< int >::type nr(nrSEXP); 117 | Rcpp::traits::input_parameter< int >::type nc(ncSEXP); 118 | Rcpp::traits::input_parameter< const int >::type type_flag(type_flagSEXP); 119 | rcpp_result_gen = Rcpp::wrap(nvMatEmtpy(nr, nc, type_flag)); 120 | return rcpp_result_gen; 121 | END_RCPP 122 | } 123 | // sexpToHostVector 124 | SEXP sexpToHostVector(SEXP x, int size, const int type_flag); 125 | RcppExport SEXP _gpuRcuda_sexpToHostVector(SEXP xSEXP, SEXP sizeSEXP, SEXP type_flagSEXP) { 126 | BEGIN_RCPP 127 | Rcpp::RObject rcpp_result_gen; 128 | Rcpp::RNGScope rcpp_rngScope_gen; 129 | Rcpp::traits::input_parameter< SEXP >::type x(xSEXP); 130 | Rcpp::traits::input_parameter< int >::type size(sizeSEXP); 131 | Rcpp::traits::input_parameter< const int >::type type_flag(type_flagSEXP); 132 | rcpp_result_gen = Rcpp::wrap(sexpToHostVector(x, size, type_flag)); 133 | return rcpp_result_gen; 134 | END_RCPP 135 | } 136 | // nvVecToSEXP 137 | void nvVecToSEXP(SEXP ptrA, SEXP x, const int type_flag); 138 | RcppExport SEXP _gpuRcuda_nvVecToSEXP(SEXP ptrASEXP, SEXP xSEXP, SEXP type_flagSEXP) { 139 | BEGIN_RCPP 140 | Rcpp::RNGScope rcpp_rngScope_gen; 141 | Rcpp::traits::input_parameter< SEXP >::type ptrA(ptrASEXP); 142 | Rcpp::traits::input_parameter< SEXP >::type x(xSEXP); 143 | Rcpp::traits::input_parameter< const int >::type type_flag(type_flagSEXP); 144 | nvVecToSEXP(ptrA, x, type_flag); 145 | return R_NilValue; 146 | END_RCPP 147 | } 148 | // nvVecEmpty 149 | SEXP nvVecEmpty(int size, const int type_flag); 150 | RcppExport SEXP _gpuRcuda_nvVecEmpty(SEXP sizeSEXP, SEXP type_flagSEXP) { 151 | BEGIN_RCPP 152 | Rcpp::RObject rcpp_result_gen; 153 | Rcpp::RNGScope rcpp_rngScope_gen; 154 | Rcpp::traits::input_parameter< int >::type size(sizeSEXP); 155 | Rcpp::traits::input_parameter< const int >::type type_flag(type_flagSEXP); 156 | rcpp_result_gen = Rcpp::wrap(nvVecEmpty(size, type_flag)); 157 | return rcpp_result_gen; 158 | END_RCPP 159 | } 160 | // cpp_length 161 | int cpp_length(SEXP ptrA, const int type_flag); 162 | RcppExport SEXP _gpuRcuda_cpp_length(SEXP ptrASEXP, SEXP type_flagSEXP) { 163 | BEGIN_RCPP 164 | Rcpp::RObject rcpp_result_gen; 165 | Rcpp::RNGScope rcpp_rngScope_gen; 166 | Rcpp::traits::input_parameter< SEXP >::type ptrA(ptrASEXP); 167 | Rcpp::traits::input_parameter< const int >::type type_flag(type_flagSEXP); 168 | rcpp_result_gen = Rcpp::wrap(cpp_length(ptrA, type_flag)); 169 | return rcpp_result_gen; 170 | END_RCPP 171 | } 172 | // cpp_ncol 173 | int cpp_ncol(SEXP ptrA, const int type_flag); 174 | RcppExport SEXP _gpuRcuda_cpp_ncol(SEXP ptrASEXP, SEXP type_flagSEXP) { 175 | BEGIN_RCPP 176 | Rcpp::RObject rcpp_result_gen; 177 | Rcpp::RNGScope rcpp_rngScope_gen; 178 | Rcpp::traits::input_parameter< SEXP >::type ptrA(ptrASEXP); 179 | Rcpp::traits::input_parameter< const int >::type type_flag(type_flagSEXP); 180 | rcpp_result_gen = Rcpp::wrap(cpp_ncol(ptrA, type_flag)); 181 | return rcpp_result_gen; 182 | END_RCPP 183 | } 184 | // cpp_nrow 185 | int cpp_nrow(SEXP ptrA, const int type_flag); 186 | RcppExport SEXP _gpuRcuda_cpp_nrow(SEXP ptrASEXP, SEXP type_flagSEXP) { 187 | BEGIN_RCPP 188 | Rcpp::RObject rcpp_result_gen; 189 | Rcpp::RNGScope rcpp_rngScope_gen; 190 | Rcpp::traits::input_parameter< SEXP >::type ptrA(ptrASEXP); 191 | Rcpp::traits::input_parameter< const int >::type type_flag(type_flagSEXP); 192 | rcpp_result_gen = Rcpp::wrap(cpp_nrow(ptrA, type_flag)); 193 | return rcpp_result_gen; 194 | END_RCPP 195 | } 196 | 197 | static const R_CallMethodDef CallEntries[] = { 198 | {"_gpuRcuda_sexpToDeviceMatrix", (DL_FUNC) &_gpuRcuda_sexpToDeviceMatrix, 4}, 199 | {"_gpuRcuda_cudaMatToSEXP", (DL_FUNC) &_gpuRcuda_cudaMatToSEXP, 3}, 200 | {"_gpuRcuda_cudaMatEmtpy", (DL_FUNC) &_gpuRcuda_cudaMatEmtpy, 3}, 201 | {"_gpuRcuda_sexpToDeviceVector", (DL_FUNC) &_gpuRcuda_sexpToDeviceVector, 3}, 202 | {"_gpuRcuda_cudaVecToSEXP", (DL_FUNC) &_gpuRcuda_cudaVecToSEXP, 3}, 203 | {"_gpuRcuda_cudaVecEmpty", (DL_FUNC) &_gpuRcuda_cudaVecEmpty, 2}, 204 | {"_gpuRcuda_sexpToHostMatrix", (DL_FUNC) &_gpuRcuda_sexpToHostMatrix, 4}, 205 | {"_gpuRcuda_nvMatToSEXP", (DL_FUNC) &_gpuRcuda_nvMatToSEXP, 3}, 206 | {"_gpuRcuda_nvMatEmtpy", (DL_FUNC) &_gpuRcuda_nvMatEmtpy, 3}, 207 | {"_gpuRcuda_sexpToHostVector", (DL_FUNC) &_gpuRcuda_sexpToHostVector, 3}, 208 | {"_gpuRcuda_nvVecToSEXP", (DL_FUNC) &_gpuRcuda_nvVecToSEXP, 3}, 209 | {"_gpuRcuda_nvVecEmpty", (DL_FUNC) &_gpuRcuda_nvVecEmpty, 2}, 210 | {"_gpuRcuda_cpp_length", (DL_FUNC) &_gpuRcuda_cpp_length, 2}, 211 | {"_gpuRcuda_cpp_ncol", (DL_FUNC) &_gpuRcuda_cpp_ncol, 2}, 212 | {"_gpuRcuda_cpp_nrow", (DL_FUNC) &_gpuRcuda_cpp_nrow, 2}, 213 | {NULL, NULL, 0} 214 | }; 215 | 216 | RcppExport void R_init_gpuRcuda(DllInfo *dll) { 217 | R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); 218 | R_useDynamicSymbols(dll, FALSE); 219 | } 220 | --------------------------------------------------------------------------------