The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: sinsi on February 22, 2012, 09:50:36 AM

Title: Getting GPU temps with NVAPI
Post by: sinsi on February 22, 2012, 09:50:36 AM
I have downloaded the nvapi sdk and tried to convert the .h file to a .inc, a few issues but nothing too bad, but one thing has got me.
The linker complains about a missing external called _fltused so what I've done is declared it public as '_fltused dd 0' which makes it work.

My questions are, what type and what value should it be?
Title: Re: Getting GPU temps with NVAPI
Post by: dedndave on February 22, 2012, 12:13:04 PM
seems that is is defined by C startup if floats are used in the program - not defined of not
i see a few references where it is defined as 1, probably an EQUate would do the trick
it appears to load some c lib float stuff

i dunno how to define "weak" externals in ASM   :P
but, here's some reading...
http://www.iecc.com/linker/linker06.html
about 3/4 of the way down the page "Weak external symbols"

you are probably going to use some floats, eh ?
probably not critical, as asm programs don't work like compiled c programs
Title: Re: Getting GPU temps with NVAPI
Post by: sinsi on February 22, 2012, 12:21:50 PM
>you are probably going to use some floats, eh ?
No way, that's why it is 0 (false, right?)
Title: Re: Getting GPU temps with NVAPI
Post by: dedndave on February 22, 2012, 12:25:59 PM
after some more thought....

it is probably referencing the external to cause the float routines to get pulled in when used with a C compiler
i would define it as
_fltused EQU 1
i.e., if you use MSVCRT, it wants the float stuff
which might also indicate that nvapi.inc should be referenced before msvcrt.lib
doesn't seem to hurt things if it isn't - lol
as i said, asm programs are not the same as c programs

the value you assign to it is probably insignifigant - the point is that it is defined or not defined
Hutch had some similar issues when creating the ver 11 windows.inc
http://www.masm32.com/board/index.php?topic=17795.msg152690#msg152690
Title: Re: Getting GPU temps with NVAPI
Post by: MichaelW on February 22, 2012, 01:02:09 PM
I think _fltused is basically undocumented. The linker returns the error when _fltused appears in an object module but is not defined in any of the linked libraries. A search for the name on my system finds it declared in one CPP source from a fairly recent DDK as:

extern "C" const int _fltused = 0;

And defined in two C source files from the CRT source files included with a 2003 PSDK as:

int _fltused = 0x9875;

If an object module is referencing _fltused then presumably it requires FP support. The only solutions I see are to remove the need, or link in the support.
Title: Re: Getting GPU temps with NVAPI
Post by: MichaelW on February 23, 2012, 06:34:51 AM
Using this source:

#include "nvapi.h"
#include <conio.h>
#include <stdio.h>
extern int _fltused; // This necessary only to display the value.
void main( void )
{
    printf("%d\n",NvAPI_Initialize());

    printf("%Xh\n",_fltused);

    getch();
}


Compiled with the Visual C++ Toolkit 2003 compiler and this command line

cl /W3 /FA  %file%.c nvapi.lib

I get no errors or warnings, and when I run the EXE on an XP system from 2003 with a GeForce FX 5200 I get:

-2
9875h

Title: Re: Getting GPU temps with NVAPI
Post by: sinsi on February 23, 2012, 06:50:59 AM
Thanks for taking the time to work things out Michael, I even went to the trouble of downloading VS2010 express but have no idea about C/C++ so couldn't get any further.
One minor point, what version of driver do you have for the FX? A return code of -2 means NVAPI_LIBRARY_NOT_FOUND.
Title: Re: Getting GPU temps with NVAPI
Post by: MichaelW on February 23, 2012, 06:55:26 AM
It looks like 6.14.10.4502 for all 4 of the related drivers (downloaded from Dell).

Per the documentation:

NvAPI is supported on ForceWare driver versions 81.20 and up.

Title: Re: Getting GPU temps with NVAPI
Post by: sinsi on February 23, 2012, 07:16:35 AM
It looks like the Dell drivers aren't Forceware drivers, I have the latest 285.62 drivers from Nvidia and there are more than 4, all version 8.17.12.8562
Once again, thanks for your help - I thought you were a die-hard win2000 fan :bg
Title: Re: Getting GPU temps with NVAPI
Post by: MichaelW on February 24, 2012, 03:18:00 AM
Well, I thought I was going to download and install recent Nvidia drivers and do some more testing, but it turns out that they will not work with the GeForce FX 5200 because it's apparently a Dell OEM part. I have run into this problem before with Dell systems.
Title: Re: Getting GPU temps with NVAPI
Post by: NPNW on February 29, 2012, 05:32:14 AM
A lot of OEM modify the hardware for their usage, price point, etc. So, the drivers won't work from Nvidia.

Here is a where is defined in this code.

https://singularity.svn.codeplex.com/svn/base/Kernel/Native/Number.cpp

extern "C" int _fltused = 0x9875;


if you back up to https://singularity.svn.codeplex.com/svn/base/Kernel/Native/
you can look at their file sources.  or hal.h, and hal.cpp


Here is some light on the extern  directive in the file.

http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html

[32.3] How can I include a non-system C header file in my C++ code?

If you are including a C header file that isn't provided by the system, you may need to wrap the #include line in an extern "C" { /*...*/ } construct. This tells the C++ compiler that the functions declared in the header file are C functions.

// This is C++ code

extern "C" {
   // Get declaration for f(int i, char c, float x)
   #include "my-C-code.h"
}

int main()
{
   f(7, 'x', 3.14);   // Note: nothing unusual in the call
   ...
}
Note: Somewhat different guidelines apply for C headers provided by the system (such as <cstdio>) and for C headers that you can change.

Hope this helps explain what is going on.