ApplyV and ApplyH give memory allocation errors with too large of Field Values

Issue #59 new
Caleb Rottman created an issue

If the Field3D value is larger than the maximum Int32 value, it leads to memory allocation errors the next time an Image3D or Field3D is declared.

Practially, its probably not necessary to be able to apply Fields that have such large values, but the memory allocation error is problematic. First, its an error that doesn't seem to make sense when debugging, and second, its problematic to not be able to allocate new memory if you overshoot the int range of a Field3D. (Because of this, everytime this error happens, i need to close and exit ipython).

This error only happens on MEM_DEVICE.

This error can be seen by running the following script:

import PyCA.Core as ca
mType = ca.MEM_DEVICE
grid = ca.GridInfo(ca.Vec3Di(10, 10, 1))
Im = ca.Image3D(grid, mType)
Im1 = ca.Image3D(grid, mType)
u = ca.Field3D(grid, mType)
ca.SetToZero(u)
ca.SetMem(u, 2100000000)
ca.SetMem(Im, 1)
for i in xrange(100):
    u += 10000000
    print i, ca.MinMax(u)
    ca.ApplyV(Im1, Im, u, 1.0, ca.BACKGROUND_STRATEGY_CLAMP)
    ca.Image3D(grid, mType)

Comments (5)

  1. Sam Preston

    Just as a note, the interpolation code is the same for CPU or GPU (in src/math/interp.h). This error doesn't occur with INTERP_NN or INTERP_CUBIC, which use the getSafeVal calls instead of the arcane logic of the trilerp() functions. The trilerp functions were written for speed (it's a bit faster than using getSafeVal), but clearly there are still some bugs. My guess is that the problem is occurring on the CPU too, but it's just not causing a crash.

  2. Sam Preston

    Also, the test code doesn't cause a deterministic error on all machines -- I get the error on my laptop, but not my desktop.

  3. Jacob Hinkle

    Are you sure the error occurs on the next declaration? Cuda error-checking is often a step-behind. This can be verified in C++ by placing an extra error check after the ApplyV call, but I'm not sure we have a way to do that from PyCA.

  4. Sam Preston

    common.CheckCUDAError() will check for cuda errors from python, although there's a bug and the 'message' parameter doesn't seem to work.

  5. Log in to comment