我的项目由五个 CUDA 文件组成:main.cu jacobian_kernel.cu hermite_kernel.cu cuSolver_LU.cpp Utilities.cu
,其中最后一个改编自这个 GitHub repo,连同它的Utilities.h
头文件;三个标题是args.h linear_solver.h Utilities.h
.
nvcc 成功编译它们,但是在构建trbdf2
可执行文件时,它对我大喊多个定义错误,例如:
nvcc -Xcompiler -fopenmp -o obj/trbdf2 obj/jacobian_kernel.o obj/hermite_kernel.o obj/utils.o obj/cusolver_lu.o obj/main.o -I/usr/local/cuda-8.0/targets/x86_64-linux/include -I../include -I/usr/local/cuda-8.0/samples/common/inc/ -L/usr/local/cuda-8.0/targets/x86_64-linux/lib -lgomp -lcublas -lcudart -lcusolver -lcusparse
obj/hermite_kernel.o: In function `vec_norminf(int, double const*)':
tmpxft_00006336_00000000-4_hermite_kernel.cudafe1.cpp:(.text+0xba1): multiple definition of `vec_norminf(int, double const*)'
obj/jacobian_kernel.o:tmpxft_00006312_00000000-4_jacobian_kernel.cudafe1.cpp:(.text+0xba1): first defined here
obj/hermite_kernel.o: In function `mat_norminf(int, int, double const*, int)':
tmpxft_00006336_00000000-4_hermite_kernel.cudafe1.cpp:(.text+0xc20): multiple definition of `mat_norminf(int, int, double const*, int)'
obj/jacobian_kernel.o:tmpxft_00006312_00000000-4_jacobian_kernel.cudafe1.cpp:(.text+0xc20): first defined here
...
obj/main.o: In function `second()':
tmpxft_00006385_00000000-4_main.cudafe1.cpp:(.text+0xf32): multiple definition of `second()'
obj/jacobian_kernel.o:tmpxft_00006312_00000000-4_jacobian_kernel.cudafe1.cpp:(.text+0xf32): first defined here
collect2: error: ld returned 1 exit status
Makefile:17: recipe for target 'obj/trbdf2' failed
make: *** [obj/trbdf2] Error 1
现在,我很确定我多次helper_cusolver.h
包含 CUDA 工具包提供的头文件,它定义了函数vec_norminf
、mat_norminf
等。我猜不出如何重写我的标题,开头如下:
参数.h:
#if !defined(ARGS_H_)
#define ARGS_H_
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <cuda.h>
#include <cuda_runtime.h>
#include <helper_cuda.h>
#include "Utilities.h"
...
#endif
线性求解器.h:
#ifndef LINEAR_SOLVER_H_
#define LINEAR_SOLVER_H_
#include <cublas_v2.h>
#include <cusparse_v2.h>
#include <cusolverDn.h>
#include <helper_cusolver.h>
...
#endif
实用程序.h:
#ifndef UTILITIES_CUH
#define UTILITIES_CUH
#include "linear_solver.h"
...
#endif
此外,依赖项是:
jacobian_kernel.cu, hermite_kernel.cu -> args.h
cuSolver_LU.cpp -> args.h, linear_solver.h, Utilities.h
main.cu -> args.h, linear_solver.h, Utilities.h
Utilities.cu -> linear_solver.cu
此外,Utilities.cu
初始指令与其他 cuda 文件开头的指令有点不同,但它是我项目中最近添加的,在添加之前我遇到了同样的错误;无论如何,这里是:
#include "cuda_runtime.h"
#include <cuda.h>
#if defined(__CUDACC__) && (CUDA_VERSION >= 7000)
#include <cusolverDn.h>
#endif
#include <cublas_v2.h>
#include "Utilities.h"
长话短说,问题似乎是helper_cusolver.h
标题被多次包含,尽管我什至在linear_solver.h
标题的第一行中放置了一些标题保护;我已经尝试了#pragma once
受支持的指令,nvcc
我什至检查了helper_cusolver
.
我是 C/C++ 的初学者,我真的不知道如何从这里开始。我尝试#include
一次取消注释大多数(显然是多个)指令,但我一直收到相同的错误。
让我知道我是否应该包含其他信息。
编辑此外,当我用示例的 cudaCheckErrors 或 Utilities.cu 中的 GitHub 的 cusolveSafeCall 包装 CUDA 和/或 cuSolver 函数时,它们似乎没有被定义:
cuSolver_LU.cpp: In function ‘void linearSolverLU(cusolverDnHandle_t, int, const double*, int, const double*, double*)’:
cuSolver_LU.cpp:28:51: error: cannot convert ‘cudaError_t {aka cudaError}’ to ‘cusolverStatus_t’ for argument ‘1’ to ‘void cusolveSafeCall(cusolverStatus_t)’
cusolveSafeCall(cudaMalloc(&info, sizeof(int)));
尽管标题 Utilities.h 已正确包含。我认为这可能是有用的信息,以便找到不正确的指令。