def run(paths): function_backends = defaultdict(list) header_functions = OrderedDict() headers = [p for p in paths if p.endswith('.h')] yamls = [p for p in paths if p.endswith('.yaml')] for path in headers: backend = 'CUDA' if re.search('THCU', path) else 'CPU' for func in common_with_cwrap.parse_header(path): if re.search(include_only, func.name) is None or re.search( exclude, func.name) is not None: continue function_backends[func.name].append(backend) if func.name not in header_functions: header_functions[func.name] = func bwd_suffixes = ['_updateGradInput', '_accGradParameters', '_backward'] declarations = [] for path in yamls: for func in parse_nn_yaml(path): cname = func['cname'] backends = function_backends[cname + '_updateOutput'] fwd_function = header_functions[cname + '_updateOutput'] bwd_functions = [] for suffix in bwd_suffixes: if cname + suffix in header_functions: bwd_functions.append(header_functions[cname + suffix]) default_scalar_types = ['Float', 'Double', 'Half' ] # Half will be stripped for CPU backend forward_backend_types = {} backward_backend_types = {} for backend in backends: backend_props = func.get(backend, {}) forward_backend_types[backend] = backend_props.get( 'forward_scalar_types', default_scalar_types) backward_backend_types[backend] = backend_props.get( 'backward_scalar_types', default_scalar_types) base = base_declaration(func, fwd_function, backends, None) declarations.append( forward_declaration(base, fwd_function, forward_backend_types)) if bwd_functions: declarations.append( backward_declaration(base, bwd_functions, backward_backend_types)) if func.get('has_inplace', False): declarations.append( base_declaration(func, fwd_function, backends, forward_backend_types, True)) declarations.append( forward_declaration(base, fwd_function, forward_backend_types, True)) return declarations
def run(paths): functions = OrderedDict() for path in paths: backend = 'CUDA' if re.search('THCU', path) else 'CPU' for func in common_with_cwrap.parse_header(path): if re.search(include_only, func.name) is None or re.search(exclude, func.name) is not None: continue if func.name in functions: functions[func.name]['backends'].append(backend) else: functions[func.name] = function_to_declaration(func, backend) declarations = [f for _, f in functions.items()] return declarations
def run(paths): function_backends = defaultdict(list) header_functions = OrderedDict() headers = [p for p in paths if p.endswith('.h')] yamls = [p for p in paths if p.endswith('.yaml')] for path in headers: backend = 'CUDA' if re.search('THCU', path) else 'CPU' for func in common_with_cwrap.parse_header(path): if re.search(include_only, func.name) is None or re.search( exclude, func.name) is not None: continue function_backends[func.name].append(backend) if func.name not in header_functions: header_functions[func.name] = func bwd_suffixes = ['_updateGradInput', '_accGradParameters', '_backward'] declarations = [] for path in yamls: for func in parse_nn_yaml(path): cname = func['cname'] backends = function_backends[cname + '_updateOutput'] fwd_function = header_functions[cname + '_updateOutput'] bwd_functions = [] for suffix in bwd_suffixes: if cname + suffix in header_functions: bwd_functions.append(header_functions[cname + suffix]) base = base_declaration(func, fwd_function, backends) declarations.append(base) declarations.append(forward_declaration(base, fwd_function)) declarations.append(backward_declaration(base, bwd_functions)) if func.get('has_inplace', False): declarations.append( base_declaration(func, fwd_function, backends, True)) declarations.append( forward_declaration(base, fwd_function, True)) return declarations
def run(paths): function_backends = defaultdict(list) header_functions = OrderedDict() headers = [p for p in paths if p.endswith('.h')] yamls = [p for p in paths if p.endswith('.yaml')] for path in headers: backend = 'CUDA' if re.search('THCU', path) else 'CPU' for func in common_with_cwrap.parse_header(path): if re.search(include_only, func.name) is None or re.search(exclude, func.name) is not None: continue function_backends[func.name].append(backend) if func.name not in header_functions: header_functions[func.name] = func bwd_suffixes = ['_updateGradInput', '_accGradParameters', '_backward'] declarations = [] for path in yamls: for func in parse_nn_yaml(path): cname = func['cname'] backends = function_backends[cname + '_updateOutput'] fwd_function = header_functions[cname + '_updateOutput'] bwd_functions = [] for suffix in bwd_suffixes: if cname + suffix in header_functions: bwd_functions.append(header_functions[cname + suffix]) base = base_declaration(func, fwd_function, backends) declarations.append(base) declarations.append(forward_declaration(base, fwd_function)) declarations.append(backward_declaration(base, bwd_functions)) if func.get('has_inplace', False): declarations.append(base_declaration(func, fwd_function, backends, True)) declarations.append(forward_declaration(base, fwd_function, True)) return declarations