Ejemplo n.º 1
0
    def test_infer_lds(self):
        """Test for infer_ld[s]()."""
        n1, n2, n3, n4, n5 = self.ns[:5]
        sig = Signature("name", Dim("m"), Dim("n"), cData("A", "ldA * n"),
                        Ld("ldA", "m"), Info())
        ex = Experiment(calls=[sig(n1, n2, "X", n1 + n3, 0)])

        ex.infer_ld(0, 4)

        self.assertEqual(ex.call.ldA, n1)

        self.assertRaises(TypeError, ex.infer_ld, 0, 3)

        # now setting along and rep
        ex.nreps = n4
        ex.vary["X"]["along"] = 0
        ex.vary["X"]["with"].add("rep")

        ex.infer_lds()

        self.assertEqual(ex.call.ldA, n1 * n4)

        # range
        ex.sumrange = ["i", range(n5)]
        ex.vary["X"]["with"].add("i")

        ex.infer_lds()

        self.assertEqual(ex.call.ldA, n1 * n4 * n5)
Ejemplo n.º 2
0
 def setUp(self):
     """Set up a default experiment."""
     TestExperiment.setUp(self)
     i = self.i
     self.ex = Experiment(
         sampler=self.sampler,
         range=[i, range(100, 2001, 100)],
         nreps=10,
         calls=[
             Signature("dgemm",
                       Trans("transA"),
                       Trans("transB"),
                       Dim("m"),
                       Dim("n"),
                       Dim("k"),
                       dScalar(),
                       dData("A", "ldA * (k if transA == 'N' else m)"),
                       Ld("ldA", "m if transA == 'N' else k"),
                       dData("B", "ldB * (n if transB == 'N' else k)"),
                       Ld("ldB", "k if transB == 'N' else n"),
                       dScalar("beta"),
                       sData("C", "ldC * n"),
                       Ld("ldC", "m"),
                       flops="2 * m * n * k")("N", "N", i, i, i, 1, "A", i,
                                              "B", i, 1, "C", i)
         ])
Ejemplo n.º 3
0
    def test_apply_connections_from(self):
        """Test for apply_connections_from()."""
        n1, n2, n3, n4 = self.ns[:4]
        sig = Signature("name", Dim("m"), Dim("n"), iData("A", "m * n"),
                        iData("B", "n * n"))
        call = sig(n1, n2, "X", "Y")
        ex = Experiment(calls=[call.copy()])

        # no connections
        ex.apply_connections_from(0, 1)
        self.assertEqual(call, ex.calls[0])

        # one call
        ex.calls[0].B = "X"
        ex.apply_connections_from(0, 2)
        self.assertNotEqual(call, ex.calls[0])
        self.assertEqual(ex.calls[0][1], n2)

        # two calls
        ex.calls = [sig(n1, n2, "X", "Y"), sig(n3, n4, "Z", "X")]

        ex.apply_connections_from(1, 2)

        self.assertEqual(ex.calls[0].m, n4)
        self.assertEqual(ex.calls[0].n, n4)
Ejemplo n.º 4
0
    def test_infer_lwork(self):
        """Test for infer_lwork[s]()."""
        n1, n2, n3 = self.ns[:3]
        sig = Signature("name", Dim("m"), Dim("n"), dWork("W", "lWork"),
                        Lwork("lWork", "m * n"))
        ex = Experiment(calls=[sig(n1, n2, "V", n1 * n2 + n3)])

        ex.infer_lwork(0, 4)

        self.assertEqual(ex.call.lWork, n1 * n2)
Ejemplo n.º 5
0
    def test_get_operand(self):
        """Test for get_operand()."""
        n1, n2, n3, n4 = self.ns[:4]
        sig = Signature("name", Dim("m"), Dim("n"), sData("A", "ldA * n"),
                        Ld("ldA", "m"))
        ex = Experiment(calls=[sig(n1, n2, "X", n1 + n3)])

        op = ex.get_operand("X")
        self.assertEqual(op["type"], sData)
        self.assertEqual(op["size"], (n1 + n3) * n2)
        self.assertEqual(op["dims"], (n1, n2))
        self.assertEqual(op["lds"], (n1 + n3, n2))
Ejemplo n.º 6
0
 def setUp(self):
     """Set up a signature and experiment with call."""
     self.m = m = random.randint(1, 100)
     self.n = n = random.randint(1, 100)
     self.sig = sig = Signature("name", Dim("m"), Dim("n"),
                                sData("A", "ldA * n"), Ld("ldA", "m"),
                                dData("B", "ldB * m"), Ld("ldB", "m"),
                                cData("C", "ldC * n"), Ld("ldC", "n"))
     self.ex = ex = Experiment()
     ex.calls = [sig(m, n, "X", None, "Y", None, "Z", None)]
     ex.infer_lds()
     self.i = Symbol("i")
     self.j = Symbol("j")
Ejemplo n.º 7
0
    def test_load_signature_file(self):
        """Test for load_signature_file()."""
        sig = Signature("adsf", Dim("m"), sData("A", "m * m"))
        filename = self.filebase + ".pysig"

        write_signature(sig, filename)
        self.assertEqual(load_signature_file(filename), sig)