NVIDIA CUDA Toolkit Test Script

Bookmark and Share

At GTC18 I mentioned that I created a script to run through all the samples in the CUDA Toolkit. I had a few moments so I thought I’d share the code. You can use the code below to loop through the sample files.

If you are interested in the results I obtained on VMs with the various profiles they are as follows:

If you would like to use the code you’ll want to open up a text editor, like VI, on the system you wish to run this on then copy and paste this code into the file.  Save and close the file (esc : wq). Set permissions on the file to make it executable (chmod +x <filename>). Once you’ve done that you can execute the script in a terminal with a ./<filename> command and let it run.

I offer it as is. The code doesn’t filter out non executable files so you will get messages like the following. “~/NVIDIA_CUDA-9.0_Samples/bin/x86_64/linux/release/FlowCPU.flo: Permission denied

#!/bin/bash

############################################################################
# Created by: Tony Foster
# Version 0.4
# Last modified April 5, 2018
# Description: Iterates through the sample files of the NVIDIA Toolkit and records the output.
# Usage: Free for public use, I wrote this to learn and hopefully it helps others to learn as well.
# Warranty: Offered as is where is with no warranty or statement of fitness expressed or implied. 
#           Use at your own risk.
############################################################################
# location of the samples directory, * is important
FILES=~/NVIDIA_CUDA-9.1_Samples/bin/x86_64/linux/release/*
# File name and location to save results to with month-day-year_hour-minute
SAVETO=~/Documents/testresults_`date +%m-%d-%y_%H-%M`.htm

# Change to the samples directory
cd ~/NVIDIA_CUDA-9.1_Samples/bin/x86_64/linux/release/

# Insure both paths are set so the samples can call the correct libraries 
PATH=/usr/local/cuda/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64

# Create the HTML header files
echo "<html>" >> $SAVETO
echo "<head><title&amp;gt;P4-4Q NVIDIA CUDA Toolkit Results Page</title>" >> $SAVETO
echo "<body>" >> $SAVETO

# Start by capturing the results of the nvidia-smi command 
echo "<H1>Evaluation of NVIDIA CUDA Toolkit Example Files </H1> Card Status: <pre>" >> $SAVETO
nvidia-smi >> $SAVETO
echo "</pre>" >> $SAVETO

# Begin the running of the files and record the start time
echo "Start of run: "`date` >> $SAVETO

# For loop to loop through all the files ($FILES) in the current directory 
for f in $FILES
do 
    echo "<H2> file: $f </H2>" >> $SAVETO
    echo "<pre>" >> $SAVETO
    # Display on screen where we are in the set of files
    echo "$f" 
    # attempt to execute the file and record the results
    "$f" &>> $SAVETO
    # close formatting
    echo "</pre><br>" >> $SAVETO
    echo "<br>" >> $SAVETO
done

# Record the time the run ended 
echo "End of run:" `date` >> $SAVETO

# Capture a post nvidia-smi status
echo "Card Status: <pre>" >> $SAVETO
nvidia-smi >> $SAVETO

# Add footer information to the bottom of the report
echo "</pre>Tests run by Tony Foster - all rights reserved " `date` >> $SAVETO
echo "Published for informational purposes only." >> $SAVETO
echo "Return to <a href='https://wondernerd.net'>wondernerd.net</a>" >> $SAVETO
echo "</body></html>" >> $SAVETO

Let me know if the script is helpful or if you run into any errors using it.

Permanent link to this article: https://www.wondernerd.net/cuda-toolkit-test-script/