Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Runtime] Add src_path and source() members to CompiledFunction #139

Merged
merged 1 commit into from
Mar 22, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions python/hidet/backend/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,14 @@ def load_task_func(lib_path: str, task) -> CompiledFunction:
return CompiledFunction(name=task.name, packed_func=packed_func, lib_path=lib_path, src_path=src_path)


def load_lib_func(lib_path: str, func_name: str, func_type: FuncType) -> CompiledFunction:
def load_lib_func(
lib_path: str, func_name: str, func_type: FuncType, src_path: Optional[str] = None
) -> CompiledFunction:
try:
lib = SharedLibrary(lib_path)
except OSError as e:
print("Removed the file '{}'".format(lib_path))
os.remove(lib_path)
raise e
packed_func = PackedFunc(param_types=list(func_type.param_types), c_func_pointer=lib[func_name])
return CompiledFunction(name=func_name, packed_func=packed_func, lib_path=lib_path)
return CompiledFunction(name=func_name, packed_func=packed_func, lib_path=lib_path, src_path=src_path)
2 changes: 1 addition & 1 deletion python/hidet/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def build_ir_module(

if load:
# load function
return load_lib_func(lib_path, 'hidet_' + func_name, func_type=func_type)
return load_lib_func(lib_path, 'hidet_' + func_name, func_type=func_type, src_path=src_path)
else:
return lib_path, func_name, func_type

Expand Down
6 changes: 6 additions & 0 deletions python/hidet/runtime/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ def __call__(self, *args):
def profile(self, *args, warmup=1, number=1, repeat=10):
return self.packed_func.profile(*args, warmup=warmup, number=number, repeat=repeat)

def source(self) -> Optional[str]:
if self.src_path is None:
return None
with open(self.src_path, 'r') as f:
return f.read()


CompiledTaskKey = namedtuple('CompiledTaskKey', ['device', 'space', 'task_str'])

Expand Down