CL_MEM_OBJECT_ALLOCATION_FAILURE in clEnqueueWriteBuffer I can't get a simple convolution to run

Hi.

I’m new to OpenCL and so I tried to implement the AMD Image Convolution tutorial using the code and style from the nVidia SDK samples.

(AMD Image Convolution Tutorial)

I started out by copying one of the sample projects, so the project settings should be okay.

When running the project I get the CL_MEM_OBJECT_ALLOCATION_FAILURE in clEnqueueWriteBuffer and I have no idea how to fix it or why it happens.

now the important code excerpts (full code at link below):

struct hostBufferStruct

{

	float * pInput;

} hostBuffers;

struct oclBufferStruct

{

	cl_mem  inputCL;

} oclBuffers;

struct paramStruct

{

	int nInWidth;	   //Input  image width

	int nInHeight;	  //Input  image height

} params;

host buffer:

int sizeInBytes = params.nInWidth * params.nInHeight * sizeof(cl_float);

	hostBuffers.pInput = (float *) malloc(sizeInBytes);

for (int i = 0; i < params.nInWidth * params.nInHeight; i++)

	{

		hostBuffers.pInput[i] = float(rand());

	}

cl buffer:

oclBuffers.inputCL = clCreateBuffer(cxGPUContext, 

									CL_MEM_READ_ONLY,

									sizeof(cl_float) * params.nInWidth*params.nInHeight,

									hostBuffers.pInput, 

									&ciErr1);

enqueueWrite

ciErr1 = clEnqueueWriteBuffer(cqCommandQue, oclBuffers.inputCL, CL_TRUE, 0, 

		sizeof(cl_float) * params.nInWidth*params.nInHeight,

		hostBuffers.pInput, 0, NULL, NULL);

	if (ciErr1 != CL_SUCCESS)

	{

		shrLog(LOGBOTH, 0.0, "Error in clEnqueueWriteBuffer, Line %u in file %s !!!\n\n", __LINE__, __FILE__);

		if(ciErr1 == CL_MEM_OBJECT_ALLOCATION_FAILURE)

			shrLog(LOGBOTH, 0.0, "=> CL_MEM_OBJECT_ALLOCATION_FAILURE\n\n");

		Cleanup(EXIT_FAILURE);

	}

The full code:

.cpp

oclConvolution.cpp

.cl (taken directly from AMD tutorial)

Kernels.cl

I really hope one of you knows what I did wrong here.

My system:

Windows 7, 64 bit version

Visual Studio 2008

SDK and driver from here: http://developer.nvidia.com/object/opencl-download.html

(190.89 driver, 2.3 SDK, both 64 bit)

The nVidia samples run without errors.

PS: just in case, I’ve attached a .zip of my full Visual Studio project

EDIT: download doesn’t work. I have uploaded it again, but I don’t know if that will help.
oclConvolution.zip (4.38 MB)

Hi, I have the same problem as well with the ATI SDK though. Do you get this error past a certain problem size? my matrix multiplication program works fine until i reach a large matrix size then it spits out CL_MEM_OBJECT_ALLOCATION_FAILURE. So i am guessing there is not enough memory on the GPU. try a smaller problem size and see if you still get it.

it’s been quite some time since I had this problem. :)

I think at the time I found what went wrong. If I remember correctly the problem was that the memory was not aligned. So instead of malloc there is an aligned_malloc or something that fixed the problem.

Now I always compile for 64 bit. Using x64 things are automatically aligned.