轮胎外观检测添加思谋语义分割模型检测工具
C3204
7 小时以前 98c0775fe3b61a37d90dd5756287f385a311adf0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;
using System.Threading.Tasks;
 
namespace LB_SmartVisionCommon
{
    public class DiskInfoHelper
    {
        public static double GetFreeSpaceGB(string driveName)
        {
            try
            {
                DriveInfo drive = new DriveInfo(driveName);
                return drive.IsReady ? Math.Round((double)drive.AvailableFreeSpace / (1024 * 1024 * 1024), 2) : -1;
            }
            catch
            {
                return -1;
            }
        }
 
        public static Dictionary<string, object> GetDiskDetails(string driveName)
        {
            var result = new Dictionary<string, object>();
 
            try
            {
                DriveInfo drive = new DriveInfo(driveName);
 
                if (drive.IsReady)
                {
                    result["DriveName"] = drive.Name;
                    result["TotalSizeGB"] = Math.Round((double)drive.TotalSize / (1024 * 1024 * 1024), 2);
                    result["FreeSpaceGB"] = Math.Round((double)drive.AvailableFreeSpace / (1024 * 1024 * 1024), 2);
                    result["DriveFormat"] = drive.DriveFormat;
                    result["DriveType"] = drive.DriveType.ToString();
                }
            }
            catch (Exception ex)
            {
                result["Error"] = ex.Message;
            }
 
            return result;
        }
 
        /// <summary>
        /// 获取GPU信息,包含系统索引和CUDA标准的NVIDIA索引
        /// </summary>
        /// <returns>GPU信息列表</returns>
        public static List<GpuInfo> GetGpuInfoWithCudaIndex()
        {
            var gpuList = new List<GpuInfo>();
            int systemIndex = 0;    // 系统显示适配器索引(包含所有显卡)
            int cudaIndex = 0;      // CUDA专属索引(仅NVIDIA GPU,从0开始)
 
            // WMI查询所有显示适配器
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(
                "root\\CIMV2",
                "SELECT Name, PNPDeviceID FROM Win32_VideoController");
 
            foreach (ManagementObject queryObj in searcher.Get())
            {
                string gpuName = queryObj["Name"]?.ToString() ?? "未知设备";
                string pnpId = queryObj["PNPDeviceID"]?.ToString() ?? string.Empty;
                bool isNvidia = gpuName.Contains("NVIDIA", StringComparison.OrdinalIgnoreCase) ||
                               pnpId.Contains("VEN_10DE", StringComparison.OrdinalIgnoreCase);
 
                var gpuInfo = new GpuInfo
                {
                    GpuName = gpuName,
                    SystemIndex = systemIndex,
                    IsNvidia = isNvidia,
                    CudaIndex = -1  // 非NVIDIA GPU默认-1
                };
 
                // 仅NVIDIA GPU分配CUDA索引
                if (isNvidia)
                {
                    gpuInfo.CudaIndex = cudaIndex;
                    cudaIndex++;
                }
                gpuList.Add(gpuInfo);
                systemIndex++;
            }
 
            return gpuList;
        }
 
    }
    /// <summary>
    /// GPU信息模型
    /// </summary>
    public class GpuInfo
    {
        public string GpuName { get; set; }    // GPU名称
        public int SystemIndex { get; set; }   // 系统显示适配器索引(WMI枚举)
        public int CudaIndex { get; set; }     // CUDA设备索引(软件显示的索引)
        public bool IsNvidia { get; set; }     // 是否为NVIDIA GPU
    }
}