我正在尝试将 CUDA 添加到 90 年代后期某个时候编写的现有单线程 C 程序中。
为此,我需要混合两种语言,C 和 C++(nvcc 是一个 c++ 编译器)。
问题是 C++ 编译器将结构视为特定大小,而 C 编译器将相同结构视为大小略有不同。那很糟。我对此感到非常困惑,因为我找不到导致 4 字节差异的原因。
/usr/lib/gcc/i586-suse-linux/4.3/../../../../i586-suse-linux/bin/ld: Warning: size of symbol `tree' changed from 324 in /tmp/ccvx8fpJ.o to 328 in gpu.o
我的 C++ 看起来像
#include <stdio.h>
#include <stdlib.h>
#include "assert.h"
extern "C"
{
#include "structInfo.h" //contains the structure declaration
}
...
我的 C 文件看起来像
#include "structInfo.h"
...
structInfo.h 看起来像
struct TB {
int nbranch, nnode, root, branches[NBRANCH][2];
double lnL;
} tree;
...
我的make文件看起来像
PRGS = prog
CC = cc
CFLAGS=-std=gnu99 -m32
CuCC = nvcc
CuFlags =-arch=sm_20
LIBS = -lm -L/usr/local/cuda-5.0/lib -lcuda -lcudart
all : $(PRGS)
prog:
$(CC) $(CFLAGS) prog.c gpu.o $(LIBS) -o prog
gpu.o:
$(CuCC) $(CuFlags) -c gpu.cu
有人问我为什么不使用不同的主机编译选项。我认为主机编译选项自 2 版前已被弃用?而且它似乎从来没有像它所说的那样做。
nvcc warning : option 'host-compilation' has been deprecated and is ignored