/// <summary> /// Enqueues a command to unmap a buffer or a <see cref="OpenCLImage"/> from the host address space. /// </summary> /// <param name="memory"> The <see cref="OpenCLMemory"/>. </param> /// <param name="mappedPtr"> The host address returned by a previous call to <see cref="OpenCLCommandQueue.Map"/>. This pointer is <c>IntPtr.Zero</c> after this method returns. </param> /// <param name="events"> A collection of events that need to complete before this particular command can be executed. If <paramref name="events"/> is not <c>null</c> or read-only a new <see cref="OpenCLEvent"/> identifying this command is created and attached to the end of the collection. </param> public void Unmap(OpenCLMemory memory, ref IntPtr mappedPtr, IReadOnlyList <OpenCLEventBase> events = null, IList <OpenCLEventBase> newEvents = null) { int eventWaitListSize; CLEventHandle[] eventHandles = OpenCLTools.ExtractHandles(events, out eventWaitListSize); CLEventHandle[] newEventHandle = (newEvents != null) ? new CLEventHandle[1] : null; OpenCLErrorCode error = CL10.EnqueueUnmapMemObject(Handle, memory.Handle, mappedPtr, eventWaitListSize, eventHandles, newEventHandle); OpenCLException.ThrowOnError(error); mappedPtr = IntPtr.Zero; if (newEvents != null) { lock (newEvents) { newEvents.Add(new OpenCLEvent(newEventHandle[0], this)); } } }
/// <summary> /// Enqueues a command to unmap a buffer or a <see cref="OpenCLImage"/> from the host address space. /// </summary> /// <param name="memory"> The <see cref="OpenCLMemory"/>. </param> /// <param name="mappedPtr"> The host address returned by a previous call to <see cref="OpenCLCommandQueue.Map"/>. This pointer is <c>IntPtr.Zero</c> after this method returns. </param> /// <param name="events"> A collection of events that need to complete before this particular command can be executed. If <paramref name="events"/> is not <c>null</c> or read-only a new <see cref="OpenCLEvent"/> identifying this command is created and attached to the end of the collection. </param> public void Unmap(OpenCLMemory memory, ref IntPtr mappedPtr, IReadOnlyList<OpenCLEventBase> events = null, IList<OpenCLEventBase> newEvents = null) { int eventWaitListSize; CLEventHandle[] eventHandles = OpenCLTools.ExtractHandles(events, out eventWaitListSize); CLEventHandle[] newEventHandle = (newEvents != null) ? new CLEventHandle[1] : null; OpenCLErrorCode error = CL10.EnqueueUnmapMemObject(Handle, memory.Handle, mappedPtr, eventWaitListSize, eventHandles, newEventHandle); OpenCLException.ThrowOnError(error); mappedPtr = IntPtr.Zero; if (newEvents != null) { lock (newEvents) { newEvents.Add(new OpenCLEvent(newEventHandle[0], this)); } } }
/// <summary> /// Sets a <c>T*</c>, <c>image2d_t</c> or <c>image3d_t</c> argument of the <see cref="OpenCLKernel"/>. /// </summary> /// <param name="index"> The argument index. </param> /// <param name="memObj"> The <see cref="OpenCLMemory"/> that is passed as the argument. </param> /// <remarks> This method will automatically track <paramref name="memObj"/> to prevent it from being collected by the GC.<br/> Arguments to the kernel are referred by indices that go from 0 for the leftmost argument to n-1, where n is the total number of arguments declared by the kernel. </remarks> public void SetMemoryArgument(int index, OpenCLMemory memObj) { //Console.WriteLine("Setting memory argument at " + index); SetValueArgument <CLMemoryHandle>(index, memObj.Handle); }