Skip to content

Commit

Permalink
Merge branch 'maint-use-system-eigen-3' into 'master'
Browse files Browse the repository at this point in the history
MAINT: use system eigen 3

See merge request oddkiva/sara!459
  • Loading branch information
Odd Kiva committed Jul 10, 2024
2 parents b27cbbe + 25c955a commit 4b2d08c
Show file tree
Hide file tree
Showing 621 changed files with 87 additions and 228,133 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ sara_dissect_version()
include(sara_use_ccache)

if(CMAKE_SYSTEM_NAME STREQUAL Emscripten)
set(EIGEN3_INCLUDE_DIRECTORY "/usr/include/eigen3")
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)
endif()

Expand Down Expand Up @@ -89,6 +90,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL iOS)
/Users/david/GitHub/Apple-Boost-BuildScript/dist/boost.xcframework/ios-arm64/libboost.a
)
elseif(NOT CMAKE_SYSTEM_NAME STREQUAL Emscripten)
find_package(Eigen3 3.4 REQUIRED NO_MODULE)

find_package(TBB)

# set(Boost_DEBUG ON)
Expand Down
9 changes: 9 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,15 @@ def build_emsdk_docker():
cwd=SARA_SOURCE_DIR,
).wait()

ret = subprocess.Popen(
[
"docker",
"push",
f"{sara_emsdk_build_image}:latest",
],
cwd=SARA_SOURCE_DIR
).wait()

