Nvcc compiler options on Eclipse

Hello!

I’m trying to get an imaging problem writenn in c++ to work with some CUDA kernels to see if I can get a decent speed up. However, I get that infamous “error: support for exception handling is disabled”. Now, I know that I have to append --host-compilation c++ to the nvcc call, but I’m completely incapable of finding where to set that up in eclipse. Been googling for hours now, and despite always ending up in project options, I can’t see where to give compiling options to nvcc compiler, only find gcc/gcc++ ones.

Hopefully someone around here is better versed in Eclipse than me and can give me the solution.

Thanks in advance,

phonta

hi,
Im not exactly sure whether we have the same problem or not…but here is what im facing:

Im having a tough time trying to figure out how i can get the nvcc compiler to compile my *.cu files in eclipse.
I followed the instruction given in http://www.ai3.uni-bayreuth.de/index.php?s…aqt%2Findex.php
The post is there on one of the nvidia forums too…so im guessing it should work.

However if you go through that link… one of the screenshots show that you should get the NVIDIA nvcc tool chain editor option after you have installed the updates…I dont get that option!..ive installed the updates but the NVDIA nvcc option does not show up on projects->properties>c++ Build->tool chain editor.

Kinda stuck, if you have worked you way around this…please let me know.

hi,
Im not exactly sure whether we have the same problem or not…but here is what im facing:

Im having a tough time trying to figure out how i can get the nvcc compiler to compile my *.cu files in eclipse.
I followed the instruction given in http://www.ai3.uni-bayreuth.de/index.php?s…aqt%2Findex.php
The post is there on one of the nvidia forums too…so im guessing it should work.

However if you go through that link… one of the screenshots show that you should get the NVIDIA nvcc tool chain editor option after you have installed the updates…I dont get that option!..ive installed the updates but the NVDIA nvcc option does not show up on projects->properties>c++ Build->tool chain editor.

Kinda stuck, if you have worked you way around this…please let me know.

hi,
Im not exactly sure whether we have the same problem or not…but here is what im facing:

Im having a tough time trying to figure out how i can get the nvcc compiler to compile my *.cu files in eclipse.
I followed the instruction given in http://www.ai3.uni-bayreuth.de/index.php?s…aqt%2Findex.php
The post is there on one of the nvidia forums too…so im guessing it should work.

However if you go through that link… one of the screenshots show that you should get the NVIDIA nvcc tool chain editor option after you have installed the updates…I dont get that option!..ive installed the updates but the NVDIA nvcc option does not show up on projects->properties>c++ Build->tool chain editor.

Kinda stuck, if you have worked you way around this…please let me know.

hi,
Im not exactly sure whether we have the same problem or not…but here is what im facing:

Im having a tough time trying to figure out how i can get the nvcc compiler to compile my *.cu files in eclipse.
I followed the instruction given in http://www.ai3.uni-bayreuth.de/index.php?s…aqt%2Findex.php
The post is there on one of the nvidia forums too…so im guessing it should work.

However if you go through that link… one of the screenshots show that you should get the NVIDIA nvcc tool chain editor option after you have installed the updates…I dont get that option!..ive installed the updates but the NVDIA nvcc option does not show up on projects->properties>c++ Build->tool chain editor.

Kinda stuck, if you have worked you way around this…please let me know.

Try this:

  1. ctrl + mouse click on your project name --> select properties (or on the menu project --> properties)

  2. c/c++ build --> tool chain editor

  3. uncheck display compatible toolchains only

I believe the nvcc toolchain will be in the current toolchain listing, or in the used tools box. I installed the plugin from the website, but couldn’t get the make to build correctly.

Post your results if you are successful so I can attempt as well.

If you want, you can use this simple Makefile hack I created. Just copy and drop it within the top directory structure of your project (and modify it to fit you needs).

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

########

Makefile for CUDA

A hack created by skeeloo to compile .cu files within Eclipse

This makefile assumes you separate the device and host code into

separate files:

HOST: _H appended to file name (code_H.cu)

DEVICE: _D appended to file name (code_D.cu)

Replace the following with your own information:

CUDA_INSTALL_PATH: /path/to/your/cuda/installation

PROGRAM: Name of Executable

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

########

CUDA Installation Path

CUDA_INSTALL_PATH = /usr/local/cuda

Source Folder (Relative to where Makefile is located)

