**4. Adaptive inference scheme for memristance drift mitigation**

In [56], the authors proposed an adaptive inference scheme called AIDX that optimizes the amplitude and duration of inference voltage pulses in order to minimize the speed of memristance drift. AIDX formulates memristance drift as an optimization problem and seeks to minimize the memristance drift error defined as the increase in mean squared error (MSE) from the initial programmed crossbar after a set number of inference operations. The initial MSE can be modeled as:

$$E\_0 = \sum\_j \left( \mathcal{Y}\_j - \sum\_i \mathcal{G}\_{\vec{\eta}} V\_i \right)^2 \tag{5}$$

Similarly, the MSE after *k* inference operations is given as:

$$E\_k = \sum\_j \left( \mathcal{y}\_j - \sum\_i \left( \mathcal{G}\_{\vec{\eta}} + \Delta \mathcal{G}\_{\vec{\eta}}^k \right) V\_i \right)^2 \tag{6}$$

where Δ*G<sup>k</sup> ij* is the accumulated memristance drift in the memristor *i*-th row and *j*-th column from *k* inference operations. The additional error due to memristance drift after *k* operations is calculated as *EDrift* ¼ *Ek* � *E*0. The naive approach of simply choosing the minimum allowable voltage amplitude and duration may seem logical because speed of memristance drift scales with amplitude and duration. However, this naïve approach would still result in significant memristance drift because of the vast differences in state drift speed in the SET and RESET drift [54]. As such, AIDX focuses on balancing the aggregate drift in the SET and RESET directions for a given application by optimizing the ratio of SET to RESET voltage pulse amplitude *A* and duration *D* (**Figure 3a**). The minimization of memristance drift with respect to voltage pulse amplitude and duration is formalized as follows:

$$\min\_{\mathbf{A}, \mathbf{D}} \mathbf{E}\_{\text{Drift}}(\mathbf{A}, \mathbf{D}) \tag{7}$$

Here, *EDrift* is a function of **A** and **D** that are vectors which represent the ratio of SET to RESET voltage pulse amplitude and duration of each row of the memristor crossbar respectively. The Broyden-Fletcher-Goldfarb-Shannon (BFGS) algorithm [67] is used to tackle this optimization problem. Since the gradient of the memristance drift error cannot be evaluated directly, the gradients used in the BFGS algorithm were numerically approximated using function evaluations. Under some circumstances, it is possible for the optimized values of **A** and **D** to be too large or small to be properly implemented on a crossbar. Extreme values of **A** and **D** are often caused by skewed memristor characteristics where memristance drift speed in one direction is much faster than the other direction or when the data distribution is heavily skewed toward one recall direction. To address this issue, AIDX randomly inverting the direction of inference for an input vector **x** with probability *a* in order to compensate for imbalanced memristor characteristics and a skewed data distribution (**Figure 3b**). The probability of input inversion is optimized to minimize *EDrift* before the optimization of **A** and **D** vectors to ensure a

*Mitigating State-Drift in Memristor Crossbar Arrays for Vector Matrix Multiplication DOI: http://dx.doi.org/10.5772/intechopen.100246*

#### **Figure 3.**

*(a) Visual representation on how AIDX's parameters changes the relative amplitude and width of positive and negative voltage pulses before and after optimization. (b) Illustration of skewed input distributions can cause an imbalance of memristance drift error in a particular direction. By applying input inversion, the input distribution is reflected such that the memristance drift error in each direction is balanced. (c) Flowchart describing the AIDX procedure for preprocessing and inference. Figure reprinted by [56].*

relatively balanced memristance drift speed in the SET and RESET directions as to prevent extreme final values of **A** and **D.**

The general usage of AIDX in both preprocessing and inference is described in (**Figure 3c)**. To ensure optimal performance, optimization is done in three scenarios: Optimizing over pulse amplitude ratio, optimizing over pulse duration ration, and optimization over both parameters simultaneously. The best set of parameters is then chosen according to lowest evaluated *EDrift*. If the parameters **A** and **D** are too extreme, the optimization of probability of input inversion *a* is performed. Applying AIDX during inference is almost identical to a normal crossbar VMM operation except that if the input was inverted, the output vector must be reinverted to recover the intended output. When applying AIDX to deep neural networks, it can be inefficient to optimize over all layers simultaneously due to the large number of parameters. Instead, AIDX applies the BFGS algorithm to each layer separately in forward pass order in order to reduce optimization time (**Figure 4a)**. AIDX used a simulated extended VTEAM model to fit real TiOx-based memristor device data. The following non-idealities were considered for testing: 15% memristor programming error, 15% random gaussian noise added to the high/low conductance states and alpha/k parameters of the extended VTEAM model for device-to-device variation. In addition, 200 ohms of source resistance and 20 ohms of line resistance were considered as well as sneak paths were also considered. AIDX was applied to a memristor system that
