Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions dace/codegen/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ def __init__(self, sdfg, lib: ReloadableDLL):
self._exit = lib.get_symbol('__dace_exit')
self._cfunc = lib.get_symbol('__program_{}'.format(sdfg.name))

@property
def filename(self):
return self._lib._library_filename

@property
def sdfg(self):
return self._sdfg
Expand Down
17 changes: 13 additions & 4 deletions dace/sdfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pickle, json
from pydoc import locate
import random
import shutil
import sys
from typing import Any, Dict, Set, Tuple, List, Union
import warnings
Expand Down Expand Up @@ -1528,7 +1529,7 @@ def specialize(self, additional_symbols=None, specialize_all_symbols=True):
# Update constants
self.constants_prop.update(syms)

def compile(self, specialize=None, optimizer=None):
def compile(self, specialize=None, optimizer=None, output_file=None):
""" Compiles a runnable binary from this SDFG.

@param specialize: If True, specializes all symbols to their
Expand All @@ -1537,6 +1538,8 @@ def compile(self, specialize=None, optimizer=None):
@param optimizer: If defines a valid class name, it will be called
during compilation to transform the SDFG as
necessary. If None, uses configuration setting.
@param output_file: If not None, copies the output library file to
the specified path.
@return: A callable CompiledSDFG object.
"""

Expand Down Expand Up @@ -1587,6 +1590,12 @@ def compile(self, specialize=None, optimizer=None):
# Compile the code and get the shared library path
shared_library = compiler.configure_and_compile(program_folder)

# If provided, save output to path or filename
if output_file is not None:
if os.path.isdir(output_file):
output_file = os.path.join(output_file, os.path.basename(shared_library))
shutil.copyfile(shared_library, output_file)

# Get the function handle
return compiler.get_program_handle(shared_library, sdfg)

Expand Down Expand Up @@ -4012,16 +4021,16 @@ def local_transients(sdfg, dfg, entry_node):
return transients


def compile(function_or_sdfg, *args, specialize=None):
def compile(function_or_sdfg, *args, **kwargs):
""" Obtain a runnable binary from a Python (@dace.program) function. """
if isinstance(function_or_sdfg, dace.frontend.python.parser.DaceProgram):
sdfg = dace.frontend.python.parser.parse_from_function(
function_or_sdfg, *args)
function_or_sdfg, *args, **kwargs)
elif isinstance(function_or_sdfg, SDFG):
sdfg = function_or_sdfg
else:
raise TypeError("Unsupported function type")
return sdfg.compile(specialize=specialize)
return sdfg.compile(**kwargs)


def is_devicelevel(sdfg: SDFG, state: SDFGState, node: dace.graph.nodes.Node):
Expand Down