Skip to content
Open
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
23 changes: 23 additions & 0 deletions blas/impl/KokkosBlas_Concepts.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// SPDX-FileCopyrightText: Copyright Contributors to the Kokkos project

#ifndef KOKKOSBLAS_CONCEPTS_HPP
#define KOKKOSBLAS_CONCEPTS_HPP

#include <concepts>
#include "KokkosBlas_util.hpp"

namespace KokkosBlas {

template <typename T>
concept TransposeOperation = is_trans_v<T>;

template <typename T>
concept BlasLevel2 = is_level2_v<T>;

template <typename T>
concept BlasLevel3 = is_level3_v<T>;

} // namespace KokkosBlas

#endif // KOKKOSBLAS_CONCEPTS_HPP
18 changes: 18 additions & 0 deletions blas/impl/KokkosBlas_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,24 @@ struct Algo {
using Pbtrs = Level2;
};

template <class T>
struct is_level3 : std::false_type {};

template <>
struct is_level3<Algo::Level3::Unblocked> : std::true_type {};

template <>
struct is_level3<Algo::Level3::Blocked> : std::true_type {};

template <>
struct is_level3<Algo::Level3::MKL> : std::true_type {};

template <>
struct is_level3<Algo::Level3::CompactMKL> : std::true_type {};

template <class T>
static constexpr bool is_level3_v = is_level3<T>::value;

template <class T>
struct is_level2 : std::false_type {};

Expand Down
3 changes: 3 additions & 0 deletions blas/unit_test/Test_Blas.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#ifndef TEST_BLAS_HPP
#define TEST_BLAS_HPP

// Blas concepts
#include "Test_Blas_Concepts.hpp"

// Blas 1
#include "Test_Blas1_abs.hpp"
#include "Test_Blas1_asum.hpp"
Expand Down
54 changes: 54 additions & 0 deletions blas/unit_test/Test_Blas_Concepts.hpp
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we add a test where we actually use the concept, i.e. create a dummy class/struct with a requirement close and observe that it goes well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added a dummy functor to explain the typical use case in mind

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// SPDX-FileCopyrightText: Copyright Contributors to the Kokkos project
#ifndef TEST_BLAS_CONCEPTS_HPP
#define TEST_BLAS_CONCEPTS_HPP

#include <gtest/gtest.h>
#include "KokkosBlas_Concepts.hpp"
#include <KokkosKernels_TestUtils.hpp>

namespace Test {

template <KokkosBlas::TransposeOperation ArgTrans>
struct DummyFunctor {};

void test_blas_concepts() {
// Check that the concepts compile for valid types
static_assert(KokkosBlas::TransposeOperation<KokkosBlas::Trans::Transpose>);
static_assert(KokkosBlas::TransposeOperation<KokkosBlas::Trans::NoTranspose>);
static_assert(KokkosBlas::TransposeOperation<KokkosBlas::Trans::ConjTranspose>);

// Check for level 2 concepts
static_assert(KokkosBlas::BlasLevel2<KokkosBlas::Algo::Level2::Unblocked>);
static_assert(KokkosBlas::BlasLevel2<KokkosBlas::Algo::Level2::Blocked>);
static_assert(KokkosBlas::BlasLevel2<KokkosBlas::Algo::Level2::MKL>);
static_assert(KokkosBlas::BlasLevel2<KokkosBlas::Algo::Level2::CompactMKL>);

static_assert(!KokkosBlas::BlasLevel2<KokkosBlas::Algo::Level3::Unblocked>);
static_assert(!KokkosBlas::BlasLevel2<KokkosBlas::Algo::Level3::Blocked>);
static_assert(!KokkosBlas::BlasLevel2<KokkosBlas::Algo::Level3::MKL>);
static_assert(!KokkosBlas::BlasLevel2<KokkosBlas::Algo::Level3::CompactMKL>);

// Check for level 3 concepts
static_assert(KokkosBlas::BlasLevel3<KokkosBlas::Algo::Level3::Unblocked>);
static_assert(KokkosBlas::BlasLevel3<KokkosBlas::Algo::Level3::Blocked>);
static_assert(KokkosBlas::BlasLevel3<KokkosBlas::Algo::Level3::MKL>);
static_assert(KokkosBlas::BlasLevel3<KokkosBlas::Algo::Level3::CompactMKL>);

static_assert(!KokkosBlas::BlasLevel3<KokkosBlas::Algo::Level2::Unblocked>);
static_assert(!KokkosBlas::BlasLevel3<KokkosBlas::Algo::Level2::Blocked>);
static_assert(!KokkosBlas::BlasLevel3<KokkosBlas::Algo::Level2::MKL>);
static_assert(!KokkosBlas::BlasLevel3<KokkosBlas::Algo::Level2::CompactMKL>);
}

void test_concepts_in_functor() {
[[maybe_unused]] DummyFunctor<KokkosBlas::Trans::NoTranspose> dummy_no_trans;
[[maybe_unused]] DummyFunctor<KokkosBlas::Trans::Transpose> dummy_trans;
[[maybe_unused]] DummyFunctor<KokkosBlas::Trans::ConjTranspose> dummy_conj_trans;
}
} // namespace Test

TEST_F(TestCategory, blas_concepts) { ::Test::test_blas_concepts(); }
TEST_F(TestCategory, concepts_in_functor) { ::Test::test_concepts_in_functor(); }

#endif // TEST_BLAS_CONCEPTS_HPP
Loading