How to get register count before kernel launch?

I can use nvcc --ptxas-options=-v to discover how many registers my kernels
will use when I compile them, but is the same information available at
run time?

I would like to prevent my code trying to launch a kernel if the product
of maxrregcount and ThreadsPerBlock would take the kernel above the number
of registers available (in deviceProp.regsPerBlock). At present, if this
limited is exceeded my program is aborted with a segfault.

Thanks in advance
Bill
(See previous topic NVS 290 texture problem Quadro NVS 290 cudaErrorInvalidTexture -arch sm_11 - CUDA Programming and Performance - NVIDIA Developer Forums)

You can inspect the “numRegs” variable in the cudaFuncAttributes structure which you can query with the cudaFuncGetAttributes(…) function.

Thanks Gert-Jan,

struct cudaFuncAttributes funcAttrib;
  checkCudaErrors(cudaFuncGetAttributes(&funcAttrib, KERNEL));
  printf("%s numRegs=%d\n",KERNELNAME,funcAttrib.numRegs);

has done the trick:-)
Bill