def test_order_4_blocks_1x1_with_missing_blocks(self): # given collector = CollectorI(order=2) collector.injectSubmatrix(M1(1), 0, 0) collector.injectSubmatrix(M1(2), 0, 1) # block (1,0) never injected # when collector.injectSubmatrix(M1(4), 1, 1) # then assert_that(collector.get_result(), is_(None))
def test_order_4_blocks_1x1_with_missing_blocks(self): # given collector = CollectorI(order=2) collector.inject(0, M1(1)) collector.inject(1, M1(2)) # block (1,0) never injected # when collector.inject(3, M1(4)) # then assert_that(collector.get_result(), is_(None))
def test_order_4_blocks_1x1(self): # given collector = CollectorI(order=2) collector.inject(0, M1(1)) collector.inject(1, M1(2)) collector.inject(2, M1(3)) # when collector.inject(3, M1(4)) # then assert_that(collector.get_result(), is_(M2(1, 2, 3, 4)))
def test_order_4_blocks_1x1(self): # given collector = CollectorI(order=2) collector.injectSubmatrix(M1(1), 0, 0) collector.injectSubmatrix(M1(2), 0, 1) collector.injectSubmatrix(M1(3), 1, 0) # when collector.injectSubmatrix(M1(4), 1, 1) # then assert_that(collector.get_result(), is_(M2(1, 2, 3, 4)))
def test_processors_1x1_block(self): # given P0 = ProcessorI() collector = Spy() A = M1(2) B = M1(5) C = M1(10) # when P0.init(0, 1, None, None, collector) P0.injectA(A, 0) P0.injectB(B, 0) # then assert_that(collector.inject, called().with_args(0, C, ANY_ARG))
def test_order_1_block_1x1(self): # given collector = CollectorI(order=1) # when M = M1(1) collector.injectSubmatrix(M, 0, 0) # then assert_that(collector.get_result(), is_(M))
def test_processors_rings(self): # given P0 = ProcessorI() P1 = Spy() P2 = Spy() collector = Stub() A0 = M1(1) B0 = M1(5) # when P0.init(1, 1, P2, P1, 2, collector) P0.injectFirst(A0, 0) P0.injectSecond(B0, 0) # then assert_that(P1.injectFirst, called(). async (1).with_args(A0, 1, ANY_ARG)) assert_that(P2.injectSecond, called(). async (1).with_args(B0, 1, ANY_ARG))
def test_linked_processors(self): P0 = self.broker.add_servant(ProcessorI(), Cannon.ProcessorPrx) P1_servant = Mimic(Spy, Cannon.Processor) P1 = self.broker.add_servant(P1_servant, Cannon.ProcessorPrx) P2_servant = Mimic(Spy, Cannon.Processor) P2 = self.broker.add_servant(P2_servant, Cannon.ProcessorPrx) collector_servant = Mimic(Spy, Cannon.Collector) collector = self.broker.add_servant(collector_servant, Cannon.CollectorPrx) A00 = M1(1) B00 = M1(5) P0.init(1, 1, P2, P1, 2, collector) P0.injectFirst(A00, 0) P0.injectSecond(B00, 0) assert_that(P1_servant.injectFirst, called().asyncio(1).with_args(A00, 1, anything())) assert_that(P2_servant.injectSecond, called().asyncio(1).with_args(B00, 1, anything()))
def test_linked_processors(self): P0 = self.broker.add_servant(ProcessorI(), Cannon.ProcessorPrx) P1_servant = Mimic(Spy, Cannon.Processor) P1 = self.broker.add_servant(P1_servant, Cannon.ProcessorPrx) P2_servant = Mimic(Spy, Cannon.Processor) P2 = self.broker.add_servant(P2_servant, Cannon.ProcessorPrx) collector_servant = Mimic(Spy, Cannon.Collector) collector = self.broker.add_servant(collector_servant, Cannon.CollectorPrx) A0 = M1(1) B0 = M1(5) P0.init(3, 2, P2, P1, collector) P0.injectA(A0, 0) P0.injectB(B0, 0) assert_that(P1_servant.injectA, called(). async (1).with_args(A0, 1, anything())) assert_that(P2_servant.injectB, called(). async (1).with_args(B0, 1, anything()))
def test_load_2x2_operands_in_2x2_processors(self): nprocs = 4 # given A = M2(1, 2, 3, 4) B = M2(5, 6, 7, 8) procs = [Spy(Cannon.Processor) for i in range(nprocs)] frontend = FrontendI(procs) # when frontend.load_processors(A, B) # then A_blocks = [M1(1), M1(2), M1(4), M1(3)] B_blocks = [M1(5), M1(8), M1(7), M1(6)] for i in range(nprocs): assert_that(procs[i].injectA, called().with_args(A_blocks[i], 0)) assert_that(procs[i].injectB, called().with_args(B_blocks[i], 0))
def test_load_2x2_operands_in_2x2_processors(self): nprocs = 4 # given A = M2(1, 2, 3, 4) B = M2(5, 6, 7, 8) procs = [Spy(Cannon.Processor) for i in range(nprocs)] loader = OperationsI(procs) # when loader.load_processors(A, B) # then A_blocks = [M1(1), M1(2), M1(4), M1(3)] B_blocks = [M1(5), M1(8), M1(7), M1(6)] for i in range(nprocs): assert_that(procs[i].injectFirst, called().with_args(A_blocks[i], 0)) assert_that(procs[i].injectSecond, called().with_args(B_blocks[i], 0))
def test_2x2_processors_2x2_operands(self): ''' initial shift: 1 2 1 2 5 6 5 8 3 4 < 4 3 7 8 7 6 ^ processors and collectors are distributed objects ''' P = [ self.broker.add_servant(ProcessorI(), Cannon.ProcessorPrx) for i in range(4) ] collector_servant = Mimic(Spy, Cannon.Collector) collector = self.broker.add_servant(collector_servant, Cannon.CollectorPrx) # by-hand shifted submatrices A0 = M1(1) A1 = M1(2) A2 = M1(4) A3 = M1(3) B0 = M1(5) B1 = M1(8) B2 = M1(7) B3 = M1(6) # by-hand processor initialization P[0].init(0, 2, P[2], P[1], collector) P[1].init(1, 2, P[3], P[0], collector) P[2].init(2, 2, P[0], P[3], collector) P[3].init(3, 2, P[1], P[2], collector) # by-hand processor loading P[0].injectA(A0, 0) P[0].injectB(B0, 0) P[1].injectA(A1, 0) P[1].injectB(B1, 0) P[2].injectA(A2, 0) P[2].injectB(B2, 0) P[3].injectA(A3, 0) P[3].injectB(B3, 0) wait_that(collector_servant.inject, called().times(4)) # expected result blocks C0 = M1(19) C1 = M1(22) C2 = M1(43) C3 = M1(50) assert_that(collector_servant.inject, called().with_args(0, C0, anything())) assert_that(collector_servant.inject, called().with_args(1, C1, anything())) assert_that(collector_servant.inject, called().with_args(2, C2, anything())) assert_that(collector_servant.inject, called().with_args(3, C3, anything()))
def test_2x2_processors_2x2_operands(self): ''' initial shift: 1 2 1 2 5 6 5 8 3 4 < 4 3 7 8 7 6 ^ processors and collector are distributed objects ''' P = [ self.broker.add_servant(ProcessorI(), Cannon.ProcessorPrx) for i in range(4) ] collector_servant = Mimic(Spy, Cannon.Collector) collector = self.broker.add_servant(collector_servant, Cannon.CollectorPrx) # by-hand shifted submatrices A00 = M1(1) A01 = M1(2) A10 = M1(4) A11 = M1(3) B00 = M1(5) B01 = M1(8) B10 = M1(7) B11 = M1(6) # by-hand processor initialization P[0].init(0, 0, P[2], P[1], 2, collector) P[1].init(0, 1, P[3], P[0], 2, collector) P[2].init(1, 0, P[0], P[3], 2, collector) P[3].init(1, 1, P[1], P[2], 2, collector) # by-hand processor loading P[0].injectFirst(A00, 0) P[0].injectSecond(B00, 0) P[1].injectFirst(A01, 0) P[1].injectSecond(B01, 0) P[2].injectFirst(A10, 0) P[2].injectSecond(B10, 0) P[3].injectFirst(A11, 0) P[3].injectSecond(B11, 0) wait_that(collector_servant.injectSubmatrix, called().times(4)) # expected result blocks C00 = M1(19) C01 = M1(22) C10 = M1(43) C11 = M1(50) assert_that(collector_servant.injectSubmatrix, called().with_args(C00, 0, 0, anything())) assert_that(collector_servant.injectSubmatrix, called().with_args(C01, 0, 1, anything())) assert_that(collector_servant.injectSubmatrix, called().with_args(C10, 1, 0, anything())) assert_that(collector_servant.injectSubmatrix, called().with_args(C11, 1, 1, anything()))
def test_2x2_processors_1x1_blocks_with_collector_injection(self): ''' A = (1, 2, 3, 4) B = (5, 6, 7, 8) ''' nprocs = 4 # given P = [ProcessorI() for i in range(nprocs)] collector = Spy(Cannon.Collector) # by-hand shift and split A0 = M1(1) A1 = M1(2) A2 = M1(4) A3 = M1(3) B0 = M1(5) B1 = M1(8) B2 = M1(7) B3 = M1(6) # when P[0].init(0, 0, P[2], P[1], 2, collector) P[1].init(0, 1, P[3], P[0], 2, collector) P[2].init(1, 0, P[0], P[3], 2, collector) P[3].init(1, 1, P[1], P[2], 2, collector) P[0].injectFirst(A0, 0) P[0].injectSecond(B0, 0) P[1].injectFirst(A1, 0) P[1].injectSecond(B1, 0) P[2].injectFirst(A2, 0) P[2].injectSecond(B2, 0) P[3].injectFirst(A3, 0) P[3].injectSecond(B3, 0) # then C0 = M1(19) C1 = M1(22) C2 = M1(43) C3 = M1(50) self.assert_collector_called(collector, C0, 0, 0, anything()) self.assert_collector_called(collector, C1, 0, 1, anything()) self.assert_collector_called(collector, C2, 1, 0, anything()) self.assert_collector_called(collector, C3, 1, 1, anything())
def test_3x3_processors_1x1_blocks_with_collector_injection(self): ''' A = (1, 2, 3, 4, 5, 6, 7, 8, 9) B = (10, 11, 12, 13, 14, 15, 16, 17, 18) ''' nprocs = 9 # given P = [ProcessorI() for i in range(nprocs)] collector = Spy(Cannon.Collector) # by-hand shift and split A0 = M1(1) A1 = M1(2) A2 = M1(3) A3 = M1(5) A4 = M1(6) A5 = M1(4) A6 = M1(9) A7 = M1(7) A8 = M1(8) B0 = M1(10) B1 = M1(14) B2 = M1(18) B3 = M1(13) B4 = M1(17) B5 = M1(12) B6 = M1(16) B7 = M1(11) B8 = M1(15) # when P[0].init(0, 0, P[6], P[2], 3, collector) P[1].init(0, 1, P[7], P[0], 3, collector) P[2].init(0, 2, P[8], P[1], 3, collector) P[3].init(1, 0, P[0], P[5], 3, collector) P[4].init(1, 1, P[1], P[3], 3, collector) P[5].init(1, 2, P[2], P[4], 3, collector) P[6].init(2, 0, P[3], P[8], 3, collector) P[7].init(2, 1, P[4], P[6], 3, collector) P[8].init(2, 2, P[5], P[7], 3, collector) P[0].injectFirst(A0, 0) P[0].injectSecond(B0, 0) P[1].injectFirst(A1, 0) P[1].injectSecond(B1, 0) P[2].injectFirst(A2, 0) P[2].injectSecond(B2, 0) P[3].injectFirst(A3, 0) P[3].injectSecond(B3, 0) P[4].injectFirst(A4, 0) P[4].injectSecond(B4, 0) P[5].injectFirst(A5, 0) P[5].injectSecond(B5, 0) P[6].injectFirst(A6, 0) P[6].injectSecond(B6, 0) P[7].injectFirst(A7, 0) P[7].injectSecond(B7, 0) P[8].injectFirst(A8, 0) P[8].injectSecond(B8, 0) # then C0 = M1(84) C1 = M1(90) C2 = M1(96) C3 = M1(201) C4 = M1(216) C5 = M1(231) C6 = M1(318) C7 = M1(342) C8 = M1(366) self.assert_collector_called(collector, C0, 0, 0, anything()) self.assert_collector_called(collector, C1, 0, 1, anything()) self.assert_collector_called(collector, C2, 0, 2, anything()) self.assert_collector_called(collector, C3, 1, 0, anything()) self.assert_collector_called(collector, C4, 1, 1, anything()) self.assert_collector_called(collector, C5, 1, 2, anything()) self.assert_collector_called(collector, C6, 2, 0, anything()) self.assert_collector_called(collector, C7, 2, 1, anything()) self.assert_collector_called(collector, C8, 2, 2, anything())