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

Use std::experimental::filesystem instead of std::filesystem #393

Merged
merged 5 commits into from
May 3, 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 CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ message("Building onnxruntime-genai for version ${VERSION_INFO}")
# Checking if CUDA is supported
include(CheckLanguage)
add_compile_definitions(BUILDING_ORT_GENAI_C)

if(USE_CUDA)
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
Expand Down
6 changes: 5 additions & 1 deletion cmake/cxx_standard.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ elseif (USE_CUDA AND CMAKE_CUDA_COMPILER AND CMAKE_CUDA_COMPILER_VERSION VERSION
else ()
message("Test is using C++20")
set(CMAKE_CXX_STANDARD 20)
endif ()
endif ()

if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 9)
add_compile_definitions(USE_EXPERIMENTAL_FILESYSTEM)
endif()
4 changes: 2 additions & 2 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ struct RootObject_Element : JSON::Element {
JSON::Element& t_;
};

void ParseConfig(const std::filesystem::path& filename, Config& config) {
void ParseConfig(const fs::path& filename, Config& config) {
std::ifstream file(filename, std::ios::binary | std::ios::ate);
if (!file.is_open()) {
throw std::runtime_error("Error opening " + filename.string());
Expand All @@ -421,7 +421,7 @@ void ParseConfig(const std::filesystem::path& filename, Config& config) {
}
}

Config::Config(const std::filesystem::path& path) : config_path{path} {
Config::Config(const fs::path& path) : config_path{path} {
ParseConfig(path / "genai_config.json", *this);

if (model.context_length == 0)
Expand Down
4 changes: 2 additions & 2 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace Generators {

struct Config {
Config() = default;
Config(const std::filesystem::path& path);
Config(const fs::path& path);

std::filesystem::path config_path; // Path of the config directory
fs::path config_path; // Path of the config directory

using ProviderOption = std::pair<std::string, std::string>;
struct ProviderOptions {
Expand Down
11 changes: 11 additions & 0 deletions src/filesystem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// TODO(baijumeswani): Remove experimental when packaging pipeline can use GCC > 8
#ifdef USE_EXPERIMENTAL_FILESYSTEM
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#else
#include <filesystem>
namespace fs = std::filesystem;
#endif
3 changes: 2 additions & 1 deletion src/generators.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
#include <assert.h>
#include <cmath>
#include <cstring>
#include <filesystem>
#include "filesystem.h"
#include <functional>
#include <iostream>
#include "span.h"
#include <memory>
#include <numeric>
Expand Down
2 changes: 1 addition & 1 deletion src/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void SetLogString(std::string_view name, std::string_view value) {
if (value.empty())
gp_logfile.reset();
else {
std::filesystem::path filename{value};
fs::path filename{std::string(value)};
gp_logfile = std::make_unique<std::ofstream>(filename);
}

Expand Down
2 changes: 1 addition & 1 deletion src/models/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void Model::CreateSessionOptions() {
}

if (options.enable_profiling.has_value()) {
std::filesystem::path profile_file_prefix{options.enable_profiling.value()};
fs::path profile_file_prefix{options.enable_profiling.value()};
ort_options.EnableProfiling(profile_file_prefix.c_str());
}

Expand Down
4 changes: 2 additions & 2 deletions src/tokenizer/c_api/tfmtok_c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

#include <cstdarg>
#include <filesystem>
#include "../filesystem.h"
#include <algorithm>

#include "tfmtok.h"
Expand Down Expand Up @@ -117,7 +117,7 @@ tfmError_t TFM_API_CALL TfmCreateTokenizer(TfmTokenizer** tokenizer,
return kTfmErrorInvalidArgument;
}

if (!std::filesystem::is_directory(tokenizer_path)) {
if (!fs::is_directory(tokenizer_path)) {
last_error_message = std::string("Cannot find the directory of ") + tokenizer_path;
return kTfmErrorInvalidArgument;
}
Expand Down
5 changes: 2 additions & 3 deletions src/tokenizer/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <string>
#include <fstream>
#include <streambuf>
#include <filesystem>
#include "../filesystem.h"

#include "config.h"

Expand Down Expand Up @@ -68,8 +68,7 @@ TfmStatus TokenConfig::LoadJson(const std::string& json_path) {
simdjson::dom::parser parser;
simdjson::dom::element root;

if (!std::filesystem::exists(
std::filesystem::path(json_path).lexically_normal())) {
if (!fs::exists(fs::path(json_path))) {
return {kTfmErrorInvalidFile, std::string(json_path) + " not found"};
}
std::string json_text = PatchJsonText(json_path);
Expand Down
4 changes: 2 additions & 2 deletions src/tokenizer/tokenizer.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "token_bpe.h"
#include "token_rwkv.h"

#include <filesystem>
#include "../filesystem.h"
#include <memory>

namespace tfm {
Expand Down Expand Up @@ -30,7 +30,7 @@ TfmStatus CreateBPETokenizer(const std::string& tokenizer_path,
if (type.empty()) {
if (BPETokenizer::IsSupportedModel(GetModelName(token_cfg->tokenizer_class_))) {
type = "BPE";
} /* else if (std::filesystem::exists(tokenizer_path + "/tokenizer.model")) {
} /* else if (fs::exists(tokenizer_path + "/tokenizer.model")) {
// if 'tokenizer.model exists in the tokenizer_path, then it is a sentencepiece model
type = "SPM";
} */ else {
Expand Down
Loading