Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Provided skeleton file below. conv 2 d . asm You must follow the MIPS calling convention. Be sure to actually follow the calling convention; solutions

Provided skeleton file below.
conv2d.asm
You must follow the MIPS calling convention. Be sure to actually follow the calling convention; solutions which do not follow the MIPS calling convention are not correct!
2d convol
Last week you implemented a simple 1D convolution function (prompt and skeleton code below) with some basic assumptions about how that convolution operates such as filter size, stride and padding. This week you're going to create a function that performs 2D convolution by calling that original function, using many of the same assumptions (a fixed 3x3 filter, with a stride of 1 and no padding). However, this time youre going to need to write the output array on the stack and print the entire array within the function. Your 2D convolution function will accept 4 parameters, input height, input width, a pointer to the start of the input array and a pointer to the filter array. You can assume the input and output matrices will be no larger than 25 by 25. See below for the C code that implements the equivalent function.
Representing a 2D array
Multi-dimensional arrays in memory do not actually have multiple dimensions, but are instead flattened. The way these arrays are flattened are determined by the programmer or the language, and fall into two general categories, row major and column major. Row major indicates that elements in the same row are physically next to each other in memory, while column major has elements in the same column next to each other. In order to index the array you need to know the length of the major axis. For example, a column major system indexed by array[row][column], the memory location of array[i][j] becomes array[ i * column_length + j ]. For this lab assume all arrays (the filter, input, and output) are all row major (the c code is already written in row major, so just follow that).
Function call notes:
Theres a lot of iteration variables that youll need to keep track of across calls to the original conv function. This is a great time to use the $s registers, but in order to ensure correctness you need to make sure to save and restore those registers in the conv function using the stack. Also, we expect the conv2D function to properly handle the $s registers, so your function will be tested in a way that ensures those registers are unaffected.
Skeleton code information:
The skeleton code has a main that accepts input height and width from the command line (in that order), then uses that to calculate the size of the input. Then it accepts all of the values in the input array from the command line as well. You can either input these manually, or prepare the inputs in a text file, then use the command:
spim -f conv2d.asm inp.txt
An example input file is provided in the drive.
Equivalent C code
void conv(int inp[], int filt[], int result[], int result_l){
int filt_width =3;
for(int i =0; i result_l; i++){
for(int j =0; j filt_width; j++){
result[i]+= inp[i + j]* filt[j];
}
}
}
//The a registers match the order of the arguments
//$a0-> inp_height, $a1-> inp_width, $a2-> inp, $a3-> filt
void conv2D(int inp_height, int inp_width, int inp[], int filt[]){
int filter_height =3;
int filter_width =3;
int out_height = inp_height - filter_height +1;
int out_width = inp_width - filter_width +1;
if(out_height =0|| out_width =0)
return;
int output[out_height * out_width];
for(int i=0; i
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

More Books

Students also viewed these Databases questions

Question

what problem does the use of genetic algorithms solve

Answered: 1 week ago

Question

Understand employee mentoring

Answered: 1 week ago

Question

Appreciate the importance of new-employee orientation

Answered: 1 week ago