Is Matlab do LU in pure half (FP16) if input is A_h=half(A_d)? which A_d is rand(n)

4 views (last 30 days)
I am generating random number in double and converting them to PF16 by half command. After that I am using LU like this:
[L_h, U_h, P_h]=lu(A_h);
My question is about the internal of LU for half in Matlab. Does it work purly in half? is the process same as single and double for partial pivoting? How can I understand more about it and be sure? Do matlab convert it to single and do the LU?
I think it is more accurate than what I expect. So based on my experiment it is not working in Half. Just the result is transformed to Half.
  2 Comments
Steven Lord
Steven Lord on 10 Jun 2022
How can I understand more about it and be sure?
Do you have a specific concern about the internal implementation of the lu for half? If you want to check whether or not lu computes the correct answer you can check that L_h, U_h, P_h, and A_h satisfy the relationship in the lu documentation.
"[L,U,P] = lu(A) also returns a permutation matrix P such that A = P'*L*U. With this syntax, L is unit lower triangular and U is upper triangular."
Nima Sahraneshin
Nima Sahraneshin on 10 Jun 2022
Thanks. But we know that x86 does not support FP16 and MATLAB should some kind of simulation for FP16. I know I can check the correctness, but is it going to compute by FP32 or exactly FP16? If it has been computed by FP32 for sure L*U=P*A but for FP16 ater some dimentions L*U=P*A is not true anymore.

Sign in to comment.

Answers (1)

Balavignesh
Balavignesh on 17 Jan 2024
Hi Nima,
MATLAB's built-in 'lu' function supports only 'single' and 'double' datatypes. It doesn't natively support half-precision (FP16) inputs directly. If a half-precision matrix is passed to the 'lu' function, MATLAB will likely covert it to single or double-precision internally to perform the computation. It then coverts the result back to half-precision before returning them.
If you suspect that MATLAB is coverting half-precision inputs to a higher precision for the computation, you could verify this by checking the precision of the intermediate results. You could use MATLAB's 'whos' function to inspect the variable types at various points in your code.
The following example code snippet may help you understand this:
% Generate a random matrix in double precision and convert to half precision
A = double(rand(10));
A_h = half(A);
% Perform LU decomposition
[L_h, U_h, P_h] = lu(A_h);
% Check the precision of the outputs
whos L_h U_h P_h
Name Size Bytes Class Attributes L_h 10x10 200 half P_h 10x10 200 half U_h 10x10 200 half
Kindly refer to the following documentation links to have more information on:

Tags

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!