Пример #1
0
 /// <summary>
 /// Constructs a new CPU-based runtime context for parallel processing.
 /// </summary>
 /// <param name="accelerator">The target CPU accelerator.</param>
 public CPURuntimeWarpContext(CPUAccelerator accelerator)
 {
     Debug.Assert(accelerator != null, "Invalid accelerator");
     WarpSize       = accelerator.WarpSize;
     shuffleBarrier = new Barrier(WarpSize);
     shuffleBank    = accelerator.Allocate <int>(WarpSize);
 }
Пример #2
0
 /// <summary>
 /// Creates a new CPU multiprocessor instance.
 /// </summary>
 /// <param name="accelerator">The parent accelerator.</param>
 /// <param name="processorIndex">The index of the multiprocessor.</param>
 /// <param name="usesSequentialProcessing">
 /// True, if this multiprocessor uses a sequential execution policy that executes
 /// a single thread at a time to improve the debugging experience.
 /// </param>
 /// <returns>The created multiprocessor.</returns>
 public static CPUMultiprocessor Create(
     CPUAccelerator accelerator,
     int processorIndex,
     bool usesSequentialProcessing) =>
 usesSequentialProcessing
     ? new SequentialProcessor(accelerator, processorIndex) as CPUMultiprocessor
     : new ParallelProcessor(accelerator, processorIndex);
Пример #3
0
 /// <summary>
 /// Constructs a new pinned array.
 /// </summary>
 /// <param name="accelerator">The accelerator.</param>
 /// <param name="extent">The extent.</param>
 internal CPUMemoryBuffer(CPUAccelerator accelerator, TIndex extent)
     : base(accelerator, extent)
 {
     array    = new T[extent.Size];
     gcHandle = GCHandle.Alloc(array, GCHandleType.Pinned);
     Pointer  = gcHandle.AddrOfPinnedObject();
 }
Пример #4
0
 /// <summary>
 /// Constructs a new CPU-based runtime context for parallel processing.
 /// </summary>
 /// <param name="accelerator">The target CPU accelerator.</param>
 public CPURuntimeGroupContext(CPUAccelerator accelerator)
 {
     Debug.Assert(accelerator != null, "Invalid accelerator");
     Accelerator        = accelerator;
     groupBarrier       = new Barrier(0);
     sharedMemoryBuffer = new MemoryBufferCache(accelerator);
     broadcastBuffer    = accelerator.Allocate <byte>(BroadcastBufferSize);
 }
Пример #5
0
        /// <summary>
        /// Constructs a new CPU-based runtime context for parallel processing.
        /// </summary>
        /// <param name="accelerator">The target CPU accelerator.</param>
        /// <param name="numThreadsPerWarp">The number of threads per warp.</param>
        public CPURuntimeWarpContext(CPUAccelerator accelerator, int numThreadsPerWarp)
            : base(accelerator)
        {
            WarpSize = numThreadsPerWarp;

            shuffleBuffer = new MemoryBufferCache(accelerator);
            shuffleBuffer.Allocate <int>(2 * sizeof(int) * numThreadsPerWarp);
        }
Пример #6
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));
 }
Пример #7
0
        /// <summary>
        /// Constructs a new CPU-based runtime context for parallel processing.
        /// </summary>
        /// <param name="accelerator">The target CPU accelerator.</param>
        protected CPURuntimeContext(CPUAccelerator accelerator)
        {
            Accelerator = accelerator
                          ?? throw new ArgumentNullException(nameof(accelerator));
            barrier = new Barrier(0);

            broadcastBuffer = new MemoryBufferCache(accelerator);
            broadcastBuffer.Allocate <int>(16);
        }
Пример #8
0
 /// <summary>
 /// Creates a new parallel processor.
 /// </summary>
 public ParallelProcessor(CPUAccelerator accelerator, int processorIndex)
     : base(accelerator, processorIndex)
 {
     // Initialize all warp barriers
     warpBarriers = new Barrier[NumWarpsPerMultiprocessor];
     for (int i = 0, e = NumWarpsPerMultiprocessor; i < e; ++i)
     {
         warpBarriers[i] = new Barrier(0);
     }
 }
Пример #9
0
        /// <summary>
        /// Creates a new CPU multiprocessor.
        /// </summary>
        /// <param name="accelerator">The parent accelerator.</param>
        /// <param name="processorIndex">The index of the multiprocessor.</param>
        protected CPUMultiprocessor(CPUAccelerator accelerator, int processorIndex)
        {
            Accelerator    = accelerator;
            ProcessorIndex = processorIndex;

            // Setup all warp and group contexts
            NumWarpsPerMultiprocessor = MaxNumThreadsPerMultiprocessor / WarpSize;
            warpContexts = new CPURuntimeWarpContext[NumWarpsPerMultiprocessor];
            groupContext = new CPURuntimeGroupContext(this);
            for (int i = 0; i < NumWarpsPerMultiprocessor; ++i)
            {
                warpContexts[i] = new CPURuntimeWarpContext(this, WarpSize);
            }

            // Instantiate all runtime threads
            threads = new Thread[MaxNumThreadsPerMultiprocessor];
            Parallel.For(0, MaxNumThreadsPerMultiprocessor, i =>
            {
                var thread = threads[i] = new Thread(ExecuteThread)
                {
                    IsBackground = true,
                    Priority     = Accelerator.ThreadPriority,
                };
                thread.Name = $"ILGPU_{Accelerator.InstanceId}_CPU_{ProcessorIndex}_{i}";
            });

            // Start or delay the creation of runtime threads
            if (MaxNumThreadsPerMultiprocessor <= 32)
            {
                StartOrContinueRuntimeThreads(MaxNumThreadsPerMultiprocessor);
            }
            else
            {
                maxNumLaunchedThreadsPerGroup = 0;
            }
        }
Пример #10
0
 /// <summary>
 /// Constructs a new pinned array.
 /// </summary>
 /// <param name="accelerator">The accelerator.</param>
 /// <param name="extent">The extent.</param>
 internal CPUMemoryBuffer(CPUAccelerator accelerator, TIndex extent)
     : base(accelerator, extent)
 {
     NativePtr = Marshal.AllocHGlobal(extent.Size * Interop.SizeOf <T>());
 }
 /// <summary>
 /// Constructs a new CPU-based runtime context for parallel processing.
 /// </summary>
 /// <param name="accelerator">The target CPU accelerator.</param>
 public CPURuntimeGroupContext(CPUAccelerator accelerator)
 {
     Debug.Assert(accelerator != null, "Invalid accelerator");
     groupBarrier       = new Barrier(0);
     sharedMemoryBuffer = new MemoryBufferCache(accelerator);
 }
Пример #12
0
 /// <summary>
 /// Constructs a new CPU-based runtime context for parallel processing.
 /// </summary>
 /// <param name="accelerator">The target CPU accelerator.</param>
 public CPURuntimeGroupContext(CPUAccelerator accelerator)
     : base(accelerator)
 {
 }
Пример #13
0
 /// <summary>
 /// Creates a new sequential processor.
 /// </summary>
 public SequentialProcessor(CPUAccelerator accelerator, int processorIndex)
     : base(accelerator, processorIndex)
 {
 }