Commit d447c00f authored by Patrick McCormick's avatar Patrick McCormick
Browse files

Tweaks to address some issues with the -fkokkos option and the addition of

command line arguments to align with the full toolchain build. One issue
is that link libraries that appear in the .cfg files can end up out of
order and result in undefined symbols.

Instead of trying to fix ordering within the config file processing in the
driver, this commit hardcodes the kokkos link libraries to the driver/toolchain
(just like cheetah/opencilk) and are set to match the internal kokkos build we
are now using.
parent 1043ece1
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@

/* kitsune default kokkos configure (.cfg) filename */
#cmakedefine KITSUNE_KOKKOS_CFG_FILENAME "${KITSUNE_KOKKOS_CFG_FILENAME}"
#cmakedefine KITSUNE_KOKKOS_EXTRA_LINK_FLAGS "${KITSUNE_KOKKOS_EXTRA_LINK_FLAGS}"
#cmakedefine KITSUNE_KOKKOS_EXTRA_LINK_LIBS "${KITSUNE_KOKKOS_EXTRA_LINK_LIBS}"

/* tapir default target-specific configure (.cfg) filenames */
#cmakedefine TAPIR_NONE_TARGET_CFG_FILENAME "${TAPIR_SERIAL_TARGET_CFG_FILENAME}"
+4 −0
Original line number Diff line number Diff line
@@ -29,6 +29,10 @@ if (KITSUNE_ENABLE_KOKKOS_SUPPORT)
      ""
      CACHE
      STRING "Additional link flags needed for Kokkos applications.")
  set(KITSUNE_KOKKOS_EXTRA_LINK_LIBS 
     ""
     CACHE 
     STRING "Additional link libraries needed for Kokkos applications.")
  #
  configure_file(${CLANG_SOURCE_DIR}/kitsune/${KITSUNE_KOKKOS_CFG_FILENAME}.in
      ${LLVM_BINARY_DIR}/share/kitsune/${KITSUNE_KOKKOS_CFG_FILENAME})
+6 −7
Original line number Diff line number Diff line
# Flags for the Kokkos mode (-fkokkos).
# CXX flags
${KITSUNE_KOKKOS_CXX_FLAGS}
${KITSUNE_KOKKOS_EXTRA_LINK_FLAGS} 
-I${CMAKE_INSTALL_PREFIX}/include  
-I${CMAKE_INSTALL_PREFIX}/include/kokkos  
-L${CMAKE_INSTALL_PREFIX}/lib/ 
-Wl,--start-group
${KITSUNE_KOKKOS_LINK_LIBS_FLAGS}

# for in-tree use... 
-I${LLVM_BINARY_DIR}/kokkos/core/src -I${LLVM_BINARY_DIR}/kokkos/containers/src 
-I${LLVM_BINARY_DIR}/runtimes/runtimes-bins/
-L${LLVM_BINARY_DIR}/runtimes/runtimes-bins/_deps/kokkos-build/core/src/ 
--end-group
+40 −20
Original line number Diff line number Diff line
@@ -831,15 +831,34 @@ bool Driver::readConfigFile(StringRef FileName) {
  llvm::SmallString<128> CfgFileName(FileName);
  llvm::sys::path::native(CfgFileName);
  ConfigFile = CfgFileName.str();
  ConfigFileList.push_back(CfgFileName.str());
  bool ContainErrors;
  ConfigFileList.push_back(ConfigFile);

  bool ContainsErrors;
  if (CfgOptions.get() == nullptr) {
    // processing the first .cfg file...
    CfgOptions = std::make_unique<InputArgList>(
      ParseArgStrings(NewCfgArgs, IsCLMode(), ContainErrors));
  if (ContainErrors) {
        ParseArgStrings(NewCfgArgs, IsCLMode(), ContainsErrors));

    if (ContainsErrors) {
      CfgOptions.reset();
      return true;
    }
  } else {
    // we've been through a previous config file so we don't want to
    // trash the cfg options previously captured...
    std::unique_ptr<InputArgList> NextCfgOpts;
    NextCfgOpts = std::make_unique<InputArgList>(
      ParseArgStrings(NewCfgArgs, IsCLMode(), ContainsErrors));

    if (ContainsErrors) {
      CfgOptions.reset();
      return true;
    }

    for(Arg *A: *NextCfgOpts)
      CfgOptions->append(A);
  }

  if (CfgOptions->hasArg(options::OPT_config)) {
    CfgOptions.reset();
    Diag(diag::err_drv_nested_config_file);
@@ -894,7 +913,6 @@ bool Driver::loadConfigFile() {
          UserConfigDir = std::string(CfgDir.begin(), CfgDir.end());
      }
    }

  }

  // First try to find config file specified in command line.
@@ -935,16 +953,17 @@ bool Driver::loadConfigFile() {

  // kitsune: check for a kokkos configuration file.
  if (CLOptions->hasArg(options::OPT_fkokkos)) {
    LLVM_DEBUG(llvm::dbgs()
               << "looking for -fkokkos mode config file '" 
    LLVM_DEBUG(llvm::dbgs() << "looking for -fkokkos mode config file '"
                            << KitsuneKokkosCfgFile.c_str() << "'.\n");
    llvm::SmallString<128> KokkosCfgFilePath;
    if (searchForFile(KokkosCfgFilePath, CfgFileSearchDirs, KitsuneKokkosCfgFile)) {
    if (searchForFile(KokkosCfgFilePath, CfgFileSearchDirs,
                      KitsuneKokkosCfgFile)) {
      if (readConfigFile(KokkosCfgFilePath))
        Diag(diag::err_drv_cannot_read_kitsune_cfg_file)
            << KokkosCfgFilePath << "-fkokkos";
    } else {
      Diag(diag::warn_drv_missing_cfg_file) << KitsuneKokkosCfgFile << "-fkokkos";
      Diag(diag::warn_drv_missing_cfg_file)
          << KitsuneKokkosCfgFile << "-fkokkos";
      for (const StringRef &SearchDir : CfgFileSearchDirs)
        if (!SearchDir.empty())
          Diag(diag::note_drv_config_file_searched_in) << SearchDir;
@@ -983,6 +1002,7 @@ bool Driver::loadConfigFile() {
    }
  }


  // If config file is not specified explicitly, try to deduce configuration
  // from executable name. For instance, an executable 'armv7l-clang' will
  // search for config file 'armv7l-clang.cfg'.
+16 −1
Original line number Diff line number Diff line
@@ -1212,9 +1212,24 @@ void ToolChain::AddTapirRuntimeLibArgs(const ArgList &Args,
    break;
  }

  // NOTE: Due to ordering issues introduced by the .cfg files it 
  // doesn't work to add the link libraries (e.g., -lkokkoscore)
  // as they end up in the wrong order and the symbols will show as
  // undefined when compiling/linking kokkos code.  As such we add
  // the bare minimum kokkos libraries here so they can be left out
  // of the .cfg files. 
  if (D.CCCIsCXX() && Args.hasArg(options::OPT_fkokkos)) {
    if (! KITSUNE_ENABLE_KOKKOS_SUPPORT)
      getDriver().Diag(diag::warn_drv_kokkos_disabled);

    else {
      #if defined(KITSUNE_KOKKOS_EXTRA_LINK_FLAGS)
      ExtractArgsFromString(KITSUNE_KOKKOS_EXTRA_LINK_FLAGS, CmdArgs, Args);
      #endif
      CmdArgs.push_back("-lkokkoscore");
      CmdArgs.push_back("-ldl");
      #if defined(KITSUNE_KOKKOS_EXTRA_LINK_LIBS)
      ExtractArgsFromString(KITSUNE_KOKKOS_EXTRA_LINK_LIBS, CmdArgs, Args);
      #endif
    }
  }
}
Loading