Sitelet https://web.archive.org/web/20250305094849/https://github.com/numba/numba/issues/7179
Skip to content

Support jit decorator flags in cc.export (e.g. fastmath)  #7179

Open
@gmarkall

Description

From #5664:

Adding the possibility of using @njit flags in @cc.export would be great! Is it possible?

and:

I have managed to add the 'fastmath' flag to the ExportEntry object:

class ExportEntry(object):
    """
    A simple record for exporting symbols.
    """

    def __init__(self, symbol, signature, function, fastmath=False):
        self.symbol = symbol
        self.signature = signature
        self.function = function
        self.fastmath = fastmath

Then, the _cull_exports methodof the _ModuleCompiler object shall me modified with the following code:

for entry in self.export_entries:
            flags_aux = flags.copy()
            if entry.fastmath:
                flags_aux.set('fastmath', value=cpu.FastMathOptions(True))

            cres = compile_extra(self.typing_context, self.context,
                                 entry.function,
                                 entry.signature.args,
                                 entry.signature.return_type, flags_aux,
                                 locals={}, library=library)

With this modifications, I am able to use the @cc.export decorator like this:

@cc.export('foo', 'float64(float64[::1], float64[::1])', fastmath=True)

And it is working for me right now. I guess this code may be improved, but this simple patch works, so I would expect that 'fastmath' and 'parallel' flags could be added to @cc.export in an "official" way.

The above could be worked up into a patch with tests added to complete the feature imp[lementation.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    AOTahead of time compilation issuefeature_requestgood first issueA good issue for a first time contributor

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions