The issue of cuda 8 and optix 4.0.2 interop, ubuntu 16.04

Hey guys

May I ask a beginner question here?

I am trying to make a cuda and optix interop sample code work, but I could not make it compile.

Here is my sample code:

#include <stdio.h>
#include <optix_world.h>

#include <cuda_runtime.h>

int main()
optix::Context context = optix::Context::create();
optix::Buffer vertex_buffer = context->createBufferForCUDA(RT_BUFFER_INPUT, RT_FORMAT_FLOAT3, 5);

float3 cuda_buffer;
*)cuda_buffer, 5 * sizeof(float3));

to use cudaMalloc, I need to include cuda_runtime.h, to use optix::Context, I need to include optix_world.h, but if I include them both, then there is a error.

/usr/local/cuda/include/cuda_runtime_api.h:252:17: error: ‘cudaError_t’ does not name a type
extern host cudaError_t CUDARTAPI cudaDeviceReset(void);
/usr/local/cuda/include/cuda_runtime_api.h:269:36: error: ‘cudaError_t’ does not name a type
extern host cudart_builtin cudaError_t CUDARTAPI cudaDeviceSynchronize(void);

I think there are something I am missing. If somebody knows it, please let me know. Thanks.

Best regards
George Liao

Try including the cuda headers before the optix headers. OptiX tries to pull CUDA types into the optix namespace if you include cuda headers after optix (in order to avoid namespace conflicts).

Also, as stated in the optix 4.0.2 docs, CUDA 8.0 is not officially supported. It should work but is not guaranteed.

Hey kmorley

Thanks a lot, that is exactly what is going on. Swapping the two headers does solve the problem.

Best regards
George Liao