编译 CUDA cuSolver 特征值示例时出现编译错误
Posted
技术标签:
【中文标题】编译 CUDA cuSolver 特征值示例时出现编译错误【英文标题】:compilation error while compiling CUDA cuSolver eigenvalue examples 【发布时间】:2021-11-01 22:34:36 【问题描述】:我是 CUDA 的新手,我正在编译和测试 Nvidia 提供的一些示例。我能够编译和运行示例 here 没有任何问题,所以我认为我通常有一个正常运行的系统。
现在,我正在尝试编译this example code,它还需要同一站点的头文件 util.hxx。我正在使用代码本身的 cmets 中建议的命令进行编译:
nvcc -ccbin gcc -I/usr/local/cuda/include -c diag.cpp -o diag.o
我收到以下错误,其中大部分只是同一对错误的变体:
In file included from diag.cpp:12:
util.hxx: In function ‘int memcpyH2D(int, const int*, int, int, const T_ELEM*, int, int, int, int, T_ELEM**, int, int)’:
util.hxx:240:49: error: there are no arguments to ‘imax’ that depend on a template parameter, so a declaration of ‘imax’ must be available [-fpermissive]
const int A_start_col = imax( JA, IBX_A ); /* base-1 */
^~~~
util.hxx:240:49: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
util.hxx:243:42: error: there are no arguments to ‘imin’ that depend on a template parameter, so a declaration of ‘imin’ must be available [-fpermissive]
const int bdd = imin( N_hat, (IBX_A + T_A -1) );
^~~~
util.hxx:244:42: error: there are no arguments to ‘imin’ that depend on a template parameter, so a declaration of ‘imin’ must be available [-fpermissive]
const int IT_A = imin( T_A, (bdd - A_start_col + 1) );
^~~~
util.hxx:249:71: error: there are no arguments to ‘IDX2F’ that depend on a template parameter, so a declaration of ‘IDX2F’ must be available [-fpermissive]
T_ELEM *d_A = array_d_A_unpacked[JA_blk_id] + IDX2F( loc_A_start_row, loc_A_start_col, LLD_A );
^~~~~
util.hxx:250:51: error: there are no arguments to ‘IDX2F’ that depend on a template parameter, so a declaration of ‘IDX2F’ must be available [-fpermissive]
const T_ELEM *h_A = h_B + IDX2F( A_start_row - IA + 1, A_start_col - JA + 1, ldb );
^~~~~
util.hxx: In function ‘int memcpyD2H(int, const int*, int, int, int, int, int, T_ELEM**, int, int, T_ELEM*, int)’:
util.hxx:328:49: error: there are no arguments to ‘imax’ that depend on a template parameter, so a declaration of ‘imax’ must be available [-fpermissive]
const int A_start_col = imax( JA, IBX_A ); /* base-1 */
^~~~
util.hxx:330:42: error: there are no arguments to ‘imin’ that depend on a template parameter, so a declaration of ‘imin’ must be available [-fpermissive]
const int bdd = imin( N_hat, (IBX_A + T_A -1) );
^~~~
util.hxx:331:42: error: there are no arguments to ‘imin’ that depend on a template parameter, so a declaration of ‘imin’ must be available [-fpermissive]
const int IT_A = imin( T_A, (bdd - A_start_col + 1) );
^~~~
util.hxx:334:77: error: there are no arguments to ‘IDX2F’ that depend on a template parameter, so a declaration of ‘IDX2F’ must be available [-fpermissive]
const T_ELEM *d_A = array_d_A_unpacked[JA_blk_id] + IDX2F( loc_A_start_row, loc_A_start_col, LLD_A );
^~~~~
util.hxx:335:45: error: there are no arguments to ‘IDX2F’ that depend on a template parameter, so a declaration of ‘IDX2F’ must be available [-fpermissive]
T_ELEM *h_A = h_B + IDX2F( A_start_row - IA + 1, A_start_col - JA + 1, ldb );
^~~~~
util.hxx: In instantiation of ‘int memcpyH2D(int, const int*, int, int, const T_ELEM*, int, int, int, int, T_ELEM**, int, int) [with T_ELEM = double]’:
diag.cpp:53:100: required from here
util.hxx:240:53: error: ‘imax’ was not declared in this scope
const int A_start_col = imax( JA, IBX_A ); /* base-1 */
~~~~^~~~~~~~~~~~~
util.hxx:240:53: note: suggested alternative: ‘fmax’
const int A_start_col = imax( JA, IBX_A ); /* base-1 */
~~~~^~~~~~~~~~~~~
fmax
util.hxx:243:46: error: ‘imin’ was not declared in this scope
const int bdd = imin( N_hat, (IBX_A + T_A -1) );
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
util.hxx:243:46: note: suggested alternative: ‘fmin’
const int bdd = imin( N_hat, (IBX_A + T_A -1) );
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
fmin
util.hxx:244:46: error: ‘imin’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
const int IT_A = imin( T_A, (bdd - A_start_col + 1) );
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
util.hxx:243:46: note: ‘imin’ declared here, later in the translation unit
const int bdd = imin( N_hat, (IBX_A + T_A -1) );
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
util.hxx:249:76: error: ‘IDX2F’ was not declared in this scope
T_ELEM *d_A = array_d_A_unpacked[JA_blk_id] + IDX2F( loc_A_start_row, loc_A_start_col, LLD_A );
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
util.hxx:249:76: note: the macro ‘IDX2F’ had not yet been defined
diag.cpp:17: note: it was later defined here
#define IDX2F(i,j,lda) ((((j)-1)*((size_t)lda))+((i)-1))
In file included from diag.cpp:12:
util.hxx:250:56: error: ‘IDX2F’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
const T_ELEM *h_A = h_B + IDX2F( A_start_row - IA + 1, A_start_col - JA + 1, ldb );
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
util.hxx:249:76: note: ‘IDX2F’ declared here, later in the translation unit
T_ELEM *d_A = array_d_A_unpacked[JA_blk_id] + IDX2F( loc_A_start_row, loc_A_start_col, LLD_A );
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
util.hxx: In instantiation of ‘int memcpyD2H(int, const int*, int, int, int, int, int, T_ELEM**, int, int, T_ELEM*, int) [with T_ELEM = double]’:
diag.cpp:242:17: required from here
util.hxx:328:53: error: ‘imax’ was not declared in this scope
const int A_start_col = imax( JA, IBX_A ); /* base-1 */
~~~~^~~~~~~~~~~~~
util.hxx:328:53: note: suggested alternative: ‘fmax’
const int A_start_col = imax( JA, IBX_A ); /* base-1 */
~~~~^~~~~~~~~~~~~
fmax
util.hxx:330:46: error: ‘imin’ was not declared in this scope
const int bdd = imin( N_hat, (IBX_A + T_A -1) );
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
util.hxx:330:46: note: suggested alternative: ‘fmin’
const int bdd = imin( N_hat, (IBX_A + T_A -1) );
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
fmin
util.hxx:331:46: error: ‘imin’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
const int IT_A = imin( T_A, (bdd - A_start_col + 1) );
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
util.hxx:330:46: note: ‘imin’ declared here, later in the translation unit
const int bdd = imin( N_hat, (IBX_A + T_A -1) );
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
util.hxx:334:82: error: ‘IDX2F’ was not declared in this scope
const T_ELEM *d_A = array_d_A_unpacked[JA_blk_id] + IDX2F( loc_A_start_row, loc_A_start_col, LLD_A );
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
util.hxx:334:82: note: the macro ‘IDX2F’ had not yet been defined
diag.cpp:17: note: it was later defined here
#define IDX2F(i,j,lda) ((((j)-1)*((size_t)lda))+((i)-1))
In file included from diag.cpp:12:
util.hxx:335:50: error: ‘IDX2F’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
T_ELEM *h_A = h_B + IDX2F( A_start_row - IA + 1, A_start_col - JA + 1, ldb );
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
util.hxx:334:82: note: ‘IDX2F’ declared here, later in the translation unit
const T_ELEM *d_A = array_d_A_unpacked[JA_blk_id] + IDX2F( loc_A_start_row, loc_A_start_col, LLD_A );
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
我搜索了一些有关模板错误的帮助,但大多数解决方案都集中在修复代码上。目前,我假设 Nvidia 的示例代码很好。我想知道我是否需要升级我的 gcc。
我在 Centos 8 系统上,默认 gcc 版本 8.3.1 和 CUDA 工具包版本 11.3。 According to Nvidia,这应该是一个很好的设置。
在我花时间在我的主目录中安装第二个 gcc 版本之前,我想知道是否有人对我有任何建议?
感谢您的帮助!
【问题讨论】:
你试过用-Xcompiler -fpermissive
编译吗?
我曾尝试过-fpermissive
,但这会产生“未知选项”错误。你刚刚告诉我我需要-Xcompiler
选项——谢谢。不幸的是,使用-Xcompiler -fpermissive
编译会产生同样的错误。
我已在 NVIDIA 内部提交了一个错误以修复文档。正如您回答的那样,我想出了一个类似的解决方法。 IDX 宏实际上已经在 main.cpp 源文件中定义,因此如果将 util.hxx 的包含移动到该点之后,那么唯一需要的就是添加 imin 和 imax 定义。但我觉得你的回答很好。
【参考方案1】:
好的,我想通了……示例代码缺少一些指令。我在主 cpp 文件和头文件的顶部添加了以下定义:
#ifndef IDX2F
#define IDX2F(i,j,lda) ((((j)-1)*((size_t)lda))+((i)-1))
#endif /* IDX2F */
#ifndef IDX1F
#define IDX1F(i) ((i)-1)
#endif /* IDX1F */
#ifndef imin
#define imin( x, y ) ((x)<(y)) ? (x) : (y)
#endif
#ifndef imax
#define imax( x, y ) ((x)>(y)) ? (x) : (y)
#endif
【讨论】:
以上是关于编译 CUDA cuSolver 特征值示例时出现编译错误的主要内容,如果未能解决你的问题,请参考以下文章
使用 GPU=1 编译 Yolo (Darknet) 时出现错误 127 -(obj/convolutioanl_kernels.o)