Skip to content

Commit

Permalink
Add basic test infrastructure for Kokkos.
Browse files Browse the repository at this point in the history
  • Loading branch information
vgvassilev committed Jan 10, 2024
1 parent 3a5ad4a commit ab2e9bd
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 1 deletion.
13 changes: 12 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@ jobs:
compiler: clang-16
clang-runtime: '17'

- name: ubu22-clang16-runtime17-kokkos
os: ubuntu-22.04
compiler: clang-16
clang-runtime: '17'
extra_packages: 'libtrilinos-kokkos-dev'

# Оld, still supported versions

- name: ubu20-gcc9-runtime7
Expand Down Expand Up @@ -474,7 +480,12 @@ jobs:
echo "deb https://apt.llvm.org/${os_codename}/ llvm-toolchain-${os_codename}-${{ matrix.clang-runtime }} main" | sudo tee -a /etc/apt/sources.list
sudo apt update
fi
sudo apt install llvm-${{ matrix.clang-runtime }}-dev llvm-${{ matrix.clang-runtime }}-tools clang-${{ matrix.clang-runtime }} libclang-${{ matrix.clang-runtime }}-dev
sudo apt install llvm-${{ matrix.clang-runtime }}-dev \
llvm-${{ matrix.clang-runtime }}-tools \
clang-${{ matrix.clang-runtime }} \
libclang-${{ matrix.clang-runtime }}-dev \
${{ matrix.extra_packages }}
- name: Setup compiler on Linux
if: runner.os == 'Linux'
run: |
Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,11 @@ if (NOT CLAD_BUILD_STATIC_ONLY)
# need to use a supported by clad compiler. Note that's a huge hack and it is
# not guaranteed to work with cmake.
set(stored_cxx_compiler ${CMAKE_CXX_COMPILER})
set(stored_cxx_flags ${CMAKE_CXX_FLAGS})

set(CMAKE_CXX_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang)
# Filter some unsupported flags by clang.
string(REPLACE "-fno-lifetime-dse" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

add_subdirectory(unittests)
add_subdirectory(test)
Expand All @@ -321,6 +325,7 @@ if (NOT CLAD_BUILD_STATIC_ONLY)

# Restore the default compiler.
set(CMAKE_CXX_COMPILER ${stored_cxx_compiler})
set(CMAKE_CXX_FLAGS ${stored_cxx_flags})
endif()

# Workaround for MSVS10 to avoid the Dialog Hell
Expand Down
5 changes: 5 additions & 0 deletions unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ function(add_clad_unittest test_dirname)
endfunction()

add_subdirectory(Basic)

find_package(Kokkos)
if (Kokkos_FOUND)
add_subdirectory(Kokkos)
endif(Kokkos_FOUND)
7 changes: 7 additions & 0 deletions unittests/Kokkos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
add_clad_unittest(KokkosTests
parallel_for.cpp
main.cpp
)

target_link_libraries(KokkosTests INTERFACE Kokkos::kokkos)
target_include_directories(KokkosTests SYSTEM PRIVATE ${Kokkos_INCLUDE_DIRS})
11 changes: 11 additions & 0 deletions unittests/Kokkos/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <Kokkos_Core.hpp>

#include <gtest/gtest.h>

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
Kokkos::initialize(argc, argv);
int res = RUN_ALL_TESTS();
Kokkos::finalize();
return res;
}
21 changes: 21 additions & 0 deletions unittests/Kokkos/parallel_for.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <Kokkos_Core.hpp>

#include "gtest/gtest.h"

#include "clad/Differentiator/Differentiator.h"

struct hello_world_pow2 {
double x = 0.;
// double result = 0.;
KOKKOS_INLINE_FUNCTION void operator()(const int i) const {
// result = x * x;
}
};

TEST(parallel_for, HelloWorldFunctor) {
hello_world_pow2 hw;
hw.x = 2;
Kokkos::parallel_for("HelloWorld", 15, hw);
// EXPECT_EQ();
// FIXME: Add the calls to clad::differentiate/gradient...
}

0 comments on commit ab2e9bd

Please sign in to comment.