Skip to content
Snippets Groups Projects
Commit fa01c039 authored by auphelia's avatar auphelia
Browse files

[Streaming FC & test] added experimental dimension fliiping

parent 6faafc0e
No related branches found
No related tags found
No related merge requests found
...@@ -469,6 +469,10 @@ class StreamingFCLayer_Batch(HLSCustomOp): ...@@ -469,6 +469,10 @@ class StreamingFCLayer_Batch(HLSCustomOp):
# reshape weight tensor to desired shape # reshape weight tensor to desired shape
pe = self.get_nodeattr("PE") pe = self.get_nodeattr("PE")
simd = self.get_nodeattr("SIMD") simd = self.get_nodeattr("SIMD")
if simd > pe:
weight_tensor = np.flip(weight_tensor, axis=-3)
#weight_tensor = np.flip(weight_tensor, axis=-2)
weight_tensor = weight_tensor.reshape(1, -1, pe*simd) weight_tensor = weight_tensor.reshape(1, -1, pe*simd)
np.save( np.save(
os.path.join(code_gen_dir, "weights.npy"), os.path.join(code_gen_dir, "weights.npy"),
......
...@@ -134,13 +134,13 @@ def prepare_inputs(input_tensor, idt, wdt): ...@@ -134,13 +134,13 @@ def prepare_inputs(input_tensor, idt, wdt):
# activation: None or DataType # activation: None or DataType
@pytest.mark.parametrize("act", [None, DataType.BIPOLAR, DataType.INT2]) @pytest.mark.parametrize("act", [None, DataType.BIPOLAR, DataType.INT2])
# weight datatype # weight datatype
@pytest.mark.parametrize("wdt", [DataType.INT2]) @pytest.mark.parametrize("wdt", [DataType.BIPOLAR, DataType.INT2])
# input datatype # input datatype
@pytest.mark.parametrize("idt", [DataType.INT2]) @pytest.mark.parametrize("idt", [DataType.BIPOLAR, DataType.INT2])
# neuron folding, -1 is maximum possible # neuron folding, -1 is maximum possible
@pytest.mark.parametrize("nf", [-1]) #, 1]) @pytest.mark.parametrize("nf", [-1]) #, 1])
# synapse folding, -1 is maximum possible # synapse folding, -1 is maximum possible
@pytest.mark.parametrize("sf", [1]) @pytest.mark.parametrize("sf", [1]) #, 1])
# HLS matrix width (input features) # HLS matrix width (input features)
@pytest.mark.parametrize("mw", [4]) @pytest.mark.parametrize("mw", [4])
# HLS matrix height (output features) # HLS matrix height (output features)
...@@ -155,13 +155,13 @@ def test_fpgadataflow_fclayer_npysim(mem_mode, idt, wdt, act, nf, sf, mw, mh): ...@@ -155,13 +155,13 @@ def test_fpgadataflow_fclayer_npysim(mem_mode, idt, wdt, act, nf, sf, mw, mh):
assert mh % pe == 0 assert mh % pe == 0
assert mw % sf == 0 assert mw % sf == 0
# generate weights # generate weights
#W = gen_finn_dt_tensor(wdt, (mw, mh)) W = gen_finn_dt_tensor(wdt, (mw, mh))
#W = np.eye(mw, mh) #W = np.eye(mw, mh)
W = np.asarray([-2., -2., 1., -2., 0., -1., -2., 0., -1., -1., 0., 0., -2., -1., 1., -1.], dtype=np.float32).reshape(mw, mh) #W = np.asarray([-2., -2., 1., -2., 0., -1., -2., 0., -1., -1., 0., 0., -2., -1., 1., -1.], dtype=np.float32).reshape(mw, mh)
#import pdb; pdb.set_trace() #import pdb; pdb.set_trace()
# generate input data # generate input data
#x = gen_finn_dt_tensor(idt, (1, mw)) x = gen_finn_dt_tensor(idt, (1, mw))
x = np.asarray([[-2, -1, 0, 1]], dtype=np.float32) #x = np.asarray([[-2, -1, 0, 1]], dtype=np.float32)
if act is None: if act is None:
# no activation, produce accumulators # no activation, produce accumulators
T = None T = None
...@@ -212,7 +212,10 @@ def test_fpgadataflow_fclayer_npysim(mem_mode, idt, wdt, act, nf, sf, mw, mh): ...@@ -212,7 +212,10 @@ def test_fpgadataflow_fclayer_npysim(mem_mode, idt, wdt, act, nf, sf, mw, mh):
y_expected = y.reshape(oshape) y_expected = y.reshape(oshape)
# execute model # execute model
y_produced = oxe.execute_onnx(model, input_dict)["outp"] y_produced = oxe.execute_onnx(model, input_dict)["outp"]
if (y_produced.reshape(y_expected.shape) == y_expected).all(): y_produced =y_produced.reshape(y_expected.shape)
if simd > pe:
y_produced = np.flip(y_produced,axis=1)
if (y_produced == y_expected).all():
test = "passed" test = "passed"
else: else:
test = "failed" test = "failed"
...@@ -222,7 +225,7 @@ def test_fpgadataflow_fclayer_npysim(mem_mode, idt, wdt, act, nf, sf, mw, mh): ...@@ -222,7 +225,7 @@ def test_fpgadataflow_fclayer_npysim(mem_mode, idt, wdt, act, nf, sf, mw, mh):
act = "None" act = "None"
writer = csv.writer(file) writer = csv.writer(file)
writer.writerow([act, wdt, idt, nf, sf, mw, mh, test, y_expected, y_produced]) writer.writerow([act, wdt, idt, nf, sf, mw, mh, test, y_expected, y_produced])
assert (y_produced.reshape(y_expected.shape) == y_expected).all(), "npysim failed" assert (y_produced == y_expected).all(), "npysim failed"
# activation: None or DataType # activation: None or DataType
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment