示例#1
0
 /// <summary>
 /// Enables a CPU device of the given kind.
 /// </summary>
 /// <param name="builder">The builder instance.</param>
 /// <param name="device">The custom CPU device.</param>
 /// <returns>The updated builder instance.</returns>
 public static Context.Builder CPU(
     this Context.Builder builder,
     CPUDevice device)
 {
     builder.DeviceRegistry.Register(device);
     return(builder);
 }
示例#2
0
 /// <summary>
 /// Enables a CPU device of the given kind.
 /// </summary>
 /// <param name="builder">The builder instance.</param>
 /// <param name="kind">The CPU device kind.</param>
 /// <returns>The updated builder instance.</returns>
 public static Context.Builder CPU(
     this Context.Builder builder,
     CPUDeviceKind kind)
 {
     builder.DeviceRegistry.Register(CPUDevice.GetDevice(kind));
     return(builder);
 }
示例#3
0
        /// <summary>
        /// Constructs a new CPU runtime.
        /// </summary>
        /// <param name="context">The ILGPU context.</param>
        /// <param name="description">The accelerator description.</param>
        /// <param name="mode">The current accelerator mode.</param>
        /// <param name="threadPriority">
        /// The thread priority of the execution threads.
        /// </param>
        internal CPUAccelerator(
            Context context,
            CPUDevice description,
            CPUAcceleratorMode mode,
            ThreadPriority threadPriority)
            : base(context, description)
        {
            NativePtr = new IntPtr(1);

            DefaultStream = CreateStream();

            NumThreads              = description.NumThreads;
            Mode                    = mode;
            ThreadPriority          = threadPriority;
            UsesSequentialExecution =
                Mode == CPUAcceleratorMode.Sequential ||
                Mode == CPUAcceleratorMode.Auto && Debugger.IsAttached;
            finishedEventPerMultiprocessor = new Barrier(NumMultiprocessors + 1);
            multiprocessors = new CPUMultiprocessor[NumMultiprocessors];
            for (int i = 0, e = NumMultiprocessors; i < e; ++i)
            {
                multiprocessors[i] = CPUMultiprocessor.Create(
                    this,
                    i,
                    UsesSequentialExecution);
            }

            Bind();
            Init(context.DefautltILBackend);
        }
示例#4
0
 /// <summary>
 /// Enables all CPU devices.
 /// </summary>
 /// <param name="builder">The builder instance.</param>
 /// <param name="predicate">
 /// The predicate to include a given device.
 /// </param>
 /// <returns>The updated builder instance.</returns>
 public static Context.Builder CPU(
     this Context.Builder builder,
     Predicate <CPUDevice> predicate)
 {
     CPUDevice.GetDevices(
         predicate,
         builder.DeviceRegistry);
     return(builder);
 }
示例#5
0
        /// <summary>
        /// Constructs a new CPU runtime.
        /// </summary>
        /// <param name="context">The ILGPU context.</param>
        /// <param name="description">The accelerator description.</param>
        /// <param name="mode">The current accelerator mode.</param>
        /// <param name="threadPriority">
        /// The thread priority of the execution threads.
        /// </param>
        internal CPUAccelerator(
            Context context,
            CPUDevice description,
            CPUAcceleratorMode mode,
            ThreadPriority threadPriority)
            : base(context, description)
        {
            NativePtr = new IntPtr(1);

            DefaultStream = CreateStream();

            NumThreads = description.NumThreads;
            Mode       = mode;
            UsesSequentialExecution =
                Mode == CPUAcceleratorMode.Sequential ||
                Mode == CPUAcceleratorMode.Auto && Debugger.IsAttached;

            Bind();
            InitExecutionEngine(threadPriority);
            Init(context.DefautltILBackend);
        }