Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/repo-refactor' into feat/repo-re…
Browse files Browse the repository at this point in the history
…factor-cpp17
  • Loading branch information
lockshaw committed Sep 1, 2023
2 parents f377089 + cee33f3 commit 868091c
Show file tree
Hide file tree
Showing 33 changed files with 262 additions and 139 deletions.
3 changes: 3 additions & 0 deletions cmake/flexflow-utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ function(ff_set_cxx_properties target)
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)
target_compile_options(${target}
PRIVATE $<$<COMPILE_LANGUAGE:CXX>:> # add C++ compile flags here
)
endfunction()

function(ff_add_library)
Expand Down
2 changes: 1 addition & 1 deletion cmake/nccl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ else()
BUILD_BYPRODUCTS ${CMAKE_BINARY_DIR}/deps/nccl/lib/libnccl${LIBEXT}
INSTALL_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND make src.build "${NCCL_BUILD_NVCC_GENCODE} --disable-warnings" "CUDA_HOME=${CUDA_TOOLKIT_ROOT_DIR}" "BUILDDIR=${CMAKE_BINARY_DIR}/deps/nccl" "CXX=${CMAKE_CXX_COMPILER}" CC="${CMAKE_CC_COMPILER}" "CXXFLAGS+=-w"
BUILD_COMMAND make src.build "${NCCL_BUILD_NVCC_GENCODE}" "CUDA_HOME=${CUDA_TOOLKIT_ROOT_DIR}" "BUILDDIR=${CMAKE_BINARY_DIR}/deps/nccl" "CXX=${CMAKE_CXX_COMPILER} -w" CC="${CMAKE_CC_COMPILER}"
BUILD_IN_SOURCE 1
)

Expand Down
2 changes: 1 addition & 1 deletion deps/fmt
Submodule fmt updated 70 files
+8 −0 .github/dependabot.yml
+3 −2 .github/pull_request_template.md
+30 −0 .github/workflows/cifuzz.yml
+9 −1 .github/workflows/doc.yml
+30 −13 .github/workflows/linux.yml
+17 −2 .github/workflows/macos.yml
+65 −0 .github/workflows/scorecard.yml
+12 −4 .github/workflows/windows.yml
+98 −41 CMakeLists.txt
+668 −1 ChangeLog.rst
+1 −1 LICENSE.rst
+42 −28 README.rst
+200 −145 doc/api.rst
+5 −6 doc/build.py
+134 −8 doc/syntax.rst
+1 −1 include/fmt/args.h
+466 −327 include/fmt/chrono.h
+18 −37 include/fmt/color.h
+27 −104 include/fmt/compile.h
+743 −1,144 include/fmt/core.h
+91 −152 include/fmt/format-inl.h
+1,081 −788 include/fmt/format.h
+44 −71 include/fmt/os.h
+22 −50 include/fmt/ostream.h
+201 −174 include/fmt/printf.h
+158 −145 include/fmt/ranges.h
+331 −37 include/fmt/std.h
+62 −33 include/fmt/xchar.h
+40 −29 src/fmt.cc
+1 −5 src/format.cc
+99 −62 src/os.cc
+3 −3 support/Vagrantfile
+0 −1 support/bazel/.bazelrc
+1 −1 support/bazel/.bazelversion
+2 −2 support/bazel/BUILD.bazel
+5 −4 support/bazel/README.md
+1 −1 support/build.gradle
+0 −54 support/cmake/cxx14.cmake
+7 −0 support/rst2md.py
+15 −3 test/CMakeLists.txt
+1 −1 test/add-subdirectory-test/CMakeLists.txt
+1 −1 test/args-test.cc
+386 −26 test/chrono-test.cc
+2 −2 test/compile-error-test/CMakeLists.txt
+1 −0 test/compile-fp-test.cc
+22 −40 test/compile-test.cc
+119 −239 test/core-test.cc
+2 −0 test/enforce-checks-test.cc
+1 −1 test/find-package-test/CMakeLists.txt
+27 −91 test/format-impl-test.cc
+285 −329 test/format-test.cc
+1 −1 test/fuzzing/CMakeLists.txt
+2 −0 test/gtest-extra-test.cc
+1 −6 test/gtest-extra.h
+1 −7 test/gtest/CMakeLists.txt
+1 −1 test/gtest/gmock-gtest-all.cc
+2 −2 test/mock-allocator.h
+36 −88 test/module-test.cc
+15 −56 test/os-test.cc
+16 −47 test/ostream-test.cc
+1 −7 test/posix-mock-test.cc
+0 −2 test/posix-mock.h
+13 −37 test/printf-test.cc
+138 −35 test/ranges-test.cc
+1 −1 test/scan-test.cc
+17 −14 test/scan.h
+1 −1 test/static-export-test/CMakeLists.txt
+198 −20 test/std-test.cc
+2 −6 test/util.h
+118 −55 test/xchar-test.cc
6 changes: 4 additions & 2 deletions lib/pcg/include/pcg/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ VISITABLE_STRUCT(::FlexFlow::Layer, attrs, name);
MAKE_VISIT_HASHABLE(::FlexFlow::Layer);

