Sunteți pe pagina 1din 38

Laboratory Manual

For

Programming Lab III

By

Fizzible
PRECAUTIONS:
 Each and every GPIO must be strictly used at 3.3v only and not more than that.
Supplying and sourcing voltage levels more than 3.3v will definitely damage
the BeagleBone Black.
 Analog in voltages are 1.8v max. Application of >1.8v to any A/D pin will
damage the processor.
 Before giving input to a GPIO it must be declared as input strictly, otherwise the
board may not respond thereafter.
 BeagleBone Black can source only 6ma through a GPIO. So high current
applications need to use respective hardware circuitry.
 External voltage greater than 3.3v starts damaging the BeagleBone Black slowly
and within few hours it completely damages the board.
 Do not apply any voltages to any I/O pins when the board is not powered on.
 Do not drive any external signals into the I/O pins until after the SYS_RESETn
signal is HI (3.3V).
 If you are applying signals from other boards into the expansion headers, make
sure you power the board up after you power up the BeagleBone Black or make
the connections after power is applied on both boards.
 Powering the processor via its I/O pins can cause damage to the processor.

Laboratory Manual for Programming Lab III Visit- fizzible.com 2


Table of Contents

1 Introduction to the BeagleBone Black . . . . 4

2 Gettting started with the BeagleBone Black . . . . 8

3 Getting SSH access . . . . . . . . 13

4 Running your first program on the BeagleBone Black . . . 15

5 Lab Experiments . . . . . . . . 17

Laboratory Manual for Programming Lab III Visit- fizzible.com 3


1
Introduction to the BeagleBone Black

 Introduction:

The BeagleBone Black is the newest member of the BeagleBoard family. It is a lower-
cost, high-expansion focused BeagleBoard using a low cost Sitara XAM3359AZCZ100
Cortex A8 ARM processor from Texas Instruments. It is similar to the BeagleBone, but
with some features removed and some features added.
The table below gives the high points on the differences between the BeagleBone and
BeagleBone Black.

Beagle boards are tiny computers with all the capability of today’s desktop machines,
without the bulk, expense, or noise. The BeagleBone Black is a low-power open-source
hardware single-board computer produced by Texas Instruments in association with Digi-
Key and Newark element14. The BeagleBone was also designed with open source
software development in mind, and as a way of demonstrating the Texas Instrument's
OMAP3530 system-on-a-chip. The board was developed by a small team of engineers as

Laboratory Manual for Programming Lab III Visit- fizzible.com 4


an educational board that could be used in colleges around the world to teach open source
hardware and software capabilities.

 BeagleBone Black Features:

 Sitara AM335x ARM cortex – A8 processor: The board is based on the Sitara
AM335x ARM Cortex-A8 processor from Texas Instruments Incorporated (TI), It
provides 1-GHz performance – 150 percent higher performance than ARM11 for
more advanced user interfaces and computation power.
 DC power: +5V DC power can be supplied to the BeagleBone through a barrel
connector or from the mini-USB, both of which are located near the large RJ45
Ethernet connector.
 2 GB on-board storage using eMMC: In addition to all the features of the
previous board (BeagleBone), the Beaglebone black now uses embedded
nonvolatile memory system using eMMC, which frees the MicroSD slot to be
used for additional storage.
 512MB DDR3: The board is having 512 megabytes of low-power DDR3L RAM,
doubling the size and speed of the volatile memory and ensuring it will execute
software faster.
 PMIC: The board uses a TI TPS65217B PMIC to generate stable supply voltages
regardless of input power variation.
 Boot button: Boot button is used to boot the Beaglebone black directly from an
external microSD card. You can boot the Beaglebone Black from an external SD
card by holding down the BOOT button when applying the power
 Micro HDMI: with this microHDMI we can connect directly to monitors and
TVs.
 USB host: USB 2.0 type A host port.
 10/100 Ethernet: 10/100 Ethernet RJ45 socket, IPv4 and IPv6 networking.
 MicroSD slot: MicroSD slot for additional user data or operating systems.

Laboratory Manual for Programming Lab III Visit- fizzible.com 5


 Expansion headers: The expansion interface on the board is comprised of two 46
pin connectors. All signals on the expansion headers are 3.3v unless otherwise
indicated.

The following table lists the key features of the BeagleBone Black.

Laboratory Manual for Programming Lab III Visit- fizzible.com 6


 BeagleBone Black Key Component Locations:

