예제 #1
0
    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, unit_static=50)

        self.resource = Resource(
            proc_region=NodeRegion(origin=PhyDim2(0, 0), dim=PhyDim2(4, 4),
                                   type=NodeRegion.PROC),
            data_regions=(NodeRegion(origin=PhyDim2(0, 0), dim=PhyDim2(4, 1),
                                     type=NodeRegion.DATA),),
            dim_array=PhyDim2(16, 16), size_gbuf=65536, size_regf=64)

        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:
            self.ifmap_layouts[wlkey] = partition.get_ofmap_layout(
                self.layers[wlkey].input_layer(), self.batch_size, part,
                self.resource.src_data_region())
    def setUp(self):
        self.network = Network('test_net')
        self.network.set_input(InputLayer(3, 224))
        self.network.add('c1', ConvLayer(3, 64, 224, 3))
        self.network.add('p1', PoolingLayer(64, 7, 32), prevs='c1')
        self.network.add('p2', PoolingLayer(64, 7, 32), prevs='c1')
        self.network.add('f1', FCLayer(64, 1000, 7), prevs=['p1', 'p2'])

        self.batch_size = 4

        self.input_layout = partition.get_ofmap_layout(
            self.network.input_layer(), self.batch_size,
            PartitionScheme(order=range(pe.NUM), pdims=[(1, 1)] * pe.NUM),
            NodeRegion(origin=PhyDim2(0, 0), dim=PhyDim2(2, 1),
                       type=NodeRegion.DATA))

        self.c1res = SchedulingResult(
            dict_loop=OrderedDict([('cost', 1.), ('time', 2.), ('ops', 4.),
                                   ('access', [[7, 8, 9]] * me.NUM),
                                  ]),
            dict_part=OrderedDict([('cost', 0.5), ('total_nhops', [4, 5, 6]),
                                   ('num_nodes', 4),
                                  ]),
            ofmap_layout=partition.get_ofmap_layout(
                self.network['c1'], self.batch_size,
                PartitionScheme(order=range(pe.NUM), pdims=[(1, 1)] * pe.NUM),
                NodeRegion(origin=PhyDim2(0, 0), dim=PhyDim2(1, 2),
                           type=NodeRegion.DATA)))

        self.pres = SchedulingResult(
            dict_loop=OrderedDict([('cost', 0.1), ('time', 0.05), ('ops', 0.1),
                                   ('access', [[.7, .8, .9]] * me.NUM),
                                  ]),
            dict_part=OrderedDict([('cost', 0.5), ('total_nhops', [.4, .5, .6]),
                                   ('num_nodes', 2),
                                  ]),
            ofmap_layout=partition.get_ofmap_layout(
                self.network['p1'], self.batch_size,
                PartitionScheme(order=range(pe.NUM), pdims=[(1, 1)] * pe.NUM),
                NodeRegion(origin=PhyDim2(0, 0), dim=PhyDim2(1, 2),
                           type=NodeRegion.DATA)))

        self.dtfl = NNDataflowScheme(self.network, self.input_layout)
        self.dtfl['c1'] = self.c1res
        self.dtfl['p1'] = self.pres
        self.dtfl['p2'] = self.pres
예제 #3
0
    def test_origin(self):
        ''' Same dim but different origins. '''
        layer = self.layers['BASE']

        part = PartitionScheme(order=(pe.BATP, pe.INPP, pe.OUTP, pe.OFMP),
                               pdims=((2, 3), (1, 5), (4, 4), (1, 1)))

        omr1 = NodeRegion(origin=PhyDim2(0, 0),
                          dim=PhyDim2(16, 16),
                          type=NodeRegion.DATA)
        dl1 = partition.get_ofmap_layout(layer, self.batch_size, part, omr1)

        omr2 = NodeRegion(origin=PhyDim2(0, 0),
                          dim=PhyDim2(16, 16),
                          type=NodeRegion.DATA)
        dl2 = partition.get_ofmap_layout(layer, self.batch_size, part, omr2)

        self._general_assert(dl1, omr1, layer)
        self._general_assert(dl2, omr2, layer)

        self.assertSetEqual(set(dl1.frmap.items()), set(dl2.frmap.items()))
