0% found this document useful (0 votes)
6 views28 pages

Cam D23it163

The document outlines a series of practical exercises aimed at teaching Python programming, MIPS assembly language, and performance profiling using Intel VTune Profiler. Each practical includes coding tasks, such as calculating hypotenuse, finding factorials, and performing multiplications and divisions in MIPS, along with profiling applications to analyze performance metrics. Additionally, it covers interfacing with Raspberry Pi to control LEDs, emphasizing the importance of proper GPIO pin configuration.

Uploaded by

nisargbhatt.n
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views28 pages

Cam D23it163

The document outlines a series of practical exercises aimed at teaching Python programming, MIPS assembly language, and performance profiling using Intel VTune Profiler. Each practical includes coding tasks, such as calculating hypotenuse, finding factorials, and performing multiplications and divisions in MIPS, along with profiling applications to analyze performance metrics. Additionally, it covers interfacing with Raspberry Pi to control LEDs, emphasizing the importance of proper GPIO pin configuration.

Uploaded by

nisargbhatt.n
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

IT263_CAMI CSPIT-KDPIT

Practical – 1
Aim: Getting started with Python programming language

A. Write a Python program to calculate the hypotenuse of a right angledtriangle.


Code:

Output:

B. Write a Python program to find the factorial of any number defined by user.
Code:

Output:

Signature:
Date:

D23IT163 Page | 1
IT263_CAMI CSPIT-KDPIT

Practical – 2
Aim: Understanding control structure for Python programming
language

A. Write a Python program to find number of prime numbers between 1 to n


where n is defined by user.

Code:

Output:

D23IT163 Page | 2
IT263_CAMI CSPIT-KDPIT

B. Write a Python program to test whether a passed letter is a vowel or


not using vowel (character) function.

Code:

Output:

Signature:
Date:

D23IT163 Page | 3
IT263_CAMI CSPIT-KDPIT

Practical – 3
Aim: Working with MIPS assembly language using Mars
simulator

A. Write an ALP to perform 8-bit and 16 bit multiplication.

8-bit Multiplication
Code:
.data
no1: .word 150
no2: .word 150
.text
lw $t0,no1
lw $t1,no2
mul $s2,$t0,$t1
li $v0,1
move $a0,$s2
syscall

Output:

D23IT163 Page | 4
IT263_CAMI CSPIT-KDPIT

16-bit Multiplication
Code:
.data
no1: .word 15020
no2: .word 15010
.text
lw $t0,no1
lw $t1,no2
mul $s2,$t0,$t1
li $v0,1
move $a0,$s2
syscall
Output:

B. Write an ALP to perform 8-bit and16-bit division


8-bit Division
Code:
.data
no1: .word 160
no2: .word 150
.text
lw $t0,no1
lw $t1,no2
div $s2,$t0,$t1
li $v0,1
move $a0,$s2
syscall

Output:

D23IT163 Page | 5
IT263_CAMI CSPIT-KDPIT

16-bit Division

Code:

.data
no1: .word 15020
no2: .word 15010
.text
lw $t0,no1
lw $t1,no2
div $s2,$t0,$t1
li $v0,1
move $a0,$s2
syscall

Output:

Signature:
Date:

D23IT163 Page | 6
IT263_CAMI CSPIT-KDPIT

Practical – 4

Aim: Simulate MIPS code to find factorial of given number

Code:

.data
n: .asciiz "Enter number:"
res: .asciiz "Factorial of given number is::"
.text
la $a0,n li $v0, 4
syscall li $v0, 5
syscall
move $t0,$v0 la $a0,
res
li $v0, 4 syscall
addi $t1, $t1, 1 addi $t2,
$t2, 1
l1: bgt $t2, $t0, exit mul $t1,
$t1, $t2 addi $t2, $t2, 1
j l1 exit:
move $a0,$t1 li $v0, 1
syscall

Output:

Signature:
Date:

D23IT163 Page | 7
IT263_CAMI CSPIT-KDPIT

Practical -5
Aim: Simulate MIPS code to sort an array in ascendingorder

Code:

.data
a: .word 4,2,13,6,7,9

.text
main: la $t0,a add
$t0,$t0,20
outerloop :
add $t1,$zero,$zero la
$a0,a
innerloop :

lw $t2,0($a0)
lw $t3,4($a0)
slt $t5,$t2,$t3
bne $t5,$zero,
continue add $t1,$zero,1
sw $t2,4($a0)
sw $t3,0($a0)
continue: addi $a0,$a0,4
bne $a0,$t0,innerloop
bne $t1,$a0,outerloop

