Skip to content

Commit 8d47958

Browse files
Bug Fix: Sub Kernel issue with input0/1 ordering. (#120)
Bug fix for Sub kernel. Issue: CartesianOp assumed commutative operations (a - b != b - a).
1 parent 4e07914 commit 8d47958

File tree

1 file changed

+6
-2
lines changed
  • p-isa_tools/kerngen/pisa_generators

1 file changed

+6
-2
lines changed

p-isa_tools/kerngen/pisa_generators/basic.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,18 @@ def to_pisa(self) -> list[PIsaOp]:
6868
# Not the same number of parts
6969
first, second = (self.input0, self.input1) if self.input0.parts < self.input1.parts else (self.input1, self.input0)
7070

71+
# Preserve the ordering of the inputs (output = input0 op input1) to avoid issues with non-commutative ops (e.g. sub)
72+
# For example input0 - input1 != input1 - input0
73+
order_preserved = first == self.input0
74+
7175
ls: list[PIsaOp] = []
7276
for unit, q in it.product(range(self.context.units), range(self.input0.start_rns, self.input0.rns)):
7377
ls.extend(
7478
self.op(
7579
self.context.label,
7680
self.output(part, q, unit),
77-
first(part, q, unit),
78-
second(0, q, unit),
81+
first(part, q, unit) if order_preserved else second(0, q, unit),
82+
second(0, q, unit) if order_preserved else first(part, q, unit),
7983
q,
8084
)
8185
for part in range(first.parts)

0 commit comments

Comments
 (0)