Why is the new "half" data type an opaque class?

조회 수: 4 (최근 30일)
James Tursa
James Tursa 2020년 4월 25일
댓글: James Tursa 2020년 5월 6일
The good news:
The new half precision data type was introduced in R2019b. Graphics cards have been using this for quite some time, so this is a welcome addition to MATLAB.
The bad news:
Unfortunately, TMW has implemented half as an opaque class (like a classdef OOP object) instead of a simple numeric class like double or single.
Why is this bad?
With simple numeric classes like double or single, the data is not hidden. It is immediately accessable to a multitude of functions such as typecast( ), and is immediately available inside of mex routines. But with an opaque class, the data is hidden. Many of the MATLAB functions that work with simple numeric classes such as double and single will not work with the new half class. And you can't get at the data inside a mex routine at all, so forget about calling any library code (3rd party or yours) for any data manipulation from a mex routine. You don't see any mxHALF_CLASS or mxGetHalfs listed in the mex doc because they aren't there and getting pointers to your half data isn't supported.
@TMW: What was the point of hiding the half numeric data from the user? Why was half implemented this way? Is it too late to reverse this decision and turn half into a simple numeric class like double and single in future versions of MATLAB? The current opaque design hamstrings the user, particularly for conversing with GPU cards. At least provide mex read access to the data areas with mxGetHalfs and mxGetComplexHalfs routines.
E.g., even for simple stuff such as fwrite( ), you have to do funky workarounds:
  댓글 수: 1
Daniel M
Daniel M 2020년 4월 26일
Interesting topic, looking forward to the discussion. Followed and voted!

댓글을 달려면 로그인하십시오.

채택된 답변

Krishna Bindumadhavan
Krishna Bindumadhavan 2020년 5월 6일
Hi James,
Appreciate your feedback regarding treating half as a native type in MATLAB (similar to single/double) and support for half with MEX API's. We will consider this in future releases as adoption of half precision increases amongst the user base.
Regarding GPU compute with half datatype, we have recently added support for half in the GPU Coder toolbox in 20a for supported NVIDIA Cards (like Volta). See https://www.mathworks.com/help/gpucoder/examples/sobel-edge-detection-in-half-precision.html for an example.
In addition, deep learning code generation supports inference with fp16 compute (using mixed precision Tensor Cores) with the TensorRT library .
Hope this helps.
Best Regards,
Krishna.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 GPU Computing in MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by