From 0e597645a57df36993baf8f21d0a57e7293ae1c6 Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Tue, 23 Jan 2024 20:02:16 -0500 Subject: [PATCH] replace boost::filesystem with std::filesystem (#96) --- CMakeLists.txt | 3 ++ cmake/CheckCXXLinkerFlag.cmake | 60 ++++++++++++++++++++++++++++++++++ cmake/googletest.cmake | 9 +++++ src/CMakeLists.txt | 3 ++ src/include/bn_fin.hpp | 5 ++- src/include/conv_fin.hpp | 25 +++++++------- src/main.cpp | 6 ++-- tests/CMakeLists.txt | 3 ++ 8 files changed, 96 insertions(+), 18 deletions(-) create mode 100644 cmake/CheckCXXLinkerFlag.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 5daef852..3cda1f58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,6 +65,9 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") endif() endif() +include(CheckCXXLinkerFlag) +check_cxx_linker_flag(stdc++fs HAS_LIB_STD_FILESYSTEM) + ############################################################ # require C++17 add_compile_options(-std=c++17) diff --git a/cmake/CheckCXXLinkerFlag.cmake b/cmake/CheckCXXLinkerFlag.cmake new file mode 100644 index 00000000..7d9e8242 --- /dev/null +++ b/cmake/CheckCXXLinkerFlag.cmake @@ -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() diff --git a/cmake/googletest.cmake b/cmake/googletest.cmake index 2a943f8d..f72eab52 100644 --- a/cmake/googletest.cmake +++ b/cmake/googletest.cmake @@ -31,9 +31,18 @@ FetchContent_Declare( GIT_TAG f8d7d77c06936315286eb55f8de22cd23c188571 ) +# Suppress ROCMChecks WARNING on GoogleTests +macro(rocm_check_toolchain_var var access value list_file) + if(NOT ROCM_DISABLE_CHECKS) + _rocm_check_toolchain_var("${var}" "${access}" "${value}" "${list_file}") + endif() +endmacro() + # Will be necessary for windows build # set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +set(ROCM_DISABLE_CHECKS TRUE) FetchContent_MakeAvailable(googletest) +set(ROCM_DISABLE_CHECKS FALSE) target_compile_options(gtest PRIVATE ${GTEST_CMAKE_CXX_FLAGS}) target_compile_options(gtest_main PRIVATE ${GTEST_CMAKE_CXX_FLAGS}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f21c8e33..1e18d39e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -37,6 +37,9 @@ if(rocblas_FOUND) target_link_libraries( fin $ ) # target_link_libraries( fin PRIVATE roc::rocblas ) endif() +if(HAS_LIB_STD_FILESYSTEM) + target_link_libraries(fin stdc++fs) +endif() # Cmake does not add flags correctly for gcc if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") diff --git a/src/include/bn_fin.hpp b/src/include/bn_fin.hpp index 46fb286d..264515c0 100644 --- a/src/include/bn_fin.hpp +++ b/src/include/bn_fin.hpp @@ -32,6 +32,7 @@ #include "tensor.hpp" #include +#include #include #include #include @@ -45,6 +46,8 @@ #define EPSILON 1e-3 +namespace fs = miopen::fs; + namespace fin { using json = nlohmann::json; @@ -425,7 +428,7 @@ int BNFin::MIOpenFindCompile() for(const auto& sln : GetBNSolutions(ctx)) { // remove the user db files - boost::filesystem::remove_all(miopen::GetCachePath(false)); + fs::remove_all(miopen::GetCachePath(false)); json res_item; res_item["solver_name"] = sln.solver_id; res_item["algorithm"] = GetAlgorithm(); diff --git a/src/include/conv_fin.hpp b/src/include/conv_fin.hpp index 8ccda8a2..98d0fdda 100644 --- a/src/include/conv_fin.hpp +++ b/src/include/conv_fin.hpp @@ -47,6 +47,7 @@ #include #include #include +#include #if MIOPEN_MODE_NOGPU #include @@ -54,7 +55,7 @@ #endif #include -#include +namespace fs = miopen::fs; #include #include @@ -236,7 +237,7 @@ int ConvFin::MIOpenPerfCompile() { json res_item; // remove the user db files - boost::filesystem::remove_all(miopen::GetCachePath(false)); + fs::remove_all(miopen::GetCachePath(false)); auto process_solver = [&]() -> bool { std::cerr << "Processing Solver: " << solver_id.ToString() << std::endl; const auto& s = solver_id.GetSolver(); @@ -373,7 +374,7 @@ int ConvFin::MIOpenFindCompile() { json res_item; // remove the user db files - boost::filesystem::remove_all(miopen::GetCachePath(false)); + fs::remove_all(miopen::GetCachePath(false)); auto process_solver = [&]() -> bool { std::cerr << "Processing Solver: " << solver_id.ToString() << std::endl; const auto& s = solver_id.GetSolver(); @@ -488,8 +489,8 @@ int ConvFin::MIOpenPerfEval() { // Somehow the direction changes mid loop ! json res_item; - boost::system::error_code ec; - boost::filesystem::remove_all(miopen::GetCachePath(false), ec); + std::error_code ec; + fs::remove_all(miopen::GetCachePath(false), ec); // boost::filesystem::remove_all(miopen::GetCachePath(true), ec); if(ec) { @@ -772,9 +773,9 @@ int ConvFin::MIOpenFindEval() { // Somehow the direction changes mid loop ! json res_item; - boost::system::error_code ec; - boost::filesystem::remove_all(miopen::GetCachePath(false), ec); - // boost::filesystem::remove_all(miopen::GetCachePath(true), ec); + std::error_code ec; + fs::remove_all(miopen::GetCachePath(false), ec); + // fs::remove_all(miopen::GetCachePath(true), ec); if(ec) { std::cerr << "Error while removing MIOpen cache: " << ec.message(); @@ -1270,7 +1271,6 @@ int ConvFin::TestPerfDbValid() #endif bool ret = true; - namespace fs = boost::filesystem; bool spec_arch = (job["arch"].size() > 0 and job["num_cu"].size() > 0); std::string db_path = miopen::GetSystemDbPath(); @@ -1480,19 +1480,16 @@ int ConvFin::SearchPreCompiledKernels() const size_t num_cu = handle.GetMaxComputeUnits(); const std::string arch = tgt_props.Name(); - namespace fs = boost::filesystem; - // to fetch the kdb folder location // ex: /opt/rocm/miopen/share/miopen/db auto pathstr = miopen::GetCachePath(true); // append the json input arch and numcu values to file - boost::filesystem::path sys_path = - pathstr / (miopen::Handle::GetDbBasename(tgt_props, num_cu) + ".kdb"); + fs::path sys_path = pathstr / (miopen::Handle::GetDbBasename(tgt_props, num_cu) + ".kdb"); std::cout << "System KernDB path = " << sys_path << std::endl; // checks the file present in shared folder - if(boost::filesystem::exists(sys_path)) + if(fs::exists(sys_path)) { std::cout << "KernDB file Present = " << sys_path << std::endl; diff --git a/src/main.cpp b/src/main.cpp index a46fd319..fa1d4302 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -85,7 +85,7 @@ int main(int argc, char* argv[], char* envp[]) { if(args[i] == "-i") { - if(!boost::filesystem::exists(args[i + 1])) + if(!fs::exists(args[i + 1])) { std::cerr << "File: " << args[i + 1] << " does not exist" << std::endl; exit(-1); @@ -98,8 +98,8 @@ int main(int argc, char* argv[], char* envp[]) } } - boost::filesystem::path input_filename(MapInputs['i']); - boost::filesystem::path output_filename(MapInputs['o']); + fs::path input_filename(MapInputs['i']); + fs::path output_filename(MapInputs['o']); // The JSON is a list of commands, so we iterate over the list and then // process each map diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index df6910a8..d6a2916f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -16,6 +16,9 @@ function(add_gtest TEST_NAME) target_compile_definitions(test_${TEST_NAME} PUBLIC TEST_RESOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}/") target_link_libraries(test_${TEST_NAME} gtest_main MIOpen ${Boost_LIBRARIES} hip::host $) gtest_discover_tests(test_${TEST_NAME}) + if(HAS_LIB_STD_FILESYSTEM) + target_link_libraries(test_${TEST_NAME} stdc++fs) + endif() endfunction() file(GLOB TESTS *.cpp)