<s> from pycuda . compiler import SourceModule <EOL> from pycuda . tools import context_dependent_memoize <EOL> from neon . backends . cuda_templates import _ew_types <EOL> from neon . backends . layer_gpu import _magic64 <EOL> """<STR_LIT>""" <EOL> @ context_dependent_memoize <EOL> def _get_conv_kernel ( dtype , filter_size , bsum , operation , filter_bounds_check = False , debug = False ) : <EOL> """<STR_LIT>""" <EOL> assert operation in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> if operation == "<STR_LIT>" or operation == "<STR_LIT>" : <EOL> lut_code = r"""<STR_LIT>""" <EOL> elif operation == "<STR_LIT>" : <EOL> lut_code = r"""<STR_LIT>""" <EOL> if bsum : <EOL> bsum_code = r"""<STR_LIT>""" <EOL> else : <EOL> bsum_code = "<STR_LIT>" <EOL> if operation == "<STR_LIT>" : <EOL> a_name = "<STR_LIT:image>" <EOL> b_name = "<STR_LIT:error>" <EOL> else : <EOL> if operation == "<STR_LIT>" : <EOL> a_name = "<STR_LIT:image>" <EOL> b_name = "<STR_LIT>" <EOL> elif operation == "<STR_LIT>" : <EOL> a_name = "<STR_LIT:error>" <EOL> b_name = "<STR_LIT>" <EOL> if filter_bounds_check : <EOL> filter_load_cond = "<STR_LIT>" <EOL> check_filter_cond = "<STR_LIT>" <EOL> else : <EOL> filter_load_cond = "<STR_LIT>" <EOL> check_filter_cond = "<STR_LIT>" <EOL> header_code = r"""<STR_LIT>""" <EOL> code = r"""<STR_LIT>""" <EOL> update_code = r"""<STR_LIT>""" <EOL> if operation == "<STR_LIT>" : <EOL> code = header_code + update_code <EOL> else : <EOL> code = header_code + code <EOL> magic = _magic64 ( filter_size ) <EOL> code = code % { <EOL> "<STR_LIT>" : filter_size , <EOL> "<STR_LIT>" : magic [ <NUM_LIT:0> ] , <EOL> "<STR_LIT>" : magic [ <NUM_LIT:1> ] , <EOL> "<STR_LIT:type>" : _ew_types [ dtype ] [ "<STR_LIT:type>" ] , <EOL> "<STR_LIT>" : lut_code , <EOL> "<STR_LIT>" : bsum_code , <EOL> "<STR_LIT>" : operation , <EOL> "<STR_LIT>" : a_name , <EOL> "<STR_LIT>" : b_name , <EOL> "<STR_LIT>" : filter_load_cond , <EOL> "<STR_LIT>" : check_filter_cond <EOL> } <EOL> options = [ "<STR_LIT>" ] <EOL> if debug and operation == "<STR_LIT>" : <EOL> options = options + [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> module = SourceModule ( code , options = options ) <EOL> kernel = module . get_function ( "<STR_LIT>" + operation ) <EOL> kernel . prepare ( "<STR_LIT>" ) <EOL> kernel . name = "<STR_LIT>" + operation <EOL> return kernel </s>