예제 #4
0
    def test_zero_region(self):
        ''' Zero dim region. '''
        layer = self.layers['BASE']

        part = PartitionScheme(order=(pe.BATP, pe.INPP, pe.OUTP, pe.OFMP),
                               pdims=((2, 3), (1, 5), (4, 4), (1, 1)))

        omr = NodeRegion(origin=PhyDim2(0, 0),
                         dim=PhyDim2(0, 0),
                         type=NodeRegion.DATA)

        with self.assertRaisesRegexp(ValueError, 'partition .*empty.*'):
            _ = partition.get_ofmap_layout(layer, self.batch_size, part, omr)
예제 #5
0
    def test_shrink_extend(self):
        ''' Both shrink and extend. '''
        layer = self.layers['BASE']

        part = PartitionScheme(order=(pe.BATP, pe.INPP, pe.OUTP, pe.OFMP),
                               pdims=((2, 3), (1, 5), (4, 4), (1, 1)))

        omr = NodeRegion(origin=PhyDim2(0, 0),
                         dim=PhyDim2(16, 16),
                         type=NodeRegion.DATA)
        dl = partition.get_ofmap_layout(layer, self.batch_size, part, omr)

        self._general_assert(dl, omr, layer)

        self.assertLessEqual(len(list(dl.frmap.items())), 16 * 16)
예제 #6
0
    def test_extend_with_inpp(self):
        ''' Extend with INPP. '''
        layer = self.layers['BASE']

        part = PartitionScheme(order=(pe.INPP, pe.BATP, pe.OUTP, pe.OFMP),
                               pdims=((2, 3), (1, 5), (1, 1), (4, 4)))

        omr = NodeRegion(origin=PhyDim2(0, 0),
                         dim=PhyDim2(4, 30),
                         type=NodeRegion.DATA)
        dl = partition.get_ofmap_layout(layer, self.batch_size, part, omr)

        self._general_assert(dl, omr, layer)

        self.assertEqual(len(list(dl.frmap.items())), 6 * 5 * (2 * 2))
예제 #7
0
    def test_shrink_nondiv(self):
        ''' Shrink non-dividable. '''
        layer = self.layers['BASE']

        part = PartitionScheme(order=(pe.BATP, pe.INPP, pe.OUTP, pe.OFMP),
                               pdims=((2, 3), (1, 5), (4, 4), (1, 1)))

        omr = NodeRegion(origin=PhyDim2(0, 0),
                         dim=PhyDim2(3, 54),
                         type=NodeRegion.DATA)
        dl = partition.get_ofmap_layout(layer, self.batch_size, part, omr)

        self._general_assert(dl, omr, layer)

        # For height, 3 // 2 = 1.
        # For width, 54 // 5 = 10, 10 // 3 = 3.
        self.assertEqual(len(list(dl.frmap.items())), 6 * 5 * (1 * 3))
        self.assertLess(len(list(dl.frmap.items())), 3 * 54)
예제 #8
0
    def test_extend_nondiv(self):
        ''' Extend non-dividable. '''
        layer = self.layers['BASE']

        part = PartitionScheme(order=(pe.INPP, pe.BATP, pe.OUTP, pe.OFMP),
                               pdims=((2, 3), (1, 5), (1, 1), (1, 1)))

        omr = NodeRegion(origin=PhyDim2(0, 0),
                         dim=PhyDim2(5, 40),
                         type=NodeRegion.DATA)
        dl = partition.get_ofmap_layout(layer, self.batch_size, part, omr)

        self._general_assert(dl, omr, layer)

        # For height, 5 // 2 = 2.
        # For width, 40 // (3 * 5) == 2.
        self.assertEqual(len(list(dl.frmap.items())), 6 * 5 * (2 * 2))
        self.assertLess(len(list(dl.frmap.items())), 5 * 40)