test_ph_bound, lar_statement, Statement( ReferenceAssign(modk, modk_std), ReferenceAssign(red_vx, red_vx_std), )), result_1)) return scheme def numeric_emulate(self, input_value): if self.sin_output: return sin(input_value) else: return cos(input_value) if __name__ == "__main__": # auto-test arg_template = ML_NewArgTemplate(default_arg=ML_SinCos.get_default_args()) # argument extraction arg_template.get_parser().add_argument( "--sin", dest="sin_output", default=False, const=True, action="store_const", help="select sine output (default is cosine)") args = arg_template.arg_extraction() ml_sincos = ML_SinCos(args) ml_sincos.gen_implementation()
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. ############################################################################### # created: Mar 25th, 2020 # last-modified: Mar 25th, 2020 # Author(s): Nicolas Brunie <*****@*****.**> ############################################################################### from metalibm_core.utility.ml_template import ML_NewArgTemplate from metalibm_functions.ml_atan import MetaAtan2 if __name__ == "__main__": # auto-test arg_template = ML_NewArgTemplate(default_arg=MetaAtan2.get_default_args()) # extra options arg_template.get_parser().add_argument( "--method", dest="method", default="piecewise", choices=["piecewise", "single"], action="store", help="select approximation method") arg_template.get_parser().add_argument( "--num-sub-intervals", default=8, type=int, action="store", help="set the number of sub-intervals in piecewise method") args = arg_template.arg_extraction() ml_atan2 = MetaAtan2(args) ml_atan2.gen_implementation()
return recp_eval_error, div_eval_error standard_test_cases = [ (1.0, sollya.parse("0x1.fffffffffffffp+1023"), sollya.parse("0x1p-1024")), (sollya.parse("-0x1.34a246p-2"), sollya.parse("-0x1.26e2e2p-1")), (sollya.parse("0x1.p0"), sollya.parse("0x1.e0ef5ep-49")), (sollya.parse("0x1.7fddbp0"), sollya.parse("0x1.e0ef5ep-49")), (sollya.parse("0x1.7fddbp-126"), sollya.parse("0x1.e0ef5ep-49")), (1.0, sollya.parse("-0x1.fffffffffffffp+1023"), sollya.parse("-0x1p-1024")), ] if __name__ == "__main__": # auto-test arg_template = ML_NewArgTemplate( default_arg=ML_Division.get_default_args()) arg_template.get_parser().add_argument( "--num-iter", dest="num_iter", default=3, type=int, action="store", help="number of newton-raphson iterations") ARGS = arg_template.arg_extraction() ml_div = ML_Division(ARGS) ml_div.gen_implementation()
def numeric_emulate(self, input_value): if self.cos_output: return cos(input_value) else: return sin(input_value) if __name__ == "__main__": arg_template = ML_NewArgTemplate( default_arg=ML_FastSinCos.get_default_args()) # argument extraction arg_template.get_parser().add_argument( "--sin", dest="cos_output", default=True, const=False, action="store_const", help="select sine output (default is cosine)") arg_template.get_parser().add_argument( "--table-size-log", dest="table_size_log", default=8, type=int, action="store", help="logarithm of the table size to be used") args = arg_template.arg_extraction() ml_fast_sincos = ML_FastSinCos(args) ml_fast_sincos.gen_implementation()
op_map[op] = [] for f in formats: op_map[op].append(f) return op_map if __name__ == "__main__": # auto-test arg_template = ML_NewArgTemplate(default_function_name="main", default_output_file="bench.c", default_arg=UnitBench.get_default_args()) # argument extraction arg_template.get_parser().add_argument("--test-num", dest="test_num", default=10000, action="store", type=int, help="number of basic iteration") arg_template.get_parser().add_argument("--unroll-factor", dest="unroll_factor", default=10, action="store", type=int, help="number of basic iteration") # TODO: on-going arg_template.get_parser().add_argument("--operations", dest="operation_map", default="binary64,binary32:add,mul", action="store", type=operation_map_parser,
sollya.parse("-0x0.4000000000000p-1022")), (sollya.parse("0x1.fffffffffffffp+1023"), -1, sollya.parse("0x0.4000000000000p-1022")), ] return (fp_64_only if self.precision.get_bit_size() >= 64 else []) \ + (fp_32_only if self.precision.get_bit_size() == 32 else []) \ + general_list if __name__ == "__main__": # declaring standard argument structure arg_template = ML_NewArgTemplate(default_arg=MetaRootN.get_default_args()) arg_template.get_parser().add_argument( "--expand-div", dest="expand_div", default=False, const=int, action="store_const", help="expand division to meta-division") # filling arg_template structure with command line options args = arg_template.arg_extraction() # declaring meta-function instance meta_function = MetaRootN(args) # generating meta_function meta_function.gen_implementation()
""" generate list of instance of input tensor descriptors for testing """ n, m, p = random_sizes tA_desc = TensorDescriptor([p, n], [1, p], self.precision) # B is a (p x m) matrix in row-major tB_desc = TensorDescriptor([m, p], [1, m], self.precision) return [tA_desc, tB_desc] if __name__ == "__main__": arg_template = ML_NewArgTemplate( default_arg=ShallowConvKernel.get_default_args()) # extra arguments arg_template.get_parser().add_argument( "--test-index-range", dest="test_index_range", default=[[16, 32], [16, 32], [16, 32]], type=eval, action="store", help="random range for matrix sizes") arg_template.get_parser().add_argument( "--kernel-size", dest="kernel_size", default=(3, 3), type=(lambda s: tuple(map(int, s.split(",")))), action="store", help="random range for matrix sizes") # argument extraction args = arg_template.arg_extraction() shallow_conv_kernel = ShallowConvKernel(args)
""" generate list of instance of output tensor descriptors for testing """ n, m, p = random_sizes # C is a (n x m) matrix in row-major tC_desc = TensorDescriptor([m, n], [1, m], self.precision) return [tC_desc] def generate_innput_tensor_descriptors(self, random_sizes): """ generate list of instance of input tensor descriptors for testing """ n, m, p = random_sizes tA_desc = TensorDescriptor([p, n], [1, p], self.precision) # B is a (p x m) matrix in row-major tB_desc = TensorDescriptor([m, p], [1, m], self.precision) return [tA_desc, tB_desc] if __name__ == "__main__": arg_template = ML_NewArgTemplate(default_arg=MatrixMultiplyKernel.get_default_args()) # extra arguments arg_template.get_parser().add_argument( "--test-index-range", dest="test_index_range", default=[[16, 32], [16, 32], [16, 32]], type=eval, action="store", help="random range for matrix sizes") arg_template.get_parser().add_argument( "--vectorize", const=True, default=False, action="store_const", help="enable matrix-multiply vectorization") # argument extraction args = arg_template.arg_extraction() matrix_multiply_kernel = MatrixMultiplyKernel(args) matrix_multiply_kernel.gen_implementation()
(sollya.parse("-0x1.86c83abe0854ep+268"), FP_MinusInfty(self.precision)), # bad sign of remainder (sollya.parse("0x1.d3fb9968850a5p-960"), sollya.parse("-0x0.23c1ed19c45fp-1022")), # bad sign of zero (FP_MinusZero(self.precision), sollya.parse("0x1.85200a9235193p-450")), # bad remainder (sollya.parse("0x1.fffffffffffffp+1023"), sollya.parse("0x1.1f31bcd002a7ap-803")), # bad sign (sollya.parse("-0x1.4607d0c9fc1a7p-878"), sollya.parse("-0x1.9b666b840b1bp-1023")), ] return fp64_list if self.precision.get_bit_size() >= 64 else [] if __name__ == "__main__": # auto-test arg_template = ML_NewArgTemplate( default_arg=MetaRemQuo.get_default_args() ) arg_template.get_parser().add_argument( "--quotient-size", dest="quotient_size", default=3, type=int, action="store", help="number of bit to return for the quotient") arg_template.get_parser().add_argument( "--mode", dest="mode", default="quotient", choices=['quotient', 'remainder', 'full'], action="store", help="number of bit to return for the quotient") ARGS = arg_template.arg_extraction() ml_remquo = MetaRemQuo(ARGS) ml_remquo.gen_implementation()
return self.emulate(*args) if __name__ == "__main__": # auto-test arg_template = ML_NewArgTemplate( default_arg=ML_ExternalBench.get_default_args()) def precision_list_parser(s): return [precision_parser(p) for p in s.split(",")] # argument extraction arg_template.get_parser().add_argument( "--function", dest="bench_function_name", default="expf", action="store", type=str, help="name of the function to be benched") arg_template.get_parser().add_argument( "--headers", dest="headers", default=[], action="store", type=lambda s: s.split(","), help="comma separated list of required headers") arg_template.get_parser().add_argument( "--libraries", dest="libraries", default=[], action="store",
io_precisions = [precision] * 2 # initializing base class ML_FunctionBasis.__init__(self, arg_template=arg_template ) self.precision = precision if __name__ == "__main__": # auto-test arg_template = ML_NewArgTemplate() arg_template.get_parser().add_argument( "--test-gappa", dest="test_gappa", action="store_const", const=True, default=False, help="test gappa install") arg_template.get_parser().add_argument( "--test-cgpe", dest="test_cgpe", action="store_const", const=True, default=False, help="test cgpe install") arg_template.get_parser().add_argument( "--full-status", dest="full_status", action="store_const", const=True, default=False, help="test full Metalibm status") # argument extraction args = arg_template.arg_extraction() if args.test_cgpe or args.full_status: print("CPGE available: {}".format(polynomials.is_cgpe_available())) if args.test_gappa or args.full_status: print("Gappa available: {}".format(gappa.is_gappa_installed()))
def numeric_emulate(self, x): """ numeric emulation """ TABLE = [1.1**i for i in range(self.table_size)] return TABLE[int(x)] @staticmethod def __call__(args): """ Static method from TestRunner: main test function """ ut_bfloat16 = ML_UT_BFloat16(args) ut_bfloat16.gen_implementation() return True run_test = ML_UT_BFloat16 if __name__ == "__main__": # auto-test arg_template = ML_NewArgTemplate(default_arg=ML_UT_BFloat16.get_default_args()) arg_template.get_parser().add_argument( "--table-size", dest="table_size", default=10, type=int, help="set internal table size") args = arg_template.arg_extraction() if run_test(args): exit(0) else: exit(1)
for arg_index, var_tag in enumerate(["x", "y", "z", "t"]) if var_tag in self.var_mapping } # TODO function evaluation graph could be pre-compiled during generate scheme # of function_expr_str parsing function_mapping = {tag: FUNCTION_MAP[tag][2] for tag in FUNCTION_MAP} return evaluate_graph(self.function_expr, value_mapping, function_mapping) if __name__ == "__main__": # auto-test ARG_TEMPLATE = ML_NewArgTemplate( default_arg=FunctionExpression.get_default_args()) ARG_TEMPLATE.get_parser().add_argument( "function_expr_str", nargs=1, type=str, help="function expression to generate") ARG_TEMPLATE.get_parser().add_argument( "--expand-div", action="store_const", default=False, const=True, help="expand division into function scheme") ARGS = ARG_TEMPLATE.arg_extraction() ML_FUNCTION_EXPR = FunctionExpression(ARGS) ML_FUNCTION_EXPR.gen_implementation()