Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the sum method for vclVector objects #115

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -278,18 +278,6 @@ truncDoublegpuMat <- function(ptrA_, nr, nc) {
.Call(`_gpuR_truncDoublegpuMat`, ptrA_, nr, nc)
}

cpp_vcl_nrow <- function(ptrA, type_flag) {
.Call(`_gpuR_cpp_vcl_nrow`, ptrA, type_flag)
}

cpp_vcl_ncol <- function(ptrA, type_flag) {
.Call(`_gpuR_cpp_vcl_ncol`, ptrA, type_flag)
}

cpp_vclVector_size <- function(ptrA, type_flag) {
.Call(`_gpuR_cpp_vclVector_size`, ptrA, type_flag)
}

cpp_gpuVector_size <- function(ptrA, type_flag) {
.Call(`_gpuR_cpp_gpuVector_size`, ptrA, type_flag)
}
Expand All @@ -314,6 +302,18 @@ cpp_gpuMatrix_ncol <- function(ptrA, type_flag) {
.Call(`_gpuR_cpp_gpuMatrix_ncol`, ptrA, type_flag)
}

cpp_vcl_nrow <- function(ptrA, type_flag) {
.Call(`_gpuR_cpp_vcl_nrow`, ptrA, type_flag)
}

cpp_vcl_ncol <- function(ptrA, type_flag) {
.Call(`_gpuR_cpp_vcl_ncol`, ptrA, type_flag)
}

cpp_vclVector_size <- function(ptrA, type_flag) {
.Call(`_gpuR_cpp_vclVector_size`, ptrA, type_flag)
}

cpp_identity_vclMatrix <- function(ptrA, type_flag) {
invisible(.Call(`_gpuR_cpp_identity_vclMatrix`, ptrA, type_flag))
}
Expand Down Expand Up @@ -878,6 +878,10 @@ cpp_vclMatrix_sum <- function(ptrA, type_flag) {
.Call(`_gpuR_cpp_vclMatrix_sum`, ptrA, type_flag)
}

cpp_vclVector_sum <- function(ptrA, type_flag) {
.Call(`_gpuR_cpp_vclVector_sum`, ptrA, type_flag)
}