Output:

Signature:
Date:

D23IT163 Page | 8
IT263_CAMI CSPIT-KDPIT

Practical -6
Aim:Getting started with intel VTune profiler.
1. Interpret performance snapshot summary for sample project
matrix application.
VTune Profiler :
VTune Profiler is a performance profiling tool developed by Intel. It analyzes
application behavior, identifies performance bottlenecks, and suggests
optimizations for better utilization of CPU resources. With support for various
programming languages and platforms, VTune helps developers enhance
application performance by providing detailed insights into code execution,
memory usage, and threading issues. Its intuitive interface and in-depth
analysis make it a valuable tool for optimizing software across a wide range of
applications and industries.
Performance snapshot :

D23IT163 Page | 9
IT263_CAMI CSPIT-KDPIT

Elapsed Time :

VTune Profiler's Elapsed Time metric measures the total execution time of a program or a
specific code section, including both compute and non-compute operations. It provides
insights into the overall efficiency of the application, helping developers identify
performance bottlenecks and optimize critical sections for better runtime. Elapsed Time is a
key indicator for assessing the real-world performance impact of code modifications and is
crucial for optimizing software for faster execution.

Logical core utilization :

VTune Profiler's logical core utilization measures how effectively a program utilizes the
available logical cores on a processor. It analyzes thread parallelism and helps identify
bottlenecks, ensuring optimal usage of computational resources. By visualizing core
activity, developers can optimize code for better performance, making it a valuable tool for
parallel programming and multithreading optimization.

Microarchitecture Usage :
D23IT163 Page | 10
IT263_CAMI CSPIT-KDPIT

VTune Profiler uses Microarchitecture Exploration to analyze and optimize code


performance at the hardware level. It provides insights into the utilization of CPU
resources, such as pipelines and cache, aiding developers in fine-tuning applications for
better efficiency. By examining microarchitectural metrics, VTune helps identify
bottlenecks and potential optimizations to enhance overall program execution on specific
hardware architectures. The tool assists in achieving optimal performance by revealing
detailed information about instruction execution, memory access patterns, and other low-
level aspects of code execution. Overall, VTune's Microarchitecture Usage analysis is
crucial for achieving peak performance in software development.

D23IT163 Page | 11
IT263_CAMI CSPIT-KDPIT

GPU Active time :

GPU Active Time in VTune Profiler measures the percentage of time a GPU spends
actively processing tasks, providing insights into GPU utilization. This metric helps identify
bottlenecks and optimize GPU-bound workloads by pinpointing periods of high or low
activity. Monitoring GPU Active Time aids developers in fine-tuning their applications for
improved performance and resource utilization. VTune Profiler's visualization tools offer a
detailed analysis of GPU workload distribution, aiding in the identification and resolution
of performance issues related to GPU utilization. Overall, GPU Active Time is a crucial
metric for optimizing GPU-bound workloads for enhanced computational efficiency.

Memory Bound :

Memory Bound in VTune Profiler refers to a performance bottleneck where a program's


execution is limited by memory-related operations. This includes high cache misses,
memory bandwidth saturation, and inefficient use of memory hierarchy. VTune helps
identify and analyze Memory Bound issues, allowing developers to optimize code by
reducing unnecessary memory accesses and improving data locality. Analyzing Memory
Bound metrics in VTune is crucial for enhancing overall application performance by
addressing memory-related bottlenecks.

D23IT163 Page | 12
IT263_CAMI CSPIT-KDPIT

Vectorization :

Vectorization in VTune Profiler refers to the process of optimizing code by utilizing SIMD
(Single Instruction, Multiple Data) instructions to perform parallel operations on multiple
data elements. VTune helps analyze and visualize vectorization efficiency, identifying areas
for improvement in parallelization, enhancing performance for applications with
computationally intensive tasks. The profiler provides insights into vectorization metrics,
such as vectorization ratio and overhead, aiding developers in optimizing their code for
better utilization of modern processor capabilities.
Collection and Platform info :

D23IT163 Page | 13
IT263_CAMI CSPIT-KDPIT

Collection in VTune Profiler involves gathering performance data from a target application.
It captures metrics like CPU utilization and memory usage. Platform Info provides details
about the hardware and software environment during profiling, aiding in analysis. Together,
they help optimize code for better performance and efficiency. VTune Profiler is a powerful
tool for performance tuning and analysis in software development.

HOTSPOT:

D23IT163 Page | 14
IT263_CAMI CSPIT-KDPIT

Anomaly detection:

