def exec_weld(values, ty, threads, weld_conf): file_path = '%s.weld' % ty weld_code = None with open(file_path, 'r') as content_file: weld_code = content_file.read() enc = NumpyArrayEncoder() names = ['x', 'y'] argtypes = [enc.py_to_weld_type(x).ctype_class for x in values] encoded = [enc.encode(x) for x in values] Args = args_factory(zip(names, argtypes)) weld_args = Args() for name, value in zip(names, encoded): setattr(weld_args, name, value) void_ptr = ctypes.cast(ctypes.byref(weld_args), ctypes.c_void_p) arg = cweld.WeldValue(void_ptr) # Compile the module err = cweld.WeldError() conf = cweld.WeldConf() conf.set("weld.threads", str(threads)) conf.set("weld.memory.limit", "20000000000") if weld_conf is not None: for key, val in weld_conf.iteritems(): conf.set(key, val) comp_start = timer() module = cweld.WeldModule(weld_code, conf, err) comp_time = timer() - comp_start if err.code() != 0: raise ValueError("Could not compile function {}: {}".format( weld_code, err.message())) # Run the module dec = ScalarDecoder() restype = WeldVec(WeldInt()) err = cweld.WeldError() exec_start = timer() weld_ret = module.run(conf, arg, err) exec_time = timer() - exec_start if err.code() != 0: raise ValueError(("Error while running function,\n{}\n\n" "Error message: {}").format( weld_code, err.message())) ptrtype = POINTER(restype.ctype_class) data = ctypes.cast(weld_ret.data(), ptrtype) result = None#dec.decode(data, restype) weld_ret.free() arg.free() return (result, comp_time, exec_time)
def join_weld(values, adaptive, lazy, threads, weld_conf): weld_code = None with open('join.weld', 'r') as content_file: weld_code = content_file.read() enc = NumpyArrayEncoder() names = ['Ra', 'Rz', 'Sa', 'Sb', 'Tb', 'Tc', 'Uc', 'Ud'] argtypes = [enc.py_to_weld_type(x).ctype_class for x in values] encoded = [enc.encode(x) for x in values] Args = args_factory(zip(names, argtypes)) weld_args = Args() for name, value in zip(names, encoded): setattr(weld_args, name, value) void_ptr = ctypes.cast(ctypes.byref(weld_args), ctypes.c_void_p) arg = cweld.WeldValue(void_ptr) # Compile the module err = cweld.WeldError() conf = cweld.WeldConf() conf.set("weld.optimization.applyAdaptiveTransforms", "true" if adaptive else "false") conf.set("weld.adaptive.lazyCompilation", "true" if lazy else "false") conf.set("weld.threads", str(threads)) conf.set("weld.memory.limit", "20000000000") if weld_conf is not None: for key, val in weld_conf: conf.set(key, val) comp_start = timer() module = cweld.WeldModule(weld_code, conf, err) comp_time = timer() - comp_start if err.code() != 0: raise ValueError("Could not compile function {}: {}".format( weld_code, err.message())) # Run the module dec = ScalarDecoder() restype = WeldLong() err = cweld.WeldError() exec_start = timer() weld_ret = module.run(conf, arg, err) exec_time = timer() - exec_start if err.code() != 0: raise ValueError(("Error while running function,\n{}\n\n" "Error message: {}").format( weld_code, err.message())) ptrtype = POINTER(restype.ctype_class) data = ctypes.cast(weld_ret.data(), ptrtype) result = dec.decode(data, restype) weld_ret.free() arg.free() return (result, comp_time, exec_time)
def benchmark(data, type, threads, weld_conf): adaptive = type == 'Adaptive' lazy = False code_path = None if (type == 'Filter->Map1'): code_path = 'filter_then_map.weld' elif (type == 'Map->Filter'): code_path = 'map_then_filter.weld' else: code_path = 'fused.weld' weld_code = None with open(code_path, 'r') as content_file: weld_code = content_file.read() enc = NumpyArrayEncoder() names = [c for c in sorted(data)] argtypes = [enc.py_to_weld_type(data[c]).ctype_class for c in names] encoded = [enc.encode(data[c]) for c in names] Args = args_factory(zip(names, argtypes)) weld_args = Args() for name, value in zip(names, encoded): setattr(weld_args, name, value) void_ptr = ctypes.cast(ctypes.byref(weld_args), ctypes.c_void_p) arg = cweld.WeldValue(void_ptr) # Compile the module err = cweld.WeldError() conf = cweld.WeldConf() conf.set("weld.optimization.applyAdaptiveTransforms", "true" if adaptive else "false") conf.set("weld.adaptive.lazyCompilation", "true" if lazy else "false") conf.set("weld.threads", str(threads)) conf.set("weld.memory.limit", "30000000000") if type == 'Map->Filter' or type == 'Filter->Map1' or type == 'Filter->Map2': conf.set( 'weld.optimization.passes', 'unroll-static-loop,infer-size,adapt-reorder-filter-projection,adapt-bloomfilter,adapt-predicate,short-circuit-booleans,predicate,vectorize,fix-iterate' ) if weld_conf is not None: for key, val in weld_conf.iteritems(): conf.set(key, val) comp_start = timer() module = cweld.WeldModule(weld_code, conf, err) comp_time = timer() - comp_start if err.code() != 0: raise ValueError("Could not compile function {}: {}".format( weld_code, err.message())) # Run the module dec = ScalarDecoder() restype = WeldLong() err = cweld.WeldError() exec_start = timer() weld_ret = module.run(conf, arg, err) exec_time = timer() - exec_start if err.code() != 0: raise ValueError(("Error while running function,\n{}\n\n" "Error message: {}").format(weld_code, err.message())) ptrtype = POINTER(restype.ctype_class) data = ctypes.cast(weld_ret.data(), ptrtype) result = dec.decode(data, restype) weld_ret.free() arg.free() return (result, comp_time, exec_time)