-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from AlexMontgomerie/dev-petros
dev-petros - Branch Optimization
- Loading branch information
Showing
99 changed files
with
23,810 additions
and
1,034 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import numpy as np | ||
import math | ||
import pydot | ||
from typing import Union, List | ||
|
||
from fpgaconvnet.data_types import FixedPoint | ||
|
||
from fpgaconvnet.models.modules import Concat3D | ||
from fpgaconvnet.models.layers import MultiPortLayer3D | ||
|
||
from fpgaconvnet.models.layers.utils import get_factors | ||
|
||
class ConcatLayer3D(MultiPortLayer3D): | ||
def __init__( | ||
self, | ||
rows: int, | ||
cols: int, | ||
depth: int, | ||
channels: List[int], | ||
ports_in: int = 1, | ||
coarse: int = 1, | ||
data_t: FixedPoint = FixedPoint(16,8), | ||
backend: str = "chisel", # default to no bias for old configs | ||
regression_model: str = "linear_regression", | ||
input_compression_ratio: list = [1.0], | ||
output_compression_ratio: list = [1.0] | ||
): | ||
|
||
# initialise parent class | ||
super().__init__([rows]*ports_in, [cols]*ports_in, [depth]*ports_in, channels, | ||
[coarse]*ports_in, [coarse]*ports_in, ports_in=ports_in, | ||
data_t=data_t, | ||
input_compression_ratio=input_compression_ratio, | ||
output_compression_ratio=output_compression_ratio) | ||
|
||
self.mem_bw_in = [100.0] * self.ports_in | ||
# parameters | ||
self._coarse = coarse | ||
|
||
# backend flag | ||
assert backend in ["chisel"], f"{backend} is an invalid backend" | ||
self.backend = backend | ||
|
||
# regression model | ||
assert regression_model in ["linear_regression", "xgboost"], f"{regression_model} is an invalid regression model" | ||
self.regression_model = regression_model | ||
|
||
# init modules | ||
self.modules = { | ||
# "concat3d" : Concat(self.rows_in(), self.cols_in(), self.depth_in(), self.channels, self.ports_in, | ||
# backend=self.backend, regression_model=self.regression_model), | ||
"concat3d" : Concat3D(self.rows_in(), self.cols_in(), self.depth_in(), self.channels, self.ports_in, | ||
backend=self.backend, regression_model=self.regression_model), | ||
} | ||
|
||
# update the layer | ||
self.update() | ||
|
||
def channels_out(self, port_index=0): | ||
assert port_index == 0, "ConcatLayer only has a single output port" | ||
return sum(self.channels) | ||
|
||
@property | ||
def coarse(self) -> int: | ||
return self._coarse | ||
|
||
@property | ||
def coarse_in(self) -> int: | ||
return [self._coarse]*self.ports_in | ||
|
||
@property | ||
def coarse_out(self) -> int: | ||
return [self._coarse] | ||
|
||
@coarse.setter | ||
def coarse(self, val: int) -> None: | ||
self._coarse = val | ||
self.update() | ||
|
||
@coarse_in.setter | ||
def coarse_in(self, val: int) -> None: | ||
self._coarse = val | ||
self.update() | ||
|
||
@coarse_out.setter | ||
def coarse_out(self, val: int) -> None: | ||
self._coarse = val | ||
self.update() | ||
|
||
def rates_in(self, port_index=0): | ||
assert port_index < self.ports_in | ||
return self.modules["concat"].rate_in(port_index) | ||
|
||
def rates_out(self, port_index=0): | ||
assert port_index == 0, "ConcatLayer3D only has a single output port" | ||
return self.modules["concat3d"].rate_out() | ||
|
||
def get_coarse_in_feasible(self, port_index=0): | ||
assert(port_index < self.ports_in) | ||
factors = set( get_factors(self.channels_in(0)) ) | ||
for i in range(self.ports_in): | ||
factors &= set( get_factors(self.channels_in(i)) ) | ||
return list(factors) | ||
|
||
def get_coarse_out_feasible(self, port_index=0): | ||
assert(port_index < self.ports_out) | ||
return self.get_coarse_in_feasible() | ||
|
||
def update(self): | ||
# concat | ||
self.modules["concat3d"].rows = self.rows_in() | ||
self.modules["concat3d"].cols = self.cols_in() | ||
self.modules["concat3d"].depth = self.depth_in() | ||
self.modules["concat3d"].channels = [self.channels_in(i)//self.coarse for i in range(self.ports_in)] | ||
self.modules["concat3d"].ports_in = self.ports_in | ||
|
||
def layer_info(self,parameters,batch_size=1): | ||
MultiPortLayer3D.layer_info(self, parameters, batch_size) | ||
parameters.rows_in = self.rows_in() | ||
parameters.cols_in = self.cols_in() | ||
parameters.depth_in = self.depth_in() | ||
parameters.rows_out = self.rows_out() | ||
parameters.cols_out = self.cols_out() | ||
parameters.depth_out = self.depth_out() | ||
parameters.channels_out = self.channels_out() | ||
parameters.coarse = self._coarse | ||
# remove the repeated rows, cols and channels | ||
del parameters.rows_in_array[:] | ||
del parameters.cols_in_array[:] | ||
del parameters.depth_in_array[:] | ||
del parameters.rows_out_array[:] | ||
del parameters.cols_out_array[:] | ||
del parameters.depth_out_array[:] | ||
del parameters.channels_out_array[:] | ||
|
Oops, something went wrong.