# Fully parallel optical matrix-matrix multiplication

In recent years, with the rapid development of electro-optic modulators, optical computing has become a potential excellent candidate for various computing tasks. New structures and devices for optical computing are emerging one after another, but the computing method is still the optical vector-matrix multiplication method that was decades ago. Here, we propose a novel optical computing paradigm that can parallelly implement matrix-matrix multiplication operation, which can directly replace existing vector-matrix multiplication, greatly improving computational efficiency. This preprint presents theoretical analysis, and we will supplement experimental results and conclusions in the future.

## 1 Introduction

Matrix-matrix multiplication (MMM) is one of the core operations in computational and processing applications, widely used in signal processing, image processing, and deep learning. For its O ⁡ ( N 3 ) O(N^{3}) time complexity, MMM, which is composed of multiple vector-matrix multiplications (VMM), becomes the most time-consuming operation in various calculation task. Due to the low performance of early computer technology, light has emerged as one of the ideal medium for replacing digital computing due to its excellent characteristics of low latency and low power consumption. Since Dr. Goodman innovatively proposed the optical vector-matrix multiplications (OVMM) prototype [ 1 ] , many researchers have utilized methods such as time multiplexing, wavelength multiplexing, and light source multiplexing to achieve more effective OVMM [ 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] . In addition to free space, Dr. Reck proposed a computational architecture based on Mach-Zehnder interferometer, verifying the possibility of calculations based on planar waveguides [ 11 ] . However, with the rapid development of integrated circuits and silicon based chip technology, optical computing, which is difficult to reconstruct structures and cannot update data in real-time, has no advantages compared to digital computing. Therefore, the academic community has also paid more attention to the field of optical communication, resulting in the long-term stagnation of the development of optical computing.

In the 2010s, with the rise of technologies such as artificial intelligence and big data, massive MMM operations brought huge computational burden, and silicon based chips were unable to continue to meet computing needs. At the same time, with the development of reconfigurable spatial light modulators (SLM) and photonic integrated circuits [ 12 , 13 , 14 ] , optical computing is once again recognized as a potential high-performance computing solution [ 15 , 16 , 17 ] . Many researchers have implemented various forms of optical computing systems using free space and planar waveguides, and used them for training or inference of optical neural networks (ONNs) [ 18 , 19 , 20 , 21 , 22 , 23 , 24 , 25 , 26 , 27 , 28 , 29 , 30 ] . However, these systems still use decades ago OVMM methods, simply replacing traditional optical devices with higher speed, larger scale, and more reconfigurable advanced devices. For example, using lenslet arrays or Dammann gratings instead of traditional multiple light sources to implement convolutional neural networks [ 31 , 32 , 33 ] , using waveshapers and optical frequency combs instead of traditional four-wave mixing to achieve wavelength multiplexing computing [ 21 , 23 , 34 , 35 ] , and using SLMs instead of traditional LED arrays and phase masks to achieve OVMMs [ 18 , 28 , 36 , 37 ] . Although the above works have greatly developed the equipment and combination strategies of optical computing, and effectively improved the actual performance of traditional optical computing methods, they have not fundamentally proposed more efficient optical computing principles.

Here, we innovatively proposed a fully parallelized optical matrix-matrix multiplication (POMMM) paradigm, which fundamentally changed Dr. Goodman’s OVMM method. The difference from previous methods is that our method does not require any pre-coding or pre-processing of matrixs, and the computing operation is completed through the propagation of light with single source and single wavelength. This method has a simple and exquisite architecture, making it a universal computing method that is very suitable for accelerating ONNs and other optical computing operations. POMMM adds an additional computational dimension to the ONN, enabling parallel training and inference of multiple samples and neurons. In addition to OVMM and 2-D convolution operations, this method has the potential to become another new parallel computing paradigm for Fourier optics.

## 2 Principle

### 2.1 Architecture of POMMM