D23IT163 Page | 15
IT263_CAMI CSPIT-KDPIT

Gpu offload:

D23IT163 Page | 16
IT263_CAMI CSPIT-KDPIT

Gpu compute/media hotspot:

D23IT163 Page | 17
IT263_CAMI CSPIT-KDPIT

Conclusion :

Vectorization in VTune Profiler measures the efficiency of utilizing vector instructions for
improved parallelism. Memory Bound highlights the impact of memory access on
performance. GPU Active Time indicates the proportion of time the GPU is actively
processing tasks. Microarchitecture Usage evaluates the efficiency of CPU execution units.
Logical Core Utilization assesses the effective utilization of CPU logical cores. Elapsed
Time provides an overall measure of the program's execution time, aiding in comprehensive
performance analysis and optimization.

Signature:
Date:

D23IT163 Page | 18
IT263_CAMI CSPIT-KDPIT

Practical-7

Aim: - Profiling application with Intel VTune profiler. Open Vtunes and create a
new project for your program. Run the following analyses and answer the
following question for your program

1. What is the IPC that you have observed?


The IPC (Instruction Per Cycle) in VTune Profiler is a metric that measures the
efficiency of the CPU by indicating how many instructions it can execute in
a single clock cycle. A higher IPC value indicates better performance, while
a lower IPC value suggests possible performance issues. VTune Profiler
allows developers to monitor and analyse IPC along with other performance
metrics to identify bottlenecks, optimize code, and improve application
performance.

The IPC metric is calculated by dividing the number of instructions executed by


the CPU by the number of clock cycle used to execute them. VTune Profiler
can display IPC data at different levels of granularity, such as per thread or
per-CPU.

D23IT163 Page | 19
IT263_CAMI CSPIT-KDPIT

2. What logical core utilization and physical core utilization have you observed?
The Logical Core Utilization and Physical Core Utilization in VTune Profiler
are metrics that measure how much of the CPU's processing power is being
used. Logical Core Utilization indicates the percentage of time each logical
processor or thread spends executing instructions, while Physical Core
Utilization indicates the percentage of time each physical core spends
executing instructions.

High utilization values can indicate good performance, but can also indicate
resource contention and potential performance issues.

VTune Profiler can display these metrics at different levels of granularity, such
as per-process, per-thread, or per-core, to help developers identify
performance bottlenecks and optimize code. Logical Core Utilization can
also help developers to detect hyper-threading issues, such as
oversubscription, that can lead to inefficient use of CPU resources.

Conclusion:

In this practical I learnt about IPC (Instructions Per Cycle) and Elapsed time
and measured IPC and Logical Core utilization as well as Physical Core
Utilization of Any executable file(.exe).

Signature:
Date:

D23IT163 Page | 20
IT263_CAMI CSPIT-KDPIT

Practical 8
Aim: -Run and interpret hotspot analysis of sample application on VTune
profiler. Open VTune and create a new project for your program. Run the
following analyses and answer the following questions for your program.

1.What % of the pipeline slots are memory bound.

Pipeline slots: refers to the number of execution slots in a particular stage. It


provides a pipeline slots analysis type that enables you to understand how
efficiently the stage is utilized during program execution. It helps to identify
performance bottlenecks and improves optimization.

Memory bound: is performance that occurs when a program is limited by


bandwidth of system memory. It is often characterized by high memory usage
and frequent access to large datasets. It provides analysis types to help identify
and optimize issues.

D23IT163 Page | 21
IT263_CAMI CSPIT-KDPIT

2. Identify and list down the statements in the program's source code
(ignore the ones that are from source code of the libraries) that were
responsible for consuming most of the CPU time (in descending order of
the % of CPU time consumed. Make sure to note down the % as well).

Top hotspot: analysis in intel vtune profiler identifies the most time-consuming
functions in your application and provides valuable information for
optimizing performance.
Signature:
Date:

D23IT163 Page | 22
IT263_CAMI CSPIT-KDPIT

Practical-9

Aim: Getting started with Raspberrypi.

A. 4 LEDs are Interfaced with Raspberry Pi.

Develop a Python script for Raspberry Pi to blink all LEDs with a specific Time
Interval.

❖ Theory of raspberry pi:

Raspberry Pi is defined as a minicomputer the size of a credit card that is interoperable


with any input and output hardware device like a monitor, a television, a mouse, or a
keyboard – effectively converting the set-up into a full-fledged PC at a low cost. This
article discusses the Raspberry Pi models available today, their key features, and use
cases.

