@@ -33,7 +33,7 @@ struct FFNvapiData {
3333    bool  inited ;
3434} nvapiData ;
3535
36- const  char *  detectMemTypeByNvapi (FFGpuDriverResult *  result )
36+ static   const  char *  detectMemTypeByNvapi (FFGpuDriverResult *  result )
3737{
3838    if  (!nvapiData .inited )
3939    {
@@ -79,11 +79,14 @@ const char* detectMemTypeByNvapi(FFGpuDriverResult* result)
7979
8080    uint32_t  gpuIndex  =  * result -> index ;
8181
82-     if  ((uint32_t ) gpuCount   <   gpuIndex )
82+     if  (gpuIndex  >=  (uint32_t ) gpuCount )
8383        return  "GPU index out of range" ;
8484
85+     // Not very sure. Need to check in multi-GPU system 
86+     NvPhysicalGpuHandle  gpuHandle  =  handles [gpuIndex ];
87+ 
8588    NvApiGPUMemoryType  memType ;
86-     if  (nvapiData .ffnvapi_GPU_GetRamType (handles [ gpuIndex ] , & memType ) <  0 )
89+     if  (nvapiData .ffnvapi_GPU_GetRamType (gpuHandle , & memType ) <  0 )
8790        return  "NvAPI_GPU_GetRamType() failed" ;
8891
8992    switch  (memType )
@@ -160,7 +163,7 @@ const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverR
160163    if  (cond -> type  &  FF_GPU_DRIVER_CONDITION_TYPE_BUS_ID )
161164    {
162165        char  pciBusIdStr [32 ];
163-         snprintf (pciBusIdStr , ARRAY_SIZE (pciBusIdStr )  -   1 , "%04x:%02x:%02x.%d" , cond -> pciBusId .domain , cond -> pciBusId .bus , cond -> pciBusId .device , cond -> pciBusId .func );
166+         snprintf (pciBusIdStr , ARRAY_SIZE (pciBusIdStr ), "%04x:%02x:%02x.%d" , cond -> pciBusId .domain , cond -> pciBusId .bus , cond -> pciBusId .device , cond -> pciBusId .func );
164167
165168        nvmlReturn_t  ret  =  nvmlData .ffnvmlDeviceGetHandleByPciBusId_v2 (pciBusIdStr , & device );
166169        if  (ret  !=  NVML_SUCCESS )
@@ -187,24 +190,28 @@ const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverR
187190
188191            break ;
189192        }
190-         if  (!device ) return  "Device not found" ;
191193    }
192194
193-     nvmlBrandType_t  brand ;
194-     if  (nvmlData .ffnvmlDeviceGetBrand (device , & brand ) ==  NVML_SUCCESS )
195+     if  (!device ) return  "Device not found" ;
196+ 
197+     if  (result .type )
195198    {
196-         switch  (brand )
199+         nvmlBrandType_t  brand ;
200+         if  (nvmlData .ffnvmlDeviceGetBrand (device , & brand ) ==  NVML_SUCCESS )
197201        {
198-             case  NVML_BRAND_NVIDIA_RTX :
199-             case  NVML_BRAND_QUADRO_RTX :
200-             case  NVML_BRAND_GEFORCE :
201-             case  NVML_BRAND_TITAN :
202-             case  NVML_BRAND_TESLA :
203-             case  NVML_BRAND_QUADRO :
204-                 * result .type  =  FF_GPU_TYPE_DISCRETE ;
205-                 break ;
206-             default :
207-                 break ;
202+             switch  (brand )
203+             {
204+                 case  NVML_BRAND_NVIDIA_RTX :
205+                 case  NVML_BRAND_QUADRO_RTX :
206+                 case  NVML_BRAND_GEFORCE :
207+                 case  NVML_BRAND_TITAN :
208+                 case  NVML_BRAND_TESLA :
209+                 case  NVML_BRAND_QUADRO :
210+                     * result .type  =  FF_GPU_TYPE_DISCRETE ;
211+                     break ;
212+                 default :
213+                     break ;
214+             }
208215        }
209216    }
210217
0 commit comments