Sunday, May 9, 2010

CUDA compilation on Linux (Makefiles)

I have been struggling with compiling complex CUDA code, with complex I mean a lot of .cu .F .cpp and .c files. I have created a makefile that can help you compile that kind of code. I'll try to give a quick view of it here explaining some parts:

First you'll need to specify the CUDA path and the compilers and linkers. Here I am using gcc and g++ for .c and .cpp files and nvcc for .cu files:

CUDA_INSTALL_PATH ?= /usr/local/cuda

CXX := g++
CC := gcc
LINK := g++ -fPIC
NVCC := nvcc -ccbin /usr/bin

Then you need to specify where to locate the CUDA header files :

# Includes
INCLUDES = -I. -I$(CUDA_INSTALL_PATH)/include

# Common flags
COMMONFLAGS += $(INCLUDES)
NVCCFLAGS += $(COMMONFLAGS)
CXXFLAGS += $(COMMONFLAGS)
CFLAGS += $(COMMONFLAGS)


Then you specify where to locate the CUDA binaries for linking :

LIB_CUDA := -L$(CUDA_INSTALL_PATH)/lib -lcudart


Then you specify the object files that the executable depends on and the name of the executable flle:

OBJS = sample_cuda_objectfile.cu.o sample_cpp_objectfile.cpp.o
TARGET = exec
LINKLINE = $(LINK) -o $(TARGET) $(OBJS) $(LIB_CUDA)


Finally you specify the compilation rules. The following are generic rules so all you need to do is change the OBJS and TARGET variables for compilation:

.SUFFIXES: .c .cpp .cu .o


%.c.o: %.c
$(CC) $(CFLAGS) -c $< -o $@

%.cu.o: %.cu
$(NVCC) $(NVCCFLAGS) -c $< -o $@

%.cpp.o: %.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@

$(TARGET): $(OBJS) Makefile
$(LINKLINE)

Tuesday, May 4, 2010

Contributing to Open Source (Why? and How?)

Open Source products are everywhere now, probably now you're using some of them. And I am sure that a lot of people are appreciating the role of open source. This post is about giving back to the community, helping others and moving forward one of the applications/tools you're using as a part of your everyday life.

Why Contribute to Open Source??

Sun Microsystems had a slogan "Change (Y)our world". And that summarizes what contributing to open source is all about. It's about making You better and making The World better. Let's make it clearer.

When you contribute to open source it helps you in some many ways, it gets you to code and practice and enhance your programming skills. Then gets your code reviewed, reviewed and then reviewed once more before it becomes a part of an official release. And finally it gets you to document your code.
Of course how much a project adds to your skills depends on the scale of the project and the importance of the feature you're implementing.

On the other hand, when you contribute to open source you're giving back to the community, helping improve the project you're contributing to and hence making someone's life easier by introducing a feature or fixing a bug and your code is out there for people to learn for it.


How to Contribute to Open Source??

First, you'll have to choose a project.
  • Start small, choose small project with a small code base that you can get familiar with easily and you can get the people who wrote the code easily too.
  • Choose a project you use, so you can be able to know what it needs and have clear vision of what's used for, what type of users you're targeting and what's missing that you once needed.
  • Choose a project you like, and that way you'll be able to give it the time and get to have a reason to commit some time for developing, testing and documenting.
You can start by scanning active projects on sourceforge or github where you can find active small scale projects.


Second, start communicating with the development community.
  • Join the project's development mailing lists and start scanning the e-mails to sense the trends and topics of interest to the community currently.
  • Join the project's IRC channel and start asking the questions you have (search for answers on the mailing lists, wiki and blog posts before going to IRC so you get an answer).
  • Chekout the code and compile it.
  • Check the project's bug tracker and try fixing a bug or two before working on a feature.

Finally if you find that you can work on the project CHECK FEATURES LIST START CODING.