diff --git a/scripts/test-config-cuda.sh b/scripts/test-config-cuda.sh new file mode 100644 index 00000000..1848174f --- /dev/null +++ b/scripts/test-config-cuda.sh @@ -0,0 +1,72 @@ +#!/bin/bash +set -e + +# require one command line argument +if [ "$#" -ne 1 ] +then + echo "Error: one argument for log location required (e.g. ./gpu-test.log)" + echo "Usage: $0 log-location" + exit 1 +fi + +# set log location from command invokation +LOG_LOC=$1 +TEST_FAIL=false + +# driver +PROC_DRIVER_FILE=/proc/driver/nvidia/version +if [ ! -f "$PROC_DRIVER_FILE" ] +then + echo "$PROC_DRIVER_FILE doesn't exist" | tee -a $LOG_LOC + echo "WARNING: CUDA driver may not be correctly installed." | tee -a $LOG_LOC + TEST_FAIL=true +else + while read line; do + IFS=' ' read -ra tmp_array <<< $line + if [ ${tmp_array[0]} = "NVRM" ] && [ ${tmp_array[1]} = "version:" ] + then + VERSION_DRIVER=${tmp_array[7]} + fi + done < $PROC_DRIVER_FILE +fi + +echo $VERSION_DRIVER | tee -a $LOG_LOC + +# toolkit +if ! TOOLKIT_CHECK_OUTPUT=$(nvcc -V 2>&1); +then + echo "Failed to run 'nvcc -V' with error message: $TOOLKIT_CHECK_OUTPUT" | tee -a $LOG_LOC + echo "WARNING: CUDA toolkit may not be correctly installed." | tee -a $LOG_LOC + TEST_FAIL=true +else + # parse output to get version number + while IFS= read -r line + do + IFS=' ' read -ra tmp_array <<< $line + if [ "${tmp_array[3]}" = "release" ] + then + VERSION_TOOLKIT=${tmp_array[5]} + fi + done <<< $TOOLKIT_CHECK_OUTPUT +fi + +echo $VERSION_TOOLKIT | tee -a $LOG_LOC + +# tensorflow +if ! VERSION_TF_OUTPUT=$(python -c 'import tensorflow as tf; print(tf.__version__)' 2>&1); +then + echo "Error: trying to get tensorflow version: $TF_VERSION" +else + while IFS= read -r line + do + VERSION_TF=$line + done <<< $VERSION_TF_OUTPUT +fi + +echo $VERSION_TF | tee -a $LOG_LOC + +if [ "$TEST_FAIL" = true ] +then + echo "WARNING: at least one of the GPU functionality tests has failed." | tee -a $LOG_LOC + echo "Please run rocker-versioned2/tests/gpu/test-gpu.sh script for more detailed information." | tee -a $LOG_LOC +fi diff --git a/scripts/tests/examples_tf.R b/scripts/tests/examples_tf.R index ca3f933c..3a942ddf 100755 --- a/scripts/tests/examples_tf.R +++ b/scripts/tests/examples_tf.R @@ -1,6 +1,6 @@ ## Tensorflow: -install.packages('keras', repos='http://cran.us.r-project.org') +install.packages('keras') library(keras) mnist <- dataset_mnist() x_train <- mnist$train$x diff --git a/tests/gpu/misc/examples_tf.R b/tests/gpu/misc/examples_tf.R new file mode 100644 index 00000000..3a942ddf --- /dev/null +++ b/tests/gpu/misc/examples_tf.R @@ -0,0 +1,36 @@ + +## Tensorflow: +install.packages('keras') +library(keras) +mnist <- dataset_mnist() +x_train <- mnist$train$x +y_train <- mnist$train$y +x_test <- mnist$test$x +y_test <- mnist$test$y +# reshape +x_train <- array_reshape(x_train, c(nrow(x_train), 784)) +x_test <- array_reshape(x_test, c(nrow(x_test), 784)) +# rescale +x_train <- x_train / 255 +x_test <- x_test / 255 +y_train <- to_categorical(y_train, 10) +y_test <- to_categorical(y_test, 10) +model <- keras_model_sequential() +model %>% + layer_dense(units = 256, activation = 'relu', input_shape = c(784)) %>% + layer_dropout(rate = 0.4) %>% + layer_dense(units = 128, activation = 'relu') %>% + layer_dropout(rate = 0.3) %>% + layer_dense(units = 10, activation = 'softmax') + + model %>% compile( + loss = 'categorical_crossentropy', + optimizer = optimizer_rmsprop(), + metrics = c('accuracy') + ) + history <- model %>% fit( + x_train, y_train, + epochs = 30, batch_size = 128, + validation_split = 0.2 + ) +model %>% evaluate(x_test, y_test) diff --git a/tests/gpu/misc/nvblas.R b/tests/gpu/misc/nvblas.R new file mode 120000 index 00000000..499cf1a8 --- /dev/null +++ b/tests/gpu/misc/nvblas.R @@ -0,0 +1 @@ +../../ml/nvblas.R \ No newline at end of file diff --git a/tests/ml/nvblas.R b/tests/ml/nvblas.R new file mode 100644 index 00000000..c0bbbda4 --- /dev/null +++ b/tests/ml/nvblas.R @@ -0,0 +1,11 @@ +install.packages("callr") + + +callr::r(function(){ + system.time({ + N <- 2^14 + M <- matrix(rnorm(N*N), nrow=N, ncol=N) + M %*% M + }) + }, env = c(LD_PRELOAD="libnvblas.so") +)