From dc99699ec99be17c0d8ff6d09a15b86522d28732 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 21 Nov 2016 17:36:25 -0600 Subject: [PATCH] implemented a no-gpu option --- stim/envi/bil.h | 50 ++++++++++++++++++++++++++------------------------ stim/envi/bip.h | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------- stim/envi/envi.h | 16 ++++++++-------- 3 files changed, 88 insertions(+), 82 deletions(-) diff --git a/stim/envi/bil.h b/stim/envi/bil.h index 1b8a747..80d26d4 100644 --- a/stim/envi/bil.h +++ b/stim/envi/bil.h @@ -1126,34 +1126,36 @@ public: /// @param co is a pointer to pre-allocated memory of size [B * B] that stores the resulting covariance matrix /// @param avg is a pointer to memory of size B that stores the average spectrum /// @param mask is a pointer to memory of size [X * Y] that stores the mask value at each pixel location - bool co_matrix(double* co, double* avg, unsigned char *mask, bool PROGRESS = false){ + bool co_matrix(double* co, double* avg, unsigned char *mask, bool use_gpu = true, bool PROGRESS = false){ progress = 0; - int dev_count; - HANDLE_ERROR(cudaGetDeviceCount(&dev_count)); //get the number of CUDA devices - std::cout<<"Number of CUDA devices: "< best_device_cc){ - best_device_cc = cc; //if this is better than the previous device, use it - best_device_id = d; - } - } + if(use_gpu){ + int dev_count; + HANDLE_ERROR(cudaGetDeviceCount(&dev_count)); //get the number of CUDA devices + std::cout<<"Number of CUDA devices: "< best_device_cc){ + best_device_cc = cc; //if this is better than the previous device, use it + best_device_id = d; + } + } - if(dev_count > 0 && prop.major != 9999){ //if the first device is not an emulator - std::cout<<"Using device "< 0 && prop.major != 9999){ //if the first device is not an emulator + std::cout<<"Using device "< best_device_cc){ - best_device_cc = cc; //if this is better than the previous device, use it - best_device_id = d; - } - } + if(use_gpu){ + int dev_count; + HANDLE_ERROR(cudaGetDeviceCount(&dev_count)); //get the number of CUDA devices + std::cout<<"Number of CUDA devices: "< best_device_cc){ + best_device_cc = cc; //if this is better than the previous device, use it + best_device_id = d; + } + } - if(dev_count > 0 && prop.major != 9999){ //if the first device is not an emulator - std::cout<<"Using device "< 0 && prop.major != 9999){ //if the first device is not an emulator + std::cout<<"Using device "< best_device_cc){ - best_device_cc = cc; //if this is better than the previous device, use it - best_device_id = d; - } - } + bool coNoise_matrix(double* coN, double* avg, unsigned char *mask, bool use_gpu = true, bool PROGRESS = false){ + + if(use_gpu){ + int dev_count; + HANDLE_ERROR(cudaGetDeviceCount(&dev_count)); //get the number of CUDA devices + std::cout<<"Number of CUDA devices: "< best_device_cc){ + best_device_cc = cc; //if this is better than the previous device, use it + best_device_id = d; + } + } - if(dev_count > 0 && prop.major != 9999){ //if the first device is not an emulator - std::cout<<"Using device "< 0 && prop.major != 9999){ //if the first device is not an emulator + std::cout<<"Using device "<*)file)->co_matrix(co, avg, mask, PROGRESS); + return ((bil*)file)->co_matrix(co, avg, mask, use_gpu, PROGRESS); else if (header.data_type == envi_header::float64) - return ((bil*)file)->co_matrix(co, avg, mask, PROGRESS); + return ((bil*)file)->co_matrix(co, avg, mask, use_gpu, PROGRESS); else{ std::cout << "ERROR: unidentified data type" << std::endl; exit(1); @@ -1458,9 +1458,9 @@ public: } else if (header.interleave == envi_header::BIP){ if (header.data_type == envi_header::float32) - return ((bip*)file)->co_matrix(co, avg, mask, PROGRESS); + return ((bip*)file)->co_matrix(co, avg, mask, use_gpu, PROGRESS); else if (header.data_type == envi_header::float64) - return ((bip*)file)->co_matrix(co, avg, mask, PROGRESS); + return ((bip*)file)->co_matrix(co, avg, mask, use_gpu, PROGRESS); else{ std::cout << "ERROR: unidentified data type" << std::endl; exit(1); @@ -1474,7 +1474,7 @@ public: /// @param co is a pointer to pre-allocated memory of size [B * B] that stores the resulting covariance matrix /// @param avg is a pointer to memory of size B that stores the average spectrum /// @param mask is a pointer to memory of size [X * Y] that stores the mask value at each pixel location - bool coNoise_matrix(double* coN, double* avg, unsigned char* mask, bool PROGRESS = false){ + bool coNoise_matrix(double* coN, double* avg, unsigned char* mask, bool use_gpu = true, bool PROGRESS = false){ if (header.interleave == envi_header::BSQ){ std::cout<<"ERROR: calculating the covariance matrix of noise for a BSQ file is impractical; convert to BIP first"<*)file)->coNoise_matrix(coN, avg, mask, PROGRESS); + return ((bip*)file)->coNoise_matrix(coN, avg, mask, use_gpu, PROGRESS); else if (header.data_type == envi_header::float64) - return ((bip*)file)->coNoise_matrix(coN, avg, mask, PROGRESS); + return ((bip*)file)->coNoise_matrix(coN, avg, mask, use_gpu, PROGRESS); else{ std::cout << "ERROR: unidentified data type" << std::endl; exit(1); -- libgit2 0.21.4