Here are the locations of the key components on the Rev A5A.

 BeagleBone Black Connector and Switch Locations:

Below is the location of the connectors and switches on the Rev A5A board. The Power Button
and Battery Connections are new additions to the Rev A5A.

Laboratory Manual for Programming Lab III Visit- fizzible.com 7


2
Getting Started with the BeagleBone Black

Read the step-by-step getting started part below to begin developing with your
BeagleBone Black in minutes.

 Getting started:

Step 1: Plug in your BeagleBone black via USB.

Use the provided USB cable to plug your Beagle into your computer. This will both
power the board and provide a development interface. BeagleBone Black will boot Linux
from the on-board 2GB eMMC. Either BeagleBone Black or original BeagleBone may
also boot from a microSD card.
BeagleBone Black will operate as a flash drive providing you with a local copy of the
documentation and drivers. Note that this interface may not be used to re-configure the
microSD card with a new image, but may be used to update the boot parameters using the
uEnv.txt file.

You'll see the PWR LED lit steadily. Within 10 seconds, you should see the other LEDs
blinking in their default configurations.

 USR0 is configured at boot to blink in a heartbeat pattern.


 USR1 is configured at boot to light during microSD card accesses.
 USR2 is configured at boot to light during CPU activity.
 USR3 is configured at boot to light during eMMC accesses.

Laboratory Manual for Programming Lab III Visit- fizzible.com 8


Step 2: Install drivers.
Install the drivers for your operating system to give you network-over-USB access to
your Beagle. Additional drivers give you serial access to your board.

Operating Usb drivers Comments


system

Windows (64- 64-bit installer If in doubt, try the 64-bit installer first.
bit)
 Note #1: Windows Driver Certification
warning may pop up two or three times.
Click "Ignore", "Install" or "Run".
Windows (32- 32-bit installer  Note #2: On systems without the latest
bit) service release, you may get an error
(0xc000007b). In that case, please install
the following and retry:

http://www.microsoft.com/en-
us/download/confirmation.aspx?id=13523

 Note #3: You may need to reboot


Windows.

MAC OS X Network serial Install both sets of drivers


Linux Mkudevrule.sh Driver installation isn't required, but you might
find a few udev rules helpful.

Laboratory Manual for Programming Lab III Visit- fizzible.com 9


Note: Additional FTDI USB to serial/JTAG information and drivers are available from

“http://www.ftdichip.com/Drivers/VCP.htm.”

Note: Additional USB to virtual Ethernet information and drivers are available from

“http://www.linux-usb.org/gadget/” / “http://joshuawise.com/horndis“

Step 3: Browse to your beagle.

Using either Chrome or Firefox (Internet Explorer will NOT work), browse to the web
server running on your board. It will load a presentation showing you the capabilities of
the board. Use the arrow keys on your keyboard to navigate the presentation.

*Older software images require you to EJECT the BEAGLE_BONE drive to start
the network. With the latest software image, that step is no longer required.

Laboratory Manual for Programming Lab III Visit- fizzible.com 10


 Expanding the Storage Partition on microSD

If you have installed a Linux distribution on your microSD you can modify the root file
system partition. You are then able to utilize all of the space on your microSD card
regardless of the size of the default partition of your given image. Follow the instructions
found on Expanding File System Partition on a MicroSD.

Note: The instructions on that page are general and are not guaranteed to work on every
Linux distribution.

 BoneScript

Bonescript is a Node.js library specifically optimized for the Beagle family, featuring
familiar Arduino function calls, exported to the browser. The BoneScript library provides
several functions useful for interacting with your hardware.

 Copy commands:

Copying a computer program to the BeagleBone black


If you want to copy a program you have written on your computer to the BeagleBone.
You can do it using the scp command. The scp command can be used in the following
ways.
To copy from computer to BeagleBone.
Syntax:
scp <source_file_location> <user_name@ip_of_remote_host:destination_location>
Example:
scp myprogram.py root@192.168.7.2:/root/
To copy from BeagleBone to Computer
Syntax:
scp <user_name@ip_of_remote_host:source_location> <destination_location>

Laboratory Manual for Programming Lab III Visit- fizzible.com 11


Example:
scp root@192.168.7.2:/root/myProgram.py /home/XYZ/Documents

 Cloud9 IDE
If you want to program the board using a complete IDE, a JavaScript IDE is available
with BeagleBone by default. To start cloud9 IDE type the following in the URL bar of
your browser.
192.168.7.2:3000

