CUDA

CUDA By Example [未完待续]

2017-02-28  本文已影响150人  4c6ed2800025

首先附上源代码以及书中用的头文件: 链接: https://pan.baidu.com/s/1o8S9mJK 密码: edse


第三章

编译运行``时会遇到如下错误:

nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
../common/cpu_bitmap.h(49): warning: conversion from a string literal to "char *" is deprecated

julia_gpu.cu(44): error: calling a __host__ function("cuComplex::cuComplex") from a __device__ function("julia") is not allowed

julia_gpu.cu(45): error: calling a __host__ function("cuComplex::cuComplex") from a __device__ function("julia") is not allowed

julia_gpu.cu(50): error: calling a __host__ function("cuComplex::cuComplex") from a __device__ function("julia") is not allowed

julia_gpu.cu(50): error: calling a __host__ function("cuComplex::cuComplex") from a __device__ function("julia") is not allowed

4 errors detected in the compilation of "/tmp/tmpxft_00003437_00000000-9_julia_gpu.cpp1.ii".

解决方法:
将cuComplex 结构体的构造函数由

 cuComplex( float a, float b ) : r(a), i(b)  {}

改为

 __device__ cuComplex( float a, float b ) : r(a), i(b)  {}

第六章

当使用命令nvcc ray.cu编译时会遇到以下错误:

nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
../common/cpu_bitmap.h(49): warning: conversion from a string literal to "char *" is deprecated

../common/cpu_bitmap.h(49): warning: conversion from a string literal to "char *" is deprecated

/tmp/tmpxft_000031e1_00000000-16_ray.o: In function `CPUBitmap::display_and_exit(void (*)(void*))':
tmpxft_000031e1_00000000-4_ray.cudafe1.cpp:(.text._ZN9CPUBitmap16display_and_exitEPFvPvE[_ZN9CPUBitmap16display_and_exitEPFvPvE]+0x5d): undefined reference to `glutInit'
tmpxft_000031e1_00000000-4_ray.cudafe1.cpp:(.text._ZN9CPUBitmap16display_and_exitEPFvPvE[_ZN9CPUBitmap16display_and_exitEPFvPvE]+0x67): undefined reference to `glutInitDisplayMode'
tmpxft_000031e1_00000000-4_ray.cudafe1.cpp:(.text._ZN9CPUBitmap16display_and_exitEPFvPvE[_ZN9CPUBitmap16display_and_exitEPFvPvE]+0x7e): undefined reference to `glutInitWindowSize'
tmpxft_000031e1_00000000-4_ray.cudafe1.cpp:(.text._ZN9CPUBitmap16display_and_exitEPFvPvE[_ZN9CPUBitmap16display_and_exitEPFvPvE]+0x88): undefined reference to `glutCreateWindow'
tmpxft_000031e1_00000000-4_ray.cudafe1.cpp:(.text._ZN9CPUBitmap16display_and_exitEPFvPvE[_ZN9CPUBitmap16display_and_exitEPFvPvE]+0x92): undefined reference to `glutKeyboardFunc'
tmpxft_000031e1_00000000-4_ray.cudafe1.cpp:(.text._ZN9CPUBitmap16display_and_exitEPFvPvE[_ZN9CPUBitmap16display_and_exitEPFvPvE]+0x9c): undefined reference to `glutDisplayFunc'
tmpxft_000031e1_00000000-4_ray.cudafe1.cpp:(.text._ZN9CPUBitmap16display_and_exitEPFvPvE[_ZN9CPUBitmap16display_and_exitEPFvPvE]+0xa1): undefined reference to `glutMainLoop'
/tmp/tmpxft_000031e1_00000000-16_ray.o: In function `CPUBitmap::Draw()':
tmpxft_000031e1_00000000-4_ray.cudafe1.cpp:(.text._ZN9CPUBitmap4DrawEv[_ZN9CPUBitmap4DrawEv]+0x29): undefined reference to `glClearColor'
tmpxft_000031e1_00000000-4_ray.cudafe1.cpp:(.text._ZN9CPUBitmap4DrawEv[_ZN9CPUBitmap4DrawEv]+0x33): undefined reference to `glClear'
tmpxft_000031e1_00000000-4_ray.cudafe1.cpp:(.text._ZN9CPUBitmap4DrawEv[_ZN9CPUBitmap4DrawEv]+0x5c): undefined reference to `glDrawPixels'
tmpxft_000031e1_00000000-4_ray.cudafe1.cpp:(.text._ZN9CPUBitmap4DrawEv[_ZN9CPUBitmap4DrawEv]+0x61): undefined reference to `glFlush'
collect2: error: ld returned 1 exit status

解决方案为使用nvcc ray.cu -lglut -lGL来进行编译。

上一篇下一篇

猜你喜欢

热点阅读