From 7e55ee77307d07694b147734922fb78254d7b406 Mon Sep 17 00:00:00 2001 From: Ben Howe <141149032+bmhowe23@users.noreply.github.com> Date: Thu, 21 Sep 2023 11:19:29 -0500 Subject: [PATCH] Make `nvq++ --version` work (#680) --- test/NVQPP/testVersion.cpp | 11 +++++++++++ tools/cudaq-quake/cudaq-quake.cpp | 6 ++---- tools/nvqpp/nvq++.in | 9 +++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 test/NVQPP/testVersion.cpp diff --git a/test/NVQPP/testVersion.cpp b/test/NVQPP/testVersion.cpp new file mode 100644 index 0000000000..70713a5321 --- /dev/null +++ b/test/NVQPP/testVersion.cpp @@ -0,0 +1,11 @@ +/******************************************************************************* + * Copyright (c) 2022 - 2023 NVIDIA Corporation & Affiliates. * + * All rights reserved. * + * * + * This source code and the accompanying materials are made available under * + * the terms of the Apache License 2.0 which accompanies this distribution. * + ******************************************************************************/ + +// Note: change |& to 2>&1| if running in bash +// RUN: nvq++ --version |& FileCheck %s +// CHECK: nvq++ Version diff --git a/tools/cudaq-quake/cudaq-quake.cpp b/tools/cudaq-quake/cudaq-quake.cpp index a4d94ca156..1af96530a5 100644 --- a/tools/cudaq-quake/cudaq-quake.cpp +++ b/tools/cudaq-quake/cudaq-quake.cpp @@ -299,6 +299,8 @@ int main(int argc, char **argv) { // Process the command-line options, including reading in a file. [[maybe_unused]] llvm::InitLLVM unused(argc, argv); cl::ParseCommandLineOptions(argc, argv, toolName); + if (showVersion) + llvm::errs() << "nvq++ Version " << cudaq::getVersion() << '\n'; ErrorOr> fileOrError = MemoryBuffer::getFileOrSTDIN(inputFilename); if (auto ec = fileOrError.getError()) { @@ -341,10 +343,6 @@ int main(int argc, char **argv) { << '\n'; }); - if (showVersion) { - llvm::errs() << "nvq++ Version " << cudaq::getVersion() << '\n'; - } - // Process arguments. std::vector clArgs = {"-std=c++20", "-resource-dir", resourceDirPath.string()}; diff --git a/tools/nvqpp/nvq++.in b/tools/nvqpp/nvq++.in index afee41d73b..f29a463004 100755 --- a/tools/nvqpp/nvq++.in +++ b/tools/nvqpp/nvq++.in @@ -221,6 +221,7 @@ SRCS= ARGS= CUDAQ_QUAKE_ARGS= DO_LINK=true +SHOW_VERSION=false ENABLE_DEVICE_CODE_LOADERS=true ENABLE_KERNEL_EXECUTION=true ENABLE_AGGRESSIVE_EARLY_INLINE=true @@ -386,6 +387,7 @@ while [ $# -ne 0 ]; do ;; --version) CUDAQ_QUAKE_ARGS="--nvqpp-version ${CUDAQ_QUAKE_ARGS}" + SHOW_VERSION=true ;; -v) ECHO=true @@ -506,6 +508,13 @@ fi OPT_PASSES="builtin.module(${OPT_PASSES})" +if ${SHOW_VERSION} && [ -z "$SRCS" ] && [ -z "$OBJS" ]; then + # If version is requested and no source files were provided, bypass the + # cudaq-quake path that expects to read code from stdin. + echo "" | ${TOOLBIN}cudaq-quake ${CUDAQ_QUAKE_ARGS} + DO_LINK=false +fi + for i in ${SRCS}; do file=$(basename -s .cc -s .cpp $i)