A complete IDE Cloud9 as can be seen in the above image will get started within your
browser. This can be used to program on BBB using JavaScript.

Laboratory Manual for Programming Lab III Visit- fizzible.com 12


3
Getting SSH Access
SSH is used to take control of the BeagleBone Black to get a root shell
access to the bone.

 SSH:
SSH (SSH client) is a program for logging into a remote machine and for executing
commands on a remote machine. SSH connects and logs into the specified host name
(with optional user name). The user must prove his/her identity to the remote machine
using one of several methods depending on the protocol version used. If command is
specified, it is executed on the remote host instead of a login shell.

Procedure:
1. Connect the BeagleBone to your computer with the USB cable provided.
2. Wait for the notification of active wire connection.
3. Press (Ctrl+Alt+T) to open a terminal, type the following terminal:

“ssh root@192.168.7.2”

4. If prompted, type yes and press Enter.

As you can see in the image below, when we were typing the ssh command the shell we
were getting was of the computer. But after getting access to BeagleBone Black, we are
getting the shell of the root user on the BeagleBone. Whatever the commands we type
here now will run on the BeagleBone Black.

Laboratory Manual for Programming Lab III Visit- fizzible.com 13


 List of common Linux commands:
 echo - print/dump value
 pwd - show current directory
 env - dump environment
 cd - change current directory
variables
 ls - list directory contents
 export - set environment variable
 chmod - change file
 history - dump command history
permissions
 grep - search dump for strings
 chown - change file ownership
 man - get help on command
 cp - copy files
 apropos - show list of man pages
 mv - move files
 find - search for files
 rm - remove files
 tar - create/extract file archives
 mkdir - make directory
 gzip - compress a file
 rmdir - remove directory
 gunzip - decompress a file
 cat - dump file contents
 du - show disk usage
 less - progressively dump file
 df - show disk free space
 vi - edit file (complex)
 mount - mount disks
 nano - edit file (simple)
 tee - write dump to file in
 head - trim dump to top
parallel

Laboratory Manual for Programming Lab III Visit- fizzible.com 14


4
Running your First Program on the BeagleBone Black

BeagleBone is a complete single board computer (SBC). Hence it can be used to program
with any language of your choice. For writing our first program on the BBB we'll use
python and C.

To get started we'll need a shell access to the BeagleBone, (Shell access procedure is
mentioned in chapter 3).

 Writing your first program using Python:

To write the program on terminal we will use a simple text editor for terminal
called as 'Nano'. To write a HelloWorld program using nano on terminal type the
following on terminal.
nano HelloWorld.py
The above command will start the Nano text editor and create the file HelloWorld.py file.
You can type your code for python in the editor. A simple hello world in Python will be
print “HelloWorld”
To save the code press Ctrl + X and press Y and then Enter. All the keyboard shortcuts
for nano are listed at the bottom of the nano interface.
The program's output can be seen in the following way.
root@beaglebone:~# python HelloWorld.py
OUTPUT: Hello World
 Writing your first program using C:

To program in C the similar procedure as done for python can be used.


Open the Nano text editor and create the HelloWorld.c file

Laboratory Manual for Programming Lab III Visit- fizzible.com 15


root@beaglebone:~# nano HelloWorld.c
Type your code for the program in the window of the Nano text editor. Simple hello
world program for C would be

#include<stdio.h>
int main(void)
{
puts(“\n\t Hello World”);
return 0;
}
Save the program using Ctrl + X and press Y and enter.
To compile the code type
root@beaglebone:~# gcc HelloWorld.c
To view the output of code type
root@beaglebone:~# ./a.out
OUTPUT: Hello World
Similarly the programs can also be written for other languages. You can also use other
terminal text editors like Vi of your choice as well. Happy Coding!

Laboratory Manual for Programming Lab III Visit- fizzible.com 16


5
Lab Experiments

Experiment 1: Elevator/Lift Simulation.

 Problem statement:

Develop an application using BeagleBone Black / ARM Cortex A5 development board to


simulate the operations of LIFT.
 Procedure:
 Connect the BeagleBone Black to your computer with the USB cable. After
connecting the BeagleBone black to your computer few blue L.E.D’s will glow
indicating that the bone is now powered.
Laboratory Manual for Programming Lab III Visit- fizzible.com 17
 Now you will see a notification saying “Wired connection is now active” on your
