Exemplo n.º 1
0
        /// <summary>
        ///     Retrieves the specified information about the OpenCL kernel.
        /// </summary>
        /// <typeparam name="T">
        ///     The type of the data that is to be returned.</param>
        ///     <param name="kernelInformation">The kind of information that is to be retrieved.</param>
        ///     <exception cref="OpenClException">
        ///         If the information could not be retrieved, then an <see cref="OpenClException" />
        ///         is thrown.
        ///     </exception>
        ///     <returns>Returns the specified information.</returns>
        private T GetKernelInformation <T>(KernelInformation kernelInformation)
        {
            // Retrieves the size of the return value in bytes, this is used to later get the full information
            Result result =
                KernelsNativeApi.GetKernelInformation(
                    Handle,
                    kernelInformation,
                    UIntPtr.Zero,
                    null,
                    out UIntPtr returnValueSize
                    );

            if (result != Result.Success)
            {
                throw new OpenClException("The kernel information could not be retrieved.", result);
            }

            // Allocates enough memory for the return value and retrieves it
            byte[] output = new byte[returnValueSize.ToUInt32()];
            result = KernelsNativeApi.GetKernelInformation(
                Handle,
                kernelInformation,
                new UIntPtr((uint)output.Length),
                output,
                out returnValueSize
                );
            if (result != Result.Success)
            {
                throw new OpenClException("The kernel information could not be retrieved.", result);
            }

            // Returns the output
            return(InteropConverter.To <T>(output));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Retrieves the specified information about the program build.
        /// </summary>
        /// <typeparam name="T">The type of the data that is to be returned.</param>
        /// <param name="program">The handle to the program for which the build information is to be retrieved.</param>
        /// <param name="device">The device for which the build information is to be retrieved.</param>
        /// <param name="programBuildInformation">The kind of information that is to be retrieved.</param>
        /// <exception cref="OpenClException">If the information could not be retrieved, then an <see cref="OpenClException"/> is thrown.</exception>
        /// <returns>Returns the specified information.</returns>
        private T GetProgramBuildInformation <T>(IntPtr program, Device device,
                                                 ProgramBuildInformation programBuildInformation)
        {
            // Retrieves the size of the return value in bytes, this is used to later get the full information
            UIntPtr returnValueSize;
            Result  result = ProgramsNativeApi.GetProgramBuildInformation(program, device.Handle,
                                                                          programBuildInformation,
                                                                          UIntPtr.Zero, null, out returnValueSize);

            if (result != Result.Success)
            {
                throw new OpenClException("The program build information could not be retrieved.", result);
            }

            // Allocates enough memory for the return value and retrieves it
            byte[] output = new byte[returnValueSize.ToUInt32()];
            result = ProgramsNativeApi.GetProgramBuildInformation(program, device.Handle, programBuildInformation,
                                                                  new UIntPtr((uint)output.Length), output, out returnValueSize);
            if (result != Result.Success)
            {
                throw new OpenClException("The program build information could not be retrieved.", result);
            }

            // Returns the output
            return(InteropConverter.To <T>(output));
        }