Esempio n. 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)
Esempio n. 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
Esempio n. 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;
}\
"""))
Esempio n. 4
0
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
Esempio n. 5
0
File: search.py Progetto: 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
Esempio n. 6
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