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)
def test_invalid_sched_seq(self): ''' Invalid sched_seq. ''' with self.assertRaisesRegexp(TypeError, 'SchedulingCondition: .*sched_seq.*'): _ = SchedulingCondition(resource=self.resource, constraint=self.none_cstr, ifmap_layout=self.ifmap_layout, sched_seq=list(self.sched_seq)) with self.assertRaisesRegexp(ValueError, 'SchedulingCondition: .*sched_seq.*'): _ = SchedulingCondition(resource=self.resource, constraint=self.none_cstr, ifmap_layout=self.ifmap_layout, sched_seq=self.sched_seq[:-1])
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))
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)
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))
def test_invalid_ifmap_layout(self): ''' Invalid ifmap_layout. ''' with self.assertRaisesRegexp(TypeError, 'SchedulingCondition: .*ifmap_layout.*'): _ = SchedulingCondition(resource=self.resource, constraint=self.none_cstr, ifmap_layout=None, sched_seq=self.sched_seq)
def test_invalid_resource(self): ''' Invalid resource. ''' with self.assertRaisesRegex(TypeError, 'SchedulingCondition: .*resource.*'): _ = SchedulingCondition(resource=None, constraint=self.none_cstr, ifmap_layout=self.ifmap_layout, sched_seq=self.sched_seq)
def test_valid_args(self): ''' Valid arguments. ''' condition = SchedulingCondition(resource=self.resource, constraint=self.none_cstr, ifmap_layout=self.ifmap_layout, sched_seq=self.sched_seq) self.assertEqual(condition.resource, self.resource) self.assertEqual(condition.constraint, self.none_cstr) self.assertEqual(condition.ifmap_layout, self.ifmap_layout) self.assertTupleEqual(condition.sched_seq, self.sched_seq)
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)
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)
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)
def test_invalid_ifmap_layout(self): ''' Invalid resource. ''' with self.assertRaisesRegexp(TypeError, 'SchedulingCondition: .*ifmap_layout.*'): _ = SchedulingCondition(resource=self.resource, ifmap_layout=None)
def test_valid_args(self): ''' Valid arguments. ''' condition = SchedulingCondition(resource=self.resource, ifmap_layout=self.ifmap_layout) self.assertEqual(condition.resource, self.resource) self.assertEqual(condition.ifmap_layout, self.ifmap_layout)