display in Cuda

Hi everybody,

Sorry for my English, it’s not very good.

So, I use Cuda associated with C++ to develop a program on GPU and CPU.

I would like display an answers in the function device host but I don’t know how I do.

And I don’t understand how work cuPrint? Maybe, there are others possibility?

I hope someone can help me.

Alaninho

For the later cards and cudatoolkit printf command works from device, global and host functions.

If your card is of computability more than 2.0 you can use printf.
You have to define sm >=20 when you compile your code to be able to use printf()
After what you can use printf like in a cpu program.

just put printf in the code where you need to check and then when you compile add the flag -arch=sm_20 . If you put printf in a device or global function each thread will execute it, so you will get lots of prints.

How I know that my card is a computable with more 2.0?

And I have to write sm>=20 like option for the nvcc?

Sorry but I begin with cuda.

Alaninho

you can check the the nvidia webpage (http://developer.nvidia.com/cuda-gpus) or you can run the devicequery example from the SDK examples and check the compute capability of your device.

pasoleatis explained better than me, use a flag for compilation.

I was not really clear it is true, I will try to explain better next time.

If you know the name of your graphic card, have a look in google to know the compute capability. I don’t know a direct link with all the compute capability for all graphics cards.

Edit: pasoleatis definitively gave you the right answer.

Thank you, the compute capability is 2.1, thus, I can use printf?

I don’t understand the flag history? I must to write -arch=sm_20 in the line with nvcc?

Can you give me a example please?

Thank you pasoleatis and Dext for you help

If you have linux you compile somethong like nvcc -O2 -arch=sm_20 your_code.cu On windows you have projects and I have no idea.

I have a Makefile but I don’t where I can write -02 -arch=sm_20 my_code.cu

This my Makefile :

NVCC= nvcc

CPPC= g++

LIBEASEA=$(EZ_PATH)libeasea/

CXXFLAGS+=-g -Wall -O2 -I$(LIBEASEA)include -I$(EZ_PATH)boost

LDFLAGS=$(EZ_PATH)boost/program_options.a $(LIBEASEA)libeasea.a -lpthread

pemsa_arbre_SRC= pemsa_arbreIndividual.cpp

pemsa_arbre_MAIN_HDR= pemsa_arbre.cpp

pemsa_arbre_UC_HDR= pemsa_arbreIndividual.hpp

pemsa_arbre_HDR= $(pemsa_arbre_SRC:.cpp=.hpp) 

SRC= $(pemsa_arbre_SRC) $(pemsa_arbre_MAIN_HDR)

CUDA_SRC = pemsa_arbreIndividual.cu

HDR= $(pemsa_arbre_HDR) $(pemsa_arbre_UC_HDR)

OBJ= $(pemsa_arbre_SRC:.cpp=.o) $(pemsa_arbre_MAIN_HDR:.cpp=.o)

#USER MAKEFILE OPTIONS :

CPPFLAGS+=

#END OF USER MAKEFILE OPTIONS

CPPFLAGS+= -I$(LIBEASEA)include -I$(EZ_PATH)boost

NVCCFLAGS+= --compiler-options -fpermissive

BIN= pemsa_arbre

all:$(BIN)

$(BIN):$(OBJ)

	$(NVCC)  $^ -o $@ $(LDFLAGS) 

%.o:%.cu

	$(NVCC) $(NVCCFLAGS) -o $@ $< -c -DTIMING $(CPPFLAGS) -g -Xcompiler -Wall

easeaclean: clean

	rm -f Makefile pemsa_arbre.prm $(SRC) $(HDR) pemsa_arbre.mak $(CUDA_SRC) *.linkinfo pemsa_arbre.png pemsa_arbre.dat pemsa_arbre.vcproj pemsa_arbre.plot pemsa_arbre.r pemsa_arbre.csv pemsa_arbre.pop

clean:

	rm -f $(OBJ) $(BIN)

Try by adding this line, it should works. NVCCFLAGS means you add the flag you want to use for the nvcc compiler

#USER MAKEFILE OPTIONS :

NVCCFLAGS+= -arch=sm_20

#END OF USER MAKEFILE OPTIONS

If it works also try with -arch=sm_21 (I don’t know if that one works, so say me if it does work. I am curious)