def create_packm_functions(myfile, coeffs): ''' Generate all of the custom add functions. myfile is the file to which we are writing coeffs is the set of all coefficients ''' def all_adds(coeffs, name): for i, coeff_set in enumerate(coeffs): if len(coeff_set) > 0: write_packm_func(myfile, coeff_set, i, name) write_break(myfile) # S matrices formed from A subblocks all_adds(transpose(coeffs[0]), 'A') # T matrices formed from B subblocks all_adds(transpose(coeffs[1]), 'B')
def create_M_add_functions(myfile, coeffs): def all_adds(coeffs, name): for i, coeff_set in enumerate(coeffs): if len(coeff_set) > 0: write_M_add_func(myfile, coeff_set, i, name) write_break(myfile) # Output C formed from multiplications #all_adds( coeffs[2], 'M' ) all_adds(transpose(coeffs[2]), 'M')
def create_kernel_header( myfile, coeffs ): write_break( myfile ) abc_micro_kernel_gen.write_header_start( myfile ) for i, coeff_set in enumerate( transpose( coeffs[2] ) ): if len( coeff_set ) > 0: nonzero_coeffs = [coeff for coeff in coeff_set if is_nonzero(coeff)] nnz = len( nonzero_coeffs ) abc_micro_kernel_gen.generate_kernel_header( myfile, nonzero_coeffs, i ) write_break( myfile ) abc_micro_kernel_gen.write_header_end( myfile )
def create_micro_functions( myfile, coeffs, kernel_header_filename ): write_line( myfile, 0, '#include "%s"' % kernel_header_filename ) write_break( myfile ) abc_micro_kernel_gen.write_common_rankk_macro_assembly( myfile ) write_break( myfile ) abc_micro_kernel_gen.macro_initialize_assembly( myfile ) write_break( myfile ) for i, coeff_set in enumerate( transpose( coeffs[2] ) ): if len( coeff_set ) > 0: nonzero_coeffs = [coeff for coeff in coeff_set if is_nonzero(coeff)] nnz = len( nonzero_coeffs ) if nnz <= 23: abc_micro_kernel_gen.generate_micro_kernel( myfile, nonzero_coeffs, i ) write_break( myfile )
def gen_model_coefficient( coeff_filename_mix, level_mix ): coeffs_mix = [] idx = 0 for coeff_file in coeff_filename_mix: coeffs = read_coeffs( coeff_file ) level = level_mix[idx] for level_id in range( level ): coeffs_mix.append( coeffs ) idx += 1 cur_coeffs = generateCoeffs( coeffs_mix ) #N_A_mul = 0 #N_B_mul = 0 #N_C_mul = 0 #N_A_add = 0 #N_B_add = 0 #N_C_add = 0 abc_counter = [ 0 for i in range(6) ] ab_counter = [ 0 for i in range(6) ] naive_counter = [ 0 for i in range(6) ] #N_mul = 0 #N_A_add = 0 #N_B_add = 0 #N_C_add = 0 comp_counter = [ 0 for i in range(4) ] for i, coeff_set in enumerate( transpose( cur_coeffs[0] ) ): nonzero_coeffs = [coeff for coeff in coeff_set if is_nonzero(coeff)] nnz = len( nonzero_coeffs ) #if ( nnz == 1 ): abc_counter[0] += nnz ab_counter[0] += nnz naive_counter[0] += 1 naive_counter[3] += nnz + 1 # if nnz == 1, naive_counter[3] += 0 comp_counter[1] += nnz - 1 for i, coeff_set in enumerate( transpose( cur_coeffs[1] ) ): nonzero_coeffs = [coeff for coeff in coeff_set if is_nonzero(coeff)] nnz = len( nonzero_coeffs ) #if ( nnz == 1 ): abc_counter[1] += nnz ab_counter[1] += nnz naive_counter[1] += 1 naive_counter[4] += nnz + 1 # if nnz == 1, naive_counter[4] += 0 comp_counter[2] += nnz - 1 for i, coeff_set in enumerate( transpose( cur_coeffs[2] ) ): nonzero_coeffs = [coeff for coeff in coeff_set if is_nonzero(coeff)] nnz = len( nonzero_coeffs ) #if ( nnz == 1 ): abc_counter[2] += nnz ab_counter[2] += 1 ab_counter[5] += 3 * nnz naive_counter[2] += 1 naive_counter[5] += 3 * nnz comp_counter[0] += 1 comp_counter[3] += nnz return [ comp_counter, abc_counter, ab_counter, naive_counter ]
def create_macro_functions( myfile, coeffs ): for i, coeff_set in enumerate( transpose( coeffs[2] ) ): if len( coeff_set ) > 0: write_macro_func( myfile, coeff_set, i, 'C' ) write_break( myfile )