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

Add logging to libcudf #12637

Merged
merged 56 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
60f6157
remove unused function
vuule Jan 28, 2023
a888ac8
logger
vuule Jan 28, 2023
5108371
log env var reads
vuule Jan 28, 2023
b2cc531
remove repeated env var reads of PREFER_PAGEABLE_TMP_MEMORY
vuule Jan 28, 2023
d7ecd33
copyright year
vuule Jan 28, 2023
830ab00
docs
vuule Jan 28, 2023
a4c51c0
yaml
vuule Jan 28, 2023
d029e1e
Merge branch 'branch-23.04' of https://github.com/rapidsai/cudf into …
vuule Jan 30, 2023
3d7c2ca
move impl to cpp
vuule Jan 31, 2023
cbda9d0
Merge branch 'branch-23.04' of https://github.com/rapidsai/cudf into …
vuule Jan 31, 2023
87c5d3a
Merge branch 'branch-23.04' of https://github.com/rapidsai/cudf into …
vuule Feb 2, 2023
0df8e97
anon namespace
vuule Feb 2, 2023
92f53f9
Merge branch 'branch-23.04' of https://github.com/rapidsai/cudf into …
vuule Feb 3, 2023
36004e5
tests mostly
vuule Feb 3, 2023
0a90a8f
style
vuule Feb 3, 2023
0e95828
Merge branch 'branch-23.04' of https://github.com/rapidsai/cudf into …
vuule Feb 6, 2023
498ac21
use macro
vuule Feb 6, 2023
f0ae3e2
fixture
vuule Feb 7, 2023
680f425
Merge branch 'branch-23.04' of https://github.com/rapidsai/cudf into …
vuule Feb 9, 2023
6ab194c
separate public logger API from logging macros
vuule Feb 9, 2023
404fa1d
Merge branch 'branch-23.04' into fea-logger
vuule Feb 9, 2023
bc12b13
guide start
vuule Feb 9, 2023
38da9b5
Merge branch 'fea-logger' of https://github.com/vuule/cudf into fea-l…
vuule Feb 9, 2023
c736164
header docs
vuule Feb 10, 2023
b0ec318
Merge branch 'branch-23.04' of https://github.com/rapidsai/cudf into …
vuule Feb 11, 2023
bae202c
Merge branch 'branch-23.04' of https://github.com/rapidsai/cudf into …
vuule Feb 13, 2023
df803a4
dev guide
vuule Feb 14, 2023
d6b8145
clean up
vuule Feb 14, 2023
e813cb9
build changes
vuule Feb 14, 2023
b1f0994
style
vuule Feb 14, 2023
c1ceb73
Merge branch 'branch-23.04' of https://github.com/rapidsai/cudf into …
vuule Feb 15, 2023
30fcd28
Apply suggestions from code review
vuule Feb 15, 2023
af09276
Merge branch 'fea-logger' of https://github.com/vuule/cudf into fea-l…
vuule Feb 15, 2023
588d6f5
remove GCC workaround
vuule Feb 15, 2023
0c24717
fix string constant
vuule Feb 15, 2023
5f090e2
Merge branch 'branch-23.04' of https://github.com/rapidsai/cudf into …
vuule Feb 18, 2023
6fea0bf
update default level, sink
vuule Feb 18, 2023
c77426d
Merge branch 'branch-23.04' of https://github.com/rapidsai/cudf into …
vuule Feb 27, 2023
5581c8a
switch to stderr
vuule Feb 27, 2023
6378bf7
missing doc
vuule Feb 27, 2023
553a57b
docs improvement
vuule Feb 27, 2023
49f3896
remove outdated docs
vuule Feb 27, 2023
0b6b27c
update dev guide
vuule Feb 28, 2023
a540928
small fixes
vuule Feb 28, 2023
dcd3b29
style
vuule Feb 28, 2023
e49f007
Merge branch 'branch-23.04' into fea-logger
vuule Feb 28, 2023
fd2636f
Merge branch 'branch-23.04' of https://github.com/rapidsai/cudf into …
vuule Mar 6, 2023
c75ff33
cmake changes
vuule Mar 6, 2023
a8c3e11
conda changes
vuule Mar 6, 2023
57f6d05
Merge branch 'fea-logger' of https://github.com/vuule/cudf into fea-l…
vuule Mar 6, 2023
eb045f7
style
vuule Mar 6, 2023
2280ecf
doc improvement
vuule Mar 10, 2023
e7fe0cd
docs that killed timezone refactor
vuule Mar 10, 2023
06893a3
Merge branch 'branch-23.04' into fea-logger
vuule Mar 10, 2023
1d1950c
Update cpp/CMakeLists.txt
vuule Mar 10, 2023
855fcc0
Merge branch 'branch-23.04' into fea-logger
vuule Mar 10, 2023
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 conda/recipes/libcudf/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ outputs:
- test -f $PREFIX/include/cudf/utilities/bit.hpp
- test -f $PREFIX/include/cudf/utilities/default_stream.hpp
- test -f $PREFIX/include/cudf/utilities/error.hpp
- test -f $PREFIX/include/cudf/utilities/logger.hpp
- test -f $PREFIX/include/cudf/utilities/span.hpp
- test -f $PREFIX/include/cudf/utilities/traits.hpp
- test -f $PREFIX/include/cudf/utilities/type_checks.hpp
Expand Down
115 changes: 115 additions & 0 deletions cpp/include/cudf/utilities/logger.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Copyright (c) 2023, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

