Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
eopXD committed Jul 13, 2023
0 parents commit 99e5945
Show file tree
Hide file tree
Showing 2,926 changed files with 255,155 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Run clang-format Linter

on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: DoozyX/[email protected]
with:
source: '.'
extensions: 'hpp,cpp'
clangFormatVersion: 12
inplace: True
- uses: EndBug/add-and-commit@v4
with:
author_name: Clang Robot
author_email: [email protected]
message: '[NFC] Auto-commit clang-format from github action'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build/
.vscode/
.cache/
include/autogen
include/AutoGenComputeOp.h
*.pyc
Empty file added .gitmodules
Empty file.
48 changes: 48 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
cmake_minimum_required(VERSION 3.13.4)

project(vector-intrinsic-fuzzing LANGUAGES CXX C)

set_property(GLOBAL PROPERTY C_STANDARD 11)
set_property(GLOBAL PROPERTY CXX_STANDARD 17)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 17)

set(INC ${CMAKE_CURRENT_LIST_DIR}/include)
set(SPIKE ${CMAKE_CURRENT_LIST_DIR}/riscv-isa-sim)
set(LIB ${CMAKE_CURRENT_LIST_DIR}/library)
set(SOFTFLOAT ${CMAKE_CURRENT_LIST_DIR}/extern/riscv-softfloat-standalone)
set(METAL_RUN ${CMAKE_CURRENT_LIST_DIR}/prebuilt/metal-run)

execute_process(COMMAND git submodule update --init --recursive ${SOFTFLOAT} WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
execute_process(COMMAND git submodule update --init --recursive ${METAL_RUN} WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})

add_custom_target(clean_headers
COMMAND rm -rf ${CMAKE_CURRENT_SOURCE_DIR}/include/autogen
COMMAND rm -rf ${CMAKE_CURRENT_SOURCE_DIR}/include/AutoGenComputeOp.h
COMMENT "Clean header files with golden compute functions for operators"
)

add_custom_target(generate_headers ALL
COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/GenerateOperatorComputeHeaders.py ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS clean_headers
COMMENT "Generate header files with golden compute functions for operators"
)

# GoogleTest requires at least C++11
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

enable_testing()

add_subdirectory(extern)
add_subdirectory(include)
add_subdirectory(library)
add_subdirectory(tool)
add_subdirectory(test)
6 changes: 6 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// https://github.com/sifive/frameworksCI
@Library('frameworksCI') _

ci([
[cpu: 10, memory: 20, minute: 60]
])
74 changes: 74 additions & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
SRCTOP:={SRCTOP}
CC:={CC}
CFLAGS:={CFLAGS}
SIM:={SIM}
NODE:={NODE}
LENGTH:={LENGTH}
SEED:={SEED}
ARCH:={ARCH}
GEN_PATH:={GEN_PATH}
GEN_PATTERN:={GEN_PATTERN}
HAS_POLICY:={HAS_POLICY}

include rules.mk

GEN:=$(GEN_PATH)/$(GEN_PATTERN)

SIM_LOGS:= $(addsuffix .log,$(TARGETS))
SIM_1_LOGS:= $(addsuffix .1.log,$(TARGETS))

ifeq ($(VERBOSE),)
V:=@
else
V:=
endif

define cmd
(set -x; $(1)) >>$@ 2>&1 \
|| (echo $(2) >> $@ && exit 1)
endef

all:
-$(MAKE) -k run
$(MAKE) report
@echo "Test done"

report: $(SIM_LOGS)
$(SRCTOP)/scripts/report

clean:
rm -f *.c *.elf *.log *.dot

run: $(SIM_LOGS)

%.log: $(GEN)
$(V) \
if [ ! -f $(subst .log,.c,$@) ]; then \
echo "Gen testcase $(subst .log,,$@)"; \
$(call cmd, $(GEN) \
--root=$(notdir $(basename $@)) \
--nodes-to-gen=$(NODE) \
--length=$(LENGTH) \
--dot=$(basename $@).dot \
--code=$(notdir $(basename $@)).c \
--seed=$(SEED) \
--march=$(ARCH) \
$(HAS_POLICY), "GEN FAIL") \
fi
$(V)echo "Compile $(subst .log,,$@)"
$(V)$(call cmd, \
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) \
$(subst .log,.c,$@) \
-o $(subst .log,.elf,$@) \
, "COMPILE FAIL")
$(V)echo "Run $(subst .log,,$@)"
$(V)$(call cmd, \
$(SIM) $(subst .log,.elf,$@) \
, "RUN FAIL")

