예제 #1
0
            protected override void EnqueueWrite(CallContext CallContext, int i, long ElementCount, OpenCLNet.MemFlags MemFlags)
            {
                Type RealElementType = Value.GetType().GetElementType();
                int  ElementSize     = System.Runtime.InteropServices.Marshal.SizeOf(RealElementType);

#if USE_HOST_POINTER
                m_GCHandle = System.Runtime.InteropServices.GCHandle.Alloc(Value, System.Runtime.InteropServices.GCHandleType.Pinned);

                MemBuffer = CallContext.Context.CreateBuffer(MemFlags | OpenCLNet.MemFlags.USE_HOST_PTR, ElementCount * ElementSize, m_GCHandle.Value.AddrOfPinnedObject());
                CallContext.Kernel.SetArg(i, MemBuffer);
#else
                MemBuffer = CallContext.Context.CreateBuffer(MemFlags, ElementCount * ElementSize, IntPtr.Zero);
                CallContext.Kernel.SetArg(i, MemBuffer);

                //
                // If the buffer is read by the device, transfer the data
                //

                if (m_ForRead)
                {
                    System.Runtime.InteropServices.GCHandle gch = System.Runtime.InteropServices.GCHandle.Alloc(Value, System.Runtime.InteropServices.GCHandleType.Pinned);

                    try
                    {
                        IntPtr p = gch.Value.AddrOfPinnedObject();
                        CallContext.CommandQueue.EnqueueWriteBuffer(MemBuffer, true, IntPtr.Zero, new IntPtr(ElementCount * ElementSize), p);
                    }
                    finally
                    {
                        gch.Free();
                    }
                }
#endif
            }
예제 #2
0
 protected abstract void EnqueueWrite(CallContext CallContext, int i, long ElementCount, OpenCLNet.MemFlags MemFlags);
예제 #3
0
            protected override void EnqueueWrite(CallContext CallContext, int i, long ElementCount, OpenCLNet.MemFlags MemFlags)
            {
                Type RealElementType = Value.GetType().GetElementType();
                int  ElementSize     = System.Runtime.InteropServices.Marshal.SizeOf(RealElementType);

                m_GCHandle = System.Runtime.InteropServices.GCHandle.Alloc(Value, System.Runtime.InteropServices.GCHandleType.Pinned);

                MemBuffer = CallContext.Context.CreateBuffer(MemFlags | OpenCLNet.MemFlags.USE_HOST_PTR, ElementCount * ElementSize, m_GCHandle.Value.AddrOfPinnedObject());
                CallContext.Kernel.SetArg(i, MemBuffer);
            }