Ejemplo n.º 1
0
    def test_schedule_search_ilayout(self):
        ''' Invalid ifmap_layout. '''
        layer = self.layers['BASE']

        schd = Scheduling(layer, self.batch_size, self.cost,
                          MapStrategyEyeriss)

        # Shift ifmap out of memory region.
        condition = SchedulingCondition(
            resource=self.resource,
            constraint=self.none_cstr,
            ifmap_layout=self.ifmap_layouts['BASE']._replace(regions=tuple(
                r._replace(origin=PhyDim2(-10, -10))
                for r in self.ifmap_layouts['BASE'].regions)),
            sched_seq=self.sched_seq)

        with self.assertRaisesRegexp(ValueError, 'Scheduling: .*ifmap.*'):
            _ = schd.schedule_search(condition, self.options)

        # Not match layer.
        condition = SchedulingCondition(
            resource=self.resource,
            constraint=self.none_cstr,
            ifmap_layout=self.ifmap_layouts['POOL'],
            sched_seq=self.sched_seq)

        with self.assertRaisesRegexp(ValueError, 'Scheduling: .*ifmap.*'):
            _ = schd.schedule_search(condition, self.options)
Ejemplo n.º 2
0
    def test_schedule_search(self):
        ''' Schedule search. '''
        for wlkey in self.layers:
            layer = self.layers[wlkey]
            ifmap_layout = self.ifmap_layouts[wlkey]

            schd = Scheduling(layer, self.batch_size, self.cost,
                              MapStrategyEyeriss)

            condition = SchedulingCondition(resource=self.resource,
                                            constraint=self.cstr,
                                            ifmap_layout=ifmap_layout,
                                            sched_seq=self.sched_seq)

            res = schd.schedule_search(condition, self.options)

            # Top N.
            self.assertLessEqual(len(res), self.options.ntops)
            self.assertTrue(all(isinstance(r, SchedulingResult) for r in res))
            for idx in range(len(res) - 1):
                self.assertLessEqual(res[idx].total_cost,
                                     res[idx + 1].total_cost)

            # Combination of loop blocking and partitioning.
            for r in res:
                self.assertAlmostEqual(r.total_cost,
                                       r.scheme['cost_op']
                                       + r.scheme['cost_access']
                                       + r.scheme['cost_noc']
                                       + r.scheme['cost_static'])
                self.assertEqual(r.total_ops, layer.total_ops(self.batch_size))
                self.assertSequenceEqual(r.scheme['total_nhops'],
                                         [nh * f for nh, f
                                          in zip(r.scheme['unit_nhops'],
                                                 r.scheme['fetch'][0])])
                self.assertEqual(r.num_nodes,
                                 self.resource.proc_region.dim.size())

            # Constraint.
            for r in res:
                self.assertEqual(r.scheme['to'][0], 1)

            # Ofmap layout.
            for r in res:
                self.assertEqual(r.ofmap_layout.complete_fmap_range().size(),
                                 layer.total_ofmap_size(self.batch_size))

            # Sequence number.
            for r in res:
                self.assertTupleEqual(r.sched_seq, condition.sched_seq)
Ejemplo n.º 3
0
    def test_schedule_search_nolbs(self):
        ''' Schedule search with no lbs. '''
        layer = self.layers['BASE']
        ifmap_layout = self.ifmap_layouts['BASE']

        schd = Scheduling(layer, self.batch_size, self.cost,
                          MapStrategyEyeriss)

        condition = SchedulingCondition(
            resource=self.resource._replace(size_regf=0),
            constraint=self.none_cstr,
            ifmap_layout=ifmap_layout,
            sched_seq=self.sched_seq)

        res = schd.schedule_search(condition, self.options)

        self.assertFalse(res)
Ejemplo n.º 4
0
    def test_pernode_sched_cache(self):
        ''' Per-node scheduling cache. '''
        # pylint: disable=no-member
        Scheduling.schedule_search_per_node.cache_clear()

        layer = self.layers['BASE']
        ifmap_layout = self.ifmap_layouts['BASE']

        schd = Scheduling(layer, self.batch_size, self.cost,
                          MapStrategyEyeriss)

        self.assertEqual(schd.schedule_search_per_node.cache_info().currsize,
                         0)
        self.assertTupleEqual(schd.cache_stats(), (0, 0))

        condition = SchedulingCondition(resource=self.resource,
                                        constraint=self.cstr,
                                        ifmap_layout=ifmap_layout,
                                        sched_seq=self.sched_seq)

        Scheduling.schedule_search.cache_clear()
        _ = schd.schedule_search(condition, self.options)

        h, m = schd.cache_stats()
        self.assertEqual(schd.schedule_search_per_node.cache_info().currsize,
                         m)
        self.assertEqual(h, 0)
        n = m

        Scheduling.schedule_search.cache_clear()
        _ = schd.schedule_search(condition, self.options)

        self.assertEqual(schd.schedule_search_per_node.cache_info().currsize,
                         n)
        self.assertTupleEqual(schd.cache_stats(), (n, n))
