MSI Afterburner .NET Class Library

Discussion in 'MSI AfterBurner Overclock Application Discussion' started by stangowner, Feb 28, 2011.

  1. stangowner

    stangowner Master Guru

    Messages:
    586
    Likes Received:
    0
    GPU:
    2xMSI N550GTX-Ti Cy II OC
    Yes, I receive 0 too. I think Afterburner only returns that value for some cards. I have a pair of 550Ti s and they return 0 too. If memory serves.....I think it should show in information dialog in Afterburner. If its missing there, then you'll get 0 from this API too.

    Using C# code that dumps the complete .net class:
    Code:
    ***** MSI AFTERBURNER GPU 0 *****
    GpuId = VEN_10DE&DEV_1244&SUBSYS_26101462&REV_A1&BUS_2&DEV_0&FN_0
    Family = GF116
    Device = GeForce GTX 550 Ti
    Driver = 306.97
    BIOS = 70.26.18.00.00
    MemAmount = 0
    
    ***** MSI AFTERBURNER GPU 1 *****
    GpuId = VEN_10DE&DEV_1244&SUBSYS_26101462&REV_A1&BUS_3&DEV_0&FN_0
    Family = GF116
    Device = GeForce GTX 550 Ti
    Driver = 306.97
    BIOS = 70.26.18.00.00
    MemAmount = 0
    And using your .ps1 code:
    Code:
    MSI Afterburner (API version 2.0)
    GPU #1
      Device: GeForce GTX 550 Ti
      Driver Version: 306.97
      Memory: 0
    GPU #2
      Device: GeForce GTX 550 Ti
      Driver Version: 306.97
      Memory: 0
    - Nick
     
  2. timiman

    timiman Member

    Messages:
    37
    Likes Received:
    0
    GPU:
    2xR9-290 Asus DCU-II
    No luck here. I've just tried that and I'm still getting the "dead shared memory" message. I also removed the "=nothing" and got the same results.

    I forgot to mention this in my post. I have an issue about the "HardwareMonitorMSIAft" because originally it is declared as object, if no datatype is set there. When I'm using "HardwareMonitorMSIAft = New HardwareMonitor" and then get the "HardwareMonitorMSIAft.GpuEntries.Count" I get no values at all. This one has to do with bad automated casting from Object to HardwareMonitor, i think. So, I left this solution out from "day 1".
     
  3. stangowner

    stangowner Master Guru

    Messages:
    586
    Likes Received:
    0
    GPU:
    2xMSI N550GTX-Ti Cy II OC
    OK, I'll try to look into it further in the next few days.

    Even if you Dim As? Sorry, I haven't really used VB since VB6.
    Code:
    Dim HardwareMonitorMSIAft As HardwareMonitor
     
  4. timiman

    timiman Member

    Messages:
    37
    Likes Received:
    0
    GPU:
    2xR9-290 Asus DCU-II
    OK. Thanks. I'm available if you want any help about tests etc.

    If I use the "Dim HardwareMonitorMSIAft As HardwareMonitor" with MSI Afterburner closed, I get the exception of "MSI Afterburnrer is not running" without been able to handle it. That's why I'm using the Try..Catch.
    Just an idea, I will try to use an "AddHandler" on HardwareMonitorMSIAft when I get home and see if this will help at all.
     

  5. danielkza

    danielkza New Member

    Messages:
    7
    Likes Received:
    0
    GPU:
    Shappire HD4830
    @stangowner

    Thanks for the confirmation. I resorted to going through the video controllers in WMI and matching them with the device IDs provided by Afterburner. I don't have a setup with two identical cards to confirm it works, but it should if all my assumptions were right.


    $abMonitor is an instance of HardwareMonitor, and $abControl is an instance of ControlMemory. The final result is an array of memory sizes in MB where the indexes correspond to the Afterburn GPU indexes.


    Code:
    Function Get-WmiGPUMem($abMonitor)
    {
        $gpuEntries = $abMonitor.GpuEntries
        $gpuMemories = @(0) * $gpuEntries.Length
      
        $videoControllers = Get-WmiObject "Win32_VideoController"
    
        # Look through the video controllers, convert their device IDs to a format comparable to Afterburner's,
        # then select the one that matches the selected GPU
    
        foreach($vc in $videoControllers)
        {
            $driver = Get-WmiObject "Win32_PnPSignedDriver" | ? {$_.DeviceID -eq $vc.PNPDeviceID}
            if($driver.Location -match 'PCI Bus (?<bus>\d+), device (?<device>\d+), function (?<function>\d+)')
            {
                $bus = $Matches['bus']
                $dev = $Matches['device']
                $fn = $Matches['function']
    
                if($vc.PNPDeviceID -match 'PCI\\([^\\]+)')
                {
                    $abDevID = $Matches[1] + ('&BUS_{0}&DEV_{1}&FN_{2}' -f $bus,$dev,$fn)
    
                    for($i=0; $i -lt $gpuEntries.Length; $i++)
                    {
                        if($gpuMemories[$i] -ne 0)
                        {
                            continue
                        }
    
                        if($abDevID -eq $gpuEntries[$i].GpuID)
                        {
                            $gpuMemories[$i] = $vc.AdapterRAM / (1024 * 1024)
                            break
                        }
                    }
                }
            }
        }
    
        return $gpuMemories
    }
    
    Function Get-GPUMem($abMonitor, $abControl)
    {
        $gpuMemories = @(0) * $abMonitor.GpuEntries.Length
        $wmiGpuMemories = $null
    
        for($i=0; $i -lt $abMonitor.GpuEntries.Length; $i++)
        {
            $gpuMonitor = $abMonitor.GpuEntries[$i]
            $gpuControl = $abControl.GpuEntries[$i]
    
            if($gpuMonitor.MemAmount -gt 0) {
                $gpuMemories[$i] = $gpuMonitor.MemAmount / 1024
            } else {
                if($WmiGPUMemories -eq $null) {
                    #Write-Warning "Failed to detect GPU RAM from Afterburner. Reverting to WMI method."
                    $WmiGPUMemories = Get-WmiGPUMem $abMonitor.GpuEntries
                }
    
                $gpuMemories[$i] = $WmiGPUMemories[$i]
            }
        }
    
        return $gpuMemories
    }
    
    And if I'm not asking too much, I noticed you have two GTX 500 cards. Would you mind testing the full script? I only have one GTX 600 card, and I would like to know if everything works as expected before launching it 'officially'. The script is here, and the needed files are here. You also need the MSI.Afterburner.NET.dll obviously. (everything in the same folder)

    The script has a bunch of options but you don't need to change any of them if you don't want, except -gpuIndex and possibly -testIterations (so you don't waste much of your time). By default the script will start with the default clocks and raise them 200Mhz at a time, and halves the step each time a test fails.

    Thanks in advance.
     
    Last edited: Jan 24, 2013
  6. stangowner

    stangowner Master Guru

    Messages:
    586
    Likes Received:
    0
    GPU:
    2xMSI N550GTX-Ti Cy II OC
    Hi,

    I've started this twice, once with some parameters and once without. The results are
    Code:
    PS E:\temp\powershell> .\MemTestG80_AutoOC.ps1
    GPU #0
      Device: GeForce GTX 550 Ti
      Driver: 306.97
      Memory Clock (default): 2150MhzMhz
      Memory Clock (current): 2150MhzMhz
      Memory Size: 1023.6875MB
    GPU #1
      Device: GeForce GTX 550 Ti
      Driver: 306.97
      Memory Clock (default): 2150MhzMhz
      Memory Clock (current): 2150MhzMhz
      Memory Size: 1023.6875MB
    False
    Trying 2350Mhz with 1023.6875MB and 50 iterations: SUCCESS
    Trying 2550Mhz with 1023.6875MB and 50 iterations: SUCCESS
    Trying 2750Mhz with 1023.6875MB and 50 iterations: SUCCESS
    Trying 2950Mhz with 1023.6875MB and 50 iterations: clock_too_high
    SUCCESS
    Trying 3150Mhz with 1023.6875MB and 50 iterations: clock_too_high
    SUCCESS
    Trying 3350Mhz with 1023.6875MB and 50 iterations: clock_too_high
    SUCCESS
    Trying 3550Mhz with 1023.6875MB and 50 iterations: clock_too_high
    SUCCESS
    ......
    Trying 50550Mhz with 1023.6875MB and 50 iterations: clock_too_high
    SUCCESS
    Trying 50750Mhz with 1023.6875MB and 50 iterations: clock_too_high
    SUCCESS
    Trying 50950Mhz with 1023.6875MB and 50 iterations: clock_too_high
    SUCCESS
    Trying 51150Mhz with 1023.6875MB and 50 iterations: clock_too_high
    SUCCESS
    Trying 51350Mhz with 1023.6875MB and 50 iterations: clock_too_high
    SUCCESS
    Trying 51550Mhz with 1023.6875MB and 50 iterations: clock_too_high
    PS E:\temp\powershell>
    In both instances, I pressed CtrlC to stop it. I have no idea why the clock keeps climbing 200 Mhz each test....I was under the assumption it was going to climb 200, 200, 200, fail, -100, 50, 25, fail, -12, etc until it found the most stable frequency. Am I not understanding this properly?

    Also, Afterburner said an external profile was applied when I started the script, but I did not notice any changes. And it only said it once. Just so you are aware, when applying changes via the API, it takes one second for the changes to be applied, but the script processes the iterations faster then that.

    Let me know your thoughts. I'll test it for you again if you want.
    - Nick
     
  7. danielkza

    danielkza New Member

    Messages:
    7
    Likes Received:
    0
    GPU:
    Shappire HD4830
    @stangowner:

    You got it right, it was supposed to go up 200 MHz and then slowly back out on failure, but I've seem to have not tested my logic enough. Thanks very much for your help, I'll work on it a bit more. At least I know it's not blowing up completely with two GPUs, it's already a start!
     
  8. stangowner

    stangowner Master Guru

    Messages:
    586
    Likes Received:
    0
    GPU:
    2xMSI N550GTX-Ti Cy II OC
    Timiman, mind doing me a favor? I've been trying to track down this handle to dead memory issue. I think I may have found the problem.

    I created a simple app using your snippet as a base to reproduce the problem. Fortunately I can reproduce it quite easily.
    Code:
    Imports System.Threading
    Imports MSI.Afterburner
    
    Module Module1
    
        Sub Main()
            Dim i As Integer
    
            While i < 40
                Try
                    Dim mahm = New HardwareMonitor
                    Console.Write(mahm)
                    mahm.Disconnect()
                    mahm = Nothing
                Catch ex As Exception
                    Console.WriteLine(ex.Message)
                End Try
                i = i + 1
                Thread.Sleep(800)
            End While
    
        End Sub
    
    End Module
    However, after stepping through the code several times and even trying several things, I could not for the life of me figure out why it was happening. So thinking it may be a garbage collection issue, I changed the sleep timer in the loop. Sure enough, anything under 1000-1500ms can cause the issue, meanwhile anything over 1500ms does not. Simply increasing that makes the issue go away.

    So my question to you is can you insert an artificial delay of 2 seconds into your application whenever you are disconnecting/disposing one of these objects? Please let me know if this solves it for you too.

    I have placed a GC.Collect() in the end of the Disconnect() method the HardwareMonitor class. This forces the garbage collector to run, and seems to resolve the issue. I can now run my test code in a loop at 100 ms, or even comment out the delay and let it run full speed, and I no longer see the issue. I can update the classes with this change once you confirm and I do more testing.

    Thanks,
    Nick
     
  9. timiman

    timiman Member

    Messages:
    37
    Likes Received:
    0
    GPU:
    2xR9-290 Asus DCU-II
    stangowner,

    I've added a 2000ms delay (even 4000ms) on my application and the problem remains as it was.
    On the other hand your snippet works without any message of "dead shared memory" at all.

    Maybe my logic of the sensors reading needs some changes, too.
    For example, the init of the available sensors runs every second. (during the test above, this timer was set to 10000ms).
    Also, every second I call a GC.Collect() to clear memory, too,
    knowing that the GC.Collect() is not always really fired, but "pushed" to be fired sooner.

    To get more realistic results with your idea, it won't be a bad idea to send me a test version of your .dll. If it is OK with you, of course.
     
  10. stangowner

    stangowner Master Guru

    Messages:
    586
    Likes Received:
    0
    GPU:
    2xMSI N550GTX-Ti Cy II OC
    Sure, just let me just update the ControlMemory class too, test it, and then I'll send you link to download.

    Thanks for testing with me.
     

  11. LongbowX

    LongbowX New Member

    Messages:
    1
    Likes Received:
    0
    GPU:
    Kingston 8GB
    Hi Strangowner,
    I emailed you last night using the address on your code documentation page. Posting here to get your attention, I'm not sure if you check that address.
    -I
     

Share This Page