CUDA 5 Debugging Mode

Hello! I was testing the Parallel Nsight Eclipse Edition with a simple code:

#include <stdio.h>

#include <stdlib.h>

#define N 20

void cpu_fill( float *vector, float value, int n ){

	for( int i = 0; i < n; i++ )

		vector[i] = value;

}

void cpu_show( float *vector, int n ){

	for( int i = 0; i < n; i++ )

		printf(" %f |", vector[i] );

}

__global__ void add( float *a, float *b, float *c ){

	int tid = blockIdx.x;

	while( tid < N ){

		c[tid] = a[tid] + b[tid];

		tid += blockDim.x * gridDim.x;

	}

}

int main( void ){

	/** CPU vectors **/

	float a[N], b[N], c[N];

	cpu_fill( a, 2, N );

	cpu_fill( b, 3, N );

	/** Device vectors **/

	float *dev_a, *dev_b, *dev_c;

	cudaMalloc( ( void** )&dev_a, N * sizeof( float ) );

	cudaMalloc( ( void** )&dev_b, N * sizeof( float ) );

        cudaMalloc( ( void** )&dev_c, N * sizeof( float ) );

	/** Fill the device vectors **/

	cudaMemcpy( dev_a, a, N * sizeof( float ), cudaMemcpyHostToDevice );

	cudaMemcpy( dev_b, b, N * sizeof( float ), cudaMemcpyHostToDevice );

	/** Execute the kernel **/

	add<<<10,1>>>(dev_a, dev_b, dev_c);

	/** Copy the dev_c vector of sums **/

	cudaMemcpy( c, dev_c, N * sizeof( float ), cudaMemcpyDeviceToHost );

	cpu_show( c, N );

	cudaFree( dev_a );

	cudaFree( dev_b );

	cudaFree( dev_c );

	return 0;

}

So, I put a breakpoint in the line number 17( int tid = blockIdx.x; ), but debugger did not start there. Despite this, I continued debugging, step over, step over, but when debugger arrived to the line 33( cudaMalloc ) an error occurs: “Can not parse XML OS data; XML support was disabled at compile time”.

what are the steps for debugging? I saw the video(http://www.youtube.com/watch?feature=player_embedded&v=FAgq8VSWJ34#!) and it builds a debug project and then starts to debug.

Am I doing it wrong?

P.S: I just want to debug a kernel i.e a CUDA function, and view how threads works.

This is what I did:

[list=1]

Created a new project using runtime template.

Replaced code in the project source file with the one from this thread.

Built the project.

Set a breakpoint on line 17.

Clicked “Debug” on the main toolbar - application was launched and shortly stopped at main.

Clicked “Resume” (F8) - application broke in CUDA kernel.

There is little chance that this is due to some issue that was fixed since the CUDA Preview Release. Most likely is that the code fails due to some problem. You need to check error codes returned by CUDA calls. You can also use a debugger feature when it breaks on CUDA API failures. To make debugger break on API failure:

[list=1]

Stop the debug session if there is one in progress.

Go to Run->Debug Configuration… on the main menu.

Select debug configuration for your project in the left-hand tree.

Open “Debugger” tab and check “Break on CUDA API call failure”.

Note that this feature is experimental and is known to produce some false-positives in the CUDA 5.0 preview toolkit.

Hello!

I tried it configuring the debugger with the Break on CUDA API call failure option, but it gives me the same message…

So, I must think that is a CUDA’s pre-release error?

Edited: I noticed there was some problems:

But I don’t think it’s influencing…

That message is not an error so you may ignore it.

Can you create CUDA runtime project from the default template and debug it?

This is a known issue in the preview toolkit and will be fixed in RC version.

Thanks for the information.

No, I can’t. I built a default runtime project, but I can not debug it, the same error appears when the program calls “cudaMalloc”.

So… I was reading about it in other places… And the problem is “libexpat”, and I should compile gdb with USE=“expat”… but I never compiled cuda-gdb, so I don’t know how to do it…
How did the editor of the video to run cuda-gdb into parallel-nsight? :S

Can you run cuda-gdb from the command line?

Please note that cuda-gdb requires exclusive access to the CUDA device. It is, you cannot use same device to both draw your OS UI and debug CUDA application. Nsight was tested on the workstations with 2 CUDA devices and on Optimus laptops (ones that have both Intel video card and NVIDIA video card).

Uhmmm yes… I can debug the default runtime cuda project with CUDA-gdb in console mode… So I stopped the lightdm service and run cuda-gdb… I tried so many commands and all work fine…

What do you think?

You cannot debug on a device used to drive your OS UI. Do you have several video adapters? Visual debugging was tested on setups with several NVIDIA adapters and on Optimus laptops (when Intel graphics is used to drive the UI and NVIDIA adapter is used for debugging).

I have got just one Nvidia video card… So, Debugging mode under linux is not supported yet?
So, If I want to debug with and IDE Should I use Visual Studio?

Edited: Why the error appears to be related with the parser and not to the cuda-gdb per se.

Thanks!