SRC_FOLDER = src

Compiler

NVCC = $(CUDA_INSTALL_PATH)/bin/nvcc

Includes

INCLUDE = $(CUDA_INSTALL_PATH)/include

Program or Executable

PROGRAM = mandelbrotCUDA

Device Code

DEVICE = _D

Host Code

HOST = _H

all : $(PROGRAM)

Create Executable by linking *.o (host and device object’s)

(PROGRAM) : (PROGRAM)(DEVICE).o (PROGRAM)$(HOST).o

$(NVCC) -o $(PROGRAM) $^

Compile device code to an object

(PROGRAM)(DEVICE).o : (SRC_FOLDER)/(PROGRAM)$(DEVICE).cu

$(NVCC) -I $(INCLUDE) -o $@ -c $<

Compile host code to an object

(PROGRAM)(HOST).o : (SRC_FOLDER)/(PROGRAM)$(HOST).cu

$(NVCC) -I $(INCLUDE) -o $@ -c $<

Remove *.o files and executables

clean :

rm *.o $(PROGRAM)

Try this:

  1. ctrl + mouse click on your project name --> select properties (or on the menu project --> properties)

  2. c/c++ build --> tool chain editor

  3. uncheck display compatible toolchains only

I believe the nvcc toolchain will be in the current toolchain listing, or in the used tools box. I installed the plugin from the website, but couldn’t get the make to build correctly.

Post your results if you are successful so I can attempt as well.

If you want, you can use this simple Makefile hack I created. Just copy and drop it within the top directory structure of your project (and modify it to fit you needs).

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

########

Makefile for CUDA

A hack created by skeeloo to compile .cu files within Eclipse

This makefile assumes you separate the device and host code into

separate files:

HOST: _H appended to file name (code_H.cu)

DEVICE: _D appended to file name (code_D.cu)

Replace the following with your own information:

CUDA_INSTALL_PATH: /path/to/your/cuda/installation

PROGRAM: Name of Executable

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

########

CUDA Installation Path

CUDA_INSTALL_PATH = /usr/local/cuda

Source Folder (Relative to where Makefile is located)

SRC_FOLDER = src

Compiler

NVCC = $(CUDA_INSTALL_PATH)/bin/nvcc

Includes

INCLUDE = $(CUDA_INSTALL_PATH)/include

Program or Executable

PROGRAM = mandelbrotCUDA

Device Code

DEVICE = _D

Host Code

HOST = _H

all : $(PROGRAM)

Create Executable by linking *.o (host and device object’s)

(PROGRAM) : (PROGRAM)(DEVICE).o (PROGRAM)$(HOST).o

$(NVCC) -o $(PROGRAM) $^

Compile device code to an object

(PROGRAM)(DEVICE).o : (SRC_FOLDER)/(PROGRAM)$(DEVICE).cu

$(NVCC) -I $(INCLUDE) -o $@ -c $<

Compile host code to an object

(PROGRAM)(HOST).o : (SRC_FOLDER)/(PROGRAM)$(HOST).cu

$(NVCC) -I $(INCLUDE) -o $@ -c $<

Remove *.o files and executables

clean :

rm *.o $(PROGRAM)

hey,

i did the toolchain thing u said…now the problem is i get an error saying nvcc: command not found…I have set my path variable through the terminal. If i try to run a program in the terminal, it seems to works fine, But not in eclipse. Ive spent a lot of time in this, kinda desperate to get this fixed. Plz help.

Yes! Alright, so you get got the toolchain problem resolved!

For Eclipse to recognize “nvcc”, I believe you need to set the environmental variables for your project:

  1. Click on your project name

  2. Ctrl + mouse click and select properties (it should be at the bottom of the list)

  3. Click on C/C++ Build --> Environment

  4. You will see the box "Environmental variables to set … I think this is where you will need to add the variable PATH with /usr/local/cuda/bin as its value

Add Button --> Name: PATH, Value: /usr/local/cuda/bin

  1. While you’re at it, you should probably add the Environmental Variable DYLD_LIBRARY_PATH with value /usr/local/cuda/lib

Hopefully this works. You can check out my blog for a quick how-to on CUDA + Eclipse Integration. Though, I take the route of creating my own makefile and dropping it into my project.

http://skeelooslaboratory.blogspot.com/

If you use your own makefile, I can provide a brief example code for you to test it out

