首页 > 其他分享 >nvidia显卡信息获取以及配置

nvidia显卡信息获取以及配置

时间:2023-01-18 12:44:26浏览次数:44  
标签:Stat POWER nvidia 获取 GPU POLICY 显卡 gcptstat NV

  1. 获取温度
		memset(&Config, 0, sizeof(Config));
		Config.version = NV_GPU_THERMAL_SETTINGS_VER;
		Stat = _NvAPI_GPU_GetThermalSettings(m_hNvGpu[i], NVAPI_THERMAL_TARGET_ALL, &Config);
		if(Stat == NVAPI_OK)
		{
			fTemp = (float)Config.sensor[0].currentTemp;
			sprintf(szName, "GpuTemperature#%d", i);
			SetProp(szName, fTemp);
		}
  1. 获取TDP(最大功耗)默认值
	NV_GPU_POWER_POLICY_INFO_PARAMS_V1	gppinfo1 = {};
	gppinfo1.version = NV_GPU_POWER_POLICY_INFO_PARAMS_VER_1;
	gppinfo1.policyMask = -1;
	gppinfo1.policyRelMask = -1;
	Stat = _NvAPI_GPU_PowerPolicyGetInfo(hGpu, (NV_GPU_POWER_POLICY_INFO_PARAMS *)&gppinfo1);
	if(Stat == NVAPI_OK)
	{
		for(i=0; i<NV_GPU_POWER_POLICY_MAX_POLICIES_V1; i++)
		{
			if(gppinfo1.policies[i].type != NV_GPU_POWER_POLICY_TYPE_TOTAL_GPU)
				continue;
			m_nNvTdpDef = gppinfo1.policies[i].limitRated;
			m_nNvTdpMin = gppinfo1.policies[i].limitMin;
			m_nNvTdpMax = gppinfo1.policies[i].limitMax;
			s_fDefTdp = m_nNvTdpDef / 1000.0f;
			plIdx = i;
			break;
		}
	}
  1. 获取TDP设置值(当前值)
	gppc.version = NV_GPU_POWER_POLICY_CONTROL_PARAMS_VER_1;
	gppc.policyMask = NV_GPU_POWER_POLICY_TYPE_HW_THRESHOLD;
	gppc.policyMask = (1<<plIdx);
	Stat = _NvAPI_GPU_PowerPolicyGetControl(hGpu, (NV_GPU_POWER_POLICY_CONTROL_PARAMS *)&gppc);
	if(Stat == NVAPI_OK)
	{
		for(i=0; i<NV_GPU_POWER_POLICY_MAX_POLICIES_V1; i++)
		{
			if(gppc.policies[i].type != NV_GPU_POWER_POLICY_TYPE_TOTAL_GPU)
				continue;
			if(gppc.policies[i].limitCurr == 0)
				continue;

			m_nNvTdpCur = gppc.policies[i].limitCurr;
			s_fCurTdp = m_nNvTdpCur / 1000.0f;
			break;
		}
	}
  1. 获取当前功耗百分比, 功耗值=默认TDP*百分比
		NV_GPU_CLIENT_POWER_TOPOLOGY_STATUS	gcptstat = {};
		gcptstat.version = NV_GPU_CLIENT_POWER_TOPOLOGY_STATUS_VER;
		gcptstat.numChannels	= 2;
		gcptstat.channels[0].channelId = NV_GPU_CLIENT_POWER_TOPOLOGY_CHANNEL_ID_TOTAL_GPU_POWER;
		gcptstat.channels[1].channelId = NV_GPU_CLIENT_POWER_TOPOLOGY_CHANNEL_ID_NORMALIZED_TOTAL_POWER;
		Stat = _NvAPI_GPU_ClientPowerTopologyGetStatus(m_hNvGpu[i], &gcptstat);		//	功率百分比
		if(Stat == NVAPI_OK)
		{
			fPowerPst = gcptstat.channels[0].power.mp/1000.0f;	//	GPU功率%
			sprintf(szName, "GpuPowPst#%d", i);
			sprintf(szValue, "%.1f", fPowerPst);
			SetProp(szName, szValue);
		}
  1. 修改TDP(功耗墙)
	limitCurr = NData::ftoi(nNvTdpDef * fTdpPst);
	gppcp2.policies[plIdx].limitCurr = limitCurr;
	Stat = _NvAPI_GPU_PowerPolicySetControl(hGpu, (NV_GPU_POWER_POLICY_CONTROL_PARAMS *)&gppcp2);
	if(Stat != NVAPI_OK)
		return FALSE;

标签:Stat,POWER,nvidia,获取,GPU,POLICY,显卡,gcptstat,NV
From: https://www.cnblogs.com/zzz3265/p/17059564.html

相关文章