def translator(code, target): # initialization ################################################### from preprocessing.main import preprocessing from parse_main.main import parse_main output = {} # implementation ################################################### # Preprocessing # ################################################### code = preprocessing(code) # find globals # ################################################### globals = find_globals(code) # parse main # ################################################### mc = find_main(code) mc, func_list, merge_function_list = parse_main(mc) # Channel # ################################################### func_list = duplicate_function_list(func_list) # Target Translator # #################################################### # done list done_list = [] # translate target = target.lower() if target.strip() == 'cuda': output = translate_to_CUDA(func_list, merge_function_list, code) elif target.strip() == 'python': pass else: # debug print "NOT proper target" print "A", target, "B" assert(False) return mc, output, globals assert(False)
def translator(code, target): # initialization ################################################### from preprocessing.main import preprocessing from parse_main.main import parse_main output = {} # implementation ################################################### # Preprocessing # ################################################### code = preprocessing(code) # find globals # ################################################### globals = find_globals(code) # parse main # ################################################### mc = find_main(code) mc, func_list, merge_function_list = parse_main(mc) # Channel # ################################################### func_list = duplicate_function_list(func_list) # Target Translator # #################################################### # done list done_list = [] # translate target = target.lower() if target.strip() == 'cuda': output = translate_to_CUDA(func_list, merge_function_list, code) elif target.strip() == 'python': pass else: # debug print "NOT proper target" print "A", target, "B" assert (False) return mc, output, globals assert (False)
def translate_main(code): # initialization ################################################### from preprocessing.main import preprocessing from parse_main.main import parse_main # Preprocessing # ################################################### code = preprocessing(code) # parse main # ################################################### mc = find_main(code) mc, _, _ = parse_main(mc) return mc
def test(test_data, test_set=True, detail=0): if test_set: vivaldi_code = test_data['test_input'] local_dict = test_data['dtype_dict'] import ast local_dict= ast.literal_eval(local_dict) test_output = test_data['test_output'] test_return_dtype = test_data['return_dtype'] # test result, result_return_dtype = vi2cu_translator(vivaldi_code=vivaldi_code, local_dict=local_dict) flag = True if flag: # check code flag = dif(result.strip(), test_output.strip()) if flag: print "OK" return True else: print "FAILED" print "test_input:", vivaldi_code.strip() print "test_output:", test_output.strip() print "result:", result.strip() return False else: test_input = test_data target = 'CUDA' from preprocessing.main import preprocessing code = preprocessing(test_input) print "CODE" print "==============================================" print code print "FUNCTION_LIST" print "==============================================" from parse_main.main import parse_main mc = find_main(code) mc, func_list, merge_function_list = parse_main(mc) for elem in func_list: print "FUNC", elem print "TRNALSATED" print "==============================================" full_code = str(code) i = 0 n = len(func_list) while i < n: func = func_list[i] func_name = func['func_name'] func['code'] = find_code(func_name, full_code) i += 1 output = {} for func in func_list: func_name = func['func_name'] func_code = func['code'] dtype_dict = func['dtype_dict'] if 'dtype_dict' in func else {} o_func_name = str(func_name) # redundant check arg_list = func['args'] for arg in arg_list: if arg in dtype_dict: dtype = dtype_dict[arg] dtype = dtype.replace('_volume','') func_name += dtype if func_name in output: continue # translation from vi2cu_translator.main import vi2cu_translator # argument matching function_call_argument_list = func['args'] function_argument_list = get_argument(func_code) dtype_dict = dtype_matching(function_call_argument_list, function_argument_list, dtype_dict) code, return_dtype = vi2cu_translator(func_code, dtype_dict) output[func_name] = {'code':code,'return_dtype':return_dtype} #result, result_return_dtype = vi2cu_translator(vivaldi_code=result, local_dict=[]) for elem in output: print "FUNC_NAME", elem print "==============================================" print output[elem]['code'] return True return False
def test(test_data, test_set=True, detail=0): if test_set: vivaldi_code = test_data['test_input'] local_dict = test_data['dtype_dict'] import ast local_dict = ast.literal_eval(local_dict) test_output = test_data['test_output'] test_return_dtype = test_data['return_dtype'] # test result, result_return_dtype = vi2cu_translator( vivaldi_code=vivaldi_code, local_dict=local_dict) flag = True if flag: # check code flag = dif(result.strip(), test_output.strip()) if flag: print "OK" return True else: print "FAILED" print "test_input:", vivaldi_code.strip() print "test_output:", test_output.strip() print "result:", result.strip() return False else: test_input = test_data target = 'CUDA' from preprocessing.main import preprocessing code = preprocessing(test_input) print "CODE" print "==============================================" print code print "FUNCTION_LIST" print "==============================================" from parse_main.main import parse_main mc = find_main(code) mc, func_list, merge_function_list = parse_main(mc) for elem in func_list: print "FUNC", elem print "TRNALSATED" print "==============================================" full_code = str(code) i = 0 n = len(func_list) while i < n: func = func_list[i] func_name = func['func_name'] func['code'] = find_code(func_name, full_code) i += 1 output = {} for func in func_list: func_name = func['func_name'] func_code = func['code'] dtype_dict = func['dtype_dict'] if 'dtype_dict' in func else {} o_func_name = str(func_name) # redundant check arg_list = func['args'] for arg in arg_list: if arg in dtype_dict: dtype = dtype_dict[arg] dtype = dtype.replace('_volume', '') func_name += dtype if func_name in output: continue # translation from vi2cu_translator.main import vi2cu_translator # argument matching function_call_argument_list = func['args'] function_argument_list = get_argument(func_code) dtype_dict = dtype_matching(function_call_argument_list, function_argument_list, dtype_dict) code, return_dtype = vi2cu_translator(func_code, dtype_dict) output[func_name] = {'code': code, 'return_dtype': return_dtype} #result, result_return_dtype = vi2cu_translator(vivaldi_code=result, local_dict=[]) for elem in output: print "FUNC_NAME", elem print "==============================================" print output[elem]['code'] return True return False