Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Bender.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ packages:
Git: https://github.com/pulp-platform/common_verification.git
dependencies: []
cva6:
revision: ee89dcc00e6c1a1f4cf97ee1835e950fcfdeebb5
revision: ea86d0ac5fe23ac7889cf8a8b8df7a8c0813bfad
version: null
source:
Git: https://github.com/pulp-platform/cva6.git
Git: https://github.com/mp-17/cva6.git
dependencies:
- axi
- common_cells
Expand Down
5 changes: 3 additions & 2 deletions Bender.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package:
dependencies:
axi: { git: "https://github.com/pulp-platform/axi.git", version: 0.39.1 }
common_cells: { git: "https://github.com/pulp-platform/common_cells.git", version: 1.22.1 }
cva6: { git: "https://github.com/pulp-platform/cva6.git", rev: ee89dcc00e6c1a1f4cf97ee1835e950fcfdeebb5 } # pulp-v1
cva6: { git: "https://github.com/mp-17/cva6.git", rev: ea86d0ac5fe23ac7889cf8a8b8df7a8c0813bfad } # rebase/pulp-v1-os
tech_cells_generic: { git: "https://github.com/pulp-platform/tech_cells_generic.git", version: 0.2.13 }
apb: { git: "https://github.com/pulp-platform/apb.git", version: 0.2.4 }

Expand Down Expand Up @@ -42,7 +42,7 @@ sources:
- hardware/src/lane/simd_mul.sv
- hardware/src/lane/vector_regfile.sv
- hardware/src/lane/power_gating_generic.sv
- hardware/src/masku/masku.sv
- hardware/src/masku/masku_operands.sv
- hardware/src/sldu/p2_stride_gen.sv
- hardware/src/sldu/sldu_op_dp.sv
- hardware/src/sldu/sldu.sv
Expand All @@ -55,6 +55,7 @@ sources:
- hardware/src/lane/vmfpu.sv
- hardware/src/lane/fixed_p_rounding.sv
- hardware/src/vlsu/vlsu.sv
- hardware/src/masku/masku.sv
# Level 3
- hardware/src/lane/vector_fus_stage.sv
# Level 4
Expand Down
46 changes: 46 additions & 0 deletions apps/verification/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright 2024 ETH Zurich and University of Bologna.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Author: Matteo Perotti, ETH Zurich

# Variables for sequence length and number of sequences
SEQ_LENGTH ?= 6
NUM_SEQS ?= 10

# Python
PYTHON ?= python3

# Directories
SRC_DIR = src
SCRIPT_DIR = script
OUTPUT_DIR = ../rand_seq_autogen

# Source files
INSTRUCTIONS_FILE = $(SRC_DIR)/vinsn_list.txt
PYTHON_SCRIPT = $(SCRIPT_DIR)/vinsn_trace_gen.py
# Output files
OUTPUT_SEQ_FILE = $(OUTPUT_DIR)/vinsn_rand_seq.S
OUTPUT_MAIN_FILE = $(OUTPUT_DIR)/main.c

# Target to generate the sequences and main file
all: $(OUTPUT_DIR) $(OUTPUT_SEQ_FILE) $(OUTPUT_MAIN_FILE)

# Target to create the output directory
$(OUTPUT_DIR):
mkdir -p $(OUTPUT_DIR)

$(OUTPUT_SEQ_FILE) $(OUTPUT_MAIN_FILE): $(INSTRUCTIONS_FILE) $(PYTHON_SCRIPT)
$(PYTHON) $(PYTHON_SCRIPT) $(INSTRUCTIONS_FILE) $(OUTPUT_SEQ_FILE) $(SEQ_LENGTH) $(NUM_SEQS) $(OUTPUT_MAIN_FILE)

.PHONY: all clean
10 changes: 10 additions & 0 deletions apps/verification/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Usage
To generate the main.c and vinsn_rand_seq.S files with specific sequence length and number of sequences, run:

