of either integers of higher bit capacity or float-point
arithmetic to renorm weights after forward pass layer
calculations, which will introduce additional delays
into the inference latency for a low-bit CPU. The lim-
itations inherent in calculations on numbers repre-
sented in the positional number system can be over-
come by using calculations on numbers represented
in the RNS.
2.1 Unsigned RNS Fundamentals
The limitations inherent in calculations on numbers
represented in the positional number system can be
overcome by using calculations on numbers repre-
sented in the RNS. Let us show the basic operations in
RNS based arithmetic on a simple example with two
coprime moduli-set:
p1 = 3 and p2 = 7
with such a choice of the moduli-set the range of rep-
resentable numbers will be [0..3·7−1).
Let’s take the number 17 and convert it to RNS
(hereinafter, % is the operation of taking the remain-
der modulo):
17 = (17%3; 17%7) = (2; 3)
This method requires repeated use of the opera-
tion of obtaining the remainder of an integer division.
There is another way to quickly convert from a po-
sitional number system, such as decimal, hexadeci-
mal or binary, which is based on the basic property of
RNS: performing operations on the bases in parallel
and independently.
For example, consider the conversion from the
decimal system to RNS:
17 = 1 ∗101+ 7 ∗100
Knowing the representation of all powers of 10,
in the range allowed for RNS:
100= (1; 1), because 1%3 = 1 and 1%7 = 1
101= (1; 3), because 10%3 = 1 and 10%7 = 3
Also, knowing the representation of each digit of
the number in RNS:
1 = (1%3; 1%7) = (1; 1)
7 = (7%3; 7%7) = (1; 0)
We get the following representation of the transla-
tion operation:
17 = 1∗101+7∗100= (1; 1)∗(1; 3)+(1; 0)∗(1; 1) =
(1; 3) + (1; 0) = (2; 3)
2.2 Signed RNS Fundamentals
In the process of calculating the layers of a neural net-
work, we need to be able to represent both positive
and negative weights in the RNS. There are several
approaches to solving this problem, let’s look at rep-
resenting numbers with a range shift (an socalled arti-
ficial number form), where both negative and positive
numbers are mapped to positive numbers.
As an example, we can extend our example with
the radix p3=2, and use a range-shifted represen-
tation of numbers, in which numbers in the range
[0..p1·p2) represent negative numbers, and numbers
in the range [p1∗p2..p1∗p2∗p3) are positive.
Then the form of representation of the number N
with offset: N0=p1∗p2 + N
N0=p1∗p2−N
The operations of addition and subtraction in this
case can be derived as:
let N10=p1∗p2 + N1and N20=p1∗p2 + N2
then N10+N20=p1∗p2 + N1 + p1∗p2 + N2
considering that (N1 + N2)0=N1 + N2 + p1∗p2
we get (N1 + N2)0=N10+N20−p1∗p2
Taking into account that p1∗p2is (0; 0; 1) in RNS
with p3 = 2 added to moduli-sets,
we get (N1 + N2)0=N10+N20−p1∗p2 =
(N1 + N2)0=N10+N20+p1∗p2
You can also notice that getting from the number
N
numbers −
N
perhaps by subtracting it from the
number (p1; p2; 1).
Consideration of the multiplication operation
requires similar reasoning:
N10∗N20=N1∗N2 + p1∗p2∗N1 + p1∗p2∗
N2 + p1∗p2∗p1∗p2
those
(N1∗N2)0=N10∗N20+p1∗p2−p1∗p2∗(N1 +
N2 + p1∗p2)
considering that p1∗p2is (0; 0; 1) in the RNS with
p3=2added, and that during the operation the
numbers will be given in prime form, we get
(N1∗N2)0=N10∗N20+p1∗p2∗(1 + p1∗p2 +
N10+N20)
since p1∗p2is an odd number, we get
(N1∗N2)0=N10∗N20+p1∗p2∗(N10+N20)
Note that if N10and N20have the same parity, then
p1∗p2∗(N10+N20)is (0; 0; 0)
And if their parity is different, then
p1∗p2∗(N10+N20)is (0; 0; 1), i.e. p1∗p2.
Also, for RNS it is quite simple, using pre-
calculated auxiliary bit vectors, to implement the op-
erations of checking the sign of a number and dividing
by the bases of the system, which is sufficient both to
implement the ReLU operation and to implement ap-
proximate dequantization after matrix operations.
More general comparison or division operations in
RNS are also feasible, but require storage or calcu-
lation of additional parameters required for such op-
erations. Because These operations are not used to
implement the basic functions of the RNS inference
WSEAS TRANSACTIONS on COMPUTERS
DOI: 10.37394/23205.2023.22.33