Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MemoryError: clCreateImage failed: mem object allocation failure #61

Closed
Kerkil opened this issue Aug 11, 2014 · 1 comment
Closed

MemoryError: clCreateImage failed: mem object allocation failure #61

Kerkil opened this issue Aug 11, 2014 · 1 comment

Comments

@Kerkil
Copy link

Kerkil commented Aug 11, 2014

I have a "complex-valued" array read from a Matlab data file .mat:

datas = scipy.io.loadmat('/Users/recondev/Projects/RMA/Data/RMA_to_iPython_interpolator_only.mat')
dataIn = datas['vec_in'].astype(np.complex64).view(cl.array.vec.float2).T

dataIn.dtype returns complex64

I am trying to create an 1d image object from the dataIn array using pyopencl.image_from_array, but I receive the following errors:

---------------------------------------------------------------------------
MemoryError                               Traceback (most recent call last)
<ipython-input-69-07fda49d952e> in <module>()
----> 1 dataInImg = pyopencl.image_from_array(ctx, dataInCont)

/Users/recondev/.virtualenvs/ipythonenv/lib/python2.7/site-packages/pyopencl/__init__.pyc in image_from_array(ctx, ary, num_channels, mode, norm_int)
   1178             ImageFormat(img_format, channel_type),
   1179             shape=shape[::-1], pitches=strides[::-1][1:],
-> 1180             hostbuf=ary)
   1181 
   1182 # }}}

/Users/recondev/.virtualenvs/ipythonenv/lib/python2.7/site-packages/pyopencl/__init__.pyc in image_init(self, context, flags, format, shape, pitches, hostbuf, is_array, buffer)
    676             desc.buffer = buffer
    677 
--> 678             image_old_init(self, context, flags, format, desc, hostbuf)
    679         else:
    680             # legacy init for CL 1.1 and older

MemoryError: clCreateImage failed: mem object allocation failure

By reducing the array to a much smaller size (the original array contains 1728_256_13 complex64 values, and the reduced array contains only 1728 complex64 values), I was able to remove the errors.

What I am troubling getting my head around is that when I create an image from float32 (as compared to complex64) array, I am able to create an image containing much larger sized array. I am able to create an image containing 1728_256_13 float32 values (23003136 bytes). However, I keep failing to create an image containing 1728*256 complex64 values (2097152 bytes).

I wonder if this is an expected behavior and what is the reason behind it.

@Kerkil
Copy link
Author

Kerkil commented Aug 11, 2014

I was able to resolve the issue by changing the following

dataInCont = dataInCont.reshape((np.size(dataInCont),1))
dataInCont = np.ascontiguousarray(dataIn)

to (I basically switched the order of the two lines)

dataInCont = np.ascontiguousarray(dataIn)
dataInCont = dataInCont.reshape((np.size(dataInCont),1))

The dataInCont was the input to pyopencl.image_from_array(context, dataInCont).

The mistake I made is that I break the contiguousness of the memory by reshaping the array.

@Kerkil Kerkil closed this as completed Aug 11, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant