vector benchmark
This commit is contained in:
33
benchmarks/vector/sgemm_nn/Makefile
Normal file
33
benchmarks/vector/sgemm_nn/Makefile
Normal file
@@ -0,0 +1,33 @@
|
||||
LIB_PATH = ../../../runtime
|
||||
|
||||
COMP = /nethome/ekim79/riscv-gnu-toolchain/drops/bin/riscv32-unknown-elf-gcc
|
||||
|
||||
CC_FLAGS = -ffreestanding -O0 -Wl,--gc-sections -nostartfiles -nostdlib -nostartfiles -nodefaultlibs -Wl,-Bstatic,-T,$(LIB_PATH)/mains/vortex_link.ld -march=rv32imv -mabi=ilp32
|
||||
|
||||
DMP = /nethome/ekim79/riscv-gnu-toolchain/drops/bin/riscv32-unknown-elf-objdump
|
||||
CPY = /nethome/ekim79/riscv-gnu-toolchain/drops/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_TEST = $(LIB_PATH)/tests/tests.c
|
||||
VX_FIO = $(LIB_PATH)/fileio/fileio.s
|
||||
VX_VEC = vx_vec_sgemm_nn.s #float --> int
|
||||
LIBS = /nethome/ekim79/riscv-gnu-toolchain/drops/riscv32-unknown-elf/lib/libc.a /nethome/ekim79/riscv-gnu-toolchain/drops/riscv32-unknown-elf/lib/libstdc++.a -static-libgcc -lgcc
|
||||
|
||||
VX_MAIN = vx_vec_sgemm_nn
|
||||
|
||||
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_TEST) $(VX_MAIN).c $(LIBS) -Iinclude -o $(VX_MAIN).elf
|
||||
95
benchmarks/vector/sgemm_nn/vx_vec_sgemm_nn.c
Normal file
95
benchmarks/vector/sgemm_nn/vx_vec_sgemm_nn.c
Normal file
@@ -0,0 +1,95 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "../../../runtime/intrinsics/vx_intrinsics.h"
|
||||
#include "vx_vec_sgemm_nn.h"
|
||||
|
||||
//---------------------------------------------------------------
|
||||
/* # void sgemm_nn(size_t n, size_t m, size_t k,
|
||||
# int *a, // m * k matri size_t lda,
|
||||
# int *b, // k * n matrix size_t ldb,
|
||||
# int *c, // m * n matrix size_t ldc)
|
||||
# c += a*b (alpha=1, no transpose on input matrices)
|
||||
# matrices stored in C row-major order */
|
||||
//---------------------------------------------------------------
|
||||
|
||||
int main()
|
||||
{
|
||||
vx_tmc(1);
|
||||
|
||||
int m = 3;
|
||||
int k = 3;
|
||||
int n = 3;
|
||||
|
||||
int* a1 = (int*)malloc(sizeof(int) * m * k);
|
||||
int* b1 = (int*)malloc(sizeof(int) * k * n);
|
||||
int* c1 = (int*)malloc(sizeof(int) * m * n);
|
||||
int* d1 = (int*)malloc(sizeof(int) * m * n); //verfication
|
||||
|
||||
for (int i = 0; i < (m * k); ++i) a1[i] = i;
|
||||
for (int i = 0; i < (k * n); ++i) b1[i] = 1;
|
||||
for (int i = 0; i < (m * n); ++i) c1[i] = 0;
|
||||
for (int i = 0; i < (m * n); ++i) d1[i] = 0;
|
||||
|
||||
|
||||
#if 1
|
||||
printf("sgemm_nn\na[%d]:", m*k);
|
||||
for (int i = 0; i < m*k; ++i) {
|
||||
if(!(i % k)) printf("\n");
|
||||
printf("%d ", a1[i]);
|
||||
}
|
||||
printf("\n\nb[%d]:", k*n);
|
||||
for (int i = 0; i < k*n; ++i) {
|
||||
if (!(i % n)) printf("\n");
|
||||
printf("%d ", b1[i]);
|
||||
}
|
||||
#endif
|
||||
|
||||
vx_vec_sgemm_nn(n, m, k, a1, b1, c1);
|
||||
// vx_vec_sgemm_nn(n, a1, b1, c1);
|
||||
|
||||
#if 1
|
||||
printf("\n\nc[%d]:\n", m*n);
|
||||
for (int i = 0; i < m*n; ++i) {
|
||||
if (!(i % n)) printf("\n");
|
||||
printf("%d ", c1[i]);
|
||||
}
|
||||
#endif
|
||||
|
||||
for (int r = 0; r < k; r++) {
|
||||
for (int c = 0; c < m; c++) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
d1[r*k+i] += a1[r*k+c]*b1[i*n+c];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if 1
|
||||
printf("\n\nc[%d]:\n", m*n);
|
||||
for(int i = 0; i < m; ++i) {
|
||||
for(int j = 0; j < n; ++j) {
|
||||
printf("%d ", c1[i*m+j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
for(int i = 0; i < m*n; ++i)
|
||||
{
|
||||
if(c1[i] != d1[i])
|
||||
{
|
||||
printf("\n<sgemm_nn> FAILED at <index: %d>! \n", i);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
printf("\nPASS.......................... <sgemm_nn> \n");
|
||||
|
||||
|
||||
free(a1); free(b1); free(c1);
|
||||
|
||||
vx_tmc(0);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
87263
benchmarks/vector/sgemm_nn/vx_vec_sgemm_nn.dump
Normal file
87263
benchmarks/vector/sgemm_nn/vx_vec_sgemm_nn.dump
Normal file
File diff suppressed because it is too large
Load Diff
BIN
benchmarks/vector/sgemm_nn/vx_vec_sgemm_nn.elf
Executable file
BIN
benchmarks/vector/sgemm_nn/vx_vec_sgemm_nn.elf
Executable file
Binary file not shown.
13
benchmarks/vector/sgemm_nn/vx_vec_sgemm_nn.h
Normal file
13
benchmarks/vector/sgemm_nn/vx_vec_sgemm_nn.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//void vx_vec_sgemm_nn(int n, int m, int k, int* a1, int lda, int* b1, int ldb, int* c1, int ldc);
|
||||
void vx_vec_sgemm_nn(int n, int m, int k, int* a1, int* b1, int* c1);
|
||||
//void vx_vec_sgemm_nn(int n, int* a1, int* b1, int* c1);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
5635
benchmarks/vector/sgemm_nn/vx_vec_sgemm_nn.hex
Normal file
5635
benchmarks/vector/sgemm_nn/vx_vec_sgemm_nn.hex
Normal file
File diff suppressed because it is too large
Load Diff
61
benchmarks/vector/sgemm_nn/vx_vec_sgemm_nn.s
Normal file
61
benchmarks/vector/sgemm_nn/vx_vec_sgemm_nn.s
Normal file
@@ -0,0 +1,61 @@
|
||||
.type vx_vec_sgemm_nn, @function
|
||||
.global vx_vec_sgemm_nn
|
||||
# RV64IDV system
|
||||
#
|
||||
# void
|
||||
# sgemm_nn(size_t n, size_t m, size_t k,
|
||||
# int *a, // m * k matrix
|
||||
# int *b, // k * n matrix
|
||||
# int *c) // m * n matrix
|
||||
#
|
||||
# c += a*b (alpha=1, no transpose on input matrices)
|
||||
# matrices stored in C row-major order
|
||||
#
|
||||
# for (int r = 0; r < k; r++) {
|
||||
# for (int c = 0; c < m; c++) {
|
||||
# for (int i = 0; i < n; i++) {
|
||||
# c[r*k+i] += a[r*k+c]*b[i*n+c];
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
# a0 = n, a1 = m, a2 = k
|
||||
# a3 = a, a4 = b, a5 = c
|
||||
# v0 = a, v2 = b, v2 = c
|
||||
# x0 = i, x1 = c, x2 = r
|
||||
#
|
||||
vx_vec_sgemm_nn:
|
||||
vsetvli t0, a2, e32, m8 # k
|
||||
loop_row: # a[m][k]
|
||||
vlw.v v0, (a3)
|
||||
sub a2, a2, t0
|
||||
slli t0, t0, 2
|
||||
add a3, a3, t0
|
||||
|
||||
vsetvli t1, a1, e32, m8 # m
|
||||
loop_col: # b[k][n]
|
||||
vlw.v v1, (a4)
|
||||
sub a1, a1, t1
|
||||
slli t1, t1, 2
|
||||
add a4, a4, t1
|
||||
|
||||
vsetvli t2, a0, e32, m8 # n
|
||||
loop_iner:
|
||||
vlw.v v2, (a5) # c[][]
|
||||
sub a0, a0, t2
|
||||
slli t2, t2, 2
|
||||
add a5, a5, t2
|
||||
|
||||
bnez t2, loop_iner
|
||||
|
||||
bnez t1, loop_col
|
||||
|
||||
|
||||
# vadd.vv v0, v0, v0
|
||||
# vsw.v v0, (a5)
|
||||
# add a5, a5, t0
|
||||
|
||||
bnez t0, loop_row
|
||||
ret
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user