示例#1
0
def find_broken_transform(fn, inputs, expected, 
                             print_transforms = True, 
                             print_functions = True, 
                             last_phase = loopify):
  from .. import interp 
  

  fn, args = specialize(fn, inputs, optimize=False)  

  try:  
    interp_result = interp.eval(fn, args)
  except:
    print "[Diagnose] Runtime before any optimizations while trying to run", fn
    raise  
    
  
   
  if not eq(interp_result, expected):
    print "[Diagnose] Expected:", expected 
    print "[Diagnose] Result:", interp_result
    print "[Diagnose] This function was busted before we optimized anything!" 
    return None 
  transforms = get_transform_list(fn, last_phase = last_phase)
  print "[Diagnose] Full list of transforms:"
  for (name, t) in transforms:
    print "  -> ", name 
  old_fn = fn 

  for (name, t) in transforms:
    print "[Diagnose] Running %s..." % (name, )
    # in case t is just a class, instantiate it 
    if not isinstance(t, Transform):
      t = t()
    assert isinstance(t, Transform)
    cloner = CloneFunction(parent_transform = t)
    new_fn = t.apply(cloner.apply(old_fn))
    if print_functions:
      print new_fn 
      
    result = interp.eval(new_fn, args)
    if not eq(result, expected):
      print "[Diagnose] Expected %s but got %s " % (expected, result)
      print "[Diagnose] After running ", t
      print "[Diagnose] Old function ", old_fn 
      print "[Diagnose] Transformed function ", new_fn 
      print "[Diagnose] The culprit was:", name 
      return t 
    old_fn = new_fn 
  print "[Diagnose] No problems found!"
  
示例#2
0
def timed_test(parakeet_fn, parakeet_args, python_fn, 
               python_args = None, min_speedup = None):
  if python_args is None:
    python_args = parakeet_args

  start = time.time()
  _ = parakeet_fn(*parakeet_args)
  parakeet_time_with_comp = time.time() - start 

  start = time.time()
  py_result = python_fn(*python_args)
  py_time = time.time() - start 

  start = time.time()
  parakeet_result = parakeet_fn(*parakeet_args)
  parakeet_time_no_comp = time.time() - start 

  print "Parakeet time (with compilation):", parakeet_time_with_comp
  print "Parakeet time (without compilation):", parakeet_time_no_comp
  print "Python time:", py_time 

  assert eq(parakeet_result, py_result), \
    "Expected %s but got %s" % (py_result, parakeet_result)
  if min_speedup is not None:
    assert py_time / parakeet_time_no_comp > min_speedup, \
        "Parakeet too slow: %.2f slowdown" % (parakeet_time_no_comp/py_time)
示例#3
0
def assert_eq_arrays(numpy_result, parakeet_result, test_name = None):
  if test_name is None:
    msg = ""
  else:
    msg = "[%s] " % test_name
  assert type(numpy_result) == type(parakeet_result), \
    "%sExpected type %s but got %s" % (msg, type(numpy_result), type(parakeet_result))
  if hasattr(numpy_result, 'shape'):
    assert hasattr(parakeet_result, 'shape')
    assert numpy_result.shape == parakeet_result.shape, \
      "%sExpected shape %s but got %s" % (msg, numpy_result.shape, parakeet_result.shape)
    assert eq(numpy_result, parakeet_result), \
      "%sExpected value %s but got %s" % (msg, numpy_result, parakeet_result)