def test_ne(self): ''' Whether ne. ''' fr1 = FmapRange((1, 2, 3, 4), (5, 7, 11, 13)) fr2 = FmapRange((1, 2, 3, 4), (5, 7, 11, 17)) fr3 = FmapRange((1, 2, 3, 17), (5, 7, 11, 20)) self.assertNotEqual(fr1, fr2) self.assertNotEqual(fr1, fr3)
def test_init_ext(self): ''' Initial with external layers. ''' self.network.add_ext('e0', InputLayer(3, 224)) self.network.add_ext('e1', InputLayer(6, 224)) e0_layout = DataLayout(frngs=(FmapRange( (0, 0, 0, 0), FmapPosition(b=self.batch_size, n=self.network['e0'].nofm, h=self.network['e0'].hofm, w=self.network['e0'].wofm)), ), regions=self.input_layout.regions, parts=self.input_layout.parts) e1_layout = DataLayout(frngs=(FmapRange( (0, 0, 0, 0), FmapPosition(b=self.batch_size, n=self.network['e1'].nofm, h=self.network['e1'].hofm, w=self.network['e1'].wofm)), ), regions=self.input_layout.regions, parts=self.input_layout.parts) ext_layout_dict = {'e0': e0_layout, 'e1': e1_layout} df = NNDataflowScheme(self.network, self.input_layout, ext_layout_dict) self.assertIn('e0', df.ext_layout_dict) self.assertIn('e1', df.ext_layout_dict) self.assertEqual(df.ext_layout_dict['e0'], e0_layout) self.assertEqual(df.ext_layout_dict['e1'], e1_layout)
def test_view(self): ''' Get view. ''' frm = self.frm.copy() frm.add(FmapRange((0, 0, 0, 16), (4, 4, 16, 20)), (PhyDim2(2, 2), PhyDim2(3, 3))) frm.add(FmapRange((0, 0, 16, 0), (4, 4, 20, 20)), (PhyDim2(1, 1), PhyDim2(3, 3), PhyDim2(5, 5))) dly = DataLayout(origin=PhyDim2(1, 1), frmap=frm, type=NodeRegion.DATA) cfr = dly.frmap.complete_fmap_range() counters = dly.frmap.rget_counter(cfr) nhops = dly.total_transfer_nhops(cfr, PhyDim2(1, 2)) dly1 = dly.view(PhyDim2(-1, -1)) self.assertEqual(dly1.origin, PhyDim2(0, 0), 'view: origin') self.assertEqual(dly1.type, dly.type, 'view: type') self.assertEqual(dly1.frmap.complete_fmap_range(), cfr, 'view: complete_fmap_range') self.assertDictEqual(dly1.frmap.rget_counter(cfr), counters, 'view: counter') self.assertEqual( dly1.total_transfer_nhops(cfr, PhyDim2(1, 2) + PhyDim2(-1, -1)), nhops, 'view: nhops') dly2 = dly.view(PhyDim2(3, 1)) self.assertEqual(dly2.type, dly.type, 'view: type') self.assertEqual(dly2.frmap.complete_fmap_range(), cfr, 'view: complete_fmap_range') self.assertDictEqual(dly2.frmap.rget_counter(cfr), counters, 'view: counter') self.assertEqual( dly2.total_transfer_nhops(cfr, PhyDim2(1, 2) + PhyDim2(3, 1)), nhops, 'view: nhops')
def test_eq(self): ''' Whether eq. ''' fr1 = FmapRange((1, 2, 3, 4), (5, 7, 11, 13)) fr2 = FmapRange((1, 2, 3, 4), (5, 7, 11, 13)) self.assertEqual(fr1, fr2) _ = fr1 == 4
def test_merge_unmatch(self): ''' Merge unmatch. ''' for fr in [ FmapRange((0, ) * 4, (4, 4, 10, 16)), FmapRange((0, ) * 4, (4, 4, 16, 32)), FmapRange((0, ) * 4, (3, 4, 16, 16)) ]: frm = FmapRangeMap() frm.add(fr, (PhyDim2(1, 1), )) dly = DataLayout(origin=PhyDim2(-1, -1), frmap=frm, type=NodeRegion.DATA) with self.assertRaisesRegexp(ValueError, 'DataLayout: .*match.*'): _ = self.dly.merge('|', dly) with self.assertRaisesRegexp(ValueError, 'DataLayout: .*match.*'): _ = self.dly.merge('+', dly) frm = FmapRangeMap() frm.add(FmapRange((0, ) * 4, (4, 2, 16, 16)), (PhyDim2(1, 1), )) dly = DataLayout(origin=PhyDim2(-1, -1), frmap=frm, type=NodeRegion.DATA) with self.assertRaisesRegexp(ValueError, 'DataLayout: .*match.*'): _ = self.dly.merge('+', dly)
def test_size(self): ''' Get size. ''' fr = FmapRange((-11, -4, 3, 0), (3, 5, 7, 11)) self.assertEqual(fr.size('n', 'w'), (5 + 4) * 11, 'size: nw') self.assertEqual(fr.size('h'), 7 - 3, 'size: h') self.assertEqual(fr.size(), 14 * 9 * 4 * 11, 'size: all')
def test_merge(self): ''' Merge. ''' fr = FmapRange((0, ) * 4, (30, ) * 4) frm = FmapRangeMap() frm.add(FmapRange((0, 0, 0, 0), (4, 1, 16, 16)), (PhyDim2(0, 0), PhyDim2(1, 1))) frm.add(FmapRange((0, 1, 0, 0), (4, 3, 16, 16)), (PhyDim2(1, 0), PhyDim2(2, 2))) dly = DataLayout(origin=PhyDim2(-1, -1), frmap=frm, type=NodeRegion.DATA) mdly1 = self.dly.merge('|', dly) mdly2 = dly.merge('|', self.dly) self.assertEqual(mdly1.type, self.dly.type, 'merge |: type') self.assertEqual(mdly2.type, dly.type, 'merge |: type') self.assertEqual(mdly1.frmap.complete_fmap_range(), mdly2.frmap.complete_fmap_range(), 'merge |: complete_fmap_range') self.assertEqual( mdly1.frmap.complete_fmap_range().size(), self.frm.complete_fmap_range().size() + frm.complete_fmap_range().size(), 'merge |: complete_fmap_range: size') self.assertEqual(mdly1.total_transfer_nhops(fr, PhyDim2(0, 0)), mdly2.total_transfer_nhops(fr, PhyDim2(0, 0)), 'merge |: nhops') self.assertEqual( mdly1.total_transfer_nhops(fr, PhyDim2(0, 0)), self.dly.total_transfer_nhops(fr, PhyDim2(0, 0)) + dly.total_transfer_nhops(fr, PhyDim2(0, 0)), 'merge |: nhops') frm.add(FmapRange((0, 3, 0, 0), (4, 4, 16, 16)), (PhyDim2(1, 3), PhyDim2(2, 1), PhyDim2(-1, -2))) # Only type differs from self.dly. sdly = DataLayout(origin=self.dly.origin, frmap=self.dly.frmap, type=NodeRegion.PROC) dly = DataLayout(origin=PhyDim2(-1, -1), frmap=frm, type=NodeRegion.PROC) mdly1 = sdly.merge('+', dly) mdly2 = dly.merge('+', sdly) self.assertEqual(mdly1.type, sdly.type, 'merge +: type') self.assertEqual(mdly2.type, dly.type, 'merge +: type') self.assertEqual(mdly1.frmap.complete_fmap_range(), mdly2.frmap.complete_fmap_range(), 'merge +: complete_fmap_range') self.assertEqual(mdly1.frmap.complete_fmap_range().size(), self.frm.complete_fmap_range().size(), 'merge +: complete_fmap_range: size') self.assertEqual(mdly1.total_transfer_nhops(fr, PhyDim2(0, 0)), mdly2.total_transfer_nhops(fr, PhyDim2(0, 0)), 'merge +: nhops') self.assertEqual( mdly1.total_transfer_nhops(fr, PhyDim2(0, 0)), sdly.total_transfer_nhops(fr, PhyDim2(0, 0)) + dly.total_transfer_nhops(fr, PhyDim2(0, 0)), 'merge +: nhops')
def test_repr(self): ''' __repr__. ''' # pylint: disable=eval-used for fr in [FmapRange((0, 0, 0, 0), (3, 5, 7, 11)), FmapRange((-11, -4, 3, 0), (3, 5, 7, 11)), FmapRange((-11, -4, 3, 0), (3, 5, 7, 11)), FmapRange((0, 0, 3, 1), (1, 1, 5, 5))]: self.assertEqual(eval(repr(fr)), fr)
def test_complete_fmap_range(self): ''' Get complete_fmap_range. ''' dl = DataLayout(frngs=(self.frng1, FmapRange((0, 4, 0, 0), (4, 8, 16, 16))), regions=(self.region1, self.region2), parts=(self.part1, self.part2)) self.assertEqual(dl.complete_fmap_range(), FmapRange((0, 0, 0, 0), (4, 8, 16, 16)))
def test_eq(self): ''' Whether eq. ''' fr1 = FmapRange((1, 2, 3, 4), (5, 7, 11, 13)) fr2 = FmapRange((1, 2, 3, 4), (5, 7, 11, 13)) self.assertEqual(fr1, fr2) fr3 = FmapRange((1, 1, 1, 1), (1, 2, 2, 2)) fr4 = FmapRange((0, 0, 0, 0), (0, 0, 0, 0)) self.assertEqual(fr3, fr4)
def test_compare_empty(self): ''' Comparison with empty FmapRange. ''' fr1 = FmapRange((-11, -4, 3, 0), (3, 5, 7, 11)) fr2 = FmapRange((100, 1, 1, 1), (101, 2, 2, 2)) fr3 = FmapRange((1, 1, 1, 1), (1, 2, 2, 2)) fr4 = FmapRange((0, 0, 0, 0), (0, 0, 0, 0)) self.assertLess(fr1, fr2) self.assertGreater(fr1, fr3) self.assertTrue(fr3 == fr4 < fr1 < fr2)
def test_rget_single(self): ''' Get rget_single. ''' for k, v in self.frm.items(): self.assertEqual(self.frm.rget_single(k), v, 'rget_single') val = self.frm.rget_single(FmapRange((0, 0, 0, 0), (1, 1, 1, 1))) self.assertEqual(val, 0, 'rget_single') val = self.frm.rget_single(FmapRange((3, 1, 10, 3), (4, 3, 13, 7))) self.assertEqual(val, 5, 'rget_single')
def test_contains(self): ''' Whether contains fmap point. ''' fr = FmapRange((-11, -4, 3, 0), (3, 5, 7, 11)) for fp in fr.range(): self.assertTrue(fp in fr, 'contains') num = 0 for fp in FmapRange((-12, -12, -12, -12), (12, 12, 12, 12)).range(): num += 1 if fp in fr else 0 self.assertEqual(num, fr.size())
def setUp(self): self.frm = FmapRangeMap() self.frm.add(FmapRange((0, 0, 0, 0), (2, 4, 8, 16)), (PhyDim2(0, 0), )) self.frm.add(FmapRange((0, 0, 8, 0), (2, 4, 16, 16)), (PhyDim2(1, 0), )) self.frm.add(FmapRange((2, 0, 0, 0), (4, 4, 8, 16)), (PhyDim2(0, 1), )) self.frm.add(FmapRange((2, 0, 8, 0), (4, 4, 16, 16)), (PhyDim2(1, 1), )) self.dly = DataLayout(origin=PhyDim2(1, 1), frmap=self.frm, type=NodeRegion.DATA)
def test_is_complete_incomplete(self): ''' Get complete_fmap_range incomplete. ''' self.frm.add(FmapRange((4, 8, 16, 16), (5, 9, 17, 17)), 10) self.assertFalse(self.frm.is_complete(), 'is_complete: incomplete') with self.assertRaisesRegex(ValueError, 'FmapRangeMap: .*complete.*'): _ = self.frm.complete_fmap_range() fr = FmapRange((1, 0, 0, 0), (3, 5, 7, 9)) frm = FmapRangeMap() frm.add(fr, 3.4) self.assertFalse(frm.is_complete(), 'is_complete: incomplete') with self.assertRaisesRegex(ValueError, 'FmapRangeMap: .*complete.*'): _ = frm.complete_fmap_range()
def test_concat_unmatch(self): ''' Concat unmatch. ''' for fr in [ FmapRange((0, ) * 4, (4, 4, 10, 16)), FmapRange((0, ) * 4, (4, 4, 16, 32)), FmapRange((0, ) * 4, (3, 4, 16, 16)) ]: dl = DataLayout(frngs=(fr, ), regions=(self.region1, ), parts=(self.part1, )) with self.assertRaisesRegexp(ValueError, 'DataLayout: .*match.*'): _ = DataLayout.concat(self.dl1, dl)
def test_compare_overlap(self): ''' Comparison with overlapping FmapRange. ''' fr1 = FmapRange((-11, -4, 3, 0), (3, 5, 7, 11)) fr2 = FmapRange((-11, -4, 3, 0), (1, 1, 5, 5)) fr3 = FmapRange((0, 0, 3, 1), (1, 1, 5, 5)) fr4 = FmapRange((0, 0, 3, 1), (3, 5, 7, 11)) with self.assertRaisesRegex(ValueError, 'FmapRange: .*overlap.*'): _ = fr1 < fr2 with self.assertRaisesRegex(ValueError, 'FmapRange: .*overlap.*'): _ = fr1 >= fr2 with self.assertRaisesRegex(ValueError, 'FmapRange: .*overlap.*'): _ = fr1 <= fr3 with self.assertRaisesRegex(ValueError, 'FmapRange: .*overlap.*'): _ = fr1 < fr4
def test_invalid_frmap_value_type(self): ''' Invalid frmap value type. ''' frm = FmapRangeMap() frm.add(FmapRange((0, ) * 4, (5, 5, 19, 19)), PhyDim2(4, 4)) with self.assertRaisesRegexp(TypeError, 'DataLayout: .*frmap.*'): _ = DataLayout(origin=PhyDim2(2, 3), frmap=frm, type=NodeRegion.DATA) frm = FmapRangeMap() frm.add(FmapRange((0, ) * 4, (5, 5, 19, 19)), (PhyDim2(4, 4), 4)) with self.assertRaisesRegexp(TypeError, 'DataLayout: .*frmap.*'): _ = DataLayout(origin=PhyDim2(2, 3), frmap=frm, type=NodeRegion.DATA)
def test_overlap(self): ''' Get overlap. ''' fr1 = FmapRange((-11, -4, 3, 0), (3, 5, 7, 11)) fr2 = FmapRange((0, 3, 3, -5), (3, 10, 4, 3)) ofr = fr1.overlap(fr2) self.assertListEqual(ofr.beg_end(), [(0, 3), (3, 5), (3, 4), (0, 3)], 'overlap') self.assertEqual(fr2.overlap(fr1), ofr, 'overlap: commutative') fr3 = FmapRange((0, 7, 3, -5), (3, 10, 4, 3)) ofr = fr1.overlap(fr3) self.assertListEqual(ofr.beg_end(), [(0, 0)] * 4, 'overlap: no') fr4 = FmapRange((-12, -12, -12, -12), (12, 12, 12, 12)) self.assertEqual(fr1.overlap(fr4), fr1)
def test_nhops_to(self): ''' Get nhops_to. ''' fr = FmapRange((0, ) * 4, (4, 4, 16, 16)) nhops = 2 * 4 * 8 * 16 * (5 + 6 + 6 + 7) self.assertEqual(self.dl1.nhops_to(fr, PhyDim2(-1, -2)), nhops) frng1 = FmapRange((0, 4, 0, 0), (4, 8, 16, 16)) dl = DataLayout(frngs=(self.frng1, frng1), regions=(self.region1, self.region2), parts=(self.part1, self.part2)) self.assertEqual(dl.nhops_to(fr, PhyDim2(-1, -2)), nhops) fr = FmapRange((0, ) * 4, (16, ) * 4) nhops += 2 * 4 * 16 * 16 * (3 + 4) self.assertEqual(dl.nhops_to(fr, PhyDim2(-1, -2)), nhops)
def test_compare_notimplemented(self): ''' Comparison with types not implemented. ''' ins1 = FmapRange((-11, -4, 3, 0), (3, 5, 7, 11)) ins2 = (3, 5, 7, 11) ins3 = None # The default comparison gives a consistent but arbitrary order. # https://docs.python.org/2/reference/expressions.html#value-comparisons sort = sorted([ins1, ins2, ins3]) self.assertGreater(sort[2], sort[1]) self.assertGreater(sort[2], sort[0]) self.assertGreater(sort[1], sort[0]) self.assertLess(sort[0], sort[1]) self.assertLess(sort[0], sort[2]) self.assertLess(sort[1], sort[2]) self.assertGreaterEqual(sort[2], sort[1]) self.assertGreaterEqual(sort[2], sort[0]) self.assertGreaterEqual(sort[1], sort[0]) self.assertLessEqual(sort[0], sort[1]) self.assertLessEqual(sort[0], sort[2]) self.assertLessEqual(sort[1], sort[2]) self.assertNotEqual(sort[0], sort[1]) self.assertNotEqual(sort[0], sort[2]) self.assertNotEqual(sort[1], sort[2])
def _make_data_layout(self, nfm, hfm, wfm, origin, nums, dims): ''' Make a DataLayout instance. ''' assert util.prod(nums) == dims.size() def _coord(idxs): # In the order of n, b, w, h, i.e., 1, 0, 3, 2. cflat = 0 for i in [1, 0, 3, 2]: cflat = cflat * nums[i] + idxs[i] assert cflat < dims.size() return PhyDim2(*divmod(cflat, dims.w)) sizes = (self.batch_size, nfm, hfm, wfm) frmap = FmapRangeMap() for idxs in itertools.product(*[range(n) for n in nums]): begs = [i * s // n for i, n, s in zip(idxs, nums, sizes)] ends = [(i + 1) * s // n for i, n, s in zip(idxs, nums, sizes)] frmap.add(FmapRange(begs, ends), (_coord(idxs), )) dl = DataLayout(frmap=frmap, origin=origin, type=NodeRegion.DATA) assert dl.frmap.complete_fmap_range().size() == util.prod(sizes) return dl
def setUp(self): self.resource = Resource( proc_region=NodeRegion(origin=PhyDim2(0, 0), dim=PhyDim2(1, 1), type=NodeRegion.PROC), dram_region=NodeRegion(origin=PhyDim2(0, 0), dim=PhyDim2(1, 1), type=NodeRegion.DRAM), src_data_region=NodeRegion(origin=PhyDim2(0, 0), dim=PhyDim2(1, 1), type=NodeRegion.DRAM), dst_data_region=NodeRegion(origin=PhyDim2(0, 0), dim=PhyDim2(1, 1), type=NodeRegion.DRAM), dim_array=PhyDim2(16, 16), size_gbuf=65536, size_regf=64, array_bus_width=float('inf'), dram_bandwidth=float('inf'), no_time_mux=False) self.none_cstr = SchedulingConstraint() part = PartitionScheme(order=range(pe.NUM), pdims=[(1, 1)] * pe.NUM) self.ifmap_layout = DataLayout( frngs=(FmapRange((0, 0, 0, 0), (2, 4, 16, 16)), ), regions=(self.resource.src_data_region, ), parts=(part, )) self.sched_seq = (2, 0, 0)
def test_ofmap_local(self): ''' With locally stored ofmaps. ''' layer = self.layers['BASE'] part = PartitionScheme(order=(pe.BATP, pe.INPP, pe.OUTP, pe.OFMP), pdims=((4, 1), (1, 1), (1, 4), (1, 1))) nr = NodeRegion(origin=PhyDim2(3, 3), dim=part.dim(), type=NodeRegion.PROC) ilayout = self._make_data_layout(layer.nifm, layer.hifm, layer.wifm, PhyDim2(-3, -3), (1, 1), (1, 1), PhyDim2(1, 1)) olayout = DataLayout(frngs=(FmapRange( (0, ) * 4, (self.batch_size, layer.nofm, layer.hofm, layer.wofm)), ), regions=(nr, ), parts=(part, )) filter_nodes = frozenset([PhyDim2(3, -3)]) nhops = partition.unit_nhops_to_proc_region(layer, self.batch_size, nr, part, filter_nodes, ilayout, olayout, self.options['BASE']) self.assertEqual(nhops[de.OFM], 0)
def setUp(self): self.scheme = OrderedDict([ ('cost', 9.876 + 1.234), ('time', 123.4), ('ops', 1234), ('num_nodes', 4), ('cost_op', 1.234), ('cost_access', 9.876), ('cost_noc', 0), ('cost_static', 0), ('proc_time', 59), ('bus_time', 40), ('dram_time', 120), ('access', [[2, 3, 4], [30, 40, 50], [400, 500, 600], [5000, 6000, 7000]]), ('remote_gbuf_access', [0, 0, 0]), ('total_nhops', [123, 456, 789]), ('fetch', [[1, 2, 1], [3, 4, 5]]), ]) part = PartitionScheme(order=range(pe.NUM), pdims=[(1, 1)] * pe.NUM) self.ofmap_layout = DataLayout( frngs=(FmapRange((0, 0, 0, 0), (2, 4, 16, 16)), ), regions=(NodeRegion(origin=PhyDim2(0, 0), dim=PhyDim2(1, 1), type=NodeRegion.DRAM), ), parts=(part, )) self.sched_seq = (2, 0, 0)
def test_invalid_frmap_incomplete(self): ''' Invalid frmap incomplete. ''' frm = self.frm.copy() frm.add(FmapRange((4, 4, 16, 16), (5, 5, 19, 19)), (PhyDim2(4, 4), )) with self.assertRaisesRegexp(ValueError, 'DataLayout: .*frmap.*'): _ = DataLayout(origin=PhyDim2(2, 3), frmap=frm, type=NodeRegion.DATA)
def test_copy(self): ''' Copy. ''' frm = self.frm.copy() self.assertListEqual(list(frm.items()), list(self.frm.items()), 'copy: equal') fr1 = FmapRange((10, 10, 10, 10), (11, 11, 11, 11)) frm.add(fr1, 10) self.assertEqual(frm.get(fr1.fp_beg), 10, 'copy: in') with self.assertRaisesRegex(KeyError, 'FmapRangeMap: .*key.*'): _ = self.frm.get(fr1.fp_beg) fr2 = FmapRange((20, 20, 20, 20), (21, 21, 21, 21)) self.frm.add(fr2, 20) self.assertEqual(self.frm.get(fr2.fp_beg), 20, 'copy: in') with self.assertRaisesRegex(KeyError, 'FmapRangeMap: .*key.*'): _ = frm.get(fr2.fp_beg)
def setUp(self): self.frm = FmapRangeMap() self.frm.add(FmapRange((0, 0, 0, 0), (2, 4, 8, 16)), 0) self.frm.add(FmapRange((0, 0, 8, 0), (2, 4, 16, 16)), 1) self.frm.add(FmapRange((0, 4, 0, 0), (2, 8, 8, 16)), 2) self.frm.add(FmapRange((0, 4, 8, 0), (2, 8, 16, 16)), 3) self.frm.add(FmapRange((2, 0, 0, 0), (4, 4, 8, 16)), 4) self.frm.add(FmapRange((2, 0, 8, 0), (4, 4, 16, 16)), 5) self.frm.add(FmapRange((2, 4, 0, 0), (4, 8, 8, 16)), 6) self.frm.add(FmapRange((2, 4, 8, 0), (4, 8, 16, 16)), 7)
def setUp(self): self.layers = {} self.layers['BASE'] = ConvLayer(8, 16, 28, 3) self.layers['POOL'] = PoolingLayer(16, 28, 2) self.layers['LR'] = LocalRegionLayer(16, 28, nreg=3, sreg=1) self.batch_size = 4 self.cost = Cost(mac_op=1, mem_hier=(200, 6, 2, 1), noc_hop=50, idl_unit=50) self.none_cstr = SchedulingConstraint() self.cstr = SchedulingConstraint(topofm=1, topbat=self.batch_size) self.resource = Resource( proc_region=NodeRegion(origin=PhyDim2(0, 0), dim=PhyDim2(4, 4), type=NodeRegion.PROC), dram_region=NodeRegion(origin=PhyDim2(0, 0), dim=PhyDim2(4, 1), type=NodeRegion.DRAM), src_data_region=NodeRegion(origin=PhyDim2(0, 0), dim=PhyDim2(4, 1), type=NodeRegion.DRAM), dst_data_region=NodeRegion(origin=PhyDim2(0, 0), dim=PhyDim2(4, 1), type=NodeRegion.DRAM), dim_array=PhyDim2(16, 16), size_gbuf=65536, size_regf=64, array_bus_width=float('inf'), dram_bandwidth=float('inf'), no_time_mux=False) self.options = Option(partition_hybrid=True, partition_batch=True, partition_ifmaps=True, ntops=10) self.ifmap_layouts = {} part = PartitionScheme(order=(pe.INPP, pe.BATP, pe.OUTP, pe.OFMP), pdims=((1, 2), (2, 1), (1, 2), (2, 1))) for wlkey in self.layers: input_layer = self.layers[wlkey].input_layer() self.ifmap_layouts[wlkey] = DataLayout( frngs=(FmapRange((0, 0, 0, 0), FmapPosition(b=self.batch_size, n=input_layer.nofm, h=input_layer.hofm, w=input_layer.wofm)), ), regions=(self.resource.src_data_region, ), parts=(part.projection(self.resource.src_data_region, appl2frng=True), )) self.sched_seq = (2, 0, 1)
def test_nhops_to_multidests_fwd(self): ''' Get nhops_to multiple destinations forwarding. ''' fr = FmapRange((0, ) * 4, (4, 4, 16, 16)) # First to (2, 2), then (2, 2) to (-1, -2), (-1, -2) to (-2, -3). nhops = 2 * 4 * 8 * 16 * (2 + 1 + 1 + 0) \ + 2 * 4 * 8 * 16 * (4 * 7) \ + 2 * 4 * 8 * 16 * (4 * 2) self.assertEqual( self.dl1.nhops_to(fr, PhyDim2(-1, -2), PhyDim2(-2, -3), PhyDim2(2, 2), forwarding=True), nhops) frng1 = FmapRange((0, 4, 0, 0), (4, 8, 16, 16)) dl = DataLayout(frngs=(self.frng1, frng1), regions=(self.region1, self.region2), parts=(self.part1, self.part2)) self.assertEqual( dl.nhops_to(fr, PhyDim2(-1, -2), PhyDim2(-2, -3), PhyDim2(2, 2), forwarding=True), nhops) nhops += 2 * 4 * 16 * 16 * ((3 + 4) + 2 * 7 + 2 * 2) fr = FmapRange((0, ) * 4, (16, ) * 4) self.assertEqual( dl.nhops_to(fr, PhyDim2(-1, -2), PhyDim2(-2, -3), PhyDim2(2, 2), forwarding=True), nhops) # (2, 2) to (3, 10) and (8, 4) nhops += 4 * 8 * 16 * 16 * (9 + 8) self.assertEqual( dl.nhops_to(fr, PhyDim2(-1, -2), PhyDim2(-2, -3), PhyDim2(2, 2), PhyDim2(3, 10), PhyDim2(8, 4), forwarding=True), nhops)