  Magnetic random-access memory (MRAM) is a promising memory technology due to
its high density, non-volatility, and high endurance. However, achieving high
memory fidelity incurs significant write-energy costs, which should be reduced
for large-scale deployment of MRAMs. In this paper, we formulate a
\emph{biconvex} optimization problem to optimize write fidelity given energy
and latency constraints. The basic idea is to allocate non-uniform write pulses
depending on the importance of each bit position. The fidelity measure we
consider is mean squared error (MSE), for which we optimize write pulses via
\emph{alternating convex search (ACS)}. By using Karush-Kuhn-Tucker (KKT)
conditions, we derive analytic solutions and propose an \emph{iterative
water-filling-type} algorithm by leveraging the analytic solutions. Hence, the
proposed iterative water-filling algorithm is computationally more efficient
than the original ACS while their solutions are identical. Although the
original ACS and the proposed iterative water-filling algorithm do not
guarantee global optimality, the MSEs obtained by the proposed algorithm are
comparable to the MSEs by complicated global nonlinear programming solvers.
Furthermore, we prove that the proposed algorithm can reduce the MSE
exponentially with the number of bits per word. For an 8-bit accessed word, the
proposed algorithm reduces the MSE by a factor of 21. We also evaluate the
proposed algorithm for MNIST dataset classification supposing that the model
parameters of deep neural networks are stored in MRAMs. The numerical results
show that the optimized write pulses can achieve \SI{40}{\%} write energy
reduction for a given classification accuracy.
