def simple_array_test(self): py_ast = ast.parse("x = 0.5 + b * c\nreturn x") dfdag = nes.ast_to_dfdag(py_ast, {'b':(2,'nodes','modes'),'c':(2,'nodes','modes')}) ct_builder = nes.dfdag_to_ctree(dfdag) ret_sym = ct_builder.return_symbol ret_sym.type = np.ctypeslib.ndpointer(dtype=np.float64)() c_ast = CFile(body=[ CppInclude("stdlib.h"), FunctionDecl( None, "test_fun", params = [ SymbolRef("b", np.ctypeslib.ndpointer(dtype=np.float64)()), SymbolRef("c", np.ctypeslib.ndpointer(dtype=np.float64)()), SymbolRef("nodes", ctypes.c_int()), SymbolRef("modes", ctypes.c_int()), ret_sym ], defn = ct_builder.c_ast ) ]) mod = JitModule() submod = CFile("test_fun", [c_ast], path=CONFIG.get('jit','COMPILE_PATH'))._compile(c_ast.codegen()) mod._link_in(submod) entry = c_ast.find(FunctionDecl, name="test_fun") c_test_fun = mod.get_callable(entry.name, entry.get_type()) nodes = 19 modes = 5 a = np.random.rand(2, nodes, modes) b = np.random.rand(2, nodes, modes) res = np.zeros((2,nodes,modes)) c_test_fun(a,b,nodes,modes,res) self.assertTrue(np.allclose( res, 0.5+a*b))
def test_gcd(self): mod = JitModule() submod = CFile("test_gcd", [gcd_ast], path=CONFIG.get('jit','COMPILE_PATH'))._compile(gcd_ast.codegen()) mod._link_in(submod) c_gcd_fn = mod.get_callable(gcd_ast.name, gcd_ast.get_type()) self.assertEqual(gcd(44, 122), c_gcd_fn(44, 122)) self.assertEqual(gcd(27, 39), c_gcd_fn(27, 39))
def test_fib(self): mod = JitModule() submod = CFile("test_fib", [fib_ast], path=CONFIG.get('jit','COMPILE_PATH'))._compile(fib_ast.codegen()) mod._link_in(submod) c_fib_fn = mod.get_callable(fib_ast.name, fib_ast.get_type()) self.assertEqual(fib(1), c_fib_fn(1)) self.assertEqual(fib(6), c_fib_fn(6))
def test_l2norm(self): mod = JitModule() submod = CFile("test_l2norm", [l2norm_ast], path=CONFIG.get('jit','COMPILE_PATH'))._compile(l2norm_ast.codegen()) mod._link_in(submod) entry = l2norm_ast.find(FunctionDecl, name="l2norm") c_l2norm_fn = mod.get_callable(entry.name, entry.get_type()) self.assertEqual(l2norm(np.ones(12, dtype=np.float64)), c_l2norm_fn(np.ones(12, dtype=np.float64), 12))
def run(self): """Starts the main OpenTuner loop.""" log.info("tuning thread '%s' starting (%d total threads now).", \ self.name, threading.active_count()) arg_parser = argparse.ArgumentParser(parents=opentuner.argparsers()) config_args = CONFIG.get("opentuner", "args").split() tuner_args = arg_parser.parse_args(config_args) interface = CtreeMeasurementInterface(self._ctree_driver, *self._ot_args, **self._ot_kwargs) TuningRunMain(interface, tuner_args).main() log.info("tuning thread '%s' terminating.", self.name)
def test_identity(self): mod = JitModule() submod = CFile("test_identity", [identity_ast], path=CONFIG.get('jit','COMPILE_PATH')). \ _compile(identity_ast.codegen()) mod._link_in(submod) c_identity_fn = mod.get_callable(identity_ast.name, identity_ast.get_type()) self.assertEqual(identity(1), c_identity_fn(1)) self.assertEqual(identity(12), c_identity_fn(12)) self.assertEqual(identity(123), c_identity_fn(123))
def test_choose(self): mod = JitModule() submod = CFile("test_choose", [choose_ast], path=CONFIG.get('jit','COMPILE_PATH')). \ _compile(choose_ast.codegen()) mod._link_in(submod) c_choose_fn = mod.get_callable(choose_ast.name, choose_ast.get_type()) self.assertEqual(choose(0.2, 44, 122), c_choose_fn(0.2, 44, 122)) self.assertEqual(choose(0.8, 44, 122), c_choose_fn(0.8, 44, 122)) self.assertEqual(choose(0.3, 27, 39), c_choose_fn(0.3, 27, 39)) self.assertEqual(choose(0.7, 27, 39), c_choose_fn(0.7, 27, 39))
def __init__(self, *ot_args, **ot_kwargs): """ Creates communication queues and spawn a thread to run the tuning logic. """ super(OpenTunerDriver, self).__init__() self._best_config = None interface = CtreeMeasurementInterface(self, *ot_args, **ot_kwargs) arg_parser = argparse.ArgumentParser(parents=opentuner.argparsers()) config_args = CONFIG.get("opentuner", "args").split() tuner_args = arg_parser.parse_args(config_args) self.manager = TuningRunManager(interface, tuner_args) self._converged = False
def __init__(self, port_name=None, verbose=False): if port_name is None: from ctree import CONFIG port_name = CONFIG.get('wattsup', 'port') self.port_name = port_name self.serial_port = serial.Serial(self.port_name, 115200) self.last_time = time.time() self.verbose = verbose self.t = [] self.power = [] self.returned_lines = 0 # I don't think device supports anything smaller self.record_interval = 1 self.start_recording()
def __init__(self, port_name=None, verbose=False): if port_name == None: from ctree import CONFIG port_name = CONFIG.get('wattsup', 'port') self.port_name = port_name self.serial_port = serial.Serial(self.port_name, 115200) self.last_time = time.time() self.verbose = verbose self.t = [] self.power = [] self.returned_lines = 0 # I don't think device supports anything smaller self.record_interval = 1 self.start_recording()
def test_getFile(self): getFile(os.path.join(CONFIG.get('jit','COMPILE_PATH'),'test_l2norm.c'))