Commit 08d1c3b9358d69b5250d4cc4d075ddb1b5072615

Authored by David Mayerich
1 parent 1c994463

fixed casting warning caused by cuBLAS

Showing 3 changed files with 14 additions and 105 deletions   Show diff stats
stim/envi/bip.h
... ... @@ -1236,7 +1236,6 @@ public:
1236 1236 cublasHandle_t handle;
1237 1237  
1238 1238 std::ofstream target(outfile.c_str(), std::ios::binary); //open the target binary file
1239   - //std::string headername = outfile + ".hdr"; //the header file name
1240 1239  
1241 1240 progress = 0; //initialize the progress to zero (0)
1242 1241 unsigned long long XY = X() * Y(); //calculate the number of elements in a band image
... ... @@ -1281,19 +1280,19 @@ public:
1281 1280 return EXIT_FAILURE;
1282 1281 }
1283 1282  
1284   - T* temp = (T*)malloc(sizeof(T) * M); //allocate space for the projected pixel to be written on the disc
1285   -
1286   - for (unsigned long long xy = 0; xy < XY; xy++){ //for each pixel
  1283 + T* temp = (T*)malloc(sizeof(T) * M); //allocate space for the projected pixel to be written on the disc
  1284 + size_t i;
  1285 + for (unsigned long long xy = 0; xy < XY; xy++){ //for each pixel
1287 1286 if (mask == NULL || mask[xy] != 0){
1288   - pixeld(s, xy); //retreive the spectrum at the current xy pixel location
  1287 + pixeld(s, xy); //retreive the spectrum at the current xy pixel location
1289 1288  
1290 1289 stat = cublasSetVector((int)B, sizeof(double), s, 1, s_dev, 1); //copy the spectrum from the host to the device
1291 1290 stat = cublasDaxpy(handle, (int)B, &axpy_alpha, center_dev, 1, s_dev, 1); //subtract the center (average)
1292 1291 stat = cublasDgemv(handle,CUBLAS_OP_N,(int)M,(int)B,&axpy_alpha2,basis_dev,(int)M,s_dev,1,&axpy_beta,A_dev,1); //performs the matrix-vector multiplication
1293   - stat = cublasGetVector((int)B, sizeof(double), A_dev, 1, A, 1); //copy the projected pixel to the host (from GPU to CPU)
1294   -
1295   - std::copy(A, A + M, temp); //casting projected pixel from double to whatever T is
  1292 + stat = cublasGetVector((int)B, sizeof(double), A_dev, 1, A, 1); //copy the projected pixel to the host (from GPU to CPU)
1296 1293  
  1294 + //std::copy<double*, T*>(A, A + M, temp);
  1295 + for(i = 0; i < M; i++) temp[i] = (T)A[i]; //casting projected pixel from double to whatever T is
1297 1296 }
1298 1297  
1299 1298 target.write(reinterpret_cast<const char*>(temp), sizeof(T) * M); //write the projected vector
... ... @@ -1310,7 +1309,7 @@ public:
1310 1309 free(s);
1311 1310 free(temp);
1312 1311 target.close(); //close the output file
1313   -
  1312 +
1314 1313 return true;
1315 1314 }
1316 1315 #endif
... ... @@ -1360,7 +1359,7 @@ public:
1360 1359 free(s); //free temporary storage arrays
1361 1360 free(rs);
1362 1361 target.close(); //close the output file
1363   -
  1362 +
1364 1363 return true;
1365 1364 }
1366 1365  
... ...
stim/envi/bsq.h
... ... @@ -394,7 +394,7 @@ public:
394 394 std::ofstream target(outname.c_str(), std::ios::binary);
395 395 std::string headername = outname + ".hdr";
396 396  
397   - size_t batches = ceil((double)(Y()) / (double)batch_slices); //calculate the number of batches
  397 + size_t batches = (size_t)ceil((double)(Y()) / (double)batch_slices); //calculate the number of batches
