%% HDL Code Generation for Streaming Matrix Multiply System Object
%
% This example shows how HDL Coder(TM) implements a streaming mode of matrix multiplication with 
% configurable sizes.

% Copyright 2013-2019 The MathWorks, Inc.
%% How to Multiply Matrices
%
% Let A, B be two matrices then C= A * B is the matrix multiplication of A
% and B. If A is an m-by-p and B is an p-by-n matrix, then C is an m-by-n matrix
% defined by
%
%   C(i,j) =  A(i,1)B(1,j) + A(i,2)B(2,j) + -------- + A(i,p)B(p,j)
%
% This inner definition says that C(i,j) is the inner product of ith row of
% A with the jth column of B
% 
% For non scalar A and B, the number of columns of A must equal to 
% the number of rows of B
% 
% *Example*:
%
%       A = [1 3 5;2 4 7];              (2 X 3 matrix)
%
%       B = [-5 8 11;3 9 21;4 0 8];     (3 X 3 matrix)
%
% After calculating inner product of rows of A with columns of B
% 
%       C = [24 35 114;30 52 162];      (2 X 3 matrix)
%
%% Introduction
%
% Streaming Matrix Multiply supports multiplication of two matrices with 
% configurable matrix sizes and dot product size. Dot product size is equal
% to the number of multipliers used for computation. This block can accepts 
% serialized input data from matrix in row major or column major format.

%% Matrix Multiply Interface:
%
% <<hdlcoder_streaming_matrix_multiply_interface.png>>
%
% *Matrix Multiply ports description*:
%
% <<hdlcoder_matrix_multiply_ports_description.png>>
%
%% MatrixMultiply Implementation
%
% <<hdlcoder_streaming_matrix_multiply_system.png>>
%
% This example model contains three subsystems: |InputSubsystem|, |MatrixMultiply|
% and |OutputSubsystem|. The |InputSubsystem| is the upstream module that 
% serializes the matrix inputs(A,B) to the processing module when |aReady| and
% |bReady| signals are enabled. The |OutputSubsystem| is the downstream
% module that deserializes the data from the processing module to matrix
% output(C) when the |cReady| signal is enabled. The |MatrixMultiply| is a
% processing module that implements the matrix multiplication.
%
open_system('hdlcoder_streaming_matrix_multiply_max_latency');
%% Matrix Multiply Timing diagrams
%
% *Timing diagram*
%
% <<hdlcoder_matrix_multiply_timing_diagram1.png>>
%
% *Timing diagram*
%
% <<hdlcoder_matrix_multiply_timing_diagram2.png>>
%
% *Modelsim results for streaming matrix multiply*
%
% <<hdlcoder_matrix_multiply_modelsim_waveform.png>>

%% Matrix Multiply Block parameters:
%
% <<hdlcoder_matrix_multiply_block_parameters.png>>
%
%  Matrix-A Row Size         : Enter row size of input matrix A as a positive integer.
%  Matrix-A Column Size      : Enter column size of input matrix B as a positive integer
%                              which is equals to input matrix B row size. 
%  Matrix-B Column Size      : Enter column size of input matrix B as a positive integer.
%  Dot product size          : Select dot product size from drop
%                              down menu(1,2,4,8,16,32,64) which should be
%                              less than input matrix A column size.
%  LatencyStrategy          :  Select latency strategy from drop
%                              down menu ({'ZERO, 'MIN', 'MAX'}) which 
%                              should be same as HDL coder latency strategy.
%                              Processing latency depends on the latency strategy.
%  Major Order               : Select row major or column major 
%                              based on the input data streaming.
%% Matrix Multiply Block usage
% # Set block parameters of Matlab System block.
% # Select input matrix sizes based on the values set in block parameters.
% # Generate HDL code for MatrixMultiply subsystem.
%
%% Generated code and Generated model
% 
% After running code generation for MatrixMultiply subsystem, generated
% code will be
%
% <<hdlcoder_makehdl_streaming_matrix_multiply.png>>
%
% Generated model contains the  MatrixMultiply Matlab System block. 
% During modelsim simulation code generation outputs are compared 
% with Matlab System block outputs.
%% Synthesis statistics
%
% <<hdlcoder_matrix_multiply_synthesis_results.png>>
%
%% Restrictions
% * Matrix dot product sizes can be |1| or a power of |2|. The allowed
%   sizes are |1|, |2|, |4|, |8|, |16|, |32| and |64|.
% * Input data types of the matrices must be |single| and block must be used
%   in the |Native Floating Point| mode.
% * Input matrices must not be larger than 64-by-64 in size.
%% References
%
% * <docid:matlab_ref#btx9i74>
%
% LocalWords:  serail deserializer AStore BStore Cmatrix muxing
% LocalWords:  Amemory Bmemory modelsim
