예제 #1
0
    def test_global_offsets_consts_array(self):
        k = KernelCode('''
            double Y[s][n];
            double F[s][n];
            double A[s][s];
            double y[n];

            for (int j = 0; j < n; ++j)
            {
              Y[0][j] += A[0][0] * F[0][j];
              Y[0][j] += A[0][1] * F[1][j];
              Y[1][j] += A[1][0] * F[0][j];
              Y[1][j] += A[1][1] * F[1][j];
              Y[0][j] = Y[0][j] + y[j];
              Y[1][j] = Y[1][j] + y[j];
            }''',
                       machine=None)
        k.set_constant('n', 100000000)
        k.set_constant('s', 2)

        offsets_warmup = k.compile_global_offsets(iteration=range(0, 10000),
                                                  spacing=0)
        for l, s in offsets_warmup:
            self.assertEqual(len(l), 5, msg="Number of load offsets")
            self.assertEqual(len(s), 2, msg="Number of store offsets")
예제 #2
0
 def test_global_offsets_2d(self):
     k = KernelCode(self.twod_code, machine=None)
     k.set_constant('N', 10)
     k.set_constant('M', 20)
     sizes = k.array_sizes(in_bytes=True, subs_consts=True)
     offsets = k.compile_global_offsets(iteration=0, spacing=0)
     read_offsets, write_offsets = list(offsets)[0]
     # read access to a[j][i-1], a[j][i+1], a[j-1][i], a[j+1][i]
     self.assertCountEqual([(1 * 10 + 0) * 8, (1 * 10 + 2) * 8,
                            (0 * 10 + 1) * 8, (2 * 10 + 1) * 8],
                           read_offsets)
     # write access to b[i][j]
     self.assertCountEqual([sizes['a'] + (1 * 10 + 1) * 8], write_offsets)
예제 #3
0
 def test_global_offsets_2d(self):
     k = KernelCode(self.twod_code, machine=None)
     k.set_constant('N', 10)
     k.set_constant('M', 20)
     sizes = k.array_sizes(in_bytes=True, subs_consts=True)
     offsets = k.compile_global_offsets(iteration=0, spacing=0)
     read_offsets, write_offsets = list(offsets)[0]
     # read access to a[j][i-1], a[j][i+1], a[j-1][i], a[j+1][i]
     self.assertCountEqual(
         [(1 * 10 + 0) * 8, (1 * 10 + 2) * 8, (0 * 10 + 1) * 8, (2 * 10 + 1) * 8],
         read_offsets)
     # write access to b[i][j]
     self.assertCountEqual(
         [sizes['a'] + (1 * 10 + 1) * 8],
         write_offsets)
예제 #4
0
    def test_global_offsets_variable_small_array(self):
        k = KernelCode('''
            double Y[s][n];
            double y[n];

            for (int l = 0; l < s; l++)
              for (int j = 0; j < n; j++)
                Y[l][j] = Y[l][j] + y[j];''', machine=None)
        k.set_constant('n', 100000000)
        k.set_constant('s', 2)

        offsets_warmup = k.compile_global_offsets(iteration=range(0, 10000), spacing=0)
        for l, s in offsets_warmup:
            self.assertEqual(len(l), 2, msg="Number of load offsets")
            self.assertEqual(len(s), 1, msg="Number of store offsets")
예제 #5
0
    def test_global_offsets_consts_array(self):
        k = KernelCode('''
            double Y[s][n];
            double F[s][n];
            double A[s][s];
            double y[n];

            for (int j = 0; j < n; ++j)
            {
              Y[0][j] += A[0][0] * F[0][j];
              Y[0][j] += A[0][1] * F[1][j];
              Y[1][j] += A[1][0] * F[0][j];
              Y[1][j] += A[1][1] * F[1][j];
              Y[0][j] = Y[0][j] + y[j];
              Y[1][j] = Y[1][j] + y[j];
            }''', machine=None)
        k.set_constant('n', 100000000)
        k.set_constant('s', 2)

        offsets_warmup = k.compile_global_offsets(iteration=range(0,10000), spacing=0)
        for l,s in offsets_warmup:
            self.assertEqual(len(l), 5, msg="Number of load offsets")
            self.assertEqual(len(s), 2, msg="Number of store offsets")