示例#1
0
def test(test_data, test_set=True, detail=0):

	if test_set:
		from preprocessing.main import preprocessing
		
		test_input = test_data['test_input']
		# preprocessing test input
		test_input = preprocessing(test_input)
		
		test_output = test_data['test_output']

	#	result, func_list = parse_main(test_input)
		result, func_list, merge_function_list = parse_main(test_input)

		flag = dif(result.rstrip(), test_output.rstrip())
		
		if flag:
			print "OK"
			if detail >= 1: 
				print result
			return True
		else:
			print "FAILED"
			print "test_input:", test_input
			print "test_output:", test_output
			print "result:", result
			print "end line check"
			return False
	else:
		test_input = test_data
		from preprocessing.main import preprocessing
		test_input = preprocessing(test_input)
		
		main_code = find_main(test_input)
		
		main_code, output, merge_function_list = parse_main(main_code)
		print "MAIN CODE"
		print "========================================"
		print main_code
		print "OUTPUT"
		print "========================================"
		for elem in output:
			print "NAME", elem
		print "MERGE FUNCTION LIST"
		print "========================================"
		print merge_function_list
示例#2
0
文件: main.py 项目: hvcl-old/Vivaldi
def test(test_data, test_set=True, detail=0):

    if test_set:
        from preprocessing.main import preprocessing

        test_input = test_data['test_input']
        # preprocessing test input
        test_input = preprocessing(test_input)

        test_output = test_data['test_output']

        #	result, func_list = parse_main(test_input)
        result, func_list, merge_function_list = parse_main(test_input)

        flag = dif(result.rstrip(), test_output.rstrip())

        if flag:
            print "OK"
            if detail >= 1:
                print result
            return True
        else:
            print "FAILED"
            print "test_input:", test_input
            print "test_output:", test_output
            print "result:", result
            print "end line check"
            return False
    else:
        test_input = test_data
        from preprocessing.main import preprocessing
        test_input = preprocessing(test_input)

        main_code = find_main(test_input)

        main_code, output, merge_function_list = parse_main(main_code)
        print "MAIN CODE"
        print "========================================"
        print main_code
        print "OUTPUT"
        print "========================================"
        for elem in output:
            print "NAME", elem
        print "MERGE FUNCTION LIST"
        print "========================================"
        print merge_function_list
示例#3
0
    def __init__(self, Vivaldi_code, log_type):
        self.log_type = log_type

        from vivaldi_translator import translator
        mc, output, globals = translator(Vivaldi_code, 'CUDA')

        from preprocessing.main import preprocessing
        Vivaldi_code = preprocessing(Vivaldi_code)
        self.python_code_dict = self.make_python_code_dict(Vivaldi_code)

        self.mc = mc
        self.output = output
        self.globals = globals
	def __init__(self, Vivaldi_code, log_type):
		self.log_type = log_type

		from vivaldi_translator import translator
		mc, output, globals  = translator(Vivaldi_code, 'CUDA')
		
		from preprocessing.main import preprocessing
		Vivaldi_code = preprocessing(Vivaldi_code)
		self.python_code_dict = self.make_python_code_dict(Vivaldi_code)
		
		self.mc = mc
		self.output = output
		self.globals = globals
示例#5
0
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)
示例#6
0
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)
示例#7
0
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
示例#8
0
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
示例#9
0
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
示例#10
0
def preprocessing(code):
    from preprocessing.main import preprocessing

    code = preprocessing(code)
    return code
def preprocessing(code):
    from preprocessing.main import preprocessing
    code = preprocessing(code)
    return code
示例#12
0
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