Skip to content
Snippets Groups Projects

Add `pystencils.make_python_function` used for KernelFunction.compile

Closed Stephan Seitz requested to merge seitz/pystencils:make_python_function into master

KernelFunction.compile = None is currently set by the create_kernel function of each respective backend as partial function of <backend>.make_python_function.

The code would be clearer with a unified make_python_function. KernelFunction.compile can then be implemented as a call to this function with the respective backend.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Stephan Seitz added 1 commit

    added 1 commit

    • 24222c87 - Add `pystencils.make_python_function` used for KernelFunction.compile

    Compare with previous version

  • Stephan Seitz added 5 commits

    added 5 commits

    • 24222c87...9b9a4b54 - 4 commits from branch pycodegen:master
    • 229e3950 - Add `pystencils.make_python_function` used for KernelFunction.compile

    Compare with previous version

  • Stephan Seitz added 1 commit

    added 1 commit

    • cef0089c - Add `pystencils.make_python_function` used for KernelFunction.compile

    Compare with previous version

  • Stephan Seitz added 1 commit

    added 1 commit

    • 0a9b03b8 - Fix llvm by manually setting backend in KernelFunction

    Compare with previous version

  • Stephan Seitz added 1 commit

    added 1 commit

    • 64c0fb22 - Fix llvm by manually setting backend in KernelFunction

    Compare with previous version

  • Stephan Seitz added 1 commit

    added 1 commit

    • 34509925 - Fix llvm by manually setting backend in KernelFunction

    Compare with previous version

  • Author Maintainer

    Maybe we want to add a llvm test that's not a Jupyter Notebook:

    # -*- coding: utf-8 -*-
    #
    # Copyright © 2019 Stephan Seitz <stephan.seitz@fau.de>
    #
    # Distributed under terms of the GPLv3 license.
    
    """
    
    """
    import llvmlite
    
    from pystencils.session import *
    
    
    def test_llvm():
        size = (60, 70)  # domain size
    
        u_arrays = [np.zeros(size), np.zeros(size), np.zeros(size)]
    
        u_fields = [ps.Field.create_from_numpy_array("u%s" % (name,), arr)
                    for name, arr in zip(["0", "1", "2"], u_arrays)]
    
        for i, field in enumerate(u_fields):
            field.latex_name = "u^{(%d)}" % (i,)
    
        discretize = ps.fd.Discretization2ndOrder()
    
        def central2nd_time_derivative(fields):
            f_next, f_current, f_last = fields
            return (f_next[0, 0] - 2 * f_current[0, 0] + f_last[0, 0]) / discretize.dt**2
    
        rhs = ps.fd.diffusion(u_fields[1], 1)
    
        wave_eq = sp.Eq(central2nd_time_derivative(u_fields), discretize(rhs))
    
        wave_eq = sp.simplify(wave_eq)
        u_next_C = u_fields[-1][0, 0]
        update_rule = ps.Assignment(u_next_C, sp.solve(wave_eq, u_next_C)[0])
        update_rule
    
        update_rule = update_rule.subs({discretize.dx: 0.1, discretize.dt: 0.05})
    
        kernel = ps.create_kernel(update_rule, target='llvm')
        kernel.compile()
    
        def run_LLVM(timesteps=1):
            for t in range(timesteps):
                kernel(u0=u_arrays[0], u1=u_arrays[1], u2=u_arrays[2])
                u_arrays[0], u_arrays[1], u_arrays[2] = u_arrays[1], u_arrays[2], u_arrays[0]
            return u_arrays[2]
        print('Yeah. LLVM does something without crashing')
    
    
    def main():
        test_llvm()
    
    
    if __name__ == '__main__':
        main()
  • Stephan Seitz added 10 commits

    added 10 commits

    • 34509925...305107fa - 8 commits from branch pycodegen:master
    • a7e61dc4 - Add `pystencils.make_python_function` used for KernelFunction.compile
    • c15b21cc - Fix llvm by manually setting backend in KernelFunction

    Compare with previous version

  • I think this change resolved this pull request. Can I close it?

  • closed

Please register or sign in to reply