cancel
Showing results for 
Search instead for 
Did you mean: 

Including Oculus OpenGL support in Cuda code

Anonymous
Not applicable
Developing on: Windows 10, 64-bit PC in Visual Studio Community 2015 with Cuda 9.1 and Oculus SDK v1.26.0

I have a body of code I wrote a few years back that successfully compiled and ran using the older Oculus SDK (I think v0.0.8) and the DK2 Rift.  I've recently upgraded to the Oculus SDK v.1.26.0 to work with the newest Oculus Rift HMD.  In the code, I  have my own Cuda code that makes use of Oculus's OpenGL extensions support header (CAPI_GLE.h).  This header is built into, for example, the Oculus_RoomTiny example.  The problem I am encountering is that when I include this header in my Cuda code (that gets compiled by the nvcc compiler), I get the error:

C:\Oculus\OculusSDK_v1.26.0\Install\LibOVRKernel\Src\Kernel/OVR_Win32_IncludeWindows.h(136): error : expected a ")"

I've created a sample program that demonstrates the failure.  It can be recreated as follows:

1. Take the OpenGL version of the OculusRoomTiny project in the 'Samples' that come with the Oculus SDK
2. Add two new files: my_cuda_parts.h & my_cuda_parts.cu composed as follows:
my_cuda_parts.h:
#ifndef __MY_CUDA_PARTS_H__
#define __MY_CUDA_PARTS_H__
#define MY_DEBUG 1
#if MY_DEBUG
#include "GL/CAPI_GLE.h"
#else
#endif
#include "cuda.h"
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <iostream>

int my_fcn(void);
__global__ void my_cuda_fcn(int a, int b, int * c);
#endif

my_cuda_parts.cu:
#include "my_cuda_parts.h"

int my_fcn(void)
{
int c;
int *dev_c;
cudaMalloc((void **)&dev_c, sizeof(int));
my_cuda_fcn << <1, 1 >> > (2, 7, dev_c);
cudaMemcpy(&c, dev_c, sizeof(int), cudaMemcpyDeviceToHost);
std::printf("2 + 7 = %d\n", c);
cudaFree(dev_c);
return c;
}

__global__ void my_cuda_fcn(int a, int b, int * c)
{
*c = a + b;
}

And in the main.cpp file of the OculusRoomTiny project:
#include "my_cuda_parts.h"
and put at the top of the WinMain function:
int c = my_fcn();
std::printf("What is %d\n", c);

When I include the GL/CAPI_GLE.h header in my_cuda_parts.h, I get the error.  If I take that line out, the code compiles and runs correctly.  Since this particular header is already included in the Win32_GLAppUtil.h that is part of the OculusRoomTiny project, it appears that when this header is processed by the Cuda compiler (using the nvcc compilation program), this error is triggered.

Is there a way to successfully use this Oculus OpenGL header in my custom Cuda code?





0 REPLIES 0