コード例 #1
0
    def test_preprocess_shim(self):
        self.assertTrue(
            preprocess.preprocess("""
__kernel void A(__global FLOAT_T* a) { int b; }"""))

        with self.assertRaises(preprocess.BadCodeException):
            preprocess.preprocess("""
__kernel void A(__global FLOAT_T* a) { int b; }""",
                                  use_shim=False)
コード例 #2
0
def get_sample(m, seed_text, seed):
    """
    Generate a new sample.

    Arguments:
        m (Model): CLgen model.
        seed_text (str): Seed text.
        seed (int): Seed value.

    Returns:
        (int, str): 0 if good sample, 1 if bad, 2 if ugly.
    """
    try:
        buf = StringIO()
        m.sample(seed_text=seed_text,
                 output=buf,
                 seed=seed,
                 max_length=5000,
                 quiet=True)
        out = buf.getvalue()
        result = preprocess.preprocess(out)
        return 0, result
    except preprocess.BadCodeException:
        return 1, None
    except preprocess.UglyCodeException:
        return 2, None
コード例 #3
0
    def test_ugly_preprocessed(self):
        # empty kernel protoype is rejected
        with self.assertRaises(preprocess.NoCodeException):
            preprocess.preprocess("""\
__kernel void A() {
}\
""")
        # kernel containing some code returns the same.
        self.assertEqual(
            """\
__kernel void A() {
  int a;
}\
""", preprocess.preprocess("""\
__kernel void A() {
  int a;
}\
"""))
コード例 #4
0
ファイル: search.py プロジェクト: ChrisCummins/phd
def get_start_code(m):
    while True:
        try:
            buf = StringIO()
            m.sample(seed_text='__kernel void A(__global float* a, '
                                '__global float* b, __global float* c, '
                                'const int d) {',
                     output=buf, max_length=5000, quiet=True)
            out = buf.getvalue()
            return preprocess.preprocess(out)
        except preprocess.BadCodeException:
            pass
        except preprocess.UglyCodeException:
            pass
コード例 #5
0
ファイル: search.py プロジェクト: 50417/phd
def get_start_code(m):
  while True:
    try:
      buf = StringIO()
      m.sample(seed_text='__kernel void A(__global float* a, '
                         '__global float* b, __global float* c, '
                         'const int d) {',
               output=buf, max_length=5000, quiet=True)
      out = buf.getvalue()
      return preprocess.preprocess(out)
    except preprocess.BadCodeException:
      pass
    except preprocess.UglyCodeException:
      pass
コード例 #6
0
ファイル: search.py プロジェクト: ChrisCummins/phd
def get_sample(m, seed_text, seed):
    """
    Generate a new sample.

    Arguments:
        m (Model): CLgen model.
        seed_text (str): Seed text.
        seed (int): Seed value.

    Returns:
        (int, str): 0 if good sample, 1 if bad, 2 if ugly.
    """
    try:
        buf = StringIO()
        m.sample(seed_text=seed_text, output=buf, seed=seed, max_length=5000,
                 quiet=True)
        out = buf.getvalue()
        result = preprocess.preprocess(out)
        return 0, result
    except preprocess.BadCodeException:
        return 1, None
    except preprocess.UglyCodeException:
        return 2, None