cuda.lib return 32bit integer

Windows specific forum
Etayson
User
User
Posts: 80
Joined: Sun Jun 05, 2016 5:01 pm

cuda.lib return 32bit integer

Post by Etayson »

Hi, sorry for my bad english :oops:
I have a problem with cuda.lib, this library return 32bit integer when should return 64bit.
Nvidia forum say that all is correct and and I'm doing something wrong
Let`s see code:

Code: Select all

   
Import "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\lib\x64\cuda.lib"
 cuInit(Flags.i)
 cuDeviceGetCount(count.i)
 cuDeviceGet(device.i, ordinal.i)
 cuDeviceGetName(name.s,len.i,dev.i)
 cuDeviceTotalMem(bytes.i,dev.i)
 cuDeviceTotalMem_v2(bytes.i,dev.i) ;UNDOCUMENTED!!!
EndImport

 ;main
 OpenConsole()
 CudaDevice.i
 namedev.s=Space(128)
 sizebytes.i
 sizebytes64.i
 piattrib.i
 major.i
 minor.i
 count.i
 mp.i
 cores.i

 cuInit(0)
 cuDeviceGetCount(@count)
 If count>0
  PrintN("Found "+count+" Cuda device.")  
 Else
  PrintN("No Cuda device found.")
  Input()
  End
 EndIf

 For i=0 To count-1
  cores=0
  cuDeviceGet(@CudaDevice, i)                 
  cuDeviceGetName(namedev,128,CudaDevice)
  cuDeviceTotalMem(@sizebytes,CudaDevice)
  cuDeviceTotalMem_v2(@sizebytes64,CudaDevice)

  PrintN("Cuda device["+Str(CudaDevice)+"]:"+namedev)
  PrintN("cuDeviceTotalMem:"+Str(sizebytes/1048576)+"Mb")
  PrintN("cuDeviceTotalMem_v2:"+Str(sizebytes64/1048576)+"Mb")
Next i

Input()
CloseConsole()
End
To run code you should have installed nvidia cudatoolkit.
So question, why nvidia say that all is ok, but documented function cuDeviceTotalMem return only 32bit integer while undocumented cuDeviceTotalMem_v2 return correct 64bit value ???
User avatar
mk-soft
Always Here
Always Here
Posts: 5386
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: cuda.lib return 32bit integer

Post by mk-soft »

32 bit Integer Signed or Unsigned?

Not testet

Code: Select all

Import "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\lib\x64\cuda.lib"
 cuInit(Flags.i)
 cuDeviceGetCount(count.i)
 cuDeviceGet(device.i, ordinal.i)
 cuDeviceGetName(name.s,len.i,dev.i)
 cuDeviceTotalMem(*bytes,dev.i)
 cuDeviceTotalMem_v2(*bytes,dev.i) ;UNDOCUMENTED!!!
EndImport

Structure llValue
  StructureUnion
    l.l
    q.q
  EndStructureUnion
EndStructure

 ;main
 OpenConsole()
 Define CudaDevice.i
 Define namedev.s=Space(128)
 Define sizebytes.llValue
 Define sizebytes64.llValue
 
 Define piattrib.i
 Define major.i
 Define minor.i
 Define count.i
 Define mp.i
 Define cores.i

 cuInit(0)
 cuDeviceGetCount(@count)
 If count>0
  PrintN("Found "+count+" Cuda device.")  
 Else
  PrintN("No Cuda device found.")
  Input()
  End
 EndIf

 For i=0 To count-1
  cores=0
  cuDeviceGet(@CudaDevice, i)                 
  cuDeviceGetName(namedev,128,CudaDevice)
  cuDeviceTotalMem(@sizebytes,CudaDevice)
  cuDeviceTotalMem_v2(@sizebytes64,CudaDevice)

  PrintN("Cuda device["+Str(CudaDevice)+"]:"+namedev)
  PrintN("cuDeviceTotalMem Signed:"+Str(sizebytes\l / 1048576)+"Mb")
  PrintN("cuDeviceTotalMem Unsigned:"+Str(sizebytes\q / 1048576)+"Mb")
  PrintN("cuDeviceTotalMem_v2:"+Str(sizebytes64\q / 1048576)+"Mb")
Next i

Input()
CloseConsole()
End
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Etayson
User
User
Posts: 80
Joined: Sun Jun 05, 2016 5:01 pm

Re: cuda.lib return 32bit integer

Post by Etayson »

mk-soft wrote:32 bit Integer Signed or Unsigned?

Not testet
Hi, thanks for answer
It is result of your code:

Code: Select all

Found 1 Cuda device.
Cuda device[0]:GeForce RTX 2080 Ti
cuDeviceTotalMem Signed:0Mb
cuDeviceTotalMem Unsigned:4095Mb
cuDeviceTotalMem_v2:11264Mb
The same like my code cuDeviceTotalMem return 32bit integer
I think that cuda.lib have bug with returned value, because undocumented functions with prefix _v2 always return correct 64bit value.
I can`t use _v2 prefix because there is same limitations..
User avatar
mk-soft
Always Here
Always Here
Posts: 5386
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: cuda.lib return 32bit integer

