예제 #1
0
        /// <summary>
        /// Constructs a new accelerator task.
        /// </summary>
        /// <param name="kernelExecutionDelegate">The execution method.</param>
        /// <param name="userConfig">The user-defined grid configuration.</param>
        /// <param name="config">The global task configuration.</param>
        public CPUAcceleratorTask(
            CPUKernelExecutionHandler kernelExecutionDelegate,
            KernelConfig userConfig,
            RuntimeKernelConfig config)
        {
            Debug.Assert(
                kernelExecutionDelegate != null,
                "Invalid execution delegate");
            if (!userConfig.IsValid)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(userConfig),
                          RuntimeErrorMessages.InvalidGridDimension);
            }

            if (!config.IsValid)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(config),
                          RuntimeErrorMessages.InvalidGridDimension);
            }

            KernelExecutionDelegate = kernelExecutionDelegate;
            TotalUserDim            = userConfig.GridDim * userConfig.GroupDim;
            GridDim  = config.GridDim;
            GroupDim = config.GroupDim;
            DynamicSharedMemoryConfig = config.SharedMemoryConfig.DynamicConfig;
        }
예제 #2
0
 /// <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));
 }
예제 #3
0
        /// <summary>
        /// Constructs a new accelerator task.
        /// </summary>
        /// <param name="kernelExecutionDelegate">The execution method.</param>
        /// <param name="userGridDim">The grid dimension that was specified by the user.</param>
        /// <param name="userGroupDim">The group dimension that was specified by the user.</param>
        /// <param name="gridDim">The grid dimension.</param>
        /// <param name="groupDim">The group dimension.</param>
        /// <param name="sharedMemSize">The required amount of shareed-memory per thread group in bytes.</param>
        public CPUAcceleratorTask(
            CPUKernelExecutionHandler kernelExecutionDelegate,
            Index3 userGridDim,
            Index3 userGroupDim,
            Index3 gridDim,
            Index3 groupDim,
            int sharedMemSize)
        {
            Debug.Assert(kernelExecutionDelegate != null, "Invalid execution delegate");
            if (sharedMemSize < 0)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(sharedMemSize),
                          RuntimeErrorMessages.InvalidSharedMemorySize);
            }
            if (gridDim.X < 0 | gridDim.Y < 0 | gridDim.Z < 0 | gridDim == Index3.Zero)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(gridDim),
                          RuntimeErrorMessages.InvalidGridDimension);
            }
            if (groupDim.X < 0 | groupDim.Y < 0 | groupDim.Z < 0 | groupDim == Index3.Zero)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(groupDim),
                          RuntimeErrorMessages.InvalidGroupDimension);
            }
            if (userGridDim.Size < 1)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(userGridDim),
                          RuntimeErrorMessages.InvalidGridDimension);
            }
            if (userGroupDim.Size < 1)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(userGroupDim),
                          RuntimeErrorMessages.InvalidGroupDimension);
            }

            KernelExecutionDelegate = kernelExecutionDelegate;
            UserGridDim             = userGridDim;
            UserDimension           = userGridDim.Size * userGroupDim.Size;
            GridDim          = gridDim;
            GroupDim         = groupDim;
            RuntimeDimension = gridDim.Size * groupDim.Size;
            SharedMemSize    = sharedMemSize;
        }