Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
32e984d
Modified default manifest to use MOD_SWITCH key instead of MOD. The f…
christopherngutierrez Jul 24, 2024
16c58b5
Added core functionality for rescale ckks. Currently not tested
christopherngutierrez Jul 24, 2024
28f5c04
Modified default manifest to use MOD_SWITCH key instead of MOD. The f…
christopherngutierrez Jul 24, 2024
954ee29
Added core functionality for rescale ckks. Currently not tested
christopherngutierrez Jul 24, 2024
218cf3f
modified manifest to include rescale
christopherngutierrez Sep 19, 2024
2b1cc97
merged manifest
christopherngutierrez Sep 26, 2024
2e51ccc
initial working version of rescale. Confirmed working for 16-128K pol…
christopherngutierrez Oct 3, 2024
fcaa364
Added core functionality for rescale ckks. Currently not tested
christopherngutierrez Jul 24, 2024
214d4de
modified manifest to include rescale
christopherngutierrez Sep 19, 2024
f7b169b
Modified default manifest to use MOD_SWITCH key instead of MOD. The f…
christopherngutierrez Jul 24, 2024
a410065
Added core functionality for rescale ckks. Currently not tested
christopherngutierrez Jul 24, 2024
a4b1dcd
initial working version of rescale. Confirmed working for 16-128K pol…
christopherngutierrez Oct 3, 2024
9b77cee
merged manifest
christopherngutierrez Oct 3, 2024
46ea5d0
Merge branch 'main' into christopherngutierrez/rescale
faberga Oct 8, 2024
a0b2fa6
Added 'partial ops' helper funcitons
christopherngutierrez Oct 9, 2024
32d60fa
Merge branch 'christopherngutierrez/rescale' of github.com:IntelLabs/…
christopherngutierrez Oct 9, 2024
5944619
Removed some duplicated code between mod and rescale. Added two helpe…
christopherngutierrez Oct 11, 2024
272333f
Created a new helper method to generate commonly used immediates
christopherngutierrez Oct 11, 2024
d96463f
moved partial_op to sep file and refactored code
christopherngutierrez Oct 12, 2024
7256dc7
Merge branch 'main' into christopherngutierrez/rescale
faberga Oct 17, 2024
dc5776c
Modified default manifest to use MOD_SWITCH key instead of MOD. The f…
christopherngutierrez Jul 24, 2024
d7485c0
Merge branch 'christopherngutierrez/rescale' of github.com:IntelLabs/…
christopherngutierrez Oct 18, 2024
7d15bd3
Modified default manifest to use MOD_SWITCH key instead of MOD. The f…
christopherngutierrez Jul 24, 2024
a0bf892
Merge branch 'christopherngutierrez/rescale' of github.com:IntelLabs/…
christopherngutierrez Oct 18, 2024
1926ae2
Merge branch 'christopherngutierrez/rescale' of github.com:IntelLabs/…
christopherngutierrez Oct 18, 2024
104882d
Merge branch 'christopherngutierrez/rescale' of github.com:IntelLabs/…
christopherngutierrez Oct 21, 2024
fff9f92
Modified default manifest to use MOD_SWITCH key instead of MOD. The f…
christopherngutierrez Jul 24, 2024
52dc7ca
Modified default manifest to use MOD_SWITCH key instead of MOD. The f…
christopherngutierrez Jul 24, 2024
a5dec3c
Documentation update (#21)
faberga Jul 26, 2024
86f4f3a
Create scorecard.yml (#22)
michaelbeale-IL Jul 26, 2024
b1dc68b
Ossf scorecard updates (#24)
michaelbeale-IL Jul 26, 2024
6b0a9fb
Update README.md (#25)
michaelbeale-IL Jul 29, 2024
1bab0e5
Create dependabot.yml (#26)
michaelbeale-IL Jul 29, 2024
543da02
Update .pylintrc (#32)
faberga Jul 30, 2024
7c34ba0
Dependabot auto update limits (#33)
michaelbeale-IL Jul 30, 2024
67ffb6a
Limit dependabot updates (#35)
michaelbeale-IL Jul 30, 2024
30ceb6a
Update pytest requirement from ~=8.1 to ~=8.3 in /kerngen (#29)
dependabot[bot] Jul 30, 2024
cc1c580
Update pylint requirement from ~=3.1 to ~=3.2 in /kerngen (#28)
dependabot[bot] Jul 30, 2024
98211f7
Update black requirement from ~=24.3 to ~=24.4 in /kerngen (#27)
dependabot[bot] Jul 30, 2024
75199ad
Add Open Source Security Foundation (OpenSSF) best practices badge (#36)
faberga Jul 31, 2024
e40b514
Documentation updates (#31)
faberga Aug 16, 2024
e646786
Update black requirement from ~=24.4 to ~=24.8 in /kerngen (#38)
dependabot[bot] Aug 20, 2024
d826851
Christopherngutierrez/test context parse results (#37)
christopherngutierrez Aug 20, 2024
937c548
Update kerngen README.md (#39)
faberga Aug 22, 2024
e803922
Kernel Language examples + Experimental VS Code Extension (#40)
faberga Aug 27, 2024
f6a6f11
Bug fix in the RELIN kernel generator to use the correct named input0…
faberga Aug 27, 2024
93c5575
Update CODEOWNERS (#42)
faberga Aug 27, 2024
8739d69
BGV Relin Bug Fixes (#43)
christopherngutierrez Sep 18, 2024
ec7b551
Enhancements to the NTT/INTT kernel to support support generic power…
christopherngutierrez Sep 18, 2024
b85e1d4
Move common functionality to basic.py and DigitDecompExtend to decomp…
christopherngutierrez Sep 20, 2024
678b41b
Fix NTT issue on odd-numbered butterfly stages
christopherngutierrez Sep 26, 2024
c90ce59
Tests for invalid poly order
christopherngutierrez Sep 26, 2024
f23802d
BGV Rotate Kernel (#48)
christopherngutierrez Sep 27, 2024
07be553
Update pylint requirement from ~=3.2 to ~=3.3 in /kerngen (#49)
dependabot[bot] Oct 1, 2024
558db6a
Added core functionality for rescale ckks. Currently not tested
christopherngutierrez Jul 24, 2024
eea3924
modified manifest to include rescale
christopherngutierrez Sep 19, 2024
cd4a73e
Modified default manifest to use MOD_SWITCH key instead of MOD. The f…
christopherngutierrez Jul 24, 2024
bf1d082
Added core functionality for rescale ckks. Currently not tested
christopherngutierrez Jul 24, 2024
12a9084
initial working version of rescale. Confirmed working for 16-128K pol…
christopherngutierrez Oct 3, 2024
5399ddc
Added core functionality for rescale ckks. Currently not tested
christopherngutierrez Jul 24, 2024
7ad2fd6
initial working version of rescale. Confirmed working for 16-128K pol…
christopherngutierrez Oct 3, 2024
0a99abf
Added 'partial ops' helper funcitons
christopherngutierrez Oct 9, 2024
8dee2fa
Bug fix for NTT Kernel generating extra unnecessary P-ISA instructions.
christopherngutierrez Oct 8, 2024
21c8eae
Removed some duplicated code between mod and rescale. Added two helpe…
christopherngutierrez Oct 11, 2024
62b3fcc
Created a new helper method to generate commonly used immediates
christopherngutierrez Oct 11, 2024
a7fe038
moved partial_op to sep file and refactored code
christopherngutierrez Oct 12, 2024
87baf86
Update black requirement from ~=24.8 to ~=24.10 in /kerngen (#54)
dependabot[bot] Oct 17, 2024
ef1b48a
fixed a typo after merging
christopherngutierrez Oct 21, 2024
8c78c6a
Merge branch 'christopherngutierrez/rescale' of github.com:IntelLabs/…
christopherngutierrez Oct 21, 2024
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
23 changes: 23 additions & 0 deletions kerngen/pisa_generators/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,26 @@ def extract_last_part_polys(input0: Polys, rns: int) -> Tuple[Polys, Polys, Poly
upto_last_coeffs.start_parts = 0

return input_last_part, last_coeff, upto_last_coeffs


def split_last_rns_polys(input0: Polys) -> Tuple[Polys, Polys]:
"""Split and extract last RNS of input0"""
return Polys.from_polys(input0, mode="last_rns"), Polys.from_polys(
input0, mode="drop_last_rns"
)


def duplicate_polys(input0: Polys, name: str) -> Polys:
"""Creates a duplicate of input0 with new name"""
return Polys(name, input0.parts, input0.rns, input0.start_parts, input0.start_rns)


def common_immediates(
r2_rns=None, iq_rns=None
) -> Tuple[Immediate, Immediate, Immediate]:
"""Generate commonly used immediates"""
return (
Immediate(name="one"),
Immediate(name="R2", rns=r2_rns),
Immediate(name="iq", rns=iq_rns),
)
11 changes: 11 additions & 0 deletions kerngen/pisa_generators/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,16 @@
"ROTATE": ["Rotate", "rotate.py"]
},
"CKKS": {
"ADD": ["Add", "basic.py"],
"MUL": ["Mul", "basic.py"],
"MULI": ["Muli", "basic.py"],
"COPY": ["Copy", "basic.py"],
"SUB": ["Sub", "basic.py"],
"SQUARE": ["Square", "square.py"],
"NTT": ["NTT", "ntt.py"],
"INTT": ["INTT", "ntt.py"],
"MOD": ["Mod", "mod.py"],
"MODUP": ["Modup", "mod.py"],
"RESCALE": ["Rescale", "rescale.py"]
}
}
78 changes: 40 additions & 38 deletions kerngen/pisa_generators/mod.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

# Copyright (C) 2024 Intel Corporation

"""Module containing conversions or operations from isa to p-isa."""

from dataclasses import dataclass
from itertools import product

from high_parser.pisa_operations import PIsaOp, Comment, Muli as pisa_op_muli
from high_parser.pisa_operations import PIsaOp, Comment
from high_parser import KernelContext, Immediate, HighOp, Polys

from .basic import Add, Muli, mixed_to_pisa_ops
from .basic import (
Add,
Muli,
mixed_to_pisa_ops,
split_last_rns_polys,
duplicate_polys,
common_immediates,
)
from .ntt import INTT, NTT
from .partial_op import muli_last_half


@dataclass
Expand All @@ -22,27 +32,18 @@ class Mod(HighOp):

def to_pisa(self) -> list[PIsaOp]:
"""Return the p-isa code to perform an mod switch down"""
# Convenience and Immediates
context = self.context
# Immediates
last_q = self.input0.rns - 1
it = Immediate(name="it")
one = Immediate(name="one")
r2 = Immediate(name="R2", rns=last_q)
iq = Immediate(name="iq", rns=last_q)
t = Immediate(name="t", rns=last_q)
one, r2, iq = common_immediates(r2_rns=last_q, iq_rns=last_q)

# Drop down input rns
input_last_rns = Polys.from_polys(self.input0, mode="last_rns")
input_remaining_rns = Polys.from_polys(self.input0, mode="drop_last_rns")
input_last_rns, input_remaining_rns = split_last_rns_polys(self.input0)

# Temp.
y = Polys(
"y",
input_last_rns.parts,
input_last_rns.rns,
start_rns=input_last_rns.start_rns,
)
x = Polys("x", input_remaining_rns.parts, input_remaining_rns.rns)
temp_input_last_rns = duplicate_polys(input_last_rns, "y")
temp_input_remaining_rns = duplicate_polys(input_remaining_rns, "x")

# Compute the `delta_i = t * [-t^-1 * c_i] mod ql` where `i` are the parts
# The `one` acts as a select flag as whether or not R2 the Montgomery
Expand All @@ -51,30 +52,31 @@ def to_pisa(self) -> list[PIsaOp]:
[
Comment("Start of mod kernel"),
Comment("Compute the delta from last rns"),
INTT(context, y, input_last_rns),
Muli(context, y, y, it),
Muli(context, y, y, one),
INTT(self.context, temp_input_last_rns, input_last_rns),
Muli(self.context, temp_input_last_rns, temp_input_last_rns, it),
Muli(self.context, temp_input_last_rns, temp_input_last_rns, one),
Comment("Compute the remaining rns"),
# drop down to pisa ops to use correct rns q
[
pisa_op_muli(
self.context.label,
x(part, q, unit),
y(part, last_q, unit),
r2(part, q, unit),
q,
)
for part, q, unit in product(
range(input_remaining_rns.parts),
range(input_remaining_rns.rns),
range(context.units),
)
],
NTT(context, x, x),
Muli(context, x, x, t),
muli_last_half(
self.context,
temp_input_remaining_rns,
temp_input_last_rns,
r2,
input_remaining_rns,
last_q,
),
NTT(self.context, temp_input_remaining_rns, temp_input_remaining_rns),
Muli(
self.context, temp_input_remaining_rns, temp_input_remaining_rns, t
),
Comment("Add the delta correction to mod down polys"),
Add(context, x, x, input_remaining_rns),
Muli(context, self.output, x, iq),
Add(
self.context,
temp_input_remaining_rns,
temp_input_remaining_rns,
input_remaining_rns,
),
Muli(self.context, self.output, temp_input_remaining_rns, iq),
Comment("End of mod kernel"),
]
)
Expand Down
124 changes: 124 additions & 0 deletions kerngen/pisa_generators/partial_op.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

"""Module containing helper methods to support binary operations using partial polys (last RNS and/or last part)"""
from dataclasses import dataclass
from itertools import product

from high_parser import KernelContext, Polys

from high_parser.pisa_operations import Sub as pisa_op_sub
from high_parser.pisa_operations import Add as pisa_op_add
from high_parser.pisa_operations import Muli as pisa_op_muli

# pylint: disable=too-many-arguments
# pylint: disable=too-many-positional-arguments


@dataclass
class PartialOpOptions:
"""Optional arguments for partial_op helper function"""

output_last_q: bool = False
input0_last_q: bool = False
input1_last_q: bool = False
input1_first_part: bool = False
op_last_q: bool = False


@dataclass
class PartialOpPolys:
"""Polynomials used in partial ops"""

output: Polys
input0: Polys
input1: Polys
input_remaining_rns: Polys


def partial_op(
context: KernelContext,
op,
polys: PartialOpPolys,
options: PartialOpOptions,
last_q: int,
):
""" "A helper function to perform partial operation, such as add/sub on last half (input1) to all of input0"""
return [
op(
context.label,
polys.output(part, last_q if options.output_last_q else q, unit),
polys.input0(part, last_q if options.input0_last_q else q, unit),
polys.input1(
0 if options.input1_first_part else part,
last_q if options.input1_last_q else q,
unit,
),
last_q if options.op_last_q else q,
)
for part, q, unit in product(
range(polys.input_remaining_rns.parts),
range(polys.input_remaining_rns.rns),
range(context.units),
)
]


def add_last_half(
context: KernelContext,
output: Polys,
input0: Polys,
input1: Polys,
input_remaining_rns: Polys,
last_q: int,
):
"""Add input0 to input1 (first part)"""
return partial_op(
context,
pisa_op_add,
PartialOpPolys(output, input0, input1, input_remaining_rns),
PartialOpOptions(
output_last_q=True,
input0_last_q=True,
input1_last_q=True,
input1_first_part=True,
op_last_q=True,
),
last_q,
)


def sub_last_half(
context: KernelContext,
output: Polys,
input0: Polys,
input1: Polys,
input_remaining_rns: Polys,
last_q: int,
):
"""Subtract input1 (first part) with input0 (last RNS)"""
return partial_op(
context,
pisa_op_sub,
PartialOpPolys(output, input0, input1, input_remaining_rns),
PartialOpOptions(input0_last_q=True, input1_first_part=True),
last_q,
)


def muli_last_half(
context: KernelContext,
output: Polys,
input0: Polys,
input1: Polys,
input_remaining_rns: Polys,
last_q: int,
):
"""Muli input0/1 w/input0 last RNS"""
return partial_op(
context,
pisa_op_muli,
PartialOpPolys(output, input0, input1, input_remaining_rns),
PartialOpOptions(input0_last_q=True),
last_q,
)
89 changes: 89 additions & 0 deletions kerngen/pisa_generators/rescale.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

# Copyright (C) 2024 Intel Corporation

"""Module containing conversions or operations from isa to p-isa."""

from dataclasses import dataclass

from high_parser.pisa_operations import PIsaOp, Comment

from high_parser import KernelContext, HighOp, Polys
from .partial_op import add_last_half, sub_last_half

from .basic import (
Muli,
mixed_to_pisa_ops,
Sub,
split_last_rns_polys,
duplicate_polys,
common_immediates,
)
from .ntt import INTT, NTT


@dataclass
class Rescale(HighOp):
"""Class representing mod down operation"""

context: KernelContext
output: Polys
input0: Polys

def to_pisa(self) -> list[PIsaOp]:
"""Return the p-isa code to perform an mod switch down"""
# Immediates
last_q = self.input0.rns - 1
one, r2, iq = common_immediates(r2_rns=last_q, iq_rns=last_q)

q_last_half = Polys("qLastHalf", 1, self.input0.rns)
q_i_last_half = Polys("qiLastHalf", 1, rns=last_q)

# split input
input_last_rns, input_remaining_rns = split_last_rns_polys(self.input0)

# Create temp vars for input_last/remaining
temp_input_last_rns = duplicate_polys(input_last_rns, "y")
temp_input_remaining_rns = duplicate_polys(input_remaining_rns, "x")

# Compute the `delta_i = t * [-t^-1 * c_i] mod ql` where `i` are the parts
# The `one` acts as a select flag as whether or not R2 the Montgomery
# factor should be applied
return mixed_to_pisa_ops(
[
Comment("Start of Rescale kernel."),
INTT(self.context, temp_input_last_rns, input_last_rns),
Muli(self.context, temp_input_last_rns, temp_input_last_rns, one),
Comment("Add the last part of the input to y"),
add_last_half(
self.context,
temp_input_last_rns,
temp_input_last_rns,
q_last_half,
input_remaining_rns,
last_q,
),
Comment("Subtract q_i (last half/last rns) from y"),
sub_last_half(
self.context,
temp_input_remaining_rns,
temp_input_last_rns,
q_i_last_half,
input_remaining_rns,
last_q,
),
Muli(
self.context, temp_input_remaining_rns, temp_input_remaining_rns, r2
),
NTT(self.context, temp_input_remaining_rns, temp_input_remaining_rns),
Sub(
self.context,
temp_input_remaining_rns,
Polys.from_polys(self.input0, mode="drop_last_rns"),
temp_input_remaining_rns,
),
Muli(self.context, self.output, temp_input_remaining_rns, iq),
Comment("End of Rescale kernel."),
]
)
Loading