namespace FlexFlow {
static_assert(is_well_behaved_value_type<Layer>::value, "");
static_assert(is_fmtable<Layer>::value, "Layer must be fmtable");

FF_VISIT_FMTABLE(Layer);
CHECK_FMTABLE(Layer);

} // namespace FlexFlow

#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _FLEXFLOW_UTILS_INCLUDE_UTILS_CONTAINERS_H
#define _FLEXFLOW_UTILS_INCLUDE_UTILS_CONTAINERS_H
#ifndef _FLEXFLOW_UTILS_INCLUDE_UTILS_CONTAINERS_DECL_H
#define _FLEXFLOW_UTILS_INCLUDE_UTILS_CONTAINERS_DECL_H

#include "utils/bidict.h"
#include "utils/invoke.h"
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/include/utils/containers.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define _FLEXFLOW_UTILS_INCLUDE_UTILS_CONTAINERS_INL

#include "bidict.h"
#include "containers.decl"
#include "containers.decl.h"
#include "invoke.h"
#include "required_core.h"
#include "type_traits_core.h"
Expand Down
25 changes: 25 additions & 0 deletions lib/utils/include/utils/exception.decl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef _FLEXFLOW_UTILS_INCLUDE_EXCEPTION_DECL_H
#define _FLEXFLOW_UTILS_INCLUDE_EXCEPTION_DECL_H

#include "utils/fmt.decl.h"
#include <stdexcept>

namespace FlexFlow {

#ifdef FF_REQUIRE_IMPLEMENTED
#define NOT_IMPLEMENTED() static_assert(false, "Function not yet implemented");
#else
#define NOT_IMPLEMENTED() throw not_implemented();
#endif

class not_implemented : public std::logic_error {
public:
not_implemented();
};

template <typename... T>
std::runtime_error mk_runtime_error(fmt::format_string<T...> fmt_str,
T &&...args);
} // namespace FlexFlow

#endif
12 changes: 1 addition & 11 deletions lib/utils/include/utils/exception.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
#ifndef _FLEXFLOW_UTILS_INCLUDE_EXCEPTION_H
#define _FLEXFLOW_UTILS_INCLUDE_EXCEPTION_H

#include "utils/exception.decl.h"
#include "utils/fmt.h"
#include <stdexcept>

