fork download
  1. make
  2. mkdir -p build
  3. /usr/local/cuda/bin/nvcc -c -I/usr/local/cuda/include *.cu
  4. nvcc warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.
  5. ptxas /var/folders/8v/1gw9hxtx40qdp2slztw3whq80000gn/T//tmpxft_00012625_00000000-5_CUDA_ConvNN.ptx, line 745; warning : Double is not supported. Demoting to float
  6. clang++ -std=c++11 -c -m32 -I/usr/local/cuda/include *.cpp
  7. /usr/local/cuda/bin/nvcc -m32 -L/usr/local/cuda/lib -lcuda -lcudart -lm -o build/main *.o
  8. nvcc warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.
  9. clang: error: unknown argument: '-malign-double' [-Wunused-command-line-argument-hard-error-in-future]
  10. clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
  11. make: *** [build] Error 1
  12.  
  13. here the makefile:
  14. ------------------
  15. ------------------
  16. PROJECT_NAME = main
  17.  
  18. # NVCC is path to nvcc. Here it is assumed /usr/local/cuda is on one's PATH.
  19. # CC is the compiler for C++ host code.
  20.  
  21. NVCC = /usr/local/cuda/bin/nvcc
  22. CC = clang++ -std=c++11
  23.  
  24. CUDAPATH = /usr/local/cuda
  25. # Directories to search for
  26. #CUDA_ROOT = /usr/local/cuda
  27. #SDK_HOME = /Developer/NVIDIA/CUDA-6.0/C
  28.  
  29. BUILD_DIR = build
  30. # note that nvcc defaults to 32-bit architecture. thus, force C/LFLAGS to comply.
  31. # you could also force nvcc to compile 64-bit with -m64 flag. (and remove -m32 instances)
  32.  
  33. CFLAGS = -c -m32 -I$(CUDAPATH)/include
  34. NVCCFLAGS = -c -I$(CUDAPATH)/include
  35. LFLAGS = -m32 -L$(CUDAPATH)/lib -lcuda -lcudart -lm
  36.  
  37. all: build clean
  38.  
  39. build: build_dir gpu cpu
  40. $(NVCC) $(LFLAGS) -o $(BUILD_DIR)/$(PROJECT_NAME) *.o
  41.  
  42. build_dir:
  43. mkdir -p $(BUILD_DIR)
  44.  
  45. gpu:
  46. $(NVCC) $(NVCCFLAGS) *.cu
  47.  
  48. cpu:
  49. $(CC) $(CFLAGS) *.cpp
  50.  
  51. clean:
  52. rm *.o
  53.  
  54. run:
  55. ./$(BUILD_DIR)/$(PROJECT_NAME)
Not running #stdin #stdout 0s 0KB
stdin
#include <stdio.h>
#define SIZE	1024

void VectorAdd(int *a, int *b, int *c, int n)
{
	int i;

	for (i = 0; i < n; ++i)
		c[i] = a[i] + b[i];
}

int main()
{
	int *a, *b, *c;

	a = (int *)malloc(SIZE * sizeof(int));
	b = (int *)malloc(SIZE * sizeof(int));
	c = (int *)malloc(SIZE * sizeof(int));

	for (int i = 0; i < SIZE; ++i)
	{
		a[i] = i;
		b[i] = i;
		c[i] = 0;
	}

	VectorAdd(a, b, c, SIZE);

	for (int i = 0; i < 10; ++i)
		printf("c[%d] = %d\n", i, c[i]);

	free(a);
	free(b);
	free(c);

	return 0;
}
stdout
Standard output is empty