From f0b272edac34731bd5e1164233f652c84b1f0090 Mon Sep 17 00:00:00 2001 From: JianxiaoYang Date: Wed, 1 Nov 2023 19:28:17 -0700 Subject: [PATCH] update function listOpenCLDevices() -> listGPUDevices() --- NAMESPACE | 2 +- R/Gpu.R | 3 ++- R/ModelFit.R | 2 +- R/RcppExports.R | 10 +++++----- ...listOpenCLDevices.Rd => listGPUDevices.Rd} | 8 ++++---- src/RcppExports.cpp | 20 +++++++++---------- src/RcppGpuInterface.cpp | 10 +++++----- tests/testthat/test-gpucox.R | 12 +++++------ tests/testthat/test-timevaryingCox.R | 4 ++-- 9 files changed, 36 insertions(+), 35 deletions(-) rename man/{listOpenCLDevices.Rd => listGPUDevices.Rd} (55%) diff --git a/NAMESPACE b/NAMESPACE index 6aecb22e..91dabff5 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -38,7 +38,7 @@ export(getNumberOfStrata) export(getUnivariableCorrelation) export(getUnivariableSeparability) export(isInitialized) -export(listOpenCLDevices) +export(listGPUDevices) export(meanLinearPredictor) export(mse) export(readCyclopsData) diff --git a/R/Gpu.R b/R/Gpu.R index 32818853..7b37e2e5 100644 --- a/R/Gpu.R +++ b/R/Gpu.R @@ -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 } diff --git a/R/ModelFit.R b/R/ModelFit.R index f4c37a82..3919efeb 100644 --- a/R/ModelFit.R +++ b/R/ModelFit.R @@ -387,7 +387,7 @@ fitCyclopsModel <- function(cyclopsData, } if (computeDevice != "native") { - stopifnot(computeDevice %in% listOpenCLDevices()) + stopifnot(computeDevice %in% listGPUDevices()) } # Build interface diff --git a/R/RcppExports.R b/R/RcppExports.R index 65ac4ea5..a2987971 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -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) { diff --git a/man/listOpenCLDevices.Rd b/man/listGPUDevices.Rd similarity index 55% rename from man/listOpenCLDevices.Rd rename to man/listGPUDevices.Rd index 69ef9f1b..162dca7d 100644 --- a/man/listOpenCLDevices.Rd +++ b/man/listGPUDevices.Rd @@ -1,11 +1,11 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/RcppExports.R -\name{listOpenCLDevices} -\alias{listOpenCLDevices} +\name{listGPUDevices} +\alias{listGPUDevices} \title{List available GPU devices} \usage{ -listOpenCLDevices() +listGPUDevices() } \description{ -\code{listOpenCLDevices} list available GPU devices +\code{listGPUDevices} list available GPU devices } diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 7f2bc62c..bf8ec7f3 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -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 } @@ -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}, diff --git a/src/RcppGpuInterface.cpp b/src/RcppGpuInterface.cpp index 976c5290..d61ff21e 100644 --- a/src/RcppGpuInterface.cpp +++ b/src/RcppGpuInterface.cpp @@ -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; @@ -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 diff --git a/tests/testthat/test-gpucox.R b/tests/testthat/test-gpucox.R index 3917f154..c439e5db 100644 --- a/tests/testthat/test-gpucox.R +++ b/tests/testthat/test-gpucox.R @@ -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 @@ -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 @@ -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, @@ -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, @@ -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, diff --git a/tests/testthat/test-timevaryingCox.R b/tests/testthat/test-timevaryingCox.R index 6dff9d47..8ff4db8b 100644 --- a/tests/testthat/test-timevaryingCox.R +++ b/tests/testthat/test-timevaryingCox.R @@ -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