```bash
make SEQ_LENGTH=6 NUM_SEQS=10
```

This will create the output directory in the parent directory and place the main.c and vinsn_rand_seq.S files inside it.
The SEQ_LENGTH and NUM_SEQS variables can be adjusted as needed when running the make command.
The generated files will include comments at the beginning indicating they were auto-generated by the Python script.
11 changes: 11 additions & 0 deletions apps/verification/script/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Execute the script with the following command:

```bash
python vinsn_trace_gen.py instructions.txt rand_seq.S 6 10 main.c
```

- instructions.txt is the input file with the list of instructions.
- rand_seq.S is the output file where the random sequences will be written.
- 6 is the length of each random sequence (including the initial vsetvli instruction).
- 10 is the number of random sequences to generate.
- main.c is the file where the main function and function declarations will be written.
92 changes: 92 additions & 0 deletions apps/verification/script/vinsn_trace_gen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Copyright 2024 ETH Zurich and University of Bologna.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Author: Matteo Perotti, ETH Zurich

import random
import sys

def load_instructions(file_path):
with open(file_path, 'r') as file:
instructions = [line.strip() for line in file if line.strip() and not line.strip().startswith('#')]
return instructions

def generate_random_sequences(instructions, sequence_length, num_sequences):
sequences = []
for _ in range(num_sequences):
XX = random.choice([8, 16, 32, 64])
Y = random.choice([1, 2, 4, 8])
initial_instruction = f'vsetvli t0, x0, e{XX}, m{Y}, ta, ma'
sequence = [initial_instruction] + random.choices(instructions, k=sequence_length - 1)
sequences.append(sequence)
return sequences

def write_sequences_to_file(sequences, output_file_path, script_name):
with open(output_file_path, 'w') as file:
file.write(f'# This file was auto-generated by {script_name}\n')
file.write('.text\n')
for i in range(len(sequences)):
file.write(f'.global rand_seq_{i}\n')
file.write('\n')

for i, sequence in enumerate(sequences):
file.write(f'rand_seq_{i}:\n')
for instruction in sequence:
file.write(f' {instruction}\n')
file.write(' ret\n\n')

def write_main_file(num_sequences, output_file_path, script_name):
with open(output_file_path, 'w') as file:
file.write(f'// This file was auto-generated by {script_name}\n')
file.write('#include <stdint.h>\n')
file.write('#include <string.h>\n\n')
file.write('#ifndef SPIKE\n')
file.write('#include "printf.h"\n')
file.write('#else\n')
file.write('#include "util.h"\n')
file.write('#include <stdio.h>\n')
file.write('#endif\n\n')

for i in range(num_sequences):
file.write(f'void rand_seq_{i}();\n')
file.write('\n')
file.write('int main() {\n')
for i in range(num_sequences):
file.write(f' printf("Rand Seq {i}\\n");\n')
file.write(f' rand_seq_{i}();\n\n')
file.write(' printf("Program end\\n");\n\n')
file.write(' return 0;\n')
file.write('}\n')

def main():
if len(sys.argv) != 6:
print("Usage: python generate_sequences.py <input_file> <output_seq_file> <sequence_length> <num_sequences> <output_main_file>")
sys.exit(1)

input_file_path = sys.argv[1]
output_seq_file_path = sys.argv[2]
sequence_length = int(sys.argv[3])
num_sequences = int(sys.argv[4])
output_main_file_path = sys.argv[5]

instructions = load_instructions(input_file_path)
sequences = generate_random_sequences(instructions, sequence_length, num_sequences)
script_name = sys.argv[0]
write_sequences_to_file(sequences, output_seq_file_path, script_name)
write_main_file(num_sequences, output_main_file_path, script_name)
print(f'{num_sequences} random sequences of length {sequence_length} have been written to {output_seq_file_path}')
print(f'Main file written to {output_main_file_path}')

if __name__ == '__main__':
main()
Loading