Ejemplo n.º 5
0
    def test_pernode_sched_cache(self):
        ''' Per-node scheduling cache. '''
        layer = self.layers['BASE']
        ifmap_layout = self.ifmap_layouts['BASE']

        schd = Scheduling(layer, self.batch_size, self.cost,
                          MapStrategyEyeriss)

        self.assertEqual(len(schd.pernode_sched_cache), 0)
        self.assertTupleEqual(schd.cache_stats(), (0, 0))

        condition = SchedulingCondition(resource=self.resource,
                                        ifmap_layout=ifmap_layout)

        _ = schd.schedule_search(condition, self.options)

        h, m = schd.cache_stats()
        self.assertEqual(len(schd.pernode_sched_cache), m)
        self.assertEqual(h, 0)
        n = m

        _ = schd.schedule_search(condition, self.options)

        self.assertEqual(len(schd.pernode_sched_cache), n)
        self.assertTupleEqual(schd.cache_stats(), (n, n))
Ejemplo n.º 6
0
    def test_valid_args(self):
        ''' Valid arguments for constructor. '''
        schd = Scheduling(self.layers['BASE'], self.batch_size, self.cost,
                          MapStrategyEyeriss)

        self.assertEqual(schd.layer, self.layers['BASE'])
        self.assertEqual(schd.batch_size, self.batch_size)
        self.assertEqual(schd.cost, self.cost)
        self.assertEqual(schd.map_strategy_class, MapStrategyEyeriss)
Ejemplo n.º 7
0
    def test_invalid_map_strategy(self):
        ''' Invalid cost argument. '''
        class _DummyClass(object):  # pylint: disable=too-few-public-methods
            pass

        with self.assertRaisesRegexp(TypeError,
                                     'Scheduling: .*map_strategy_class.*'):
            _ = Scheduling(self.layers['BASE'], self.batch_size, self.cost,
                           _DummyClass)
Ejemplo n.º 8
0
    def test_pernode_sched_cache_key(self):
        ''' Per-node scheduling cache key must be hash-able. '''
        layer = self.layers['BASE']
        ifmap_layout = self.ifmap_layouts['BASE']

        schd = Scheduling(layer, self.batch_size, self.cost,
                          MapStrategyEyeriss)

        condition = SchedulingCondition(resource=self.resource,
                                        ifmap_layout=ifmap_layout)

        _ = schd.schedule_search(condition, self.options)

        h, m = schd.cache_stats()
        self.assertEqual(h, 0)

        # Make another instance.
        rsrc = Resource(**self.resource._asdict())
        opts = Option(**self.options._asdict())
        self.assertNotEqual(id(rsrc), id(self.resource))
        self.assertNotEqual(id(opts), id(self.options))

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

        _ = schd.schedule_search_per_node(part, rsrc, opts)

        h2, m2 = schd.cache_stats()
        self.assertEqual(h2, h + 1)
        self.assertEqual(m2, m)
Ejemplo n.º 9
0
    def test_schedule_search_ilayout(self):
        ''' Invalid ifmap_layout. '''
        layer = self.layers['BASE']
        ifmap_layout = self.ifmap_layouts['BASE']

        schd = Scheduling(layer, self.batch_size, self.cost,
                          MapStrategyEyeriss)

        # Shift ifmap out of memory region.
        condition = SchedulingCondition(
            resource=self.resource,
            ifmap_layout=ifmap_layout.view(PhyDim2(1, 1)))

        with self.assertRaisesRegexp(ValueError, 'Scheduling: .*ifmap.*'):
            _ = schd.schedule_search(condition, self.options)

        # Not match layer.
        condition = SchedulingCondition(
            resource=self.resource,
            ifmap_layout=self.ifmap_layouts['POOL'])

        with self.assertRaisesRegexp(ValueError, 'Scheduling: .*ifmap.*'):
            _ = schd.schedule_search(condition, self.options)
Ejemplo n.º 10
0
 def test_invalid_cost(self):
     ''' Invalid cost argument. '''
     with self.assertRaisesRegexp(TypeError, 'Scheduling: .*cost.*'):
         _ = Scheduling(self.layers['BASE'], self.batch_size,
                        tuple(self.cost), MapStrategyEyeriss)
Ejemplo n.º 11
0
 def test_invalid_layer(self):
     ''' Invalid layer argument. '''
     with self.assertRaisesRegexp(TypeError, 'Scheduling: .*layer.*'):
         _ = Scheduling((64, 128, 28, 3), self.batch_size, self.cost,
                        MapStrategyEyeriss)