Пример #1
0
        /// <summary>
        /// Set a <see cref="MemoryObject"/> argument (<see cref="Buffer"/> or <see cref="Image"/>) for <see cref="Kernel"/> execution.
        /// </summary>
        /// <param name="index">Is the argument index. Arguments to the kernel are referred by indices that go from 0 for the leftmost argument to n - 1, where n is the total number of arguments declared by a kernel. </param>
        /// <param name="memoryObject">The memory object to set as argument.</param>
        /// <returns></returns>
        public bool SetArgument(UInt32 index, MemoryObject memoryObject)
        {
            GCHandle gcHandle = GCHandle.Alloc(memoryObject.Handle, GCHandleType.Pinned);

            error = clSetKernelArg(Handle, index, new UIntPtr((UInt64)Marshal.SizeOf <IntPtr>()), gcHandle.AddrOfPinnedObject());
            gcHandle.Free();
            return(error == ErrorCode.Success);
        }
Пример #2
0
        /// <summary>
        /// Creates a monodimensional <see cref="Image"/> using the data from a buffer.
        /// </summary>
        /// <typeparam name="DataType">The type of image data.</typeparam>
        /// <param name="buffer">The buffer from where the image pixels are taken.</param>
        /// <param name="data">An array of data to use with the image.</param>
        /// <param name="width">The width of the image.</param>
        /// <param name="memoryFlags">Is used to specify allocation and usage information about the image memory object being created.</param>
        /// <param name="channelOrder">Specifies the number of channels and the channel layout.</param>
        /// <param name="channelType">Describes the size of the channel data type.</param>
        /// <returns>A new image.</returns>
        public Image CreateImage1DBuffer <DataType>(MemoryObject buffer, DataType[] data, UInt64 width, MemoryFlags memoryFlags, ImageChannelOrder channelOrder, ImageChannelType channelType)
        {
            ImageFormat format = new ImageFormat
            {
                ChannelOrder = channelOrder,
                ChannelType  = channelType
            };
            ImageDescriptor descriptor = new ImageDescriptor
            {
                ImageType       = MemoryObjectType.Image1DBuffer,
                Width           = new UIntPtr(width),
                Height          = new UIntPtr(1),
                Depth           = new UIntPtr(1),
                ImageArraySize  = UIntPtr.Zero,
                ImageRowPitch   = UIntPtr.Zero,
                ImageSlicePitch = UIntPtr.Zero,
                NumMipLevels    = 0,
                NumSamples      = 0,
                Buffer          = buffer.Handle
            };

            return(CreateImage <DataType>(data, memoryFlags, format, descriptor));
        }
Пример #3
0
 /// <summary>
 /// Creates a monodimensional <see cref="Image"/> using the data from a buffer.
 /// </summary>
 /// <param name="buffer">The buffer from where the image pixels are taken.</param>
 /// <param name="width">The width of the image.</param>
 /// <param name="memoryFlags">Is used to specify allocation and usage information about the image memory object being created.</param>
 /// <param name="channelOrder">Specifies the number of channels and the channel layout.</param>
 /// <param name="channelType">Describes the size of the channel data type.</param>
 /// <returns>A new image.</returns>
 public Image CreateImage1DBuffer(MemoryObject buffer, UInt64 width, MemoryFlags memoryFlags, ImageChannelOrder channelOrder, ImageChannelType channelType)
 {
     return(CreateImage1DBuffer <dynamic>(buffer, null, width, memoryFlags, channelOrder, channelType));
 }