/// <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; }
internal CLKernel( CLAccelerator accelerator, CLCompiledKernel kernel, MethodInfo launcher) : base(accelerator, kernel, launcher) { CLException.ThrowIfFailed(LoadKernel( accelerator, kernel.Source, out programPtr, out kernelPtr)); }
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);
/// <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)); }
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; }
/// <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); }
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 }