$(GEN):
ifeq ("$(wildcard $(GEN))","")
mkdir -p build
cd build && cmake $(SRCTOP)
cd build && $(MAKE)
endif
77 changes: 77 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# RVV Intrinsic Fuzzing (RIF)

This repository aims to create fuzz testing for the RVV C intrinsic.

## Usage

### How To Use?

`rif-test` is the current driver to fuzz all existing intrinsics in `include/CustomOperator.def`.

```
./rif-test --help
usage: rif-test [-h] [--gen {random_gen,fused_gen}] [--sim SIM] [--cc CC]
[--mode {full,fast}] [--node NODE] [--arch ARCH] [--abi ABI]
[--cflags CFLAGS] [--seed SEED] [--random {on,off}] [--has-policy]
optional arguments:
-h, --help show this help message and exit
--gen {random_gen,fused_gen}
Random gen pattern
--sim SIM Path to simulator
--cc CC Path to compiler
--mode {full,fast} Testing mode
--node NODE Minimal # of node
--arch ARCH Target arch config, default is rv64gcv_zvfh
--abi ABI Target ABI config, default is lp64d
--cflags CFLAGS Default compilation flag
--seed SEED Fixed random seed
--random {on,off} Feed random seed
--has-policy Enable policy if set
```

RIF already have linked a pre-built simulator from [metal-run](https://github.com/sifive/metal-run). So the minimum
requirement for testing it to specify a compiler that is able to compile RISC-V vector intrinsics. To specify your
own simulator (QEMU), please add `${PATH_TO_QEMU_BINARY} ${CPU_CONFIGS}` of how you wish to run
`${PATH_TO_QEMU_BINARY} ${CPU_CONFIGS} ${PATH_TO_ELF}` under --sim.


```
$ git clone https://github.com/sifive/rvv-intrinsic-fuzzing
$ mkdir test
$ cd test
$ ../rvv-intrinsic-fuzzing/rif-test --cc=<YOUR-COMPILER-PATH>
$ make
```



### How To Build?

```
$ git clone https://github.com/sifive/rvv-intrinsic-fuzzing
$ cd rvv-intrinsic-fuzzing
$ mkdir build; cd build
$ cmake ..
$ make
$ ./tool/random_gen --help
Usage: random_gen [OPTION...]
-c, --code=FILE C code file, default filename: 'output.c'
-d, --dot=FILE Graphviz visualization file, default filename is
'output.dot'
-h Give this help list
-m, --march=ARCH_STRING Arch string for testing, default is rv64gcv
-n, --nodes-to-gen=NODES_TO_GEN
The number of nodes to generate for the graph.
-r, --root=OPERATOR_ENUM Initial node for the graph generation, default
root is 'AddVV32'
-s, --seed=RANDOM_SEED Seed for random number generator, default seed is
'0xdeadbeef'
-v, --verbose Produce verbose output
-?, --help Give this help list
--usage Give a short usage message
Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
```
1 change: 1 addition & 0 deletions extern/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(riscv-softfloat-standalone)
2 changes: 2 additions & 0 deletions extern/riscv-softfloat-standalone/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
.cache
12 changes: 12 additions & 0 deletions extern/riscv-softfloat-standalone/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.13.4)

project(riscv-softfloat-standalone LANGUAGES C)

set_property(GLOBAL PROPERTY C_STANDARD 11)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_C_FLAGS "-Wall -Wno-unused -Wno-nonportable-include-path -g -O2 -fPIC")
set(INC ${CMAKE_CURRENT_LIST_DIR}/include)
set(LIB ${CMAKE_CURRENT_LIST_DIR}/lib)

add_subdirectory(include)
add_subdirectory(lib)
12 changes: 12 additions & 0 deletions extern/riscv-softfloat-standalone/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Softfloat from RISC-V ISA Simulator

This is an extracted standlone for users hoping to reproduce floating point operations identical to the official riscv isa simulator. All licensing in this repository follows [riscv-software-src/riscv-isa-sim](https://github.com/riscv-software-src/riscv-isa-sim).

## Usage

```
git clone https://github.com/eopXD/riscv-softfloat-standalone
mkdir build ; cd build
cmake ..
make
```
Empty file.
Loading

0 comments on commit 99e5945

Please sign in to comment.