Huggett example without GPU: Error

I tried to run the example based on Huggett (1996) in VFItoolkit-matlab-examples/OLG/Huggett1996_Example.m at master · vfitoolkit/VFItoolkit-matlab-examples · GitHub

using a computer without Nvidia GPU but I received the following error message:

ReturnFn =

  function_handle with value:

    @(aprime,a,z,sigma,r,ybarj,theta,b,bvec,T,delta,alpha,A,bc_equalsminusw)Huggett1996_ReturnFn(aprime,a,z,sigma,r,ybarj,theta,b,bvec,T,delta,alpha,A,bc_equalsminusw)

Test ValueFnIter
Error using zeros
Unable to find a supported GPU device.

Error in ExogShockSetup_FHorz (line 83)
        z_gridvals_J=zeros(prod(n_z),length(n_z),'gpuArray');
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in ValueFnIter_Case1_FHorz (line 251)
    [z_gridvals_J, pi_z_J, vfoptions]=ExogShockSetup_FHorz(n_z,z_grid,pi_z,N_j,Parameters,vfoptions,3);
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in Huggett1996_Example (line 151)
[V, Policy]=ValueFnIter_Case1_FHorz(0,n_a,n_z,N_j, 0, a_grid, z_grid, pi_z, ReturnFn, Params, DiscountFactorParamNames, [],vfoptions);
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Related documentation

Maybe this example uses some advanced feature and is not supposed to work on CPU…

I checked also this simpler example VFItoolkit-matlab-examples/FiniteHorizon at master · vfitoolkit/VFItoolkit-matlab-examples · GitHub and it gives the same error message

ReturnFn =

  function_handle with value:

    @(aprime,a,Wz,gamma,r,Wj)FiniteHorzStochConsSavings_ReturnFn(aprime,a,Wz,gamma,r,Wj)

Error using zeros
Unable to find a supported GPU device.

Error in ExogShockSetup_FHorz (line 83)
        z_gridvals_J=zeros(prod(n_z),length(n_z),'gpuArray');
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in ValueFnIter_Case1_FHorz (line 251)
    [z_gridvals_J, pi_z_J, vfoptions]=ExogShockSetup_FHorz(n_z,z_grid,pi_z,N_j,Parameters,vfoptions,3);
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in FiniteHorzStochConsSavings (line 59)
[V, Policy]=ValueFnIter_Case1_FHorz(0,n_a,n_z,N_j, 0, a_grid, z_grid, pi_z, ReturnFn, Params, DiscountFactorParamNames, [],vfoptions);
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Related documentation

As I mentioned earlier, this isn’t a priority for me :slight_smile: I simply check the CPU version from time to time, as I may consider using the toolkit for teaching in the future and want to see if the basic stuff works even without a Nvidia GPU (so no iid shocks, no semi-exo, no Ptype, no experience assets… just models with action space d,a’,a,z)

The finite horizon one now works. I didn’t check if this makes Huggett 1996 work or not.

1 Like

Thanks! I spotted a few instances in the CPU code where one could use automatic expansion

In ValueFnIter_FHorz_Par1_nod_raw.m, lines 34 and 69: replace

EV_z=EV.*(ones(N_a,1)*pi_z(z_c,:));

with

EV_z=EV.*pi_z(z_c,:); % this is (a',z')

In ValueFnIter_FHorz_Par1_raw.m same thing in lines 35 and 71

Added the automatic expansion, nice spot.

Huggett (1996) should work now for CPU. I separated out the CPU codes from the rest so they hopefully won’t break anymore. Also means I can now code knowing everything is always GPU which will save me some headaches.

1 Like