Example program clock.cu Warnings, showing up on example code?

In the compilation of clock.cu, I used the following command line as shown below. It did compile clock.cu, but made some unusual warnings. Take the last two first. It says timedReduction was declared, but never referenced. The clock.cu function does reference it. Yet, it says that it does not? I cannot understand the reason for the warning. In the second one format ‘%d’ expects type ‘int’, but argument 2 has type ‘long int’. indeed it does, Is this bad programming on this source code. Again, the program does compile, but issues a lot of warnings. is this bad practice. Again why doe s it say timedReduction was declared, but never referenced when clearly it is.

nvcc -g -G -I…/…/common/inc -L…/…/lib -I /home/errol/NVIDIA_GPU_Computing_SDK/shared/inc -L /home/errol/NVIDIA_GPU_Computing_SDK/C/lib -L /home/errol/NVIDIA_GPU_Computing_SDK/shared/lib -o clock clock.cu clock_kernel.cu -lcutil_i386 -lshrutil_i386
clock.cu: In function ‘int main(int, char**)’:
clock.cu:100: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘long int’
clock_kernel.cu(22): warning: function “timedReduction” was declared but never referenced

clock_kernel.cu(22): warning: function “timedReduction” was declared but never referenced

Newport_j

I don’t expect that you will understand why, but the warning is correct - at the scope of clock_kernel.cu timeReduction is never referenced. Device code compilation and assembly occurs at file scope. There is no device code linker. You are actually compiling timeReduction twice. If you look at the code inside clock.cu and the Makefile, it should be obvious why.

Of course the obvious question is why bother using anything other than the perfectly good Makefile provided?

If we are actually compiling timeReduction twice let us examine the makefile:

############################################################

#####################

# Copyright 1993-2006 NVIDIA Corporation.  All rights reserved.

#

# NOTICE TO USER:   

#

# This source code is subject to NVIDIA ownership rights under U.S. and 

# international Copyright laws.  

#

# NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE 

# CODE FOR ANY PURPOSE.  IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR 

# IMPLIED WARRANTY OF ANY KIND.  NVIDIA DISCLAIMS ALL WARRANTIES WITH 

# REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF 

# MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.   

# IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, 

# OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 

# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 

# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE 

# OR PERFORMANCE OF THIS SOURCE CODE.  

#

# U.S. Government End Users.  This source code is a "commercial item" as 

# that term is defined at 48 C.F.R. 2.101 (OCT 1995), consisting  of 

# "commercial computer software" and "commercial computer software 

# documentation" as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) 

# and is provided to the U.S. Government only as a commercial end item.  

# Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through 

# 227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the 

# source code with only those rights set forth herein.

#

############################################################

####################

#

# Build script for project

#

############################################################

####################

# Add source files here

EXECUTABLE	:= clock

# Cuda source files (compiled with cudacc)

CUFILES		:= clock.cu

# C/C++ source files (compiled with gcc / c++)

CCFILES		:=

############################################################

####################

# Rules and targets

include ../../common/common.mk

Now how are we compiling timeReduction twice? I do not see it.

Newport_j

Not the makefile, your own build commands:

nvcc -g -G -I../../common/inc -L../../lib -I /home/errol/NVIDIA_GPU_Computing_SDK/shared/inc -L /home/errol/NVIDIA_GPU_Computing_SDK/C/lib -L /home/errol/NVIDIA_GPU_Computing_SDK/shared/lib -o clock clock.cu clock_kernel.cu -lcutil_i386 -lshrutil_i386

The makefile only compiles clock.cu. You compiled both clock.cu and clock_kernel.cu. If you look in clock.cu you will see it #includes clock_kernel.cu. Therefore, you compiled the kernel twice. In a regular C build, you would get a link error because of duplicate symbols. In CUDA you don’t, because there is no linker for device code. But the compiler provides a warning that the kernel instance compiled in clock_kernel.cu is never used. Which is correct.