예제 #1
0
        /// <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)));
        }
예제 #2
0
 /// <summary>
 /// Constructs a new cached kernel.
 /// </summary>
 /// <param name="kernel">The kernel to cache.</param>
 /// <param name="kernelInfo">Detailed kernel information.</param>
 public CachedKernel(
     WeakReference <object> kernel,
     KernelInfo kernelInfo)
 {
     kernelReference = kernel;
     KernelInfo      = kernelInfo;
 }
예제 #3
0
        /// <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);
        }
예제 #4
0
 /// <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));
 }
예제 #5
0
 /// <summary>
 /// Loads an automatically grouped kernel.
 /// </summary>
 public Kernel LoadKernel(
     Accelerator accelerator,
     CompiledKernel compiledKernel,
     out KernelInfo kernelInfo) =>
 accelerator.LoadAutoGroupedKernel(
     compiledKernel,
     out kernelInfo);
예제 #6
0
 /// <summary>
 /// Loads an implicitly grouped kernel.
 /// </summary>
 public Kernel LoadKernel(
     Accelerator accelerator,
     CompiledKernel compiledKernel,
     out KernelInfo kernelInfo) =>
 accelerator.LoadImplicitlyGroupedKernel(
     compiledKernel,
     GroupSize,
     out kernelInfo);
예제 #7
0
 /// <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>
 /// <param name="kernelInfo">
 /// Detailed kernel information about the loaded kernel.
 /// </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,
     out KernelInfo kernelInfo)
 {
     Bind();
     return(LoadImplicitlyGroupedKernelInternal(
                kernel,
                customGroupSize,
                out kernelInfo));
 }
예제 #8
0
            /// <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);
            }
예제 #9
0
 /// <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>
 protected abstract Kernel LoadAutoGroupedKernelInternal(
     CompiledKernel kernel,
     out KernelInfo kernelInfo);
예제 #10
0
 /// <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>
 /// <param name="kernelInfo">
 /// Detailed kernel information about the loaded kernel.
 /// </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>
 protected abstract Kernel LoadImplicitlyGroupedKernelInternal(
     CompiledKernel kernel,
     int customGroupSize,
     out KernelInfo kernelInfo);