desktop.
 Now open the terminal (CTRL+ALT+T) of your Linux desktop.
 Write the following command in your terminal:
“Ssh root@192.168.7.2”
*This command will let you access the operating system of your BeagleBone
black.
 Now to open the editor for writing the program code type the following command:
“Nano programname (your program name without spaces).py”
Ex: nano lift.py
 Now start writing your program in the editor which is opened on your screen.
 You can save your program by pressing “CTRL+O”.
 Now to exit out from the editor, press “CTRL+X”.
 You can now again see the terminal on your screen.
 To execute the program you have saved write the following command:
“Python programname.py”
Ex: python lift.py.
Laboratory Manual for Programming Lab III Visit- fizzible.com 18
 Now connect the BeagleBone black to your elevator simulator card using the FRC
cable.
 Now you can see the red L.E.D is on, indicating the board is powered up properly.
 On the elevator simulator card you can see the 5 push button representing 5
different floors.

 Besides the push button switches you can see two L.E.D’s (red & green); red
indicating the lift is at halt and green indicating the lift is in motion.
 After pressing any of the push button switch you can you can see the status of the
lift by the following two things:
o The arrow L.E.D’s shows the direction of the lift i.e. upwards or
downwards.
o The seven segment displays shows the current floor of the lift.

Laboratory Manual for Programming Lab III Visit- fizzible.com 19


Experiment 2: Traffic Light Simulation

 Problem statement:

Develop an application using BeagleBone Black/ ARM Cortex A5 development board to


simulate the working of signal lights.
 Procedure:
 Connect the BeagleBone black to your computer with the USB cable. After
connecting the BeagleBone black with your computer few blue L.E.D’s will glow
indicating that the bone is now powered.
 Now you will see a notification saying “wired connection is now active” on your
desktop.
 Now open the terminal (CTRL+ALT+T) of your Linux desktop.
 Write the following command in your terminal:
“ssh root@192.168.7.2”

Laboratory Manual for Programming Lab III Visit- fizzible.com 20


*This command will let you access the operating system of your BeagleBone
black.

 Now to open the editor for writing the program code type the following command:
“Nano programname (your program name without spaces).py”
Ex: nano trafficlight.py
 Now start writing your program in the editor which is opened on your screen.
 You can save your program by pressing “CTRL+O”.
 Now to exit out from the editor, press “CTRL+X”.
 You can now again see the terminal on your screen.
 To execute the program you have saved write the following command:
“Python programname.py”
Ex: python trafficlight.py.
 Now connect the BeagleBone Black to your traffic light simulator card using the
FRC cable.
 Connect the power adapter (5V 2A) to the traffic light simulator card.
 Now you can see the red L.E.D is on, indicating the board is powered up properly.
 On the traffic light simulator card you can see a four way which has 4 traffic
signals.

Laboratory Manual for Programming Lab III Visit- fizzible.com 21


The traffic signals are represented by red, yellow and green L.E.D’S indicating
STOP, BEWARE AND GO respectively.
 Once the program is executed, the traffic light signal will function accordingly.
When the green light of one signal is ON the corresponding red light of the other 3
signals will be ON.

 The time required to wait between red and yellow light is displayed on the seven
segment display. Also the time required for transition between the yellow and
green light is also displayed on the same.

Laboratory Manual for Programming Lab III Visit- fizzible.com 22


Experiment 3: Stepper Motor Simulation
 Problem statement:

Develop Robotics (stepper motor) Application using BeagleBone Black.


 Procedure:
 Connect the BeagleBone black to your computer with the USB cable. After
connecting the BeagleBone black with your computer few blue L.E.D’s will glow
indicating that the bone is now powered.
 Now you will see a notification saying “wired connection is now active” on your
desktop.
 Now open the terminal (CTRL+ALT+T) of your Linux desktop.
 Write the following command in your terminal:
“ssh root@192.168.7.2”
*This command will let you access the operating system of your BeagleBone
black.
 Now to open the editor for writing the program code type the following command:
“Nano programname (your program name without spaces).py”
Ex: nano trafficlight.py
 Now start writing your program in the editor which is opened on your screen.
 You can save your program by pressing “CTRL+O”.
 Now to exit out from the editor, press “CTRL+X”.
 You can now again see the terminal on your screen.
 To execute the program you have saved write the following command:
“Python programname.py”
Ex: python trafficlight.py.
 Now connect the BeagleBone Black to your traffic light simulator card using the