# Run the docker image.
ret = subprocess.Popen(
[
Expand Down
7 changes: 4 additions & 3 deletions cmake/sara_use_halide.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ function (shakti_halide_library_v2)
target_include_directories(${generator_NAME}.generator
PRIVATE
${DO_Sara_DIR}/cpp/src
${DO_Sara_ThirdParty_DIR}
${DO_Sara_ThirdParty_DIR}/eigen)
target_link_libraries(${generator_NAME}.generator PRIVATE Halide::Generator)
${DO_Sara_ThirdParty_DIR})
target_link_libraries(${generator_NAME}.generator
PRIVATE Eigen3::Eigen
Halide::Generator)

if (generator_HALIDE_TARGET_FEATURES)
add_halide_library(${generator_NAME}
Expand Down
5 changes: 2 additions & 3 deletions cpp/drafts/NuScenes/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
add_library(NuScenes STATIC NuImages.hpp NuImages.cpp NuScenes.hpp NuScenes.cpp)
target_include_directories(
NuScenes #
PUBLIC ${CMAKE_SOURCE_DIR}/cpp/third-party
${CMAKE_SOURCE_DIR}/cpp/third-party/eigen)
target_link_libraries(NuScenes PRIVATE Boost::filesystem)
PUBLIC ${CMAKE_SOURCE_DIR}/cpp/third-party)
target_link_libraries(NuScenes PUBLIC Eigen3::Eigen)
set_property(TARGET NuScenes PROPERTY FOLDER "Datasets/NuScenes")

add_executable(nuimages_cpp_devkit_usage_example
Expand Down
12 changes: 6 additions & 6 deletions cpp/drafts/NuScenes/NuImages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@

#include <drafts/NuScenes/NuImages.hpp>

#include <boost/filesystem.hpp>

#include <nlohmann/json.hpp>

#include <filesystem>


namespace fs = std::filesystem;


static auto load_json(const std::string& dataroot, const std::string& version,
const std::string& table_name) -> nlohmann::json
{
namespace fs = boost::filesystem;

const auto table_json_filepath =
fs::path{dataroot} / version / (table_name + ".json");

Expand All @@ -36,7 +37,7 @@ static auto load_json(const std::string& dataroot, const std::string& version,
NuImages::NuImages(const std::string& version_, //
const std::string& dataroot_, //
bool verbose_/*, //
float map_resolution = 0.1*/)
float map_resolution = 0.1*/)
: version{version_}
, dataroot{dataroot_}
, verbose{verbose_}
Expand Down Expand Up @@ -233,7 +234,6 @@ auto NuImages::load_log_table() -> void

auto NuImages::get_data_path(const SampleData& data) const -> std::string
{
namespace fs = boost::filesystem;
return (fs::path{dataroot} / data.filename).string();
}

Expand Down
10 changes: 5 additions & 5 deletions cpp/drafts/NuScenes/NuScenes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@

#include <drafts/NuScenes/NuScenes.hpp>

#include <boost/filesystem.hpp>

#include <nlohmann/json.hpp>

#include <filesystem>


namespace fs = std::filesystem;


static auto load_json(const std::string& dataroot, const std::string& version,
const std::string& table_name) -> nlohmann::json
{
namespace fs = boost::filesystem;

const auto table_json_filepath =
fs::path{dataroot} / version / (table_name + ".json");

Expand Down Expand Up @@ -257,7 +258,6 @@ auto NuScenes::load_sensor_table() -> void

auto NuScenes::get_data_path(const SampleData& data) const -> std::string
{
namespace fs = boost::filesystem;
return (fs::path{dataroot} / data.filename).string();
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/examples/Kalpana/EasyGL/hello_coordinate_systems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class App
{
// Encode the vertex data in a tensor.
const auto vertices = make_cube();
_num_vertices = vertices.size();
_num_vertices = static_cast<GLsizei>(vertices.size());

_vao.generate();
_vbo.generate();
Expand Down
2 changes: 1 addition & 1 deletion cpp/examples/Kalpana/EasyGL/hello_square.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class App
0, 1, 2,
2, 3, 0;
// clang-format on
_num_triangle_indices = triangles.size();
_num_triangle_indices = static_cast<GLsizei>(triangles.size());

_vao.generate();
_vbo.generate();
Expand Down
2 changes: 1 addition & 1 deletion cpp/examples/Kalpana/EasyGL/hello_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class App
0, 1, 2,
2, 3, 0;
// clang-format on
_num_triangle_indices = triangles.size();
_num_triangle_indices = static_cast<GLsizei>(triangles.size());

_vao.generate();

Expand Down
2 changes: 1 addition & 1 deletion cpp/examples/Kalpana/EasyGL/hello_transformations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class App
0, 1, 2,
2, 3, 0;
// clang-format on
_num_triangle_indices = triangles.size();
_num_triangle_indices = static_cast<GLsizei>(triangles.size());

_vao.generate();
// Vertex attributes.
Expand Down
2 changes: 1 addition & 1 deletion cpp/examples/Shakti/Vulkan/hello_vulkan_image/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ class VulkanImageRenderer : public kvk::GraphicsBackend
auto define_descriptor_set_types() -> void
{
const auto num_frames_in_flight = _swapchain.images.size();
for (auto i = std::size_t{}; i != num_frames_in_flight; ++i)
for (auto i = 0u; i != num_frames_in_flight; ++i)
{
// 1. Descriptor set #1: the model-view-projection matrix stack uniform.
auto buffer_info = VkDescriptorBufferInfo{};
Expand Down
2 changes: 1 addition & 1 deletion cpp/examples/Shakti/Vulkan/hello_vulkan_triangle/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class VulkanTriangleRenderer : public kvk::GraphicsBackend
_mvp_dmems[i].map_memory<ModelViewProjectionStack>(1));
}

for (auto i = std::size_t{}; i != num_frames_in_flight; ++i)
for (auto i = 0u; i != num_frames_in_flight; ++i)
{
// 4.a) Register the byte size, the type of buffer which the descriptor
// references to.
Expand Down
20 changes: 2 additions & 18 deletions cpp/src/DO/Sara/Core/EigenExtension.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,7 @@
# define NOMINMAX
#endif

#if defined(__GNUC__)
# pragma GCC diagnostic push
# if defined(__has_warning) // clang
# if __has_warning("-Wmaybe-uninitialized")
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
# endif
# if __has_warning("-Wconversion")
# pragma GCC diagnostic ignored "-Wconversion"
# endif
# else // GCC
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
# endif
#endif
#include <Eigen/Eigen>
#if defined(__GNUC__)
# pragma GCC diagnostic pop
#endif

#include <sstream>

Expand Down Expand Up @@ -137,7 +121,7 @@ namespace Eigen {
//! @}


namespace DO { namespace Sara {
namespace DO::Sara {

/*!
@ingroup Core
Expand Down Expand Up @@ -217,4 +201,4 @@ namespace DO { namespace Sara {

//! @}

}} // namespace DO::Sara
} // namespace DO::Sara
6 changes: 3 additions & 3 deletions cpp/src/DO/Sara/ImageIO/Details/Exif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ namespace DO::Sara {
auto read_exif_info(EXIFInfo& info, const std::string& file_path) -> bool
{
// Read the JPEG file into a buffer
FILE* fp = fopen(file_path.c_str(), "rb");
const auto fp = fopen(file_path.c_str(), "rb");
if (!fp)
{
std::cout << "Can't open file:" << std::endl << file_path << std::endl;
return false;
}
fseek(fp, 0, SEEK_END);
unsigned long fsize = ftell(fp);
const auto fsize = static_cast<unsigned long>(ftell(fp));
rewind(fp);

std::vector<unsigned char> buf(fsize);
Expand All @@ -110,7 +110,7 @@ namespace DO::Sara {
fclose(fp);

// Parse EXIF info.
const auto code = info.parseFrom(&buf[0], fsize);
const auto code = info.parseFrom(&buf[0], static_cast<unsigned int>(fsize));

return !code;
}
Expand Down
23 changes: 12 additions & 11 deletions cpp/src/DO/Sara/KDTree/KDTree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# if __has_warning("-Wconversion")
# pragma GCC diagnostic ignored "-Wconversion"
# endif
# pragma GCC diagnostic ignored "-Wunused-but-set-variable"
# pragma GCC diagnostic ignored "-Wunused-but-set-variable"
# endif
#endif
#include <flann/flann.hpp>
Expand Down Expand Up @@ -59,10 +59,10 @@ namespace DO::Sara {

//! k-NN search for a single query column vector.
template <int N, int Options, int MaxRows, int MaxCols>
void
knn_search(const Eigen::Matrix<double, N, 1, Options, MaxRows, MaxCols>& query,
int num_nearest_neighbors, std::vector<int>& nn_indices,
std::vector<double>& nn_squared_distances)
void knn_search(
const Eigen::Matrix<double, N, 1, Options, MaxRows, MaxCols>& query,
int num_nearest_neighbors, std::vector<int>& nn_indices,
std::vector<double>& nn_squared_distances)
{
if (static_cast<int>(_row_major_matrix_view.cols) != query.size())
throw std::runtime_error{"Dimension of query vector do not match "
Expand Down Expand Up @@ -93,11 +93,11 @@ namespace DO::Sara {

//! Radius search for a single query column vector.
template <int N, int Options, int MaxRows, int MaxCols>
int
radius_search(const Eigen::Matrix<double, N, 1, Options, MaxRows, MaxCols>& query,
double squared_search_radius, std::vector<int>& nn_indices,
std::vector<double>& nn_squared_distances,
int max_num_nearest_neighbors = -1)
int radius_search(
const Eigen::Matrix<double, N, 1, Options, MaxRows, MaxCols>& query,
double squared_search_radius, std::vector<int>& nn_indices,
std::vector<double>& nn_squared_distances,
int max_num_nearest_neighbors = -1)
{
if (static_cast<int>(_row_major_matrix_view.cols) != query.size())
throw std::runtime_error{"Dimension of query vector do not match "
Expand All @@ -110,7 +110,8 @@ namespace DO::Sara {
}

//! Radius search for a set of of query column vectors.
void radius_search(const Eigen::MatrixXd& queries, double squared_search_radius,
void radius_search(const Eigen::MatrixXd& queries,
double squared_search_radius,
std::vector<std::vector<int>>& nn_indices,
std::vector<std::vector<double>>& nn_squared_distances,
int max_num_nearest_neighbors = -1);
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/DO/Sara/NeuralNetworks/Darknet/Layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ auto Shortcut::to_output_stream(std::ostream& os) const -> void
os << "- activation = " << activation;
}

auto Shortcut::forward(const TensorView_<float, 4>& fx, const TensorView_<float, 4>& x)
auto Shortcut::forward_2(const TensorView_<float, 4>& fx,
const TensorView_<float, 4>& x)
-> const TensorView_<float, 4>&
{
output.flat_array() = fx.flat_array() + x.flat_array();
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/DO/Sara/NeuralNetworks/Darknet/Layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ namespace DO::Sara::Darknet {

auto to_output_stream(std::ostream&) const -> void override;

auto forward(const TensorView_<float, 4>& fx,
const TensorView_<float, 4>& x)
auto forward_2(const TensorView_<float, 4>& fx,
const TensorView_<float, 4>& x)
-> const TensorView_<float, 4>&;
};

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/DO/Sara/NeuralNetworks/Darknet/Network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ namespace DO::Sara::Darknet {
: shortcut.from;
const auto& fx = net[i1]->output;
const auto& x = net[i2]->output;
shortcut.forward(fx, x);
shortcut.forward_2(fx, x);

if (profile)
toc("Shortcut");
Expand Down
5 changes: 3 additions & 2 deletions cpp/src/DO/Sara/UseDOSaraCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ if(NOT DO_Sara_Core_ADDED)

target_include_directories(
DO_Sara_Core #
PUBLIC ${CMAKE_SOURCE_DIR}/cpp/third-party/eigen #
PUBLIC $<$<PLATFORM_ID:Emscripten>:${EIGEN3_INCLUDE_DIRECTORY}> #
$<$<NOT:$<PLATFORM_ID:iOS>>:${HDF5_INCLUDE_DIRS}>)
target_link_libraries(
DO_Sara_Core #
PUBLIC fmt::fmt # This is a deliberate choice.
PUBLIC fmt::fmt #
$<$<NOT:$<PLATFORM_ID:Emscripten>>:Eigen3::Eigen> #
$<$<NOT:$<PLATFORM_ID:iOS>>:${HDF5_CXX_LIBRARIES}>)
target_compile_definitions(
DO_Sara_Core
Expand Down
1 change: 1 addition & 0 deletions cpp/src/DO/Sara/UseDOSaraDisjointSets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ if (SARA_USE_FROM_SOURCE)
sara_glob_directory(${DO_Sara_SOURCE_DIR}/DisjointSets)
sara_create_common_variables("DisjointSets")
sara_generate_library("DisjointSets")
target_link_libraries(DO_Sara_DisjointSets PUBLIC Eigen3::Eigen)
endif ()
endif ()
3 changes: 2 additions & 1 deletion cpp/src/DO/Sara/UseDOSaraFeatureDescriptors.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ if(SARA_USE_FROM_SOURCE)
endif ()
target_link_libraries(
DO_Sara_FeatureDescriptors
PUBLIC DO::Sara::Features #
PUBLIC Eigen3::Eigen #
DO::Sara::Features #
DO::Sara::ImageProcessing
$<$<BOOL:${OpenMP_CXX_FOUND}>:OpenMP::OpenMP_CXX>)
endif()
Expand Down
10 changes: 4 additions & 6 deletions cpp/src/DO/Sara/UseDOSaraFeatures.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ if (SARA_USE_FROM_SOURCE)
sara_generate_library("Features")

target_include_directories(DO_Sara_Features
PUBLIC
${HDF5_INCLUDE_DIRS})
PUBLIC ${HDF5_INCLUDE_DIRS})
target_link_libraries(DO_Sara_Features
PRIVATE
DO::Sara::Geometry
PUBLIC
${HDF5_LIBRARIES})
PRIVATE DO::Sara::Geometry
PUBLIC Eigen3::Eigen
${HDF5_LIBRARIES})
endif ()
endif ()
5 changes: 4 additions & 1 deletion cpp/src/DO/Sara/UseDOSaraImageProcessing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ if(SARA_USE_FROM_SOURCE)
sara_create_common_variables("ImageProcessing")
sara_generate_library("ImageProcessing")

target_link_libraries(DO_Sara_ImageProcessing PRIVATE DO::Sara::Core)
target_link_libraries(
DO_Sara_ImageProcessing
PUBLIC Eigen3::Eigen
PRIVATE DO::Sara::Core)

if(SARA_USE_HALIDE)
target_compile_definitions(DO_Sara_ImageProcessing
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/DO/Sara/UseDOSaraKDTree.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ if (SARA_USE_FROM_SOURCE)
$<BUILD_INTERFACE:${DO_Sara_ThirdParty_DIR}/flann/src/cpp>)
target_link_libraries(DO_Sara_KDTree
PRIVATE flann_cpp_s
PUBLIC $<$<BOOL:${OpenMP_CXX_FOUND}>:OpenMP::OpenMP_CXX>)
PUBLIC Eigen3::Eigen
$<$<BOOL:${OpenMP_CXX_FOUND}>:OpenMP::OpenMP_CXX>)
endif ()
endif ()
Loading

0 comments on commit 4b2d08c

Please sign in to comment.