Example #1
0
def parse_line(line, local_dict):

	# Find data type
	#
	#####################################################################################
	# find data type of elements in the line
	from vi2cu_translator.functions.dtype_check.dtype_check import find_dtype
	find_dtype(line, local_dict)
Example #2
0
def parse_line(line, local_dict):

    # Find data type
    #
    #####################################################################################
    # find data type of elements in the line
    from vi2cu_translator.functions.dtype_check.dtype_check import find_dtype
    find_dtype(line, local_dict)
Example #3
0
def change_return(code_list, local_dict):
	# change return statement for CUDA style
	# from return max
	# to rb[(z-rb_DATA_RANGE->start.z)*(rb_DATA_RANGE->end.y-rb_DATA_RANGE->start.y)*(rb_DATA_RANGE->end.x-rb_DATA_RANGE->start.x)+(y-rb_DATA_RANGE->start.y)*(rb_DATA_RANGE->end.x-rb_DATA_RANGE->start.x)+(x-rb_DATA_RANGE->start.x)] = max
	
	k = 0
	for code in code_list:
	
		flag = True
		idx1 = -1
		while flag:
			flag = False
			idx2 = code.find('return', idx1+1)
			
			if idx2 != -1:
				flag = True
				
				# before
				before = code[:idx2]
				# mid
				mid = ''
				i = 0
				for axis in AXIS:
					if axis in local_dict:
						mid += '+(' + axis + '-rb_DATA_RANGE->buffer_start.' + axis + ')'
						
						for axis2 in AXIS[:i]:
							mid += '*(rb_DATA_RANGE->buffer_end.' + axis2 + '-rb_DATA_RANGE->buffer_start.' + axis2 + ')'
						
						i += 1
					else:
						break
				mid = 'rb[' + mid[1:] + '] = ' 
				# after
				after = code[idx2 + len('return'):]
				
				idx3 = after.find('\n')
				indent = get_indent(code[:idx2+1])
#				after = after[:idx3+1] + indent + 'return\n' + after[idx3+1:] 
				var_name = after[:idx3+1].strip()
				
				global return_dtype
				return_dtype = find_dtype(var_name, local_dict)
				return_dtype = to_CUDA_dtype(return_dtype)
				
				after = after[:idx3+1].strip() + '\n' + indent + 'return\n' + after[idx3+1:] 
			
				# merge
				code = before + mid + after
				
				# idx1 = found + mid + idx3 + indent
				num = idx2 + len(mid) + idx3 + len(indent)
				idx1 = num + 1
				
				
		code_list[k] = code
		k += 1
				
	
	return code_list
Example #4
0
def change_return(code_list, local_dict):
    # change return statement for CUDA style
    # from return max
    # to rb[(z-rb_DATA_RANGE->start.z)*(rb_DATA_RANGE->end.y-rb_DATA_RANGE->start.y)*(rb_DATA_RANGE->end.x-rb_DATA_RANGE->start.x)+(y-rb_DATA_RANGE->start.y)*(rb_DATA_RANGE->end.x-rb_DATA_RANGE->start.x)+(x-rb_DATA_RANGE->start.x)] = max

    k = 0
    for code in code_list:

        flag = True
        idx1 = -1
        while flag:
            flag = False
            idx2 = code.find('return', idx1 + 1)

            if idx2 != -1:
                flag = True

                # before
                before = code[:idx2]
                # mid
                mid = ''
                i = 0
                for axis in AXIS:
                    if axis in local_dict:
                        mid += '+(' + axis + '-rb_DATA_RANGE->buffer_start.' + axis + ')'

                        for axis2 in AXIS[:i]:
                            mid += '*(rb_DATA_RANGE->buffer_end.' + axis2 + '-rb_DATA_RANGE->buffer_start.' + axis2 + ')'

                        i += 1
                    else:
                        break
                mid = 'rb[' + mid[1:] + '] = '
                # after
                after = code[idx2 + len('return'):]

                idx3 = after.find('\n')
                indent = get_indent(code[:idx2 + 1])
                #				after = after[:idx3+1] + indent + 'return\n' + after[idx3+1:]
                var_name = after[:idx3 + 1].strip()

                global return_dtype
                return_dtype = find_dtype(var_name, local_dict)
                return_dtype = to_CUDA_dtype(return_dtype)

                after = after[:idx3 + 1].strip(
                ) + '\n' + indent + 'return\n' + after[idx3 + 1:]

                # merge
                code = before + mid + after

                # idx1 = found + mid + idx3 + indent
                num = idx2 + len(mid) + idx3 + len(indent)
                idx1 = num + 1

        code_list[k] = code
        k += 1

    return code_list
Example #5
0
def find_return_dtype(code='', local_dict={}):
	# find return dtype of CUDA code
	
	if False:
		# False
		print "FIND RETURN", local_dict
	n = len(code)
	idx1 = -1
	return_dtype = ''
	while True:
		# find value assignment of return buffer
		idx1 = code.find('rb[', idx1+1)
		if idx1 == -1: break
		
		# find assignment operator
		idx2 = code.find('=',idx1+1)
		
		# find variable name
		flag = False
		i = idx2+1
		var_name = ''
		
		# find variable start
		start = i+1
		
		# find variable end
		while i < n:
			w = code[i]
			
			# end line
			if w == ';':
				break
			i += 1
		end = i
		# variable name
		var_name = code[start: end]
		
		# CUDA to VIVALDI style
		# because implemented function get VIVALDI code to input 
		
		# remove <...>: not in the python
	
		n = len(var_name)
		output = ''
		i = 0
		flag = True
		while i < n:
			w = var_name[i]
			if w == '<':
				flag = False
				
			if flag:
				output += w
				
			if w == '>':
				flag = True
			i += 1

		return_dtype = find_dtype(output, local_dict)
	
		## to CUDA dtype
		return_dtype = to_CUDA_dtype(return_dtype)
		
		return return_dtype
		
	return return_dtype
Example #6
0
def find_return_dtype(code='', local_dict={}):
    # find return dtype of CUDA code

    if False:
        # False
        print "FIND RETURN", local_dict
    n = len(code)
    idx1 = -1
    return_dtype = ''
    while True:
        # find value assignment of return buffer
        idx1 = code.find('rb[', idx1 + 1)
        if idx1 == -1: break

        # find assignment operator
        idx2 = code.find('=', idx1 + 1)

        # find variable name
        flag = False
        i = idx2 + 1
        var_name = ''

        # find variable start
        start = i + 1

        # find variable end
        while i < n:
            w = code[i]

            # end line
            if w == ';':
                break
            i += 1
        end = i
        # variable name
        var_name = code[start:end]

        # CUDA to VIVALDI style
        # because implemented function get VIVALDI code to input

        # remove <...>: not in the python

        n = len(var_name)
        output = ''
        i = 0
        flag = True
        while i < n:
            w = var_name[i]
            if w == '<':
                flag = False

            if flag:
                output += w

            if w == '>':
                flag = True
            i += 1

        return_dtype = find_dtype(output, local_dict)

        ## to CUDA dtype
        return_dtype = to_CUDA_dtype(return_dtype)

        return return_dtype

    return return_dtype