From 002ba9ae1e74b15211a7756b26c7ec5b32fe97af Mon Sep 17 00:00:00 2001 From: Malcolm Roberts Date: Wed, 8 Jan 2020 09:17:08 -0700 Subject: [PATCH] Add verbose option to rider. --- clients/rider/rider.cpp | 83 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 76 insertions(+), 7 deletions(-) diff --git a/clients/rider/rider.cpp b/clients/rider/rider.cpp index c04ebec8..8bee66d0 100644 --- a/clients/rider/rider.cpp +++ b/clients/rider/rider.cpp @@ -38,6 +38,39 @@ bool increment_colmajor(std::vector& index, const std::vector& length) return !std::all_of(index.begin(), index.end(), [](int i) { return i == 0; }); } +// Output a formatted general-dimensional array with given length and stride in batches separated by +// dist. +template +void printbuffer(const std::vector& output, + const std::vector length, + const std::vector stride, + const size_t nbatch, + const size_t dist) +{ + for(size_t b = 0; b < nbatch; b++) + { + std::vector index(length.size()); + std::fill(index.begin(), index.end(), 0); + do + { + const int i = std::inner_product(index.begin(), index.end(), stride.begin(), b * dist); + std::cout << output[i] << " "; + for(int i = 0; i < index.size(); ++i) + { + if(index[i] == (length[i] - 1)) + { + std::cout << "\n"; + } + else + { + break; + } + } + } while(increment_colmajor(index, length)); + std::cout << std::endl; + } +} + // Perform a transform using rocFFT. We assume that all input is valid at this point. // ntrial is the number of trials; if this is 0, then we just do a correctness check. template @@ -56,7 +89,8 @@ int transform(const std::vector length, rocfft_transform_type transformType, double scale, int deviceId, - const int ntrial) + const int ntrial, + const int verbose) { HIP_V_THROW(hipSetDevice(deviceId), " hipSetDevice failed"); @@ -143,6 +177,12 @@ int transform(const std::vector length, } while(increment_colmajor(index, length)); } + if(verbose) + { + std::cout << "input:\n"; + printbuffer(input, length, istride, nbatch, idist); + } + HIP_V_THROW(hipMemcpy(ibuffer[0], input.data(), isize, hipMemcpyHostToDevice), "hipMemcpy failed"); } @@ -186,6 +226,12 @@ int transform(const std::vector length, size_t p3 = b * idist; input[p3] = delta; } + if(verbose) + { + std::cout << "\ninput:\n"; + printbuffer(input, length, istride, nbatch, idist); + } + HIP_V_THROW(hipMemcpy(ibuffer[0], input.data(), isize, hipMemcpyHostToDevice), "hipMemcpy failed"); } @@ -228,6 +274,13 @@ int transform(const std::vector length, } while(increment_colmajor(index, length)); } + + if(verbose) + { + std::cout << "\ninput:\n"; + printbuffer(input, length, istride, nbatch, idist); + } + HIP_V_THROW(hipMemcpy(ibuffer[0], input.data(), isize, hipMemcpyHostToDevice), "hipMemcpy failed"); } @@ -409,6 +462,12 @@ int transform(const std::vector length, } } while(increment_colmajor(index, length)); } + + if(verbose) + { + std::cout << "output:\n"; + printbuffer(output, length, ostride, nbatch, odist); + } } break; case rocfft_array_type_hermitian_planar: @@ -488,6 +547,12 @@ int transform(const std::vector length, } } while(increment_colmajor(index, length)); } + + if(verbose) + { + std::cout << "output:\n"; + printbuffer(output, length, ostride, nbatch, odist); + } } break; default: @@ -587,6 +652,9 @@ int main(int argc, char* argv[]) // This helps with mixing output of both wide and narrow characters to the screen std::ios::sync_with_stdio(false); + // Control output verbosity: + int verbose; + // hip Device number for running tests: int deviceId; @@ -626,10 +694,9 @@ int main(int argc, char* argv[]) po::options_description desc("rocfft rider command line options"); desc.add_options()("help,h", "produces this help message") ("version,v", "Print queryable version information from the rocfft library") - ("device", po::value(&deviceId)->default_value(0), - "Select a specific device id") - ("ntrial,N", po::value(&ntrial)->default_value(1), - "Trial size for the problem") + ("device", po::value(&deviceId)->default_value(0), "Select a specific device id") + ("verbose", po::value(&verbose)->implicit_value(0), "Control output verbosity") + ("ntrial,N", po::value(&ntrial)->default_value(1), "Trial size for the problem") ("notInPlace,o", "Not in-place FFT transform (default: in-place)") ("double", "Double precision transform (default: single)") ("transformType,t", po::value(&transformType) @@ -1039,7 +1106,8 @@ int main(int argc, char* argv[]) transformType, scale, deviceId, - ntrial); + ntrial, + verbose); } else { @@ -1058,7 +1126,8 @@ int main(int argc, char* argv[]) transformType, scale, deviceId, - ntrial); + ntrial, + verbose); } } catch(std::exception& e)