Skip to content

Commit

Permalink
set up rstudio-gpu template #101
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkEdmondson1234 committed Feb 14, 2019
1 parent 0ed73a1 commit b0a117c
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 66 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Fix project-id error if numbers in project (#72)
* Block users using "rstudio" as a login name
* Remove defunct example from `gce_schedule_docker`
* Support GPU images for Tensorflow, keras etc. (#101)
* Support GPU images for Tensorflow, keras etc. (#101) via `gce_vm_gpu()` and `gce_vm(template = "rstudio-gpu")` (#101)
* Support common instance metadata by supply `gce_set_metadata(instance = "project-wide")`
* Support minCpuPlatform in instance creation and via `gce_set_mincpuplatform()` (#112)

Expand Down
60 changes: 30 additions & 30 deletions R/gpus.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#' A deeplearning templated VM for use with gce_vm_template
#' @noRd
set_gpu_template <- function(dots){
dots$return_dots <- TRUE
do.call(gce_vm_gpu, args = dots)
}


#' Retrieves a list GPUs you can attach to an instance
#'
#' @seealso \href{https://cloud.google.com/compute/docs/gpus/add-gpus#create-new-gpu-instance}{Google Documentation}
#' @seealso \href{https://cloud.google.com/compute/docs/gpus/#introduction}{GPUs on Compute Engine}
#'
#'
#' @details
#' Authentication scopes used by this function are:
#' \itemize{
#' \item https://www.googleapis.com/auth/cloud-platform
#' \item https://www.googleapis.com/auth/compute
#' \item https://www.googleapis.com/auth/compute.readonly
#' }
#'
#' @details
#'
#' To filter you need a single string in the form \code{field_name eq|ne string}
#' e.g. \code{gce_list_instances("status eq RUNNING")} where \code{eq} is 'equals' and \code{ne} is 'not-equals'.
Expand All @@ -31,8 +31,7 @@ gce_list_gpus <- function(filter = NULL,
project = gce_get_global_project(),
zone = gce_get_global_zone()) {

warning("This is using the beta version of the Google Compute Engine API and may not work in the future.")
url <- sprintf("https://www.googleapis.com/compute/beta/projects/%s/zones/%s/acceleratorTypes",
url <- sprintf("https://www.googleapis.com/compute/v1/projects/%s/zones/%s/acceleratorTypes",
project, zone)
pars <- list(filter = filter,
maxResults = maxResults,
Expand All @@ -57,64 +56,65 @@ gce_list_gpus <- function(filter = NULL,
#' Helper function that fills in some defaults passed to \link{gce_vm}
#'
#' @param ... arguments passed to \link{gce_vm}
#' @param return_dots If TRUE will only return default options in a list, not launch the VM
#'
#' @details
#'
#' If not specified, this function will enter defaults to get a GPU instance up and running.
#'
#' \itemize{
#' \item \code{use_beta: TRUE}
#' \item \code{acceleratorCount: 1}
#' \item \code{acceleratorType: "nvidia-tesla-k80"}
#' \item \code{scheduling: list(onHostMaintenance = "terminate", automaticRestart = TRUE)}
#' \item \code{image_project: "centos-cloud"}
#' \item \code{image_family: "centos-7"}
#' \item \code{predefined_type: "n1-standard-1"}
#' \item \code{metadata: the contents of the the startup script in
#' system.file("startupscripts", "centos7cuda8.sh", package = "googleComputeEngineR")}
#' \item \code{acceleratorType: "nvidia-tesla-p4"}
#' \item \code{scheduling: list(onHostMaintenance = "TERMINATE", automaticRestart = TRUE)}
#' \item \code{image_project: "deeplearning-platform-release"}
#' \item \code{image_family: "tf-latest-cu92"}
#' \item \code{predefined_type: "n1-standard-8"}
#' \item \code{metadata: "install-nvidia-driver" = "True"}
#' }
#'
#' @family GPU instances
#' @export
#'
#' @seealso \href{Deep Learning VM}{https://cloud.google.com/deep-learning-vm/docs/quickstart-cli}
#'
#' @return A VM object
gce_vm_gpu <- function(...){
gce_vm_gpu <- function(..., return_dots = FALSE){

dots <- list(...)

if(is.null(dots$scheduling)){
dots$scheduling <- list(
onHostMaintenance = "terminate",
onHostMaintenance = "TERMINATE",
automaticRestart = TRUE
)
}

if(is.null(dots$acceleratorCount)){

dots$acceleratorCount <- 1
dots$acceleratorType <- "nvidia-tesla-k80"
dots$acceleratorType <- "nvidia-tesla-p4"
}

if(is.null(dots$image_project)){
dots$image_project <- "centos-cloud"
dots$image_project <- "deeplearning-platform-release"
}

if(is.null(dots$image_family)){
dots$image_family <- "centos-7"
dots$image_family <- "tf-latest-cu92"
}

if(is.null(dots$predefined_type)){
dots$predefined_type <- "n1-standard-1"
dots$predefined_type <- "n1-standard-8"
}

dots$use_beta <- TRUE

if(is.null(dots$metadata)){
startup_file <- system.file("startupscripts", "centos7cuda8.sh", package = "googleComputeEngineR")
dots$metadata <- list("startup-script" = readChar(startup_file,
nchars = file.info(startup_file)$size))
dots$metadata <- list("install-nvidia-driver" = "True")
} else {
dots$metadata <- c(list("install-nvidia-driver" = "True"), dots$metadata)
}

myMessage("Launching VM with GPU support. If using docker_cmd() functions make sure to include nvidia=TRUE parameter", level = 3)

do.call(gce_vm,
args = dots)

Expand Down
13 changes: 12 additions & 1 deletion R/template.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,30 @@ gce_vm_template <- function(template = c("rstudio","shiny","opencpu",
password = password,
dynamic_image = dynamic_image)

if(grepl("gpu$", template)){
# setup GPU specific options
dots <- set_gpu_template(dots)
}

## metadata
upload_meta <- list(template = template)
if(grepl("rstudio", template)){
upload_meta$rstudio_users <- username
}

if(is.null(dots$metadata)){
metadata <- upload_meta
} else {
metadata <- c(upload_meta, dots$metadata)
}

## build VM
job <- do.call(gce_vm_container,
c(dots, list(
cloud_init = cloud_init_file,
image_family = image_family,
tags = list(items = list("http-server")), # no use now
metadata = upload_meta
metadata = metadata
)))

if(wait){
Expand Down
6 changes: 4 additions & 2 deletions R/vms.R
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ gce_vm_delete <- function(instance,
#'
#' @section GPUs:
#'
#' You can add GPUs to your instance, but they must be present in the zone you have specified. Refer to \href{https://cloud.google.com/compute/docs/gpus/#introduction}{this} link for a list of current GPUs per zone.
#' Some defaults for launching GPU enabled VMs are available at \link{gce_vm_gpu}
#'
#' You can add GPUs to your instance, but they must be present in the zone you have specified - use \link{gce_list_gpus} to see which are available. Refer to \href{https://cloud.google.com/compute/docs/gpus/#introduction}{this} link for a list of current GPUs per zone.
#'
#' @inheritParams Instance
#' @inheritParams gce_make_machinetype_url
Expand All @@ -224,7 +226,7 @@ gce_vm_delete <- function(instance,
#' @param dry_run whether to just create the request JSON
#' @param disk_size_gb If not NULL, override default size of the boot disk (size in GB)
#' @param use_beta If set to TRUE will use the beta version of the API. Should not be used for production purposes.
#' @param acceleratorCount Number of GPUs to add to instance
#' @param acceleratorCount Number of GPUs to add to instance. If using this, you may want to instead use \link{gce_vm_gpu} which sets some defaults for GPU instances.
#' @param acceleratorType Name of GPU to add, see \link{gce_list_gpus}
#'
#' @return A zone operation, or if the name already exists the VM object from \link{gce_get_instance}
Expand Down
12 changes: 0 additions & 12 deletions inst/startupscripts/centos7cuda8.sh

This file was deleted.

9 changes: 1 addition & 8 deletions man/gce_list_gpus.Rd

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

1 change: 1 addition & 0 deletions man/gce_set_metadata.Rd

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

2 changes: 1 addition & 1 deletion man/gce_vm.Rd

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

6 changes: 4 additions & 2 deletions man/gce_vm_create.Rd

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

20 changes: 11 additions & 9 deletions man/gce_vm_gpu.Rd

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

0 comments on commit b0a117c

Please sign in to comment.