Post by mk-soft »

The result of 32bit Unsigned Integer is right

Limit of Unsigned Value

Code: Select all

Structure llValue
  StructureUnion
    l.l
    q.q
  EndStructureUnion
EndStructure

a.llValue

#MegaBytes = 1024 *1024
a\l = $FFFFFFFF

Debug a\q
Debug a\q / #MegaBytes
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Etayson
User
User
Posts: 80
Joined: Sun Jun 05, 2016 5:01 pm

Re: cuda.lib return 32bit integer

Post by Etayson »

mk-soft wrote:The result of 32bit Unsigned Integer is right

Limit of Unsigned Value

Code: Select all

Structure llValue
  StructureUnion
    l.l
    q.q
  EndStructureUnion
EndStructure

a.llValue

#MegaBytes = 1024 *1024
a\l = $FFFFFFFF

Debug a\q
Debug a\q / #MegaBytes
Returned value should be 64bit Unsigned Integer, not 32 bit. And i use x64 cuda.lib library.
It is my post on devtalk nvidia https://devtalk.nvidia.com/default/topi ... 3/#5350253
Last edited by Etayson on Sat Jul 20, 2019 8:10 pm, edited 1 time in total.
User avatar
mk-soft
Always Here
Always Here
Posts: 5386
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: cuda.lib return 32bit integer

Post by mk-soft »

It is often the case that out of compality a new function "_v2" is added to the old 32 bit version.
I think you can use the new function safely. Simply search for examples with google.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Etayson
User
User
Posts: 80
Joined: Sun Jun 05, 2016 5:01 pm

Re: cuda.lib return 32bit integer

Post by Etayson »

mk-soft wrote:It is often the case that out of compality a new function "_v2" is added to the old 32 bit version.
I think you can use the new function safely. Simply search for examples with google.
I just wanted to make sure it was really a bug. And that Nvidia ignores him for some reason.
32bit restriction not only in this function, but also in many others.
That's why I wanted to make sure that it’s not just me or I’m doing something wrong.
And that answer i got on devtalk about cuMemAlloc function (the same bug of 32bit)
cuMemAlloc_v2 doesn't appear to be a documented part of the CUDA driver API:

https://docs.nvidia.com/cuda/cuda-drive ... _CUDA__MEM

I'm not aware of any 32-bit limitation on cuMemAlloc:

https://docs.nvidia.com/cuda/cuda-drive ... c31e8aa467

size_t is 64-bits on a 64-bit platform.
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Re: cuda.lib return 32bit integer

Post by pdwyer »

I'm replying to this thread for a slightly different reason.

I'm using 11.6
Import "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\lib\x64\cuda.lib"

and I don't have the problem you are having but I have a problem with the string returned for the name. I've tried converting between ascii,utf8,unicode in different ways but I get a garbled string.

Code: Select all

Found 1 Cuda device.
Cuda device[0]:噎䑉䅉䜠䙥牯散䜠塔ㄠ㔶0                                                                                  
cuDeviceTotalMem Signed:0Mb
cuDeviceTotalMem Unsigned:4095Mb
cuDeviceTotalMem_v2:4095Mb
I would really like to use cuda or opencl in my code as I have a processing job I'd like to run with GPU so I'd be happy to collaborate on anything others are doing.

Anyway, I'll look around the forums and the docs that came with the toolkit to see what I can work out.
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Re: cuda.lib return 32bit integer

Post by pdwyer »

Okay, found a way through with

Code: Select all

PrintN("Cuda device["+Str(CudaDevice)+"]:"+ PeekS(@namedev,128,#PB_Ascii)  )
Looks simple in hindsight but went off course with ascii() and other things. passing the address directly to peeks did the trick.

1 problem down, 1,000,000 to go :mrgreen:
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Post Reply