namespace FlexFlow {

#ifdef FF_REQUIRE_IMPLEMENTED
#define NOT_IMPLEMENTED() static_assert(false, "Function not yet implemented");
#else
#define NOT_IMPLEMENTED() throw not_implemented();
#endif

class not_implemented : public std::logic_error {
public:
not_implemented() : std::logic_error("Function not yet implemented"){};
};

template <typename... T>
std::runtime_error mk_runtime_error(fmt::format_string<T...> fmt_str,
T &&...args) {
Expand Down
41 changes: 41 additions & 0 deletions lib/utils/include/utils/fmt.decl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef _FLEXFLOW_UTILS_INCLUDE_UTILS_FMT_DECL_H
#define _FLEXFLOW_UTILS_INCLUDE_UTILS_FMT_DECL_H

#include "fmt/format.h"
#include <unordered_set>
#include <vector>

namespace FlexFlow {

template <typename T>
using is_fmtable = ::fmt::is_formattable<T>;

template <typename T, typename Enable = void>
struct already_has_ostream_operator;

template <typename T>
typename std::enable_if<!already_has_ostream_operator<T>::value,
std::ostream &>::type
operator<<(std::ostream &s, T const &t);

} // namespace FlexFlow

namespace fmt {

template <typename T>
struct formatter<::std::unordered_set<T>> : formatter<::std::string> {
template <typename FormatContext>
auto format(::std::unordered_set<T> const &m, FormatContext &ctx)
-> decltype(ctx.out());
};

template <typename T>
struct formatter<::std::vector<T>> : formatter<::std::string> {
template <typename FormatContext>
auto format(::std::vector<T> const &m, FormatContext &ctx)
-> decltype(ctx.out());
};

} // namespace fmt

#endif
59 changes: 35 additions & 24 deletions lib/utils/include/utils/fmt.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
#ifndef _FLEXFLOW_UTILS_INCLUDE_FMT_H
#define _FLEXFLOW_UTILS_INCLUDE_FMT_H

#include "fmt/core.h"
#include "fmt/format.h"
#include "utils/containers.decl"
#include "utils/containers.decl.h"
#include "utils/fmt.decl.h"
#include "utils/test_types.h"
#include "utils/type_traits_core.h"
#include <unordered_set>

namespace FlexFlow {

template <typename T, typename Enable = void>
struct is_fmtable : std::false_type {};

template <typename T>
struct is_fmtable<T, void_t<decltype(fmt::format("{}", std::declval<T>()))>>
: std::true_type {};

template <typename T, typename = void>
template <typename T, typename Enable>
struct already_has_ostream_operator : std::false_type {};

template <>
Expand All @@ -43,12 +35,18 @@ operator<<(std::ostream &s, T const &t) {
}
*/

#define CHECK_FMTABLE(...) \
static_assert(::FlexFlow::is_fmtable<__VA_ARGS__>::value, \
#__VA_ARGS__ " must be fmtable");

// This will not
template <typename T>
typename std::enable_if<!already_has_ostream_operator<T>::value,
std::ostream &>::type
operator<<(std::ostream &s, T const &t) {
std::string result = fmt::format("{}", t);
CHECK_FMTABLE(T);

std::string result = fmt::to_string(t);
return s << result;
}

Expand All @@ -63,17 +61,30 @@ typename std::enable_if<!already_has_ostream_operator<T>::value,
namespace fmt {

template <typename T>
struct formatter<::std::unordered_set<T>> : formatter<::std::string> {
template <typename FormatContext>
auto format(::std::unordered_set<T> const &m, FormatContext &ctx)
-> decltype(ctx.out()) {
std::string result =
join_strings(m.cbegin(), m.cend(), ", ", [](T const &t) {
return fmt::to_string(t);
});
return formatter<std::string>::format(result, ctx);
}
};
template <typename FormatContext>
auto formatter<::std::unordered_set<T>>::format(
::std::unordered_set<T> const &m, FormatContext &ctx)
-> decltype(ctx.out()) {
CHECK_FMTABLE(T);

std::string result = join_strings(
m.cbegin(), m.cend(), ", ", [](T const &t) { return fmt::to_string(t); });
return formatter<std::string>::format(result, ctx);
}

template <typename T>
template <typename FormatContext>
auto formatter<::std::vector<T>>::format(::std::vector<T> const &m,
FormatContext &ctx)
-> decltype(ctx.out()) {
CHECK_FMTABLE(T);
std::string result = join_strings(
m.cbegin(), m.cend(), ", ", [](T const &t) { return fmt::to_string(t); });
return formatter<std::string>::format(result, ctx);
}

CHECK_FMTABLE(std::vector<int>);
CHECK_FMTABLE(std::unordered_set<int>);

} // namespace fmt

Expand Down
6 changes: 2 additions & 4 deletions lib/utils/include/utils/graph/cow_ptr_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ namespace FlexFlow {

template <typename T>
struct cow_ptr_t {
// static_assert(is_clonable<T>::value,
// "cow_ptr_t requires the type to have a clone() method"); //
// TODO:
// https://github.com/flexflow/FlexFlow/issues/909#issue-1833470024
static_assert(is_clonable<T>::value,
"cow_ptr_t requires the type to have a clone() method");

cow_ptr_t(std::shared_ptr<T> const &ptr) : ptr(ptr) {}
cow_ptr_t(std::shared_ptr<T> &&ptr) : ptr(std::move(ptr)) {}
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/include/utils/graph/digraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct DiGraphView {
unsafe_create_without_ownership(IDiGraphView const &graphView);

private:
DiGraphView(std::shared_ptr<IDiGraphView const> ptr) : ptr(ptr) {}
DiGraphView(std::shared_ptr<IDiGraphView const> ptr);

friend struct GraphInternal;

Expand Down
2 changes: 1 addition & 1 deletion lib/utils/include/utils/graph/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "utils/graph/digraph.h"
#include "utils/graph/digraph_interfaces.h"
#include "utils/graph/labelled/labelled_open.decl"
#include "utils/graph/labelled/labelled_open.decl.h"
#include "utils/graph/labelled/labelled_open_interfaces.h"
#include "utils/graph/multidigraph.h"
#include "utils/graph/multidigraph_interfaces.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _FLEXFLOW_UTILS_INCLUDE_UTILS_GRAPH_LABELLED_LABELLED_OPEN_DECL
#define _FLEXFLOW_UTILS_INCLUDE_UTILS_GRAPH_LABELLED_LABELLED_OPEN_DECL
#ifndef _FLEXFLOW_UTILS_INCLUDE_UTILS_GRAPH_LABELLED_LABELLED_OPEN_DECL_H
#define _FLEXFLOW_UTILS_INCLUDE_UTILS_GRAPH_LABELLED_LABELLED_OPEN_DECL_H

#include "labelled_open_interfaces.h"
#include "node_labelled.h"
Expand Down Expand Up @@ -63,7 +63,11 @@ struct LabelledOpenMultiDiGraph {
operator OpenMultiDiGraphView() const;

friend void swap(LabelledOpenMultiDiGraph &lhs,
LabelledOpenMultiDiGraph &rhs);
LabelledOpenMultiDiGraph &rhs) {
using std::swap;

swap(lhs.ptr, rhs.ptr);
}

Node add_node(NodeLabel const &l);
NodeLabel &at(Node const &n);
Expand Down
10 changes: 1 addition & 9 deletions lib/utils/include/utils/graph/labelled/labelled_open.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _FLEXFLOW_UTILS_INCLUDE_UTILS_GRAPH_LABELLED_LABELLED_OPEN_H
#define _FLEXFLOW_UTILS_INCLUDE_UTILS_GRAPH_LABELLED_LABELLED_OPEN_H

#include "labelled_open.decl"
#include "labelled_open.decl.h"
#include "labelled_open_interfaces.h"
#include "node_labelled.h"
#include "utils/graph/internal.h"
Expand Down Expand Up @@ -69,14 +69,6 @@ LabelledOpenMultiDiGraph<N, E, I, O>::operator OpenMultiDiGraphView() const {
return GraphInternal::create_open_multidigraph_view(this->ptr);
}

template <typename N, typename E, typename I, typename O>
void swap(LabelledOpenMultiDiGraph<N, E, I, O> &lhs,
LabelledOpenMultiDiGraph<N, E, I, O> &rhs) {
using std::swap;

swap(lhs.ptr, rhs.ptr);
}

template <typename NodeLabel, typename E, typename I, typename O>
Node LabelledOpenMultiDiGraph<NodeLabel, E, I, O>::add_node(
NodeLabel const &l) {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/include/utils/graph/multidigraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct MultiDiGraphView {
unsafe_create_without_ownership(IMultiDiGraphView const &);

private:
MultiDiGraphView(std::shared_ptr<IMultiDiGraphView const> ptr) : ptr(ptr) {}
MultiDiGraphView(std::shared_ptr<IMultiDiGraphView const> ptr);

friend struct GraphInternal;

Expand Down
2 changes: 1 addition & 1 deletion lib/utils/include/utils/graph/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct GraphView {
}

private:
GraphView(std::shared_ptr<IGraphView const> ptr) : ptr(ptr) {}
GraphView(std::shared_ptr<IGraphView const> ptr);

friend struct GraphInternal;

Expand Down
3 changes: 1 addition & 2 deletions lib/utils/include/utils/graph/open_graphs.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ struct OpenMultiDiGraphView {
}

private:
OpenMultiDiGraphView(std::shared_ptr<IOpenMultiDiGraphView const> ptr)
: ptr(ptr) {}
OpenMultiDiGraphView(std::shared_ptr<IOpenMultiDiGraphView const> ptr);

friend struct GraphInternal;

Expand Down
4 changes: 2 additions & 2 deletions lib/utils/include/utils/graph/query_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define _FLEXFLOW_UTILS_INCLUDE_UTILS_GRAPH_QUERY_SET_H

#include "utils/bidict.h"
#include "utils/containers.decl"
#include "utils/containers.decl.h"
#include "utils/exception.h"
#include "utils/optional.h"
#include <unordered_set>
Expand All @@ -12,7 +12,7 @@ namespace FlexFlow {
template <typename T>
struct query_set {
query_set() = delete;
query_set(T const &query) : query({query}) {}
query_set(T const &t) : query(std::unordered_set<T>{t}) {}

query_set(std::unordered_set<T> const &query) : query(query) {}

Expand Down
3 changes: 1 addition & 2 deletions lib/utils/include/utils/graph/undirected.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ struct UndirectedGraphView {
unsafe_create_without_ownership(IUndirectedGraphView const &);

private:
UndirectedGraphView(std::shared_ptr<IUndirectedGraphView const> ptr)
: ptr(ptr) {}
UndirectedGraphView(std::shared_ptr<IUndirectedGraphView const> ptr);

friend struct GraphInternal;

Expand Down
Loading

0 comments on commit 868091c

Please sign in to comment.