
Cloo : memory access problem
Posted Sunday, 20 December, 2009 - 13:45 by viewon01 inHi,
I use Cloo to execute some OpenCL and when I call the Queue.Execute(Kernel, globalWorkSize, null, null);
I got the following error : "Attempted to read or write protected memory."
Here is my code (where proxy just call the Cloo methos):
ComputeBuffer<OCLMITData> mitDataCB = new ComputeBuffer<OCLMITData>(_proxy.Context, MemFlags.MemReadOnly | MemFlags.MemCopyHostPtr, mitData); _proxy.Kernel.SetMemoryArg(0, mitDataCB); _proxy.Kernel.SetValueArg(1, (Vector4)ray.Origin); _proxy.Kernel.SetValueArg(2, (Vector4)ray.Direction); _proxy.Kernel.SetValueArg(3, ray.Maximum); _proxy.Kernel.SetValueArg(4, ray.IsShadowRay ? 1 : 0); _proxy.Kernel.SetValueArg(5, _rayOffset); ComputeBuffer<BoundingVolume> nodesCB = new ComputeBuffer<BoundingVolume>(_proxy.Context, MemFlags.MemReadOnly | MemFlags.MemCopyHostPtr, _nodes); _proxy.Kernel.SetMemoryArg(6, nodesCB); ComputeBuffer<int> primitivesIdsCB = new ComputeBuffer<int>(_proxy.Context, MemFlags.MemReadOnly | MemFlags.MemCopyHostPtr, _primitivesIds); _proxy.Kernel.SetMemoryArg(7, primitivesIdsCB); TriangleMesh mesh = (TriangleMesh)_primitiveList; ComputeBuffer<int> indicesCB = new ComputeBuffer<int>(_proxy.Context, MemFlags.MemReadOnly | MemFlags.MemCopyHostPtr, mesh.Indices); _proxy.Kernel.SetMemoryArg(8, indicesCB); ComputeBuffer<float> pointsCB = new ComputeBuffer<float>(_proxy.Context, MemFlags.MemReadOnly | MemFlags.MemCopyHostPtr, mesh.Points); _proxy.Kernel.SetMemoryArg(9, pointsCB); ComputeBuffer<OCLIntersectionResult> oclResultCB = new ComputeBuffer<OCLIntersectionResult>(_proxy.Context, MemFlags.MemReadWrite | MemFlags.MemCopyHostPtr, oclResult); _proxy.Kernel.SetMemoryArg(10, oclResultCB); _proxy.Execute(new int[] { 1 });


Comments
Re: Cloo : memory access problem
I usually get this kind of error after wrongly setting a kernel (memory) argument. It pops out during
ComputeJobQueue.Execute(..)when the kernel tries to actually read or write the said argument. However, there's always a chance this is a Cloo bug. Can you post some code that I can actually debug?Edit: A second look into that code dismissed my hypothesis. Nevertheless, I could still use a small test case.
Re: Cloo : memory access problem
I have try on the AMD driver and when I do :
Kernel.SetValueArg(1, origin);
I got the following exception : "InvalidMemoryObjectComputeException" error : -38
Where origin is declared like this :
Vector4 origin;
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public struct Vector4
{
public float x, y, z, w;
}
Re: Cloo : memory access problem
How does the kernel signature look like?
Re: Cloo : memory access problem
Here is my ".cl" code :
Re: Cloo : memory access problem
Observations:
1)
T*maps toComputeBuffer<T>.2) if you need to pass a value you have to define it as
Tin the kernel.That said you need to change you kernel signature to
... float4 origin, float4 direction, float rayMaximum, int isShadowRay, // 1 = true, 0 = false float4 rayOffset, ...