Maya + Cuda 11 type redeclaration error

Bit of a newb here with trying to link cuda with other apps. I’m trying to compile a Maya plugin and link cuda 11 in the plugin. I’m getting the same error that’s been listed a number of times, however the fixes don’t seem to work any longer. It’s a straight forward plugin.

I have a displace.cuh file that is included in both the .cu file and the .cpp file for my plugin.

#include “cuda.h”
#include “cuda_runtime.h”
void cu_displace();
int cuda_displace();

and a displace.cu

#include <stdio.h>
#include “dlCudaDisplace.h”
__global __ void displace() {
int x = threadIdx.x + blockIdx.x * blockDim.x;
int offset = x * blockDim.x * gridDim.x;
printf(“running cuda code\n”);
}
int cuda_displace() {
dim3 blocks(DIM/16,DIM/16);
dim3 threads(16,16);
//
displace<<<blocks, threads>>>();
return 0;
}

I get these errors for all the various types that are the same as in Cuda.

C:\Program Files\Autodesk\Maya2021\include\maya/MTypes.h(219): note: see declaration of ‘double4’

However, trying this

namespace cuda {
#include “cuda.h”
#include “cuda_runtime.h”
}

Gives these errors.

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\include\cuda_runtime.h(310): error C2039: ‘cudaEventCreateWithFlags’: is no
t a member of ‘global namespace'' C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\include\cuda_runtime.h(376): error C2039: 'cudaHostAlloc': is not a member of 'global namespace’’

I’m using CMake to build the plugin, with these cuda variables

find_package(Maya REQUIRED)
find_package(CUDA REQUIRED)
enable_language(CUDA)
set(CMAKE_CUDA_FLAGS "{CMAKE_CUDA_FLAGS} -gencode arch=compute_50,code=sm_50 -lcuda -lcudart") include_directories({MAYA_INCLUDE_DIR})
link_directories({MAYA_LIBRARY_DIR}) add_library({PROJECT_NAME} SHARED {SOURCE_FILES}) target_link_libraries({PROJECT_NAME} ${MAYA_LIBRARIES})

Any help would be appreciated.

I was able to get this working once I removed the

#include “cuda.h”
#include “cuda_runtime.h”

from the .cuh file. And I added this to the CMakeLists.txt file.

find_package(Maya REQUIRED)
find_package(CUDA REQUIRED)

enable_language(CUDA)
set(CMAKE_CUDA_FLAGS “${CMAKE_CUDA_FLAGS} -gencode arch=compute_50,code=sm_50 -lcuda -lcudart”)

include_directories({MAYA_INCLUDE_DIR} {CUDA_INCLUDE_DIRS})
link_directories({MAYA_LIBRARY_DIR} {CUDA_LIBS})
add_library({PROJECT_NAME} SHARED {SOURCE_FILES})
target_link_libraries({PROJECT_NAME} {MAYA_LIBRARIES} ${CUDA_LIBRARIES})