/// <summary> /// Loads an implicitly grouped kernel on the current accelerator. /// </summary> /// <param name="kernel">The compiled kernel to load.</param> /// <param name="customGroupSize">The user-defined group size.</param> /// <param name="kernelInfo">The resolved kernel information.</param> /// <returns>The loaded kernel.</returns> protected sealed override Kernel LoadImplicitlyGroupedKernelInternal( CompiledKernel kernel, int customGroupSize, out KernelInfo kernelInfo) { if (kernel == null) { throw new ArgumentNullException(nameof(kernel)); } if (customGroupSize < 0 || customGroupSize > MaxNumThreadsPerGroup) { throw new ArgumentOutOfRangeException(nameof(customGroupSize)); } if (!(kernel is TCompiledKernel compiledKernel)) { throw new NotSupportedException(RuntimeErrorMessages.NotSupportedKernel); } if (kernel.EntryPoint.IsExplicitlyGrouped) { throw new NotSupportedException( RuntimeErrorMessages.NotSupportedExplicitlyGroupedKernel); } kernelInfo = KernelInfo.CreateFrom( kernel.Info, customGroupSize, null); return(CreateKernel( compiledKernel, GenerateKernelLauncherMethod(compiledKernel, customGroupSize))); }
/// <summary> /// Loads the given implicitly-grouped kernel while using an automatically /// computed grouping configuration. /// </summary> /// <param name="kernel">The kernel to load.</param> /// <param name="kernelInfo"> /// Detailed kernel information about the loaded kernel. /// </param> /// <returns>The loaded kernel.</returns> /// <remarks> /// Note that the returned kernel will not be managed by the kernel cache. /// </remarks> public Kernel LoadAutoGroupedKernel( CompiledKernel kernel, out KernelInfo kernelInfo) { Bind(); return(LoadAutoGroupedKernelInternal(kernel, out kernelInfo)); }
/// <summary> /// Loads an auto grouped kernel on the current accelerator. /// </summary> /// <param name="kernel">The compiled kernel to load.</param> /// <param name="kernelInfo">The resolved kernel information.</param> /// <returns>The loaded kernel.</returns> protected sealed override Kernel LoadAutoGroupedKernelInternal( CompiledKernel kernel, out KernelInfo kernelInfo) { if (kernel == null) { throw new ArgumentNullException(nameof(kernel)); } if (!(kernel is TCompiledKernel compiledKernel)) { throw new NotSupportedException(RuntimeErrorMessages.NotSupportedKernel); } if (kernel.EntryPoint.IsExplicitlyGrouped) { throw new NotSupportedException( RuntimeErrorMessages.NotSupportedExplicitlyGroupedKernel); } var result = CreateKernel(compiledKernel); int groupSize = EstimateGroupSizeInternal(result, 0, 0, out int minGridSize); result.Launcher = GenerateKernelLauncherMethod(compiledKernel, groupSize); kernelInfo = KernelInfo.CreateFrom( kernel.Info, groupSize, minGridSize); return(result); }
/// <summary> /// Loads the given implicitly-grouped kernel while using an automatically /// computed grouping configuration. /// </summary> /// <param name="kernel">The kernel to load.</param> /// <param name="groupSize">The estimated group size to gain maximum occupancy on this device.</param> /// <param name="minGridSize">The minimum grid size to gain maximum occupancy on this device.</param> /// <returns>The loaded kernel.</returns> /// <remarks> /// Note that the returned kernel will not be managed by the kernel cache. /// </remarks> public Kernel LoadAutoGroupedKernel( CompiledKernel kernel, out int groupSize, out int minGridSize) { Bind(); return(LoadAutoGroupedKernelInternal(kernel, out groupSize, out minGridSize)); }
/// <summary> /// Loads an automatically grouped kernel. /// </summary> public Kernel LoadKernel( Accelerator accelerator, CompiledKernel compiledKernel, out KernelInfo kernelInfo) => accelerator.LoadAutoGroupedKernel( compiledKernel, out kernelInfo);
/// <summary> /// Loads an implicitly grouped kernel. /// </summary> public Kernel LoadKernel( Accelerator accelerator, CompiledKernel compiledKernel, out KernelInfo kernelInfo) => accelerator.LoadImplicitlyGroupedKernel( compiledKernel, GroupSize, out kernelInfo);
/// <summary cref="Accelerator.LoadAutoGroupedKernelInternal(CompiledKernel, out int, out int)"/> protected override Kernel LoadAutoGroupedKernelInternal( CompiledKernel kernel, out int groupSize, out int minGridSize) { groupSize = WarpSize; minGridSize = NumThreads / WarpSize; return(LoadKernel(kernel, groupSize)); }
internal CudaKernel( CudaAccelerator accelerator, CompiledKernel kernel, MethodInfo launcher) : base(accelerator, kernel, launcher) { CudaException.ThrowIfFailed(CudaAPI.Current.LoadModule(out modulePtr, kernel.GetBuffer())); CudaException.ThrowIfFailed(CudaAPI.Current.GetModuleFunction(out functionPtr, modulePtr, kernel.EntryName)); }
/// <summary> /// Constructs a new kernel. /// </summary> /// <param name="accelerator">The associated accelerator.</param> /// <param name="compiledKernel">The source kernel.</param> /// <param name="launcher">The launcher method for the given kernel.</param> protected Kernel( Accelerator accelerator, CompiledKernel compiledKernel, MethodInfo launcher) : base(accelerator) { CompiledKernel = compiledKernel ?? throw new ArgumentNullException(nameof(compiledKernel)); Launcher = launcher; }
/// <summary> /// Loads a compiled kernel into the given Cuda context as kernel program. /// </summary> /// <param name="accelerator">The associated accelerator.</param> /// <param name="kernel">The source kernel.</param> /// <param name="launcher">The launcher method for the given kernel.</param> /// <param name="kernelExecutionDelegate">The execution method.</param> internal CPUKernel( CPUAccelerator accelerator, CompiledKernel kernel, MethodInfo launcher, CPUKernelExecutionHandler kernelExecutionDelegate) : base(accelerator, kernel, launcher) { KernelExecutionDelegate = kernelExecutionDelegate ?? throw new ArgumentNullException(nameof(kernelExecutionDelegate)); }
/// <summary> /// Loads an auto grouped kernel. /// </summary> protected override Kernel LoadAutoGroupedKernelInternal( CompiledKernel kernel, out KernelInfo kernelInfo) { var result = LoadKernel(kernel, WarpSize); kernelInfo = new KernelInfo(WarpSize, NumThreads / WarpSize); return(result); }
/// <summary> /// Loads the given implicitly-grouped kernel. /// </summary> /// <param name="kernel">The kernel to load.</param> /// <param name="customGroupSize">The custom group size to use.</param> /// <returns>The loaded kernel.</returns> /// <remarks> /// Note that implicitly-grouped kernel will be launched with the given group /// size. /// </remarks> /// <remarks> /// Note that the returned kernel will not be managed by the kernel cache. /// </remarks> public Kernel LoadImplicitlyGroupedKernel( CompiledKernel kernel, int customGroupSize) { Bind(); return(LoadImplicitlyGroupedKernelInternal( kernel, customGroupSize, out var _)); }
/// <summary cref="Accelerator.LoadImplicitlyGroupedKernelInternal(CompiledKernel, int)"/> protected override Kernel LoadImplicitlyGroupedKernelInternal( CompiledKernel kernel, int customGroupSize) { if (customGroupSize < 0) { throw new ArgumentOutOfRangeException(nameof(customGroupSize)); } return(LoadKernel(kernel, customGroupSize)); }
/// <summary> /// Constructs a new kernel. /// </summary> /// <param name="accelerator">The associated accelerator.</param> /// <param name="compiledKernel">The source kernel.</param> /// <param name="launcher">The launcher method for the given kernel.</param> protected Kernel( Accelerator accelerator, CompiledKernel compiledKernel, MethodInfo launcher) : base(accelerator) { Debug.Assert(compiledKernel != null, "Invalid compiled kernel"); Specialization = compiledKernel.Specialization; Launcher = launcher; NumParameters = compiledKernel.EntryPoint.Parameters.NumParameters; }
/// <summary cref="IKernelLoader.LoadKernel(Accelerator, CompiledKernel)"/> public Kernel LoadKernel(Accelerator accelerator, CompiledKernel compiledKernel) { var result = accelerator.LoadAutoGroupedKernel( compiledKernel, out int groupSize, out int minGridSize); GroupSize = groupSize; MinGridSize = minGridSize; return(result); }
/// <summary> /// Loads an explicitly grouped kernel. /// </summary> public Kernel LoadKernel( Accelerator accelerator, CompiledKernel compiledKernel, out KernelInfo kernelInfo) { var kernel = accelerator.LoadKernel(compiledKernel); kernelInfo = KernelInfo.CreateFrom( compiledKernel.Info, null, null); return(kernel); }
/// <summary cref="Accelerator.LoadKernelInternal(CompiledKernel)"/> protected sealed override Kernel LoadKernelInternal(CompiledKernel kernel) { if (kernel == null) { throw new ArgumentNullException(nameof(kernel)); } if (!(kernel is TCompiledKernel compiledKernel)) { throw new NotSupportedException(RuntimeErrorMessages.NotSupportedKernel); } return(CreateKernel( compiledKernel, GenerateKernelLauncherMethod(compiledKernel, 0))); }
/// <summary> /// Loads an implicitly grouped kernel. /// </summary> protected override Kernel LoadImplicitlyGroupedKernelInternal( CompiledKernel kernel, int customGroupSize, out KernelInfo kernelInfo) { if (customGroupSize < 0) { throw new ArgumentOutOfRangeException(nameof(customGroupSize)); } kernelInfo = KernelInfo.CreateFrom( kernel.Info, customGroupSize, null); return(LoadKernel(kernel, customGroupSize)); }
/// <summary> /// Loads the given kernel. /// </summary> /// <param name="kernel">The kernel to load.</param> /// <param name="customGroupSize">The custom group size.</param> /// <returns>The loaded kernel</returns> private Kernel LoadKernel(CompiledKernel kernel, int customGroupSize) { if (kernel == null) { throw new ArgumentNullException(nameof(kernel)); } if (!(kernel is ILCompiledKernel ilKernel)) { throw new NotSupportedException(RuntimeErrorMessages.NotSupportedKernel); } var launcherMethod = GenerateKernelLauncherMethod(ilKernel, customGroupSize); return(new CPUKernel( this, kernel, launcherMethod, ilKernel.ExecutionHandler)); }
/// <summary> /// Loads the given kernel. /// </summary> /// <param name="kernel">The kernel to load.</param> /// <param name="customGroupSize">The custom group size.</param> /// <returns>The loaded kernel</returns> private Kernel LoadKernel(CompiledKernel kernel, int customGroupSize) { if (kernel == null) { throw new ArgumentNullException(nameof(kernel)); } var launcherMethod = GenerateKernelLauncherMethod( kernel, out Type taskType, out FieldInfo[] taskArgumentMapping, customGroupSize); var executionMethod = GenerateKernelExecutionMethod( kernel, taskType, taskArgumentMapping); return(new CPUKernel( this, kernel, launcherMethod, (CPUKernelExecutionHandler)executionMethod.CreateDelegate( typeof(CPUKernelExecutionHandler)))); }
/// <summary> /// Loads the given kernel. /// Note that implictly-grouped kernels will be launched with a group size /// of the current warp size of the accelerator. /// </summary> /// <param name="kernel">The kernel to load.</param> /// <returns>The loaded kernel.</returns> /// <remarks> /// Note that the returned kernel will not be managed by the kernel cache. /// </remarks> protected abstract Kernel LoadKernelInternal(CompiledKernel kernel);
/// <summary> /// Loads the given kernel. /// Note that implictly-grouped kernels will be launched with a group size /// of the current warp size of the accelerator. /// </summary> /// <param name="kernel">The kernel to load.</param> /// <returns>The loaded kernel.</returns> /// <remarks> /// Note that the returned kernel will not be managed by the kernel cache. /// </remarks> public Kernel LoadKernel(CompiledKernel kernel) { Bind(); return(LoadKernelInternal(kernel)); }
/// <summary cref="IKernelLoader.LoadKernel(Accelerator, CompiledKernel)"/> public Kernel LoadKernel(Accelerator accelerator, CompiledKernel compiledKernel) { return(accelerator.LoadImplicitlyGroupedKernel(compiledKernel, GroupSize)); }
/// <summary> /// Loads the given implicitly-grouped kernel while using an automatically /// computed grouping configuration. /// </summary> /// <param name="kernel">The kernel to load.</param> /// <param name="groupSize">The estimated group size to gain maximum occupancy on this device.</param> /// <param name="minGridSize">The minimum grid size to gain maximum occupancy on this device.</param> /// <returns>The loaded kernel.</returns> /// <remarks> /// Note that the returned kernel will not be managed by the kernel cache. /// </remarks> protected abstract Kernel LoadAutoGroupedKernelInternal( CompiledKernel kernel, out int groupSize, out int minGridSize);
/// <summary cref="IKernelLoader.LoadKernel(Accelerator, CompiledKernel)"/> public Kernel LoadKernel(Accelerator accelerator, CompiledKernel compiledKernel) { return(accelerator.LoadKernel(compiledKernel)); }
/// <summary> /// Loads the given implicitly-grouped kernel while using an automatically /// computed grouping configuration. /// </summary> /// <param name="kernel">The kernel to load.</param> /// <returns>The loaded kernel.</returns> /// <remarks> /// Note that the returned kernel will not be managed by the kernel cache. /// </remarks> public Kernel LoadAutoGroupedKernel(CompiledKernel kernel) => LoadAutoGroupedKernel(kernel, out var _, out var _);
/// <summary> /// Loads the given implicitly-grouped kernel while using an automatically /// computed grouping configuration. /// </summary> /// <param name="kernel">The kernel to load.</param> /// <returns>The loaded kernel.</returns> /// <remarks> /// Note that the returned kernel will not be managed by the kernel cache. /// </remarks> public Kernel LoadAutoGroupedKernel(CompiledKernel kernel) { return(LoadAutoGroupedKernel(kernel, out int groupSize, out int minGridSize)); }
/// <summary> /// Loads the given implicitly-grouped kernel. /// </summary> /// <param name="kernel">The kernel to load.</param> /// <param name="customGroupSize">The custom group size to use.</param> /// <returns>The loaded kernel.</returns> /// <remarks> /// Note that implictly-grouped kernel will be launched with the given /// group size. /// </remarks> /// <remarks> /// Note that the returned kernel will not be managed by the kernel cache. /// </remarks> protected abstract Kernel LoadImplicitlyGroupedKernelInternal( CompiledKernel kernel, int customGroupSize);
/// <summary cref="Accelerator.LoadKernelInternal(CompiledKernel)"/> protected override Kernel LoadKernelInternal(CompiledKernel kernel) => LoadKernel(kernel, 0);
/// <summary cref="Accelerator.LoadKernelInternal(CompiledKernel)"/> protected override Kernel LoadKernelInternal(CompiledKernel kernel) { return(LoadKernel(kernel, 0)); }