/// <summary> /// Execute the kernel /// </summary> /// <param name="globalsize">The global size</param> /// <param name="localsize">The local size</param> /// <param name="sync">If true, the code is run synchronously (blocking)</param> /// <param name="q">Optional Opencl queue</param> /// <returns>True if the execution is sucessful</returns> public bool Run(IntPtr[] globalsize, IntPtr[] localsize, bool sync, Queue q = null) { Debug.Assert(localsize == null || globalsize.Length == localsize.Length, "The dimension of global size do not match the dimension of local size."); GCHandle gHandle = GCHandle.Alloc(globalsize, GCHandleType.Pinned); GCHandle lHandle; if (localsize != null) { lHandle = GCHandle.Alloc(localsize, GCHandleType.Pinned); } else { lHandle = new GCHandle(); } try { return(OclInvoke.oclKernelRun( _ptr, globalsize.Length, gHandle.AddrOfPinnedObject(), localsize == null ? IntPtr.Zero : lHandle.AddrOfPinnedObject(), sync, q)); } finally { gHandle.Free(); if (localsize != null) { lHandle.Free(); } } }