Run Linux Commands on NVIDIA Hardware

The NVIDIA® DRIVE and Jetson hardware runs a Linux® distribution as the operating system. Using utilities shipped in the GPU Coder™ Support Package for NVIDIA GPUs, you can remotely execute Linux shell commands on theNVIDIA hardware directly from the MATLAB® command line. For example, you can run and stop an executable, list the contents of a folder, look up the CPU load of a process running on the hardware.CUDA®NVIDIA You can also start an interactive SSH session directly from within MATLAB.

Create a Communication Object

The GPU Coder Support Package for NVIDIA GPUs uses an SSH connection over TCP/IP to execute commands while building and running the generated CUDA code on the DRIVE or Jetson platforms. You can use the infrastructure developed for this purpose to communicate with the NVIDIA hardware. Connect the target platform to the same network as the host computer. Alternatively, use an Ethernet crossover cable to connect the board directly to the host computer. Refer to the NVIDIA documentation on how to set up and configure your board.

To communicate with the NVIDIA hardware, you must create a live hardware connection object by using the drive or jetson function. To create a live hardware connection object, provide the host name or IP address, user name, and password of the target board. For example, to create a live object for the Jetson hardware:

hwobj = jetson('192.168.1.15','ubuntu','ubuntu');

During the hardware live object creation checking of hardware, IO server installation and gathering peripheral info on target are performed. This information is displayed in the command window as shown.

Checking for CUDA availability on the Target...
Checking for NVCC in the target system path...
Checking for CUDNN library availability on the Target...
Checking for TensorRT library availability on the Target...
Checking for Prerequisite libraries is now complete.
Fetching hardware details...
Fetching hardware details is now complete. Displaying details.
 Board name        : NVIDIA Jetson TX2
 CUDA Version      : 9.0
 cuDNN Version     : 7.0
 TensorRT Version  : 3.0
 Available Webcams : UVC Camera (046d:0809)
 Available GPUs    : NVIDIA Tegra X2

Similarly, to create live object for DRIVE hardware:

hwobj = drive('192.168.1.16','nvidia','nvidia');

Note

If there is a connection failure, a diagnostics error message is reported on the MATLAB command line. If the connection has failed, the most likely cause is incorrect IP address or host name.

Execute System Commands on Your NVIDIA Hardware

You can use the system method of the jetson or drive object to execute various Linux shell commands on the NVIDIA hardware from MATLAB. For example, to list the contents of the home folder on the target:

system(hwobj,'ls -al ~')

This statement executes a folder list shell command and returns the resulting text output at the MATLAB command prompt. You can store the result in a MATLAB variable to perform further processing. Establish who is the owner of the .profile file under /home/ubuntu.

output = system(hwobj,'ls -al /home/ubuntu');
ret = regexp(output, '\s+[\w-]+\s+\d\s+(\w+)\s+.+\.profile\s+', 'tokens');
ret{1}

You can also achieve the same result using a single shell command.

system(hwobj,'stat --format="%U" /home/ubuntu/.profile')

You cannot execute interactive system commands using the system() method. To execute interactive commands on the NVIDIA hardware, you must open a terminal session.

openShell(hwobj)

This command opens a PuTTY terminal that can execute interactive shell commands like 'top'.

Run/Stop a CUDA Executable on Your NVIDIA Hardware

To run/stop a CUDA executable, you can use the runExecutable and killApplication methods of the jetson or drive object.

1. To run a CUDA executable you previously run on the NVIDIA hardware, execute the following command on the MATLAB command line:

runExecutable(hwobj,'<executable name>')

where the string '<executable name>' is the name of the CUDA executable you want to run on the NVIDIA hardware.

2. To stop a CUDA executable running on the NVIDIA hardware, execute the following command on the MATLAB command line:

killApplication(hwobj,'<executable name>')

This command kills the Linux process with the name '<executable name>.elf' on the NVIDIA hardware. Alternatively, you can execute the following command to stop the model:

system(hwobj,'sudo killall <executable name>'')

Manipulate Files

The jetson or drive object provides basic file manipulation capabilities. To transfer a file on hardware to your host computer,NVIDIA you use the getFile() method.

getFile(hwobj,'/usr/share/pixmaps/debian-logo.png');

You can then read the PNG file in MATLAB:

img = imread('debian-logo.png');
image(img);

The getFile() method takes an optional second argument that allows you to define the file destination. To transfer a file on your host computer to NVIDIA hardware, you use putFile() method.

putFile(hwobj,'debian-logo.png','/home/ubuntu/debian-logo.png.copy');

Make sure that file is copied.

system(hwobj,'ls -l /home/ubuntu/debian-logo.png.copy')

You can delete files on your NVIDIA hardware using the deleteFile() command.

deleteFile(hwobj,'/home/ubuntu/debian-logo.png.copy');

Make sure that file is deleted.

system(hwobj,'ls -l /home/ubuntu/debian-logo.png.copy')

The command results in an error indicating that the file cannot be found.

See Also

| | | | | | | | |

Related Examples

More About