Commit 617ba2df authored by Marc Modat's avatar Marc Modat

Modification to set up the CUDA context when several card are present

parent c42b2cc8
......@@ -587,51 +587,50 @@ int main(int argc, char **argv)
// Create the reg_f3d object
reg_f3d<PrecisionTYPE> *REG=NULL;
#ifdef _USE_CUDA
CUdevice dev;
CUcontext ctx;
if(useGPU){
if(linearEnergyWeight0==linearEnergyWeight0 ||
linearEnergyWeight1==linearEnergyWeight1 ||
L2NormWeight==L2NormWeight){
fprintf(stderr,"\n[NiftyReg WARNING CUDA] The linear elasticity has not been implemented with CUDA yet.\n");
fprintf(stderr,"[NiftyReg WARNING CUDA] GPU implementation has been turned off.\n");
fprintf(stderr,"\n[NiftyReg CUDA WARNING] The linear elasticity has not been implemented with CUDA yet.\n");
fprintf(stderr,"[NiftyReg CUDA WARNING] GPU implementation has been turned off.\n");
useGPU=false;
}
if(useSym){
fprintf(stderr,"\n[NiftyReg WARNING CUDA] GPU implementation of the symmetric registration is not available yet.\n");
fprintf(stderr,"[NiftyReg WARNING CUDA] GPU implementation has been turned off.\n");
fprintf(stderr,"\n[NiftyReg CUDA WARNING] GPU implementation of the symmetric registration is not available yet.\n");
fprintf(stderr,"[NiftyReg CUDA WARNING] GPU implementation has been turned off.\n");
useGPU=false;
}
if(useVel){
fprintf(stderr,"\n[NiftyReg WARNING CUDA] GPU implementation of velocity field parametrisartion is not available yet.\n");
fprintf(stderr,"[NiftyReg WARNING CUDA] GPU implementation has been turned off.\n");
fprintf(stderr,"\n[NiftyReg CUDA WARNING] GPU implementation of velocity field parametrisartion is not available yet.\n");
fprintf(stderr,"[NiftyReg CUDA WARNING] GPU implementation has been turned off.\n");
useGPU=false;
}
if(!(referenceImage->dim[4]==1 && floatingImage->dim[4]==1) &&
!(referenceImage->dim[4]==2 && floatingImage->dim[4]==2)){
fprintf(stderr,"\n[NiftyReg WARNING CUDA] The GPU implementation only handle 1 to 1 or 2 to 2 image(s) registration\n");
fprintf(stderr,"[NiftyReg WARNING CUDA] GPU implementation has been turned off.\n");
fprintf(stderr,"\n[NiftyReg CUDA WARNING] The GPU implementation only handle 1 to 1 or 2 to 2 image(s) registration\n");
fprintf(stderr,"[NiftyReg CUDA WARNING] GPU implementation has been turned off.\n");
useGPU=false;
}
// Set up the cuda card and display some relevant information and check if the card is suitable
int major, minor;
if(cudaCommon_setCUDACard(&dev, &ctx, major, minor, verbose)){
fprintf(stderr,"\n[NiftyReg ERROR CUDA] Error while detecting a CUDA card\n");
fprintf(stderr,"[NiftyReg WARNING CUDA] GPU implementation has been turned off.\n");
if(cudaCommon_setCUDACard(&ctx, verbose)){
fprintf(stderr,"\n[NiftyReg CUDA ERROR] Error while detecting a CUDA card\n");
fprintf(stderr,"[NiftyReg CUDA WARNING] GPU implementation has been turned off.\n");
useGPU=false;
}
// Create the registration object using the GPU class
if(useGPU)
if(useGPU){
REG = new reg_f3d_gpu(referenceImage->nt, floatingImage->nt);
#ifdef NDEBUG
if(verbose==true)
if(verbose==true)
#endif // NDEBUG
printf("\n[NiftyReg F3D GPU] GPU implementation is used\n");
printf("\n[NiftyReg F3D GPU] GPU implementation is used\n");
}
}
#endif
if(useSym && REG==NULL){
......
......@@ -15,10 +15,7 @@
/* ******************************** */
/* ******************************** */
int cudaCommon_setCUDACard(CUdevice *dev,
CUcontext *ctx,
int &major,
int &minor,
int cudaCommon_setCUDACard(CUcontext *ctx,
bool verbose)
{
// The CUDA card is setup
......@@ -42,7 +39,7 @@ int cudaCommon_setCUDACard(CUdevice *dev,
++current_device;
}
NR_CUDA_SAFE_CALL(cudaSetDevice(max_gflops_device));
NR_CUDA_SAFE_CALL(cuCtxCreate(ctx, 0, *dev))
NR_CUDA_SAFE_CALL(cuCtxCreate(ctx, CU_CTX_SCHED_SPIN, max_gflops_device))
NR_CUDA_SAFE_CALL(cudaGetDeviceProperties(&deviceProp, max_gflops_device));
if(deviceProp.major<1){
......@@ -53,8 +50,6 @@ int cudaCommon_setCUDACard(CUdevice *dev,
size_t free=0;
size_t total=0;
cuMemGetInfo(&free, &total);
major=deviceProp.major;
minor=deviceProp.minor;
if(deviceProp.totalGlobalMem != total){
fprintf(stderr,"[NiftyReg CUDA ERROR] The CUDA card %s does not seem to be available\n",
deviceProp.name);
......@@ -69,8 +64,8 @@ int cudaCommon_setCUDACard(CUdevice *dev,
(unsigned long int)(free/(1024*1024)),
(unsigned long int)(total/(1024*1024)));
printf("[NiftyReg CUDA] Card compute capability: %i.%i\n",
major,
minor);
deviceProp.major,
deviceProp.minor);
printf("[NiftyReg CUDA] Shared memory size in bytes: %lu\n",
deviceProp.sharedMemPerBlock);
printf("[NiftyReg CUDA] CUDA version %i\n",
......@@ -80,7 +75,7 @@ int cudaCommon_setCUDACard(CUdevice *dev,
printf("[NiftyReg CUDA] Card has %i multiprocessor(s)\n",
deviceProp.multiProcessorCount);
}
NiftyReg_CudaBlock100 *NR_BLOCK = NiftyReg_CudaBlock::getInstance(major);
NiftyReg_CudaBlock100 *NR_BLOCK = NiftyReg_CudaBlock::getInstance(deviceProp.major);
}
return EXIT_SUCCESS;
}
......
......@@ -13,10 +13,7 @@
/* ******************************** */
/* ******************************** */
int cudaCommon_setCUDACard(CUdevice *dev,
CUcontext *ctx,
int &major,
int &minor,
int cudaCommon_setCUDACard(CUcontext *ctx,
bool verbose);
/* ******************************** */
void cudaCommon_unsetCUDACard(CUcontext *ctx);
......
......@@ -19,12 +19,9 @@ int main(int argc, char **argv)
int dimension=atoi(argv[1]);
char *type=argv[2];
// Check and setup the GPU card
CUdevice dev;
CUcontext ctx;
int major;
int minor;
if(cudaCommon_setCUDACard(&dev, &ctx, major, minor, true))
// Check and setup the GPU card
CUcontext ctx;
if(cudaCommon_setCUDACard(&ctx, true))
return EXIT_FAILURE;
// Create the input images
......
......@@ -30,11 +30,8 @@ int main(int argc, char **argv)
char *type=argv[2];
// Check and setup the GPU card
CUdevice dev;
CUcontext ctx;
int major;
int minor;
if(cudaCommon_setCUDACard(&dev,&ctx, major, minor, true))
if(cudaCommon_setCUDACard(&ctx, true))
return EXIT_FAILURE;
// Compute some useful variables
......
......@@ -22,11 +22,8 @@ int main(int argc, char **argv)
char *type=argv[4];
// Check and setup the GPU card
CUdevice dev;
CUcontext ctx;
int major;
int minor;
if(cudaCommon_setCUDACard(&dev,&ctx, major, minor, true))
if(cudaCommon_setCUDACard(&ctx, true))
return EXIT_FAILURE;
// Read the input floating image and converts it to a float
......
......@@ -30,12 +30,9 @@ int main(int argc, char **argv)
int dimension=atoi(argv[1]);
char *type=argv[2];
// Check and setup the GPU card
CUdevice dev;
CUcontext ctx;
int major;
int minor;
if(cudaCommon_setCUDACard(&dev,&ctx, major, minor, true))
// Check and setup the GPU card
CUcontext ctx;
if(cudaCommon_setCUDACard(&ctx, true))
return EXIT_FAILURE;
// Create the input images
......
......@@ -19,12 +19,9 @@ int main(int argc, char **argv)
if(strcmp(type,"conjugate")!=0)
type=(char *)"descent";
// Check and setup the GPU card
CUdevice dev;
CUcontext ctx;
int major;
int minor;
if(cudaCommon_setCUDACard(&dev,&ctx, major, minor, true))
// Check and setup the GPU card
CUcontext ctx;
if(cudaCommon_setCUDACard(&ctx, true))
return EXIT_FAILURE;
// Create fake registration objects
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment