Skip to content

Commit

Permalink
started split layer (#26)
Browse files Browse the repository at this point in the history
* started split layer

* working with main branch now (for current tests)

* added test for optimiser

* working on improving resource modelling

* updated resource models

* changes to split layer

* fixed merge conflict

* updated visualiser and fn model for splitlayer

Co-authored-by: AlexMontgomerie <[email protected]>
Co-authored-by: AlexMontgomerie <[email protected]>
  • Loading branch information
3 people authored and Ben Biggs committed Jul 6, 2021
1 parent 1873043 commit 729db73
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 28 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ A suite of tests have been created for the optimiser repo. To run all of them, u
python -m unittest discover tests/
```

## Testing

A suite of tests have been created for the optimiser repo. To run all of them, use the following:

```
python -m unittest discover tests/
```

## Optimiser Framework

The main tool is the optimisation script which generates an optimised hardware topology for a given model and platform. There are several components needed for this: a model of the hardware, transforms that map the model to the hardware and an optimisation scheme that chooses the best mapping. These will be outlined later.
Expand Down
2 changes: 2 additions & 0 deletions fpgaconvnet_optimiser/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

import fpgaconvnet_optimiser.tools.graphs as graphs

import fpgaconvnet_optimiser.tools.graphs as graphs

def main():
parser = argparse.ArgumentParser(description="Optimiser Script")
parser.add_argument('-n','--name',metavar='PATH',required=True,
Expand Down
12 changes: 6 additions & 6 deletions fpgaconvnet_optimiser/models/layers/ConvolutionLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ def rates_graph(self):
rates_graph[0,0] = 1
rates_graph[0,1] = 1
else:
rates_graph[0,0] = self.modules['sliding_window'].rate_in(0)
rates_graph[0,1] = self.modules['sliding_window'].rate_out(0)
rates_graph[0,0] = self.modules['sliding_window'].rate_in()
rates_graph[0,1] = self.modules['sliding_window'].rate_out()
# fork
rates_graph[1,1] = self.modules['fork'].rate_in(0)
rates_graph[1,2] = self.modules['fork'].rate_out(0)
rates_graph[1,1] = self.modules['fork'].rate_in()
rates_graph[1,2] = self.modules['fork'].rate_out()
# conv
rates_graph[2,2] = self.modules['conv'].rate_in(0)
rates_graph[2,3] = self.modules['conv'].rate_out(0)
rates_graph[2,2] = self.modules['conv'].rate_in()
rates_graph[2,3] = self.modules['conv'].rate_out()
# accum
rates_graph[3,3] = self.modules['accum'].rate_in(0)
rates_graph[3,4] = self.modules['accum'].rate_out(0)
Expand Down
12 changes: 6 additions & 6 deletions fpgaconvnet_optimiser/models/layers/InnerProductLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ def rates_graph(self):
rates_graph[0,0] = self.modules['fork'].rate_in(0)
rates_graph[0,1] = self.modules['fork'].rate_out(0)
# conv
rates_graph[1,1] = self.modules['conv'].rate_in(0)
rates_graph[1,2] = self.modules['conv'].rate_out(0)
rates_graph[1,1] = self.modules['conv'].rate_in()
rates_graph[1,2] = self.modules['conv'].rate_out()
# accum
rates_graph[2,2] = self.modules['accum'].rate_in(0)
rates_graph[2,3] = self.modules['accum'].rate_out(0)
rates_graph[2,2] = self.modules['accum'].rate_in()
rates_graph[2,3] = self.modules['accum'].rate_out()
# glue
rates_graph[3,3] = self.modules['glue'].rate_in(0)
rates_graph[3,4] = self.modules['glue'].rate_out(0)
rates_graph[3,3] = self.modules['glue'].rate_in()
rates_graph[3,4] = self.modules['glue'].rate_out()

return rates_graph

Expand Down
1 change: 0 additions & 1 deletion fpgaconvnet_optimiser/models/layers/Layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ def load_coef(self):
# "../../coefficients/{}_rsc_coef.npy".format(module))
# )


def update(self):
pass

Expand Down
10 changes: 5 additions & 5 deletions fpgaconvnet_optimiser/models/layers/PoolingLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(
k_size =2,
stride =2,
pad =0,
fine =1,
fine =1
):

# initialise parent class
Expand Down Expand Up @@ -108,11 +108,11 @@ def update(self):
def rates_graph(self):
rates_graph = np.zeros( shape=(2,3) , dtype=float )
# sliding_window
rates_graph[0,0] = self.modules['sliding_window'].rate_in(0)
rates_graph[0,1] = self.modules['sliding_window'].rate_out(0)
rates_graph[0,0] = self.modules['sliding_window'].rate_in()
rates_graph[0,1] = self.modules['sliding_window'].rate_out()
# pool
rates_graph[1,1] = self.modules['pool'].rate_in(0)
rates_graph[1,2] = self.modules['pool'].rate_out(0)
rates_graph[1,1] = self.modules['pool'].rate_in()
rates_graph[1,2] = self.modules['pool'].rate_out()

return rates_graph

Expand Down
34 changes: 30 additions & 4 deletions tests/test_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class TestPoolingLayer(TestLayerTemplate,unittest.TestCase):
"tests/configs/layers/pooling/config_12.json",
)
def test_layer_configurations(self, config_path):

# open configuration
with open(config_path, "r") as f:
config = json.load(f)
Expand All @@ -59,7 +58,6 @@ def test_layer_configurations(self, config_path):
stride=config["stride"],
pad=config["pad"],
)

# run tests
self.run_test_dimensions(layer)
self.run_test_rates(layer)
Expand Down Expand Up @@ -88,12 +86,10 @@ class TestConvolutionLayer(TestLayerTemplate,unittest.TestCase):
"tests/configs/layers/convolution/config_19.json",
)
def test_layer_configurations(self, config_path):

# open configuration
with open(config_path, "r") as f:
config = json.load(f)

# initialise layer
layer = ConvolutionLayer(
config["filters"],
config["rows"],
Expand All @@ -108,6 +104,36 @@ def test_layer_configurations(self, config_path):
fine=config["fine"],
)

# run tests
self.run_test_dimensions(layer)
self.run_test_rates(layer)

@ddt.ddt
class TestSplitLayer(TestLayerTemplate,unittest.TestCase):

@ddt.data(
"tests/configs/layers/split/config_0.json",
)
def test_layer_configurations(self, config_path):

# open configuration
with open(config_path, "r") as f:
config = json.load(f)

# initialise layer
layer = SplitLayer(
config["rows"],
config["cols"],
config["channels"],
config["coarse"],
ports_out=config["ports_out"]
)

# run tests
self.run_test_dimensions(layer)
self.run_test_rates(layer)


# run tests
self.run_test_dimensions(layer)
self.run_test_rates(layer)
Expand Down
15 changes: 9 additions & 6 deletions tests/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ def run_test_resources(self, module):
self.assertGreaterEqual(rsc["BRAM"], 0.0)


def run_test_resources(self, module):

rsc = module.rsc()
self.assertGreaterEqual(rsc["LUT"], 0.0)
self.assertGreaterEqual(rsc["FF"], 0.0)
self.assertGreaterEqual(rsc["DSP"], 0.0)
self.assertGreaterEqual(rsc["BRAM"], 0.0)


@ddt.ddt
class TestForkModule(TestModuleTemplate,unittest.TestCase):

Expand Down Expand Up @@ -77,12 +86,6 @@ def test_module_configurations(self, config_path):
self.run_test_methods_exist(module)
self.run_test_dimensions(module)
self.run_test_rates(module)
<<<<<<< HEAD

=======
self.run_test_resources(module)

>>>>>>> 9c525fe... started split layer (#26)
# additional checks
self.assertGreater(module.filters,0)

Expand Down

0 comments on commit 729db73

Please sign in to comment.