About cuDeviceGetName

Hello there!
Can anyone help me with this:

CUdevice dev = new CUdevice();
cuDeviceGet(dev, 0);
byte[] name = new byte[1];
int len = 10;
cuDeviceGetName(name, len, dev);
System.out.println("Name: " + name[0]);
	
int[] major = new int[1];
int[] minor = new int[1];
JCudaDriver.cuDeviceComputeCapability(major, minor, dev);
System.out.println(String.format("ComputeCapability: %d.%d", major[0], minor[0]));
	
CUdevprop prop = new CUdevprop();
cuDeviceGetProperties(prop, dev);
System.out.println(String.format("Grid size: %d x %d x %d", prop.maxGridSize[0], prop.maxGridSize[1], prop.maxGridSize[2]));
System.out.println(String.format("ThreadsDim: %d x %d x %d", prop.maxThreadsDim[0], prop.maxThreadsDim[1], prop.maxThreadsDim[2]));
System.out.println("Threads per block: " + prop.maxThreadsPerBlock + "
");```

I get this:

Name: 71
ComputeCapability: 2.1
Grid size: 65535 x 65535 x 65535
ThreadsDim: 1024 x 1024 x 64
Threads per block: 1024

How can i get real name for my GPU (it's GeForce 450 GTS actually).
Thanks.

Hello

You’re allocating a single byte, and passing in ‚len=10‘ - this may overwrite memory, and may be „dangerous“ (things like that can cause nasty crashes). In any case, you are only printing the first byte (as an ASCII int value), so you now know that your device name starts with a ‚G‘ :smiley:

Unfortunately, the String returned by cuDeviceGetName is zero-terminated, so it may be a little bit inceonvenient to create a „nice“ String from the result, but a little helper function should to the job:

void init()
{
    ...
    byte nameBytes[] = new byte[1000];
    cuDeviceGetName(nameBytes, nameBytes.length, dev);
    System.out.println("Device name: "+createNiceString(nameBytes));
}

private static String createNiceString(byte bytes[])
{
    StringBuilder sb = new StringBuilder();
    for (int i=0; i<bytes.length; i++)
    {
        if (bytes** == 0)
        {
            break;
        }
        sb.append((char)bytes**);
    }
    return sb.toString();
}

bye

Thank you for the quick reply. That worked.

Name: GeForce GTS 450
ComputeCapability: 2.1
Grid size: 65535 x 65535 x 65535
ThreadsDim: 1024 x 1024 x 64
Threads per block: 1024

What to say? Im a noob, you’re a pro. :slight_smile:

btw, when i just started deal with jcuda, i used jcuda libraries from http://www.hoopoe-cloud.com/Solutions/jCUDA/Default.aspx

Just a piece from one of samples:

//Init CUDA Driver
CUDA cuda = new CUDA(true);

	int count = cuda.getDeviceCount();
	
	System.out.println("Total number of devices: " + count);
	
	for (int i = 0; i < count; i++) {
		CUdevice dev = cuda.getDevice(i);
		
		String name = cuda.getDeviceName(dev);
		System.out.println("Name: " + name);
		
		int version[] = cuda.getDeviceComputeCapability(dev);
		System.out.println("Version: " + String.format("%d.%d", version[0], version[1]));

=================================================================
Obvious, that getting the GPU name in this way is much easier.
Sure, im not the one who can point out, but that would be great to implement such approach (in the future ;))
Thanks again, Marco, you’re a great guy anyway :stuck_out_tongue:

The library from hoopoe-cloud is called „jCUDA“, whereas my library is called „JCuda“ (and there is also a JCUDA - fortunately, Java is case sensitive :wink: ). The libraries are completely unrelated. But it seems that jCUDA has not been maintained since CUDA 1.x anyhow.

JCuda offers the CUDA functions as-they-are - this may sometimes be verbose or inconvenient, and not always perfectly suited for Java, but leaves all options open. Originally, I also wanted to create an Object-Oriented abstraction layer, but this would take a lot of time to get it right, and at the moment I’m too busy with other things (but the idea is not dead - maybe one day I’ll find the time…)