Skip to content

Commit

Permalink
begin consolidating code so C++ can be recycled for both gpu/vcl objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Determan authored and Determan committed Nov 17, 2017
1 parent 82004cf commit e37e09f
Show file tree
Hide file tree
Showing 8 changed files with 496 additions and 1,501 deletions.
88 changes: 22 additions & 66 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -718,48 +718,48 @@ cpp_vclMatrix_min <- function(ptrA, type_flag) {
.Call(`_gpuR_cpp_vclMatrix_min`, ptrA, type_flag)
}

cpp_gpuVector_axpy <- function(alpha, ptrA, ptrB, order, type_flag, ctx_id) {
invisible(.Call(`_gpuR_cpp_gpuVector_axpy`, alpha, ptrA, ptrB, order, type_flag, ctx_id))
cpp_gpuVector_axpy <- function(alpha, ptrA, AisVCL, ptrB, BisVCL, order, type_flag, ctx_id) {
invisible(.Call(`_gpuR_cpp_gpuVector_axpy`, alpha, ptrA, AisVCL, ptrB, BisVCL, order, type_flag, ctx_id))
}

cpp_gpuVector_unary_axpy <- function(ptrA, type_flag, ctx_id) {
invisible(.Call(`_gpuR_cpp_gpuVector_unary_axpy`, ptrA, type_flag, ctx_id))
cpp_gpuVector_unary_axpy <- function(ptrA, AisVCL, type_flag, ctx_id) {
invisible(.Call(`_gpuR_cpp_gpuVector_unary_axpy`, ptrA, AisVCL, type_flag, ctx_id))
}

cpp_gpuVector_inner_prod <- function(ptrA, ptrB, type_flag, ctx_id) {
.Call(`_gpuR_cpp_gpuVector_inner_prod`, ptrA, ptrB, type_flag, ctx_id)
cpp_gpuVector_inner_prod <- function(ptrA, AisVCL, ptrB, BisVCL, type_flag, ctx_id) {
.Call(`_gpuR_cpp_gpuVector_inner_prod`, ptrA, AisVCL, ptrB, BisVCL, type_flag, ctx_id)
}

cpp_gpuVector_outer_prod <- function(ptrA, ptrB, ptrC, type_flag, ctx_id) {
invisible(.Call(`_gpuR_cpp_gpuVector_outer_prod`, ptrA, ptrB, ptrC, type_flag, ctx_id))
cpp_gpuVector_outer_prod <- function(ptrA, AisVCL, ptrB, BisVCL, ptrC, CisVCL, type_flag, ctx_id) {
invisible(.Call(`_gpuR_cpp_gpuVector_outer_prod`, ptrA, AisVCL, ptrB, BisVCL, ptrC, CisVCL, type_flag, ctx_id))
}

cpp_gpuVector_elem_prod <- function(ptrA, ptrB, ptrC, type_flag, ctx_id) {
invisible(.Call(`_gpuR_cpp_gpuVector_elem_prod`, ptrA, ptrB, ptrC, type_flag, ctx_id))
cpp_gpuVector_elem_prod <- function(ptrA, AisVCL, ptrB, BisVCL, ptrC, CisVCL, type_flag, ctx_id) {
invisible(.Call(`_gpuR_cpp_gpuVector_elem_prod`, ptrA, AisVCL, ptrB, BisVCL, ptrC, CisVCL, type_flag, ctx_id))
}

cpp_gpuVector_scalar_prod <- function(ptrC, scalar, type_flag, ctx_id) {
invisible(.Call(`_gpuR_cpp_gpuVector_scalar_prod`, ptrC, scalar, type_flag, ctx_id))
cpp_gpuVector_scalar_prod <- function(ptrC, CisVCL, scalar, type_flag, ctx_id) {
invisible(.Call(`_gpuR_cpp_gpuVector_scalar_prod`, ptrC, CisVCL, scalar, type_flag, ctx_id))
}

cpp_gpuVector_elem_div <- function(ptrA, ptrB, ptrC, type_flag, ctx_id) {
invisible(.Call(`_gpuR_cpp_gpuVector_elem_div`, ptrA, ptrB, ptrC, type_flag, ctx_id))
cpp_gpuVector_elem_div <- function(ptrA, AisVCL, ptrB, BisVCL, ptrC, CisVCL, type_flag, ctx_id) {
invisible(.Call(`_gpuR_cpp_gpuVector_elem_div`, ptrA, AisVCL, ptrB, BisVCL, ptrC, CisVCL, type_flag, ctx_id))
}

cpp_gpuVector_scalar_div <- function(ptrC, scalar, order, type_flag, ctx_id) {
invisible(.Call(`_gpuR_cpp_gpuVector_scalar_div`, ptrC, scalar, order, type_flag, ctx_id))
cpp_gpuVector_scalar_div <- function(ptrC, CisVCL, scalar, order, type_flag, ctx_id) {
invisible(.Call(`_gpuR_cpp_gpuVector_scalar_div`, ptrC, CisVCL, scalar, order, type_flag, ctx_id))
}

cpp_gpuVector_elem_pow <- function(ptrA, ptrB, ptrC, type_flag, ctx_id) {
invisible(.Call(`_gpuR_cpp_gpuVector_elem_pow`, ptrA, ptrB, ptrC, type_flag, ctx_id))
cpp_gpuVector_elem_pow <- function(ptrA, AisVCL, ptrB, BisVCL, ptrC, CisVCL, type_flag, ctx_id) {
invisible(.Call(`_gpuR_cpp_gpuVector_elem_pow`, ptrA, AisVCL, ptrB, BisVCL, ptrC, CisVCL, type_flag, ctx_id))
}

cpp_gpuVector_scalar_pow <- function(ptrA, scalar, ptrC, order, type_flag, ctx_id) {
invisible(.Call(`_gpuR_cpp_gpuVector_scalar_pow`, ptrA, scalar, ptrC, order, type_flag, ctx_id))
cpp_gpuVector_scalar_pow <- function(ptrA, AisVCL, scalar, ptrC, CisVCL, order, type_flag, ctx_id) {
invisible(.Call(`_gpuR_cpp_gpuVector_scalar_pow`, ptrA, AisVCL, scalar, ptrC, CisVCL, order, type_flag, ctx_id))
}

cpp_gpuVector_sqrt <- function(ptrA, ptrB, type_flag, ctx_id) {
invisible(.Call(`_gpuR_cpp_gpuVector_sqrt`, ptrA, ptrB, type_flag, ctx_id))
cpp_gpuVector_sqrt <- function(ptrA, AisVCL, ptrB, BisVCL, type_flag, ctx_id) {
invisible(.Call(`_gpuR_cpp_gpuVector_sqrt`, ptrA, AisVCL, ptrB, BisVCL, type_flag, ctx_id))
}

cpp_gpuVector_elem_sin <- function(ptrA, ptrB, type_flag, ctx_id) {
Expand Down Expand Up @@ -822,50 +822,6 @@ cpp_gpuVector_min <- function(ptrA, type_flag, ctx_id) {
.Call(`_gpuR_cpp_gpuVector_min`, ptrA, type_flag, ctx_id)
}

cpp_vclVector_axpy <- function(alpha, ptrA, ptrB, order, type_flag) {
invisible(.Call(`_gpuR_cpp_vclVector_axpy`, alpha, ptrA, ptrB, order, type_flag))
}

cpp_vclVector_unary_axpy <- function(ptrA, type_flag) {
invisible(.Call(`_gpuR_cpp_vclVector_unary_axpy`, ptrA, type_flag))
}

cpp_vclVector_inner_prod <- function(ptrA, ptrB, type_flag) {
.Call(`_gpuR_cpp_vclVector_inner_prod`, ptrA, ptrB, type_flag)
}

cpp_vclVector_outer_prod <- function(ptrA, ptrB, ptrC, type_flag) {
invisible(.Call(`_gpuR_cpp_vclVector_outer_prod`, ptrA, ptrB, ptrC, type_flag))
}

cpp_vclVector_elem_prod <- function(ptrA, ptrB, ptrC, type_flag) {
invisible(.Call(`_gpuR_cpp_vclVector_elem_prod`, ptrA, ptrB, ptrC, type_flag))
}

cpp_vclVector_scalar_prod <- function(ptrC, scalar, type_flag) {
invisible(.Call(`_gpuR_cpp_vclVector_scalar_prod`, ptrC, scalar, type_flag))
}

cpp_vclVector_elem_div <- function(ptrA, ptrB, ptrC, type_flag) {
invisible(.Call(`_gpuR_cpp_vclVector_elem_div`, ptrA, ptrB, ptrC, type_flag))
}

cpp_vclVector_scalar_div <- function(ptrC, scalar, order, type_flag, ctx_id) {
invisible(.Call(`_gpuR_cpp_vclVector_scalar_div`, ptrC, scalar, order, type_flag, ctx_id))
}

cpp_vclVector_elem_pow <- function(ptrA, ptrB, ptrC, type_flag) {
invisible(.Call(`_gpuR_cpp_vclVector_elem_pow`, ptrA, ptrB, ptrC, type_flag))
}

cpp_vclVector_scalar_pow <- function(ptrA, scalar, ptrC, type_flag) {
invisible(.Call(`_gpuR_cpp_vclVector_scalar_pow`, ptrA, scalar, ptrC, type_flag))
}

cpp_vclVector_sqrt <- function(ptrA, ptrB, type_flag) {
invisible(.Call(`_gpuR_cpp_vclVector_sqrt`, ptrA, ptrB, type_flag))
}

cpp_vclVector_elem_sin <- function(ptrA, ptrB, type_flag) {
invisible(.Call(`_gpuR_cpp_vclVector_elem_sin`, ptrA, ptrB, type_flag))
}
Expand Down
24 changes: 12 additions & 12 deletions R/inplace.R
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ setMethod("inplace",
function(f, x, y){

switch(deparse(substitute(f)),
`+` = vclVec_axpy(1, y, x, inplace = TRUE),
`-` = vclVec_axpy(-1, y, x, inplace = TRUE),
`*` = vclVecElemMult(x, y, inplace = TRUE),
`/` = vclVecElemDiv(x, y, inplace = TRUE),
`+` = gpuVec_axpy(1, y, x, inplace = TRUE),
`-` = gpuVec_axpy(-1, y, x, inplace = TRUE),
`*` = gpuVecElemMult(x, y, inplace = TRUE),
`/` = gpuVecElemDiv(x, y, inplace = TRUE),
stop("undefined operation")
)
})
Expand Down Expand Up @@ -212,14 +212,14 @@ setMethod("inplace",
switch(deparse(substitute(f)),
`+` = {
z <- vclVector(rep(y, length(x)), type=typeof(x), ctx_id = x@.context_index)
vclVec_axpy(1, z, x, inplace = TRUE)
gpuVec_axpy(1, z, x, inplace = TRUE)
},
`-` = {
z <- vclVector(rep(y, length(x)), type=typeof(x), ctx_id = x@.context_index)
vclVec_axpy(-1, z, x, inplace = TRUE)
gpuVec_axpy(-1, z, x, inplace = TRUE)
},
`*` = vclVecScalarMult(x, y, inplace = TRUE),
`/` = vclVecScalarDiv(x, y, inplace = TRUE),
`*` = gpuVecScalarMult(x, y, inplace = TRUE),
`/` = gpuVecScalarDiv(x, y, inplace = TRUE),
stop("undefined operation")
)
})
Expand All @@ -233,14 +233,14 @@ setMethod("inplace",
switch(deparse(substitute(f)),
`+` = {
z <- vclVector(x, length = length(y), type=typeof(y), ctx_id = y@.context_index)
vclVec_axpy(1, z, y, inplace = TRUE)
gpuVec_axpy(1, z, y, inplace = TRUE)
},
`-` = {
z <- vclVector(x, length = length(y), type=typeof(y), ctx_id = y@.context_index)
vclVec_axpy(-1, z, y, inplace = TRUE, order = 1)
gpuVec_axpy(-1, z, y, inplace = TRUE, order = 1)
},
`*` = vclVecScalarMult(x, y, inplace = TRUE),
`/` = vclVecScalarDiv(x, y, 1, inplace = TRUE),
`*` = gpuVecScalarMult(x, y, inplace = TRUE),
`/` = gpuVecScalarDiv(x, y, 1, inplace = TRUE),
stop("undefined operation")
)
})
Expand Down
38 changes: 19 additions & 19 deletions R/methods-vclVector.R
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ setMethod("%*%", signature(x="vclVector", y = "vclVector"),
if( length(x) != length(y)){
stop("Non-conformant arguments")
}
return(vclVecInner(x, y))
return(gpuVecInnerProd(x, y))
},
valueClass = "vclVector"
)
Expand All @@ -397,7 +397,7 @@ setMethod("%*%", signature(x="vclVector", y = "vclMatrix"),
setMethod("%o%", signature(X="vclVector", Y = "vclVector"),
function(X,Y)
{
return(vclVecOuter(X, Y))
return(gpuVecOuterProd(X, Y))
},
valueClass = "vclMatrix"
)
Expand All @@ -413,11 +413,11 @@ setMethod("Arith", c(e1="vclVector", e2="vclVector"),

op = .Generic[[1]]
switch(op,
`+` = vclVec_axpy(1, e1, e2),
`-` = vclVec_axpy(-1, e2, e1),
`*` = vclVecElemMult(e1, e2),
`/` = vclVecElemDiv(e1,e2),
`^` = vclVecElemPow(e1, e2),
`+` = gpuVec_axpy(1, e1, e2),
`-` = gpuVec_axpy(-1, e2, e1),
`*` = gpuVecElemMult(e1, e2),
`/` = gpuVecElemDiv(e1,e2),
`^` = gpuVecElemPow(e1, e2),
stop("undefined operation")
)
},
Expand All @@ -435,20 +435,20 @@ setMethod("Arith", c(e1="numeric", e2="vclVector"),
switch(op,
`+` = {
e1 = vclVector(rep(e1, length(e2)), type=typeof(e2), ctx_id = e2@.context_index)
vclVec_axpy(1, e1, e2)
gpuVec_axpy(1, e1, e2)
},
`-` = {
e1 = vclVector(rep(e1, length(e2)), type=typeof(e2), ctx_id = e2@.context_index)
vclVec_axpy(-1, e2, e1)
gpuVec_axpy(-1, e2, e1)
},
`*` = vclVecScalarMult(e2, e1),
`*` = gpuVecScalarMult(e2, e1),
`/` = {
e1 = vclVector(rep(e1, length(e2)), type=typeof(e2), ctx_id = e2@.context_index)
vclVecElemDiv(e1, e2)
gpuVecElemDiv(e1, e2)
},
`^` = {
e1 <- vclVector(rep(e1, length(e2)), type=typeof(e2), ctx_id = e2@.context_index)
vclVecElemPow(e1, e2)
gpuVecElemPow(e1, e2)
},
stop("undefined operation")
)
Expand All @@ -467,15 +467,15 @@ setMethod("Arith", c(e1="vclVector", e2="numeric"),
switch(op,
`+` = {
e2 = vclVector(rep(e2, length(e1)), type=typeof(e1), ctx_id = e1@.context_index)
vclVec_axpy(1, e1, e2)
gpuVec_axpy(1, e1, e2)
},
`-` = {
e2 = vclVector(rep(e2, length(e1)), type=typeof(e1), ctx_id = e1@.context_index)
vclVec_axpy(-1, e2, e1)
gpuVec_axpy(-1, e2, e1)
},
`*` = vclVecScalarMult(e1, e2),
`/` = vclVecScalarDiv(e1, e2),
`^` = vclVecScalarPow(e1, e2),
`*` = gpuVecScalarMult(e1, e2),
`/` = gpuVecScalarDiv(e1, e2, 0),
`^` = gpuVecScalarPow(e1, e2, 0),
stop("undefined operation")
)
},
Expand All @@ -489,7 +489,7 @@ setMethod("Arith", c(e1="vclVector", e2="missing"),
{
op = .Generic[[1]]
switch(op,
`-` = vclVector_unary_axpy(e1),
`-` = gpuVector_unary_axpy(e1),
stop("undefined operation")
)
},
Expand Down Expand Up @@ -531,7 +531,7 @@ setMethod("Math", c(x="vclVector"),
`log10` = vclVecElemLog10(x),
`exp` = vclVecElemExp(x),
`abs` = vclVecElemAbs(x),
`sqrt` = vclVecSqrt(x),
`sqrt` = gpuVecSqrt(x),
`sign` = gpuVecSign(x),
stop("undefined operation")
)
Expand Down
Loading

0 comments on commit e37e09f

Please sign in to comment.