Small error in matrixmul_drv/matrixmul_drv.cpp? Just an error report

Hi,

I just tried to compile the CUDA SDK samples and

[font=“Courier”]matrixmul_drv/matrixmul_drv.cpp[/font]

refused to compile. The error message was (using gcc version 4.1.2):

[font=“Courier”]matrixmul_drv.cpp: In function ‘CUresult initCUDA(char*, CUfunc_st**)’:
matrixmul_drv.cpp:207: error: jump to label ‘Error’
matrixmul_drv.cpp:191: error: from here
matrixmul_drv.cpp:193: error: crosses initialization of ‘char* module_path’
matrixmul_drv.cpp:207: error: jump to label ‘Error’
matrixmul_drv.cpp:187: error: from here
matrixmul_drv.cpp:193: error: crosses initialization of ‘char* module_path’
matrixmul_drv.cpp:207: error: jump to label ‘Error’
matrixmul_drv.cpp:184: error: from here
matrixmul_drv.cpp:193: error: crosses initialization of ‘char* module_path’[/font]

I took a look at the function and there seems to be a small error (I never used goto’s so I am not sure if this really is an error). I think [font=“Courier”]char* module_path[/font] should be defined before the first goto or the code after the error label can not be compiled/executed since it uses [font=“Courier”]module_path[/font]. :)

-Jens

BTW: Except that problem everything is working as expected even on an unsupported Ubuntu system. :)

I believe that this is an Ubuntu specific bug, as I cannot reproduce it under the supported RHEL-4.3-x86 environment.

Support for additional Linux distributions will be added at a future date.

Thanks,
Lonni

Did you look at the source code?

This is from matrixmul_drv.cpp (I highlighted the problematic parts)

[font=“Courier”]static CUresult

initCUDA(char* executablePath, CUfunction *pMatrixMul )

{

CUfunction cuFunction = 0;

cuDevice = 0;

CUresult status = cuInit();

if ( CUDA_SUCCESS != status )

goto Error;

char* module_path = cutFindFilePath(“matrixmul_kernel.cubin”, executablePath);

Error:

cuCtxDetach( );

free(module_path);

return status;

}[/font]

If the first branch is taken than module_path has not been defined … how can free be called? :blink:

I know this more C question than directly related to cuda and therefor may be considered off-topic … but I am curious anyway. :D

Hi Jensman,

Yes, this is indeed a bug in the sample code. We’ll have a fix in the next release. For now, you can easily fix it in your local copy:

If ( bug) goto Error;

char *p = new char[256]; // this line generates compile error

…

Error:

char *p;

If ( bug ) goto Error;

p = new char[256];	// no more compile error

...

Error:

Mark