gpt4 book ai didi

c++ - CUDA C++ 链接错误 undefined reference threadIdx.x

转载 作者:行者123 更新时间:2023-11-30 05:32:10 31 4
gpt4 key购买 nike

您好,您正在尝试在 CUDA 上并行化格子玻尔兹曼求解器。不知何故,我在将目标文件链接在一起时遇到错误。对象编译没有错误。

LBMSolver.o: In function >LBMSolver::calcMoments_GPU(LBMUniformGrid2D::LBMGridNode**, int)':
tmpxft_00004b33_00000000-3_LBMSolver.cudafe1.cpp:(.text+0x939): undefined >reference to
blockDim' tmpxft_00004b33_00000000-3_LBMSolver.cudafe1.cpp:(.text+0x93f): undefined >reference to blockIdx'
tmpxft_00004b33_00000000-3_LBMSolver.cudafe1.cpp:(.text+0x948): undefined >reference to
threadIdx' tmpxft_00004b33_00000000-3_LBMSolver.cudafe1.cpp:(.text+0x953): undefined >reference to blockDim'
tmpxft_00004b33_00000000-3_LBMSolver.cudafe1.cpp:(.text+0x959): undefined >reference to
blockIdx' tmpxft_00004b33_00000000-3_LBMSolver.cudafe1.cpp:(.text+0x962): undefined >reference to `threadIdx'

这是我的生成文件:

OBJS = main.o LBMSolver.o LBMUniformGrid2D.o LBMBoundaryConditions.o   writeVTK.o
CC = g++
NVCC = nvcc
CFLAGS = -Wall -c
LFLAGS = -Wall
XCOMPILER = -Xcompiler "-Wall"
NVCFLAGS = -c -G -g -ccbin=$(CC) $(XCOMPILER)
NVLFLAGS = -G -g -ccbin=$(CC) $(XCOMPILER)


main : $(OBJS)
$(NVCC) $(NVLFLAGS) $(OBJS) -o main

main.o : main.cu LBMSolver.h writeVTK.h
$(NVCC) $(NVCFLAGS) main.cu

LBMSolver.o : LBMSolver.cu LBMSolver.h LBMUniformGrid2D.h LBMBoundaryConditions.h
$(NVCC) $(NVCFLAGS) LBMSolver.cu

LBMBoundaryConditions.o : LBMBoundaryConditions.cu LBMBoundaryConditions.h LBMSolver.h
$(NVCC) $(NVCFLAGS) LBMBoundaryConditions.cu

LBMUniformGrid2D.o : LBMUniformGrid2D.cpp LBMUniformGrid2D.h
$(CC) $(CFLAGS) LBMUniformGrid2D.cpp

writeVTK.o : writeVTK.h writeVTK.cpp
$(CC) $(CFLAGS) writeVTK.cpp

clean_obj:
\rm *.o main

报错的函数和头文件:

#pragma once
#include "LBMUniformGrid2D.h"
#include <cuda.h>

#ifdef __CUDACC__
#define CUDA_HOSTDEV __host__ __device__
#else
#define CUDA_HOSTDEV
#endif

class LBMSolver{
...
CUDA_HOSTDEV void calcMoments_GPU(LBMUniformGrid2D::LBMGridNode **field, int nx);

__host__ __device__ void LBMSolver::calcMoments_GPU(LBMUniformGrid2D::LBMGridNode **field, int nx){
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;

LBMUniformGrid2D::LBMGridNode *node;
node = field[x+y*nx];
calc_rho_GPU(node);
calc_ux_GPU(node);
calc_uy_GPU(node);
calc_v_GPU(node);
}

最佳答案

您不能将包含设备代码的函数定义为 __host__,因为主机代码不支持特定于设备的功能。删除它,事情可能会正确编译。

关于c++ - CUDA C++ 链接错误 undefined reference threadIdx.x,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35228158/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com