Example #1
0
def generate_integral_code(ir, prefix, parameters):
    "Generate code for integral from intermediate representation."

    info("Generating code from ffc.uflacs representation")

    # FIXME: Is this the right precision value to use? Make it default to None or 0.
    precision = ir["integrals_metadata"]["precision"]

    # Create FFC C++ backend
    backend = FFCBackend(ir, parameters)

    # Configure kernel generator
    ig = IntegralGenerator(ir, backend, precision)

    # Generate code ast for the tabulate_tensor body
    parts = ig.generate()

    # Format code as string
    body = format_indented_lines(parts.cs_format(precision), 1)

    # Generate generic ffc code snippets and add uflacs specific parts
    code = initialize_integral_code(ir, prefix, parameters)
    code["tabulate_tensor"] = body
    code["additional_includes_set"] = set(ig.get_includes())
    code["additional_includes_set"].update(
        ir.get("additional_includes_set", ()))

    # TODO: Move to initialize_integral_code, this is not representation specific
    if ir.get("num_cells") is not None:
        ret = backend.language.Return(ir["num_cells"])
        code["num_cells"] = format_indented_lines(ret.cs_format(), 1)

    return code
Example #2
0
def generate_integral_code(ir, prefix, parameters):
    "Generate code for integral from intermediate representation."

    info("Generating code from ffc.uflacs representation")

    # FIXME: Is this the right precision value to use? Make it default to None or 0.
    precision = ir["integrals_metadata"]["precision"]

    # Create FFC C++ backend
    backend = FFCBackend(ir, parameters)

    # Configure kernel generator
    ig = IntegralGenerator(ir, backend, precision)

    # Generate code ast for the tabulate_tensor body
    parts = ig.generate()

    # Format code as string
    body = format_indented_lines(parts.cs_format(precision), 1)

    # Generate generic ffc code snippets and add uflacs specific parts
    code = initialize_integral_code(ir, prefix, parameters)
    code["tabulate_tensor"] = body
    code["additional_includes_set"] = set(ig.get_includes())
    code["additional_includes_set"].update(ir.get("additional_includes_set", ()))

    # TODO: Move to initialize_integral_code, this is not representation specific
    if ir.get("num_cells") is not None:
        ret = backend.language.Return(ir["num_cells"])
        code["num_cells"] = format_indented_lines(ret.cs_format(), 1)

    return code
Example #3
0
def generate_integral_code(ir, prefix, parameters):
    "Generate code for integral from intermediate representation."

    info("Generating code from tsfc representation")

    # Generate generic ffc code snippets
    code = initialize_integral_code(ir, prefix, parameters)

    # Go unoptimized if TSFC mode has not been set yet
    integral_data, form_data, prefix, parameters = ir["compile_integral"]
    parameters = parameters.copy()
    parameters.setdefault("mode", "vanilla")

    # Generate tabulate_tensor body
    ast = compile_integral(integral_data, form_data, None, parameters,
                           interface=ufc_interface)

    # COFFEE vectorize
    knl = ASTKernel(ast)
    knl.plan_cpu(dict(optlevel='Ov'))

    tsfc_code = "".join(b.gencode() for b in ast.body)
    tsfc_code = tsfc_code.replace("#pragma coffee", "//#pragma coffee") # FIXME
    code["tabulate_tensor"] = tsfc_code

    includes = set()
    includes.update(ir.get("additional_includes_set", ()))
    includes.update(ast.headers)
    includes.add("#include <cstring>")  # memset
    if any(node.funcall.symbol.startswith("boost::math::")
           for node in Find(coffee.FunCall).visit(ast)[coffee.FunCall]):
        includes.add("#include <boost/math/special_functions.hpp>")
    code["additional_includes_set"] = includes

    return code
