Question: You need to modify the assembly code, which you developed in the previous exercise, with the RISC - V V extension. It is important to

You need to modify the assembly code, which you developed in the previous exercise, with the RISC-V V
extension. It is important to note that the specification of the vector engine of our virtual RISC-V (i.e.,
vlen=256, elen=16) is different from the one used in the previous exercise (i.e., vlen=128, elen=16).
Specifically, you are asked to achieve the same speed up as arraymul_improved_version1.c in the
previous exercise. In other words, to get familiar with the design of the vector engine, the performance
improvement of this assignment against the baseline version in 3-2 array multiplication should be the same as
the performance improvement achieved in 3-3. Array multiplication (a vectorized version with the V extension,
improved_version1). Besides, you should do the same as 3-3 to collect performance data and derive related
performance statistics.
As shown in the improved_version2() function, you are responsible for writing the assembly for the
for-loop code: for (...) y[i]= h[i]* x[i]+ c;.
NOTE: You should put your assembly code within the arraymul_improved_version2.c file, as
indicated in asm volatile( #include "arraymul_improved_version2.c" : [h]"+r"
(p_h),...); within the improved_version2() function in exercise2_2.c.
Your code should use the RISC-V V Extension and run with Spike simulator using the specific
configurations (i.e., vlen=256, elen=16).
NOTE: Please do not modify the rest of the header file.
Variables/Constants defined in the header files used in this exercise.
Var./Cons. Name Definition
x[] Input array 1 in arraymul.h
h[] Input array 2 in arraymul.h
y[] Output array in arraymul.h
improved_version2_cycle_count
Clock cycle in vectorsum_improved_version2.c you need
to calculate
cycle_time
The given clock cycle time of the target RISC-V processor
running at 2.6 GHz
improved_version2_cpu_time
The CPU time in vectorsum_improved_version2.c you
need to calculate
arr_size Size of the arrays used in this exercise
student_id
student_id = your_student_id %100
i.g. F12345678:
student_id =12345678%100=78
Your obtained scores of this exercise is determined by the correctness of your reported performance
data.
1. Achieved speedup.(10%)
As described above, the printed out speedup number should be 1.
The improved_version2 function in exercise2_2.c is as follows.
//The code snippet for improved_version2() in exercise2_2.c
void improved_version2(){
short int *p_h = h;
short int *p_x = x;
short int *p_y = y;
short int id = student_id;// id = your_student_id %100;
/* original C code
for (int i =0; i < arr_size; i++){
p_y[i]= p_h[i]* p_x[i]+ id;
}
*/
asm volatile(
#include "arraymul_improved_version2.c"
: [h]"+r"(p_h),[x]"+r"(p_x),[y]"+r"(p_y),[add_cnt]"+r"(add_cnt),
[sub_cnt]"+r"(sub_cnt),[mul_cnt]"+r"(mul_cnt),[div_cnt]"+r"(div_cnt),
[lw_cnt]"+r"(lw_cnt),[sw_cnt]"+r"(sw_cnt),[others_cnt]"+r"(others_cnt)
: [id]"r"(id),[arr_size]"r"(arr_size)
: "t0","v0","v1","v2"
);
printf("
===== Question 2-2=====
");
printf("output: ");
for (int i =0; i < arr_size; i++){
printf("%d ", y[i]);
}
printf("
");
printf("add counter used: %d
", add_cnt);
printf("sub counter used: %d
", sub_cnt);
printf("mul counter used: %d
", mul_cnt);
printf("div counter used: %d
", div_cnt);
printf("lw counter used: %d
", lw_cnt);
printf("sw counter used: %d
", sw_cnt);
printf("others counter used: %d
", others_cnt);
macro_improved_version2_cycle_count
printf("The total cycle count in this program: %.0f
",
improved_version2_cycle_count);
macro_improved_version2_cpu_time
printf("CPU time =%f us
", improved_version2_cpu_time);
float speedup =0.0;
FILE *fp;
fp = fopen("improved_version1_cpu_time.txt","r");
fscanf(fp,"%f", &speedup);
fclose(fp);
speedup = speedup / improved_version2_cpu_time;
printf("The enhanced V extension version is %f times faster than the baseline
vectorized version
", speedup);
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!