mirror of
https://github.com/zama-ai/tfhe-rs.git
synced 2026-01-06 21:34:05 -05:00
This backend abstract communication with Hpu Fpga hardware.
It define it's proper entities to prevent circular dependencies with
tfhe-rs.
Object lifetime is handle through Arc<Mutex<T>> wrapper, and enforce
that all objects currently alive in Hpu Hw are also kept valid on the
host side.
It contains the second version of HPU instruction set (HIS_V2.0):
* DOp have following properties:
+ Template as first class citizen
+ Support of Immediate template
+ Direct parser and conversion between Asm/Hex
+ Replace deku (and it's associated endianess limitation) by
+ bitfield_struct and manual parsing
* IOp have following properties:
+ Support various number of Destination
+ Support various number of Sources
+ Support various number of Immediat values
+ Support of multiple bitwidth (Not implemented yet in the Fpga
firmware)
Details could be view in `backends/tfhe-hpu-backend/Readme.md`
111 lines
2.6 KiB
Python
111 lines
2.6 KiB
Python
from . import analysis
|
|
|
|
class BaseInstruction:
|
|
def __init__(self, data):
|
|
self.data = data
|
|
|
|
def args(self):
|
|
return str(self.data)
|
|
|
|
def __str__(self):
|
|
return f'{self.__class__.__name__} {self.args()}'
|
|
|
|
class NamedInstruction:
|
|
def __init__(self, name, args):
|
|
self.name = name
|
|
self._args = args
|
|
def args(self):
|
|
return self._args
|
|
def __str__(self):
|
|
return f'{self.name} {self.args()}'
|
|
|
|
class PBS(BaseInstruction):
|
|
def __init__(self, d):
|
|
self.__dict__ = d
|
|
|
|
def args(self):
|
|
return f'R{self.dst_rid} R{self.src_rid} @{self.gid}'
|
|
|
|
class LD(BaseInstruction):
|
|
def __init__(self, d):
|
|
self.__dict__ = d
|
|
|
|
def args(self):
|
|
return f'R{self.rid} @{hex(self.slot["Addr"])}'
|
|
|
|
class ST(BaseInstruction):
|
|
def __init__(self, d):
|
|
self.__dict__ = d
|
|
|
|
def args(self):
|
|
return f'@{hex(self.slot["Addr"])} R{self.rid}'
|
|
|
|
class MAC(BaseInstruction):
|
|
def __init__(self, d):
|
|
self.__dict__ = d
|
|
|
|
def args(self):
|
|
return f'R{self.dst_rid} R{self.src0_rid} ' +\
|
|
f'R{self.src1_rid} X{self.mul_factor} '
|
|
|
|
class ADD(BaseInstruction):
|
|
def __init__(self, d):
|
|
self.__dict__ = d
|
|
|
|
def args(self):
|
|
return f'R{self.dst_rid} R{self.src0_rid} R{self.src1_rid}'
|
|
|
|
class ADDS(BaseInstruction):
|
|
def __init__(self, d):
|
|
self.__dict__ = d
|
|
|
|
def args(self):
|
|
return f'R{self.dst_rid} R{self.src_rid} {self.msg_cst["Cst"]}'
|
|
|
|
class SUB(BaseInstruction):
|
|
def __init__(self, d):
|
|
self.__dict__ = d
|
|
|
|
def args(self):
|
|
return f'R{self.dst_rid} R{self.src0_rid} R{self.src1_rid}'
|
|
|
|
class SSUB(BaseInstruction):
|
|
def __init__(self, d):
|
|
self.__dict__ = d
|
|
|
|
def args(self):
|
|
return f'R{self.dst_rid} {self.msg_cst["Cst"]} R{self.src_rid}'
|
|
|
|
class SUBS(BaseInstruction):
|
|
def __init__(self, d):
|
|
self.__dict__ = d
|
|
|
|
def args(self):
|
|
return f'R{self.dst_rid} R{self.src_rid} {self.msg_cst["Cst"]}'
|
|
|
|
class SYNC(BaseInstruction):
|
|
def __init__(self, d):
|
|
self.__dict__ = d
|
|
|
|
def args(self):
|
|
return f"{self.sid}"
|
|
|
|
PBS_ML2 = PBS
|
|
PBS_ML4 = PBS
|
|
PBS_ML8 = PBS
|
|
PBS_F = PBS
|
|
PBS_ML2_F = PBS
|
|
PBS_ML4_F = PBS
|
|
PBS_ML8_F = PBS
|
|
MULS = ADDS
|
|
SUBS = ADDS
|
|
|
|
class Insn:
|
|
def __init__(self, insn):
|
|
self.opcode, data = next(iter(insn.items()))
|
|
self.data = globals()[self.opcode](data) if self.opcode in globals() \
|
|
else NamedInstruction(self.opcode, data)
|
|
|
|
def to_analysis(self):
|
|
return analysis.Instruction(self.opcode, self.data.args())
|