This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430FR5994: Matrix multiplication using 'int' or 'float' values

Part Number: MSP430FR5994


I am working on implementing multiple matrix multiplication and addition steps for a neural network. I tried to look at some previous questions related to the same but couldn't find a concrete answer regarding the same. In the current implementation that I use, the MSP DSP Library is performing matrix multiplication but using '_q15' variables - here, the values are being shifted due to the fixed point representation being used for numbers. I want to clarify if there is any method at all where a normal matrix multiplication can be performed on simple integer values such that the results are stored as it is without any bit shifts. I understand that using the fixed point representation would lead to shifting of the calculated result according to the definition of the system. However, I would like to avoid this and simply keep the result as is. I would prefer using the LEA but since the LEA generally uses the '_q15' format if the only available methods are without using LEA, even those would work. 

The reason why I am aiming for a standard matrix calculation is that the matrices that contain weights and biases of the neural network can directly be fed with the quantized values such that all of the entries are integer values. This would make it rather straightforward to go through multiple layers or steps of the neural networks unlike the case using fixed point representation where-in the integrity of each calculation needs to be verified. Please let me know if any kind of example is needed to understand what the calculations would like since I am keeping the question a bit theoretical as this is more of a conceptual dilemna I have rather than some part of code that I do no understand. Any kind of leads are appreciated, including some reference guide or manual that might contain more information about this. Thanks.

  • I suggest that you get a C compiler on your PC and run some simulations. If you do not need fractional values, there should be no problem, however, you can run out of dynamic range very quickly.

  • I checked my matrix calculations on a C compiler and they are all working out. The results of the matrix and the dimensions are also correct. 

    I am looking to do calculations like the folllowing:

    The input matrices can be considered as follows: A= [[2,3], [4,5]], B= [[4,5], [2,3]] . 
    The result of this calculation would be AB = [[14,19], [26,35]].

    The matrices will contain values in the range [-127,127] and any multiplication that would be carried out would stay in the range of an 'int16_t' type integer declaration. 

    Such a calculation cannot be replicated with the LEA since it requires '_q15' parameters and fixed point representation - the result of AB would be shifted by 15 bits. However, if I want to execute the above calculation and get the resultant matrix AB as mentioned in the description above - could I do it on the MSP430 using the MPY32 or even with the LEA? If so, is there any reference article or guide where such matrix operations on the MSP430 are described? I could not find anything other than the MSP DSPLibrary and all possible methods that are defined here use fixed point representation. 

    Please let me know if any more details are required, I would gladly provide the necessary information. Thanks for your patience and response. 

  • If you are just multiplying small matrices like that, I would just hard code the multiplication and be done with it. Only worry if it turns out to be a bottleneck.

  • Thanks for the quick response. The small matrix was an example I cited to explain what I am looking to do. The calculations I need to execute however are bigger with the maximum matrix dimensions spanning upto [12*12]. 

  • First do it simply using basic C. If that is too slow then you can think about using the multiply accumulate ability of the hardware multiplier. (like the DSP library does.) Or assembly language.  But be sure you need the speed or you are just wasting your time.

  • Alright, thank you. I will try this out in a day or two and then update the issue here once I either have some result or some feedback about the method. Thanks for the response.

**Attention** This is a public forum