FRC cable.
 Connect the power adapter (5V 2A) to the stepper motor simulator card.
Laboratory Manual for Programming Lab III Visit- fizzible.com 23
 Now you can see the red L.E.D is on, indicating the board is powered up properly.
 On the stepper motor card you can see a gear attached to a motor which will rotate
clockwise or anticlockwise according to the changes made in the code. You can
also move the motor with a desired step angle.
 Once the program is executed the motor will start rotating either
clockwise/anticlockwise.

The sequence bits (denoted by blue L.E.D’s) will change according to each step the

motor takes.

Laboratory Manual for Programming Lab III Visit- fizzible.com 24


Experiment 4: IP Application
 Problem Statement:
Develop a network based application by setting up IP address on BeagleBoard/ ARM
Cortex A5.

 Objective:
By the end of this experiment you should be able to:
1) Understand what IP address is and how to change it on a Linux computer.
2) Remotely access the BeagleBone over a local network.
3) Access the GUI of the BeagleBone remotely on another computer.
4) Understand the concepts of SSH and VNC.

 Concepts:
1) IP Address:
Internet Protocol Address (or IP Address) is a unique address that computing device use
to identify itself and communicate with other devices in the Internet Protocol network.
Any device connected to the IP network must have a unique IP address within its
network. An IP address is analogous to a street address or telephone number in that it is
used to uniquely identify a network device to deliver mail message, or call ("view") a
website.

1.1) The Format of an IP Address:


The format of an IP address is a 32-bit numeric address written as four numbers separated
by periods. Each number can be zero to 255. For example, 1.160.10.240 could be an IP
address.

Laboratory Manual for Programming Lab III Visit- fizzible.com 25


2) What is an SSH? :
SSH (SSH client) is a program for logging into a remote machine and for executing
commands on a remote machine.
SSH connects and logs into the specified hostname (with optional user name). The user
must prove his/her identity to the remote machine using one of several methods
depending on the protocol version used.
If command is specified, it is executed on the remote host instead of a login shell.

3) VNC:
In computing, Virtual Network Computing (VNC) is a graphical desktop sharing system
that uses the Remote Frame Buffer protocol (RFB) to remotely control another computer.
It transmits the keyboard and mouse events from one computer to another, relaying the
graphical screen updates back in the other direction, over a network.

 Software Required:
For SSH:
If you're using Windows then the software “Putty” is required. But if you're using Ubuntu
OS, no special software is required.

For VNC:
Install VNC viewer.
X11-VNC-server has to be installed on the BeagleBone.

 Procedure:
Initial configuration (Before connecting the BeagleBone to the network)
1. Connect the BeagleBone to your computer with the USB cable provided.
2. Wait for the notification of active wire connection.
3. Press Ctrl+Alt+T to open a terminal, type the following terminal:
ssh root@192.168.7.2
4. If prompted, type yes and press Enter.
Laboratory Manual for Programming Lab III Visit- fizzible.com 26
Fig: Getting ssh access to the BeagleBone.

5. View the current IP address configurations of the BeagleBone by the following


command:
ifconfig
6. The output will be the list of network interfaces which are available for creating a
network with the BeagleBone, and their respective configurations.

Fig: Output of the ifconfig command

7. The configuration file of the IP address setting is located in /etc/network/interfaces


Laboratory Manual for Programming Lab III Visit- fizzible.com 27
8. To edit the IP address configurations type the following command:
nano /etc/network/interfaces
9. Next we'll configure the eth0 interface. Uncomment the line 'iface eth0 inet dhcp'
10. Change it to 'iface eth0 inet static'

11. Enter the configurations details below the changed line for eth0 as follows:
address 10.0.1.37
netmask 255.255.255.0
network 10.0.1.0
gateway 10.0.1.1
12. Exit by pressing Ctrl+X.
13. In prompt: Press Y to save the changes and press Enter.
14. To shut down the BeagleBone:, type the following command:
shutdown -h now.
15. Unplug the BeagleBone from your computer and connect it to your network
(Ethernet cable).
16. Switch on the BeagleBone using the external 5 volt power adapter.

Laboratory Manual for Programming Lab III Visit- fizzible.com 28


