From 3b0868251169f166038b0ba1b61998ff201c3c1c Mon Sep 17 00:00:00 2001 From: "Yount, Chuck" Date: Wed, 4 Jan 2023 15:18:03 -0800 Subject: [PATCH 1/9] Trivial clean-up for AWP. --- src/stencils/AwpStencil.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/stencils/AwpStencil.cpp b/src/stencils/AwpStencil.cpp index e5972cfe..79672719 100644 --- a/src/stencils/AwpStencil.cpp +++ b/src/stencils/AwpStencil.cpp @@ -638,7 +638,7 @@ namespace { // Macros for the "abc" versions. // Set the following macro to define all points, even those above the - // surface that are never used. This make error-checking more consistent. + // surface that are never used. This makes error-checking more consistent. #define SET_ALL_POINTS // Set the following macro to use intermediate scratch vars. @@ -702,7 +702,7 @@ namespace { // Since we're defining points when z == surface + 1, // the surface itself will be at z - 1; - auto surf = _base->z - 1; + auto surf = z - 1; #ifdef USE_SCRATCH_VARS From 78af37868a9e973bf9a14394fb6ed84505b52015 Mon Sep 17 00:00:00 2001 From: "Yount, Chuck" Date: Wed, 11 Jan 2023 09:22:58 -0800 Subject: [PATCH 2/9] Improve handling of spaces in command-line args. Add more specific invocation strings for compiler and kernel binaries. --- include/yask_common_api.hpp | 6 ++- src/common/common_utils.cpp | 71 ++++++++++++++++++++-------------- src/common/common_utils.hpp | 3 ++ src/compiler/compiler_main.cpp | 2 +- src/kernel/yask.sh | 6 ++- src/kernel/yask_main.cpp | 2 +- 6 files changed, 57 insertions(+), 33 deletions(-) diff --git a/include/yask_common_api.hpp b/include/yask_common_api.hpp index 54252efb..99f4605f 100644 --- a/include/yask_common_api.hpp +++ b/include/yask_common_api.hpp @@ -659,10 +659,12 @@ namespace yask { /// Print a YASK spash message to `os`. /** Splash message contains the YASK copyright, URL, and version. - If `argc > 1`, also prints the program invocation string. + If `argc > 1`, also prints `invocation_leader` followed by + the program invocation string. */ extern void - yask_print_splash(std::ostream& os, int argc, char** argv); + yask_print_splash(std::ostream& os, int argc, char** argv, + std::string invocation_leader = "invocation: "); #endif diff --git a/src/common/common_utils.cpp b/src/common/common_utils.cpp index 20fc246e..fd62f42e 100644 --- a/src/common/common_utils.cpp +++ b/src/common/common_utils.cpp @@ -44,7 +44,7 @@ namespace yask { // for numbers above 9 (at least up to 99). // Format: "major.minor.patch[-alpha|-beta]". - const string version = "4.01.00"; + const string version = "4.01.01"; string yask_get_version_string() { return version; @@ -145,6 +145,28 @@ namespace yask { return os.str(); } + // Add quotes around whitespace in string. + std::string quote_whitespace(const std::string& str) { + auto pos = str.find_first_of(" \t\r\n"); + if (pos != string::npos) { + string r = str; + + // Must not use chars already in the string. + auto apos = r.find('\''); + auto qpos = r.find('"'); + if (apos == string::npos) // No apostrophes. + r = string("\"") + r + '"'; // Add quotes. + else if (qpos == string::npos) // No quotes. + r = string("'") + r + "'"; // Add apostrophes. + else { // Has both :(. + r = regex_replace(r, regex("'"), "\\'"); // Escape apostrophes. + r = string("'") + r + "'"; // Add apostrophes. + } + return r; + } + return str; + } + // A var that behaves like OMP_NUM_THREADS. int yask_num_threads[yask_max_levels] = { 0 }; @@ -449,8 +471,8 @@ namespace yask { string str; while (getline(ss, str, ',')) { if (_allowed_strs.size() && _allowed_strs.count(str) == 0) { - THROW_YASK_EXCEPTION("illegal argument '" + str + "' to option '" + - args[argi - 2] + "'"); + THROW_YASK_EXCEPTION("illegal argument '" + quote_whitespace(str) + + "' to option '" + args[argi - 2] + "'"); } _val.push_back(str); } @@ -525,22 +547,8 @@ namespace yask { rem += " "; // Space between words. // Add quotes around 'r' if it has whitespace. - auto pos = r.find_first_of(" \t\r\n"); - if (pos != string::npos) { - - // Must not use chars already in the string. - auto apos = r.find('\''); - auto qpos = r.find('"'); - if (apos == string::npos) // No apostrophes. - r = string("\"") + r + '"'; // Add quotes. - else if (qpos == string::npos) // No quotes. - r = string("'") + r + "'"; // Add apostrophes. - else { // Has both :(. - r = regex_replace(r, regex("'"), "\\'"); // Escape apostrophes. - r = string("'") + r + "'"; // Add apostrophes. - } - } - + r = quote_whitespace(r); + rem += r; } return rem; @@ -549,6 +557,7 @@ namespace yask { // Tokenize args from a string. vector command_line_parser::set_args(const string& arg_string) { string tmp; // current arg. + bool is_ok = false; // current arg is valid. char in_quote = '\0'; // current string delimiter or null if none. vector args; for (char c : arg_string) { @@ -559,8 +568,7 @@ namespace yask { // End of quoted string, i.e., this char // matches opening quote. if (in_quote == c) { - args.push_back(tmp); // may be empty string. - tmp.clear(); + is_ok = true; // even if empty. in_quote = '\0'; } @@ -570,9 +578,10 @@ namespace yask { // If WS, save old string and start a new string. else if (isspace(c)) { - if (tmp.length()) + if (is_ok) args.push_back(tmp); tmp.clear(); + is_ok = false; } // If quote, remember delimiter. @@ -581,8 +590,10 @@ namespace yask { } // Otherwise, just add to tmp. - else + else { tmp += c; + is_ok = true; + } } if (in_quote != '\0') @@ -590,13 +601,14 @@ namespace yask { arg_string + "'"); // Last string. - if (tmp.length()) + if (is_ok) args.push_back(tmp); return args; } // Print a spash message. - void yask_print_splash(ostream& os, int argc, char** argv) { + void yask_print_splash(ostream& os, int argc, char** argv, + string invocation_leader) { // See https://en.wikipedia.org/wiki/Box-drawing_character. os << "\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n" @@ -608,9 +620,12 @@ namespace yask { // Echo invocation parameters for record-keeping. if (argc) { - os << "Binary invocation:"; - for (int argi = 0; argi < argc; argi++) - os << " " << argv[argi]; + os << invocation_leader; + for (int argi = 0; argi < argc; argi++) { + if (argi) + os << " "; + os << quote_whitespace(argv[argi]); + } os << endl; } } diff --git a/src/common/common_utils.hpp b/src/common/common_utils.hpp index 24d04360..42c2ddec 100644 --- a/src/common/common_utils.hpp +++ b/src/common/common_utils.hpp @@ -81,6 +81,9 @@ namespace yask { extern std::string make_num_str(idx_t num); extern std::string make_num_str(double num); + // Add quotes around whitespace in string. + extern std::string quote_whitespace(const std::string& str); + // Divide 'num' equally into 'nparts'. // Returns the size of the 'n'th part, // where 0 <= 'n' < 'nparts'. diff --git a/src/compiler/compiler_main.cpp b/src/compiler/compiler_main.cpp index 09e9add4..67a1ad79 100644 --- a/src/compiler/compiler_main.cpp +++ b/src/compiler/compiler_main.cpp @@ -167,7 +167,7 @@ int main(int argc, char* argv[]) { yc_factory factory; try { - yask_print_splash(cout, argc, argv); + yask_print_splash(cout, argc, argv, "YASK compiler invocation: "); cout << "\nYASK Stencil Compiler\n"; // Option parser. diff --git a/src/kernel/yask.sh b/src/kernel/yask.sh index 554b4967..a6e136f5 100755 --- a/src/kernel/yask.sh +++ b/src/kernel/yask.sh @@ -282,7 +282,11 @@ while true; do fi # Pass this option to executable. - opts+=" $1" + if [[ $1 =~ [[:space:]] ]]; then + opts+=" '$1'" + else + opts+=" $1" + fi shift fi diff --git a/src/kernel/yask_main.cpp b/src/kernel/yask_main.cpp index c3b8f51a..cbde424a 100644 --- a/src/kernel/yask_main.cpp +++ b/src/kernel/yask_main.cpp @@ -266,7 +266,7 @@ int main(int argc, char** argv) kenv->assert_equality_over_ranks(opts.validate ? 0 : 1, "validation"); // Print splash banner and related info. - yask_print_splash(os, argc, argv); + yask_print_splash(os, argc, argv, "YASK kernel invocation: "); os << "\nYASK performance and validation utility\n" "Stencil name: " << ksoln->get_name() << endl; From 3c7f59ab8e44ac58564710ec4e78a38e415093e5 Mon Sep 17 00:00:00 2001 From: "Yount, Chuck" Date: Wed, 11 Jan 2023 09:48:10 -0800 Subject: [PATCH 3/9] Add print_splash() API to kernel. Small change to invocation output. --- .../html/classyask_1_1yk__env-members.html | 9 +- docs/api/html/classyask_1_1yk__env.html | 48 ++++++++++ docs/api/html/functions_func_p.html | 1 + docs/api/html/functions_p.html | 1 + docs/api/html/group__yask.html | 21 +++-- docs/api/html/search/all_13.js | 2 +- docs/api/html/search/all_d.js | 7 +- docs/api/html/search/functions_11.js | 2 +- docs/api/html/search/functions_c.js | 7 +- docs/api/html/yask__common__api_8hpp.html | 6 +- .../html/yask__common__api_8hpp_source.html | 16 ++-- .../html/yask__kernel__api_8hpp_source.html | 90 ++++++++++--------- docs/api/html/yk__var__api_8hpp_source.html | 2 +- include/yask_common_api.hpp | 3 +- include/yask_kernel_api.hpp | 13 +++ src/compiler/compiler_main.cpp | 3 +- src/kernel/yask_main.cpp | 5 +- 17 files changed, 159 insertions(+), 77 deletions(-) diff --git a/docs/api/html/classyask_1_1yk__env-members.html b/docs/api/html/classyask_1_1yk__env-members.html index c4a98b7d..8d8f5f72 100644 --- a/docs/api/html/classyask_1_1yk__env-members.html +++ b/docs/api/html/classyask_1_1yk__env-members.html @@ -88,10 +88,11 @@ get_rank_index() const =0yask::yk_envpure virtual global_barrier() const =0yask::yk_envpure virtual is_trace_enabled()yask::yk_envstatic - set_debug_output(yask_output_ptr debug)yask::yk_envstatic - set_trace_enabled(bool enable)yask::yk_envstatic - sum_over_ranks(idx_t rank_val) const =0yask::yk_envpure virtual - ~yk_env() (defined in yask::yk_env)yask::yk_envinlinevirtual + print_splash(int argc, char **argv, std::string invocation_leader="invocation: ")yask::yk_envinlinestatic + set_debug_output(yask_output_ptr debug)yask::yk_envstatic + set_trace_enabled(bool enable)yask::yk_envstatic + sum_over_ranks(idx_t rank_val) const =0yask::yk_envpure virtual + ~yk_env() (defined in yask::yk_env)yask::yk_envinlinevirtual