Sign in to follow this  

cl::vector vs std::vector with cl::Event error

Recommended Posts


I am trying to figure out why this code generates an error (Unhandled exception, Access violation reading location...)  when releasing the events if __NO_STD_VECTOR is defined, i.e. using the built in more simple vector class in OpenCL, but works perfectly fine using std::vector. i've been scratching my head bout this issue for quite some time now. Its like the destructor of cl::Event is called twice, once in destructor of the vector and once when leaving the scope of main. But it feels like this isn't the intended behaviour considering they are vectors of cl::Event everywhere in the c++ API of openCL, which in turn makes me believe i've overseen an obvious error in the code. Still it works with std::vector and not cl::vector... 

#define __NO_STD_STRING 
#define __NO_STD_VECTOR

#include <CL/cl.hpp>

const __int64 FILE_LENGTH = 1024*128;
#define NUM_WRITES 2

int main()
	cl::CommandQueue commandQueues;
	cl::Program program;
	cl::Context context;
	cl_device_id device_id; 
	VECTOR_CLASS<cl::Platform> platforms;
	VECTOR_CLASS<cl::Device> devices;

	cl_int error;
	error = cl::Platform::get(&platforms);

	if(error !=CL_SUCCESS)//handle error better
		return false;

	cl_device_type type = CL_DEVICE_TYPE_GPU;

	error = platforms[0].getDevices (type, &devices);
	if(error != CL_SUCCESS) //handle error better
		return false; 

	context =  cl::Context(devices);

	cl::CommandQueue queue = cl::CommandQueue(context, devices[0]);

	VECTOR_CLASS<cl::Event> m_Events;
	cl::Buffer destinationbuffer[NUM_WRITES];
	int n = 0;
	for(int i = 0;i<NUM_WRITES;i++)
		destinationbuffer[i] = cl::Buffer(context,CL_MEM_ALLOC_HOST_PTR|CL_MEM_READ_ONLY,FILE_LENGTH,0,&error);
		if(error != CL_SUCCESS) //handle error better
		error = queue.enqueueFillBuffer<int>(destinationbuffer[i],n,0,FILE_LENGTH,0,&m_Events[i]);
		if(error != CL_SUCCESS) //handle error better
	return 0;

(removing m_Events.clear() doesn't change anything)


I've been requested to not use std::vector or std::string, so going with what works is not really an option. 


The error occurs in both intel and amd sdk of opencl. 

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this