Why is the new "half" data type an opaque class?
Show older comments
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 Comment
Daniel M
on 26 Apr 2020
Interesting topic, looking forward to the discussion. Followed and voted!
Accepted Answer
More Answers (0)
Categories
Find more on Get Started with GPU Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!