extern internal static ComputeErrorCode BuildProgram( CLProgramHandle program, Int32 num_devices, [MarshalAs(UnmanagedType.LPArray)] CLDeviceHandle[] device_list, String options, ComputeProgramBuildNotifier pfn_notify, IntPtr user_data);
private void notify(CLProgramHandle programHandle, IntPtr userDataPtr) { log.WriteLine("Program build notification."); byte[] bytes = program.Binaries[0]; log.WriteLine("Beginning of program binary (compiled for the 1st selected device):"); log.WriteLine(BitConverter.ToString(bytes, 0, 24) + "..."); }
extern internal static ComputeErrorCode GetProgramBuildInfo( CLProgramHandle program, CLDeviceHandle device, ComputeProgramBuildInfo param_name, IntPtr param_value_size, IntPtr param_value, out IntPtr param_value_size_ret);
public GPURadixSort( ComputeCommandQueue commandQue, ComputeContext context, ComputeDevice device ) { gpuConstants = new GPUConstants(); gpuConstants.L = radix_BitsL; gpuConstants.numGroupsPerBlock = NumGroupsPerBlock; gpuConstants.R = R; gpuConstants.numThreadsPerGroup = numThreadsPerBlock / NumGroupsPerBlock; gpuConstants.numThreadsPerBlock = numThreadsPerBlock; gpuConstants.numBlocks = numBlocks; gpuConstants.numRadices = num_Radices; gpuConstants.numRadicesPerBlock = num_Radices / numBlocks; gpuConstants.bitMask = BIT_MASK_START; counters.Initialize(); ComputeErrorCode error; cxGPUContext = context.Handle; cqCommandQueue = commandQue.Handle; _device = device.Handle; //Create a command queue, where all of the commands for execution will be added /*cqCommandQueue = CL10.CreateCommandQueue(cxGPUContext, _device, (CommandQueueProperties)0, out error); * CheckErr(error, "CL10.CreateCommandQueue");*/ string programSource = System.IO.File.ReadAllText(programPath); IntPtr[] progSize = new IntPtr[] { (IntPtr)programSource.Length }; string flags = "-cl-fast-relaxed-math"; ComputeProgram prog = new ComputeProgram(context, programSource); prog.Build(new List <ComputeDevice>() { device }, flags, null, IntPtr.Zero); if (prog.GetBuildStatus(device) != ComputeProgramBuildStatus.Success) { Debug.WriteLine(prog.GetBuildLog(device)); throw new ArgumentException("UNABLE to build programm"); } // ComputeProgram clProgramRadix = CL10.CreateProgramWithSource(cxGPUContext, 1, new[] { programSource },progSize, // out error); CLProgramHandle clProgramRadix = prog.Handle; ckSetupAndCount = CL10.CreateKernel(clProgramRadix, "SetupAndCount", out error); CheckErr(error, "CL10.CreateKernel"); ckSumIt = CL10.CreateKernel(clProgramRadix, "SumIt", out error); CheckErr(error, "CL10.CreateKernel"); ckReorderingKeysOnly = CL10.CreateKernel(clProgramRadix, "ReorderingKeysOnly", out error); CheckErr(error, "CL10.CreateKernel"); ckReorderingKeyValue = CL10.CreateKernel(clProgramRadix, "ReorderingKeyValue", out error); CheckErr(error, "CL10.CreateKernel"); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Creates a new <see cref="ComputeProgram"/> from an array of source code strings. /// </summary> /// /// <remarks> /// The created <see cref="ComputeProgram"/> is associated with the /// <see cref="ComputeContext.Devices"/>. /// </remarks> /// /// <param name="context"> A <see cref="ComputeContext"/>. </param> /// <param name="source"> The source code lines for the <see cref="ComputeProgram"/>. </param> //////////////////////////////////////////////////////////////////////////////////////////////////// public ComputeProgram(ComputeContext context, string[] source) { Ensure.Argument(context).NotNull("context is null"); Handle = CL12.CreateProgramWithSource(context.Handle, source.Length, source, null, out var error); ComputeException.ThrowOnError(error); this.context = context; devices = context.Devices; this.source = new ReadOnlyCollection <string>(source); RILogManager.Default?.SendTrace("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information"); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Creates a new <see cref="ComputeProgram"/> from a specified list of binaries. /// </summary> /// /// <param name="context"> A <see cref="ComputeContext"/>. </param> /// <param name="binaries"> A list of binaries, one for each item in <paramref name="devices"/>. </param> /// <param name="devices"> A subset of the <see cref="ComputeContext.Devices"/>. If /// <paramref name="devices"/> is <c>null</c>, OpenCL will associate /// every binary from <see cref="ComputeProgram.Binaries"/> with a /// corresponding <see cref="ComputeDevice"/> from /// <see cref="ComputeContext.Devices"/>. </param> //////////////////////////////////////////////////////////////////////////////////////////////////// public ComputeProgram(ComputeContext context, IList <byte[]> binaries, IList <ComputeDevice> devices) { int count; Ensure.Argument(context).NotNull("context is null"); CLDeviceHandle[] deviceHandles = (devices != null) ? ComputeTools.ExtractHandles(devices, out count) : ComputeTools.ExtractHandles(context.Devices, out count); IntPtr[] binariesPtrs = new IntPtr[count]; IntPtr[] binariesLengths = new IntPtr[count]; int[] binariesStats = new int[count]; GCHandle[] binariesGCHandles = new GCHandle[count]; try { for (int i = 0; i < count; i++) { binariesGCHandles[i] = GCHandle.Alloc(binaries[i], GCHandleType.Pinned); binariesPtrs[i] = binariesGCHandles[i].AddrOfPinnedObject(); binariesLengths[i] = new IntPtr(binaries[i].Length); } Handle = CL12.CreateProgramWithBinary(context.Handle, count, deviceHandles, binariesLengths, binariesPtrs, binariesStats, out var error); ComputeException.ThrowOnError(error); } finally { for (int i = 0; i < count; i++) { binariesGCHandles[i].Free(); } } this.binaries = new ReadOnlyCollection <byte[]>(binaries); this.context = context; this.devices = new ReadOnlyCollection <ComputeDevice>((devices != null) ? devices : context.Devices); RILogManager.Default?.SendTrace("Create " + this + " in Thread(" + Thread.CurrentThread.ManagedThreadId + ").", "Information"); }
extern internal static CLKernelHandle CreateKernel(CLProgramHandle program, string kernel_name, out ComputeErrorCode errcode_ret);
extern internal static ComputeErrorCode CreateKernelsInProgram( CLProgramHandle program, Int32 num_kernels, [Out, MarshalAs(UnmanagedType.LPArray)] CLKernelHandle[] kernels, out Int32 num_kernels_ret);
extern internal static ComputeErrorCode ReleaseProgram(CLProgramHandle program);