public CpuComputeDevice(int id, string group, string name, int threads, ulong affinityMask, int cpuCount) : base(id, name, true, DeviceGroupType.CPU, DeviceType.CPU, string.Format(Translations.Tr("CPU#{0}"), cpuCount), 0) { Threads = threads; AffinityMask = affinityMask; var uuid = GetUuid(ID, GroupNames.GetGroupName(DeviceGroupType, ID), Name, DeviceGroupType); Uuid = uuid; AlgorithmSettings = DefaultAlgorithms.GetAlgorithmsForDevice(this); Index = ID; // Don't increment for CPU _cpuCounter = new PerformanceCounter { CategoryName = "Processor", CounterName = "% Processor Time", InstanceName = "_Total" }; // plugin device var bd = new BaseDevice(DeviceType.CPU, uuid, name, ID); // TODO UUID PluginDevice = new CPUDevice(bd, threads, true, affinityMask); // TODO hyperthreading }
public static Task <CPUDevice> TryQueryCPUDeviceTask() { return(Task.Run(async() => { var(cpuJSON, cpuID) = await TryQueryCPUDevicesAsync(); Logger.Info(Tag, cpuJSON); if (!CpuUtils.IsCpuMiningCapable(cpuID)) { return null; } var cpuDetectResult = QueryCPUDevice(); // get all CPUs var cpuCount = cpuID.PhysicalProcessorCount; var name = cpuID.Name.Trim(); // get all cores (including virtual - HT can benefit mining) var threadsPerCpu = cpuDetectResult.VirtualCoresCount / cpuCount; // TODO important move this to settings var threadsPerCpuMask = threadsPerCpu; if (threadsPerCpu * cpuCount > 64) { // set lower threadsPerCpuMask = 64; } List <ulong> affinityMasks = null; // multiple CPUs are identified as a single CPU from nhm perspective, it is the miner plugins job to handle this correctly if (cpuCount > 1) { name = $"({cpuCount}x){name}"; affinityMasks = new List <ulong>(); for (var i = 0; i < cpuCount; i++) { var affinityMask = CpuUtils.CreateAffinityMask(i, threadsPerCpuMask); affinityMasks.Add(affinityMask); } } var hashedInfo = $"{0}--{name}--{threadsPerCpu}"; foreach (var cpuInfo in cpuDetectResult.CpuInfos) { hashedInfo += $"{cpuInfo.Family}--{cpuInfo.ModelName}--{cpuInfo.NumberOfCores}--{cpuInfo.PhysicalID}--{cpuInfo.VendorID}"; hashedInfo += cpuJSON; } var uuidHEX = UUID.GetHexUUID(hashedInfo); var uuid = $"CPU-{uuidHEX}"; // plugin device var bd = new BaseDevice(DeviceType.CPU, uuid, name, 0); var cpu = new CPUDevice(bd, cpuCount, threadsPerCpu, cpuDetectResult.IsHyperThreadingEnabled, affinityMasks, CpuUtils.SupportedExtensions(cpuID), cpuID); return cpu; })); }
public void TestCustomDeviceSetup( int numThreadsPerWarp, int numWarpsPerMultiprocessor, int numMultiprocessors) { // Create a custom CPU device and register it with the context pipeline var customDevice = new CPUDevice( numThreadsPerWarp, numWarpsPerMultiprocessor, numMultiprocessors); // Skip specific tests on MacOS if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { // Detect the number of processors and check whether we run in a supported // range of tests int maxNumThreads = Environment.ProcessorCount * 768; Skip.If(customDevice.NumThreads > maxNumThreads); } using var context = Context.Create(builder => builder.Assertions().CPU(customDevice)); // Spawn a new accelerator and invoke a simple sequence kernel to check // whether all threads are actually executed using var accl = context.CreateCPUAccelerator(0); // Compute the total number of parallel threads int numParallelThreads = numThreadsPerWarp * numWarpsPerMultiprocessor * numMultiprocessors; Assert.Equal(numParallelThreads, accl.NumThreads); Assert.Equal(numParallelThreads, accl.MaxNumThreads); // Allocate a buffer for IO purposes using var buff = accl.Allocate1D <int>(numParallelThreads); // Validate the implicit kernel var implicitKernel = accl.LoadAutoGroupedStreamKernel < Index1D, ArrayView <int> >(TestCustomDeviceSetup_ImplicitKernel); buff.MemSetToZero(); implicitKernel(buff.IntExtent, buff.View); var implicitData = buff.GetAsArray1D(); for (int i = 0; i < implicitData.Length; ++i) { Assert.Equal(implicitData[i], i); } // Validate the explicit kernel var explicitKernel = accl.LoadStreamKernel <ArrayView <int> >( TestCustomDeviceSetup_ExplicitKernel); buff.MemSetToZero(); explicitKernel( (numMultiprocessors, numThreadsPerWarp * numWarpsPerMultiprocessor), buff.View); var explicitData = buff.GetAsArray1D(); for (int i = 0; i < explicitData.Length; ++i) { Assert.Equal(explicitData[i], i); } }