techPowerUp! Forums

Go Back   techPowerUp! Forums > Our Software > GPU-Z

Reply
 
Thread Tools
Old Apr 12, 2012, 06:30 PM   #1
JohnnyUT
5 Posts
 
Join Date: Jul 2008
Posts: 7 (0.00/day)
Thanks: 0
Thanked 4 Times in 4 Posts

GPU-Z Shared Memory C# Wrapper

As I got some PNs that the link I've posted in the sticky thread 4 years ago is dead and other users still need the source code, I'll upload it again. With this source code, C# developers can conveniently access the shared memory (and therefore the data) provided by GPU-Z within their programs.

Here's a link to a newly created .zip archive which includes two visual studio 2010 projects, one that's written in C++ and used to create a .dll and the other one to show how you can access the shared memory via the .dll in C#. Usually including the .dll into your project (such as done in the demo project) will be sufficient, but if that doesn't work, you might try to adjust/compile the .dll project by yourself. I've also compiled a x64 version of the .dll, but normally the 32 bit version should work also on all 64 bit OS.

Here is a short snippet from the demo project, showing how the shared memory can be accessed:

Code:

Code:
GpuzWrapper gpuz = new GpuzWrapper();
gpuz.Open();
Console.WriteLine(gpuz.DataKey(0) + ": " + gpuz.DataValue(0));
Console.WriteLine(gpuz.SensorName(0) + ": " + gpuz.SensorValue(0) + " " + gpuz.SensorUnit(0));
gpuz.Close();
Output:

Code:
DirectXSupport: 11.0
GPU Core Clock: 732,1149 MHz
The C# code is pretty straight forward. Please don't mind that I might have not used some fancy C# stuff that would have made the GpuzWrapper more convenient, but actually I'm a Java developer that programmed the whole thing 4 years ago..

Feel free to enjoy the demo and ask if something is unclear.

Here are some links to download it:
http://www.file-upload.net/download-...ShMem.zip.html
http://www.filedropper.com/gpuzshmem
https://github.com/JohnnyUT/GpuzShMem/zipball/master

And here is the link to the github project, if you want to take a look at the sources without downloading the whole archive:
https://github.com/JohnnyUT/GpuzShMem

PS: You might have to update the location of the GpuzShMem.dll file in the GpuzDemo project. I think visual studio uses the absolute path. -.-

Last edited by JohnnyUT; Apr 12, 2012 at 07:39 PM.
JohnnyUT is offline  
Reply With Quote
The Following User Says Thank You to JohnnyUT For This Useful Post:
Old Apr 12, 2012, 06:54 PM   #2
W1zzard
Benevolent Dictator
 
W1zzard's Avatar
 
Join Date: May 2004
Location: Stuttgart, Germany
Posts: 13,870 (4.17/day)
Thanks: 184
Thanked 10,453 Times in 3,219 Posts
Send a message via ICQ to W1zzard Send a message via AIM to W1zzard Send a message via MSN to W1zzard Send a message via Skype™ to W1zzard

System Specs

thanks. suggestion: put it on github
W1zzard is online now  
Reply With Quote
Old Apr 12, 2012, 07:40 PM   #3
JohnnyUT
5 Posts
 
Join Date: Jul 2008
Posts: 7 (0.00/day)
Thanks: 0
Thanked 4 Times in 4 Posts

Done. I added the link to the original post.
JohnnyUT is offline  
Reply With Quote
Old Apr 12, 2012, 07:40 PM   #4
Kreij
Hardcore Monkey Moderator
 
Kreij's Avatar
 
Join Date: Feb 2007
Location: Cheeseland (Wisconsin, USA)
Posts: 12,254 (5.27/day)
Thanks: 591
Thanked 5,510 Times in 2,948 Posts

System Specs

Thanks Johnny !!
__________________

Cloud (noun, singular): A dynamic arrangement of multiple potential single points of failure, with a user at one end and their data at the other.


Get more tech news on a wide variety of topics at NextPowerUp
Kreij is offline  
Reply With Quote
Old Apr 12, 2012, 11:13 PM   #5
Kreij
Hardcore Monkey Moderator
 
Kreij's Avatar
 
Join Date: Feb 2007
Location: Cheeseland (Wisconsin, USA)
Posts: 12,254 (5.27/day)
Thanks: 591
Thanked 5,510 Times in 2,948 Posts

System Specs

Okay, I thought I'd try my hand at accessing the shared memory from GPU-Z as I haven't done anything with shared memory before.

I'm using that MemoryMappedFiles namespace they added in .Net 4
I sort of works. I get the version, busy and lastUpdate values okay (at least I think so), but I'm seeing garbage in the names and values of the data array of GPUZ_RECORD.

Code Inside


Maybe a problem with the c# char type and WCHAR ?
Maybe something with mem boundaries of the way structures are stored?
Maybe I don't have a clue what I doing ? <---- most likely scenario

Any thoughts appreciated.
__________________

Cloud (noun, singular): A dynamic arrangement of multiple potential single points of failure, with a user at one end and their data at the other.


Get more tech news on a wide variety of topics at NextPowerUp
Kreij is offline  
Reply With Quote
Old Apr 12, 2012, 11:24 PM   #6
W1zzard
Benevolent Dictator
 
W1zzard's Avatar
 
Join Date: May 2004
Location: Stuttgart, Germany
Posts: 13,870 (4.17/day)
Thanks: 184
Thanked 10,453 Times in 3,219 Posts
Send a message via ICQ to W1zzard Send a message via AIM to W1zzard Send a message via MSN to W1zzard Send a message via Skype™ to W1zzard

System Specs

WCHAR is a 16 bit unicode character

#pragma pack(push, 1) means 1-byte aligned structure members
W1zzard is online now  
Reply With Quote
The Following User Says Thank You to W1zzard For This Useful Post:
Old Apr 13, 2012, 02:15 PM   #7
Kreij
Hardcore Monkey Moderator
 
Kreij's Avatar
 
Join Date: Feb 2007
Location: Cheeseland (Wisconsin, USA)
Posts: 12,254 (5.27/day)
Thanks: 591
Thanked 5,510 Times in 2,948 Posts

System Specs

Got a bit farther. Yay !

I forced the BinaryReader to use unicode decoding for text (which I thought was the default, but apparently not)
Code:
BinaryReader reader = new BinaryReader(stream, Encoding.Unicode);
Realized that GPU-Z is saving the busy value (long) as 4 bytes, not 8, so a quick change to ReadInt32 got things back in line. I forgot about "long long" in C++ as C# always makes longs 8 bytes.

... after much code abuse ...

Everything works with no DLLImports of PInvoke calls. WooHooo !!
Now to make it useful. lol
__________________

Cloud (noun, singular): A dynamic arrangement of multiple potential single points of failure, with a user at one end and their data at the other.


Get more tech news on a wide variety of topics at NextPowerUp

Last edited by Kreij; Apr 13, 2012 at 06:03 PM.
Kreij is offline  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
GPU-Z Shared Memory Layout W1zzard GPU-Z 31 Jan 6, 2013 04:37 PM
exe to read GPU-Z shared memory data? Irios GPU-Z 11 Apr 13, 2012 01:50 AM
C# Shared Memory GPU-Z symbiote_venom GPU-Z 0 Mar 30, 2011 07:54 AM
Increasing shared graphics memory Ben Clarke General Hardware 5 Mar 24, 2007 02:50 AM
Increasing shared graphics memory Ben Clarke General Hardware 3 Mar 24, 2007 01:18 AM


All times are GMT. The time now is 05:26 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
no new posts