Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eigen package is optional (support for removed eigen) #108

Merged
merged 7 commits into from
May 28, 2024
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
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

find_package (Eigen3 3.3.7 REQUIRED NO_MODULE)
message(STATUS "Found Eigen3 in: ${Eigen3_DIR}")
find_package (Eigen3 3.3.7 QUIET NO_MODULE)

if (Eigen3_FOUND)
message(STATUS "Found Eigen3: ${Eigen3_DIR}")
add_definitions(-DEIGEN_FOUND)
endif()

set(CMAKE_CXX_STANDARD 17 CACHE STRING "")

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ If you're a C++ developer and require low-level control, optimization, or integr
* GNU Make (4.2.1)
* LLVM (17.0.6) - [src](https://github.com/llvm/llvm-project/tree/release/17.x), [release](https://releases.llvm.org/download.html#17.0.6)
* Support for latest LLVM versions would be added soon
* Eigen library (3.3.7)
* Eigen library (3.3.7) (Optional)
* Python (3.6.7)
* Other python requirements
* For training the vocabulary are available in [seed_embeddings/OpenKE/requirements.txt](./seed_embeddings/OpenKE/requirements.txt), and
Expand Down
8 changes: 6 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ if(NOT LLVM_IR2VEC)

add_library(objlib OBJECT ${libsrc})
set_property(TARGET objlib PROPERTY POSITION_INDEPENDENT_CODE 1)
target_link_libraries (objlib Eigen3::Eigen)
if(Eigen3_FOUND)
target_link_libraries (objlib Eigen3::Eigen)
endif()

add_library(${IR2VEC_LIB} SHARED $<TARGET_OBJECTS:objlib>)
add_library(${IR2VEC_LIB_STATIC} STATIC $<TARGET_OBJECTS:objlib>)
Expand Down Expand Up @@ -71,7 +73,9 @@ else()
intrinsics_gen
)

target_link_libraries(LLVMIR2Vec PRIVATE Eigen3::Eigen)
if(Eigen3_FOUND)
target_link_libraries(LLVMIR2Vec PRIVATE Eigen3::Eigen)
endif()
target_include_directories(LLVMIR2Vec PRIVATE ${LLVM_MAIN_INCLUDE_DIR})
target_include_directories(LLVMIR2Vec PRIVATE .)

Expand Down
4 changes: 4 additions & 0 deletions src/FlowAware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
// file in the top-level directory for more details.
//
#include "FlowAware.h"
#ifdef EIGEN_FOUND
#include "VectorSolverEigen.h"
#else
#include "VectorSolver.h"
#endif

#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/MapVector.h"
Expand Down
63 changes: 63 additions & 0 deletions src/include/VectorSolverEigen.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) 2021, S. VenkataKeerthy, Rohit Aggarwal
// Department of Computer Science and Engineering, IIT Hyderabad
//
// This software is available under the BSD 4-Clause License. Please see LICENSE
// file in the top-level directory for more details.
//
#ifndef __VECTOR_SOLVER_H__
#define __VECTOR_SOLVER_H__
#define EIGEN_MPL2_ONLY

#include "Eigen/LU"
#include "Eigen/QR"
#include "llvm/ADT/SmallVector.h"
#include <vector>

using namespace Eigen;
using namespace llvm;

typedef std::vector<std::vector<double>> matrix;

MatrixXd calculate(MatrixXd A, MatrixXd B) {
if (A.determinant() != 0) {
return A.fullPivHouseholderQr().solve(B);
} else {
// To-Do: perturb probabilities
llvm_unreachable("inconsistent/infinitely many solutions");
}
}

MatrixXd formMatrix(std::vector<std::vector<double>> a, int r, int l) {
MatrixXd M(r, l);
for (int i = 0; i < r; i++)
M.row(i) = VectorXd::Map(&a[i][0], a[i].size());

return M;
}

matrix solve(matrix A, matrix B) {
int r = A.size();
int c = A[0].size();
MatrixXd mA(r, c);
mA = formMatrix(A, r, c);

r = B.size();
c = B[0].size();
MatrixXd mB(r, c);
mB = formMatrix(B, r, c);

r = A.size();
MatrixXd x(r, c);
x = calculate(mA, mB);
std::vector<std::vector<double>> raw_data;
// raw_data.resize(x.rows());
for (unsigned i = 0; i < x.rows(); i++) {
std::vector<double> tmp;
tmp.resize(x.cols());
VectorXd::Map(&tmp[0], x.cols()) = x.row(i);
raw_data.push_back(tmp);
}
return raw_data;
}

#endif
Loading