I’m gonna post some stuff on MPI + CUDA + Eclipse if I can get it to work…

Just wondering if you were able to get nvcc to work in Eclipse …

I’ve posted a Quickstart on my blog on how to use the Plugin provided by Bayreuth University … check it out. Let me know if you have any problems:

http://skeelooslaboratory.blogspot.com/201…g-bayreuth.html

You can drop the following .cu files into your source folder to test out the build:

mandelbrotCUDA_D.cu (Device Code)

[codebox]/*

  • mandelbrotCUDA_D.cu

  • Created on: May 25, 2010

  •  Author: marklagatuz
    

*/

#define SIZE 1024

#define MAX_ITER 255

#define DEBUG 1

#include

global void compute(float* ptr_d) {

// Block Index

int bIdx = blockIdx.x;

// Thread Index

int tIdx = threadIdx.x;

// Number of Threads in a Block

int bDimx = blockDim.x;

//printf("bIdx --> %d "

//		"bDimx --> %d "

//	   "tIdx --> %d\n\n",

//	   bIdx, bDimx, tIdx);

int col,

	xmin = -2,

	xmax = 2,

	ymin = -2,

	ymax = 2,

	n;

double c_real, c_imag, x, y;

double cw_x, cw_y;

for (col = 0; col < SIZE; ++col) {

	//------------------------------------

	// convertToWorld

	cw_x = col;

	cw_y = SIZE - tIdx;

	cw_x /= SIZE;

	cw_y /= SIZE;

	cw_x = ( cw_x * (xmax - xmin) + xmin );

	cw_y = ( cw_y * (ymax - ymin) + ymin );

	c_real = cw_x;

	c_imag = cw_y;

	//------------------------------------

	x = y = 0.0;

	n = 0;

	while ( (n < MAX_ITER) && ( ((x * x) + (y * y) ) < 4.0) ) {

		//------------------------------------

		// compute

		x = ( (x * x) - (y * y) ) + c_real;

		y = (2 * (x * y)) + c_imag;

		//------------------------------------

		n++;

	}

	/*if (DEBUG) {

		printf("Device: Index --> %d "

		   	   "Row: %d "

			   "Col: %d "

			   "n = %d\n",

				( ( (bIdx * bDimx) + tIdx) * SIZE ) + col,

				(bIdx * bDimx) + tIdx, col, n);

	}*/

	// Row --> blockIdx.x * blockDim.x + threadIdx.x

	// Index --> Row * SIZE + col

	ptr_d[( ( (bIdx * bDimx) + tIdx ) * SIZE) + col] = n;

}

}[/codebox]

mandelbrotCUDA_H.cu (Host code)

[codebox]/*

  • mandelbrotCUDA_H.cu

  • Created on: May 25, 2010

  •  Author: marklagatuz
    

*/

#define SIZE 1024

#define BLOCKS 2

#define THREADS 256

#define DEBUG 1

#include

using namespace std;

global void compute(float* ptr_d);

int main (int argc, char* argv) {

int numBlocks = BLOCKS;

int numThreads = THREADS;

// Variables used to print (DEBUG)

int row,

	col;

// Host Computation Buffer

float *ptr_h = new float[BLOCKS * THREADS * SIZE* 256];

// Device Computation Buffer

float *ptr_d;

// Allocate Device Buffer

cudaMalloc((void**)&ptr_d, BLOCKS * THREADS * SIZE * 256);

// Copy Buffer to Device

cudaMemcpy(ptr_d, ptr_h, BLOCKS * THREADS * SIZE * 256, cudaMemcpyHostToDevice);

// Launch the device computation

compute<<<numBlocks, numThreads>>>(ptr_d);

// Read computation from Device

cudaMemcpy(ptr_h, ptr_d, BLOCKS * THREADS * SIZE * 256, cudaMemcpyDeviceToHost);

// Free Device Memory

cudaFree(ptr_d);

if (DEBUG) {

	cout << endl << endl;

	for (row = 0; row < (BLOCKS * THREADS); ++row) {

		for (col = 0; col < SIZE; ++col) {

			cout << "Host: Index --> "

				 << ( row * SIZE ) + col

				 <<	" Row: " << row

				 << " Col: " << col

				 << " --> n = " << ptr_h[(row * SIZE) + col]

				 << endl;

		}

	}

}

delete ptr_h;

return 0;

}

[/codebox]