How to use half precision ?
How to use half precision ?, are there any c++ code samples or is this done by some flags ?
Best regards
fp16 is still very much an experimental feature. It can only be used for some operations and only works well on the CUDA backend. Through a couple of issues with indexing and on the OpenCL side of things but I will write a tutorial page after it is more complete.
If you have host side data, I would suggest creating an fp32 array and calling the as member function to convert it to fp16. Here is an example:
vector<float> hdata(100, 3.14);
array data(10, 10, hdata.data());
array fp16data = data.as(fp16);
...
So far all element-wise operations should work, as well as af_gemm, reductions, transpose, and join. Printing also works. If you want to test, please let us know of any functions you need to port to fp16.
Ok thank you, best regards.
Ok but i also have one question how to compile arrayfire with cmake for half precision and how get the right include file(s).
Best regards
I am not sure I understand. Are you running into errors? Can you post the compile log?
No but the datatype fp16 was not found for converting it, so something is missing.
Its defined here: https://github.com/arrayfire/arrayfire/blob/master/include/af/defines.h#L227. That file is included with arrayfire.h. Are you sure you are compiling the latest master?
yes i do
ok now it works
it should be called f16 instead of fp32
arrayfire.h should also look like this
#include "af/compatible.h" #include "af/algorithm.h" #include "af/arith.h" #include "af/array.h" #include "af/backend.h" #include "af/blas.h" #include "af/constants.h" #include "af/complex.h" #include "af/data.h" #include "af/device.h" #include "af/exception.h" #include "af/features.h" #include "af/gfor.h" #include "af/graphics.h" #include "af/half.h" #include "af/image.h" #include "af/index.h" #include "af/lapack.h" #include "af/random.h" #include "af/seq.h" #include "af/signal.h" #include "af/sparse.h" #include "af/statistics.h" #include "af/timing.h" #include "af/util.h" #include "af/version.h" #include "af/vision.h" #include "af/defines.h" //is missing
half precision only works for some specific kinds of operations, i think it does not work for convolution, best regards
the error for convolution would be
ArrayFire Exception (Function does not support this data type:204): In function af_err convolve(void**, af_array, af_array) [with long long int baseDim = 2; bool expand = false; af_array = void*] In file src/api/c/convolve.cpp:154 Invalid type for argument 1
In function af::array af::convolve2(const af::array&, const af::array&, af::convMode, af::convDomain) In file src/api/cpp/convolve.cpp:49 terminate called after throwing an instance of 'af::exception' what(): ArrayFire Exception (Function does not support this data type:204): In function af_err convolve(void**, af_array, af_array) [with long long int baseDim = 2; bool expand = false; af_array = void*] In file src/api/c/convolve.cpp:154 Invalid type for argument 1
In function af::array af::convolve2(const af::array&, const af::array&, af::convMode, af::convDomain) In file src/api/cpp/convolve.cpp:49
Convolve has not been converted to support fp16.
Ok thx.
Convolve has not been converted to support fp16.
It would be nice to have such operations, because these operations are really expensive.
@ZeroCool11000 could you please check if AF 3.7.0 now please you ?
Half precision support is added to the following convolution functions only at the moment. latest release has added couple of Machine learning specific functions
@ZeroCool11000 If the above mentioned suffices your case, you may close the issue. If you need f16 support for regular convolution functions. Feel free to rename the issue as feature request to add f16 support for convolutions in general
Closing due to inactivity.
Is it possible to add half-point support for regular convolutions?