View Full Version : cl_command_queue , cl_context as member variable of a class?
10-23-2009, 03:37 PM
by following code , I get at the end an error "Unhandled exception at 0x1000693a in IntensityRange.exe: 0xC0000005: Access violation reading location 0xcdcdcdd1." in VS.
template<typename TReferenceImage, typename TAlignImage>
size_t localWorkSize, globalWorkSize;
unsigned int WORKGROUP_COUNT = 256;
localWorkSize = WORKGROUP_COUNT;
localWorkSize = 1;
globalWorkSize = WORKGROUP_COUNT*localWorkSize;
globalWorkSize = 1;
clSetKernelArg(m_ckHistogram256, 7, sizeof(cl_mem),
clEnqueueNDRangeKernel(m_cqCommandQue, m_ckHistogram256, 2, NULL,
globalWorkSize, localWorkSize, 0, NULL, NULL);
I get the error at the end by clEnqueueNDRa....
At this point, no variables are NULL, so I cannot understand the problem. I have a first version of the same code which is working fine. The only difference between them is, that the first version takes cl_command_queue cqCommandQue, cl_kernel ckHistogram256, as parameters and everything works fine. Now, my second version of code has a class and the variable , which are given as parameters in the first version, are now member variables of the class (they are already initialized and everything). There are no other changes , everything is the same. Why does my first version works fine whereas the second one does not ? Is there any openCL policies like "not allowed to hold cl_command_queueu or cl_kernel as member variables of a class" ???
10-24-2009, 10:36 AM
Following instruction solves the problem, but it is not clean and I don't understand some things:
clReleaseCommandQueue(this->m_cqCommandQue); //before clEnqueueNDRangeKernel()
If I do so, it works, but it doesnt make sense to me. Before I do clReleaseCommandQueue , I checked the reference count values for both CommendQueue and Context. Both are 1 (which is normal). Now if I do clRelease on both CommandQueue and Context, then the reference count of Context is 0 whereas the reference count of CommandQueue is 4277075694, which is too strange, because both of them should be 0 in this case.
However, after doing clRelease on CommandQueue (and making the reference count 4277075694, which doesnt make sense) , everything works then fine. But why?
I tried to do a retain instead of release, making the reference count of CommandQueue 2. In this case it doesnt work as well. Why does it work for reference count 4277075694 , but not for reference count 2 or even 1 (actually it should work by 1, without doing any releases or retains) ???
I also tried to do a retain and immediatelly a release , holding the ref count by 1. This is also not working. It only works if I do a release on CommandQueue, which has ref count 1 before release and 4277075694 after realease, which is very strange.
Does anyone have any explanations for this ? The solution is not a clean one , I think....
I don't know exactly what is going on, but I suspect you are actually passing in the wrong data to the function call. A reference count that large suggests that the structure you are accessing is invalid and you're just reading back garbage.
A few other comments: getting the internal reference counts for objects should be used only for debugging and not for your program as the value is stale as soon as it is returned. Also, if you release the command queue before using it you're likely to crash if the runtime has cleaned up before you try to use it again.
10-24-2009, 02:01 PM
Did u read the first post ? It is not my intention to get ref counts. As u said, I only used ref counts for debug purposes and posted the results. I am not using ref counts for my program and i never want to release or retain any thing.
If you please read my two posts again, you will see that I described a problem in my first post. Then in my second post, I just wrote the information, that the problem in the first post is solved if I do release on CommandQueue and I asked why it is so ? One of other things which I would know was, why the ref count for the Context and CommandQueue, which has the same value "1" before calling any relaese, do have different values after calling release one time on both of them.
I never mentioned that I do want to use ref counts , releases and retains in my program. I still have the problem , described on my first post and i would like to fix it. In that sense , please forget everything about release and so forth, if they re confusing u .
Does anyone know why I do have this problem described on my first post ?
10-25-2009, 06:43 AM
Now, my second version of code has a class and the variable , which are given as parameters in the first version, are now member variables of the class......
.... Is there any openCL policies like "not allowed to hold cl_command_queueu or cl_kernel as member variables of a class" ???
No, no rules like that. I'm doing it all the time without problems.
The retain count you give is 0xFEEEFEEE in hex, which looks to me like a pattern somebody might use to blank out a released piece of memory, or possibly an error code. I expect that your member variable is being corrupted somehow, or something else is releasing the command queue between when you set the member variable and when you use it.
My suggestion is to add some debug callbacks to your context (see clCreateContext) as these might give you some clues as to what is going wrong. They did for me when I was trying the debug why a command queue became invalid. Also adding some checking of error codes returned by the functions will let you see the first point that an error occurs.
BTW: What platform are you on?
10-25-2009, 03:40 PM
like I said, as I come to the place before clEnqueueNDRangeKernel, there are no problems, because I dont get any error indicating that context or commandqueue is not valid. I do use both clGet...Info() and clRelease() . If one of the would be invalid, then those calls should deliver an error message indicating that the member variables are invalid, but all of them deliver error msg CL_SUCCEDED. And clGet..Info delivers for both of them ref count 1, which is normal.
What I do is the following:
After building the object, I call an init() function, where Context and everything is initialized. clSetKernelArgs are also done in init(). Right after init() , I call the method which I wrote about in the first post. In that sense , nothing should be invalid , and like I sad I dont get err msg indicating something is invalid.
I tried with callback function. The function is never being called.
I still couldnt find out where the problem is.
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.