Hi,
I’m facing a strange problem where a CUDA program, that uses driver APIs, when built as a DLL, causes an executable that links to the DLL to hang after it exits main(). The process then has to be killed from the task manager.
The same code when built as an executable works fine. Also, this problem occurs only on certain configurations (details later in the post).
DLL.cpp: This file is compiled and built into a DLL.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define CUDA_SAFE_CALL(x) \
do { \
CUresult result = x; \
if (result != CUDA_SUCCESS) { \
const char *msg; \
cuGetErrorName(result, &msg); \
fprintf(stderr, "CUDA: %s\n", msg); \
} \
} while(0)
// For the CUDA runtime routines (prefixed with "cuda_")
#include <cuda_runtime.h>
#include <cuda.h>
__declspec(dllexport) int __cdecl
mainEntry(void)
{
cuInit(0);
// Error code to check return values for CUDA calls
cudaError_t err = cudaSuccess;
// Print the vector length to be used, and compute its size
int numElements = 50000;
size_t size = numElements * sizeof(float);
// Allocate the device input vector A
float *d_A = NULL;
err = cudaMalloc((void **)&d_A, size);
if (err != cudaSuccess)
{
fprintf(stderr, "Failed to allocate device vector A (error code %s)!\n", cudaGetErrorString(err));
exit(EXIT_FAILURE);
}
// Free device global memory
//err = cudaFree(d_A);
CUDA_SAFE_CALL(cuMemFree((CUdeviceptr)d_A));
if (err != cudaSuccess)
{
fprintf(stderr, "Failed to free device vector A (error code %s)!\n", cudaGetErrorString(err));
exit(EXIT_FAILURE);
}
printf("Hello world\n");
return 0;
}
main.cpp: This file is built as an executable that uses the DLL above.
int mainEntry(void);
int main()
{
mainEntry();
}
The executable hangs at exit (i.e., after printing “Hello world”) on the following configuration:
Windows 7 Professional
NVIDIA driver 369.3
CUDA Toolkit 8.0
GeForce GTX 980ti / GTX 960 / GTX 560Ti
This looks to be a CUDA driver bug and any workaround suggestions would be very helpful.
Thanks.
- Vaivaswatha.