Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[kitsune] Add kit-config tool #59

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kitsune/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ endforeach()

add_subdirectory(configs)
add_subdirectory(include/kitsune)
add_subdirectory(tools)
add_subdirectory(experiments)

if(KITSUNE_INCLUDE_TESTS)
Expand Down
2 changes: 1 addition & 1 deletion kitsune/cmake/caches/kitsune-dev-darwin-aarch64.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ set(CLANG_VENDOR_UTI "gov.lanl.kitsune" CACHE STRING "")
set(LLVM_TARGETS_TO_BUILD "AArch64;X86;NVPTX;AMDGPU" CACHE STRING "")

# Enable specific tapir targets.
set(KITSUNE_ENABLE_TAPIR_TARGETS "cuda;hip;opencilk")
set(KITSUNE_ENABLED_TAPIR_TARGETS "cuda;hip;opencilk")

# Enable tailored Kokkos compilation.
set(KITSUNE_KOKKOS_ENABLED ON CACHE BOOL
Expand Down
2 changes: 1 addition & 1 deletion kitsune/cmake/caches/kitsune-dev-darwin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ set(CLANG_VENDOR_UTI "gov.lanl.kitsune" CACHE STRING "")
set(LLVM_TARGETS_TO_BUILD "X86;NVPTX;AMDGPU" CACHE STRING "")

# Enable specific tapir targets.
set(KITSUNE_ENABLE_TAPIR_TARGETS "cuda;hip;opencilk")
set(KITSUNE_ENABLED_TAPIR_TARGETS "cuda;hip;opencilk")

# Enable tailored Kokkos compilation.
set(KITSUNE_KOKKOS_ENABLED ON CACHE BOOL
Expand Down
2 changes: 1 addition & 1 deletion kitsune/cmake/caches/kitsune-dev-desktop.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ set(CLANG_VENDOR "Kitsune" CACHE STRING "")
set(CLANG_VENDOR_UTI "gov.lanl.kitsune" CACHE STRING "")

# Enable specific tapir targets.
set(KITSUNE_ENABLE_TAPIR_TARGETS "cuda;hip;opencilk")
set(KITSUNE_ENABLED_TAPIR_TARGETS "cuda;hip;opencilk")

# Enable tailored Kokkos compilation.
set(KITSUNE_KOKKOS_ENABLED ON CACHE BOOL
Expand Down
3 changes: 3 additions & 0 deletions kitsune/include/kitsune/Config/config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,7 @@
#define KITSUNE_REALM_EXTRA_COMPILER_FLAGS "${KITSUNE_REALM_EXTRA_COMPILER_FLAGS}"
#define KITSUNE_REALM_EXTRA_LINKER_FLAGS "${KITSUNE_REALM_EXTRA_LINKER_FLAGS}"

// The Tapir targets that have been enabled in this build
#define KITSUNE_ENABLED_TAPIR_TARGETS "${KITSUNE_ENABLED_TAPIR_TARGETS_STR}"

#endif
1 change: 1 addition & 0 deletions kitsune/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(kit-config)
9 changes: 9 additions & 0 deletions kitsune/tools/kit-config/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set(LLVM_LINK_COMPONENTS
Support)

# set(BUILDVARIABLES_SRCPATH ${CMAKE_CURRENT_SOURCE_DIR}/BuildVariables.inc.in)
# set(BUILDVARIABLES_OBJPATH ${CMAKE_CURRENT_BINARY_DIR}/BuildVariables.inc)

# Add the kit-config tool.
add_llvm_tool(kit-config
kit-config.cpp)
91 changes: 91 additions & 0 deletions kitsune/tools/kit-config/kit-config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//===-- kit-config.cpp - Kitsune configuration utility --------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This tool encapsulates information about Kitsune's configuration. This is
// an analog of the LLVM project's llvm-config utility, but the scope is very
// narrow. For most things, llvm-config should be used.
//
//===----------------------------------------------------------------------===//

#include "kitsune/Config/config.h"
#include "llvm/Config/config.h"
#include "llvm/Support/raw_ostream.h"

using namespace llvm;

static void usage(bool exitWithFailure = true) {
errs() << "\
usage: kit-config <OPTION>... \n\
\n\
Get configuration information about Kitsune\n\
\n\
Options:\n\
--cuda-prefix The cuda prefix (only relevant if the Cuda tapir target was bbuilt)\n\
--cuda-target Has the Cuda Tapir target been built (ON or OFF).\n\
--help Print a summary of kit-config arguments.\n\
--hip-prefix The rocm prefix (only relevant if the Hip tapir target was built)\n\
--hip-target Has the Hip Tapir target been built (ON or OFF).\n\
--kokkos-mode Is Kokkos mode enabled (ON or OFF).\n\
--opencilk-target Has the OpenCilk Tapir target been built (ON or OFF).\n\
--openmp-target Has the OpenMP Tapir target been built (ON or OFF).\n\
--qthreads-target Has the Qthreads Tapir target been built (ON or OFF).\n\
--realm-target Has the Realm Tapir target been built (ON or OFF).\n\
--tapir-targets List all tapir targets that have been built.\n\
--version Print LLVM version.\n";
if (exitWithFailure)
exit(1);
}

int main(int argc, char **argv) {
bool hasAnyOption = false;

raw_ostream &os = outs();
for (int i = 1; i != argc; ++i) {
StringRef Arg = argv[i];

if (Arg.starts_with("-")) {
hasAnyOption = true;
if (Arg == "--version") {
os << PACKAGE_VERSION << "\n";
} else if (Arg == "--help") {
usage(false);
} else if (Arg == "--cuda-prefix") {
if (KITSUNE_CUDA_ENABLED)
os << KITSUNE_CUDA_PREFIX << "\n";
} else if (Arg == "--cuda-target") {
os << (KITSUNE_CUDA_ENABLED ? "ON" : "OFF") << "\n";
} else if (Arg == "--hip-prefix") {
if (KITSUNE_HIP_ENABLED)
os << KITSUNE_HIP_PREFIX << "\n";
} else if (Arg == "--hip-target") {
os << (KITSUNE_HIP_ENABLED ? "ON" : "OFF") << "\n";
} else if (Arg == "--kokkos-mode") {
os << (KITSUNE_KOKKOS_ENABLED ? "ON" : "OFF") << "\n";
} else if (Arg == "--opencilk-target") {
os << (KITSUNE_OPENCILK_ENABLED ? "ON" : "OFF") << "\n";
} else if (Arg == "--openmp-target") {
os << (KITSUNE_OPENMP_ENABLED ? "ON" : "OFF") << "\n";
} else if (Arg == "--qthreads-target") {
os << (KITSUNE_QTHREADS_ENABLED ? "ON" : "OFF") << "\n";
} else if (Arg == "--realm-target") {
os << (KITSUNE_REALM_ENABLED ? "ON" : "OFF") << "\n";
} else if (Arg == "--tapir-targets") {
os << KITSUNE_ENABLED_TAPIR_TARGETS << "\n";
} else {
usage();
}
} else {
usage();
}
}

if (!hasAnyOption)
usage();

return 0;
}
15 changes: 10 additions & 5 deletions llvm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -288,24 +288,29 @@ set(KITSUNE_DEFAULT_TAPIR_TARGETS
CACHE STRING
"The Tapir targets that are built by default if targets are not explicitly specified.")

set(KITSUNE_ENABLE_TAPIR_TARGETS
set(KITSUNE_ENABLED_TAPIR_TARGETS
"${KITSUNE_DEFAULT_TAPIR_TARGETS}"
CACHE STRING
"Semicolon-separated list of runtime targets to build (or \"all\".)")

if (NOT KITSUNE_ENABLE_TAPIR_TARGETS)
if (NOT KITSUNE_ENABLED_TAPIR_TARGETS)
message(FATAL_ERROR "At least one runtime target must be built")
endif ()

foreach(target IN LISTS KITSUNE_ENABLE_TAPIR_TARGETS)
# The serial Tapir target is always enabled
set(KITSUNE_TAPIR_TARGETS_STR "serial")
foreach(target IN LISTS KITSUNE_ENABLED_TAPIR_TARGETS)
if (target IN_LIST KITSUNE_ALL_TAPIR_TARGETS)
message(STATUS "${target} tapir target enabled")
string(TOUPPER "${target}" upper_target)
set(KITSUNE_${upper_target}_ENABLED ON CACHE INTERNAL "Enable the ${target} tapir target" FORCE)
string(TOUPPER "${target}" upper)
set(KITSUNE_${upper}_ENABLED ON CACHE INTERNAL "Enable the ${target} tapir target" FORCE)
string(TOLOWER "${target}" lower)
set(KITSUNE_TAPIR_TARGETS_STR "${KITSUNE_TAPIR_TARGETS_STR} ${lower}")
else ()
message(FATAL_ERROR "Unknown Tapir target: ${target}")
endif()
endforeach()
string(STRIP "${KITSUNE_TAPIR_TARGETS_STR}" KITSUNE_ENABLED_TAPIR_TARGETS_STR)

# We always want libLLVM to be build because we link to it in Kitsune's runtime,
# libkitrt
Expand Down