private void InitCL(String[] kernelSource, String[] kernelNames, string compileArguments)
        {
            lock (lockObj)
            {
                if (!hasClInitialized && clDevice != null)
                {
                    Result err;
                    var    devicesArray = new IntPtr[] { clDevice };
                    clContext = ContextsNativeApi.CreateContext(IntPtr.Zero, 1, devicesArray, IntPtr.Zero, IntPtr.Zero, out err);
                    if (err != Result.Success)
                    {
                        throw new OpenClException("Failed to create context!", err);
                    }

                    commandQueue = CommandQueuesNativeApi.CreateCommandQueue(clContext, clDevice, CommandQueueProperty.None, out err);
                    if (err != Result.Success)
                    {
                        throw new OpenClException("Failed to create command queue!", err);
                    }

                    IntPtr[] sourceList = kernelSource.Select(source => Marshal.StringToHGlobalAnsi(source)).ToArray();
                    clProgram = ProgramsNativeApi.CreateProgramWithSource(clContext, 1, sourceList, null, out err);
                    if (err != Result.Success)
                    {
                        throw new OpenClException("Failed to create program!", err);
                    }

                    err = ProgramsNativeApi.BuildProgram(clProgram, 1, new IntPtr[] { clDevice }, compileArguments, IntPtr.Zero, IntPtr.Zero);
                    if (err != Result.Success)
                    {
                        var infoBuffer = GetProgramBuildInformation <string>(clProgram, clDevice, ProgramBuildInformation.Log);
                        if (err != Result.Success)
                        {
                            throw new OpenClException("Failed to build program! " + (infoBuffer == null ? "?" : infoBuffer.ToString()), err);
                        }
                    }

                    foreach (var item in kernelNames)
                    {
                        kernels[item] = KernelsNativeApi.CreateKernel(clProgram, item, out err);
                        if (err != Result.Success)
                        {
                            throw new OpenClException("Failed to create kernel: " + item, err);
                        }
                    }

                    hasClInitialized = true;
                }
            }
        }
        //public void EnqueueAcquireGLObjects(MemoryObject[] objs)
        //{
        //    IntPtr waitEventPointer;
        //    Result result = EnqueuedCommandsNativeApi.EnqueueAcquireGLObjects(this.Handle, (uint)objs.Length, objs.Select(x=>x.Handle).ToArray(), 0, null, out waitEventPointer);

        //    // Checks if the kernel was enqueued successfully, if not, then an exception is thrown
        //    if (result != Result.Success)
        //        throw new OpenClException("The Gl Objects could not be acuired.", result);
        //}

        //public void EnqueueReleaseGLObjects(MemoryObject[] objs)
        //{
        //    IntPtr waitEventPointer;
        //    Result result = EnqueuedCommandsNativeApi.EnqueueReleaseGLObjects(this.Handle, (uint)objs.Length, objs.Select(x => x.Handle).ToArray(), 0, null, out waitEventPointer);

        //    // Checks if the kernel was enqueued successfully, if not, then an exception is thrown
        //    if (result != Result.Success)
        //        throw new OpenClException("The Gl Objects could not be acuired.", result);
        //}

        #endregion

        #region Public Static Methods

        /// <summary>
        /// Creates a new command queue for the specified context and device.
        /// </summary>
        /// <param name="context">The context for which the command queue is to be created.</param>
        /// <param name="device">The devices for which the command queue is to be created.</param>
        /// <exception cref="OpenClException">If the command queue could not be created, then an <see cref="OpenClException"/> exception is thrown.</exception>
        /// <returns>Returns the created command queue.</returns>
        public static CommandQueue CreateCommandQueue(Context context, Device device)
        {
            // Creates the new command queue for the specified context and device
            Result result;
            IntPtr commandQueuePointer = CommandQueuesNativeApi.CreateCommandQueue(context.Handle, device.Handle, 0, out result);

            // Checks if the command queue creation was successful, if not, then an exception is thrown
            if (result != Result.Success)
            {
                throw new OpenClException("The command queue could not be created.", result);
            }

            // Creates the new command queue object from the pointer and returns it
            return(new CommandQueue(commandQueuePointer));
        }