From 0f336f54a190265d6ed95ebabefe1e74faaefe56 Mon Sep 17 00:00:00 2001 From: Colin Unger Date: Wed, 13 Mar 2024 23:26:32 -0700 Subject: [PATCH 01/14] Remove unnecessary dependencies and allow using external installs --- .gitmodules | 18 -- CMakeLists.txt | 7 +- cmake/fmt.cmake | 8 +- cmake/json.cmake | 12 +- cmake/nccl.cmake | 230 +++++++++--------- cmake/spdlog.cmake | 8 +- deps/any | 1 - deps/googletest | 1 - deps/invoke | 1 - deps/optional | 1 - deps/pybind11 | 1 - deps/variant | 1 - lib/kernels/CMakeLists.txt | 12 +- lib/kernels/include/kernels/array_shape.h | 7 +- lib/kernels/include/kernels/device.h | 1 + lib/kernels/src/cuda/batch_norm_kernels.cu | 30 +-- lib/kernels/src/cuda/cast_kernels.cu | 6 +- lib/kernels/src/device.h | 1 + lib/op-attrs/include/op-attrs/datatype.h | 4 +- lib/op-attrs/include/op-attrs/get_op_type.h | 2 +- .../include/op-attrs/get_output_shapes.h | 8 +- .../include/op-attrs/operator_attrs.h | 6 +- lib/op-attrs/include/op-attrs/ops/conv_2d.h | 4 +- lib/op-attrs/include/op-attrs/ops/linear.h | 12 +- .../include/op-attrs/ops/loss_functions.h | 4 +- lib/op-attrs/src/operator_attrs.cc | 4 +- .../src/parallel_dim_mapping_record.cc | 4 +- .../src/parallel_dim_mapping_record.h | 7 +- .../src/parallel_dim_mapping_record_solver.cc | 8 +- .../src/parallel_dim_mapping_record_solver.h | 8 +- .../include/pcg/computation_graph_builder.h | 122 +++++----- lib/pcg/include/pcg/device_id.h | 3 +- .../include/pcg/file_format/v1/data_type.h | 3 +- lib/pcg/include/pcg/file_format/v1/graphs.h | 2 +- .../include/pcg/file_format/v1/initializer.h | 10 +- .../pcg/file_format/v1/operator_attrs.h | 6 +- .../pcg/file_format/v1/parallel_tensor.h | 10 +- lib/pcg/include/pcg/file_format/v1/tensor.h | 10 +- lib/pcg/include/pcg/initializer.h | 10 +- lib/pcg/include/pcg/layer.h | 6 +- lib/pcg/include/pcg/operator.h | 2 +- lib/pcg/include/pcg/parallel_tensor.h | 12 +- lib/pcg/include/pcg/tensor.h | 6 +- lib/pcg/src/computation_graph_builder.cc | 84 +++---- lib/pcg/src/device_id.cc | 5 +- lib/pcg/src/layer.cc | 2 +- lib/pcg/src/operator.cc | 2 +- lib/pcg/src/parallel_tensor.cc | 4 +- lib/runtime/src/serialization.h | 8 +- lib/substitutions/src/substitution.cc | 2 +- lib/utils/CMakeLists.txt | 4 - lib/utils/include/utils/containers.decl.h | 23 +- lib/utils/include/utils/containers.h | 26 +- lib/utils/include/utils/disjoint_set.h | 32 +-- lib/utils/include/utils/dot_file.h | 13 +- lib/utils/include/utils/fmt.h | 18 +- lib/utils/include/utils/graph/algorithms.h | 26 +- .../graph/labelled/output_labelled_open.h | 4 +- lib/utils/include/utils/graph/open_edge.h | 6 +- lib/utils/include/utils/graph/query_set.h | 8 +- .../include/utils/graph/serialparallel.h | 10 +- lib/utils/include/utils/graph/traversal.h | 4 +- lib/utils/include/utils/graph/views.h | 5 +- lib/utils/include/utils/invoke.h | 12 - lib/utils/include/utils/json.h | 26 +- lib/utils/include/utils/optional.decl | 8 +- lib/utils/include/utils/optional.h | 8 +- lib/utils/include/utils/sequence.h | 4 +- lib/utils/include/utils/stack_map.h | 9 +- lib/utils/include/utils/stack_vector.h | 8 +- lib/utils/include/utils/tuple.h | 11 +- lib/utils/include/utils/type_traits.h | 1 - lib/utils/include/utils/variant.h | 102 ++++---- lib/utils/include/utils/visitable.h | 7 +- lib/utils/src/graph/algorithms.cc | 22 +- lib/utils/src/graph/serialparallel.cc | 24 +- lib/utils/src/graph/serialparallel_internal.h | 6 +- lib/utils/src/graph/traversal.cc | 4 +- lib/utils/src/stack_vector.cc | 1 + lib/utils/src/tuple.cc | 1 + 80 files changed, 564 insertions(+), 595 deletions(-) delete mode 160000 deps/any delete mode 160000 deps/googletest delete mode 160000 deps/invoke delete mode 160000 deps/optional delete mode 160000 deps/pybind11 delete mode 160000 deps/variant delete mode 100644 lib/utils/include/utils/invoke.h create mode 100644 lib/utils/src/stack_vector.cc create mode 100644 lib/utils/src/tuple.cc diff --git a/.gitmodules b/.gitmodules index e6068aa368..7ee487bb6a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,18 +4,6 @@ [submodule "deps/nccl"] path = deps/nccl url = https://github.com/NVIDIA/nccl.git -[submodule "deps/pybind11"] - path = deps/pybind11 - url = https://github.com/pybind/pybind11.git -[submodule "deps/googletest"] - path = deps/googletest - url = https://github.com/google/googletest.git -[submodule "deps/variant"] - path = deps/variant - url = https://github.com/mpark/variant -[submodule "deps/optional"] - path = deps/optional - url = https://github.com/TartanLlama/optional.git [submodule "deps/json"] path = deps/json url = https://github.com/nlohmann/json.git @@ -37,9 +25,3 @@ [submodule "deps/fmt"] path = deps/fmt url = https://github.com/fmtlib/fmt.git -[submodule "deps/invoke"] - path = deps/invoke - url = https://github.com/BlackMATov/invoke.hpp.git -[submodule "deps/any"] - path = deps/any - url = https://github.com/thelink2012/any.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 418a2a7538..8341c8f364 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.10) project(FlexFlow) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR}/cmake) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR}/cmake ${CMAKE_CURRENT_LIST_DIR}/cmake/Modules) # Detect OS type and Linux version (if it applies) set(LINUX_VERSION "") @@ -77,20 +77,15 @@ include(nccl) # set_property(CACHE FF_GPU_BACKEND PROPERTY STRINGS ${FF_GPU_BACKENDS}) include(json) -include(optional) include(expected) include(spdlog) -include(variant) include(doctest) include(visit_struct) include(CTest) include(fmt) include(legion) include(rapidcheck) -include(invoke) -include(any) #include(gtest) -#include(fmt) include(flexflow-utils) diff --git a/cmake/fmt.cmake b/cmake/fmt.cmake index 9eeb85611c..283caad69d 100644 --- a/cmake/fmt.cmake +++ b/cmake/fmt.cmake @@ -1,5 +1,9 @@ include(aliasing) -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/deps/fmt) +if (FF_USE_EXTERNAL_FMT) + find_package(fmt REQUIRED) +else() + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/deps/fmt) -alias_library(fmt fmt::fmt) + alias_library(fmt fmt::fmt) +endif() diff --git a/cmake/json.cmake b/cmake/json.cmake index 97d4e5f9f7..093ec51cdc 100644 --- a/cmake/json.cmake +++ b/cmake/json.cmake @@ -1,6 +1,12 @@ include(aliasing) -set(JSON_BuildTests OFF CACHE INTERNAL "") -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/deps/json) +if (FF_USE_EXTERNAL_JSON) + find_package(nlohmann_json REQUIRED) -alias_library(json nlohmann_json::nlohmann_json) + alias_library(json nlohmann_json) +else() + set(JSON_BuildTests OFF CACHE INTERNAL "") + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/deps/json) + + alias_library(json nlohmann_json::nlohmann_json) +endif() diff --git a/cmake/nccl.cmake b/cmake/nccl.cmake index 12062958cd..00ab3643ac 100644 --- a/cmake/nccl.cmake +++ b/cmake/nccl.cmake @@ -1,109 +1,121 @@ -set(NCCL_NAME nccl_internal) -# set(NCCL_CUDA_ARCH "-gencode=arch=compute_${CUDA_ARCH},code=sm_${CUDA_ARCH}") -# message("NCCL_CUDA_ARCH: ${NCCL_CUDA_ARCH}") - -set(NCCL_URL "") -if((FF_USE_PREBUILT_NCCL OR FF_USE_ALL_PREBUILT_LIBRARIES) AND CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64") - if(LINUX_VERSION MATCHES "20.04") - if (CUDA_VERSION VERSION_EQUAL "11.0") - set(NCCL_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/nccl_ubuntu-20.04_11.0.3.tar.gz") - elseif(CUDA_VERSION VERSION_EQUAL "11.1") - set(NCCL_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/nccl_ubuntu-20.04_11.1.1.tar.gz") - elseif(CUDA_VERSION VERSION_EQUAL "11.2") - set(NCCL_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/nccl_ubuntu-20.04_11.2.2.tar.gz") - elseif(CUDA_VERSION VERSION_EQUAL "11.3") - set(NCCL_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/nccl_ubuntu-20.04_11.3.1.tar.gz") - elseif(CUDA_VERSION VERSION_EQUAL "11.4") - set(NCCL_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/nccl_ubuntu-20.04_11.4.3.tar.gz") - elseif(CUDA_VERSION VERSION_EQUAL "11.5") - set(NCCL_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/nccl_ubuntu-20.04_11.5.2.tar.gz") - elseif(CUDA_VERSION VERSION_EQUAL "11.6") - set(NCCL_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/nccl_ubuntu-20.04_11.6.2.tar.gz") - elseif(CUDA_VERSION VERSION_EQUAL "11.7") - set(NCCL_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/nccl_ubuntu-20.04_11.7.0.tar.gz") - endif() - elseif(LINUX_VERSION MATCHES "18.04") - if (CUDA_VERSION VERSION_EQUAL "10.1") - set(NCCL_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/nccl_ubuntu-18.04_10.1.243.tar.gz") - elseif (CUDA_VERSION VERSION_EQUAL "10.2") - set(NCCL_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/nccl_ubuntu-18.04_10.2.89.tar.gz") - elseif (CUDA_VERSION VERSION_EQUAL "11.0") - set(NCCL_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/nccl_ubuntu-18.04_11.0.3.tar.gz") - elseif(CUDA_VERSION VERSION_EQUAL "11.1") - set(NCCL_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/nccl_ubuntu-18.04_11.1.1.tar.gz") - elseif(CUDA_VERSION VERSION_EQUAL "11.2") - set(NCCL_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/nccl_ubuntu-18.04_11.2.2.tar.gz") - elseif(CUDA_VERSION VERSION_EQUAL "11.3") - set(NCCL_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/nccl_ubuntu-18.04_11.3.1.tar.gz") - elseif(CUDA_VERSION VERSION_EQUAL "11.4") - set(NCCL_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/nccl_ubuntu-18.04_11.4.3.tar.gz") - elseif(CUDA_VERSION VERSION_EQUAL "11.5") - set(NCCL_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/nccl_ubuntu-18.04_11.5.2.tar.gz") - elseif(CUDA_VERSION VERSION_EQUAL "11.6") - set(NCCL_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/nccl_ubuntu-18.04_11.6.2.tar.gz") - elseif(CUDA_VERSION VERSION_EQUAL "11.7") - set(NCCL_URL "https://github.com/flexflow/flexflow-third-party/releases/latest/download/nccl_ubuntu-18.04_11.7.0.tar.gz") - endif() - endif() -endif() - -if(NCCL_URL) - # Download and import pre-compiled NCCL library - message(STATUS "Using pre-compiled NCCL library") - message(STATUS "NCCL_URL: ${NCCL_URL}") - - include(FetchContent) - FetchContent_Declare(${NCCL_NAME} - URL ${NCCL_URL} - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - ) - FetchContent_GetProperties(${NCCL_NAME}) - if(NOT ${NCCL_NAME}_POPULATED) - FetchContent_Populate(${NCCL_NAME}) - endif() - - set(NCCL_FOLDER_PATH ${${NCCL_NAME}_SOURCE_DIR}/deps/nccl) - set(NCCL_INCLUDE_DIR ${NCCL_FOLDER_PATH}/include) - set(NCCL_LIB_DIR ${NCCL_FOLDER_PATH}/lib) - message(STATUS "NCCL library path: ${NCCL_FOLDER_PATH}") - add_library(nccl SHARED IMPORTED) - set_target_properties(nccl PROPERTIES IMPORTED_LOCATION ${NCCL_FOLDER_PATH}) - - list(APPEND FLEXFLOW_INCLUDE_DIRS ${NCCL_INCLUDE_DIR}) - list(APPEND FLEXFLOW_EXT_LIBRARIES ${NCCL_LIB_DIR}/libnccl${LIBEXT}) - install(DIRECTORY ${NCCL_INCLUDE_DIR}/ DESTINATION include) - install(DIRECTORY ${NCCL_LIB_DIR}/ DESTINATION lib PATTERN "pkgconfig" EXCLUDE) - - set(NCCL_LIB "${INSTALL_DIR}/lib/libnccl${LIBEXT}") -else() - # Build NCCL from source - message(STATUS "Building NCCL from source") - list(TRANSFORM CUDA_GENCODE PREPEND "NVCC_GENCODE=" OUTPUT_VARIABLE NCCL_BUILD_NVCC_GENCODE) - - include(ExternalProject) - ExternalProject_Add(${NCCL_NAME} - SOURCE_DIR ${PROJECT_SOURCE_DIR}/deps/nccl - PREFIX ${CMAKE_BINARY_DIR}/deps/nccl - INSTALL_DIR ${CMAKE_BINARY_DIR}/deps/nccl - BUILD_BYPRODUCTS ${CMAKE_BINARY_DIR}/deps/nccl/lib/libnccl${LIBEXT} - INSTALL_COMMAND "" - CONFIGURE_COMMAND "" - 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 - ) - - ExternalProject_Get_Property(${NCCL_NAME} INSTALL_DIR) - message(STATUS "NCCL install dir: ${INSTALL_DIR}") - set_directory_properties(PROPERTIES ADDITIONAL_CLEAN_FILES "${CMAKE_BINARY_DIR}/deps/nccl/lib/") - - set(NCCL_INCLUDE_DIR "${INSTALL_DIR}/include") - set(NCCL_LIB "${INSTALL_DIR}/lib/libnccl${LIBEXT}") -endif() -message("NCCL_LIB = ${NCCL_LIB}") -message("INSTALL_DIR = ${INSTALL_DIR}") - -add_library(nccl INTERFACE) -target_include_directories(nccl SYSTEM INTERFACE ${NCCL_INCLUDE_DIR}) -add_dependencies(nccl ${NCCL_NAME}) -target_link_libraries(nccl INTERFACE ${NCCL_LIB}) +find_package(NCCL REQUIRED) +#set(NCCL_NAME nccl_internal) +## set(NCCL_CUDA_ARCH "-gencode=arch=compute_${CUDA_ARCH},code=sm_${CUDA_ARCH}") +## message("NCCL_CUDA_ARCH: ${NCCL_CUDA_ARCH}") +# +#if (FF_USE_PREBUILT_NCCL OR FF_USE_ALL_PREBUILT_LIBRARIES) +# if(NCCL_PATH) +# set(NCCL_ROOT ${NCCL_PATH}) +# else() +# # if NCCL_PATH is not set, let's try to find it in the CUDA root +# set(NCCL_ROOT ${CUDA_TOOLKIT_ROOT_DIR}) +# endif() +# +# find_library(NCCL_LIBRARY +# NAMES libnccl${LIBEXT} +# PATHS ${NCCL_ROOT} ${CUDA_ROOT} +# PATH_SUFFIXES lib lib64 +# DOC "NCCL library." ) +# +# find_path(NCCL_INCLUDE_DIR +# NAMES nccl.h +# HINTS ${NCCL_ROOT} +# PATH_SUFFIXES include +# DOC "NCCL include directory.") +# +# # find NCCL, set NCCL lib and include +# if(NCCL_LIBRARY AND NCCL_INCLUDE_DIR) +# set(NCCL_FOUND ON) +# set(NCCL_LIBRARIES ${NCCL_LIBRARY}) +# set(NCCL_INCLUDE_DIRS ${NCCL_INCLUDE_DIR}) +# endif() +# +# # find NCCL +# if(NCCL_FOUND) +# message( STATUS "NCCL include : ${NCCL_INCLUDE_DIRS}" ) +# message( STATUS "NCCL libraries : ${NCCL_LIBRARIES}" ) +# add_library(nccl SHARED IMPORTED) +# +# # Build NCCL from source +#else() +# message(STATUS "Building NCCL from source") +# list(TRANSFORM CUDA_GENCODE PREPEND "NVCC_GENCODE=" OUTPUT_VARIABLE NCCL_BUILD_NVCC_GENCODE) +# +# ExternalProject_Add(${NCCL_NAME} +# SOURCE_DIR ${PROJECT_SOURCE_DIR}/deps/${NCCL_NAME} +# PREFIX ${CMAKE_BINARY_DIR}/deps/${NCCL_NAME} +# INSTALL_DIR ${CMAKE_BINARY_DIR}/deps/${NCCL_NAME} +# BUILD_BYPRODUCTS ${CMAKE_BINARY_DIR}/deps/${NCCL_NAME}/lib/libnccl${LIBEXT} +# INSTALL_COMMAND "" +# CONFIGURE_COMMAND "" +# BUILD_COMMAND make src.build "${NCCL_BUILD_NVCC_GENCODE}" "CUDA_HOME=${CUDA_TOOLKIT_ROOT_DIR}" "BUILDDIR=${CMAKE_BINARY_DIR}/deps/${NCCL_NAME}" +# BUILD_IN_SOURCE 1 +# ) +# +# ExternalProject_Get_Property(${NCCL_NAME} INSTALL_DIR) +# message(STATUS "NCCL install dir: ${INSTALL_DIR}") +# set_directory_properties(PROPERTIES ADDITIONAL_CLEAN_FILES "${CMAKE_BINARY_DIR}/deps/${NCCL_NAME}/lib/") +# +# install(DIRECTORY ${CMAKE_BINARY_DIR}/deps/${NCCL_NAME}/include/ DESTINATION include) +# install(DIRECTORY ${CMAKE_BINARY_DIR}/deps/${NCCL_NAME}/lib/ DESTINATION lib PATTERN "pkgconfig" EXCLUDE) +# endif() +# +# # Download and import pre-compiled NCCL library +# message(STATUS "Using pre-compiled NCCL library") +# message(STATUS "NCCL_URL: ${NCCL_URL}") +# +# include(FetchContent) +# FetchContent_Declare(${NCCL_NAME} +# URL ${NCCL_URL} +# CONFIGURE_COMMAND "" +# BUILD_COMMAND "" +# ) +# FetchContent_GetProperties(${NCCL_NAME}) +# if(NOT ${NCCL_NAME}_POPULATED) +# FetchContent_Populate(${NCCL_NAME}) +# endif() +# +# set(NCCL_FOLDER_PATH ${${NCCL_NAME}_SOURCE_DIR}/deps/nccl) +# set(NCCL_INCLUDE_DIR ${NCCL_FOLDER_PATH}/include) +# set(NCCL_LIB_DIR ${NCCL_FOLDER_PATH}/lib) +# message(STATUS "NCCL library path: ${NCCL_FOLDER_PATH}") +# add_library(nccl SHARED IMPORTED) +# set_target_properties(nccl PROPERTIES IMPORTED_LOCATION ${NCCL_FOLDER_PATH}) +# +# list(APPEND FLEXFLOW_INCLUDE_DIRS ${NCCL_INCLUDE_DIR}) +# list(APPEND FLEXFLOW_EXT_LIBRARIES ${NCCL_LIB_DIR}/libnccl${LIBEXT}) +# install(DIRECTORY ${NCCL_INCLUDE_DIR}/ DESTINATION include) +# install(DIRECTORY ${NCCL_LIB_DIR}/ DESTINATION lib PATTERN "pkgconfig" EXCLUDE) +# +# set(NCCL_LIB "${INSTALL_DIR}/lib/libnccl${LIBEXT}") +#else() +# # Build NCCL from source +# message(STATUS "Building NCCL from source") +# list(TRANSFORM CUDA_GENCODE PREPEND "NVCC_GENCODE=" OUTPUT_VARIABLE NCCL_BUILD_NVCC_GENCODE) +# +# include(ExternalProject) +# ExternalProject_Add(${NCCL_NAME} +# SOURCE_DIR ${PROJECT_SOURCE_DIR}/deps/nccl +# PREFIX ${CMAKE_BINARY_DIR}/deps/nccl +# INSTALL_DIR ${CMAKE_BINARY_DIR}/deps/nccl +# BUILD_BYPRODUCTS ${CMAKE_BINARY_DIR}/deps/nccl/lib/libnccl${LIBEXT} +# INSTALL_COMMAND "" +# CONFIGURE_COMMAND "" +# 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 +# ) +# +# ExternalProject_Get_Property(${NCCL_NAME} INSTALL_DIR) +# message(STATUS "NCCL install dir: ${INSTALL_DIR}") +# set_directory_properties(PROPERTIES ADDITIONAL_CLEAN_FILES "${CMAKE_BINARY_DIR}/deps/nccl/lib/") +# +# set(NCCL_INCLUDE_DIR "${INSTALL_DIR}/include") +# set(NCCL_LIB "${INSTALL_DIR}/lib/libnccl${LIBEXT}") +#endif() +#message("NCCL_LIB = ${NCCL_LIB}") +#message("INSTALL_DIR = ${INSTALL_DIR}") +# +#add_library(nccl INTERFACE) +#target_include_directories(nccl SYSTEM INTERFACE ${NCCL_INCLUDE_DIRS}) +#add_dependencies(nccl ${NCCL_NAME}) +#target_link_libraries(nccl INTERFACE ${NCCL_LIB}) diff --git a/cmake/spdlog.cmake b/cmake/spdlog.cmake index a0d36fc3b2..cd18944460 100644 --- a/cmake/spdlog.cmake +++ b/cmake/spdlog.cmake @@ -1,5 +1,9 @@ include(aliasing) -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/deps/spdlog) +if (FF_USE_EXTERNAL_SPDLOG) + find_package(spdlog REQUIRED) +else() + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/deps/spdlog) -alias_library(spdlog spdlog::spdlog) + alias_library(spdlog spdlog::spdlog) +endif() diff --git a/deps/any b/deps/any deleted file mode 160000 index e88b1bfc16..0000000000 --- a/deps/any +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e88b1bfc160fa9b01e6174dd29c812eeeece3be9 diff --git a/deps/googletest b/deps/googletest deleted file mode 160000 index 2fe3bd994b..0000000000 --- a/deps/googletest +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2fe3bd994b3189899d93f1d5a881e725e046fdc2 diff --git a/deps/invoke b/deps/invoke deleted file mode 160000 index 2c1eabc2e2..0000000000 --- a/deps/invoke +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2c1eabc2e20ab02961f95c704ff0c0818671ddd1 diff --git a/deps/optional b/deps/optional deleted file mode 160000 index c28fcf74d2..0000000000 --- a/deps/optional +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c28fcf74d207fc667c4ed3dbae4c251ea551c8c1 diff --git a/deps/pybind11 b/deps/pybind11 deleted file mode 160000 index 8de7772cc7..0000000000 --- a/deps/pybind11 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8de7772cc72daca8e947b79b83fea46214931604 diff --git a/deps/variant b/deps/variant deleted file mode 160000 index 23cb94f027..0000000000 --- a/deps/variant +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 23cb94f027d4ef33bf48133acc2695c7e5c6f1e7 diff --git a/lib/kernels/CMakeLists.txt b/lib/kernels/CMakeLists.txt index 59c7d44b60..a963c7b49b 100644 --- a/lib/kernels/CMakeLists.txt +++ b/lib/kernels/CMakeLists.txt @@ -1,12 +1,14 @@ set(project_target kernels) project(${project_target} - LANGUAGES CUDA) + LANGUAGES CXX CUDA) file(GLOB_RECURSE SRC CONFIGURE_DEPENDS LIST_DIRECTORIES False - src/*.cc) + src/*.cc + # src/*.cu + ) add_library( ${project_target} @@ -16,7 +18,7 @@ add_library( target_include_directories( ${project_target} PRIVATE - src/cuda/ + src/ PUBLIC include/ ) @@ -28,10 +30,10 @@ target_link_libraries( nccl ) -define_ff_vars(kernels) +define_ff_vars(${project_target}) set_target_properties( ${project_target} PROPERTIES - CUDA_STANDARD 11 + CUDA_STANDARD 17 ) diff --git a/lib/kernels/include/kernels/array_shape.h b/lib/kernels/include/kernels/array_shape.h index 41c8275b1c..0a0124e13c 100644 --- a/lib/kernels/include/kernels/array_shape.h +++ b/lib/kernels/include/kernels/array_shape.h @@ -2,7 +2,6 @@ #define _FLEXFLOW_KERNELS_ARRAY_SHAPE_H #include "legion_dim.h" -#include "utils/optional.h" #include "utils/stack_vector.h" #include "utils/visitable.h" #include @@ -36,11 +35,11 @@ struct ArrayShape { legion_dim_t last_idx() const; legion_dim_t neg_idx(int) const; - optional at_maybe(std::size_t) const; + std::optional at_maybe(std::size_t) const; ArrayShape reversed_dim_order() const; - ArrayShape sub_shape(optional start, - optional end); + ArrayShape sub_shape(std::optional start, + std::optional end); public: LegionTensorDims dims; diff --git a/lib/kernels/include/kernels/device.h b/lib/kernels/include/kernels/device.h index b1571da1b3..b6a501c1f6 100644 --- a/lib/kernels/include/kernels/device.h +++ b/lib/kernels/include/kernels/device.h @@ -24,6 +24,7 @@ #include #include #include +#include #if defined(FF_USE_CUDA) || defined(FF_USE_HIP_CUDA) typedef cudaStream_t ffStream_t; diff --git a/lib/kernels/src/cuda/batch_norm_kernels.cu b/lib/kernels/src/cuda/batch_norm_kernels.cu index 8c5ea76f73..66f3b95e89 100644 --- a/lib/kernels/src/cuda/batch_norm_kernels.cu +++ b/lib/kernels/src/cuda/batch_norm_kernels.cu @@ -13,8 +13,11 @@ * limitations under the License. */ +#include "kernels/allocation.h" +#include "kernels/device.h" +#include "kernels/ff_handle.h" #include "kernels/batch_norm_kernels.h" -#include "kernels/cuda_helper.h" +#include "device.h" namespace FlexFlow { namespace Kernels { @@ -86,7 +89,7 @@ void backward_kernel(cudaStream_t stream, m->saveVar)); } -BatchNormPerDeviceState init_kernel(PerDeviceFFHandle handler, +BatchNormPerDeviceState init_kernel(PerDeviceFFHandle handle, Allocator allocator, float *runningMean, int output_n, @@ -125,19 +128,18 @@ BatchNormPerDeviceState init_kernel(PerDeviceFFHandle handler, checkCUDNN(cudnnSetTensor4dDescriptor( biasTensor, CUDNN_TENSOR_NCHW, CUDNN_DATA_FLOAT, 1, output_c, 1, 1)); // allocate memory for runningMean, runningVar, saveMean, saveVar - { - size_t totalSize = sizeof(float) * output_c * 4; - runningMean = (float *)allocator.allocate(totalSize); - float *runningVar = (float *)runningMean + output_c; - float *saveMean = (float *)runningVar + output_c; - float *saveVar = (float *)saveMean + output_c; - cudaStream_t stream; + size_t totalSize = sizeof(float) * output_c * 4; + runningMean = (float *)allocator.allocate(totalSize); + float *runningVar = (float *)runningMean + output_c; + float *saveMean = (float *)runningVar + output_c; + float *saveVar = (float *)saveMean + output_c; + cudaStream_t stream; + + assign_kernel<<>>( + runningMean, output_c, 0.0f); + assign_kernel<<>>( + runningVar, output_c, 0.0f); - assign_kernel<<>>( - runningMean, output_c, 0.0f); - assign_kernel<<>>( - runningVar, output_c, 0.0f); - } if (relu) { checkCUDNN(cudnnCreateActivationDescriptor(&actiDesc)); checkCUDNN(cudnnSetActivationDescriptor( diff --git a/lib/kernels/src/cuda/cast_kernels.cu b/lib/kernels/src/cuda/cast_kernels.cu index 3d8804862d..ce93e8a5f7 100644 --- a/lib/kernels/src/cuda/cast_kernels.cu +++ b/lib/kernels/src/cuda/cast_kernels.cu @@ -59,7 +59,8 @@ struct BackwardKernel { } }; -void forward_kernel(ffStream_t stream, +void forward_kernel(PerDeviceFFHandle handle, + ffStream_t stream, GenericTensorAccessorR const &input, GenericTensorAccessorW const &output, DataType input_type, @@ -68,7 +69,8 @@ void forward_kernel(ffStream_t stream, input_type, output_type, stream, handle, input, output); } -void backward_kernel(ffStream_t stream, +void backward_kernel(PerDeviceFFHandle handle, + ffStream_t stream, GenericTensorAccessorR const &input, GenericTensorAccessorW const &output, DataType input_type, diff --git a/lib/kernels/src/device.h b/lib/kernels/src/device.h index 5c4239a5cf..00f2888f45 100644 --- a/lib/kernels/src/device.h +++ b/lib/kernels/src/device.h @@ -5,6 +5,7 @@ #include "kernels/device.h" #include "op-attrs/datatype.h" #include "op-attrs/op.h" +#include #if defined(FF_USE_CUDA) #include diff --git a/lib/op-attrs/include/op-attrs/datatype.h b/lib/op-attrs/include/op-attrs/datatype.h index 2417f37fdb..1c6c723eeb 100644 --- a/lib/op-attrs/include/op-attrs/datatype.h +++ b/lib/op-attrs/include/op-attrs/datatype.h @@ -3,7 +3,7 @@ #include "utils/fmt.h" #include "utils/fp16.h" -#include "utils/variant.h" +#include namespace FlexFlow { @@ -50,7 +50,7 @@ typename data_type_enum_to_class
::type cast_to(T t) { template using real_type = typename data_type_enum_to_class
::type; -using DataTypeValue = variant, +using DataTypeValue = std::variant, real_type, real_type, real_type, diff --git a/lib/op-attrs/include/op-attrs/get_op_type.h b/lib/op-attrs/include/op-attrs/get_op_type.h index 421c464843..a2db4ab5f0 100644 --- a/lib/op-attrs/include/op-attrs/get_op_type.h +++ b/lib/op-attrs/include/op-attrs/get_op_type.h @@ -45,7 +45,7 @@ struct GetOpTypeFunctor { }; template -OperatorType get_op_type(variant const &attrs) { +OperatorType get_op_type(std::variant const &attrs) { return visit(GetOpTypeFunctor{}, attrs); } diff --git a/lib/op-attrs/include/op-attrs/get_output_shapes.h b/lib/op-attrs/include/op-attrs/get_output_shapes.h index 5f78ec2d3f..6fb93aac91 100644 --- a/lib/op-attrs/include/op-attrs/get_output_shapes.h +++ b/lib/op-attrs/include/op-attrs/get_output_shapes.h @@ -177,19 +177,19 @@ struct GetOutputShapesFunctor { template std::vector - get_output_shapes(variant const &t, + get_output_shapes(std::variant const &t, std::vector const &s) { return get_output_shape(GetOutputShapesFunctor{s}, t); } template -typename std::enable_if::value, optional>::type +typename std::enable_if::value, std::optional>::type get_num_outputs(T const &) { - return nullopt; + return std::nullopt; } template -typename std::enable_if::value, optional>::type +typename std::enable_if::value, std::optional>::type get_num_outputs(T const &) { return 1; } diff --git a/lib/op-attrs/include/op-attrs/operator_attrs.h b/lib/op-attrs/include/op-attrs/operator_attrs.h index a7ba84624c..a8d66aa041 100644 --- a/lib/op-attrs/include/op-attrs/operator_attrs.h +++ b/lib/op-attrs/include/op-attrs/operator_attrs.h @@ -35,7 +35,7 @@ namespace FlexFlow { -using SharedOperatorAttrs = variant::value, ""); static_assert(is_valid_opattr::value, ""); using ParallelOperatorAttrs = - variant; + std::variant; using ComputationGraphAttrs = - variant_join>; + variant_join>; using CompGraphOperatorAttrs = ComputationGraphAttrs; using PCGOperatorAttrs = diff --git a/lib/op-attrs/include/op-attrs/ops/conv_2d.h b/lib/op-attrs/include/op-attrs/ops/conv_2d.h index 3034dc8c62..79980d545d 100644 --- a/lib/op-attrs/include/op-attrs/ops/conv_2d.h +++ b/lib/op-attrs/include/op-attrs/ops/conv_2d.h @@ -10,9 +10,9 @@ namespace FlexFlow { struct Conv2DAttrs { - req out_channels, kernel_h, kernel_w, stride_h, stride_w, padding_h, + int out_channels, kernel_h, kernel_w, stride_h, stride_w, padding_h, padding_w, groups; - req> activation; + std::optional activation; req use_bias; }; diff --git a/lib/op-attrs/include/op-attrs/ops/linear.h b/lib/op-attrs/include/op-attrs/ops/linear.h index 3be8be2040..2c27b09f7c 100644 --- a/lib/op-attrs/include/op-attrs/ops/linear.h +++ b/lib/op-attrs/include/op-attrs/ops/linear.h @@ -21,14 +21,14 @@ struct L2RegularizerAttrs { FF_VISITABLE_STRUCT(L2RegularizerAttrs, lambda); CHECK_VALID_OP_ATTR(L2RegularizerAttrs); -using RegularizerAttrs = variant; +using RegularizerAttrs = std::variant; struct LinearAttrs { - req out_channels; - req use_bias; - req data_type; - req activation; - req> regularizer; + int out_channels; + bool use_bias; + DataType data_type; + Activation activation; + req> regularizer; }; FF_VISITABLE_STRUCT( LinearAttrs, out_channels, use_bias, data_type, activation, regularizer); diff --git a/lib/op-attrs/include/op-attrs/ops/loss_functions.h b/lib/op-attrs/include/op-attrs/ops/loss_functions.h index 7a3db05329..4c11c33fd6 100644 --- a/lib/op-attrs/include/op-attrs/ops/loss_functions.h +++ b/lib/op-attrs/include/op-attrs/ops/loss_functions.h @@ -3,7 +3,7 @@ #include "core.h" #include "utils/exception.h" -#include "utils/variant.h" +#include #include "utils/visitable.h" namespace FlexFlow { @@ -31,7 +31,7 @@ FF_VISITABLE_STRUCT(OtherLossAttrs, loss_type); CHECK_VALID_OP_ATTR(OtherLossAttrs); using LossAttrs = - variant; + std::variant; LossFunction get_loss_function(OtherLossAttrs const &); LossFunction get_loss_function(SparseCategoricalCrossEntropyLossAttrs const &); diff --git a/lib/op-attrs/src/operator_attrs.cc b/lib/op-attrs/src/operator_attrs.cc index 16f410f870..a524ab3d14 100644 --- a/lib/op-attrs/src/operator_attrs.cc +++ b/lib/op-attrs/src/operator_attrs.cc @@ -166,8 +166,8 @@ struct AsDot { }; template -RecordFormatter as_dot(variant const &o) { - return mpark::visit(AsDot{}, o); +RecordFormatter as_dot(std::variant const &o) { + return std::visit(AsDot{}, o); } struct IsValidFunctor { diff --git a/lib/op-attrs/src/parallel_dim_mapping_record.cc b/lib/op-attrs/src/parallel_dim_mapping_record.cc index a5fa6823e9..5e734e88cd 100644 --- a/lib/op-attrs/src/parallel_dim_mapping_record.cc +++ b/lib/op-attrs/src/parallel_dim_mapping_record.cc @@ -13,7 +13,7 @@ ParallelDimMappingRecord ParallelDimMappingRecord::input_output_record( int input_dim, int output_idx, int output_dim, - tl::optional operation) { + std::optional operation) { ParallelDimMappingRecord r(MappingRecordType::INPUT_OUTPUT); r.operation = operation; @@ -36,7 +36,7 @@ ParallelDimMappingRecord ParallelDimMappingRecord::input_weight_record( int input_dim, int weight_idx, int weight_dim, - tl::optional operation) { + std::optional operation) { ParallelDimMappingRecord r(MappingRecordType::INPUT_WEIGHT); r.operation = operation; diff --git a/lib/op-attrs/src/parallel_dim_mapping_record.h b/lib/op-attrs/src/parallel_dim_mapping_record.h index c0f325ab7e..c37ac79b40 100644 --- a/lib/op-attrs/src/parallel_dim_mapping_record.h +++ b/lib/op-attrs/src/parallel_dim_mapping_record.h @@ -1,7 +1,6 @@ #ifndef _FLEXFLOW_OP_META_SRC_PARELLEL_DIM_MAPPING_RECORD_H #define _FLEXFLOW_OP_META_SRC_PARELLEL_DIM_MAPPING_RECORD_H -#include "tl/optional.hpp" #include "utils/visitable.h" #include @@ -23,18 +22,18 @@ class ParallelDimMappingRecord { int input_dim, int output_idx, int output_dim, - tl::optional operation = tl::nullopt); + std::optional operation = std::nullopt); static ParallelDimMappingRecord input_weight_record( int input_idx, int input_dim, int weight_idx, int weight_dim, - tl::optional operation = tl::nullopt); + std::optional operation = std::nullopt); MappingRecordType get_type() const; public: MappingRecordType type; - tl::optional operation; + std::optional operation; int output_dim, input_dim, weight_dim; int output_idx, input_idx, weight_idx; diff --git a/lib/op-attrs/src/parallel_dim_mapping_record_solver.cc b/lib/op-attrs/src/parallel_dim_mapping_record_solver.cc index 68686393f5..11cfbc125c 100644 --- a/lib/op-attrs/src/parallel_dim_mapping_record_solver.cc +++ b/lib/op-attrs/src/parallel_dim_mapping_record_solver.cc @@ -44,7 +44,7 @@ ParallelDimMappingRecord int output_dim, int input_idx, int output_idx, - tl::optional operation) { + std::optional operation) { NOT_IMPLEMENTED(); } @@ -53,7 +53,7 @@ ParallelDimMappingRecord int weight_dim, int input_idx, int weight_idx, - tl::optional operation) { + std::optional operation) { NOT_IMPLEMENTED(); } /* int get_output_to_input_dim_mapping(ParallelTensorShape const &output, */ @@ -209,7 +209,7 @@ void construct_weight_parallel_dims( int weight_dim, int input_idx, int weight_idx, - tl::optional operation) { + std::optional operation) { records.push_back(ParallelDimMappingRecord::input_weight_record( input_idx, input_dim, weight_idx, weight_dim, operation)); } @@ -274,7 +274,7 @@ void construct_output_parallel_dims( int output_dim, int input_idx, int output_idx, - tl::optional operation) { + std::optional operation) { records.push_back(ParallelDimMappingRecord::input_output_record( input_idx, input_dim, output_idx, output_dim, operation)); } diff --git a/lib/op-attrs/src/parallel_dim_mapping_record_solver.h b/lib/op-attrs/src/parallel_dim_mapping_record_solver.h index d28cd419ca..a46192edeb 100644 --- a/lib/op-attrs/src/parallel_dim_mapping_record_solver.h +++ b/lib/op-attrs/src/parallel_dim_mapping_record_solver.h @@ -29,7 +29,7 @@ ParallelDimMappingRecord construct_weight_parallel_dims( int weight_dim, int input_idx = 0, int weight_idx = 0, - tl::optional operation = tl::nullopt); + std::optional operation = std::nullopt); std::vector construct_output_parallel_dims(std::vector> mappings, @@ -44,7 +44,7 @@ ParallelDimMappingRecord construct_output_parallel_dims( int output_dim, int input_idx = 0, int output_idx = 0, - tl::optional operation = tl::nullopt); + std::optional operation = std::nullopt); struct ParallelDimMappingSolution { std::vector weight_shapes; @@ -85,7 +85,7 @@ ParallelDimMappingSolution solve_parallel_dim_mappings( /* int weight_dim, */ /* int input_idx = 0, */ /* int weight_idx = 0, */ -/* tl::optional operation = tl::nullopt); */ +/* std::optional operation = std::nullopt); */ /* void register_output_parallel_dims( */ /* std::vector> mappings, */ /* int input_idx = 0, */ @@ -95,7 +95,7 @@ ParallelDimMappingSolution solve_parallel_dim_mappings( /* int output_dim, */ /* int input_idx = 0, */ /* int output_idx = 0, */ -/* tl::optional operation = tl::nullopt); */ +/* std::optional operation = std::nullopt); */ /* private: */ /* std::vector *parallel_dims_mapping; */ diff --git a/lib/pcg/include/pcg/computation_graph_builder.h b/lib/pcg/include/pcg/computation_graph_builder.h index ae937c590d..cedcb2b977 100644 --- a/lib/pcg/include/pcg/computation_graph_builder.h +++ b/lib/pcg/include/pcg/computation_graph_builder.h @@ -12,61 +12,61 @@ struct ComputationGraphBuilder // C++ APIs for constructing models // Add an exp layer - Tensor exp(Tensor const &, optional const &name = nullopt); + Tensor exp(Tensor const &, std::optional const &name = std::nullopt); // Add an add layer Tensor add(Tensor const &x, Tensor const &y, - optional const &name = nullopt); + std::optional const &name = std::nullopt); // Add a subtract layer Tensor subtract(Tensor const &x, Tensor const &y, - optional const &name = nullopt); + std::optional const &name = std::nullopt); // Add a multiply layer Tensor multiply(Tensor const &x, Tensor const &y, - optional const &name = nullopt); + std::optional const &name = std::nullopt); // Add a divide layer Tensor divide(Tensor const &x, Tensor const &y, - optional const &name = nullopt); + std::optional const &name = std::nullopt); // Add a max layer Tensor max(Tensor const &x, Tensor const &y, - optional const &name = nullopt); + std::optional const &name = std::nullopt); // Add a min layer Tensor min(Tensor const &x, Tensor const &y, - optional const &name = nullopt); + std::optional const &name = std::nullopt); // Add a rsqrt layer - Tensor rsqrt(Tensor const &x, optional const &name = nullopt); + Tensor rsqrt(Tensor const &x, std::optional const &name = std::nullopt); // Add a pow layer Tensor pow(Tensor const &x, float exponent, - optional const &name = nullopt); + std::optional const &name = std::nullopt); // Add a scalar multiply layer Tensor scalar_multiply(Tensor const &x, float scalar, - optional const &name = nullopt); + std::optional const &name = std::nullopt); Tensor scalar_add(Tensor const &x, float scalar, - optional const &name = nullopt); + std::optional const &name = std::nullopt); Tensor scalar_sub(Tensor const &lhs, float rhs, - optional const &name = nullopt); + std::optional const &name = std::nullopt); Tensor scalar_truediv(Tensor const &numerator, float denominator, - optional const &name = nullopt); + std::optional const &name = std::nullopt); // Add a sin layer - Tensor sin(Tensor const &x, optional const &name = nullopt); + Tensor sin(Tensor const &x, std::optional const &name = std::nullopt); // Add a cos layer - Tensor cos(Tensor const &x, optional const &name = nullopt); + Tensor cos(Tensor const &x, std::optional const &name = std::nullopt); // Add an activation layer - Tensor relu(Tensor const &x, optional const &name = nullopt); - Tensor identity(Tensor const &x, optional const &name = nullopt); - Tensor gelu(Tensor const &x, optional const &name = nullopt); - Tensor sigmoid(Tensor const &x, optional const &name = nullopt); - Tensor tanh(Tensor const &x, optional const &name = nullopt); - Tensor elu(Tensor const &x, optional const &name = nullopt); + Tensor relu(Tensor const &x, std::optional const &name = std::nullopt); + Tensor identity(Tensor const &x, std::optional const &name = std::nullopt); + Tensor gelu(Tensor const &x, std::optional const &name = std::nullopt); + Tensor sigmoid(Tensor const &x, std::optional const &name = std::nullopt); + Tensor tanh(Tensor const &x, std::optional const &name = std::nullopt); + Tensor elu(Tensor const &x, std::optional const &name = std::nullopt); // Add a 2D convolutional layer Tensor conv2d(Tensor const &input, int outChannels, @@ -76,37 +76,37 @@ struct ComputationGraphBuilder int strideW, int paddingH, int paddingW, - optional const &activation = nullopt, + std::optional const &activation = std::nullopt, int groups = 1, bool use_bias = true, - optional kernel_initializer = nullopt, - optional bias_initializer = nullopt, - optional kernel_regularizer = nullopt, - optional const &name = nullopt); + std::optional const &kernel_initializer = std::nullopt, + std::optional const &bias_initializer = std::nullopt, + std::optional const & kernel_regularizer = std::nullopt, + std::optional const &name = std::nullopt); // Add a dropout layer Tensor dropout(Tensor const &input, float rate, unsigned long long seed = 0, - optional const &name = nullopt); + std::optional const &name = std::nullopt); // Add an embedding layer Tensor embedding(Tensor const &input, int num_entries, int outDim, AggregateOp aggr, DataType dtype = DataType::FLOAT, - optional kernel_initializer = nullopt, - optional const &name = nullopt); + std::optional const &kernel_initializer = std::nullopt, + std::optional const &name = std::nullopt); // Add a gather layer std::vector gather(Tensor const &input, Tensor const &index, ff_dim_t dim, - optional const &name = nullopt); + std::optional const &name = std::nullopt); // Add a cache layer Tensor cache(Tensor const &input, int num_batches, std::function score_f = {}, - optional const &name = nullopt); + std::optional const &name = std::nullopt); // Add a 2D pooling layer Tensor pool2d(Tensor const &input, int kernelH, @@ -116,38 +116,38 @@ struct ComputationGraphBuilder int paddingH, int paddingW, PoolOp type = PoolOp::MAX, - optional const &activation = nullopt, - optional const &name = nullopt); + std::optional const &activation = std::nullopt, + std::optional const &name = std::nullopt); Tensor layer_norm(Tensor const &input, std::vector const &axes, bool elementwise_affine, float eps, - optional const &name = nullopt); + std::optional const &name = std::nullopt); Tensor batch_norm(Tensor const &input, bool relu = true, - optional const &name = nullopt); + std::optional const &name = std::nullopt); Tensor batch_matmul(Tensor const &A, Tensor const &B, int a_seq_length_dim = -1, int b_seq_length_dim = -1, - optional const &name = nullopt); + std::optional const &name = std::nullopt); Tensor dense(Tensor const &input, int outDim, - optional activation = nullopt, + std::optional activation = std::nullopt, bool use_bias = true, DataType data_type = DataType::FLOAT, - optional kernel_initializer = nullopt, - optional bias_initializer = nullopt, - optional const &name = nullopt); + std::optional const &kernel_initializer = std::nullopt, + std::optional const & bias_initializer = std::nullopt, + std::optional const &name = std::nullopt); // Add a cast layer Tensor cast(Tensor const &input, DataType dtype, - optional const &name = nullopt); + std::optional const &name = std::nullopt); // Add a concat layer Tensor concat(int n, std::vector const &tensors, int axis, - optional const &name = nullopt); + std::optional const &name = std::nullopt); // Add a mean layer Tensor mean(Tensor const &input, std::vector const &dims, @@ -158,32 +158,32 @@ struct ComputationGraphBuilder Tensor *outputs, std::vector const &split, int axis, - optional const &name = nullopt); + std::optional const &name = std::nullopt); // Add a flat layer - Tensor flat(Tensor const &input, optional const &name = nullopt); + Tensor flat(Tensor const &input, std::optional const &name = std::nullopt); // Add a softmax layer Tensor softmax(Tensor const &input, int dim = -1, - optional const &name = nullopt); + std::optional const &name = std::nullopt); // Create input tensors and constants Tensor transpose(Tensor const &input, std::vector const &perm, - optional const &name = nullopt); + std::optional const &name = std::nullopt); Tensor reduce_sum(Tensor const &input, std::vector const &axes, bool keepdims = false, - optional const &name = nullopt); + std::optional const &name = std::nullopt); Tensor reshape(Tensor const &input, std::vector const &shape, - optional const &name = nullopt); + std::optional const &name = std::nullopt); Tensor reverse(Tensor const &input, int axis, - optional const &name = nullopt); + std::optional const &name = std::nullopt); void top_k(Tensor const &input, Tensor *outputs, int k, bool sorted, - optional const &name = nullopt); + std::optional const &name = std::nullopt); Tensor multihead_attention(Tensor const &query, Tensor const &key, @@ -196,13 +196,13 @@ struct ComputationGraphBuilder bool bias = true, bool add_bias_kv = false, bool add_zero_attn = false, - optional initializer = nullopt, - optional const &name = nullopt); + std::optional initializer = std::nullopt, + std::optional const &name = std::nullopt); Tensor create_tensor(TensorShape const &, bool create_grad = true); Parameter create_weight(TensorShape const &, bool create_grad = true, - optional initializer = nullopt, - optional sync_type = nullopt); + std::optional const &initializer = std::nullopt, + std::optional sync_type = std::nullopt); std::vector get_outputs(Layer const &) const; Tensor get_output(Layer const &, int idx) const; @@ -220,13 +220,13 @@ struct ComputationGraphBuilder Tensor add_layer(Layer const &layer, std::vector const &inputs, - std::vector>> const + std::vector>> const &weight_shapes, TensorShape const &output_shape); std::vector add_layer(Layer const &layer, std::vector const &inputs, - std::vector>> const + std::vector>> const &weight_shapes, std::vector const &output_shapes); @@ -237,21 +237,21 @@ struct ComputationGraphBuilder Tensor element_binary(OperatorType, Tensor const &lhs, Tensor const &rhs, - optional const &name = nullopt); + std::optional const &name = std::nullopt); Tensor element_unary(OperatorType, Tensor const &input, - optional const &name = nullopt); + std::optional const &name = std::nullopt); Tensor element_scalar_unary(OperatorType, Tensor const &input, float scalar, - optional const &name = nullopt); + std::optional const &name = std::nullopt); Tensor element_unary(ElementUnaryAttrs const &, Tensor const &input, - optional const &name = nullopt); + std::optional const &name = std::nullopt); Tensor element_scalar_unary(ElementScalarUnaryAttrs const &attrs, Tensor const &x, - optional const &maybe_name); + std::optional const &maybe_name); public: ComputationGraph computation_graph; diff --git a/lib/pcg/include/pcg/device_id.h b/lib/pcg/include/pcg/device_id.h index 3ace2fd84e..50c2558e39 100644 --- a/lib/pcg/include/pcg/device_id.h +++ b/lib/pcg/include/pcg/device_id.h @@ -3,7 +3,6 @@ #include "device_type.h" #include "utils/strong_typedef.h" -#include "utils/variant.h" namespace FlexFlow { @@ -15,7 +14,7 @@ struct cpu_id_t : strong_typedef { using strong_typedef::strong_typedef; }; -using device_id_t = variant; +using device_id_t = std::variant; device_id_t operator+(device_id_t, size_t); DeviceType get_device_type(device_id_t); diff --git a/lib/pcg/include/pcg/file_format/v1/data_type.h b/lib/pcg/include/pcg/file_format/v1/data_type.h index dad98e462d..ad2fad7d89 100644 --- a/lib/pcg/include/pcg/file_format/v1/data_type.h +++ b/lib/pcg/include/pcg/file_format/v1/data_type.h @@ -3,11 +3,10 @@ #include "utils/fp16.h" #include "utils/json.h" -#include "utils/variant.h" namespace FlexFlow { -using V1DataTypeValue = variant; +using V1DataTypeValue = std::variant; enum class V1DataType { BOOL, diff --git a/lib/pcg/include/pcg/file_format/v1/graphs.h b/lib/pcg/include/pcg/file_format/v1/graphs.h index 71a8adb344..6bc852b0f1 100644 --- a/lib/pcg/include/pcg/file_format/v1/graphs.h +++ b/lib/pcg/include/pcg/file_format/v1/graphs.h @@ -53,7 +53,7 @@ struct V1JsonableGraph { struct V1Layer { V1CompGraphOperatorAttrs attrs; - req> name; + req> name; }; FF_VISITABLE_STRUCT(V1Layer, attrs, name); V1Layer to_v1(Layer const &); diff --git a/lib/pcg/include/pcg/file_format/v1/initializer.h b/lib/pcg/include/pcg/file_format/v1/initializer.h index 24f0320bd9..bf219ef149 100644 --- a/lib/pcg/include/pcg/file_format/v1/initializer.h +++ b/lib/pcg/include/pcg/file_format/v1/initializer.h @@ -19,15 +19,15 @@ struct V1ZeroInitializer {}; FF_VISITABLE_STRUCT(V1ZeroInitializer); struct V1UniformInitializer { - req seed; - req min_val; + int seed; + float min_val; req max_val; }; FF_VISITABLE_STRUCT(V1UniformInitializer, seed, min_val, max_val); struct V1NormInitializer { - req seed; - req mean; + int seed; + float mean; req stddev; }; FF_VISITABLE_STRUCT(V1NormInitializer, seed, mean, stddev); @@ -37,7 +37,7 @@ struct V1ConstantInitializer { }; FF_VISITABLE_STRUCT(V1ConstantInitializer, value); -using V1Initializer = variant namespace FlexFlow { @@ -12,8 +12,8 @@ FF_VISITABLE_STRUCT(V1Conv2DAttrs); static_assert( std::is_same, std::tuple<>>::value, ""); -using V1CompGraphOperatorAttrs = variant; -using V1PCGOperatorAttrs = variant; +using V1CompGraphOperatorAttrs = std::variant; +using V1PCGOperatorAttrs = std::variant; } // namespace FlexFlow diff --git a/lib/pcg/include/pcg/file_format/v1/parallel_tensor.h b/lib/pcg/include/pcg/file_format/v1/parallel_tensor.h index 1ea4cd04de..c215569b21 100644 --- a/lib/pcg/include/pcg/file_format/v1/parallel_tensor.h +++ b/lib/pcg/include/pcg/file_format/v1/parallel_tensor.h @@ -11,22 +11,22 @@ namespace FlexFlow { struct V1ParallelDim { - req size; - req degree; + size_t size; + int degree; req is_replica_dim; }; FF_VISITABLE_STRUCT(V1ParallelDim, size, degree, is_replica_dim); struct V1ParallelTensorShape { - req> dims; + std::vector dims; req data_type; }; FF_VISITABLE_STRUCT(V1ParallelTensorShape, dims, data_type); struct V1ParallelTensor { V1ParallelTensorShape shape; - req> sync_type; - req> initializer; + std::optional sync_type; + std::optional initializer; req create_grad; }; FF_VISITABLE_STRUCT( diff --git a/lib/pcg/include/pcg/file_format/v1/tensor.h b/lib/pcg/include/pcg/file_format/v1/tensor.h index e1f6828186..c304a41401 100644 --- a/lib/pcg/include/pcg/file_format/v1/tensor.h +++ b/lib/pcg/include/pcg/file_format/v1/tensor.h @@ -12,7 +12,7 @@ namespace FlexFlow { struct V1TensorShape { - req> dims; + std::vector dims; req data_type; }; FF_VISITABLE_STRUCT(V1TensorShape, dims, data_type); @@ -21,10 +21,10 @@ V1TensorShape to_v1(TensorShape const &); struct V1Tensor { V1TensorShape shape; - req> initializer; - req create_gradients; - req> sync_type; - req> name; + std::optional initializer; + bool create_gradients; + std::optional sync_type; + req> name; }; FF_VISITABLE_STRUCT( V1Tensor, shape, initializer, create_gradients, sync_type, name); diff --git a/lib/pcg/include/pcg/initializer.h b/lib/pcg/include/pcg/initializer.h index 58e4fcc242..bd5aa81822 100644 --- a/lib/pcg/include/pcg/initializer.h +++ b/lib/pcg/include/pcg/initializer.h @@ -20,15 +20,15 @@ struct ZeroInitializer { FF_VISITABLE_STRUCT(ZeroInitializer); struct UniformInitializer { - req seed; - req min_val; + int seed; + float min_val; req max_val; }; FF_VISITABLE_STRUCT(UniformInitializer, seed, min_val, max_val); struct NormInitializer { - req seed; - req mean; + int seed; + float mean; req stddev; }; FF_VISITABLE_STRUCT(NormInitializer, seed, mean, stddev); @@ -38,7 +38,7 @@ struct ConstantInitializer { }; FF_VISITABLE_STRUCT(ConstantInitializer, value); -using Initializer = variant { +struct Layer { public: Layer() = delete; - Layer(CompGraphOperatorAttrs const &attrs, optional const &name); + Layer(CompGraphOperatorAttrs const &attrs, std::optional const &name); public: - optional> name; + std::optional> name; CompGraphOperatorAttrs attrs; }; diff --git a/lib/pcg/include/pcg/operator.h b/lib/pcg/include/pcg/operator.h index c7a49bb57e..4a52fe2028 100644 --- a/lib/pcg/include/pcg/operator.h +++ b/lib/pcg/include/pcg/operator.h @@ -11,7 +11,7 @@ namespace FlexFlow { struct Operator : public use_visitable_cmp { public: Operator() = delete; - Operator(PCGOperatorAttrs const &attrs, optional const &name); + Operator(PCGOperatorAttrs const &attrs, std::optional const &name); operator PCGOperatorAttrs() const; diff --git a/lib/pcg/include/pcg/parallel_tensor.h b/lib/pcg/include/pcg/parallel_tensor.h index eadc83d9fd..c3f7ebdfed 100644 --- a/lib/pcg/include/pcg/parallel_tensor.h +++ b/lib/pcg/include/pcg/parallel_tensor.h @@ -39,19 +39,19 @@ struct ParallelTensor : public use_visitable_cmp { ParallelTensor(ParallelTensorShape const &, CreateGrad create_gradients, - optional sync_type = nullopt, - optional initializer = nullopt); + std::optional sync_type = std::nullopt, + std::optional initializer = std::nullopt); ParallelTensor(ParallelTensorDims const &, DataType, CreateGrad create_gradients, - optional sync_type = nullopt, - optional initializer = nullopt); + std::optional sync_type = std::nullopt, + std::optional initializer = std::nullopt); public: ParallelTensorDims dims; DataType data_type; - optional sync_type = nullopt; - optional initializer = nullopt; + std::optional sync_type = std::nullopt; + std::optional initializer = std::nullopt; CreateGrad create_gradients; }; diff --git a/lib/pcg/include/pcg/tensor.h b/lib/pcg/include/pcg/tensor.h index cb79be245a..975a69809d 100644 --- a/lib/pcg/include/pcg/tensor.h +++ b/lib/pcg/include/pcg/tensor.h @@ -24,9 +24,9 @@ struct Tensor { public: TensorDims dims; DataType data_type; - req> initializer; - req create_gradients; - req> sync_type; + std::optional initializer; + bool create_gradients; + req> sync_type; }; FF_VISITABLE_STRUCT( Tensor, dims, data_type, initializer, create_gradients, sync_type); diff --git a/lib/pcg/src/computation_graph_builder.cc b/lib/pcg/src/computation_graph_builder.cc index 9f8e930919..14047ba7be 100644 --- a/lib/pcg/src/computation_graph_builder.cc +++ b/lib/pcg/src/computation_graph_builder.cc @@ -15,7 +15,7 @@ void ComputationGraphBuilder::add_layer(Layer const &layer, Tensor ComputationGraphBuilder::add_layer( Layer const &layer, std::vector const &inputs, - std::vector>> const + std::vector>> const &weight_shapes, TensorShape const &output_shape) { NOT_IMPLEMENTED(); @@ -23,7 +23,7 @@ Tensor ComputationGraphBuilder::add_layer( std::vector ComputationGraphBuilder::add_layer( Layer const &layer, std::vector const &inputs, - std::vector>> const + std::vector>> const &weight_shapes, std::vector const &output_shapes) { NOT_IMPLEMENTED(); @@ -34,7 +34,7 @@ Tensor ComputationGraphBuilder::broadcast(Tensor const &, TensorShape const &) { } Tensor ComputationGraphBuilder::cast(Tensor const &input, DataType dtype, - optional const &name){ + std::optional const &name){ NOT_IMPLEMENTED()} Tensor ComputationGraphBuilder::as_type(Tensor const &x, @@ -60,14 +60,14 @@ static std::string get_default_name(ComputationGraphAttrs const &attrs) { } template -static std::string get_default_name(variant const &attrs) { +static std::string get_default_name(std::variant const &attrs) { return get_default_name(widen(attrs)); } Tensor ComputationGraphBuilder::element_unary( ElementUnaryAttrs const &attrs, Tensor const &x, - optional const &maybe_name) { + std::optional const &maybe_name) { std::string name = maybe_name.value_or(get_default_name(attrs)); Tensor input = this->as_type(x, DataType::FLOAT, name + "input_pre_cast"); @@ -81,7 +81,7 @@ Tensor ComputationGraphBuilder::element_unary( Tensor ComputationGraphBuilder::element_scalar_unary( ElementScalarUnaryAttrs const &attrs, Tensor const &x, - optional const &maybe_name) { + std::optional const &maybe_name) { std::string name = maybe_name.value_or(get_default_name(attrs)); Tensor input = this->as_type(x, DataType::FLOAT, name + "input_pre_cast"); @@ -95,7 +95,7 @@ Tensor ComputationGraphBuilder::element_scalar_unary( Tensor ComputationGraphBuilder::element_unary(OperatorType op_type, Tensor const &input, - optional const &name) { + std::optional const &name) { ElementUnaryAttrs attrs = {op_type}; return this->element_unary(attrs, input, name); } @@ -104,7 +104,7 @@ Tensor ComputationGraphBuilder::element_scalar_unary( OperatorType op_type, Tensor const &input, float scalar, - optional const &name) { + std::optional const &name) { ElementScalarUnaryAttrs attrs = {op_type, scalar}; return this->element_scalar_unary(attrs, input, name); } @@ -113,7 +113,7 @@ Tensor ComputationGraphBuilder::element_binary( OperatorType op_type, Tensor const &lhs, Tensor const &rhs, - optional const &maybe_name) { + std::optional const &maybe_name) { std::string name = maybe_name.value_or(get_default_name(op_type)); TensorShape compute_shape = this->get_broadcast_target_shape({lhs, rhs}); @@ -135,119 +135,119 @@ Tensor ComputationGraphBuilder::element_binary( } Tensor ComputationGraphBuilder::exp(Tensor const &input, - optional const &name) { + std::optional const &name) { return this->element_unary(Op::EXP, input, name); } Tensor ComputationGraphBuilder::add(Tensor const &lhs, Tensor const &rhs, - optional const &name) { + std::optional const &name) { return this->element_binary(Op::EW_ADD, lhs, rhs, name); } Tensor ComputationGraphBuilder::subtract(Tensor const &lhs, Tensor const &rhs, - optional const &name) { + std::optional const &name) { return this->element_binary(Op::EW_SUB, lhs, rhs, name); } Tensor ComputationGraphBuilder::multiply(Tensor const &lhs, Tensor const &rhs, - optional const &name) { + std::optional const &name) { return this->element_binary(Op::EW_MUL, lhs, rhs, name); } Tensor ComputationGraphBuilder::divide(Tensor const &lhs, Tensor const &rhs, - optional const &name) { + std::optional const &name) { return this->element_binary(Op::EW_DIV, lhs, rhs, name); } Tensor ComputationGraphBuilder::max(Tensor const &lhs, Tensor const &rhs, - optional const &name) { + std::optional const &name) { return this->element_binary(Op::EW_MAX, lhs, rhs, name); } Tensor ComputationGraphBuilder::min(Tensor const &lhs, Tensor const &rhs, - optional const &name) { + std::optional const &name) { return this->element_binary(Op::EW_MIN, lhs, rhs, name); } Tensor ComputationGraphBuilder::rsqrt(Tensor const &input, - optional const &name) { + std::optional const &name) { return this->element_unary(Op::RSQRT, input, name); } Tensor ComputationGraphBuilder::pow(Tensor const &input, float exponent, - optional const &name) { + std::optional const &name) { return this->element_scalar_unary(Op::POW, input, exponent, name); } Tensor ComputationGraphBuilder::scalar_multiply( - Tensor const &input, float scalar, optional const &name) { + Tensor const &input, float scalar, std::optional const &name) { return this->element_scalar_unary(Op::SCALAR_MULTIPLY, input, scalar, name); } Tensor ComputationGraphBuilder::scalar_add(Tensor const &input, float scalar, - optional const &name) { + std::optional const &name) { return this->element_scalar_unary(Op::SCALAR_ADD, input, scalar, name); } Tensor ComputationGraphBuilder::scalar_sub(Tensor const &lhs, float rhs, - optional const &name) { + std::optional const &name) { return this->element_scalar_unary(Op::SCALAR_SUB, lhs, rhs, name); } Tensor ComputationGraphBuilder::scalar_truediv(Tensor const &numerator, float denominator, - optional const &name) { + std::optional const &name) { return this->element_scalar_unary( Op::SCALAR_TRUE_DIV, numerator, denominator, name); } Tensor ComputationGraphBuilder::sin(Tensor const &input, - optional const &name) { + std::optional const &name) { return this->element_unary(Op::SIN, input, name); } Tensor ComputationGraphBuilder::cos(Tensor const &input, - optional const &name) { + std::optional const &name) { return this->element_unary(Op::COS, input, name); } Tensor ComputationGraphBuilder::relu(Tensor const &input, - optional const &name) { + std::optional const &name) { return this->element_unary(Op::RELU, input, name); } Tensor ComputationGraphBuilder::identity(Tensor const &input, - optional const &name) { + std::optional const &name) { return this->element_unary(Op::IDENTITY, input, name); } Tensor ComputationGraphBuilder::gelu(Tensor const &input, - optional const &name) { + std::optional const &name) { return this->element_unary(Op::GELU, input, name); } Tensor ComputationGraphBuilder::sigmoid(Tensor const &input, - optional const &name) { + std::optional const &name) { return this->element_unary(Op::SIGMOID, input, name); } Tensor ComputationGraphBuilder::tanh(Tensor const &input, - optional const &name) { + std::optional const &name) { return this->element_unary(Op::TANH, input, name); } Tensor ComputationGraphBuilder::elu(Tensor const &input, - optional const &name) { + std::optional const &name) { return this->element_unary(Op::ELU, input, name); } @@ -260,13 +260,13 @@ Tensor ComputationGraphBuilder::conv2d( int strideW, int paddingH, int paddingW, - optional const &activation, + std::optional const &activation, int groups, bool use_bias, - optional kernel_initializer, - optional bias_initializer, - optional kernel_regularizer, - optional const &maybe_name) { + std::optional const &kernel_initializer, + std::optional const &bias_initializer, + std::optional const &kernel_regularizer, + std::optional const &maybe_name) { Conv2DAttrs attrs = {outChannels, kernelH, kernelW, @@ -284,7 +284,7 @@ Tensor ComputationGraphBuilder::conv2d( Layer layer = {attrs, name}; TensorShape output_shape = get_output_shape(attrs, input); - std::vector>> weights; + std::vector>> weights; weights.push_back({get_kernel_shape(attrs, input), kernel_initializer}); @@ -299,7 +299,7 @@ Tensor ComputationGraphBuilder::dropout(Tensor const &x, float rate, unsigned long long seed, - optional const &maybe_name) { + std::optional const &maybe_name) { DropoutAttrs attrs = {rate, seed}; std::string name = maybe_name.value_or(get_default_name(attrs)); @@ -317,8 +317,8 @@ Tensor ComputationGraphBuilder::embedding( int outDim, AggregateOp aggr, DataType dtype, - optional kernel_initializer, - optional const &maybe_name) { + std::optional const &kernel_initializer, + std::optional const &maybe_name) { EmbeddingAttrs attrs = {num_entries, outDim, aggr, dtype}; std::string name = maybe_name.value_or(get_default_name(attrs)); @@ -336,7 +336,7 @@ std::vector ComputationGraphBuilder::gather(Tensor const &input, Tensor const &index, ff_dim_t dim, - optional const &maybe_name) { + std::optional const &maybe_name) { GatherAttrs attrs = {dim}; std::string name = maybe_name.value_or(get_default_name(attrs)); @@ -370,7 +370,7 @@ std::vector get_shape(std::vector const &) { // std::vector const &exp_preds, // int n, // float lambda_bal, -// optional const &maybe_name) { +// std::optional const &maybe_name) { // AggregateAttrs attrs = {n, lambda_bal}; // std::string name = maybe_name.value_or(get_default_name(attrs)); @@ -389,7 +389,7 @@ std::vector get_shape(std::vector const &) { // } Tensor ComputationGraphBuilder::batch_norm( - Tensor const &input, bool relu, optional const &maybe_name) { + Tensor const &input, bool relu, std::optional const &maybe_name) { BatchNormAttrs attrs = BatchNormAttrs{relu}; std::string name = maybe_name.value_or(get_default_name(attrs)); diff --git a/lib/pcg/src/device_id.cc b/lib/pcg/src/device_id.cc index 64be75667a..c615736991 100644 --- a/lib/pcg/src/device_id.cc +++ b/lib/pcg/src/device_id.cc @@ -1,13 +1,14 @@ #include "pcg/device_id.h" #include +#include "utils/exception.h" namespace FlexFlow { DeviceType get_device_type(device_id_t const &id) { - if (holds_alternative(id)) { + if (std::holds_alternative(id)) { return DeviceType::GPU; } else { - assert(holds_alternative(id)); + assert(std::holds_alternative(id)); return DeviceType::CPU; } } diff --git a/lib/pcg/src/layer.cc b/lib/pcg/src/layer.cc index 27d5b31003..00fb07a8c5 100644 --- a/lib/pcg/src/layer.cc +++ b/lib/pcg/src/layer.cc @@ -3,7 +3,7 @@ namespace FlexFlow { Layer::Layer(CompGraphOperatorAttrs const &_attrs, - optional const &_name) + std::optional const &_name) : attrs(_attrs), name(_name) {} } // namespace FlexFlow diff --git a/lib/pcg/src/operator.cc b/lib/pcg/src/operator.cc index 8c79c67464..92ece9a2bf 100644 --- a/lib/pcg/src/operator.cc +++ b/lib/pcg/src/operator.cc @@ -3,7 +3,7 @@ namespace FlexFlow { Operator::Operator(PCGOperatorAttrs const &attrs, - optional const &name) + std::optional const &name) : attrs(attrs) {} Operator::operator PCGOperatorAttrs() const { diff --git a/lib/pcg/src/parallel_tensor.cc b/lib/pcg/src/parallel_tensor.cc index a8d7b15ea9..19dc1e96d3 100644 --- a/lib/pcg/src/parallel_tensor.cc +++ b/lib/pcg/src/parallel_tensor.cc @@ -5,8 +5,8 @@ namespace FlexFlow { ParallelTensor::ParallelTensor(ParallelTensorDims const &dims, DataType data_type, CreateGrad create_gradients, - optional sync_type, - optional initializer) + std::optional sync_type, + std::optional initializer) : dims(dims), data_type(data_type), sync_type(sync_type), initializer(initializer), create_gradients(create_gradients) {} diff --git a/lib/runtime/src/serialization.h b/lib/runtime/src/serialization.h index 53edb09075..2c71582b5e 100644 --- a/lib/runtime/src/serialization.h +++ b/lib/runtime/src/serialization.h @@ -106,11 +106,11 @@ struct is_trivially_serializable> : is_trivially_serializable {}; template -struct is_trivially_serializable> - : elements_satisfy> {}; +struct is_trivially_serializable> + : elements_satisfy> {}; template -struct is_trivially_serializable> : is_trivially_serializable {}; +struct is_trivially_serializable> : is_trivially_serializable {}; template struct std_array_size_helper; @@ -146,7 +146,7 @@ static_assert(is_trivially_serializable::value, ""); static_assert(is_trivially_serializable::value, ""); static_assert(is_trivially_serializable::value, ""); static_assert(is_trivially_serializable::value, ""); -static_assert(is_trivially_serializable>::value, ""); +static_assert(is_trivially_serializable>::value, ""); static_assert(std::is_same, std::tuple>::value, ""); diff --git a/lib/substitutions/src/substitution.cc b/lib/substitutions/src/substitution.cc index 72c9248e6c..dd28a9aa5d 100644 --- a/lib/substitutions/src/substitution.cc +++ b/lib/substitutions/src/substitution.cc @@ -226,7 +226,7 @@ Operator get_operator_attrs(SubParallelComputationGraph const &graph, get(assignments.at(OperatorAttributeKey::USE_BIAS)), get(assignments.at(OperatorAttributeKey::DATA_TYPE)), get(assignments.at(OperatorAttributeKey::ACTIVATION)), - get>( + get>( assignments.at(OperatorAttributeKey::REGULARIZER))}, nullopt); case Op::MULTIHEAD_ATTENTION: diff --git a/lib/utils/CMakeLists.txt b/lib/utils/CMakeLists.txt index ac23248db6..a0d77b9f76 100644 --- a/lib/utils/CMakeLists.txt +++ b/lib/utils/CMakeLists.txt @@ -8,14 +8,10 @@ ff_add_library( PRIVATE_INCLUDE src/ DEPS - optional expected - variant visit_struct fmt - invoke json - any cuda ) diff --git a/lib/utils/include/utils/containers.decl.h b/lib/utils/include/utils/containers.decl.h index 8ad65a4488..84fd4a5acc 100644 --- a/lib/utils/include/utils/containers.decl.h +++ b/lib/utils/include/utils/containers.decl.h @@ -2,7 +2,6 @@ #define _FLEXFLOW_UTILS_INCLUDE_UTILS_CONTAINERS_DECL_H #include "utils/bidict.h" -#include "utils/invoke.h" #include "utils/optional.decl" #include "utils/required_core.h" #include "utils/type_traits_core.h" @@ -119,14 +118,14 @@ template std::unordered_set without_order(C const &c); template -optional index_of(Container const &c, Element const &e); +std::optional index_of(Container const &c, Element const &e); template std::unordered_set intersection(std::unordered_set const &l, std::unordered_set const &r); template -optional intersection(C const &c); +std::optional intersection(C const &c); template bool are_disjoint(std::unordered_set const &l, @@ -146,13 +145,13 @@ bidict merge_maps(bidict const &lhs, bidict const &rhs); template , - typename V = invoke_result_t> + typename V = std::invoke_result_t> std::unordered_map generate_map(C const &c, F const &f); template , - typename V = invoke_result_t> + typename V = std::invoke_result_t> bidict generate_bidict(C const &c, F const &f); template @@ -189,7 +188,7 @@ std::unordered_set std::unordered_set const &input); template -optional maybe_get_only(C const &c); +std::optional maybe_get_only(C const &c); template typename C::value_type get_only(C const &c); @@ -204,7 +203,7 @@ template void extend(std::unordered_set &lhs, C const &rhs); template -void extend(C &lhs, optional const &e); +void extend(C &lhs, std::optional const &e); template bool all_of(C const &c, F const &f); @@ -240,7 +239,7 @@ std::unordered_set transform(std::unordered_set const &v, F const &f); template std::string transform(std::string const &s, F const &f); -template > +template > std::vector repeat(int n, F const &f); template @@ -256,7 +255,7 @@ std::vector flatmap(std::vector const &v, F const &f); template >> + typename Out = get_element_type_t>> std::unordered_set flatmap(std::unordered_set const &v, F const &f); template @@ -292,12 +291,12 @@ template T reversed(T const &t); template -std::vector value_all(std::vector> const &v); +std::vector value_all(std::vector> const &v); template std::vector subvec(std::vector const &v, - optional const &maybe_start, - optional const &maybe_end); + std::optional const &maybe_start, + std::optional const &maybe_end); template struct reversed_container_t; diff --git a/lib/utils/include/utils/containers.h b/lib/utils/include/utils/containers.h index 679586ba69..cdf4591cdb 100644 --- a/lib/utils/include/utils/containers.h +++ b/lib/utils/include/utils/containers.h @@ -3,11 +3,9 @@ #include "bidict.h" #include "containers.decl.h" -#include "invoke.h" #include "required_core.h" #include "type_traits_core.h" #include "utils/exception.h" -#include "utils/optional.h" #include "utils/type_traits.h" #include #include @@ -244,10 +242,10 @@ std::unordered_set without_order(C const &c) { } template -tl::optional index_of(Container const &c, Element const &e) { +std::optional index_of(Container const &c, Element const &e) { auto it = std::find(c.cbegin(), c.cend(), e); if (it == c.cend()) { - return tl::nullopt; + return std::nullopt; } else { return std::distance(c.cbegin(), it); } @@ -266,8 +264,8 @@ std::unordered_set intersection(std::unordered_set const &l, } template -optional intersection(C const &c) { - optional result; +std::optional intersection(C const &c) { + std::optional result; for (T const &t : c) { result = intersection(result.value_or(t), t); } @@ -420,11 +418,11 @@ std::unordered_set } template -optional maybe_get_only(C const &c) { +std::optional maybe_get_only(C const &c) { if (c.size() == 1) { return *c.cbegin(); } else { - return nullopt; + return std::nullopt; } } @@ -454,7 +452,7 @@ void extend(std::unordered_set &lhs, C const &rhs) { } template -void extend(C &lhs, optional const &e) { +void extend(C &lhs, std::optional const &e) { if (e.has_value()) { return extend(lhs, e.value()); } @@ -570,7 +568,7 @@ struct get_element_type { }; template -struct get_element_type> { +struct get_element_type> { using type = T; }; @@ -666,8 +664,8 @@ T reversed(T const &t) { } template -std::vector value_all(std::vector> const &v) { - return transform(v, [](optional const &element) { +std::vector value_all(std::vector> const &v) { + return transform(v, [](std::optional const &element) { return unwrap(element, [] { throw mk_runtime_error( "Encountered element without value in call to value_all"); @@ -677,8 +675,8 @@ std::vector value_all(std::vector> const &v) { template std::vector subvec(std::vector const &v, - optional const &maybe_start, - optional const &maybe_end) { + std::optional const &maybe_start, + std::optional const &maybe_end) { auto begin_iter = v.cbegin(); auto end_iter = v.cend(); diff --git a/lib/utils/include/utils/disjoint_set.h b/lib/utils/include/utils/disjoint_set.h index e0a3aaa5ee..3ae5f7c6c8 100644 --- a/lib/utils/include/utils/disjoint_set.h +++ b/lib/utils/include/utils/disjoint_set.h @@ -12,19 +12,19 @@ namespace FlexFlow { template class m_disjoint_set { public: - void m_union(optional const &l, optional const &r) { + void m_union(std::optional const &l, std::optional const &r) { this->add_node_if_missing(l); this->add_node_if_missing(r); - optional const ll = this->find(l); - optional const rr = this->find(r); + std::optional const ll = this->find(l); + std::optional const rr = this->find(r); if (ll != rr) { this->mapping[ll] = rr; } } - optional const find(optional const &t) const { + std::optional const find(std::optional const &t) const { this->add_node_if_missing(t); - optional const parent = this->mapping.at(t); + std::optional const parent = this->mapping.at(t); if (!parent.has_value()) { return t; } else { @@ -33,18 +33,18 @@ class m_disjoint_set { } private: - void add_node_if_missing(optional const &t) const { + void add_node_if_missing(std::optional const &t) const { if (mapping.find(t) == mapping.end()) { - mapping[t] = nullopt; + mapping[t] = std::nullopt; } } - mutable std::unordered_map, optional> mapping; + mutable std::unordered_map, std::optional> mapping; }; // Custom comparator for optional template struct OptionalComparator { - bool operator()(optional const &lhs, optional const &rhs) const { + bool operator()(std::optional const &lhs, std::optional const &rhs) const { if (!lhs.has_value() || !rhs.has_value()) { return false; } @@ -55,34 +55,34 @@ struct OptionalComparator { template > class disjoint_set { public: - void m_union(optional const &l, optional const &r) const { + void m_union(std::optional const &l, std::optional const &r) const { this->nodes.insert(l); this->nodes.insert(r); this->ds.m_union(this->get_node(l), this->get_node(r)); } - optional const find(optional const &t) const { + std::optional const find(std::optional const &t) const { this->nodes.insert(t); // Make sure the node is in the set return this->ds.find(this->get_node(t)); } - std::map, optional, Compare> get_mapping() const { - std::map, optional, Compare> mapping; - for (optional const &t : this->nodes) { + std::map, std::optional, Compare> get_mapping() const { + std::map, std::optional, Compare> mapping; + for (std::optional const &t : this->nodes) { mapping[t] = this->ds.find(t); } return mapping; } private: - optional const get_node(optional const &t) const { + std::optional const get_node(std::optional const &t) const { auto it = this->nodes.find(t); assert(it != this->nodes.end()); return *it; } mutable m_disjoint_set ds; - mutable std::set, Compare> + mutable std::set, Compare> nodes; // Note(lambda): make mutable to allow using ds->find() to be const // because while the result is invariant to path compression, etc. }; diff --git a/lib/utils/include/utils/dot_file.h b/lib/utils/include/utils/dot_file.h index 9529c659e2..6cdc78f6d4 100644 --- a/lib/utils/include/utils/dot_file.h +++ b/lib/utils/include/utils/dot_file.h @@ -2,7 +2,6 @@ #define _DOT_FILE_H #include "record_formatter.h" -#include "tl/optional.hpp" #include #include #include @@ -20,9 +19,9 @@ class DotFile { std::map node_ids; std::unordered_map> subgraphs; std::unordered_map> subgraph_children; - std::unordered_map> subgraph_parents; - tl::optional owned_fstream = tl::nullopt; - tl::optional out = tl::nullopt; + std::unordered_map> subgraph_parents; + std::optional owned_fstream = std::nullopt; + std::ostream *out = nullptr; std::string get_node_name(size_t node_id) const { std::ostringstream s; s << "node" << node_id; @@ -52,7 +51,7 @@ class DotFile { DotFile(std::string const &filename) : owned_fstream(filename) { this->start_output(); } - DotFile(std::ostream &s) : node_id(0), out(s) { + DotFile(std::ostream &s) : node_id(0), out(&s) { this->start_output(); } @@ -113,7 +112,7 @@ class DotFile { this->get_ostream().flush(); } - size_t add_subgraph(tl::optional parent_id = tl::nullopt) { + size_t add_subgraph(std::optional parent_id = std::nullopt) { size_t subgraph = this->subgraph_id; subgraph_id++; this->subgraph_children[subgraph]; @@ -134,7 +133,7 @@ class DotFile { throw std::runtime_error(oss.str()); } this->subgraphs[subgraph].insert(this->node_ids.at(node)); - tl::optional parent = this->subgraph_parents.at(subgraph); + std::optional parent = this->subgraph_parents.at(subgraph); if (parent.has_value()) { this->add_node_to_subgraph(node, parent.value()); } diff --git a/lib/utils/include/utils/fmt.h b/lib/utils/include/utils/fmt.h index ddf5b00355..58982d6f36 100644 --- a/lib/utils/include/utils/fmt.h +++ b/lib/utils/include/utils/fmt.h @@ -40,15 +40,15 @@ operator<<(std::ostream &s, T const &t) { #__VA_ARGS__ " must be fmtable"); // This will not -template -typename std::enable_if::value, - std::ostream &>::type - operator<<(std::ostream &s, T const &t) { - // CHECK_FMTABLE(T); - - std::string result = fmt::to_string(t); - return s << result; -} +/* template */ +/* typename std::enable_if::value, */ +/* std::ostream &>::type */ +/* operator<<(std::ostream &s, T const &t) { */ +/* // CHECK_FMTABLE(T); */ + +/* std::string result = fmt::to_string(t); */ +/* return s << result; */ +/* } */ // template // typename std::enable_if::value, std::ostream &>::type diff --git a/lib/utils/include/utils/graph/algorithms.h b/lib/utils/include/utils/graph/algorithms.h index 4b08fd5e4a..854b1bab52 100644 --- a/lib/utils/include/utils/graph/algorithms.h +++ b/lib/utils/include/utils/graph/algorithms.h @@ -174,12 +174,12 @@ struct GetDstNodeFunctor { }; template -Node get_src_node(variant const &t) { +Node get_src_node(std::variant const &t) { return visit(GetSrcNodeFunctor{}, t); } template -Node get_dst_node(variant const &t) { +Node get_dst_node(std::variant const &t) { return visit(GetDstNodeFunctor{}, t); } @@ -203,12 +203,12 @@ struct GetDstIdxFunctor { }; template -NodePort get_src_idx(variant const &t) { +NodePort get_src_idx(std::variant const &t) { return visit(GetSrcIdxFunctor{}, t); } template -NodePort get_dst_idx(variant const &t) { +NodePort get_dst_idx(std::variant const &t) { return visit(GetDstIdxFunctor{}, t); } @@ -229,8 +229,8 @@ std::unordered_set get_open_sources(OpenMultiDiGraphView const &g); std::unordered_set get_open_sinks(OpenMultiDiGraphView const &g); bool is_acyclic(MultiDiGraphView const &, std::unordered_set const &); -tl::optional is_acyclic(DiGraphView const &); -tl::optional is_acyclic(MultiDiGraphView const &); +std::optional is_acyclic(DiGraphView const &); +std::optional is_acyclic(MultiDiGraphView const &); std::unordered_map> get_dominators(DiGraphView const &); @@ -240,14 +240,14 @@ std::unordered_set get_dominators(DiGraphView const &, std::unordered_map> get_post_dominators(DiGraphView const &); -std::unordered_map> +std::unordered_map> get_imm_dominators(DiGraphView const &); -std::unordered_map> +std::unordered_map> get_imm_post_dominators(DiGraphView const &); -tl::optional get_imm_post_dominator(DiGraphView const &, Node const &); -tl::optional get_imm_post_dominator(MultiDiGraphView const &, +std::optional get_imm_post_dominator(DiGraphView const &, Node const &); +std::optional get_imm_post_dominator(MultiDiGraphView const &, Node const &); -tl::optional get_imm_post_dominator(DiGraphView const &, +std::optional get_imm_post_dominator(DiGraphView const &, std::unordered_set const &); std::vector @@ -328,8 +328,8 @@ void export_as_dot( DotFile &, DiGraphView const &, std::function const &, - tl::optional const &> = - tl::nullopt); + std::optional> = + std::nullopt); } // namespace FlexFlow diff --git a/lib/utils/include/utils/graph/labelled/output_labelled_open.h b/lib/utils/include/utils/graph/labelled/output_labelled_open.h index cb41a7158a..eb406d1804 100644 --- a/lib/utils/include/utils/graph/labelled/output_labelled_open.h +++ b/lib/utils/include/utils/graph/labelled/output_labelled_open.h @@ -129,12 +129,12 @@ struct OutputLabelledOpenMultiDiGraph } template - EdgeLabel const &at(variant const &e) const { + EdgeLabel const &at(std::variant const &e) const { return visit([&](auto const &e) -> auto const & { return this->at(e); }, e); } template - EdgeLabel &at(variant const &e) { + EdgeLabel &at(std::variant const &e) { return visit([&](auto const &e) -> auto & { return this->at(e); }, e); } diff --git a/lib/utils/include/utils/graph/open_edge.h b/lib/utils/include/utils/graph/open_edge.h index e83c58196b..37e98a419d 100644 --- a/lib/utils/include/utils/graph/open_edge.h +++ b/lib/utils/include/utils/graph/open_edge.h @@ -6,11 +6,11 @@ namespace FlexFlow { using OpenMultiDiEdge = - variant; + std::variant; -using DownwardOpenMultiDiEdge = variant; +using DownwardOpenMultiDiEdge = std::variant; -using UpwardOpenMultiDiEdge = variant; +using UpwardOpenMultiDiEdge = std::variant; bool is_input_edge(OpenMultiDiEdge const &); bool is_output_edge(OpenMultiDiEdge const &); diff --git a/lib/utils/include/utils/graph/query_set.h b/lib/utils/include/utils/graph/query_set.h index 8192949cb0..30817e2184 100644 --- a/lib/utils/include/utils/graph/query_set.h +++ b/lib/utils/include/utils/graph/query_set.h @@ -4,8 +4,8 @@ #include "utils/bidict.h" #include "utils/containers.decl.h" #include "utils/exception.h" -#include "utils/optional.h" #include +#include namespace FlexFlow { @@ -16,7 +16,7 @@ struct query_set { query_set(std::unordered_set const &query) : query(query) {} - query_set(optional> const &query) : query(query) {} + query_set(std::optional> const &query) : query(query) {} query_set(std::initializer_list const &l) : query_set(std::unordered_set{l}) {} @@ -43,11 +43,11 @@ struct query_set { } static query_set matchall() { - return {nullopt}; + return {std::nullopt}; } private: - optional> query; + std::optional> query; }; template diff --git a/lib/utils/include/utils/graph/serialparallel.h b/lib/utils/include/utils/graph/serialparallel.h index b58281de7d..47bcb4031e 100644 --- a/lib/utils/include/utils/graph/serialparallel.h +++ b/lib/utils/include/utils/graph/serialparallel.h @@ -4,7 +4,7 @@ #include "digraph.h" #include "multidigraph.h" #include "utils/optional.h" -#include "utils/variant.h" +#include #include namespace FlexFlow { @@ -12,22 +12,22 @@ namespace FlexFlow { Node find_source_node(DiGraphView const &); Node find_sink_node(DiGraphView const &); -optional find_bottleneck_node(DiGraphView const &); +std::optional find_bottleneck_node(DiGraphView const &); struct Parallel; struct Serial { - std::vector> children; + std::vector> children; }; struct Parallel { - std::vector> children; + std::vector> children; }; FF_VISITABLE_STRUCT_NONSTANDARD_CONSTRUCTION(Parallel, children); FF_VISITABLE_STRUCT_NONSTANDARD_CONSTRUCTION(Serial, children); -using SerialParallelDecomposition = variant; +using SerialParallelDecomposition = std::variant; SerialParallelDecomposition get_serial_parallel_decomposition(DiGraphView const &); diff --git a/lib/utils/include/utils/graph/traversal.h b/lib/utils/include/utils/graph/traversal.h index a4101de64d..3c3992cd53 100644 --- a/lib/utils/include/utils/graph/traversal.h +++ b/lib/utils/include/utils/graph/traversal.h @@ -76,7 +76,7 @@ struct bfs_iterator { bfs_iterator(DiGraphView const &, std::queue const &, - optional> const &); + std::optional> const &); bfs_iterator(DiGraphView const &, std::unordered_set const &starting_points); @@ -91,7 +91,7 @@ struct bfs_iterator { private: DiGraphView graph; std::queue q; - optional> seen; + std::optional> seen; }; struct CheckedDFSView { diff --git a/lib/utils/include/utils/graph/views.h b/lib/utils/include/utils/graph/views.h index 776a72e6d5..e891a948f0 100644 --- a/lib/utils/include/utils/graph/views.h +++ b/lib/utils/include/utils/graph/views.h @@ -6,7 +6,6 @@ #include "labelled_graphs.h" #include "multidigraph.h" #include "open_graphs.h" -#include "tl/optional.hpp" #include "undirected.h" #include "utils/bidict.h" #include "utils/graph/digraph_interfaces.h" @@ -217,8 +216,8 @@ struct SingleSourceNodeView : public IDiGraphView { private: DiGraphView g; - optional singleton_src; - optional joined_view; + std::optional singleton_src; + std::optional joined_view; std::unique_ptr added_edges_view; }; diff --git a/lib/utils/include/utils/invoke.h b/lib/utils/include/utils/invoke.h deleted file mode 100644 index cee1eaee0e..0000000000 --- a/lib/utils/include/utils/invoke.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _FLEXFLOW_UTILS_INCLUDE_UTILS_INVOKE_H -#define _FLEXFLOW_UTILS_INCLUDE_UTILS_INVOKE_H - -#include "invoke.hpp/invoke.hpp" - -namespace FlexFlow { - -using namespace ::invoke_hpp; - -} - -#endif diff --git a/lib/utils/include/utils/json.h b/lib/utils/include/utils/json.h index a753c52daa..f9ed105ebb 100644 --- a/lib/utils/include/utils/json.h +++ b/lib/utils/include/utils/json.h @@ -149,7 +149,7 @@ struct VariantToJsonFunctor { }; template -void variant_to_json(json &j, variant const &v) { +void variant_to_json(json &j, std::variant const &v) { visit(::FlexFlow::VariantToJsonFunctor{j}, v.value); } @@ -160,8 +160,8 @@ struct VariantFromJsonFunctor { json const &j; template - optional operator()(std::integral_constant const &) const { - using Type = typename variant_alternative::type; + std::optional operator()(std::integral_constant const &) const { + using Type = typename std::variant_alternative::type; if (visit_struct::get_name()) { return j.at("value").get(); @@ -170,8 +170,8 @@ struct VariantFromJsonFunctor { }; template -variant variant_from_json(json const &j) { - ::FlexFlow::VariantFromJsonFunctor<::FlexFlow::variant> func(j); +std::variant variant_from_json(json const &j) { + ::FlexFlow::VariantFromJsonFunctor> func(j); auto result = seq_map(func, seq_enumerate_args_t{}); if (!result.has_value()) { throw ::FlexFlow::mk_runtime_error("Invalid type {} found in json", @@ -219,9 +219,9 @@ struct adl_serializer< template struct adl_serializer< - ::FlexFlow::optional, + std::optional, typename std::enable_if<::FlexFlow::is_jsonable::value>::type> { - static void to_json(json &j, ::FlexFlow::optional const &t) { + static void to_json(json &j, std::optional const &t) { if (t.has_value()) { to_json(j, t.value()); } else { @@ -229,9 +229,9 @@ struct adl_serializer< } } - static void from_json(json const &j, ::FlexFlow::optional &t) { + static void from_json(json const &j, std::optional &t) { if (j == nullptr) { - t = ::FlexFlow::nullopt; + t = std::nullopt; } else { t = j.get(); } @@ -239,15 +239,15 @@ struct adl_serializer< }; template -struct adl_serializer<::FlexFlow::variant, +struct adl_serializer, typename std::enable_if<::FlexFlow::elements_satisfy< ::FlexFlow::is_json_serializable, - ::FlexFlow::variant>::value>::type> { - static void to_json(json &j, ::FlexFlow::variant const &v) { + std::variant>::value>::type> { + static void to_json(json &j, std::variant const &v) { return ::FlexFlow::variant_to_json(j, v); } - static ::FlexFlow::variant from_json(json const &j) { + static std::variant from_json(json const &j) { return ::FlexFlow::variant_from_json(j); } }; diff --git a/lib/utils/include/utils/optional.decl b/lib/utils/include/utils/optional.decl index 370026fcc0..82f4bd984d 100644 --- a/lib/utils/include/utils/optional.decl +++ b/lib/utils/include/utils/optional.decl @@ -1,17 +1,15 @@ #ifndef _FLEXFLOW_UTILS_OPTIONAL_H #define _FLEXFLOW_UTILS_OPTIONAL_H -#include "tl/optional.hpp" +#include namespace FlexFlow { -using namespace tl; - template -T const &unwrap(optional const &o, F const &f); +T const &unwrap(std::optional const &o, F const &f); template -T const &assert_unwrap(optional const &o); +T const &assert_unwrap(std::optional const &o); } // namespace FlexFlow diff --git a/lib/utils/include/utils/optional.h b/lib/utils/include/utils/optional.h index 43d2ef4104..71b6d9d975 100644 --- a/lib/utils/include/utils/optional.h +++ b/lib/utils/include/utils/optional.h @@ -8,7 +8,7 @@ namespace FlexFlow { template -T const &unwrap(optional const &o, F const &f) { +T const &unwrap(std::optional const &o, F const &f) { if (o.has_value()) { return o.value(); } else { @@ -18,7 +18,7 @@ T const &unwrap(optional const &o, F const &f) { } template -T const &assert_unwrap(optional const &o) { +T const &assert_unwrap(std::optional const &o) { assert(o.has_value()); return o.value(); } @@ -28,9 +28,9 @@ T const &assert_unwrap(optional const &o) { namespace fmt { template -struct formatter<::FlexFlow::optional> : formatter { +struct formatter<::std::optional> : formatter { template - auto format(::FlexFlow::optional const &q, FormatContext &ctx) + auto format(::std::optional const &q, FormatContext &ctx) -> decltype(ctx.out()) { std::string result; if (q.has_value()) { diff --git a/lib/utils/include/utils/sequence.h b/lib/utils/include/utils/sequence.h index 67c2e72ac1..9f6a1236c2 100644 --- a/lib/utils/include/utils/sequence.h +++ b/lib/utils/include/utils/sequence.h @@ -1,10 +1,10 @@ #ifndef _FLEXFLOW_UTILS_INCLUDE_UTILS_SEQUENCE_H #define _FLEXFLOW_UTILS_INCLUDE_UTILS_SEQUENCE_H -#include "optional.h" #include "utils/tuple.h" #include "utils/visitable_core.h" #include +#include namespace FlexFlow { @@ -119,7 +119,7 @@ auto seq_select(F const &f, int i, seq const &s) template auto seq_select(F const &f, int i, seq<> const &) -> decltype(f(std::declval>())) { - return nullopt; + return std::nullopt; } template diff --git a/lib/utils/include/utils/stack_map.h b/lib/utils/include/utils/stack_map.h index f2cdf0d88b..76e6e951df 100644 --- a/lib/utils/include/utils/stack_map.h +++ b/lib/utils/include/utils/stack_map.h @@ -2,7 +2,6 @@ #define _FLEXFLOW_UTILS_STACK_MAP_H #include "containers.h" -#include "optional.h" #include "stack_vector.h" namespace std { @@ -22,7 +21,7 @@ struct stack_map { stack_map() = default; V &operator[](K const &k) { - optional idx = get_idx(k); + std::optional idx = get_idx(k); if (!idx.has_value()) { this->contents.push_back({k, {}}); idx = this->contents.size() - 1; @@ -35,7 +34,7 @@ struct stack_map { } void insert(K const &k, V const &v) { - optional idx = get_idx(k); + std::optional idx = get_idx(k); if (!idx.has_value()) { this->contents.push_back({k, v}); } else { @@ -116,14 +115,14 @@ struct stack_map { return sorted_by(this->contents, comparator); } - optional get_idx(K const &k) const { + std::optional get_idx(K const &k) const { for (std::size_t idx = 0; idx < contents.size(); idx++) { if (contents.at(idx).first == k) { return idx; } } - return nullopt; + return std::nullopt; } stack_vector, MAXSIZE> contents; diff --git a/lib/utils/include/utils/stack_vector.h b/lib/utils/include/utils/stack_vector.h index 3d5a433725..417f2b22fb 100644 --- a/lib/utils/include/utils/stack_vector.h +++ b/lib/utils/include/utils/stack_vector.h @@ -3,7 +3,7 @@ #include "containers.h" #include "hash-utils.h" -#include "optional.h" +#include #include "utils/fmt.h" #include "utils/test_types.h" #include "utils/type_traits.h" @@ -17,18 +17,18 @@ template struct stack_vector { private: using element_type = - conditional_t::value, T, optional>; + conditional_t::value, T, std::optional>; static T const &get_value(T const &t) { return t; } - static T const &get_value(optional const &t) { + static T const &get_value(std::optional const &t) { return t.value(); } static T &get_value(T &t) { return t; } - static T &get_value(optional &t) { + static T &get_value(std::optional &t) { return t.value(); } diff --git a/lib/utils/include/utils/tuple.h b/lib/utils/include/utils/tuple.h index 202e62b5ad..e84cf65e01 100644 --- a/lib/utils/include/utils/tuple.h +++ b/lib/utils/include/utils/tuple.h @@ -1,12 +1,13 @@ #ifndef _FLEXFLOW_UTILS_TUPLE_H #define _FLEXFLOW_UTILS_TUPLE_H -#include "utils/any.h" #include "utils/exception.decl.h" #include #include #include #include +#include "utils/type_traits_core.h" +#include // Adapted from // https://github.com/bitwizeshift/BackportCpp/blob/4f33a7f9b219f169e60d8ed2fd5731a3a23288e4/include/bpstd/tuple.hpp @@ -48,11 +49,11 @@ void visit_tuple(Visitor &v, std::tuple const &tup) { struct tuple_get_visitor { tuple_get_visitor() = delete; - tuple_get_visitor(int requested_idx, any &result) + tuple_get_visitor(int requested_idx, std::any &result) : requested_idx(requested_idx), result(result) {} int requested_idx; - any &result; + std::any &result; template void operator()(int idx, T const &t) { @@ -63,13 +64,13 @@ struct tuple_get_visitor { }; template -any get(std::tuple const &t, int idx) { +std::any get(std::tuple const &t, int idx) { size_t tuple_size = std::tuple_size::value; if (idx < 0 || idx >= tuple_size) { throw mk_runtime_error( "Error: idx {} out of bounds for tuple of size {}", idx, tuple_size); } - any result; + std::any result; visit_tuple(t, tuple_get_visitor{idx, result}); return result; } diff --git a/lib/utils/include/utils/type_traits.h b/lib/utils/include/utils/type_traits.h index ee45e8dc2e..0c0408723d 100644 --- a/lib/utils/include/utils/type_traits.h +++ b/lib/utils/include/utils/type_traits.h @@ -1,7 +1,6 @@ #ifndef _FLEXFLOW_UTILS_INCLUDE_TYPE_TRAITS_H #define _FLEXFLOW_UTILS_INCLUDE_TYPE_TRAITS_H -#include "utils/invoke.h" #include "utils/metafunction.h" #include "utils/type_traits_core.h" #include "utils/visitable_core.h" diff --git a/lib/utils/include/utils/variant.h b/lib/utils/include/utils/variant.h index b1a1dc1081..cb238be324 100644 --- a/lib/utils/include/utils/variant.h +++ b/lib/utils/include/utils/variant.h @@ -1,28 +1,12 @@ #ifndef _FLEXFLOW_UTILS_VARIANT_H #define _FLEXFLOW_UTILS_VARIANT_H -#include "mpark/variant.hpp" -#include "utils/optional.h" #include "utils/type_traits.h" +#include +#include namespace FlexFlow { -/* using mp = mpark; */ - -/* template */ -/* using variant = ::mpark::variant; */ - -using namespace ::mpark; - -/* template */ -/* using optional = ::tl::optional; */ - -/* template */ -/* using get = ::mpark::get; */ - -/* template */ -/* using holds_alternative = ::mpark::holds_alternative; */ - template struct pack_contains_all_of; @@ -35,14 +19,14 @@ template struct pack_contains_all_of> : std::false_type {}; template -struct pack_contains_all_of, Needles...> +struct pack_contains_all_of, Needles...> : pack_contains_all_of, Needles...> {}; template -bool is(variant const &v) { +bool is(std::variant const &v) { static_assert(pack_contains_all_of, T, TRest...>::value, ""); - return holds_alternative(v) || is(v); + return std::holds_alternative(v) || is(v); } /* template */ @@ -54,88 +38,88 @@ bool is(variant const &v) { /* using type = mpark::variant; */ /* }; */ template