Skip to content

Commit 71328ae

Browse files
program_mapper: add support for muli
1 parent 88ac3cc commit 71328ae

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

p-isa_tools/program_mapper/p_isa/pisakernel.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,24 @@ inline std::string genKernInput(const pisa::poly::PolyOperation &op)
6262
<< " " << inputs[i].num_of_polynomials << "\n";
6363
}
6464

65+
// For muli operations, add the immediate value as an additional DATA input
66+
bool has_immediate = false;
67+
if (op.Name() == "muli")
68+
{
69+
// Check if we have an operand parameter (immediate value)
70+
try
71+
{
72+
op.getParam("operand");
73+
// Add immediate value as input1 with 1 polynomial (scalar)
74+
input << "DATA input" << op.numInputOperands() << " 1\n";
75+
has_immediate = true;
76+
}
77+
catch (...)
78+
{
79+
// No operand parameter, treat as regular operation
80+
}
81+
}
82+
6583
// OP
6684
input << std::uppercase << op.Name() << std::nouppercase;
6785
for (int i = 0; i < op.numOutputOperands(); ++i)
@@ -74,6 +92,11 @@ inline std::string genKernInput(const pisa::poly::PolyOperation &op)
7492
input << " "
7593
<< "input" << i /*inputs[i].register_name*/;
7694
}
95+
// For muli, add the immediate as the second input
96+
if (has_immediate)
97+
{
98+
input << " input" << op.numInputOperands();
99+
}
77100

78101
return input.str();
79102
}

p-isa_tools/program_mapper/poly_program/operations/core.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ static const PolyOperationDesc Sub("sub", { OP_NAME, FHE_SCHEME, POLYMOD_DEG_LOG
4040
* */
4141
static const PolyOperationDesc Mul("mul", { OP_NAME, FHE_SCHEME, POLYMOD_DEG_LOG2, KEY_RNS, OUTPUT_ARGUMENT, INPUT_ARGUMENT, INPUT_ARGUMENT });
4242

43+
/** \brief PolyOperation multiply immediate (scalar multiplication) PolyOperationDesc
44+
* Op name: muli
45+
* | Param | description |
46+
* | ----- | ----------- |
47+
* | FHE_SCHEME | specifies the FHE_SCHEME of the poly operation |
48+
* | POLYMOD_DEG_LOG2 | Specifies the modulus degree of the input polynomials |
49+
* | KEY_RNS | Specifies number of RNS key values |
50+
* | OUTPUT_ARGUMENT | Destination ciphertext |
51+
* | INPUT_ARGUMENT | Input ciphertext label |
52+
* | PARAM | Immediate/scalar value |
53+
* */
54+
static const PolyOperationDesc Muli("muli", { OP_NAME, FHE_SCHEME, POLYMOD_DEG_LOG2, KEY_RNS, OUTPUT_ARGUMENT, INPUT_ARGUMENT, PARAM });
55+
4356
/** \brief PolyOperation Square PolyOperationDesc
4457
* Adds two polynomials with specified specified polymodulus degree, RNS terms, and polynomial parts and writes the result to the specified output.
4558
* | Param | description |

p-isa_tools/program_mapper/poly_program/poly_operation_library.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ static std::map<std::string, PolyOperationDesc> core_operation_library = {
1313
{ "sub", library::core::Sub },
1414
{ "mul", library::core::Mul },
1515
{ "mul_plain", library::core::Mul },
16+
{ "muli", library::core::Muli }, // Multiply immediate (scalar multiplication)
1617
{ "square", library::core::Square },
1718
{ "ntt", library::core::Ntt },
1819
{ "intt", library::core::Intt },

p-isa_tools/program_mapper/poly_program/polyprogram.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ void PolyOperation::setComponents(const heracles::fhe_trace::Instruction &instr_
209209
setGaloisElt(stoi(v.value()));
210210
if (k == "factor")
211211
setFactor(stoi(v.value()));
212+
if (k == "operand")
213+
// For muli operations, the operand is the immediate scalar value
214+
// Store it as a parameter that will be used when generating the kernel
215+
setParam({ k, { v.value(), ValueType::DOUBLE } });
212216
}
213217
}
214218
heracles::fhe_trace::Instruction *PolyOperation::getProtobuffFHETraceInstruction()

0 commit comments

Comments
 (0)