c++ - CUDA error: expected constructor, destructor, or type conversion before 'void' -


i new cuda programing. practice, trying run simple program adds elements in 2 arrays , stores result in new array. organization purposes, trying separating code multiple files. thank in advanced!

i keep getting error when try compile it: "hello.cpp:6: error: expected constructor, destructor, or type conversion before ‘void’"

here code: hello.cpp

#include <simple.h> #include <stdlib.h> #include <stdio.h> #define n 100  __global__ void add(int *a, int *b, int *c) {    int tid = blockidx.x;   if (tid < n)     {       adding(a, b, c, tid);     } }  int main() {   int a[n], b[n], c[n];   int *dev_a, *dev_b, *dev_c;   cudamalloc((void **) &dev_a, n*sizeof(int));   cudamalloc((void **) &dev_b, n*sizeof(int));   cudamalloc((void **) &dev_c, n*sizeof(int));   // fill arrays   (int = 0; < n; i++)     {       a[i] = i,     b[i] = 1;     }   cudamemcpy(dev_a, a, n*sizeof(int), cudamemcpyhosttodevice);   cudamemcpy(dev_b, b, n*sizeof(int), cudamemcpyhosttodevice);   add<<<n,1>>>(dev_a, dev_b, dev_c);   cudamemcpy(c, dev_c, n*sizeof(int), cudamemcpydevicetohost);   (int = 0; < n; i++)     {       printf("%d + %d = %d\n", a[i], b[i], c[i]);     }   return 0; } 

simple.cpp

#include <simple.h>  __device__ void adding(int *a, int *b, int *c, int tid) {        c[tid] = a[tid] + b[tid];   } 

simple.h

#ifndef __simple_h__ #define __simple_h__   __device__ void adding(int *a, int *b, int *c, int tid); #endif 

makefile

objects = hello.o simple.o  all: $(objects)     /usr/local/cuda-7.0/bin/nvcc -arch=sm_20 $(objects) -o app  %.o: %.cpp %.cu     /usr/local/cuda-7.0/bin/nvcc -x cu -arch=sm_20 -i. -dc $< -o $@  clean:     rm -f *.o app 

when run project on computer, make seems use implicit variables when compiling *.cpp files results in using g++ instead of using nvcc specified.

to change behavior, have set variables cxx , cxxflags. following makefile worked me:

objects = hello.o simple.o  cxx = /usr/local/cuda-7.0/bin/nvcc cxxflags = -x cu -arch=sm_20 -i. -dc  all: $(objects)     $(cxx) $(objects) -o app  %.o: %.cpp %.cu     $(cxx) $(cxxflags) $< -o $@ 

Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -