Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ workflow:

.load-modules:
before_script:
- ml vis/Graphviz/8.1.0-GCCcore-12.3.0 fpga xilinx/xrt/2.16 devel/Doxygen/1.9.7-GCCcore-12.3.0 compiler/GCC/12.3.0 devel/CMake/3.26.3-GCCcore-12.3.0
- ml vis/Graphviz/8.1.0-GCCcore-12.3.0 fpga xilinx/xrt/2.16 devel/Doxygen/1.9.7-GCCcore-12.3.0 compiler/GCC/12.3.0 devel/CMake/3.26.3-GCCcore-12.3.0 devel/Boost/1.82.0-GCC-12.3.0

build-dependencies:
id_tokens:
Expand Down
7 changes: 0 additions & 7 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
[submodule "external/mdspan"]
path = external/mdspan
url = https://github.com/kokkos/mdspan.git
[submodule "external/boost"]
path = external/boost
url = https://github.com/boostorg/boost.git
ignore = dirty
[submodule "external/json"]
path = external/json
url = https://github.com/nlohmann/json.git
Expand Down
22 changes: 4 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ include(cmake/CheckSubmodules.cmake)

# Doxygen

option(FINN_BUILD_DOC "Build documentation" OFF)

if (CMAKE_BUILD_TYPE STREQUAL "Release")
set(FINN_BUILD_DOC ON)
option(FINN_BUILD_DOC "Build documentation" ON)
else()
option(FINN_BUILD_DOC "Build documentation" OFF)
endif()

# Setup the doxygen code documentation
Expand Down Expand Up @@ -93,21 +93,7 @@ find_package(XRT REQUIRED)
find_package(OpenMP REQUIRED)

#Boost
set(Boost_DEBUG OFF)
set(Boost_NO_SYSTEM_PATHS ON)
set(BOOST_ROOT "${FINN_BASE_DIR}/deps/finn_boost")
set(BOOST_INCLUDEDIR "${FINN_BASE_DIR}/deps/finn_boost")
set(BOOST_LIBRARYDIR "${FINN_BASE_DIR}/deps/finn_boost/stage/lib/boost")
set(Boost_NAMESPACE "finnBoost")
set(FINN_SAVE_BOOST_ROOT $ENV{BOOST_ROOT})
set(ENV{BOOST_ROOT} "")
find_package(Boost 1.80.0 COMPONENTS system log log_setup program_options filesystem ${BOOST_THREAD} REQUIRED)
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
set(ENV{BOOST_ROOT} ${FINN_SAVE_BOOST_ROOT})
message(STATUS "${Boost_LIBRARIES}")

#mdspan
include_directories(SYSTEM external/mdspan/include)
find_package(Boost 1.79.0 COMPONENTS system log log_setup program_options filesystem ${BOOST_THREAD} REQUIRED)

#xsimd
add_subdirectory(external/xsimd)
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,4 @@ target_link_libraries(main PRIVATE finnc_core OpenCL xrt_coreutil uuid finnc_uti

### Known Issues

* Building against Boost results in undefined references:
* This issue is caused by namespaces leaking from inside XRT. The C++ has its own renamed (partial) boost version called finnBoost that can be used as a replacement.

Please refer to the git issues for currently known issues and possible ways to mitigate them.
41 changes: 0 additions & 41 deletions buildDependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,5 @@

#Setup
git submodule update --init --recursive
if [ ! -d "deps" ]; then
mkdir -p "deps"
else
rm -rf "deps"/*
fi
cd external/boost

#Build minimal version of boost needed for renaming
./bootstrap.sh || exit 1 #bootstrap b2 build system
./b2 headers || exit 1
./b2 tools/bcp tools/boost_install || exit 1


#Copy and rename boost
if [ ! -d "../../deps/finn_boost" ]; then
mkdir -p "../../deps/finn_boost"
else
rm -rf "../../deps/finn_boost"/*
fi

./dist/bin/bcp --namespace=finnBoost log build boost_install config predef program_options thread circular_buffer dynamic_bitset filesystem ../../deps/finn_boost/ || exit 1
cp boostcpp.jam ../../deps/finn_boost/
cp boost-build.jam ../../deps/finn_boost/
cp project-config.jam ../../deps/finn_boost/
cp bootstrap.sh ../../deps/finn_boost/

#Cleanup of submodule
./b2 --clean-all
git clean -f -x -d
git submodule foreach --recursive git clean -xfd
git reset --hard
git submodule foreach --recursive git reset --hard
cd ../../deps/finn_boost

#Build new finnBoost Version
./bootstrap.sh || exit 1 #bootstrap b2 build system for finnBoost
./b2 --without-python release || exit 1
mv stage/lib/boost-* stage/lib/boost 2>/dev/null || true

echo "Dependecies successfully build!"
echo "You can now build the finn-cpp-driver."


1 change: 0 additions & 1 deletion external/boost
Submodule boost deleted from 32da69
2 changes: 1 addition & 1 deletion external/json
Submodule json updated 795 files
1 change: 0 additions & 1 deletion external/mdspan
Submodule mdspan deleted from f84035
16 changes: 11 additions & 5 deletions src/FINNCppDriver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ add_subdirectory(utils)
add_subdirectory(core)
add_subdirectory(config)

add_executable(finn FINNDriver.cpp)
target_include_directories(finn SYSTEM PRIVATE ${XRT_INCLUDE_DIRS})
target_include_directories(finn PRIVATE ${FINN_SRC_DIR})
target_link_directories(finn PRIVATE ${XRT_LIB_CORE_LOCATION} ${XRT_LIB_OCL_LOCATION} ${BOOST_LIBRARYDIR})
target_link_libraries(finn PRIVATE finnc_core finnc_options Threads::Threads OpenCL xrt_coreutil uuid finnc_utils finn_config ${Boost_LIBRARIES} nlohmann_json::nlohmann_json OpenMP::OpenMP_CXX)
add_executable(finnhpc FINNDriver.cpp)
target_include_directories(finnhpc SYSTEM PRIVATE ${XRT_INCLUDE_DIRS})
target_include_directories(finnhpc PRIVATE ${FINN_SRC_DIR})
target_link_directories(finnhpc PRIVATE ${XRT_LIB_CORE_LOCATION} ${XRT_LIB_OCL_LOCATION} ${BOOST_LIBRARYDIR})
target_link_libraries(finnhpc PRIVATE finnc_core finnc_options Threads::Threads OpenCL xrt_coreutil uuid finnc_utils finn_config ${Boost_LIBRARIES} nlohmann_json::nlohmann_json OpenMP::OpenMP_CXX)
set_target_properties(finnhpc
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)



34 changes: 20 additions & 14 deletions src/FINNCppDriver/FINNDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ void runWithInputFile(Finn::Driver<true>& baseDriver, logger_type& logger, const
*/
void validateDriverMode(const std::string& mode) {
if (mode != "execute" && mode != "throughput") {
throw finnBoost::program_options::error_with_option_name("'" + mode + "' is not a valid driver mode!", "exec_mode");
throw boost::program_options::error_with_option_name("'" + mode + "' is not a valid driver mode!", "exec_mode");
}

FINN_LOG(Logger::getLogger(), loglevel::info) << finnMainLogPrefix() << "Driver Mode: " << mode;
Expand All @@ -404,7 +404,7 @@ void validateDriverMode(const std::string& mode) {
*/
void validateBatchSize(int batch) {
if (batch <= 0) {
throw finnBoost::program_options::error_with_option_name("Batch size must be positive, but is '" + std::to_string(batch) + "'", "batchsize");
throw boost::program_options::error_with_option_name("Batch size must be positive, but is '" + std::to_string(batch) + "'", "batchsize");
}
}

Expand All @@ -416,7 +416,7 @@ void validateBatchSize(int batch) {
void validateConfigPath(const std::string& path) {
auto configFilePath = std::filesystem::path(path);
if (!std::filesystem::exists(configFilePath)) {
throw finnBoost::program_options::error_with_option_name("Cannot find config file at " + configFilePath.string(), "configpath");
throw boost::program_options::error_with_option_name("Cannot find config file at " + configFilePath.string(), "configpath");
}

FINN_LOG(Logger::getLogger(), loglevel::info) << finnMainLogPrefix() << "Config file found at " << configFilePath.string();
Expand All @@ -431,14 +431,14 @@ void validateInputPath(const std::vector<std::string>& path) {
for (auto&& elem : path) {
auto inputFilePath = std::filesystem::path(elem);
if (!std::filesystem::exists(inputFilePath)) {
throw finnBoost::program_options::error_with_option_name("Cannot find input file at " + inputFilePath.string());
throw boost::program_options::error_with_option_name("Cannot find input file at " + inputFilePath.string());
}
FINN_LOG(Logger::getLogger(), loglevel::info) << finnMainLogPrefix() << "Input file found at " << inputFilePath.string();
}
}


namespace po = finnBoost::program_options;
namespace po = boost::program_options;

/**
* @brief Main entrypoint for the frontend of the C++ Finn driver
Expand All @@ -454,22 +454,28 @@ int main(int argc, char* argv[]) {
try {
// Command Line Argument Parser
po::options_description desc{"Options"};
//clang-format off
// clang-format off
desc.add_options()("help,h", "Display help")("exec_mode,e", po::value<std::string>()->default_value("throughput")->notifier(&validateDriverMode),
R"(Please select functional verification ("execute") or throughput test ("throughput")")("configpath,c", po::value<std::string>()->required()->notifier(&validateConfigPath),
"Required: Path to the config.json file emitted by the FINN compiler")(
"input,i", po::value<std::vector<std::string>>()->multitoken()->composing()->notifier(&validateInputPath), "Path to one or more input files (npy format). Only required if mode is set to \"file\"")(
"output,o", po::value<std::vector<std::string>>()->multitoken()->composing(), "Path to one or more output files (npy format). Only required if mode is set to \"file\"")(
"batchsize,b", po::value<int>()->default_value(1)->notifier(&validateBatchSize), "Number of samples for inference");
//clang-format on
R"(Please select functional verification ("execute") or throughput test ("throughput")")("configpath,c", po::value<std::string>()->required()->notifier(&validateConfigPath),
"Required: Path to the config.json file emitted by the FINN compiler")(
"input,i", po::value<std::vector<std::string>>()->multitoken()->composing()->notifier(&validateInputPath), "Path to one or more input files (npy format). Only required if mode is set to \"file\"")(
"output,o", po::value<std::vector<std::string>>()->multitoken()->composing(), "Path to one or more output files (npy format). Only required if mode is set to \"file\"")(
"batchsize,b", po::value<int>()->default_value(1)->notifier(&validateBatchSize), "Number of samples for inference")("check", "Outputs the compile time configuration");
// clang-format on
po::variables_map varMap;
po::store(po::parse_command_line(argc, argv, desc), varMap);

// Display help screen
// Help option has to be processed before po::notify call to not enforce required options in combination with help
if (varMap.count("help") != 0) {
FINN_LOG(logger, loglevel::info) << desc;
return 1;
std::cout << desc << "\n";
return 0;
}

if (varMap.count("check") != 0) {
std::cout << "input_t: " << Finn::type_name<InputFinnType>() << "\n";
std::cout << "output_t: " << Finn::type_name<OutputFinnType>() << "\n";
return 0;
}

po::notify(varMap);
Expand Down
9 changes: 8 additions & 1 deletion src/FINNCppDriver/config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@ configure_file("${PROJECT_SOURCE_DIR}/src/FINNCppDriver/config/CompilationOption


add_library(finn_config INTERFACE)
target_include_directories(finn_config INTERFACE "${PROJECT_BINARY_DIR}/src")
target_include_directories(finn_config INTERFACE "${PROJECT_BINARY_DIR}/src")

set_target_properties(finn_config
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
13 changes: 13 additions & 0 deletions src/FINNCppDriver/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,16 @@ target_link_directories(finnc_core_test PRIVATE ${BOOST_LIBRARYDIR})
# target_link_directories(finnc_core_test PUBLIC ${XRT_LIB_CORE_LOCATION})
# target_link_directories(finnc_core_test PUBLIC ${XRT_LIB_OCL_LOCATION})
# target_link_libraries(finnc_core_test PUBLIC ${Boost_LIBRARIES} finnc_options finnc_utils Threads::Threads OpenCL xrt_coreutil uuid)

set_target_properties(finnc_core
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
set_target_properties(finnc_core_test
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
2 changes: 1 addition & 1 deletion src/FINNCppDriver/core/DeviceBuffer/DeviceBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ namespace Finn {
*
* @return std::string
*/
virtual std::string loggerPrefix() { return "[" + finnBoost::typeindex::type_id<decltype(this)>().pretty_name() + " - " + name + "] "; }
virtual std::string loggerPrefix() { return "[" + boost::typeindex::type_id<decltype(this)>().pretty_name() + " - " + name + "] "; }

/**
* @brief Synchronizes the Buffer data to the data on the FPGA
Expand Down
6 changes: 6 additions & 0 deletions src/FINNCppDriver/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ add_library(finnc_utils SHARED ${UTILS_SRC})
target_link_libraries(finnc_utils PUBLIC finnc_options ${Boost_LIBRARIES} nlohmann_json::nlohmann_json)
target_link_directories(finnc_utils PRIVATE ${BOOST_LIBRARYDIR})
target_include_directories(finnc_utils PRIVATE ${FINN_SRC_DIR})
set_target_properties(finnc_utils
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
76 changes: 75 additions & 1 deletion src/FINNCppDriver/utils/FinnDatatypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file FinnDatatypes.hpp
* @author Linus Jungemann (linus.jungemann@uni-paderborn.de) and others
* @brief Implements a (mostly) constexpr typesystem for FINN Datatypes
* @version 0.1
* @version 0.2
* @date 2023-10-31
*
* @copyright Copyright (c) 2023
Expand All @@ -17,10 +17,84 @@

#include <concepts>
#include <limits>
#include <source_location>
#include <string_view>
#include <type_traits>
#include <utility>

namespace Finn {

/**
* @brief Get the name of a type as a string_view
*
* @tparam T The type to get the name of
* @return constexpr std::string_view The name of the type as a string
*/
template<typename T>
constexpr std::string_view type_name();

/**
* @brief Specialization of type_name for void
*
* @return constexpr std::string_view "void"
*/
template<>
constexpr std::string_view type_name<void>() {
return "void";
}

namespace detail {

/**
* @brief Type used as a probe for determining type name extraction details
*/
using type_name_prober = void;

/**
* @brief Gets the wrapped function name which contains the type name
*
* @tparam T The type to extract the name for
* @return constexpr std::string_view The function signature containing the type name
*/
template<typename T>
constexpr std::string_view wrapped_type_name() {
return std::source_location::current().function_name();
}

/**
* @brief Calculates the length of the prefix before the type name in the function signature
*
* @return constexpr std::size_t Length of the prefix
*/
constexpr std::size_t wrapped_type_name_prefix_length() { return wrapped_type_name<type_name_prober>().find(type_name<type_name_prober>()); }

/**
* @brief Calculates the length of the suffix after the type name in the function signature
*
* @return constexpr std::size_t Length of the suffix
*/
constexpr std::size_t wrapped_type_name_suffix_length() { return wrapped_type_name<type_name_prober>().length() - wrapped_type_name_prefix_length() - type_name<type_name_prober>().length(); }

} // namespace detail

/**
* @brief Get the name of a type as a string_view
*
* This implementation extracts the type name from the function signature
* provided by std::source_location.
*
* @tparam T The type to get the name of
* @return constexpr std::string_view The name of the type
*/
template<typename T>
constexpr std::string_view type_name() {
constexpr auto wrapped_name = detail::wrapped_type_name<T>();
constexpr auto prefix_length = detail::wrapped_type_name_prefix_length();
constexpr auto suffix_length = detail::wrapped_type_name_suffix_length();
constexpr auto type_name_length = wrapped_name.length() - prefix_length - suffix_length;
return wrapped_name.substr(prefix_length, type_name_length);
}

/**
* @brief Concept for an integral type
*
Expand Down
6 changes: 3 additions & 3 deletions src/FINNCppDriver/utils/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ logger_type& Logger::getLogger(bool console) {
}

Logger::Logger(bool console) {
auto backend = finnBoost::make_shared<backend_type>(kw::file_name = "finnLog_%N.log", kw::rotation_size = 10 * 1024 * 1024, kw::time_based_rotation = bl::sinks::file::rotation_at_time_point(0, 0, 0), kw::auto_flush = true);
auto backend = boost::make_shared<backend_type>(kw::file_name = "finnLog_%N.log", kw::rotation_size = 10 * 1024 * 1024, kw::time_based_rotation = bl::sinks::file::rotation_at_time_point(0, 0, 0), kw::auto_flush = true);

auto sink = finnBoost::make_shared<sink_type>(backend);
auto sink = boost::make_shared<sink_type>(backend);
sink->set_formatter(bl::parse_formatter(logFormat));

bl::core::get()->add_sink(sink);
Expand All @@ -85,7 +85,7 @@ void Logger::initLogging(bool console) {
if (!init) {
init = !init;
bl::register_simple_formatter_factory<bl::trivial::severity_level, char>("Severity");
finnBoost::log::add_common_attributes();
boost::log::add_common_attributes();

if (console)
bl::add_console_log(std::clog, bl::keywords::format = logFormat);
Expand Down
2 changes: 1 addition & 1 deletion src/FINNCppDriver/utils/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <boost/smart_ptr/intrusive_ref_counter.hpp> // IWYU pragma: keep
#include <string> // for allocator, string

namespace bl = finnBoost::log;
namespace bl = boost::log;
namespace loglevel = bl::trivial;

/**
Expand Down
Loading