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

Fix compilation on SELS/RHEL after #2657 merged #2690

Merged
merged 8 commits into from
Jan 24, 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
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ else()
set(MIOPEN_DEFAULT_BACKEND "OpenCL")
endif()

if(NOT WIN32)
include(CheckCXXLinkerFlag)
check_cxx_linker_flag(stdc++fs HAS_LIB_STD_FILESYSTEM)
endif()

list(APPEND CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX} ${CMAKE_INSTALL_PREFIX}/llvm ${CMAKE_INSTALL_PREFIX}/hip /opt/rocm /opt/rocm/llvm /opt/rocm/hip)

option(ENABLE_HIP_WORKAROUNDS Off)
Expand Down
4 changes: 4 additions & 0 deletions addkernels/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@
set(ADD_KERNELS_SOURCE include_inliner.cpp addkernels.cpp)

add_executable(addkernels EXCLUDE_FROM_ALL ${ADD_KERNELS_SOURCE})
target_include_directories(addkernels PRIVATE ${PROJECT_SOURCE_DIR}/src/include)
if(HAS_LIB_STD_FILESYSTEM)
target_link_libraries(addkernels PRIVATE stdc++fs)
endif()

clang_tidy_check(addkernels)
7 changes: 3 additions & 4 deletions addkernels/addkernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
*******************************************************************************/
#include "include_inliner.hpp"
#include <algorithm>
#include <filesystem>
#include <fstream>
#include <iomanip>
#include <iostream>
Expand Down Expand Up @@ -125,22 +124,22 @@ void PrintHelp()
WrongUsage(ss.str());
}

