Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • pystencils pystencils
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 19
    • Issues 19
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 6
    • Merge requests 6
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • pycodegen
  • pystencilspystencils
  • Issues
  • #7
Closed
Open
Issue created Jul 15, 2019 by Stephan Seitz@seitzMaintainer

In compile_and_load C-code is generated twice

When I was reviewing my old code I saw that I placed a TODO here. generate_c is just called to generate the hash and then again for the real code (if not loaded from shared object on disk). Maybe the ast can be hashed directly instead (danger point: generate_c may have changed since last generation).

I remember that I directly hashed the assignments for generation of torch/tensorflow code. This had the disadvantage that I had to deactivate caching when developing/changing code affecting generate_c.

def compile_and_load(ast):
    cache_config = get_cache_config()
    # TODO: inefficient to generate_c just for hash? could reuse it
    code_hash_str = "mod_" + hashlib.sha256(generate_c(ast).encode()).hexdigest()
    code = ExtensionModuleCode(module_name=code_hash_str)
    code.add_function(ast, ast.function_name)

    if cache_config['object_cache'] is False:
        with TemporaryDirectory() as base_dir:
            lib_file = compile_module(code, code_hash_str, base_dir)
            result = load_kernel_from_file(code_hash_str, ast.function_name, lib_file)
    else:
        lib_file = compile_module(code, code_hash_str, base_dir=cache_config['object_cache'])
        result = load_kernel_from_file(code_hash_str, ast.function_name, lib_file)

    rtn = KernelWrapper(result, ast.get_parameters(), ast)
    rtn.code = code.code
    return rtn
Assignee
Assign to
Time tracking