// If using GCC, temporary workaround for older libcudacxx defining _LIBCPP_VERSION
// undefine it before including spdlog, due to fmtlib checking if it is defined
// TODO: remove once libcudacxx is on Github and RAPIDS depends on it
vuule marked this conversation as resolved.
Show resolved Hide resolved
#ifdef __GNUG__
#undef _LIBCPP_VERSION
#endif
#include <spdlog/sinks/basic_file_sink.h>
#include <spdlog/spdlog.h>
vuule marked this conversation as resolved.
Show resolved Hide resolved

#include <iostream>
#include <string>

namespace cudf {

namespace detail {

/**
* @brief Returns the default log filename for the global logger.
*
* If the environment variable `CUDF_DEBUG_LOG_FILE` is defined, its value is used as the path and
* name of the log file. Otherwise, the file `cudf_log.txt` in the current working directory is
* used.
*
* @return std::string The default log file name.
*/
inline std::string default_log_filename()
{
auto* filename = std::getenv("LIBCUDF_DEBUG_LOG_FILE");
return (filename == nullptr) ? std::string{"cudf_log.txt"} : std::string{filename};
}

/**
* @brief Simple wrapper around a spdlog::logger that performs cuDF-specific initialization.
*/
struct logger_wrapper {
spdlog::logger logger_; ///< wrapped `spdlog` logger

/**
* @brief Converts the level name into the `spdlog` level enum.
*
* @param str logging level name
* @return corresponding`spdlog` level enum; info if input string is invalid
*/
spdlog::level::level_enum spdlog_level_from_string(std::string_view str)
{
if (str == "TRACE") return spdlog::level::trace;
if (str == "DEBUG") return spdlog::level::debug;
if (str == "INFO") return spdlog::level::info;
if (str == "WARN") return spdlog::level::warn;
if (str == "ERR") return spdlog::level::err;
if (str == "CRITICAL") return spdlog::level::critical;
if (str == "OFF") return spdlog::level::off;

// keep the default if the env var is invalid
return spdlog::level::info;
}

logger_wrapper()
: logger_{"CUDF",
std::make_shared<spdlog::sinks::basic_file_sink_mt>(
default_log_filename(), true // truncate file
)}
{
logger_.set_pattern("[%6t][%H:%M:%S:%f][%-6l] %v");
logger_.flush_on(spdlog::level::warn);

auto const env_level = std::getenv("LIBCUDF_LOGGING_LEVEL");
if (env_level != nullptr) { logger_.set_level(spdlog_level_from_string(env_level)); }
}
};

} // namespace detail

/**
* @brief Returns the global logger
*
* This is a spdlog logger. The easiest way to log messages is to use the `CUDF_LOG_*` macros.
*
* @return spdlog::logger& The logger.
*/
inline spdlog::logger& logger()
{
static detail::logger_wrapper wrapped{};
return wrapped.logger_;
}

// The default is INFO, but it should be used sparingly, so that by default a log file is only
// output if there is important information, warnings, errors, and critical failures
// Log messages that require computation should only be used at level TRACE and DEBUG
#define CUDF_LOG_TRACE(...) SPDLOG_LOGGER_TRACE(&cudf::logger(), __VA_ARGS__)
#define CUDF_LOG_DEBUG(...) SPDLOG_LOGGER_DEBUG(&cudf::logger(), __VA_ARGS__)
#define CUDF_LOG_INFO(...) SPDLOG_LOGGER_INFO(&cudf::logger(), __VA_ARGS__)
#define CUDF_LOG_WARN(...) SPDLOG_LOGGER_WARN(&cudf::logger(), __VA_ARGS__)
#define CUDF_LOG_ERROR(...) SPDLOG_LOGGER_ERROR(&cudf::logger(), __VA_ARGS__)
#define CUDF_LOG_CRITICAL(...) SPDLOG_LOGGER_CRITICAL(&cudf::logger(), __VA_ARGS__)

} // namespace cudf
6 changes: 0 additions & 6 deletions cpp/src/io/utilities/config_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@

