I created a shared library that use OptiX. Now I want to add some computation on the GPU using Cuda.
As a starting point I created this simple kernel, in a file called “sort_cuda.cu”:
#include <cuda_runtime.h>
#include <iostream>
__global__ void testKernel(optix::float3* cudaBuf) {
cudaBuf.x+=1.0f;
cudaBuf.y+=1.0f;
cudaBuf.z+=1.0f;
}
bool runKernel() {
optix::float3 ret;
testKernel<<<1, 1>>>(cudaBuf);
cudaMemcpy( &ret,
cudaBuf,
sizeof(optix::float3),
cudaMemcpyDeviceToHost);
std::cout << "Ret: " << ret.x << " , "
<< ret.y << " , "
<< ret.z << std::endl;
}
When I compile the whole project, I’ve got an undefined reference to “runKernel”.
I compared with an OptiX sample using Cuda (optixRaycasting), and I saw when compiling the sample there is this line:
[ 83%] Building NVCC (Device) object lib/ptx/./optixRaycasting_generated_optixRaycastingKernels.cu.o
While when I compile my project I have nothing similar, it seems my file “sort_cuda.cu” is not taken into account (if it was, it won’t be able to comple “runKernel” as it is)! I don’t understand what I’m missing.
Here is my library part in my “CMakeList.txt”:
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/sort_cuda.cu
PROPERTIES CUDA_SOURCE_PROPERTY_FORMAT OBJ
)
# Create RayGen library
add_library(RayGen SHARED
file1.cpp
file2.cpp
file3.cpp
file4.cpp
sort_cuda.cu
triangle_mesh.cu
)
# Link openmp to RayGen library
target_link_libraries(RayGen
-fopenmp
optix
sutil_sdk
${optix_rpath}
${CUDA_LIBRARIES}
)
For information I’m under CentOs 7, with OptiX 6.0 and Cuda 10.2