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

replace boost::filesystem with std::filesystem #96

Merged
merged 2 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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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()
9 changes: 9 additions & 0 deletions cmake/googletest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ if(rocblas_FOUND)
target_link_libraries( fin $<BUILD_INTERFACE:roc::rocblas> )
# 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")
Expand Down
5 changes: 4 additions & 1 deletion src/include/bn_fin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "tensor.hpp"

#include <miopen/execution_context.hpp>
#include <miopen/filesystem.hpp>
#include <miopen/miopen.h>
#include <miopen/batchnorm/problem_description.hpp>
#include <miopen/batch_norm.hpp>
Expand All @@ -45,6 +46,8 @@

#define EPSILON 1e-3

namespace fs = miopen::fs;

namespace fin {

using json = nlohmann::json;
Expand Down Expand Up @@ -425,7 +428,7 @@ int BNFin<Tgpu, Tref>::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();
Expand Down
25 changes: 11 additions & 14 deletions src/include/conv_fin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@
#include <miopen/perf_field.hpp>
#include <miopen/solver_id.hpp>
#include <miopen/version.h>
#include <miopen/filesystem.hpp>

#if MIOPEN_MODE_NOGPU
#include <miopen/kernel_cache.hpp>
#include <miopen/nogpu/handle_impl.hpp>
#endif

#include <boost/range/adaptor/sliced.hpp>
#include <boost/filesystem.hpp>
namespace fs = miopen::fs;

#include <algorithm>
#include <cstdlib>
Expand Down Expand Up @@ -236,7 +237,7 @@ int ConvFin<Tgpu, Tref>::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();
Expand Down Expand Up @@ -373,7 +374,7 @@ int ConvFin<Tgpu, Tref>::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();
Expand Down Expand Up @@ -488,8 +489,8 @@ int ConvFin<Tgpu, Tref>::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)
{
Expand Down Expand Up @@ -772,9 +773,9 @@ int ConvFin<Tgpu, Tref>::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();
Expand Down Expand Up @@ -1270,7 +1271,6 @@ int ConvFin<Tgpu, Tref>::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();

Expand Down Expand Up @@ -1480,19 +1480,16 @@ int ConvFin<Tgpu, Tref>::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;

Expand Down
6 changes: 3 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<BUILD_INTERFACE:roc::rocblas>)
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)
Expand Down