For MMM, assuming matrix A A (N rows, M columns) and matrix B B (M rows, N columns), then matrix C = A ​ B C=AB (N rows, N columns), the value c n ​ m c_{nm} of the n-th row and m-th column of C C can be expressed as: c n ​ m = ∑ i = 1 M a n ​ i ​ b i ​ m . c_{nm}=\sum_{i=1}^{M}{a_{ni}b_{im}}. (1) Based on the above equation, we summarize the core steps of POMMM as (1) parallel implementation of row and column multiplication and addition (MAC) operations, and (2) moving the results to different positions, and design the architecture as shown in Fig.1.

The matrix A A is modulated to the amplitude of wavefront by an amplitude spatial light modulator (ASLM), and is imaged to the surface of phase spatial light modulator (PSLM) by a 4f system. PSLM will modulate a linearly changing phase along the x-direction (m) for each row of the matrix, and change its rate K ⁡ ( n ) K(n) along the y-direction (n) direction: 2 ​ π ​ K ​ ( n ) ​ m 2\pi K(n)m . So the modulated wavefront can be represented by complex exponents, as shown in matrix A ′ A^{\prime} in Fig.1. Then, the wavefront is imaged along the x-direction on the ASLM2 surface through a cylindrical lens, and the y-direction is the result of free diffraction. Therefore, every point on the ASLM2 surface is a complex sum of matrix A ′ A^{\prime} along the y-direction, while the relationship in the x-direction remains unchanged, as shown in matrix A ′′ A^{\prime\prime} in Fig.1. Transpose matrix B B and flip it along the y-direction to matrix B T ​ F B^{TF} , which is modulated to the wavefront through ASLM2 to achieve dot product ( ⊙ \odot ) with the corresponding position of matrix A ′′ A^{\prime\prime} : b n ​ m T ​ F ⊙ a n ​ m ′′ = b n ​ m T ​ F ​ ∑ i = 1 N a i ​ m ​ e j ​ 2 ​ π ​ K ​ ( i ) ​ m . b^{TF}_{nm}\odot a^{\prime\prime}_{nm}=b^{TF}_{nm}\sum_{i=1}^{N}a_{im}e^{j2\pi K(i)m}. (2) From the perspective of spatial frequency domain, the above equation indicates that each row of the matrix contains N spatial frequency components K ⁡ ( 1 ) ​ K ​ ( N ) K(1)~K(N) , and the amplitude of the i-th frequency component on position (n,m) is the dot product of a n ​ m a_{nm} and b n ​ m T ​ F b^{TF}_{nm} . By combining a 2-D lens with a x-direction cylindrical lens, imaging along y-direction and focusing (optical Fourier transform) along x-direction can be achieved, which is similar to traditional OVMM. According to the principle of optical Fourier transform, when focusing along x-direction, N frequency components correspond to N focal points along x-direction, and the intensity of the n-th focal point is related to the sum amplitude of M points: ∑ i = 1 M a i ​ n ​ b n ​ i T ​ F \sum_{i=1}^{M}a_{in}b^{TF}_{ni} . Fig.2 illustrates this process more vividly compared to traditional OVMM.

Obviously, a N × N N\times N -sized Matrix is composed by N frequency components in N rows captured by the qCMOS, which is the transposition of matrix C C .

### 2.2 ONN based on POMMM

The most time-consuming part of neural network training and inference is the convolutional layer and fully connected layer, which are the parts that most ONNs attempts to accelerate. The principles of convolutional layer and fully connected layer are both based on VMM. As shown in Fig.3, the convolutional layer is to achieve the inner product of the slices with the convolutional kernels to form a new sample, the fully connected layer is to achieve VMM on samples and weight matrix ( ω n ​ m \omega_{n}m and ω i ​ j \omega_{i}j ). For convolutional layers, POMMM can process multiple convolutional kernels ( k m ​ 1 k_{m}1 , k m ​ 2 k_{m}2 ,…) in parallel, which is very effective for multi feature extraction. The fully connected layer based on POMMM can process multiple samples ( a 1 ​ m a_{1}m , a 2 ​ m a_{2}m ,…) in parallel, greatly improving computational speed. By comparison, simply replacing the existing OVMM with our POMMM can achieve parallel convolutional layer and fully connected layer processing, greatly improving training and inference of ONNs.

