cudaDriverGetVersion() returns incorrect data when running a 32-bit executable against the 64-bit dr

It appears that when 32-bit host code in the presence of a 64-bit CUDA driver, the runtime incorrectly reports the driver version from a call to [font=“Courier New”]cudaDriverGetVersion()[/font], which seems to cause a runtime error in my application, “CUDA driver version is insufficient for CUDA runtime version.

My test environment is a 64-bit CentOS 5 Linux workstation with the 64-bit CUDA driver v256.25 and the 3.1 beta toolkit. I am attaching a small test application, which may be compiled with GNU make/gcc to demonstrate the problem.

/* Save this code in a file named "driver_version.c"

 * Compile with GNU make:

 * % make driver_version CFLAGS="-DCUDART_LIBRARY=libcudart.so -I/usr/local/cuda/include" LDLIBS="-ldl" -f/dev/null

 *

 * Changing the architecture options causes different behaviour. With a 64-bit executable, the results are as expected:

 * % rm driver_version; make driver_version TARGET_ARCH=-m64 CFLAGS="-DCUDART_LIBRARY=libcudart.so -I/usr/local/cuda/include" LDLIBS="-ldl" -f/dev/null

 * % ./driver_version

 * > CUDA driver v3010 runtime v3010

 *

 * With a 32-bit executable, the driver version is reported incorrectly:

 * % rm driver_version; make driver_version TARGET_ARCH=-m64 CFLAGS="-DCUDART_LIBRARY=libcudart.so -I/usr/local/cuda/include" LDLIBS="-ldl" -f/dev/null

 * % ./driver_version

 * > CUDA driver v8334885 runtime v3010

 * 

 */

#include <stdlib.h>

#include <stdio.h>

#include <dlfcn.h>

#include <cuda_runtime_api.h>

#ifndef CUDART_LIBRARY

#error Must define CUDART_LIBRARY (e.g. -DCUDART_LIBRARY=libcudart.so or -DCUDART_LIBRARY=libcudart.dylib)

#endif

#define Q_(IT) #IT

#define Q(IT) Q_(IT)

typedef cudaError_t (*cudaDriverGetVersion_f)(int *);

typedef cudaError_t (*cudaRuntimeGetVersion_f)(int *);

int main (int argc, char **argv) {

  const char* dll = Q(CUDART_LIBRARY);

void *cudaRT = NULL;

  cudaDriverGetVersion_f cudaDriverGetVersion = NULL;

  cudaRuntimeGetVersion_f cudaRuntimeGetVersion = NULL;

cudaRT = dlopen(dll, RTLD_NOW);

  if (!cudaRT) return 1;

  cudaDriverGetVersion = (cudaDriverGetVersion_f)dlsym(cudaRT, "cudaDriverGetVersion");

  cudaRuntimeGetVersion = (cudaRuntimeGetVersion_f)dlsym(cudaRT, "cudaRuntimeGetVersion");

int vdriver, vruntime;

  cudaDriverGetVersion(&vdriver);

  cudaRuntimeGetVersion(&vruntime);

fprintf(stderr, "CUDA driver v%d runtime v%d\n", vdriver, vruntime);

  return 0;

}