Skip to content

Commit

Permalink
Wiki examples for BLAS2 functions are added (kokkos#2122)
Browse files Browse the repository at this point in the history
Some small additional change the the function headers themselves
to add some missing header file inclusions.

Applying clang-format

Removing constexpr since it won't happen before some work in Core.
  • Loading branch information
lucbv authored and brian-kelley committed Mar 14, 2024
1 parent 17d940f commit 9b477fd
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 14 deletions.
11 changes: 2 additions & 9 deletions blas/src/KokkosBlas2_ger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#ifndef KOKKOSBLAS2_GER_HPP_
#define KOKKOSBLAS2_GER_HPP_

#include "KokkosKernels_helpers.hpp"

#include <KokkosBlas2_ger_spec.hpp>

namespace KokkosBlas {
Expand All @@ -42,15 +44,6 @@ template <class ExecutionSpace, class XViewType, class YViewType,
void ger(const ExecutionSpace& space, const char trans[],
const typename AViewType::const_value_type& alpha, const XViewType& x,
const YViewType& y, const AViewType& A) {
static_assert(
Kokkos::SpaceAccessibility<typename AViewType::memory_space,
typename XViewType::memory_space>::assignable,
"AViewType memory space must be assignable from XViewType");
static_assert(
Kokkos::SpaceAccessibility<typename AViewType::memory_space,
typename YViewType::memory_space>::assignable,
"AViewType memory space must be assignable from YViewType");

static_assert(
Kokkos::SpaceAccessibility<ExecutionSpace,
typename AViewType::memory_space>::accessible,
Expand Down
7 changes: 2 additions & 5 deletions blas/src/KokkosBlas2_syr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#ifndef KOKKOSBLAS2_SYR_HPP_
#define KOKKOSBLAS2_SYR_HPP_

#include "KokkosKernels_helpers.hpp"

#include <KokkosBlas2_syr_spec.hpp>

namespace KokkosBlas {
Expand Down Expand Up @@ -64,11 +66,6 @@ template <class ExecutionSpace, class XViewType, class AViewType>
void syr(const ExecutionSpace& space, const char trans[], const char uplo[],
const typename AViewType::const_value_type& alpha, const XViewType& x,
const AViewType& A) {
static_assert(
Kokkos::SpaceAccessibility<typename AViewType::memory_space,
typename XViewType::memory_space>::assignable,
"AViewType memory space must be assignable from XViewType");

static_assert(
Kokkos::SpaceAccessibility<ExecutionSpace,
typename AViewType::memory_space>::accessible,
Expand Down
2 changes: 2 additions & 0 deletions blas/src/KokkosBlas2_syr2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#ifndef KOKKOSBLAS2_SYR2_HPP_
#define KOKKOSBLAS2_SYR2_HPP_

#include "KokkosKernels_helpers.hpp"

#include <KokkosBlas2_syr2_spec.hpp>
#include <sstream>

Expand Down
1 change: 1 addition & 0 deletions example/wiki/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ADD_SUBDIRECTORY(blas)
ADD_SUBDIRECTORY(sparse)
ADD_SUBDIRECTORY(graph)
19 changes: 19 additions & 0 deletions example/wiki/blas/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
KOKKOSKERNELS_INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
KOKKOSKERNELS_INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})

KOKKOSKERNELS_INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../../../test_common)

KOKKOSKERNELS_ADD_EXECUTABLE_AND_TEST(
wiki_blas2_ger
SOURCES KokkosBlas2_wiki_ger.cpp
)

KOKKOSKERNELS_ADD_EXECUTABLE_AND_TEST(
wiki_blas2_syr
SOURCES KokkosBlas2_wiki_syr.cpp
)

KOKKOSKERNELS_ADD_EXECUTABLE_AND_TEST(
wiki_blas2_syr2
SOURCES KokkosBlas2_wiki_syr2.cpp
)
23 changes: 23 additions & 0 deletions example/wiki/blas/KokkosBlas2_wiki_ger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <Kokkos_Core.hpp>
#include <KokkosBlas2_ger.hpp>

int main(int argc, char* argv[]) {
Kokkos::initialize(argc, argv);
{
constexpr int M = 5;
constexpr int N = 4;

Kokkos::View<double**> A("A", M, N);
Kokkos::View<double*> x("X", M);
Kokkos::View<double*> y("Y", N);

Kokkos::deep_copy(A, 1.0);
Kokkos::deep_copy(x, 3.0);
Kokkos::deep_copy(y, 1.3);

const double alpha = Kokkos::ArithTraits<double>::one();

KokkosBlas::ger("T", alpha, x, y, A);
}
Kokkos::finalize();
}
20 changes: 20 additions & 0 deletions example/wiki/blas/KokkosBlas2_wiki_syr.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <Kokkos_Core.hpp>
#include <KokkosBlas2_syr.hpp>

int main(int argc, char* argv[]) {
Kokkos::initialize(argc, argv);
{
constexpr int M = 5;

Kokkos::View<double**> A("A", M, M);
Kokkos::View<double*> x("X", M);

Kokkos::deep_copy(A, 1.0);
Kokkos::deep_copy(x, 3.0);

const double alpha = double(1.0);

KokkosBlas::syr("T", "U", alpha, x, A);
}
Kokkos::finalize();
}
22 changes: 22 additions & 0 deletions example/wiki/blas/KokkosBlas2_wiki_syr2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <Kokkos_Core.hpp>
#include <KokkosBlas2_syr2.hpp>

int main(int argc, char* argv[]) {
Kokkos::initialize(argc, argv);
{
constexpr int M = 5;

Kokkos::View<double**> A("A", M, M);
Kokkos::View<double*> x("X", M);
Kokkos::View<double*> y("Y", M);

Kokkos::deep_copy(A, 1.0);
Kokkos::deep_copy(x, 3.0);
Kokkos::deep_copy(y, 1.3);

const double alpha = double(1.0);

KokkosBlas::syr2("T", "U", alpha, x, y, A);
}
Kokkos::finalize();
}

0 comments on commit 9b477fd

Please sign in to comment.