Skip to content

Commit

Permalink
Merge pull request #1 from esl-epfl/review_pr_obi_virtualization
Browse files Browse the repository at this point in the history
Review pull request: OBI Virtualization
  • Loading branch information
denizkasap authored Jan 9, 2024
2 parents 127d2fb + c666310 commit 7c256d3
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 242 deletions.
5 changes: 5 additions & 0 deletions hw/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# X-HEEP hardware reference

https://github.com/esl-epfl/x-heep-femu

d7b7341d2be860289760541477f1009ade953a49
Binary file modified hw/x_heep.bit
100755 → 100644
Binary file not shown.
156 changes: 70 additions & 86 deletions hw/x_heep.hwh
100755 → 100644

Large diffs are not rendered by default.

15 changes: 6 additions & 9 deletions sw/arm/apps/virtual_obi_read/virtual_obi_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,17 @@
# Compile the application
x_heep.compile_app("virtual_obi_read")

# Init the OBI
obi = x_heep.init_obi()
# Init the OBI memory
obi = x_heep.init_obi_mem()

# Reset the OBI Memory
x_heep.reset_obi(obi)
# Reset the OBI memory
x_heep.reset_obi_mem(obi)

#Write the OBI Memory
# Write to the OBI memory
write_list = list()
for i in range(1024):
write_list.append(i ** 2)
x_heep.write_obi_memory(write_list, obi)

#Check if OBI memory is as desired
obi_read = x_heep.read_obi(obi)
x_heep.write_obi_mem(write_list, obi)

# Run the application
x_heep.run_app()
Expand Down
18 changes: 7 additions & 11 deletions sw/arm/apps/virtual_obi_write/virtual_obi_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,22 @@
# Compile the application
x_heep.compile_app("virtual_obi_write")

# Init the OBI
obi = x_heep.init_obi()
# Init the OBI memory
obi = x_heep.init_obi_mem()

# Reset the OBI Memory
x_heep.reset_obi(obi)

#Check if OBI memory is resetted
obi_read = x_heep.read_obi(obi)
# Reset the OBI memory
x_heep.reset_obi_mem(obi)

# Run the application
x_heep.run_app()

#Compare application output
obi_read = x_heep.read_obi(obi)
# Read the OBI memory
obi_read = x_heep.read_obi_mem(obi)
target_read = list()
for i in range(1024):
target_read.append(i ** 2)
#print(target_read)
if target_read == obi_read:
print("Arrays matching! Write from RISCV Successful.")
print("Write operation successful.")

