Why is half-precision slower than double-precision?
    조회 수: 12 (최근 30일)
  
       이전 댓글 표시
    
    MathWorks Support Team
    
 2019년 8월 19일
  
    
    
    
    
    편집: MathWorks Support Team
    
 2021년 9월 22일
            While executing same calculations in MATLAB, speed of double-precision variables is faster than half-precision.
Is this normal? Is there any way to speed up?
채택된 답변
  MathWorks Support Team
    
 2019년 8월 19일
        This is true.
n = 100;
t1= zeros(1,n);
t2= zeros(1,n);
for i = 1:n
a = ones(10,10,100,100);
b = zeros(10,10,100,100);
a2 = half(a);
b2 = half(b);
tic
temp = plus(a,b);
c = sum(temp(:));
t1(i) = toc;
tic
temp2 = plus(a2,b2);
c2 = sum(temp2(:));
t2(i) = toc;
end
sum(t1)
sum(t2)
ans = 
0.1456
ans=
0.2737
Computations with half-precision data types is slower than those with double precision data types. This is because, unlike double, half-precision is not a native data type in MATLAB and hence, requires additional tweak to do the computations.
댓글 수: 0
추가 답변 (1개)
  Krishna Bindumadhavan
    
 2020년 4월 9일
        
      편집: MathWorks Support Team
    
 2021년 9월 22일
  
      To accelerate half precision floating point math, from 20a onwards, you can now generate CUDA code from your MATLAB Algorithm for NVIDIA GPU's with Compute Capability > 5.3 which have native half precision floating point support: https://www.mathworks.com/help/gpucoder/ug/sobel-edge-detection-in-half-precision.html.
댓글 수: 0
참고 항목
카테고리
				Help Center 및 File Exchange에서 GPU Computing에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

