Hardware/ATI/ATIGPU.cs
author moel.mich
Sun, 15 Aug 2010 14:46:58 +0000
changeset 167 b7cc9d09aefe
parent 165 813d8bc3192f
child 176 c16fd81b520a
permissions -rw-r--r--
Fixed some Code Analysis warnings.
     1 /*
     2   
     3   Version: MPL 1.1/GPL 2.0/LGPL 2.1
     4 
     5   The contents of this file are subject to the Mozilla Public License Version
     6   1.1 (the "License"); you may not use this file except in compliance with
     7   the License. You may obtain a copy of the License at
     8  
     9   http://www.mozilla.org/MPL/
    10 
    11   Software distributed under the License is distributed on an "AS IS" basis,
    12   WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
    13   for the specific language governing rights and limitations under the License.
    14 
    15   The Original Code is the Open Hardware Monitor code.
    16 
    17   The Initial Developer of the Original Code is 
    18   Michael Möller <m.moeller@gmx.ch>.
    19   Portions created by the Initial Developer are Copyright (C) 2009-2010
    20   the Initial Developer. All Rights Reserved.
    21 
    22   Contributor(s):
    23 
    24   Alternatively, the contents of this file may be used under the terms of
    25   either the GNU General Public License Version 2 or later (the "GPL"), or
    26   the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
    27   in which case the provisions of the GPL or the LGPL are applicable instead
    28   of those above. If you wish to allow use of your version of this file only
    29   under the terms of either the GPL or the LGPL, and not to allow others to
    30   use your version of this file under the terms of the MPL, indicate your
    31   decision by deleting the provisions above and replace them with the notice
    32   and other provisions required by the GPL or the LGPL. If you do not delete
    33   the provisions above, a recipient may use your version of this file under
    34   the terms of any one of the MPL, the GPL or the LGPL.
    35  
    36 */
    37 
    38 using System;
    39 using System.Collections.Generic;
    40 using System.Globalization;
    41 
    42 namespace OpenHardwareMonitor.Hardware.ATI {
    43   internal sealed class ATIGPU : Hardware {
    44 
    45     private string name;
    46     private int adapterIndex;
    47     private int busNumber;
    48     private int deviceNumber;
    49     private Sensor temperature;
    50     private Sensor fan;
    51     private Sensor coreClock;
    52     private Sensor memoryClock;
    53     private Sensor coreVoltage;
    54     private Sensor coreLoad;
    55     private Sensor fanControl;
    56 
    57     public ATIGPU(string name, int adapterIndex, int busNumber, 
    58       int deviceNumber, ISettings settings) 
    59     {
    60       this.name = name;
    61       this.adapterIndex = adapterIndex;
    62       this.busNumber = busNumber;
    63       this.deviceNumber = deviceNumber;
    64 
    65       this.temperature = new Sensor("GPU Core", 0, SensorType.Temperature, this, settings);
    66       this.fan = new Sensor("GPU Fan", 0, SensorType.Fan, this, settings);
    67       this.coreClock = new Sensor("GPU Core", 0, SensorType.Clock, this, settings);
    68       this.memoryClock = new Sensor("GPU Memory", 1, SensorType.Clock, this, settings);
    69       this.coreVoltage = new Sensor("GPU Core", 0, SensorType.Voltage, this, settings);
    70       this.coreLoad = new Sensor("GPU Core", 0, SensorType.Load, this, settings);
    71       this.fanControl = new Sensor("GPU Fan", 0, SensorType.Control, this, settings);
    72       Update();                   
    73     }
    74 
    75     public int BusNumber { get { return busNumber; } }
    76 
    77     public int DeviceNumber { get { return deviceNumber; } }
    78 
    79     public override string Name {
    80       get { return name; }
    81     }
    82 
    83     public override Identifier Identifier {
    84       get { 
    85         return new Identifier("atigpu", 
    86           adapterIndex.ToString(CultureInfo.InvariantCulture)); 
    87       }
    88     }
    89 
    90     public override HardwareType HardwareType {
    91       get { return HardwareType.GPU; }
    92     }
    93 
    94     public override void Update() {
    95       ADLTemperature adlt = new ADLTemperature();
    96       if (ADL.ADL_Overdrive5_Temperature_Get(adapterIndex, 0, ref adlt)
    97         == ADL.ADL_OK) 
    98       {
    99         temperature.Value = 0.001f * adlt.Temperature;
   100         ActivateSensor(temperature);
   101       } else {
   102         temperature.Value = null;
   103       }
   104 
   105       ADLFanSpeedValue adlf = new ADLFanSpeedValue();
   106       adlf.SpeedType = ADL.ADL_DL_FANCTRL_SPEED_TYPE_RPM;
   107       if (ADL.ADL_Overdrive5_FanSpeed_Get(adapterIndex, 0, ref adlf)
   108         == ADL.ADL_OK) 
   109       {
   110         fan.Value = adlf.FanSpeed;
   111         ActivateSensor(fan);
   112       } else {
   113         fan.Value = null;
   114       }
   115 
   116       adlf = new ADLFanSpeedValue();
   117       adlf.SpeedType = ADL.ADL_DL_FANCTRL_SPEED_TYPE_PERCENT;
   118       if (ADL.ADL_Overdrive5_FanSpeed_Get(adapterIndex, 0, ref adlf)
   119         == ADL.ADL_OK) {
   120         fanControl.Value = adlf.FanSpeed;
   121         ActivateSensor(fanControl);
   122       } else {
   123         fanControl.Value = null;
   124       }
   125 
   126       ADLPMActivity adlp = new ADLPMActivity();
   127       if (ADL.ADL_Overdrive5_CurrentActivity_Get(adapterIndex, ref adlp)
   128         == ADL.ADL_OK) 
   129       {
   130         if (adlp.EngineClock > 0) {
   131           coreClock.Value = 0.01f * adlp.EngineClock;
   132           ActivateSensor(coreClock);
   133         }
   134 
   135         if (adlp.MemoryClock > 0) {
   136           memoryClock.Value = 0.01f * adlp.MemoryClock;
   137           ActivateSensor(memoryClock);
   138         }
   139 
   140         if (adlp.Vddc > 0) {
   141           coreVoltage.Value = 0.001f * adlp.Vddc;
   142           ActivateSensor(coreVoltage);
   143         }
   144 
   145         coreLoad.Value = Math.Min(adlp.ActivityPercent, 100);                        
   146         ActivateSensor(coreLoad);
   147       } else {
   148         coreClock.Value = null;
   149         memoryClock.Value = null;
   150         coreVoltage.Value = null;
   151         coreLoad.Value = null;
   152       }
   153     }
   154   }
   155 }