public IntPtr CreateBuffer(uint size, CLEnum flags) { var result = Bindings.OpenCl.CreateBuffer( Handle, flags, (UIntPtr)size, Span <byte> .Empty, Span <int> .Empty ); if (result == IntPtr.Zero) { throw new Exception("Failed to allocate device memory!"); } var error = (CLEnum)Bindings.OpenCl.RetainMemObject(result); if (error != CLEnum.Success) { throw new Exception("Failed to retain device memory!"); } OpenBuffers.Add(result); return(result); }
public IntPtr CreateBufferHost <T>(Span <T> span) where T : unmanaged { var error = new int[1]; var result = Bindings.OpenCl.CreateBuffer( Handle, CLEnum.MemUseHostPtr, (UIntPtr)(span.Length * Marshal.SizeOf <T>()), span, new Span <int>(error) ); if (result == IntPtr.Zero) { throw new Exception("Failed to allocate device host memory!"); } var retainError = (CLEnum)Bindings.OpenCl.RetainMemObject(result); if (retainError != CLEnum.Success) { throw new Exception("Failed to retain device host memory!"); } OpenBuffers.Add(result); return(result); }
public unsafe IntPtr AllocBufferHost(uint size) { /* TODO: Figure out why this fails */ var error = 0; var ptr = 0; var result = Bindings.OpenCl.CreateBuffer( Handle, CLEnum.MemAllocHostPtr | CLEnum.MemReadWrite, (UIntPtr)size, &ptr, &error ); if (result == IntPtr.Zero) { throw new Exception("Failed to allocate device host memory!"); } OpenBuffers.Add(result); return(result); }