cpp_vclMatrix_svd <- function(ptrA, ptrD, ptrU, ptrV, type_flag, ctx_id) {
invisible(.Call(`_gpuR_cpp_vclMatrix_svd`, ptrA, ptrD, ptrU, ptrV, type_flag, ctx_id))
}
Expand Down
1 change: 1 addition & 0 deletions R/methods-vclVector.R
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ setMethod("Summary", c(x="vclVector"),
result <- switch(op,
`max` = vclVecMax(x),
`min` = vclVecMin(x),
`sum` = vclVecSum(x),
stop("undefined operation")
)
return(result)
Expand Down
18 changes: 18 additions & 0 deletions R/wrappers-vclVector.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,22 @@ vclVecMin <- function(A){
return(C)
}

# GPU Vector sum
vclVecSum <- function(A){

type <- typeof(A)

C <- switch(type,
integer = {
stop("integer not currently implemented")
},
float = {cpp_vclVector_sum(A@address, 6L)
},
double = {
cpp_vclVector_sum(A@address, 8L)
},
stop("type not recognized")
)
return(C)
}

91 changes: 52 additions & 39 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,42 +761,6 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
// cpp_vcl_nrow
SEXP cpp_vcl_nrow(SEXP ptrA, const int type_flag);
RcppExport SEXP _gpuR_cpp_vcl_nrow(SEXP ptrASEXP, SEXP type_flagSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< SEXP >::type ptrA(ptrASEXP);
Rcpp::traits::input_parameter< const int >::type type_flag(type_flagSEXP);
rcpp_result_gen = Rcpp::wrap(cpp_vcl_nrow(ptrA, type_flag));
return rcpp_result_gen;
END_RCPP
}
// cpp_vcl_ncol
SEXP cpp_vcl_ncol(SEXP ptrA, const int type_flag);
RcppExport SEXP _gpuR_cpp_vcl_ncol(SEXP ptrASEXP, SEXP type_flagSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< SEXP >::type ptrA(ptrASEXP);
Rcpp::traits::input_parameter< const int >::type type_flag(type_flagSEXP);
rcpp_result_gen = Rcpp::wrap(cpp_vcl_ncol(ptrA, type_flag));
return rcpp_result_gen;
END_RCPP
}
// cpp_vclVector_size
SEXP cpp_vclVector_size(SEXP ptrA, const int type_flag);
RcppExport SEXP _gpuR_cpp_vclVector_size(SEXP ptrASEXP, SEXP type_flagSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< SEXP >::type ptrA(ptrASEXP);
Rcpp::traits::input_parameter< const int >::type type_flag(type_flagSEXP);
rcpp_result_gen = Rcpp::wrap(cpp_vclVector_size(ptrA, type_flag));
return rcpp_result_gen;
END_RCPP
}
// cpp_gpuVector_size
SEXP cpp_gpuVector_size(SEXP ptrA, const int type_flag);
RcppExport SEXP _gpuR_cpp_gpuVector_size(SEXP ptrASEXP, SEXP type_flagSEXP) {
Expand Down Expand Up @@ -870,6 +834,42 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
// cpp_vcl_nrow
SEXP cpp_vcl_nrow(SEXP ptrA, const int type_flag);
RcppExport SEXP _gpuR_cpp_vcl_nrow(SEXP ptrASEXP, SEXP type_flagSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< SEXP >::type ptrA(ptrASEXP);
Rcpp::traits::input_parameter< const int >::type type_flag(type_flagSEXP);
rcpp_result_gen = Rcpp::wrap(cpp_vcl_nrow(ptrA, type_flag));
return rcpp_result_gen;
END_RCPP
}
// cpp_vcl_ncol
SEXP cpp_vcl_ncol(SEXP ptrA, const int type_flag);
RcppExport SEXP _gpuR_cpp_vcl_ncol(SEXP ptrASEXP, SEXP type_flagSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< SEXP >::type ptrA(ptrASEXP);
Rcpp::traits::input_parameter< const int >::type type_flag(type_flagSEXP);
rcpp_result_gen = Rcpp::wrap(cpp_vcl_ncol(ptrA, type_flag));
return rcpp_result_gen;
END_RCPP
}
// cpp_vclVector_size
SEXP cpp_vclVector_size(SEXP ptrA, const int type_flag);
RcppExport SEXP _gpuR_cpp_vclVector_size(SEXP ptrASEXP, SEXP type_flagSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< SEXP >::type ptrA(ptrASEXP);
Rcpp::traits::input_parameter< const int >::type type_flag(type_flagSEXP);
rcpp_result_gen = Rcpp::wrap(cpp_vclVector_size(ptrA, type_flag));
return rcpp_result_gen;
END_RCPP
}
// cpp_identity_vclMatrix
void cpp_identity_vclMatrix(SEXP ptrA, const int type_flag);
RcppExport SEXP _gpuR_cpp_identity_vclMatrix(SEXP ptrASEXP, SEXP type_flagSEXP) {
Expand Down Expand Up @@ -2849,6 +2849,18 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
// cpp_vclVector_sum
SEXP cpp_vclVector_sum(SEXP ptrA, const int type_flag);
RcppExport SEXP _gpuR_cpp_vclVector_sum(SEXP ptrASEXP, SEXP type_flagSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< SEXP >::type ptrA(ptrASEXP);
Rcpp::traits::input_parameter< const int >::type type_flag(type_flagSEXP);
rcpp_result_gen = Rcpp::wrap(cpp_vclVector_sum(ptrA, type_flag));
return rcpp_result_gen;
END_RCPP
}
// cpp_vclMatrix_svd
void cpp_vclMatrix_svd(SEXP ptrA, SEXP ptrD, SEXP ptrU, SEXP ptrV, int type_flag, int ctx_id);
RcppExport SEXP _gpuR_cpp_vclMatrix_svd(SEXP ptrASEXP, SEXP ptrDSEXP, SEXP ptrUSEXP, SEXP ptrVSEXP, SEXP type_flagSEXP, SEXP ctx_idSEXP) {
Expand Down Expand Up @@ -2938,15 +2950,15 @@ static const R_CallMethodDef CallEntries[] = {
{"_gpuR_truncIntgpuMat", (DL_FUNC) &_gpuR_truncIntgpuMat, 3},
{"_gpuR_truncFloatgpuMat", (DL_FUNC) &_gpuR_truncFloatgpuMat, 3},
{"_gpuR_truncDoublegpuMat", (DL_FUNC) &_gpuR_truncDoublegpuMat, 3},
{"_gpuR_cpp_vcl_nrow", (DL_FUNC) &_gpuR_cpp_vcl_nrow, 2},
{"_gpuR_cpp_vcl_ncol", (DL_FUNC) &_gpuR_cpp_vcl_ncol, 2},
{"_gpuR_cpp_vclVector_size", (DL_FUNC) &_gpuR_cpp_vclVector_size, 2},
{"_gpuR_cpp_gpuVector_size", (DL_FUNC) &_gpuR_cpp_gpuVector_size, 2},
{"_gpuR_cpp_gpuVector_max", (DL_FUNC) &_gpuR_cpp_gpuVector_max, 3},
{"_gpuR_cpp_gpuMatrix_max", (DL_FUNC) &_gpuR_cpp_gpuMatrix_max, 2},
{"_gpuR_cpp_gpuMatrix_min", (DL_FUNC) &_gpuR_cpp_gpuMatrix_min, 2},
{"_gpuR_cpp_gpuMatrix_nrow", (DL_FUNC) &_gpuR_cpp_gpuMatrix_nrow, 2},
{"_gpuR_cpp_gpuMatrix_ncol", (DL_FUNC) &_gpuR_cpp_gpuMatrix_ncol, 2},
{"_gpuR_cpp_vcl_nrow", (DL_FUNC) &_gpuR_cpp_vcl_nrow, 2},
{"_gpuR_cpp_vcl_ncol", (DL_FUNC) &_gpuR_cpp_vcl_ncol, 2},
{"_gpuR_cpp_vclVector_size", (DL_FUNC) &_gpuR_cpp_vclVector_size, 2},
{"_gpuR_cpp_identity_vclMatrix", (DL_FUNC) &_gpuR_cpp_identity_vclMatrix, 2},
{"_gpuR_cpp_vclMatrix_get_diag", (DL_FUNC) &_gpuR_cpp_vclMatrix_get_diag, 3},
{"_gpuR_cpp_vclMat_vclVec_set_diag", (DL_FUNC) &_gpuR_cpp_vclMat_vclVec_set_diag, 3},
Expand Down Expand Up @@ -3088,6 +3100,7 @@ static const R_CallMethodDef CallEntries[] = {
{"_gpuR_cpp_vclMatrix_rowmean", (DL_FUNC) &_gpuR_cpp_vclMatrix_rowmean, 3},
{"_gpuR_cpp_vclMatrix_rowsum", (DL_FUNC) &_gpuR_cpp_vclMatrix_rowsum, 3},
{"_gpuR_cpp_vclMatrix_sum", (DL_FUNC) &_gpuR_cpp_vclMatrix_sum, 2},
{"_gpuR_cpp_vclVector_sum", (DL_FUNC) &_gpuR_cpp_vclVector_sum, 2},
{"_gpuR_cpp_vclMatrix_svd", (DL_FUNC) &_gpuR_cpp_vclMatrix_svd, 6},
{"_gpuR_cpp_gpuMatrix_svd", (DL_FUNC) &_gpuR_cpp_gpuMatrix_svd, 5},
{NULL, NULL, 0}
Expand Down
30 changes: 29 additions & 1 deletion src/vienna_stats.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#include "gpuR/windows_check.hpp"

// eigen headers for handling the R input data
Expand Down Expand Up @@ -221,6 +220,18 @@ cpp_vclMatrix_sum(
return wrap(res);
}

template <typename T>
SEXP
cpp_vclVector_sum(
SEXP ptrA_)
{
Rcpp::XPtr<dynVCLVec<T> > pA(ptrA_);
viennacl::vector_range<viennacl::vector_base<T> > vcl_A = pA->data();

T res = viennacl::linalg::sum(vcl_A);
return wrap(res);
}


template <typename T>
void
Expand Down Expand Up @@ -1102,3 +1113,20 @@ cpp_vclMatrix_sum(
throw Rcpp::exception("unknown type detected for vclMatrix object!");
}
}
// [[Rcpp::export]]
SEXP
cpp_vclVector_sum(
SEXP ptrA,
const int type_flag)
{
switch(type_flag) {
case 4:
return cpp_vclVector_sum<int>(ptrA);
case 6:
return cpp_vclVector_sum<float>(ptrA);
case 8:
return cpp_vclVector_sum<double>(ptrA);
default:
throw Rcpp::exception("unknown type detected for vclMatrix object!");
}
}