(dtype, compute_capability, rounding=False)
return template_vals
Set up template code snippets that are reused across multiple kernels.
    Most are data type conversion and statistics collection related.
Set up template code snippets that are reused across multiple kernels.
    Most are data type conversion and statistics collection related.
Set up template code snippets that are reused across multiple kernels . Most are data type conversion and statistics collection related .
def prepare_template_vals(dtype, compute_capability, rounding=False):
    """
    Set up template code snippets that are reused across multiple kernels.
    Most are data type conversion and statistics collection related.
    """
    template_vals = dict()
    for key in ("inits", "finish", "stats_args", "mul_by_scale", "atomic_max", "cvt_out"):
        template_vals[key] = ""

    template_vals["common"] = _common_divmod

    if rounding:
        template_vals["common"] += _common_urand_gen
        template_vals["common"] += _common_round["nearest"].get(dtype, "")
        template_vals["inits"] += _init_rand_func + _init_rand_round_func
        template_vals["finish"] += _finish_rand_func
        mode = "random"
    else:
        mode = "nearest"

    template_vals["common"] += _common_round[mode].get(dtype, "")
    template_vals["common"] += _common_max_abs

    if (compute_capability[0] == 3 and compute_capability[1] < 5) or compute_capability[0] < 3:
        template_vals["common"] += _common_kepler

    template_vals["type"] = _ew_types[dtype]["type"]
    template_vals["cvt"] = _ew_types[dtype]["cvt"]

    if dtype == "f2":
        template_vals["common"] += _common_fp16_to_fp32
        template_vals["cvt_out"] = "fp32_to_fp16"
    elif dtype == "x2":
        template_vals["stats_args"] += ", int* maxabs, float scale0"
        template_vals["cvt"] = "(float)"
        template_vals["cvt_out"] = "fp32_to_int16"
        template_vals["mul_by_scale"] += "1/scale0 *"
        template_vals["atomic_max"] += atomic_max
    elif dtype == "f4":
        pass
    else:
        raise ValueError("Did not understand clss dtype " + str(dtype))

    return template_vals
def prepare_template_vals ( dtype , compute_capability , rounding = False ) : template_vals = dict ( ) for key in ( "inits" , "finish" , "stats_args" , "mul_by_scale" , "atomic_max" , "cvt_out" ) : template_vals [ key ] = "" template_vals [ "common" ] = _common_divmod if rounding : template_vals [ "common" ] += _common_urand_gen template_vals [ "common" ] += _common_round [ "nearest" ] . get ( dtype , "" ) template_vals [ "inits" ] += _init_rand_func + _init_rand_round_func template_vals [ "finish" ] += _finish_rand_func mode = "random" else : mode = "nearest" template_vals [ "common" ] += _common_round [ mode ] . get ( dtype , "" ) template_vals [ "common" ] += _common_max_abs if ( compute_capability [ 0 ] == 3 and compute_capability [ 1 ] < 5 ) or compute_capability [ 0 ] < 3 : template_vals [ "common" ] += _common_kepler template_vals [ "type" ] = _ew_types [ dtype ] [ "type" ] template_vals [ "cvt" ] = _ew_types [ dtype ] [ "cvt" ] if dtype == "f2" : template_vals [ "common" ] += _common_fp16_to_fp32 template_vals [ "cvt_out" ] = "fp32_to_fp16" elif dtype == "x2" : template_vals [ "stats_args" ] += ", int* maxabs, float scale0" template_vals [ "cvt" ] = "(float)" template_vals [ "cvt_out" ] = "fp32_to_int16" template_vals [ "mul_by_scale" ] += "1/scale0 *" template_vals [ "atomic_max" ] += atomic_max elif dtype == "f4" : pass else : raise ValueError ( "Did not understand clss dtype " + str ( dtype ) ) return template_vals