From 15d7fea337a34ca335f0f2bc85a673e500cfa9bc Mon Sep 17 00:00:00 2001 From: Alexandr-Solovev Date: Mon, 2 Sep 2024 05:05:16 -0700 Subject: [PATCH] minor fixes --- cpp/daal/src/externals/istrconv_daal_el.h | 35 ---- cpp/daal/src/externals/service_service_ref.h | 2 +- .../backend/primitives/lapack/test/eigen.cpp | 173 ------------------ .../primitives/lapack/test/syevd_dpc.cpp | 171 +++++++++++++++++ dev/bazel/deps/mkl.tpl.BUILD | 36 +--- dev/make/common.mk | 20 +- dev/make/deps.mkl.mk | 2 +- 7 files changed, 195 insertions(+), 244 deletions(-) delete mode 100755 cpp/daal/src/externals/istrconv_daal_el.h delete mode 100644 cpp/oneapi/dal/backend/primitives/lapack/test/eigen.cpp create mode 100644 cpp/oneapi/dal/backend/primitives/lapack/test/syevd_dpc.cpp diff --git a/cpp/daal/src/externals/istrconv_daal_el.h b/cpp/daal/src/externals/istrconv_daal_el.h deleted file mode 100755 index 32d0ef187ee..00000000000 --- a/cpp/daal/src/externals/istrconv_daal_el.h +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* -* Copyright 2014 Intel Corporation -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*******************************************************************************/ - -// -// Abstract: -// -// External header file for libistrconv. -// -// ============================================================================= - -#ifndef _ISTRCONV_EL_H_ -#define _ISTRCONV_EL_H_ - -#if defined(__cplusplus) - #define _ISTRCONV_EXTERN_C extern "C" -#else - #define _ISTRCONV_EXTERN_C extern -#endif - -_ISTRCONV_EXTERN_C int __FPK_string_to_int_generic(const char * nptr, char ** endptr); - -#endif /*_ISTRCONV_H_*/ diff --git a/cpp/daal/src/externals/service_service_ref.h b/cpp/daal/src/externals/service_service_ref.h index da67ef66e0f..a76884a5039 100644 --- a/cpp/daal/src/externals/service_service_ref.h +++ b/cpp/daal/src/externals/service_service_ref.h @@ -93,7 +93,7 @@ struct RefService { return 0; // Old one - just to see what the method is for - // return fpk_serv_set_memory_limit(type, limit); + // return mkl_serv_set_memory_limit(type, limit); } static size_t serv_strnlen_s(const char * src, size_t slen) diff --git a/cpp/oneapi/dal/backend/primitives/lapack/test/eigen.cpp b/cpp/oneapi/dal/backend/primitives/lapack/test/eigen.cpp deleted file mode 100644 index 4e53f2dc16e..00000000000 --- a/cpp/oneapi/dal/backend/primitives/lapack/test/eigen.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/******************************************************************************* -* Copyright 2021 Intel Corporation -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*******************************************************************************/ - -// #include "oneapi/dal/backend/primitives/lapack/eigen.hpp" - -#include "oneapi/dal/test/engine/common.hpp" -#include "oneapi/dal/test/engine/math.hpp" -#include "oneapi/dal/test/engine/io.hpp" - -namespace oneapi::dal::backend::primitives::test { - -namespace te = dal::test::engine; -namespace la = te::linalg; - -template -class sym_eigvals_test { -public: - // std::int64_t generate_dim() const { - // return GENERATE(3, 28, 125, 256); - // } - - // la::matrix generate_symmetric_positive() { - // const std::int64_t dim = this->generate_dim(); - // return la::generate_symmetric_positive_matrix(dim, -1, 1, seed_); - // } - - // auto call_sym_eigvals_inplace(const la::matrix& symmetric_matrix) { - // constexpr bool is_ascending = true; - // return call_sym_eigvals_inplace_generic(symmetric_matrix, is_ascending); - // } - - // auto call_sym_eigvals_inplace_descending(const la::matrix& symmetric_matrix) { - // constexpr bool is_ascending = false; - // return call_sym_eigvals_inplace_generic(symmetric_matrix, is_ascending); - // } - - // auto call_sym_eigvals_descending(const la::matrix& symmetric_matrix, - // std::int64_t eigval_count) { - // ONEDAL_ASSERT(symmetric_matrix.get_row_count() == symmetric_matrix.get_column_count()); - - // const std::int64_t dim = symmetric_matrix.get_row_count(); - // const auto s_copy_flat = symmetric_matrix.copy().get_array(); - - // auto data_or_scratchpad_nd = ndarray::wrap_mutable(s_copy_flat, { dim, dim }); - // auto eigvecs_nd = ndarray::empty({ eigval_count, dim }); - // auto eigvals_nd = ndarray::empty(eigval_count); - // sym_eigvals_descending(data_or_scratchpad_nd, eigval_count, eigvecs_nd, eigvals_nd); - - // const auto eigvecs = la::matrix::wrap_nd(eigvecs_nd); - // const auto eigvals = la::matrix::wrap_nd(eigvals_nd); - // return std::make_tuple(eigvecs, eigvals); - // } - - // auto call_sym_eigvals_inplace_generic(const la::matrix& symmetric_matrix, - // bool is_ascending) { - // ONEDAL_ASSERT(symmetric_matrix.get_row_count() == symmetric_matrix.get_column_count()); - - // const std::int64_t dim = symmetric_matrix.get_row_count(); - // const auto s_copy_flat = symmetric_matrix.copy().get_array(); - - // auto data_or_eigenvectors_nd = ndarray::wrap_mutable(s_copy_flat, { dim, dim }); - // auto eigenvalues_nd = ndarray::empty(dim); - // if (is_ascending) { - // sym_eigvals(data_or_eigenvectors_nd, eigenvalues_nd); - // } - // else { - // sym_eigvals_descending(data_or_eigenvectors_nd, eigenvalues_nd); - // } - - // const auto eigenvectors = la::matrix::wrap_nd(data_or_eigenvectors_nd); - // const auto eigenvalues = la::matrix::wrap_nd(eigenvalues_nd); - // return std::make_tuple(eigenvectors, eigenvalues); - // } - - // void check_eigvals_definition(const la::matrix& s, - // const la::matrix& eigvecs, - // const la::matrix& eigvals) const { - // INFO("convert results to float64"); - // const auto s_f64 = la::astype(s); - // const auto eigvals_f64 = la::astype(eigvals); - // const auto eigvecs_f64 = la::astype(eigvecs); - - // INFO("check eigenvectors and eigenvalues definition"); - // for (std::int64_t i = 0; i < eigvecs.get_row_count(); i++) { - // const auto v = la::transpose(eigvecs_f64.get_row(i)); - // const double w = eigvals_f64.get(i); - // CAPTURE(i, w); - - // // Input matrix is positive-definite, so all eigenvalues must be positive - // REQUIRE(w > 0); - - // const double tol = te::get_tolerance(1e-4, 1e-10) * w; - - // // Check condition: $S \times v_i = w_i \dot v_i$ - // const double err = la::rel_error(la::dot(s_f64, v), la::multiply(w, v), tol); - // REQUIRE(err < tol); - // } - // } - - // void check_eigvals_are_ascending(const la::matrix& eigvals) const { - // INFO("check eigenvalues order is ascending"); - // la::enumerate_linear(eigvals, [&](std::int64_t i, Float x) { - // if (i > 0) { - // REQUIRE(eigvals.get(i - 1) <= x); - // } - // }); - // } - - // void check_eigvals_are_descending(const la::matrix& eigvals) const { - // INFO("check eigenvalues order is descending"); - // la::enumerate_linear(eigvals, [&](std::int64_t i, Float x) { - // if (i > 0) { - // REQUIRE(eigvals.get(i - 1) >= x); - // } - // }); - // } - -private: - static constexpr int seed_ = 7777; -}; - -using eigen_types = COMBINE_TYPES((float, double)); - -#define SYM_EIGVALS_TEST(name) \ - TEMPLATE_LIST_TEST_M(sym_eigvals_test, name, "[sym_eigvals]", eigen_types) - -SYM_EIGVALS_TEST("check inplace sym_eigvals on symmetric positive-definite matrix") { - REQUIRE(1 == 1); - // const auto s = this->generate_symmetric_positive(); - - // const auto [eigenvectors, eigenvalues] = this->call_sym_eigvals_inplace(s); - - // this->check_eigvals_definition(s, eigenvectors, eigenvalues); - // this->check_eigvals_are_ascending(eigenvalues); -} - -SYM_EIGVALS_TEST("check inplace sym_eigvals_descending on symmetric positive-definite matrix") { - REQUIRE(1 == 1); - // const auto s = this->generate_symmetric_positive(); - - // const auto [eigenvectors, eigenvalues] = this->call_sym_eigvals_inplace_descending(s); - - // this->check_eigvals_definition(s, eigenvectors, eigenvalues); - // this->check_eigvals_are_descending(eigenvalues); -} - -SYM_EIGVALS_TEST("check sym_eigvals_descending on symmetric positive-definite matrix") { - REQUIRE(1 == 1); - // const auto s = this->generate_symmetric_positive(); - // const std::int64_t eigvals_count = GENERATE_COPY(1, s.get_row_count() / 2, s.get_row_count()); - - // const auto [eigenvectors, eigenvalues] = this->call_sym_eigvals_descending(s, eigvals_count); - - // REQUIRE(eigenvectors.get_row_count() == eigvals_count); - // REQUIRE(eigenvalues.get_count() == eigvals_count); - // this->check_eigvals_definition(s, eigenvectors, eigenvalues); - // this->check_eigvals_are_descending(eigenvalues); -} - -} // namespace oneapi::dal::backend::primitives::test diff --git a/cpp/oneapi/dal/backend/primitives/lapack/test/syevd_dpc.cpp b/cpp/oneapi/dal/backend/primitives/lapack/test/syevd_dpc.cpp new file mode 100644 index 00000000000..56484014a81 --- /dev/null +++ b/cpp/oneapi/dal/backend/primitives/lapack/test/syevd_dpc.cpp @@ -0,0 +1,171 @@ +/******************************************************************************* +* Copyright 2021 Intel Corporation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*******************************************************************************/ + +#include "oneapi/dal/backend/primitives/lapack/syevd.hpp" + +#include "oneapi/dal/test/engine/common.hpp" +#include "oneapi/dal/test/engine/math.hpp" +#include "oneapi/dal/test/engine/fixtures.hpp" + +namespace oneapi::dal::backend::primitives::test { + +namespace te = dal::test::engine; +namespace la = te::linalg; + +template +class syevd_test : public te::float_algo_fixture { +public: + using float_t = Float; + std::int64_t generate_dim() const { + return GENERATE(3, 28, 125, 256); + } + + la::matrix generate_symmetric_positive() { + const std::int64_t dim = this->generate_dim(); + return la::generate_symmetric_positive_matrix(dim, -1, 1, seed_); + } + + auto call_sym_eigvals_inplace(const la::matrix& symmetric_matrix) { + constexpr bool is_ascending = true; + return call_sym_eigvals_inplace_generic(symmetric_matrix, is_ascending); + } + + auto call_sym_eigvals_inplace_descending(const la::matrix& symmetric_matrix) { + constexpr bool is_ascending = false; + return call_sym_eigvals_inplace_generic(symmetric_matrix, is_ascending); + } + + auto call_sym_eigvals_inplace_generic(const la::matrix& symmetric_matrix, + bool is_ascending) { + ONEDAL_ASSERT(symmetric_matrix.get_row_count() == symmetric_matrix.get_column_count()); + + const std::int64_t dim = symmetric_matrix.get_row_count(); + const auto s_copy_flat = symmetric_matrix.copy().get_array(); + + auto data_or_eigenvectors_nd = ndarray::wrap_mutable(s_copy_flat, { dim, dim }); + data_or_eigenvectors_nd.to_device(this->get_queue()); + auto eigenvalues_nd = + ndarray::empty(this->get_queue(), { dim }, sycl::usm::alloc::device); + if (is_ascending) { + auto syevd_event = syevd(this->get_queue(), + dim, + data_or_eigenvectors_nd, + dim, + eigenvalues_nd, + {}); + syevd_event.wait_and_throw(); + const auto eigenvectors = + la::matrix::wrap_nd(data_or_eigenvectors_nd.to_host(this->get_queue())); + const auto eigenvalues = + la::matrix::wrap_nd(eigenvalues_nd.to_host(this->get_queue())); + return std::make_tuple(eigenvectors, eigenvalues); + } + else { + auto syevd_event = syevd(this->get_queue(), + dim, + data_or_eigenvectors_nd, + dim, + eigenvalues_nd, + {}); + syevd_event.wait_and_throw(); + + auto data_ptr = eigenvalues_nd.get_data(); + auto flipped_eigenvalues = + ndarray::empty(this->get_queue(), { dim }, sycl::usm::alloc::device); + auto flipped_eigenvalues_ptr = flipped_eigenvalues.get_mutable_data(); + auto queue = this->get_queue(); + auto flip_event = queue.submit([&](sycl::handler& h) { + const auto range = make_range_1d(dim); + h.depends_on({ syevd_event }); + h.parallel_for(range, [=](sycl::id<1> id) { + const std::int64_t col = id[0]; + flipped_eigenvalues_ptr[col] = data_ptr[(dim - 1) - col]; + }); + }); + const auto eigenvectors = + la::matrix::wrap_nd(data_or_eigenvectors_nd.to_host(this->get_queue())); + const auto eigenvalues = + la::matrix::wrap_nd(flipped_eigenvalues.to_host(this->get_queue())); + return std::make_tuple(eigenvectors, eigenvalues); + } + } + + void check_eigvals_definition(const la::matrix& s, + const la::matrix& eigvecs, + const la::matrix& eigvals) const { + INFO("convert results to float64"); + const auto s_f64 = la::astype(s); + const auto eigvals_f64 = la::astype(eigvals); + const auto eigvecs_f64 = la::astype(eigvecs); + + INFO("check eigenvectors and eigenvalues definition"); + for (std::int64_t i = 0; i < eigvecs.get_row_count(); i++) { + const auto v = la::transpose(eigvecs_f64.get_row(i)); + const double w = eigvals_f64.get(i); + CAPTURE(i, w); + + // Input matrix is positive-definite, so all eigenvalues must be positive + REQUIRE(w > 0); + + const double tol = te::get_tolerance(1e-4, 1e-10) * w; + + // Check condition: $S \times v_i = w_i \dot v_i$ + const double err = la::rel_error(la::dot(s_f64, v), la::multiply(w, v), tol); + REQUIRE(err < tol); + } + } + + void check_eigvals_are_ascending(const la::matrix& eigvals) const { + INFO("check eigenvalues order is ascending"); + la::enumerate_linear(eigvals, [&](std::int64_t i, Float x) { + if (i > 0) { + REQUIRE(eigvals.get(i - 1) <= x); + } + }); + } + + void check_eigvals_are_descending(const la::matrix& eigvals) const { + INFO("check eigenvalues order is descending"); + la::enumerate_linear(eigvals, [&](std::int64_t i, Float x) { + if (i > 0) { + REQUIRE(eigvals.get(i - 1) >= x); + } + }); + } + +private: + static constexpr int seed_ = 7777; +}; + +using eigen_types = COMBINE_TYPES((float)); + +TEMPLATE_LIST_TEST_M(syevd_test, "test syevd with pos def matrix", "[sym_eigvals]", eigen_types) { + const auto s = this->generate_symmetric_positive(); + const auto [eigenvectors, eigenvalues] = this->call_sym_eigvals_inplace(s); + + this->check_eigvals_definition(s, eigenvectors, eigenvalues); + this->check_eigvals_are_ascending(eigenvalues); +} + +TEMPLATE_LIST_TEST_M(syevd_test, "test syevd with pos def matrix 2", "[sym_eigvals]", eigen_types) { + const auto s = this->generate_symmetric_positive(); + + const auto [eigenvectors, eigenvalues] = this->call_sym_eigvals_inplace_descending(s); + + this->check_eigvals_are_descending(eigenvalues); +} + +} // namespace oneapi::dal::backend::primitives::test diff --git a/dev/bazel/deps/mkl.tpl.BUILD b/dev/bazel/deps/mkl.tpl.BUILD index 680bb49a703..f47413c79d2 100644 --- a/dev/bazel/deps/mkl.tpl.BUILD +++ b/dev/bazel/deps/mkl.tpl.BUILD @@ -3,34 +3,12 @@ package(default_visibility = ["//visibility:public"]) cc_library( name = "headers", hdrs = glob([ - "include/*.h", - "include/oneapi/*.hpp", - "include/oneapi/mkl/*.hpp", - "include/oneapi/mkl/blas/*.hpp", - "include/oneapi/mkl/spblas/*.hpp", - "include/oneapi/mkl/lapack/*.hpp", - "include/oneapi/mkl/vm/*.hpp", - "include/oneapi/mkl/vm/device/*.hpp", - "include/oneapi/mkl/vm/device/detail/*.hpp", - "include/oneapi/mkl/rng/*.hpp", - "include/oneapi/mkl/rng/detail/*.hpp", - "include/oneapi/mkl/rng/device/*.hpp", - "include/oneapi/mkl/rng/device/detail/*.hpp" + "include/**/*.h", + "include/**/*.hpp", ]), includes = [ "include", - "include/oneapi", - "include/oneapi/mkl", - "include/oneapi/mkl/blas", - "include/oneapi/mkl/spblas", - "include/oneapi/mkl/lapack", - "include/oneapi/mkl/vm", - "include/oneapi/mkl/vm/device", - "include/oneapi/mkl/vm/device/detail", - "include/oneapi/mkl/rng", - "include/oneapi/mkl/rng/device", - "include/oneapi/mkl/rng/device/detail", - "include/oneapi/mkl/rng/detail" ], + ], defines = [ "MKL_ILP64" ], @@ -83,18 +61,12 @@ cc_library( ], ) -cc_library( - name = "headers_dpc", - hdrs = glob(["include/*.h", "include/*.hpp"]), - includes = [ "include" ], -) - cc_library( name = "mkl_dpc", srcs = [ "lib/libmkl_sycl.a", ], deps = [ - ":headers_dpc", + ":headers", ], ) diff --git a/dev/make/common.mk b/dev/make/common.mk index 291ca7e406b..26d8f33bfc7 100644 --- a/dev/make/common.mk +++ b/dev/make/common.mk @@ -76,6 +76,22 @@ secure.opts.link.win = -DYNAMICBASE -NXCOMPAT secure.opts.link.lnx = -z relro -z now -z noexecstack secure.opts.link.mac = +link.dynamic.flags = -WX -nologo -map + +ifeq ($(COMPILER),vc) + link.dynamic.flags := /WX /nologo /map +else ifeq ($(COMPILER),msvc) + link.dynamic.flags := /WX /nologo /map +endif + +link.dynamic.flags_dpc = -WX -nologo -map -dll + +ifeq ($(COMPILER),vc) + link.dynamic.flags_dpc := /WX /nologo /map /dll +else ifeq ($(COMPILER),msvc) + link.dynamic.flags_dpc := /WX /nologo /map /dll +endif + RC.COMPILE = rc.exe $(RCOPT) -fo$@ $< # Used as $(eval $(call set_c_compile,$(COMPILER),$(_OS),$(gcc_toolchain)) @@ -117,7 +133,7 @@ LINK.DYNAMIC = $(mkdir)$(call rm,$@)$(link.dynamic.cmd) link.dynamic.cmd = $(call link.dynamic.$(_OS),$(secure.opts.link.$(_OS)) $(or $1,$(^.no-mkdeps)) $(LOPT)) link.dynamic.lnx = $(if $(link.dynamic.lnx.$(COMPILER)),$(link.dynamic.lnx.$(COMPILER)),$(error link.dynamic.lnx.$(COMPILER) must be defined)) \ -Wl,-soname,$(@F).$(MAJORBINARY) -shared $(-sGRP) $(patsubst %_link.txt,@%_link.txt,$(patsubst %_link.def,@%_link.def,$1)) $(-eGRP) -o $@ -link.dynamic.win = link $(link.dynamic.win.$(COMPILER)) -WX -nologo -map -dll $(-DEBL) \ +link.dynamic.win = link $(link.dynamic.win.$(COMPILER)) $(link.dynamic.flags) $(-DEBL) \ $(patsubst %_link.txt,@%_link.txt,$(patsubst %.def,-DEF:%.def,$1)) -out:$@ link.dynamic.mac = $(if $(link.dynamic.mac.$(COMPILER)),$(link.dynamic.mac.$(COMPILER)),$(error link.dynamic.mac.$(COMPILER) must be defined)) \ -undefined dynamic_lookup -dynamiclib -Wl,-flat_namespace -Wl,-install_name,@rpath/$(subst .dylib,.$(MAJORBINARY).dylib,$(@F)) \ @@ -132,7 +148,7 @@ dpc.link.dynamic.lnx = $(if $(link.dynamic.lnx.dpcpp),$(link.dynamic.lnx.dpcpp), $(secure.opts.link.lnx) -shared $(-sGRP) $(patsubst %_link.txt,@%_link.txt,$(patsubst %_link.def,@%_link.def,$1)) $(-eGRP) -o $@ dpc.link.dynamic.win = $(if $(link.dynamic.win.dpcpp),$(link.dynamic.win.dpcpp),$(error link.dynamic.win.dpcpp must be defined)) \ -LD $(patsubst %_link.txt,@%_link.txt,$(filter %_link.txt,$1)) $(filter-out -IMPLIB:%,$(filter %.lib,$1)) -o$@ \ - -link $(secure.opts.link.win) $(filter -IMPLIB:%,$1) $(patsubst %.def,-DEF:%.def,$(filter %.def,$1)) -WX -nologo -map $(-DEBL) + -link $(secure.opts.link.win) $(filter -IMPLIB:%,$1) $(patsubst %.def,-DEF:%.def,$(filter %.def,$1)) $(link.dynamic.flags_dpc) $(-DEBL) LINK.DYNAMIC.POST = $(call link.dynamic.post.$(_OS)) link.dynamic.post.lnx = diff --git a/dev/make/deps.mkl.mk b/dev/make/deps.mkl.mk index eff38ffa863..e9c6938dbde 100644 --- a/dev/make/deps.mkl.mk +++ b/dev/make/deps.mkl.mk @@ -73,6 +73,6 @@ daaldep.fbsd32e.ipp := $(if $(COV.libia),$(COV.libia)/libcov.a) daaldep.vml := $(daaldep.$(PLAT).vml) daaldep.ipp := $(daaldep.$(PLAT).ipp) -daaldep.math_backend.ext := $(daaldep.ipp) $(daaldep.vml) $(daaldep.mkl) $(daaldep.math_backend.thr) +daaldep.math_backend.ext := $(daaldep.ipp) $(daaldep.vml) $(daaldep.mkl) daaldep.math_backend.sycl := $(daaldep.math_backend.sycl) daaldep.math_backend.oneapi := $(daaldep.ipp) $(daaldep.vml) $(daaldep.mkl)