namespace cudf::io::detail {

std::string getenv_or(std::string const& env_var_name, std::string_view default_val)
{
auto const env_val = std::getenv(env_var_name.c_str());
return std::string{(env_val == nullptr) ? default_val : env_val};
}

namespace cufile_integration {

namespace {
Expand Down
11 changes: 10 additions & 1 deletion cpp/src/io/utilities/config_utils.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022, NVIDIA CORPORATION.
* Copyright (c) 2021-2023, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,8 @@
*/
#pragma once

#include <cudf/utilities/logger.hpp>

#include <sstream>
#include <string>

Expand All @@ -28,6 +30,13 @@ template <typename T>
T getenv_or(std::string_view env_var_name, T default_val)
{
auto const env_val = std::getenv(env_var_name.data());
if (env_val != nullptr) {
logger().debug("Environment variable {} read as {}", env_var_name, env_val);
} else {
logger().debug(
"Environment variable {} is not set, using default value {}", env_var_name, default_val);
}

if (env_val == nullptr) { return default_val; }

std::stringstream sstream(env_val);
Expand Down
11 changes: 8 additions & 3 deletions cpp/src/io/utilities/hostdevice_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@

#include <variant>

inline bool hostdevice_vector_uses_pageable_buffer()
vyasr marked this conversation as resolved.
Show resolved Hide resolved
{
static bool const use_pageable =
cudf::io::detail::getenv_or("LIBCUDF_IO_PREFER_PAGEABLE_TMP_MEMORY", 0);
return use_pageable;
}

/**
* @brief A helper class that wraps fixed-length device memory for the GPU, and
* a mirror host pinned memory for the CPU.
Expand All @@ -56,9 +63,7 @@ class hostdevice_vector {
{
CUDF_EXPECTS(initial_size <= max_size, "initial_size cannot be larger than max_size");

auto const use_pageable_buffer =
cudf::io::detail::getenv_or("LIBCUDF_IO_PREFER_PAGEABLE_TMP_MEMORY", 0);
if (use_pageable_buffer) {
if (hostdevice_vector_uses_pageable_buffer()) {
h_data_owner = thrust::host_vector<T>();
} else {
h_data_owner = thrust::host_vector<T, cudf::detail::pinned_allocator<T>>();
Expand Down