I was curious to see how possible/impossible it would be to compute a FHorz value function iteration using single precision arithmetic. Answer: not that hard.
Because this was just an experiment, I cobbled together the call:
ValueFnIter_FHorz_ExpAsset_e_raw(single(n_d1),single(n_d2),single(n_a1),single(n_a2),single(n_z), single(vfoptions.n_e), single(N_j), single(d_gridvals), single(d2_gridvals), single(a1_gridvals), single(a2_grid), single(z_gridvals_J), single(vfoptions.e_gridvals_J), single(pi_z_J), single(vfoptions.pi_e_J), ReturnFn, aprimeFn, Parameters, DiscountFactorParamNames, ReturnFnParamNames, aprimeFnParamNames, vfoptions);
Then made a two fixes to the called function:
% Create a vector containing all the return function parameters (in order)
ReturnFnParamsVec=CreateVectorFromParams(Parameters, ReturnFnParamNames,N_j);
% FIX FOR SINGLE PRECISION
ReturnFnParamsVec=single(ReturnFnParamsVec); V=zeros(N_a,N_z,N_e,N_j,'single','gpuArray'); Policy=zeros(N_a,N_z,N_e,N_j,'single','gpuArray');
% Create a vector containing all the return function parameters (in order)
ReturnFnParamsVec=CreateVectorFromParams(Parameters, ReturnFnParamNames,jj);
DiscountFactorParamsVec=CreateVectorFromParams(Parameters, DiscountFactorParamNames,jj);
DiscountFactorParamsVec=prod(DiscountFactorParamsVec);
aprimeFnParamsVec=CreateVectorFromParams(Parameters, aprimeFnParamNames,jj);
% FIX FOR SINGLE PRECISION
aprimeFnParamsVec=single(aprimeFnParamsVec); DiscountFactorParamsVec=single(DiscountFactorParamsVec); ReturnFnParamsVec=single(ReturnFnParamsVec);
I also needed to create single-precision versions of my ReturnFn and aprimeFn.
And voila! In this case I observed that single precision runs faster than double precision (up to 2x) and uses 2x less GPU memory. This tells me that the VFI toolkit is not itself terribly opinionated about single vs. double precision. The biggest issue in my ReturnFn and aprimeFn was the fact that assigning zero to a parameter defaults to double, so changing x=0; to x=single(0); in my own code. The biggest issue likely for the toolkit is changing its calls to zeros and ones to return single vs. double arrays, and of course the construction of parameter vectors. Parameter values can remain their feral double-precision selves.
And of course users will have to be careful to create grids of the precisions they want. Though one could allow the PType mechanism to convert grids to preferred precisions when storing them in PType structuresā¦
Make of this what you will, but I think it wouldnāt be too difficult to support larger models / faster runtimes when one is just experimenting and super-tight tolerances are not needed for publication/replication.