Example #4
0
def generate_pyop2_ir(ir, prefix, parameters):
    "Generate code for integral from intermediate representation."
    code = initialize_integral_code(ir, prefix, parameters)
    code["additional_includes_set"] = ir["additional_includes_set"]
    code["metadata"] = ""

    body_ir = _tabulate_tensor(ir, parameters)
    return pyop2.FunDecl("void", code["classname"], _arglist(ir), body_ir, ["static", "inline"])
Example #5
0
def generate_integral_code(ir, prefix, parameters):
    "Generate code for integral from intermediate representation."

    # Prefetch formatting to speedup code generation (well...)
    ret = format["return"]

    # Generate code
    code = initialize_integral_code(ir, prefix, parameters)
    code["num_cells"] = ret(ir["num_cells"])
    code["tabulate_tensor"] = _tabulate_tensor(ir, prefix, parameters)
    code["additional_includes_set"] = ir["additional_includes_set"]

    return code
def generate_integral_code(ir, prefix, parameters):
    "Generate code for integral from intermediate representation."

    info("Generating code from uflacs representation")

    # Generate generic ffc code snippets
    code = initialize_integral_code(ir, prefix, parameters)

    # Delegate to uflacs to generate tabulate_tensor body
    import uflacs.backends.ffc
    ucode = uflacs.backends.ffc.generate_tabulate_tensor_code(ir, parameters)
    code["tabulate_tensor"] = ucode["tabulate_tensor"]
    code["additional_includes_set"] = ir.get("additional_includes_set",set()) | set(ucode["additional_includes_set"])
    return code
def generate_integral_code(ir, prefix, parameters):
    "Generate code for integral from intermediate representation."

    info("Generating code from uflacs representation")

    # Generate generic ffc code snippets
    code = initialize_integral_code(ir, prefix, parameters)

    # Delegate to uflacs to generate tabulate_tensor body
    import uflacs.backends.ffc
    ucode = uflacs.backends.ffc.generate_tabulate_tensor_code(ir, parameters)
    code["tabulate_tensor"] = ucode["tabulate_tensor"]
    code["additional_includes_set"] = ir.get(
        "additional_includes_set", set()) | set(
            ucode["additional_includes_set"])
    return code
Example #8
0
def generate_integral_code(ir, prefix, parameters):
    "Generate code for integral from intermediate representation."

    # Prefetch formatting to speedup code generation (well...)
    ret = format["return"]

    # Generate code
    code = initialize_integral_code(ir, prefix, parameters)
    code["num_cells"] = indent(ret(ir["num_cells"]), 4)
    code["tabulate_tensor"] = indent(_tabulate_tensor(ir, prefix, parameters), 4)
    code["additional_includes_set"] = ir["additional_includes_set"]

    precision = ir["integrals_metadata"].get("precision")
    if precision is not None and precision != parameters["precision"]:
        warning("Ignoring precision in integral metadata compiled "
                "using quadrature representation. Not implemented.")

    return code
Example #9
0
def generate_integral_code(ir, prefix, parameters):
    "Generate code for integral from intermediate representation."

    # Prefetch formatting to speedup code generation (well...)
    ret = format["return"]

    # Generate code
    code = initialize_integral_code(ir, prefix, parameters)
    code["num_cells"] = indent(ret(ir["num_cells"]), 4)
    code["tabulate_tensor"] = indent(_tabulate_tensor(ir, prefix, parameters),
                                     4)
    code["additional_includes_set"] = ir["additional_includes_set"]

    precision = ir["integrals_metadata"].get("precision")
    if precision is not None and precision != parameters["precision"]:
        warning("Ignoring precision in integral metadata compiled "
                "using quadrature representation. Not implemented.")

    return code
Example #10
0
def generate_integral_code(ir, prefix, parameters):
    "Generate code for integral from intermediate representation."

    info("Generating code from uflacs representation")

    # Generate generic ffc code snippets
    code = initialize_integral_code(ir, prefix, parameters)

    # Generate tabulate_tensor body using uflacs algorithms
    uflacs_code = generate_tabulate_tensor_code(ir, parameters)

    code["tabulate_tensor"] = uflacs_code["tabulate_tensor"]

    code["additional_includes_set"] = set()
    code["additional_includes_set"].update(
        ir.get("additional_includes_set", ()))
    code["additional_includes_set"].update(
        uflacs_code["additional_includes_set"])

    return code