❖ Pin configuration and two nodes (BCM & Board mode):

There are two kinds of Input and Output pin numbering for the Raspberry Pi. One is the
BCM and the other is the BOARD. These pin numberings are useful for writing Python
scripts for the Raspberry Pi.

• GPIO BOARD– This type of pin numbering refers to the number of the pin in
the plug, i.e., the numbers printed on the board, for example, P1. The advantage
of this type of numbering is, that it will not change even though the version of the
board changes.

• GPIO BCM– The BCM option refers to the pin by “Broadcom SOC Channel.
They signify the Broadcom SOC channel designation. The BCM channel changes
as the version number changes.

Note: It is very important to wire the GPIO pins with limited resistors to avoid serious
damage to the Raspberry Pi. LEDs must have resistors to limit the current passing
through them. The motors should not be connected to the GPIO pins directly.

D23IT163 Page | 23
IT263_CAMI CSPIT-KDPIT

Program:
import RPi.GPIO as GPIO
import time
GPIO.setmode (GPIO.BCM)
LED_PORT = [2,3,4,17,27]
#Setup GPIO pin as an Output
for i in LED_PORT:
GPIO.setup (i, GPIO.OUT)
while True:
#send logic 1 on each pin of LED Port
for i in LED_PORT:
GPIO.output (i, GPIO.HIGH)
#generate delay for 1 second
time.sleep (1)
#send logic 0 on each pin of LED port
for i in LED_PORT:
GPIO.output (i, GPIO.LOW)
#generate delay for 0 second
time.sleep (1)

Results:

Conclusion:
The Raspberry Pi is a powerful little beast and a great platform for building low-cost, but highly
capable, embedded systems. The interfaces built into its GPIO connector make it easy to bolt on
modules using simple low-cost electronics and a bit of configuration to create very functional and
flexible systems.
Signature:
Date:

D23IT163 Page | 24
IT263_CAMI CSPIT-KDPIT

Practical-10

Aim: Controlling LEDs with a push button on Raspberry pi

A. Push Buttons (4 Nos.) and LEDs (4 Nos.) are Interfaced with Raspberry Pi.
Develop a python script for Raspberry Pi to turn on & off LED with respect
to the switch (Button pressed, LED ON & Button Released, LED OFF)
Program:
import RPi.GPIO as GPIO
import time

BTN = 12
led=7

def gpio_setup():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(led, GPIO.OUT)
GPIO.setup(BTN,GPIO.IN,pull_up_down=GPIO.PUD_UP)

def main():
gpio_setup()
count=0
btn_closed = True
while True:
btn_val = GPIO.input(BTN)
if btn_val and btn_closed:
GPIO.output(led, True)
print("OPEN")
btn_closed = False
elif btn_val==False and btn_closed==False:
count+=1
GPIO.output(led, False)
print("CLOSE")
btn_closed=True
time.sleep(0.1)

if name== 'main':
main()

D23IT163 Page | 25
IT263_CAMI CSPIT-KDPIT

Output:

Conclusion:
The Raspberry Pi is a powerful little beast and a great platform for building low-cost,
but highly capable, embedded systems. The interfaces built into its GPIO connector
make it easy to bolt on modules using simple low-cost electronics and a bit of
configuration to create very functional and flexible systems.

Signature:
Date:

D23IT163 Page | 26
IT263_CAMI CSPIT-KDPIT

Practical-11

Aim: Interfacing RaspberryPi with Common Cathode Seven Segment

A. Common Cathode Seven Segment (1 No.) is interfaced with the Raspberry Pi Board.

Write a Python Script to generate a counter of 0 to 9 on A segmented display with Specific Time
Intervals.

Program:
import RPi.GPIO as IO
import time
IO.setmode(IO.BOARD)
#pin=[29,31,33,35,37,36,38,40]#for NSK
pin=[40,38,36,37,35,33,31,29] #for high speed
for i in pin:
IO.setup(i,IO.OUT)

hax=[0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x98]

while 1:
for i in range (10):
h=hax[i]
for j in range (8):
mask = 1 << j
b = (h & mask) >> j
IO.output(pin[j],b)
time.sleep(1)

D23IT163 Page | 27
IT263_CAMI CSPIT-KDPIT

Output:

Conclusion:
The Raspberry Pi is a powerful little beast and a great platform for building low-cost, but
highly capable, embedded systems. The interfaces built into its GPIO connector make it
easy to bolt on modules using simple low-cost electronics and a bit of configuration to
create very functional and flexible systems.

Signature:
Date:

D23IT163 Page | 28

You might also like