예제 #1
0
 /// <summary>
 /// Constructs a new OpenCL buffer.
 /// </summary>
 /// <param name="accelerator">The accelerator.</param>
 /// <param name="extent">The extent.</param>
 internal CLMemoryBuffer(CLAccelerator accelerator, TIndex extent)
     : base(accelerator, extent)
 {
     CLException.ThrowIfFailed(
         CLAPI.CreateBuffer(
             accelerator.ContextPtr,
             CLBufferFlags.CL_MEM_KERNEL_READ_AND_WRITE,
             new IntPtr(extent.Size * ElementSize),
             IntPtr.Zero,
             out IntPtr resultPtr));
     NativePtr = resultPtr;
 }
예제 #2
0
 internal CLKernel(
     CLAccelerator accelerator,
     CLCompiledKernel kernel,
     MethodInfo launcher)
     : base(accelerator, kernel, launcher)
 {
     CLException.ThrowIfFailed(LoadKernel(
                                   accelerator,
                                   kernel.Source,
                                   out programPtr,
                                   out kernelPtr));
 }
예제 #3
0
파일: CLKernel.cs 프로젝트: rpfeuti/ILGPU
 public static CLError LoadKernel(
     CLAccelerator accelerator,
     string source,
     CLCVersion version,
     out IntPtr programPtr,
     out IntPtr kernelPtr,
     out string errorLog) =>
 LoadKernel(
     accelerator,
     CLCompiledKernel.EntryName,
     source,
     version,
     out programPtr,
     out kernelPtr,
     out errorLog);
예제 #4
0
        /// <summary>
        /// Loads the given OpenCL kernel.
        /// </summary>
        /// <param name="accelerator">The associated accelerator.</param>
        /// <param name="name">The name of the entry-point function.</param>
        /// <param name="source">The OpenCL source code.</param>
        /// <param name="version">The OpenCL C version.</param>
        /// <param name="programPtr">The created program pointer.</param>
        /// <param name="kernelPtr">The created kernel pointer.</param>
        /// <param name="errorLog">The error log (if any).</param>
        /// <returns>
        /// True, if the program and the kernel could be loaded successfully.
        /// </returns>
        public static CLError LoadKernel(
            CLAccelerator accelerator,
            string name,
            string source,
            CLCVersion version,
            out IntPtr programPtr,
            out IntPtr kernelPtr,
            out string errorLog)
        {
            errorLog  = null;
            kernelPtr = IntPtr.Zero;
            var programError = CurrentAPI.CreateProgram(
                accelerator.NativePtr,
                source,
                out programPtr);

            if (programError != CLError.CL_SUCCESS)
            {
                return(programError);
            }

            // Specify the OpenCL C version.
            string options = "-cl-std=" + version.ToString();

            var buildError = CurrentAPI.BuildProgram(
                programPtr,
                accelerator.DeviceId,
                options);

            if (buildError != CLError.CL_SUCCESS)
            {
                CLException.ThrowIfFailed(
                    CurrentAPI.GetProgramBuildLog(
                        programPtr,
                        accelerator.DeviceId,
                        out errorLog));
                CLException.ThrowIfFailed(
                    CurrentAPI.ReleaseProgram(programPtr));
                programPtr = IntPtr.Zero;
                return(buildError);
            }

            return(CurrentAPI.CreateKernel(
                       programPtr,
                       name,
                       out kernelPtr));
        }
예제 #5
0
파일: CLStream.cs 프로젝트: losttech/ILGPU
        internal CLStream(CLAccelerator accelerator)
            : base(accelerator)
        {
            CLCommandQueueProperties properties =
                Accelerator.Context.Properties.EnableProfiling
                ? CLCommandQueueProperties.CL_QUEUE_PROFILING_ENABLE
                : default;

            CLException.ThrowIfFailed(
                CurrentAPI.CreateCommandQueue(
                    accelerator.PlatformVersion,
                    accelerator.DeviceId,
                    accelerator.NativePtr,
                    properties,
                    out queuePtr));
            responsibleForHandle = true;
        }
예제 #6
0
        /// <summary>
        /// Loads the given OpenCL kernel.
        /// </summary>
        /// <param name="accelerator">The associated accelerator.</param>
        /// <param name="source">The OpenCL source code.</param>
        /// <param name="programPtr">The created program pointer.</param>
        /// <param name="kernelPtr">The created kernel pointer.</param>
        /// <returns>True, if the program and the kernel could be loaded successfully.</returns>
        internal static CLError LoadKernel(
            CLAccelerator accelerator,
            string source,
            out IntPtr programPtr,
            out IntPtr kernelPtr)
        {
            kernelPtr = IntPtr.Zero;
            var error = CLAPI.CreateProgram(
                accelerator.ContextPtr,
                source,
                out programPtr);

            if (error != CLError.CL_SUCCESS)
            {
                return(error);
            }

            // TODO: OpenCL compiler options
            string options = string.Empty;

            error |= CLAPI.BuildProgram(
                programPtr,
                accelerator.DeviceId,
                options);

            error |= CLAPI.CreateKernel(
                programPtr,
                CLCompiledKernel.EntryName,
                out kernelPtr);

            if (error != CLError.CL_SUCCESS)
            {
                CLException.ThrowIfFailed(
                    CLAPI.ReleaseProgram(programPtr));
                programPtr = IntPtr.Zero;
            }
            return(error);
        }
예제 #7
0
        public CLKernel(
            CLAccelerator accelerator,
            CLCompiledKernel kernel,
            MethodInfo launcher)
            : base(accelerator, kernel, launcher)
        {
#if DEBUG
            var errorCode = LoadKernel(
                accelerator,
                kernel.Source,
                kernel.CVersion,
                out programPtr,
                out kernelPtr,
                out var errorLog);
            if (errorCode != CLError.CL_SUCCESS)
            {
                Debug.WriteLine("Kernel loading failed:");
                if (string.IsNullOrWhiteSpace(errorLog))
                {
                    Debug.WriteLine(">> No error information available");
                }
                else
                {
                    Debug.WriteLine(errorLog);
                }
            }
            CLException.ThrowIfFailed(errorCode);
#else
            CLException.ThrowIfFailed(LoadKernel(
                                          accelerator,
                                          kernel.Source,
                                          kernel.CVersion,
                                          out programPtr,
                                          out kernelPtr,
                                          out var _));
#endif
        }