使用IFORT和nvcc和CUSP的未解析引用
Unresolved references using IFORT with nvcc and CUSP
我有一个像这样编译的程序:
(...) Some ifort *.f -c
nvcc -c src/bicgstab.cu -o bicgstab.o -I/home/ricardo/apps/cusp/cusplibrary
(...) Some more *.for -c
ifort *.o -L/usr/local/cuda-5.5/lib64 -lcudart -lcublas -lcusparse -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -openmp -o program
一切都很好,直到我添加了CUSP支持,我有这个包装器(bgstab .cu):
#include <cusp/csr_matrix.h>
#include <cusp/krylov/bicgstab.h>
#if defined(__cplusplus)
extern "C" {
#endif
void bicgstab_(int * device_I, int * device_J, float * device_V, float * device_x, float * device_b, int N, int NNZ){
// *NOTE* raw pointers must be wrapped with thrust::device_ptr!
thrust::device_ptr<int> wrapped_device_I(device_I);
thrust::device_ptr<int> wrapped_device_J(device_J);
thrust::device_ptr<float> wrapped_device_V(device_V);
thrust::device_ptr<float> wrapped_device_x(device_x);
thrust::device_ptr<float> wrapped_device_b(device_b);
// use array1d_view to wrap the individual arrays
typedef typename cusp::array1d_view< thrust::device_ptr<int> > DeviceIndexArrayView;
typedef typename cusp::array1d_view< thrust::device_ptr<float> > DeviceValueArrayView;
DeviceIndexArrayView row_indices (wrapped_device_I, wrapped_device_I + (N+1));
DeviceIndexArrayView column_indices(wrapped_device_J, wrapped_device_J + NNZ);
DeviceValueArrayView values (wrapped_device_V, wrapped_device_V + NNZ);
DeviceValueArrayView x (wrapped_device_x, wrapped_device_x + N);
DeviceValueArrayView b (wrapped_device_b, wrapped_device_b + N);
// combine the three array1d_views into a csr_matrix_view
typedef cusp::csr_matrix_view<DeviceIndexArrayView,
DeviceIndexArrayView,
DeviceValueArrayView> DeviceView;
// construct a csr_matrix_view from the array1d_views
DeviceView A(N, N, NNZ, row_indices, column_indices, values);
// set stopping criteria:
// iteration_limit = 100
// relative_tolerance = 1e-5
cusp::verbose_monitor<float> monitor(b, 100, 1e-5);
// solve the linear system A * x = b with the Conjugate Gradient method
cusp::krylov::bicgstab(A, x, b, monitor);
}
#if defined(__cplusplus)
}
#endif
Nvcc编译并生成对象,但在最后一个命令中,当我将所有链接在一起时,由于链接出现了一堆错误:
ipo: warning #11021: unresolved __gxx_personality_v0
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZTVSt9exception
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZTVSt9bad_alloc
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZdlPv
Referenced in bicgstab.o
ipo: warning #11021: unresolved __cxa_guard_acquire
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZNSaIcEC1Ev
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZNSsC1EPKcRKSaIcE
Referenced in bicgstab.o
ipo: warning #11021: unresolved __cxa_guard_release
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZNSsD1Ev
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZNSaIcED1Ev
Referenced in bicgstab.o
ipo: warning #11021: unresolved __cxa_guard_abort
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZNSsC1ERKSs
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZNSt13runtime_errorD2Ev
Referenced in bicgstab.o
ipo: warning #11021: unresolved __cxa_call_unexpected
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZNSt13runtime_errorC2ERKSs
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZNSsC1Ev
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZNKSs5emptyEv
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZNKSt13runtime_error4whatEv
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZNSsaSEPKc
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZNSspLEPKc
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZNSspLERKSs
Referenced in bicgstab.o
ipo: warning #11021: unresolved __cxa_begin_catch
Referenced in bicgstab.o
ipo: warning #11021: unresolved __cxa_end_catch
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZNKSs5c_strEv
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZNKSt9bad_alloc4whatEv
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZNSt9bad_allocD2Ev
Referenced in bicgstab.o
ipo: warning #11021: unresolved __cxa_allocate_exception
Referenced in bicgstab.o
ipo: warning #11021: unresolved __cxa_free_exception
Referenced in bicgstab.o
ipo: warning #11021: unresolved __cxa_throw
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZNSt9exceptionD2Ev
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZSt4cout
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZNSolsEf
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZNSolsEm
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZNSolsEPFRSoS_E
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZSt9terminatev
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZStlsIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_St5_Setw
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZNSolsEPFRSt8ios_baseS0_E
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZNSt9bad_allocD1Ev
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZTISt9bad_alloc
Referenced in bicgstab.o
ipo: warning #11021: unresolved __cxa_pure_virtual
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZTVN10__cxxabiv120__si_class_type_infoE
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZTISt9exception
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZTISt13runtime_error
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZTVN10__cxxabiv117__class_type_infoE
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZNSt8ios_base4InitC1Ev
Referenced in bicgstab.o
ipo: warning #11021: unresolved _ZNSt8ios_base4InitD1Ev
Referenced in bicgstab.o
我相信这是因为努力是添加或删除下划线,添加小写/大写或其他任何东西,因为文件正在编译写,如果我在程序外生成二进制文件,只是为了测试,它工作得很好。
提前非常感谢!
当涉及多个文件时,ipo相当复杂。它实际上是在链接时在所有模块上重新运行编译器。我不是这方面的专家,但这听起来是相当困难的事情。
一个可能的选择可能是你尝试编译你的cuda代码到一个共享库(.so),并链接到它。它应该防止英特尔编译器工具链试图针对nvcc/gcc生成的代码重新编译和优化。我认为这将限制你的"单文件优化"。不知道这是否会显著影响你的表现。
使用这里的示例,我将修改编译命令如下:
$ nvcc -Xcompiler="-fPIC" -shared bicgstab.cu -o bicgstab.so -I/home-2/robertc/misc/cusp/cusplibrary-master
$ ifort -c -fast bic.f90
$ ifort bic.o bicgstab.so -L/shared/apps/cuda/CUDA-v6.0.37/lib64 -lcudart -o program
ipo: remark #11001: performing single-file optimizations
ipo: remark #11006: generating object file /tmp/ipo_ifortxEdpin.o
$
您没有指出在编译过程中添加-fast
开关的位置。如果只在ifort
编译命令上,我相信上面的方法可以工作。如果在link命令上也想要/需要它,那么看起来ifort想要构建一个完全静态链接的可执行文件(并进行模块间优化…),使用上述过程将无法工作。
相关文章:
- 将对象数组的引用传递给函数
- 什么时候在C++中返回常量引用是个好主意
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- 何时在引用或唯一指针上使用移动语义
- 如何在c++中使用引用实现类似python的行为
- 编译C++时未定义的引用
- Ctypes wstring通过引用传递
- c++r值引用应用于函数指针
- 理解c++中的引用
- C++取消引用指针.为什么会发生变化
- 如何修复此错误:未定义对"距离(浮点数,浮点数,浮点数,浮点数,浮点数)"的引用
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- C++Boost Asio Pool线程,带有lambda函数和传递引用变量
- 强制转换为引用类型
- 引用一个已擦除类型(void*)的指针
- 向量元素的引用地址与它所指向的向量元素的地址不同.为什么
- 具有默认值的引用获取函数
- 如何使用基类指针引用派生类成员
- 使用取消引用的指针的多态性会产生意外的结果.为什么?
- 使用IFORT和nvcc和CUSP的未解析引用