project tests refactoring

This commit is contained in:
Blaise Tine
2021-06-13 17:42:04 -07:00
parent 47c3234659
commit 03406c0a3f
631 changed files with 394471 additions and 653511 deletions

View File

@@ -0,0 +1,32 @@
LIB_PATH = ../../../runtime
COMP = /home/priya/dev/riscv_vec/riscv-gnu/bin/riscv32-unknown-elf-gcc
CC_FLAGS = -ffreestanding -O0 -Wl,--gc-sections -nostartfiles -nostdlib -nostartfiles -nodefaultlibs -Wl,-Bstatic,-T,$(LIB_PATH)/startup/vx_link.ld -march=rv32imv -mabi=ilp32
DMP = /home/priya/dev/riscv_vec/riscv-gnu/bin/riscv32-unknown-elf-objdump
CPY = /home/priya/dev/riscv_vec/riscv-gnu/bin/riscv32-unknown-elf-objcopy
# VX_STR = ../../startup/vx_start.S
NEWLIB = $(LIB_PATH)/newlib/newlib.c
VX_STR = $(LIB_PATH)/startup/vx_start.S
VX_INT = $(LIB_PATH)/intrinsics/vx_intrinsics.S
VX_IO = $(LIB_PATH)/io/vx_io.S $(LIB_PATH)/io/vx_io.c
VX_API = $(LIB_PATH)/vx_api/vx_api.c
VX_FIO = $(LIB_PATH)/fileio/fileio.S
VX_VEC = vx_vec_saxpy.s #float --> int
LIBS = /home/priya/dev/riscv_vec/riscv-gnu/riscv32-unknown-elf/lib/libc.a /home/priya/dev/riscv_vec/riscv-gnu/riscv32-unknown-elf/lib/libstdc++.a -static-libgcc -lgcc
VX_MAIN = vx_vec_saxpy
all: HEX DUMP ELF
DUMP: ELF
$(DMP) -D $(VX_MAIN).elf > $(VX_MAIN).dump
HEX: ELF
$(CPY) -O ihex $(VX_MAIN).elf $(VX_MAIN).hex
ELF:
$(COMP) $(CC_FLAGS) $(VX_STR) $(VX_VEC) $(VX_FIO) $(NEWLIB) $(VX_INT) $(VX_IO) $(VX_API) $(VX_MAIN).c $(LIBS) -Iinclude -o $(VX_MAIN).elf

View File

@@ -0,0 +1,78 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../../../runtime/intrinsics/vx_intrinsics.h"
#include "vx_vec_saxpy.h"
//---------------------------------------------------------------
/* # void saxpy(size_t n, const float a, const float *x, float *y)
# ==> convert to int!!
# void saxpy(size_t n, const int a, const int *x, int *y)
# { size_t i;
# for (i=0; i<n; i++) y[i] = a * x[i] + y[i]; } */
//---------------------------------------------------------------
int main()
{
vx_tmc(1);
int n = 64; //#define NUM_DATA 65536
int *a = (int*)malloc(sizeof(int) * n);
int *b = (int*)malloc(sizeof(int) * n);
int *c = (int*)malloc(sizeof(int) * n); //verification
// float factor = ((float)rand()/(float)(RAND_MAX)) * 100.0;
int factor = ((float)rand()/(RAND_MAX)) * 100.0;
for (int i = 0; i < n; ++i) {
a[i] = ((float)rand()/(RAND_MAX)) * 100.0;
b[i] = 0;
c[i] = 0;
}
//; c[i] = 2;}
#if 1
printf("saxpy\nfactor: %d\na[%d]: ", factor, n);
for(int i = 0; i < n; ++i) printf("%d ", a[i]);
// printf("\nb[%d]: ", n);
// for(int i = 0; i < n; ++i) printf("%d \n", b[i]);
#endif
int startCycles = vx_num_cycles();
int startInst = vx_num_instrs();
vx_vec_saxpy(n, factor, a, b);
int endCycles = vx_num_cycles();
int endInst = vx_num_instrs();
int totalInst = (endInst - startInst);
int totalCycles = (endCycles - startCycles);
printf("\nCycles = %d, Instructions = %d", totalCycles, totalInst);
#if 0
printf("\nsaxpy\na[%d]: ", n);
for(int i = 0; i < n; ++i) printf("%d ", a[i]);
printf("\n\nb[%d]: ", n);
for(int i = 0; i < n; ++i) printf("%d ", b[i]);
#endif
for(int i = 0; i < n; ++i)
{
if(b[i] != ((a[i] * factor) + c[i]))
{
printf("\n<saxpy> FAILED at <index: %d>! \n", i);
return 1;
}
}
printf("\nPASSED.......................... <saxpy> \n");
free(a); free(b); free(c);
vx_tmc(0);
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,12 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
void vx_vec_saxpy(int n, int scalar, int* a, int* b);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,26 @@
.type vx_vec_saxpy, @function
.global vx_vec_saxpy
# void
# saxpy(size_t n, int factor, int *a, int *b)
# { for (int i=0; i<n; i++) { y[i] = a * x[i] + y[i];} }
#
# register arguments:
# a0 n
# a1 factor
# a2 a
# a3 b
vx_vec_saxpy:
loop:
vsetvli a4, a0, e32
vlw.v v0, (a2)
sub a0, a0, a4
slli a4, a4, 2
add a2, a2, a4
vlw.v v1, (a3)
vmul.vx v0, v0, a1
vadd.vv v1, v0, v1
# vmacc.vx v1, rs1, v0
vsw.v v1, (a3)
add a3, a3, a4
bnez a0, loop
ret