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

initial commit for adding boost lib #2985

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
16 changes: 16 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,29 @@ onedal_repo(
root_env_var = "DALROOT",
)

http_archive(
name = "boost",
url = "https://archives.boost.io/release/1.86.0/source/boost_1_86_0.tar.gz",
sha256 = "2575e74ffc3ef1cd0babac2c1ee8bdb5782a0ee672b1912da40e5b4b591ca01f",
strip_prefix = "boost_1_86_0",
build_file = "@onedal//dev/bazel/deps:boost.tpl.BUILD",
)

http_archive(
name = "catch2",
url = "https://github.com/catchorg/Catch2/archive/v3.7.1.tar.gz",
sha256 = "c991b247a1a0d7bb9c39aa35faf0fe9e19764213f28ffba3109388e62ee0269c",
strip_prefix = "Catch2-3.7.1",
)

http_archive(
name = "eigen",
url = "https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.gz",
sha256 = "8586084f71f9bde545ee7fa6d00288b264a2b7ac3607b974e54d13e7162c1c72",
build_file = "@onedal//dev/bazel/deps:eigen.tpl.BUILD",
strip_prefix = "eigen-3.4.0",
)

http_archive(
name = "fmt",
url = "https://github.com/fmtlib/fmt/archive/11.0.2.tar.gz",
Expand Down
41 changes: 41 additions & 0 deletions cpp/oneapi/dal/backend/primitives/lapack/test/syevd_dpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,46 @@ class syevd_test : public te::float_algo_fixture<Float> {
}
}

void check_eigvals_with_eigen(const la::matrix<Float>& s,
const la::matrix<Float>& eigvecs,
const la::matrix<Float>& eigvals) const {
INFO("convert results to float64");
const auto s_f64 = la::astype<double>(s);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an alternative, perhaps the input values could be hard-coded along with the solutions instead of checking them against a different library.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but with this solution there is no opportunity to use random generated data(I mean extend tests with for example row_count = GENERATE(3, 28, 125, 256);) and also it will be complicated to check results for big datasets

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about putting them in the existing folders with .csv files that have data and expected results?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible, but let's say for pca it's necessary to contain gold eigenvectors, eigenvalues, and it will increase the total size of the repo, especially with big datasets. I see no reasons to avoid this pr tbh

const auto eigvals_f64 = la::astype<double>(eigvals);
const auto eigvecs_f64 = la::astype<double>(eigvecs);
std::int64_t row_count = s.get_row_count();
std::int64_t column_count = s.get_column_count();
const Float* data = s.get_data();

Eigen::Matrix<Float, Eigen::Dynamic, Eigen::Dynamic> eigen_matrix(row_count, column_count);
for (int i = 0; i < eigen_matrix.rows(); ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An Eigen matrix can also be created from a non-owned pointer for float/double data. I think something along the lines of Eigen::map< Eigen::Matrix<info, incl. row/col major> , alignment, stride >.

for (int j = 0; j < eigen_matrix.cols(); ++j) {
eigen_matrix(i, j) = data[i * column_count + j];
}
}

Eigen::SelfAdjointEigenSolver<Eigen::Matrix<Float, Eigen::Dynamic, Eigen::Dynamic>> es(
eigen_matrix);

auto eigenvalues = es.eigenvalues().real();
INFO("oneDAL eigvals vs Eigen eigvals");
la::enumerate_linear(eigvals_f64, [&](std::int64_t i, Float x) {
REQUIRE(abs(eigvals_f64.get(i) - eigenvalues(i)) < 0.1);
});

INFO("oneDAL eigvectors vs Eigen eigvectors");
auto eigenvectors = es.eigenvectors().real();

const double* eigenvec_ptr = eigvecs_f64.get_data();
//TODO: investigate Eigen classes and align checking between oneDAL and Eigen classes.
for (int j = 0; j < eigvecs.get_column_count(); ++j) {
auto column_eigen = eigenvectors.col(j);
for (int i = 0; i < eigvecs.get_row_count(); ++i) {
REQUIRE((abs(eigenvec_ptr[j * row_count + i]) - abs(column_eigen(i))) < 0.1);
}
}
}

void check_eigvals_are_ascending(const la::matrix<Float>& eigvals) const {
INFO("check eigenvalues order is ascending");
la::enumerate_linear(eigvals, [&](std::int64_t i, Float x) {
Expand Down Expand Up @@ -158,6 +198,7 @@ TEMPLATE_LIST_TEST_M(syevd_test, "test syevd with pos def matrix", "[sym_eigvals

this->check_eigvals_definition(s, eigenvectors, eigenvalues);
this->check_eigvals_are_ascending(eigenvalues);
this->check_eigvals_with_eigen(s, eigenvectors, eigenvalues);
}

TEMPLATE_LIST_TEST_M(syevd_test, "test syevd with pos def matrix 2", "[sym_eigvals]", eigen_types) {
Expand Down
2 changes: 2 additions & 0 deletions cpp/oneapi/dal/test/engine/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ dal_test_module(
"@onedal//cpp/oneapi/dal/test/engine/metrics",
],
extra_deps = [
"@boost//:boost",
"@catch2//:catch2",
"@eigen//:eigen",
"@fmt//:fmt",
],
)
Expand Down
5 changes: 5 additions & 0 deletions cpp/oneapi/dal/test/engine/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
#include <type_traits>

#include <fmt/core.h>
//Necessary headers from boost
#include <boost/process.hpp>

#include <Eigen/Dense>
#include <Eigen/Eigenvalues>

#include "oneapi/dal/train.hpp"
#include "oneapi/dal/infer.hpp"
Expand Down
18 changes: 18 additions & 0 deletions dev/bazel/deps/boost.tpl.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package(default_visibility = ["//visibility:public"])

cc_library(
name = "boost",
srcs = glob([
"libs/libboost*.a",
]),
hdrs = glob([
"boost/**/*.h",
"boost/**/*.hpp",
"boost/**/*.ipp",
]),
includes = [
".",
],
visibility = ["//visibility:public"],
)

8 changes: 8 additions & 0 deletions dev/bazel/deps/eigen.tpl.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package(default_visibility = ["//visibility:public"])

cc_library(
name = "eigen",
hdrs = glob(["Eigen/**"]),
includes = [""],
visibility = ["//visibility:public"],
)
Loading