Skip to content

Commit

Permalink
update function listOpenCLDevices() -> listGPUDevices()
Browse files Browse the repository at this point in the history
  • Loading branch information
jianxiaoyang committed Nov 2, 2023
1 parent 87d0494 commit f0b272e
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 35 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export(getNumberOfStrata)
export(getUnivariableCorrelation)
export(getUnivariableSeparability)
export(isInitialized)
export(listOpenCLDevices)
export(listGPUDevices)
export(meanLinearPredictor)
export(mse)
export(readCyclopsData)
Expand Down
3 changes: 2 additions & 1 deletion R/Gpu.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
#'
#' @export
setOpenCLDevice <- function(name) {
devices <- listOpenCLDevices()
devices <- listGPUDevices()

if (!(name %in% devices)) {
stop("Unable to find device.")
}

Sys.setenv(BOOST_COMPUTE_DEFAULT_DEVICE = name)
# TODO set CUDA device
}
2 changes: 1 addition & 1 deletion R/ModelFit.R
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ fitCyclopsModel <- function(cyclopsData,
}

if (computeDevice != "native") {
stopifnot(computeDevice %in% listOpenCLDevices())
stopifnot(computeDevice %in% listGPUDevices())
}

# Build interface
Expand Down
10 changes: 5 additions & 5 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@
#' @title List available GPU devices
#'
#' @description
#' \code{listOpenCLDevices} list available GPU devices
#' \code{listGPUDevices} list available GPU devices
#'
#' @export
listOpenCLDevices <- function() {
.Call(`_Cyclops_listOpenCLDevices`)
listGPUDevices <- function() {
.Call(`_Cyclops_listGPUDevices`)
}

.getDefaultOpenCLDevice <- function() {
.Call(`_Cyclops_getDefaultOpenCLDevice`)
.getDefaultGPUDevice <- function() {
.Call(`_Cyclops_getDefaultGPUDevice`)
}

.isSorted <- function(dataFrame, indexes, ascending) {
Expand Down
8 changes: 4 additions & 4 deletions man/listOpenCLDevices.Rd → man/listGPUDevices.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,23 +379,23 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
// listOpenCLDevices
Rcpp::CharacterVector listOpenCLDevices();
RcppExport SEXP _Cyclops_listOpenCLDevices() {
// listGPUDevices
Rcpp::CharacterVector listGPUDevices();
RcppExport SEXP _Cyclops_listGPUDevices() {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
rcpp_result_gen = Rcpp::wrap(listOpenCLDevices());
rcpp_result_gen = Rcpp::wrap(listGPUDevices());
return rcpp_result_gen;
END_RCPP
}
// getDefaultOpenCLDevice
std::string getDefaultOpenCLDevice();
RcppExport SEXP _Cyclops_getDefaultOpenCLDevice() {
// getDefaultGPUDevice
std::string getDefaultGPUDevice();
RcppExport SEXP _Cyclops_getDefaultGPUDevice() {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
rcpp_result_gen = Rcpp::wrap(getDefaultOpenCLDevice());
rcpp_result_gen = Rcpp::wrap(getDefaultGPUDevice());
return rcpp_result_gen;
END_RCPP
}
Expand Down Expand Up @@ -875,8 +875,8 @@ static const R_CallMethodDef CallEntries[] = {
{"_Cyclops_cyclopsRunBootstrap", (DL_FUNC) &_Cyclops_cyclopsRunBootstrap, 4},
{"_Cyclops_cyclopsLogModel", (DL_FUNC) &_Cyclops_cyclopsLogModel, 1},
{"_Cyclops_cyclopsInitializeModel", (DL_FUNC) &_Cyclops_cyclopsInitializeModel, 4},
{"_Cyclops_listOpenCLDevices", (DL_FUNC) &_Cyclops_listOpenCLDevices, 0},
{"_Cyclops_getDefaultOpenCLDevice", (DL_FUNC) &_Cyclops_getDefaultOpenCLDevice, 0},
{"_Cyclops_listGPUDevices", (DL_FUNC) &_Cyclops_listGPUDevices, 0},
{"_Cyclops_getDefaultGPUDevice", (DL_FUNC) &_Cyclops_getDefaultGPUDevice, 0},
{"_Cyclops_isSorted", (DL_FUNC) &_Cyclops_isSorted, 3},
{"_Cyclops_isSortedVectorList", (DL_FUNC) &_Cyclops_isSortedVectorList, 2},
{"_Cyclops_isRcppPtrNull", (DL_FUNC) &_Cyclops_isRcppPtrNull, 1},
Expand Down
10 changes: 5 additions & 5 deletions src/RcppGpuInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
//' @title List available GPU devices
//'
//' @description
//' \code{listOpenCLDevices} list available GPU devices
//' \code{listGPUDevices} list available GPU devices
//'
//' @export
// [[Rcpp::export("listOpenCLDevices")]]
Rcpp::CharacterVector listOpenCLDevices() {
// [[Rcpp::export("listGPUDevices")]]
Rcpp::CharacterVector listGPUDevices() {
using namespace Rcpp;
CharacterVector devices;

Expand All @@ -45,8 +45,8 @@ Rcpp::CharacterVector listOpenCLDevices() {
return devices;
}

// [[Rcpp::export(".getDefaultOpenCLDevice")]]
std::string getDefaultOpenCLDevice() {
// [[Rcpp::export(".getDefaultGPUDevice")]]
std::string getDefaultGPUDevice() {
#ifdef HAVE_OPENCL
return boost::compute::system::default_device().name();
#else
Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/test-gpucox.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ library("testthat")
library("survival")


GpuDevice <- listOpenCLDevices()[1]
GpuDevice <- listGPUDevices()[1]
tolerance <- 1E-4


# small cox
test_that("Check small Cox on GPU", {
skip_if(length(listOpenCLDevices()) == 0, "GPU not available")
skip_if(length(listGPUDevices()) == 0, "GPU not available")
test <- read.table(header=T, sep = ",", text = "
start, length, event, x1, x2
0, 4, 1,0,0
Expand All @@ -34,7 +34,7 @@ test_that("Check small Cox on GPU", {
})

test_that("Check very small Cox example with time-ties", {
skip_if(length(listOpenCLDevices()) == 0, "GPU not available")
skip_if(length(listGPUDevices()) == 0, "GPU not available")
test <- read.table(header=T, sep = ",", text = "
start, length, event, x1, x2
0, 4, 1,0,0
Expand All @@ -60,7 +60,7 @@ start, length, event, x1, x2

# large cox
test_that("Check Cox on GPU", {
skip_if(length(listOpenCLDevices()) == 0, "GPU not available")
skip_if(length(listGPUDevices()) == 0, "GPU not available")
set.seed(123)
sim <- simulateCyclopsData(nstrata = 1,
nrows = 100000,
Expand All @@ -85,7 +85,7 @@ test_that("Check Cox on GPU", {

# lasso cv
test_that("Check cross-validation for lasso Cox on GPU", {
skip_if(length(listOpenCLDevices()) == 0, "GPU not available")
skip_if(length(listGPUDevices()) == 0, "GPU not available")
set.seed(123)
sim <- simulateCyclopsData(nstrata = 1,
nrows = 900,
Expand Down Expand Up @@ -115,7 +115,7 @@ test_that("Check cross-validation for lasso Cox on GPU", {

# multi-core
test_that("Check multi-core cross-validation for lasso Cox on GPU", {
skip_if(length(listOpenCLDevices()) == 0, "GPU not available")
skip_if(length(listGPUDevices()) == 0, "GPU not available")
set.seed(123)
sim <- simulateCyclopsData(nstrata = 1,
nrows = 900,
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-timevaryingCox.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
library(survival)
library(testthat)

GpuDevice <- listOpenCLDevices()[1]
GpuDevice <- listGPUDevices()[1]
tolerance <- 1E-4

test_that("Check very small Cox example with time-varying coefficient as stratified model", {
skip_if(length(listOpenCLDevices()) == 0, "GPU not available")
skip_if(length(listGPUDevices()) == 0, "GPU not available")
test <- read.table(header=T, sep = ",", text = "
start, length, event, x1, x2
0, 4, 1,0,0
Expand Down

0 comments on commit f0b272e

Please sign in to comment.