[Jetson TK1] Use CUDA class inside C++ project

Hello,

I am currently working on a C++ project and I want to replace a function within this project with a similar one written in CUDA.

I am developing the code directly on Jetson and I am using Eclipse; not the Nsight version because I read that it is not supported by Jetson.

Can someone help me with the procedure for embedding CUDA code (class) in a C++ project? I checked online and I could not find any tutorial.

Thanks,
Fabio

Did you look at the CUDA samples? http://elinux.org/Jetson/Installing_CUDA

You can compile C++ file without CUDA related code with g++.
And you can compile CUDA code with nvcc.
Then, you can link them with nvcc to output executable file.

My Makefile is looks like this:

CXX := g++
NVCC := nvcc

CCFLAGS := -std=c++11 -Wall -Wextra
NVCCFLAGS := -std c++11

$(PROGNAME) : $(OBJS)
        $(NVCC) --linker-options --gc-sections -o $@ $^

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

%.o : %.cu
        $(NVCC) $(NVCCFLAGS) -dc -o $@ $^

My .cu files have both device functions and host functions.
Device functions in the .cu files are not accessible from other .cu or .cpp file.
But host functions in the .cu files can be called from other .cpp files.

I use thrust library.
It is similar to STL and in C++.
http://docs.nvidia.com/cuda/thrust/index.html

If you define a class which have thrust::device_vector or thrust::host_vector and it is used in .cpp files, they need to be invisible to .cpp.
You can use Pimpl Idiom to hide them.

The Nsight Eclipse/Visual Studio Editions have been developed specifically for Jetson. Where did you read the opposite of this? Also, if you are writing native code, how are you able to run Eclipse on the Jetson? The Eclipse IDE does not support ARM architecture.

@demotomohiro: Thanks for you reply. What happens if I compile the whole project that contains CUDA code and C++ with nvcc? I made a simple hello world example and it works fine.

@CRAKC: what I understood is that I cannot use Nsight Eclipse DIRECTLY on Jetson. I can only use it to cross-compile projects (http://devblogs.nvidia.com/parallelforall/nvidia-nsight-eclipse-edition-for-jetson-tk1/). Whereas in my case I want to use Eclipse directly on Jetson. I managed to do it though. Following this “http://pourounas.blogspot.co.uk/2012/03/getting-ready-to-develop-with-cuda-in.html” plus some modifications I managed to compile CUDA code directly on Jetson via Eclipse CDT.