internal void InitializeInternal(CLMem openclMem, SizeT sizeInternal, Context context, DeviceBufferAccess access) { this.Access = access; this.Context = context; this.openCLMem = openclMem; this.openCLMemSize = sizeInternal; }
internal override void SetAsKernelArgument(CLKernel kernel, int index) { var clMem = new CLMem { Value = openCLSampler.Value }; OpenCLError.Validate(OpenCLDriver.clSetKernelArg(kernel, index, new SizeT(IntPtr.Size), ref clMem)); }
public static DeviceImage CreateFromTexture2D(UInt32 texture, Int32 mipLevel, DeviceBufferAccess access, Context context) { CLError error = CLError.None; CLMem mem = ManOCL.Internal.OpenCL.OpenGL.OpenCLGLDriver.clCreateFromGLTexture2D(context.CLContext, GetMemFlags(access), 3553 /* GL_TEXTURE_2D */, mipLevel, texture, ref error); OpenCLError.Validate(error); DeviceImage result = new DeviceImage(new Mem { Value = mem.Value }); return(result); }
private static Event WriteBytesInternal(CLMem openCLMem, CommandQueue commandQueue, Array array, Int64 bytesToCopy, Int64 arrayOffset, Int64 arraySize, Int64 bufferOffset, Int64 bufferSize, Events eventWaitList, WriteOperation writeDelegate) { if (bufferSize < bufferOffset + bytesToCopy) { throw new ArgumentException(Resources.Buffer_out_of_bounds); } if (arraySize < arrayOffset + bytesToCopy) { throw new ArgumentException(Resources.Array_out_of_bounds); } GCHandle valueHandle = GCHandle.Alloc(array, GCHandleType.Pinned); try { CLEvent e = new CLEvent(); unsafe { IntPtr valuePtr = new IntPtr((Byte *)(valueHandle.AddrOfPinnedObject().ToPointer()) + arrayOffset); OpenCLError.Validate ( writeDelegate ( commandQueue.CLCommandQueue, openCLMem, CLBool.True, new SizeT(bufferOffset), new SizeT(bytesToCopy), valuePtr, eventWaitList == null ? 0 : eventWaitList.Count, eventWaitList == null ? null : eventWaitList.OpenCLEventArray, ref e ) ); } return(new Event(e)); } finally { valueHandle.Free(); } }
/// <summary> /// Multiply an array by a constant value /// </summary> internal static void Multiply() { try { CLError err = new CLError(); //Allocate memory float[] arr = new float[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; GCHandle arrGC = GCHandle.Alloc(arr, GCHandleType.Pinned); CLMem bufferFilter = OpenCLDriver.clCreateBuffer(ctx, CLMemFlags.ReadWrite | CLMemFlags.CopyHostPtr, new SizeT(arr.Length * sizeof(float)), arrGC.AddrOfPinnedObject(), ref err); //set parameters unsafe { OpenCLDriver.clSetKernelArg(kernel_mult, 0, new SizeT(sizeof(CLMem)), ref bufferFilter); } //Define grid & execute err = OpenCLDriver.clFinish(comQ); SizeT[] localws = { 5, 1 }; SizeT[] globalws = { 10, 1 }; CLEvent eventObj = new CLEvent(); err = OpenCLDriver.clEnqueueNDRangeKernel(comQ, kernel_mult, 2, null, globalws, localws, 0, null, ref eventObj); CLEvent[] eventObjs = new CLEvent[1]; eventObjs[0] = eventObj; OpenCLDriver.clWaitForEvents(1, eventObjs); // read buffer err = OpenCLDriver.clEnqueueReadBuffer(comQ, bufferFilter, CLBool.True, 0, 10 * sizeof(float), arrGC.AddrOfPinnedObject(), 0, null, ref eventObj); TableForm.ShowTableStatic(arr, "OpenCL Test"); } catch (Exception exc) { MessageBox.Show(exc.ToString()); } }
public static extern CLError clGetGLTextureInfo( CLMem memobj, uint param_name, SizeT param_value_size, IntPtr param_value, ref SizeT param_value_size_ret);
public static extern CLError clGetGLObjectInfo( CLMem memobj, ref uint gl_object_type, ref uint gl_object_name);