/// <summary> /// Init OpenCL C language information. /// </summary> private void InitCInfo() { // Determine the supported OpenCL C version var clVersionString = CurrentAPI.GetDeviceInfo( DeviceId, CLDeviceInfoType.CL_DEVICE_OPENCL_C_VERSION); if (!CLCVersion.TryParse(clVersionString, out CLCVersion version)) { version = CLCVersion.CL10; } CVersion = version; }
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)); }
/// <summary> /// Constructs a new OpenCL accelerator reference. /// </summary> /// <param name="platformId">The OpenCL platform id.</param> /// <param name="deviceId">The OpenCL device id.</param> public CLAcceleratorId(IntPtr platformId, IntPtr deviceId) : base(AcceleratorType.OpenCL) { if (platformId == IntPtr.Zero) { throw new ArgumentOutOfRangeException(nameof(platformId)); } if (deviceId == IntPtr.Zero) { throw new ArgumentOutOfRangeException(nameof(deviceId)); } PlatformId = platformId; DeviceId = deviceId; DeviceType = (CLDeviceType)CLAPI.GetDeviceInfo <long>( deviceId, CLDeviceInfoType.CL_DEVICE_TYPE); // Resolve extensions var extensionString = CLAPI.GetDeviceInfo( DeviceId, CLDeviceInfoType.CL_DEVICE_EXTENSIONS); extensionSet = new HashSet <string>( extensionString.ToLower().Split(' ')); Extensions = extensionSet.ToImmutableArray(); // Determine the supported OpenCL C version var clVersionString = CLAPI.GetDeviceInfo( DeviceId, CLDeviceInfoType.CL_DEVICE_OPENCL_C_VERSION); if (!CLCVersion.TryParse(clVersionString, out CLCVersion version)) { version = CLCVersion.CL10; } CVersion = version; // Resolve extension method getKernelSubGroupInfo = CLAPI.GetExtension <clGetKernelSubGroupInfoKHR>( platformId); }