Example #11
0
def generate_integral_code(ir, prefix, parameters):
    "Generate code for integral from intermediate representation."

    info("Generating code from tsfc representation")

    # Generate generic ffc code snippets
    code = initialize_integral_code(ir, prefix, parameters)

    # Go unoptimized if TSFC mode has not been set yet
    integral_data, form_data, prefix, parameters = ir["compile_integral"]
    parameters = parameters.copy()
    parameters.setdefault("mode", "vanilla")

    # Generate tabulate_tensor body
    ast = compile_integral(integral_data,
                           form_data,
                           None,
                           parameters,
                           interface=ufc_interface)

    # COFFEE vectorize
    knl = ASTKernel(ast)
    knl.plan_cpu(dict(optlevel='Ov'))

    tsfc_code = "".join(b.gencode() for b in ast.body)
    tsfc_code = tsfc_code.replace("#pragma coffee",
                                  "//#pragma coffee")  # FIXME
    code["tabulate_tensor"] = tsfc_code

    includes = set()
    includes.update(ir.get("additional_includes_set", ()))
    includes.update(ast.headers)
    includes.add("#include <cstring>")  # memset
    if any(
            node.funcall.symbol.startswith("boost::math::")
            for node in Find(coffee.FunCall).visit(ast)[coffee.FunCall]):
        includes.add("#include <boost/math/special_functions.hpp>")
    code["additional_includes_set"] = includes

    return code
Example #12
0
def generate_integral_code(ir, prefix, parameters):
    "Generate code for integral from intermediate representation."

    info("Generating code from uflacs representation")

    # Generate generic ffc code snippets
    code = initialize_integral_code(ir, prefix, parameters)

    # Generate tabulate_tensor body using uflacs algorithms
    uflacs_code = generate_tabulate_tensor_code(ir, prefix, parameters)

    code["tabulate_tensor"] = uflacs_code["tabulate_tensor"]

    # TODO: Use code generation utils here for consistency
    if ir.get("num_cells") is not None:
        code["num_cells"] = "  return %d;" % (ir["num_cells"],)

    code["additional_includes_set"] = set()
    code["additional_includes_set"].update(ir.get("additional_includes_set",()))
    code["additional_includes_set"].update(uflacs_code["additional_includes_set"])

    return code
Example #13
0
def generate_integral_code(ir, prefix, parameters):
    "Generate code for integral from intermediate representation."

    info("Generating code from uflacs representation")

    # Generate generic ffc code snippets
    code = initialize_integral_code(ir, prefix, parameters)

    # Generate tabulate_tensor body using uflacs algorithms
    uflacs_code = generate_tabulate_tensor_code(ir, prefix, parameters)

    code["tabulate_tensor"] = uflacs_code["tabulate_tensor"]

    # TODO: Use code generation utils here for consistency
    if ir.get("num_cells") is not None:
        code["num_cells"] = "  return %d;" % (ir["num_cells"], )

    code["additional_includes_set"] = set()
    code["additional_includes_set"].update(
        ir.get("additional_includes_set", ()))
    code["additional_includes_set"].update(
        uflacs_code["additional_includes_set"])

    return code
Example #14
0
def generate_integral_code(ir, prefix, parameters):
    "Generate code for integral from intermediate representation."
    code = initialize_integral_code(ir, prefix, parameters)
    code["tabulate_tensor"] = _tabulate_tensor(ir, parameters)
    return code
def generate_integral_code(ir, prefix, parameters):
    "Generate code for integral from intermediate representation."
    code = initialize_integral_code(ir, prefix, parameters)
    code["tabulate_tensor"] = _tabulate_tensor(ir, parameters)
    return code