# Delete OBI
del obi
8 changes: 0 additions & 8 deletions sw/arm/jupyter_notebooks/hello_world.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@
"# Run the application\n",
"x_heep.run_app()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1fefd8b2",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
8 changes: 0 additions & 8 deletions sw/arm/jupyter_notebooks/virtual_flash_read.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,6 @@
"# Delete flash\n",
"del flash"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dcdc39b0",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
8 changes: 0 additions & 8 deletions sw/arm/jupyter_notebooks/virtual_flash_write.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,6 @@
"# Delete flash\n",
"del flash"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5d639370",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
33 changes: 7 additions & 26 deletions sw/arm/jupyter_notebooks/virtual_obi_read.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"metadata": {},
"outputs": [],
"source": [
"#Initialize the OBI\n",
"obi = x_heep.init_obi()"
"# Init the OBI memory\n",
"obi = x_heep.init_obi_mem()"
]
},
{
Expand All @@ -51,8 +51,8 @@
"metadata": {},
"outputs": [],
"source": [
"#Reset the OBI\n",
"x_heep.reset_obi(obi)"
"# Reset the OBI memory\n",
"x_heep.reset_obi_mem(obi)"
]
},
{
Expand All @@ -62,28 +62,17 @@
"metadata": {},
"outputs": [],
"source": [
"#Write to OBI Memory a custom array\n",
"# Write to the OBI memory\n",
"write_list = list()\n",
"for i in range(1024):\n",
" write_list.append(i ** 2)\n",
"x_heep.write_obi_memory(write_list, obi)"
"x_heep.write_obi_mem(write_list, obi)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2f6a9c40",
"metadata": {},
"outputs": [],
"source": [
"#Check if the memory values are correct\n",
"obi_read = x_heep.read_obi(obi)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fd8e74c7",
"id": "b4b82dd7",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -101,14 +90,6 @@
"# Delete OBI\n",
"del obi"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "19eca63d",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
34 changes: 7 additions & 27 deletions sw/arm/jupyter_notebooks/virtual_obi_write.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"metadata": {},
"outputs": [],
"source": [
"#Initialize the OBI\n",
"obi = x_heep.init_obi()"
"# Init the OBI memory\n",
"obi = x_heep.init_obi_mem()"
]
},
{
Expand All @@ -51,19 +51,8 @@
"metadata": {},
"outputs": [],
"source": [
"#Reset the OBI\n",
"x_heep.reset_obi(obi)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2f6a9c40",
"metadata": {},
"outputs": [],
"source": [
"#Check if the memory is resetted to zeros\n",
"obi_read = x_heep.read_obi(obi)"
"# Reset the OBI memory\n",
"x_heep.reset_obi_mem(obi)"
]
},
{
Expand All @@ -84,14 +73,13 @@
"metadata": {},
"outputs": [],
"source": [
"#Read the memory and compare with what is expected\n",
"obi_read = x_heep.read_obi(obi)\n",
"# Read the OBI memory\n",
"obi_read = x_heep.read_obi_mem(obi)\n",
"target_read = list()\n",
"for i in range(1024):\n",
" target_read.append(i ** 2)\n",
"#print(target_read)\n",
"if target_read == obi_read:\n",
" print(\"Arrays matching! Write from RISCV Successful.\")"
" print(\"Write operation successful.\")"
]
},
{
Expand All @@ -104,14 +92,6 @@
"# Delete OBI\n",
"del obi"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c514a7ec",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
81 changes: 37 additions & 44 deletions sw/arm/sdk/x_heep_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,16 @@
import csv

ADC_OFFSET = 0x40000000
FLASH_AXI_ADDRESS_ADDER_OFFSET = 0x43c00000
#PERFORMANCE_COUNTERS_OFFSET = 0x43C10000
OBI_AXI_ADDRESS_ADDER_OFFSET = 0x43c10000
PERFORMANCE_COUNTERS_OFFSET = 0x43c20000
FLASH_AXI_ADDRESS_ADDER_OFFSET = 0x43C00000
OBI_AXI_ADDRESS_ADDER_OFFSET = 0x43C10000
PERFORMANCE_COUNTERS_OFFSET = 0x43C20000

class x_heep(Overlay):

def __init__(self, ILA_debug = False, **kwargs):

# Load bitstream
if not ILA_debug:
super().__init__("/home/xilinx/x-heep-femu-sdk/hw/x_heep.bit", **kwargs)
else:
"""
When debugging with ILA, you first need to program the FPGA with base.bit, then program it again from the Vivado with the desired bitstream file. For this, set ILA_debug = True when debugging and initializing the x_heep class in Python.
"""
super().__init__("base.bit", **kwargs)
super().__init__("/home/xilinx/x-heep-femu-sdk/hw/x_heep.bit", **kwargs)


def load_bitstream(self):
Expand Down Expand Up @@ -70,36 +63,13 @@ def init_flash(self):
flash[:] = 0

return flash

def init_obi(self):

# Allocate OBI Memory
obi = allocate(shape=(1024,)) #32768 -> old value

# Write Flash base address to AXI address adder
axi_address_adder = MMIO(OBI_AXI_ADDRESS_ADDER_OFFSET, 0x4)
axi_address_adder.write(0x0, obi.physical_address)

#Test: Check if the value written and read from the register is the same or not.
#result = axi_address_adder.read(0x0)
#print(obi.physical_address == result)

# Reset Flash
obi[:] = 0

return obi


def reset_flash(self, flash):

# Reset Flash
flash[:] = 0

def reset_obi(self, obi):

# Reset OBI
obi[:] = 0


def write_flash(self, flash):

Expand All @@ -110,11 +80,6 @@ def write_flash(self, flash):
flash[i] = (file_byte[i*4+3] << 24) | (file_byte[i*4+2] << 16) | (file_byte[i*4+1] << 8) | file_byte[i*4];
file.close()

def write_obi_memory(self, write_list, obi):

#Write to the memory space allocated for OBI applications a test case
obi[:] = write_list


def read_flash(self, flash):

Expand All @@ -123,11 +88,6 @@ def read_flash(self, flash):
byte_array = bytearray(flash)
file.write(byte_array)
file.close()

def read_obi(self, obi):

print(obi)
return list(obi)


def init_adc_mem(self):
Expand Down Expand Up @@ -168,6 +128,39 @@ def read_adc_mem(self, adc_mem):
file.close()


def init_obi_mem(self):

# Allocate OBI memory
obi = allocate(shape=(1024,))

# Write OBI memory base address to AXI address adder
axi_address_adder = MMIO(OBI_AXI_ADDRESS_ADDER_OFFSET, 0x4)
axi_address_adder.write(0x0, obi.physical_address)

# Reset OBI memory
obi[:] = 0

return obi


def reset_obi_mem(self, obi):

# Reset OBI memory
obi[:] = 0


def write_obi_mem(self, write_list, obi):

# Write OBI memory
obi[:] = write_list


def read_obi_mem(self, obi):

# Read OBI memory
return list(obi)


def init_perf_cnt(self):

# Map performance counters
Expand Down
Loading

0 comments on commit 7c256d3

Please sign in to comment.