2017-04-20 39 views
0

我正在使用可分離編譯的CUDA C++項目,並且在編譯推力函數時遇到了一些問題。使用推力時的未定義符號錯誤:: max_element

直到下面的函數調用被添加,項目纔會沒有問題。

thrust::device_ptr<float> max_int = thrust::max_element(
    thrust::device_ptr<float>(dev_temp_intensity_buffer), 
    thrust::device_ptr<float>(dev_temp_intensity_buffer + INT_BUF_SIZE); 

至於說,我得到的編譯錯誤:

Severity Code Description Project File Line Suppression State 
Error LNK2019 unresolved external symbol __fatbinwrap_66_tmpxft_00006db0_00000000_18_cuda_device_runtime_compute_61_cpp1_ii_8b1a5d37 referenced in function __cudaRegisterLinkedBinary_66_tmpxft_00006db0_00000000_18_cuda_device_runtime_compute_61_cpp1_ii_8b1a5d37 visualize C:\Users\13\Google Drive\WireMeshOT Rafael\CUDA\simulator\build\src\visualize_intermediate_link.obj 1 

有趣的是,這一等推力函數調用編譯就好:

thrust::exclusive_scan(thrust::device_ptr<unsigned int>(dev_ray_alive), 
    thrust::device_ptr<unsigned int>(dev_ray_alive + NRAYS), 
    thrust::device_ptr<unsigned int>(dev_scanned_alive_rays)); 

OBS1:dev_temp_intensity_buffer是一個浮動設備指針,我包括thrust/extrema.hthrust/device_ptr.h

Obs2:我正在使用CMake來配置構建。下面顯示了相關的CMake代碼摘錄。

SET(CUDA_SEPARABLE_COMPILATION ON) 

set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -rdc=true -D_FORCE_INLINES) 
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -arch=compute_52 -code=sm_52 -lcudart -lcudadevrt -lcuda) 
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xptxas -v) 

cuda_add_executable(
project 
file1.cu 
    ...) 

target_link_libraries (project glut glew) 
+0

類似於這樣的問題:http://stackoverflow.com/questions/35704204/linking-cuda-plain-c-code-undefined-reference-to-fatbinwrap-66-tmpxft-e –

+0

@JaredHoberock是的。我已經添加了-lcudadevrt到nvcc標誌,我也嘗試過使用'target_link_libraries(可視化utils cuda_utils glut glew $ {CUDA_LIBRARIES})'沒有任何成功。感謝您的評論。 –

+0

問題是否獨立於您的CMake構建發生?你能夠從命令行手動鏈接一個程序嗎?你可以發佈一個小的再現程序來演示問題,以便其他人可以嘗試他們的系統嗎? –

回答

1

我終於明白了!

鏈接問題是由於cudadevrt庫缺失的事實。值得注意的是,只有將-lcudadevrt添加到CUDA_NVCC_FLAGS是不夠的!

的問題消失聯,如下所示CUDA運行時庫設備的CMake的目標時:

target_link_libraries(project glut glew ${CUDA_cudadevrt_LIBRARY})

OBS1:所述CUDA_cudadevrt_LIBRARY變量僅在CMake的版本3.7.2以上提供。添加行cmake_minimum_required(VERSION 3.7.2)是一個好主意。

Obs2:僅鏈接到CUDA_LIBRARIES只有在使用CMake版本高於3.7.2的情況下才能解決此問題。在較低版本中,此變量存在但不包含cudadevrt庫。

target_link_libraries(project glut glew ${CUDA_LIBRARIES})