Skip to content

Commit

Permalink
[FixBug] Don't instantiate symbol for primitive functions (#291)
Browse files Browse the repository at this point in the history
Previously, if a primitive function calls a primitive function, the
`instantiate_symbols` pass will update the corresponding
`hidet.ir.primitives.func.PrimitiveFunctionRegistry.function` in-place
(I am not sure exactly how it's done, but this is what I observed),
adding symbol variables to its parameters. The primitive function pool
is a global variable, therefore this effect is cumulative across tuning
candidates. So while candidate 0 will have no problem, candidate 1 will
have two extra copies of symbol params, and so on, leading to compile
errors.

Since primitive functions do not need symbol vars, a quick fix is just
to not instantiate any symbols for them.
  • Loading branch information
hjjq committed Jun 26, 2023
1 parent 64b9f03 commit f3aad89
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions python/hidet/transforms/instantiate_symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from hidet.ir.func import Function
from hidet.ir.module import IRModule
from hidet.ir.functors import IRRewriter
from hidet.ir.primitives import is_primitive_function
from hidet.ir.primitives.runtime import get_symbol_value
from hidet.ir.stmt import LetStmt, LaunchKernelStmt
from hidet.ir.tools import collect
Expand Down Expand Up @@ -59,6 +60,9 @@ def visit_Function(self, func: Function):
else:
assert False

if is_primitive_function(func.name):
return func

ordered_symbols: List[SymbolVar] = list(symbols)
symbol_params: List[Var] = [Var(symbol.name, symbol.type) for symbol in ordered_symbols]
self.func_symbols[func.name] = FuncSymbols(
Expand Down

0 comments on commit f3aad89

Please sign in to comment.