17. Open the terminal in your computer and try pinging the address which you set in
the interfaces configurations. For that type the command:
Ping 10.0.1.37
18. If you can ping to the particular address that means the BeagleBone has started.
19. If you cannot ping, check the IP configurations again and try restarting the
BeagleBone.
20. Next, type in:
ssh root@10.0.1.37
If prompted, type yes and press Enter.

 Installing the VNC software on the BeagleBone black:


1. Type the following command:
apt-get update
(This will update the software packages repositories on the BeagleBone)
2. After the update, type:
apt-get install x11vnc
When prompted press Y and Enter.
 Accessing the BeagleBone GUI through VNC:

1. Next, we need to start the X11 VNC server on the BeagleBone Black to access its
GUI.
2. We need to start X11 VNC server, type the following command:

x11vnc -bg -o %HOME/ .x11vnc.log.%VNCDISPLAY -auth /var/run/lightdm/root/ :0 –forever

3. Avoid repeatedly typing this command, copy this command into a shell file and
when this command is in use, just run that shell file.

4. To create a shell file:


nano filename.sh
5. Type the command in the file. Save it.
Laboratory Manual for Programming Lab III Visit- fizzible.com 29
6. To make the shell file executable type:
chmod +x filename.sh
7. While running the file when command is in use:
./filename.sh
8. In your computer, open Remmina Remote Desktop Client.
9. Create a new file, enter the IP of the BeagleBone in the server field, i.e. 10.0.1.37
10. Click on Connect.
11. A small window will open, select console in the module field, click connect.
The BeagleBone GUI will be displayed.

This method can be used to connect to the Beagle Bone using any device which has an
SSH client and a VNC client like Computers, Laptops, tablets & Phones.

Laboratory Manual for Programming Lab III Visit- fizzible.com 30


Experiment 5: Parallel Quick Sort Algorithm
 Problem Statement:
Implement a Parallel Quick Sort algorithm using NVIDIA GPU or equivalent ARM
board.
 CUDA:
Introduction:
CUDA® is a parallel computing platform and programming model invented by NVIDIA.
It enables dramatic increases in computing performance by harnessing the power of the
graphics processing unit (GPU).

System Requirements

To use CUDA on your system, you will need the following installed:

 CUDA-capable GPU
 A supported version of Linux with a gcc compiler and toolchain
 NVIDIA CUDA Toolkit (available at http://developer.nvidia.com/cuda-
downloads.

 Verify You Have a CUDA-Capable GPU.

To verify that your GPU is CUDA-capable, go to your distribution's equivalent of System


Properties, or, from the command line, enter:

$lspci | grep -i nvidia

If you do not see any settings, update the PCI hardware database that Linux maintains by
entering update-pciids (generally found in/ sbin) at the command line and retun the
previous lspci command.

Laboratory Manual for Programming Lab III Visit- fizzible.com 31


 Verify the System Has gcc Installed.

The gcc compiler is required for development using the CUDA Toolkit. It is not required
for running CUDA applications. It is generally installed as part of the Linux installation,
and in most cases the version of gcc installed with a supported version of Linux will work
correctly.

To verify the version of gcc installed on your system, type the following on the command
line:

$gcc --version

If an error message displays, you need to install the development tools from your Linux
distribution or obtain a version of gcc and its accompanying tool chain from the Web.

 Verify the Driver Version.

If you installed the driver, verify that the correct version of it is installed.

This can be done through your System Properties (or equivalent) or by executing the
command
Note that this command will not work on an iGPU / dGPU system.

 Compiling the Examples.

The version of the CUDA Toolkit can be checked by running nvcc-C in a terminal
window. The nvcc command runs the compiler driver that compiles CUDA programs. It
calls the gcc compiler for C code and the NVIDIA PTX compiler for the CUDA code.
The NVIDIA CUDA Toolkit includes sample programs in source form. You should
compile them by changing to ~/NVIDIA_CUDA-6.5_Samples and typing make. The
resulting binaries will be placed under ~/NVIDIA_CUDA-6.5_Samples/bin.

Laboratory Manual for Programming Lab III Visit- fizzible.com 32


 Running the Binaries.

After compilation, find and run deviceQuery under ~/NVIDIA_CUDA-6.5_Samples. If


the CUDA software is installed and configured correctly, the output for
deviceQuery should look similar to that shown in the figure below:

Valid Results from deviceQuery CUDA Sample

The exact appearance and the output lines might be different on your system. The
important outcomes are that a device was found (the first highlighted line), that the
device matches the one on your system (the second highlighted line), and that the test
passed (the final highlighted line).

If a CUDA-capable device and the CUDA Driver are installed but Valid Results from
deviceQuery CUDA Sample Reports that no CUDA-capable devices are present, this likely
means that the /dev/nvidia* files are missing or have the wrong permissions.

On systems where SELinux is enabled, you might need to temporarily disable this
security feature to run deviceQuery. To do this, type:
$setenforce 0
Laboratory Manual for Programming Lab III Visit- fizzible.com 33
From the command line as the superuser.

Running the bandwidth Test program ensures that the system and the CUDA-capable
device are able to communicate correctly. Its output is shown in the figure below.

Valid Results from bandwidthTest CUDA Sample.

Note that the measurements for your CUDA-capable device description will vary from
system to system. The important point is that you obtain measurements, and that the
second-to-last line (in the above figure) confirms that all necessary tests passed.

Should the tests not pass, make sure you have a CUDA-capable NVIDIA GPU on your
system and make sure it is properly installed.

If you run into difficulties with the link step (such as libraries not being found), consult
the Linux Release Notes found in the doc folder in the CUDA Samples directory.

 Compile and Run CUDA C/C++ Programs


Programs must be compiled into binary code by nvcc to execute on the device.

Laboratory Manual for Programming Lab III Visit- fizzible.com 34


 Parallel Quicksort :

 Algorithm:

// Let 0 < i < p-1 and p denote the local thread index and thread count .
QSort (e = <e1,.....,en>)
begin
if n < M then return SmallSort(e)
if i = 0 then pick a pivot d belongs to e
Laboratory Manual for Programming Lab III Visit- fizzible.com 35
ai := bi := ci := 0
t := e
for i*n/p <= j <= (( i+1)*(n/p)) do
if t[ j ] < d then ai ++
else if t[ j ] = d then bi++
else ci++
end
scan(a0,.....,ap-1)
scan(b0,.....,bp-1)
scan(c0,......,cp-1)
for i*n/p <= j <= ((i+1)*(n/p))
if t[ j ] < d then e [ ai ] := t [ j ] ai++
else if t[ j ] = d then e[ bi ] := t[ j ] bi++
else e [ ci ] := t[ j ] ci++
end
return
Concatenate(Qsort(<e1,.....,e[ai] >), < e[ ai+1 ],........,e[ bi ]>), Qsort(<e[ bi+1],......,en>))
end

 Process