void Process(const std::filesystem::path& sourcePath,
void Process(const fs::path& sourcePath,
std::ostream& target,
size_t bufferSize,
size_t lineSize,
bool recurse,
bool as_extern,
bool mark_includes)
{
if(!std::filesystem::exists(sourcePath))
if(!fs::exists(sourcePath))
{
std::cerr << "File not found: " << sourcePath << std::endl;
// NOLINTNEXTLINE (concurrency-mt-unsafe)
std::exit(1);
}

std::filesystem::path root{sourcePath.has_parent_path() ? sourcePath.parent_path() : ""};
fs::path root{sourcePath.has_parent_path() ? sourcePath.parent_path() : ""};
std::ifstream sourceFile{sourcePath, std::ios::in | std::ios::binary};
std::istream* source = &sourceFile;

Expand Down
13 changes: 6 additions & 7 deletions addkernels/include_inliner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ std::string IncludeFileExceptionBase::What() const

void IncludeInliner::Process(std::istream& input,
std::ostream& output,
const std::filesystem::path& root,
const std::filesystem::path& file_name,
const fs::path& root,
const fs::path& file_name,
const std::string& directive,
bool allow_angle_brackets,
bool recurse)
Expand All @@ -50,8 +50,8 @@ void IncludeInliner::Process(std::istream& input,

void IncludeInliner::ProcessCore(std::istream& input,
std::ostream& output,
const std::filesystem::path& root,
const std::filesystem::path& file_name,
const fs::path& root,
const fs::path& file_name,
int line_number,
const std::string& directive,
bool allow_angle_brackets,
Expand Down Expand Up @@ -115,10 +115,9 @@ void IncludeInliner::ProcessCore(std::istream& input,
const std::string include_file_path =
line.substr(first_quote_pos + 1, second_quote_pos - first_quote_pos - 1);

const auto abs_include_file_path{
std::filesystem::weakly_canonical(root / include_file_path)};
const auto abs_include_file_path{miopen::weakly_canonical(root / include_file_path)};

if(!std::filesystem::exists(abs_include_file_path))
if(!fs::exists(abs_include_file_path))
{
if(include_optional)
continue;
Expand Down
9 changes: 4 additions & 5 deletions addkernels/include_inliner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

#include "source_file_desc.hpp"
#include <exception>
#include <filesystem>
#include <memory>
#include <ostream>
#include <stack>
Expand Down Expand Up @@ -120,8 +119,8 @@ class IncludeInliner

void Process(std::istream& input,
std::ostream& output,
const std::filesystem::path& root,
const std::filesystem::path& file_name,
const fs::path& root,
const fs::path& file_name,
const std::string& directive,
bool allow_angle_brackets,
bool recurse);
Expand All @@ -133,8 +132,8 @@ class IncludeInliner

void ProcessCore(std::istream& input,
std::ostream& output,
const std::filesystem::path& root,
const std::filesystem::path& file_name,
const fs::path& root,
const fs::path& file_name,
int line_number,
const std::string& directive,
bool allow_angle_brackets,
Expand Down
10 changes: 5 additions & 5 deletions addkernels/source_file_desc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@
#ifndef SOURCE_FILE_DESC_HPP
#define SOURCE_FILE_DESC_HPP

#include <filesystem>
#include <miopen/filesystem.hpp>
#include <memory>
#include <string>

namespace fs = miopen::fs;

class SourceFileDesc
{
public:
std::filesystem::path path;
fs::path path;
int included_line;
std::shared_ptr<SourceFileDesc> included_from;

SourceFileDesc(const std::filesystem::path& path_,
std::shared_ptr<SourceFileDesc> from,
int line)
SourceFileDesc(const fs::path& path_, std::shared_ptr<SourceFileDesc> from, int line)
: path(path_), included_line(line), included_from(from)
{
}
Expand Down
60 changes: 60 additions & 0 deletions cmake/CheckCXXLinkerFlag.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
################################################################################
#
# MIT License
#
# Copyright (c) 2024 Advanced Micro Devices, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
################################################################################

set(check_cxx_linker_flag_patterns
FAIL_REGEX "[Uu]nrecogni[sz]ed .*option" # GNU, NAG
FAIL_REGEX "switch .* is no longer supported" # GNU
FAIL_REGEX "unknown .*option" # Clang
FAIL_REGEX "optimization flag .* not supported" # Clang
FAIL_REGEX "unknown argument ignored" # Clang (cl)
FAIL_REGEX "ignoring unknown option" # MSVC, Intel
FAIL_REGEX "warning D9002" # MSVC, any lang
FAIL_REGEX "option.*not supported" # Intel
FAIL_REGEX "invalid argument .*option" # Intel
FAIL_REGEX "ignoring option .*argument required" # Intel
FAIL_REGEX "ignoring option .*argument is of wrong type" # Intel
FAIL_REGEX "[Uu]nknown option" # HP
FAIL_REGEX "[Ww]arning: [Oo]ption" # SunPro
FAIL_REGEX "command option .* is not recognized" # XL
FAIL_REGEX "command option .* contains an incorrect subargument" # XL
FAIL_REGEX "Option .* is not recognized. Option will be ignored." # XL
FAIL_REGEX "not supported in this configuration. ignored" # AIX
FAIL_REGEX "File with unknown suffix passed to linker" # PGI
FAIL_REGEX "[Uu]nknown switch" # PGI
FAIL_REGEX "WARNING: unknown flag:" # Open64
FAIL_REGEX "Incorrect command line option:" # Borland
FAIL_REGEX "Warning: illegal option" # SunStudio 12
FAIL_REGEX "[Ww]arning: Invalid suboption" # Fujitsu
FAIL_REGEX "An invalid option .* appears on the command line" # Cray
)

include (CheckCXXSourceCompiles)

function(check_cxx_linker_flag _flag _var)
set (_source "int main() { return 0; }")
check_cxx_source_compiles("${_source}" _result ${check_cxx_linker_flag_patterns})
set(${_var} "${_result}" PARENT_SCOPE)
endfunction()
2 changes: 1 addition & 1 deletion fin
Submodule fin updated from a39808 to 0e5976
3 changes: 1 addition & 2 deletions src/anyramdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
#include <miopen/errors.hpp>
#include <miopen/logger.hpp>

#include <boost/filesystem/operations.hpp>
#include <boost/filesystem.hpp>
#include <miopen/filesystem.hpp>

#include <chrono>
#include <ctime>
Expand Down
54 changes: 26 additions & 28 deletions src/binary_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include <miopen/db.hpp>
#include <miopen/db_path.hpp>
#include <miopen/target_properties.hpp>
#include <boost/filesystem.hpp>
#include <miopen/filesystem.hpp>
#include <fstream>
#include <iostream>

Expand All @@ -49,20 +49,20 @@ MIOPEN_DECLARE_ENV_VAR_STR(MIOPEN_CUSTOM_CACHE_DIR)

namespace miopen {

static boost::filesystem::path ComputeSysCachePath()
static fs::path ComputeSysCachePath()
{
const std::string cache_dir = GetSystemDbPath();
auto p = miopen::ExpandUser(cache_dir);
if(!boost::filesystem::exists(p))
if(!fs::exists(p))
return {};
else
return p;
}

static boost::filesystem::path ComputeUserCachePath()
static fs::path ComputeUserCachePath()
{
#ifdef MIOPEN_CACHE_DIR
boost::filesystem::path p;
fs::path p;
/// If MIOPEN_CUSTOM_CACHE_DIR is set in the environment, then
/// use exactly that path.
const auto& custom = miopen::GetStringEnv(ENV(MIOPEN_CUSTOM_CACHE_DIR));
Expand All @@ -81,21 +81,21 @@ static boost::filesystem::path ComputeUserCachePath()
#if !MIOPEN_BUILD_DEV
/// \ref nfs-detection
if(IsNetworkedFilesystem(p))
p = boost::filesystem::temp_directory_path();
p = fs::temp_directory_path();
#endif
}
if(!boost::filesystem::exists(p) && !MIOPEN_DISABLE_USERDB)
boost::filesystem::create_directories(p);
if(!fs::exists(p) && !MIOPEN_DISABLE_USERDB)
fs::create_directories(p);
return p;
#else
return {};
#endif
}

boost::filesystem::path GetCachePath(bool is_system)
fs::path GetCachePath(bool is_system)
{
static const boost::filesystem::path user_path = ComputeUserCachePath();
static const boost::filesystem::path sys_path = ComputeSysCachePath();
static const fs::path user_path = ComputeUserCachePath();
static const fs::path sys_path = ComputeSysCachePath();
if(is_system)
{
if(MIOPEN_DISABLE_SYSDB)
Expand Down Expand Up @@ -130,23 +130,21 @@ KDb GetDb(const TargetProperties& target, size_t num_cu)
{
static const auto user_dir = ComputeUserCachePath();
static const auto sys_dir = ComputeSysCachePath();
boost::filesystem::path user_path =
user_dir / (Handle::GetDbBasename(target, num_cu) + ".ukdb");
boost::filesystem::path sys_path = sys_dir / (Handle::GetDbBasename(target, num_cu) + ".kdb");
fs::path user_path = user_dir / (Handle::GetDbBasename(target, num_cu) + ".ukdb");
fs::path sys_path = sys_dir / (Handle::GetDbBasename(target, num_cu) + ".kdb");
if(user_dir.empty())
user_path = user_dir;
if(!boost::filesystem::exists(sys_path))
if(!fs::exists(sys_path))
sys_path = sys_dir / (target.DbId() + ".kdb");
#if !MIOPEN_EMBED_DB
if(!boost::filesystem::exists(sys_path))
sys_path = boost::filesystem::path{};
if(!fs::exists(sys_path))
sys_path = fs::path{};
#endif
return {sys_path.string(), user_path.string()};
}
#endif

boost::filesystem::path
GetCacheFile(const std::string& device, const std::string& name, const std::string& args)
fs::path GetCacheFile(const std::string& device, const std::string& name, const std::string& args)
{
const std::string filename = name + ".o";
return GetCachePath(false) / miopen::md5(device + ":" + args) / filename;
Expand Down Expand Up @@ -198,17 +196,17 @@ void SaveBinary(const std::string& hsaco,
db.StoreRecord(cfg);
}
#else
boost::filesystem::path LoadBinary(const TargetProperties& target,
const size_t num_cu,
const std::string& name,
const std::string& args)
fs::path LoadBinary(const TargetProperties& target,
const size_t num_cu,
const std::string& name,
const std::string& args)
{
if(miopen::IsCacheDisabled())
return {};

(void)num_cu;
auto f = GetCacheFile(target.DbId(), name, args);
if(boost::filesystem::exists(f))
if(fs::exists(f))
{
return f.string();
}
Expand All @@ -218,20 +216,20 @@ boost::filesystem::path LoadBinary(const TargetProperties& target,
}
}

void SaveBinary(const boost::filesystem::path& binary_path,
void SaveBinary(const fs::path& binary_path,
const TargetProperties& target,
const std::string& name,
const std::string& args)
{
if(miopen::IsCacheDisabled())
{
boost::filesystem::remove(binary_path);
fs::remove(binary_path);
}
else
{
auto p = GetCacheFile(target.DbId(), name, args);
boost::filesystem::create_directories(p.parent_path());
boost::filesystem::rename(binary_path, p);
fs::create_directories(p.parent_path());
fs::rename(binary_path, p);
}
}
#endif
Expand Down
Loading