398 398 T* ptrDst;
399 399 T* ptrSrc;
400 400 for(size_t c = 0; c < batches; c++){
... ...
stim/envi/envi.h
... ... @@ -59,15 +59,17 @@ class envi{
59 59 for(size_t i = 0; i < len; i++)
60 60 cast(&dst[i], &src[i]);
61 61 }
62   -
  62 +
63 63 public:
  64 + envi_header header;
64 65  
  66 +
65 67 /// Default constructor
66 68 envi(){
67 69 file = NULL; //set the file pointer to NULL
68 70 }
69 71  
70   - envi_header header;
  72 +
71 73  
72 74 void* malloc_spectrum(){
73 75 return alloc_array(header.bands);
... ... @@ -1171,46 +1173,6 @@ public:
1171 1173 return false;
1172 1174 }
1173 1175  
1174   - /// Retrieve a spectrum from the specified location
1175   -
1176   - /// @param ptr is a pointer to pre-allocated memory of size B*sizeof(T)
1177   - /// @param x is the x-coordinate of the spectrum
1178   - /// @param y is the y-coordinate of the spectrum
1179   - /*bool spectrum(void* ptr, unsigned long long x, unsigned long long y, bool PROGRESS = false){
1180   -
1181   - if(header.interleave == envi_header::BSQ){ //if the infile is bsq file
1182   - if(header.data_type ==envi_header::float32)
1183   - return ((bsq<float>*)file)->spectrum((float*)ptr, x, y, PROGRESS);
1184   - else if (header.data_type == envi_header::float64)
1185   - return ((bsq<double>*)file)->spectrum((double*)ptr, x, y, PROGRESS);
1186   - else{
1187   - std::cout << "ERROR: unidentified data type" << std::endl;
1188   - exit(1);
1189   - }
1190   - }
1191   - else if (header.interleave == envi_header::BIL){
1192   - if (header.data_type == envi_header::float32)
1193   - return ((bil<float>*)file)->spectrum((float*)ptr, x, y, PROGRESS);
1194   - else if (header.data_type == envi_header::float64)
1195   - return ((bil<double>*)file)->spectrum((double*)ptr, x, y, PROGRESS);
1196   - else{
1197   - std::cout << "ERROR: unidentified data type" << std::endl;
1198   - exit(1);
1199   - }
1200   - }
1201   - else if (header.interleave == envi_header::BIP){
1202   - if (header.data_type == envi_header::float32)
1203   - return ((bip<float>*)file)->spectrum((float*)ptr, x, y, PROGRESS);
1204   - else if (header.data_type == envi_header::float64)
1205   - return ((bip<double>*)file)->spectrum((double*)ptr, x, y, PROGRESS);
1206   - else{
1207   - std::cout << "ERROR: unidentified data type" << std::endl;
1208   - exit(1);
1209   - }
1210   - }
1211   - return false;
1212   - }*/
1213   -
1214 1176 // Retrieve a spectrum at the specified 1D location
1215 1177  
1216 1178 /// @param ptr is a pointer to pre-allocated memory of size B*sizeof(T)
... ... @@ -1274,50 +1236,6 @@ public:
1274 1236 void spectrum(T* ptr, size_t x, size_t y, bool PROGRESS = false){
1275 1237  
1276 1238 spectrum<T>(ptr, y * header.samples + x, PROGRESS);
1277   - /*void* temp = alloc_array<T>(header.bands); //allocate space for the output array
1278   -
1279   - if(header.interleave == envi_header::BSQ){ //if the infile is bsq file
1280   - if(header.data_type ==envi_header::float32){
1281   - ((bsq<float>*)file)->spectrum((float*)temp, x, y, PROGRESS);
1282   - cast<T, float>(ptr, temp, header.bands);
1283   - }
1284   - else if (header.data_type == envi_header::float64){
1285   - ((bsq<double>*)file)->spectrum((double*)temp, x, y, PROGRESS);
1286   - cast<T, double>(ptr, temp, header.bands);
1287   - }
1288   - else{
1289   - std::cout << "ERROR: unidentified data type" << std::endl;
1290   - exit(1);
1291   - }
1292   - }
1293   - else if (header.interleave == envi_header::BIL){
1294   - if (header.data_type == envi_header::float32){
1295   - ((bil<float>*)file)->spectrum((float*)temp, x, y, PROGRESS);
1296   - cast<T, float>(ptr, temp, header.bands);
1297   - }
1298   - else if (header.data_type == envi_header::float64){
1299   - ((bil<double>*)file)->spectrum((double*)temp, x, y, PROGRESS);
1300   - cast<T, double>(ptr, temp, header.bands);
1301   - }
1302   - else{
1303   - std::cout << "ERROR: unidentified data type" << std::endl;
1304   - exit(1);
1305   - }
1306   - }
1307   - else if (header.interleave == envi_header::BIP){
1308   - if (header.data_type == envi_header::float32){
1309   - ((bip<float>*)file)->spectrum((float*)temp, x, y, PROGRESS);
1310   - cast<T, float>(ptr, temp, header.bands);
1311   - }
1312   - else if (header.data_type == envi_header::float64){
1313   - ((bip<double>*)file)->spectrum((double*)temp, x, y, PROGRESS);
1314   - cast<T, double>(ptr, temp, header.bands);
1315   - }
1316   - else{
1317   - std::cout << "ERROR: unidentified data type" << std::endl;
1318   - exit(1);
1319   - }
1320   - }*/
1321 1239 }
1322 1240  
1323 1241 /// Retrieve a single band (based on index) and stores it in pre-allocated memory.
... ... @@ -1405,14 +1323,6 @@ public:
1405 1323 if (header.interleave == envi_header::BSQ){
1406 1324 std::cout<<"ERROR: calculating the covariance matrix for a BSQ file is impractical; convert to BIL or BIP first"<<std::endl;
1407 1325 exit(1);
1408   - /*if (header.data_type == envi_header::float32)
1409   - return ((bsq<float>*)file)->co_matrix(co, avg, mask, PROGRESS);
1410   - else if (header.data_type == envi_header::float64)
1411   - return ((bsq<double>*)file)->co_matrix(co, avg, mask, PROGRESS);
1412   - else{
1413   - std::cout << "ERROR: unidentified data type" << std::endl;
1414   - exit(1);
1415   - }*/
1416 1326 }
1417 1327 else if (header.interleave == envi_header::BIL){
1418 1328 if (header.data_type == envi_header::float32)
... ...