Command Line Procedure
Step 1: Save your program with the extension .cu let say example.cu.
Step 2: Open Terminal and locate your program directory.
Step 3: Type in command prompt (Terminal in Linux) nvcc example.cu –o
example.

For implementing the quicksort program: nvcc-I/usr/local/cuda/include –


L/usr/local/cuda/lib cdpQuicksort.cu –o cdpQuicksort

Laboratory Manual for Programming Lab III Visit- fizzible.com 36


Experiment 6: CPU Frequency Alteration.
 Problem Statement:
Write an application to and demonstrate the change in BeagleBoard / ARM Cortex
A5 / Microprocessor / CPU frequency or square wave of programmable frequency.
 Procedure:
 Connect the BeagleBone black to your computer with the USB cable. After
connecting the BeagleBone black with your computer few blue L.E.D’s will glow
indicating that the bone is now powered.
 Now you will see a notification saying “wired connection is now active” on your
desktop.
 Now open the terminal (CTRL+ALT+T) of your Linux desktop.
 Write the following command in your terminal:
“ssh root@192.168.7.2”

*This command will let you access the operating system of your BeagleBone black.

 Now to open the editor for writing the program code type the following command:
“Nano programname (your program name without spaces).py”
Ex: nano cpufrequency.py
 Now start writing your program in the editor which is opened on your screen.
 You can save your program by pressing “CTRL+O”.
 Now to exit out from the editor, press “CTRL+X”.
 You can now again see the terminal on your screen.
 To execute the program you have saved, write the following command:
“Python programname.py”
Ex: python cpufrequency.py.
 Now insert a single pin to pin wire in pin no. 13 and ground pin (P9_01) of
BeagleBone Black.
Laboratory Manual for Programming Lab III Visit- fizzible.com 37
 Connect pin no. P9_13 and ground pin (P9_01) to your CRO / DSO.
 Now execute the code by pressing enter key.
 Observe the square wave.

Laboratory Manual for Programming Lab III Visit- fizzible.com 38

S-ar putea să vă placă și