Skip to content
Merged
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
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "tpls/kokkos"]
path = tpls/kokkos
url = https://github.com/kokkos/kokkos.git
[submodule "tpls/googletest"]
path = tpls/googletest
url = https://github.com/google/googletest.git
56 changes: 37 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
cmake_minimum_required(VERSION 3.21)
project(kokkos_internal CXX)
set(CMAKE_CXX_STANDARD 20 CACHE STRING "The C++ standard to use")
set(CMAKE_CXX_STANDARD_REQUIRED ON)
message(STATUS "Kokkos is building with C++ Standard: ${CMAKE_CXX_STANDARD}")
set(DESUL_ENABLE_FOR_TEST ON CACHE BOOL "Enable Desul test mode (used by subprojects via FetchContent)" FORCE)
include(FetchContent)
set(KOKKOS_FETCH_TAG "5.1.1" CACHE STRING "Kokkos git tag to fetch")
find_package(Kokkos 5.1.1 QUIET)
if (NOT Kokkos_FOUND)
message(STATUS "Kokkos not found locally - fetching tag " "${KOKKOS_FETCH_TAG} via FetchContent")
FetchContent_Declare(kokkos GIT_REPOSITORY https://github.com/kokkos/kokkos.git GIT_TAG ${KOKKOS_FETCH_TAG} GIT_SHALLOW ON)
FetchContent_MakeAvailable(kokkos)
cmake_minimum_required(VERSION 3.22)
project(Kokkos_Nums VERSION 0.0.1 LANGUAGES CXX)
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tpls/kokkos/cmake")
set(Kokkos_Nums_VERSION ${PROJECT_VERSION})
set(Kokkos_Nums_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(Kokkos_Nums_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(Kokkos_Nums_VERSION_PATCH ${PROJECT_VERSION_PATCH})

set(KOKKOS_REQUIRED_VERSION 5.2)
option(Kokkos_Nums_ENABLE_TESTS "Enable tests" ON)
option(Kokkos_Nums_ENABLE_INTERNAL_KOKKOS "Enable internal Kokkos build" OFF)
option(Kokkos_Nums_USE_find_package "Use find_package to locate Kokkos" OFF)
option(Kokkos_Nums_GYSELALIBXX_USE "Use GyselaLibxx" ON)
if(Kokkos_Nums_USE_find_package)
if(NOT TARGET Kokkos::kokkos)
find_package(Kokkos ${KOKKOS_REQUIRED_VERSION} REQUIRED)
endif()
else()
message(STATUS "Using pre-installed Kokkos: ${Kokkos_DIR}")
add_subdirectory(tpls/kokkos)
endif()
FetchContent_Declare(
googletest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG v1.17.0)
FetchContent_MakeAvailable(googletest)
enable_testing()
add_subdirectory(kokkos_tree)
message(STATUS "Kokkos_Nums_ENABLE_TESTS: ${Kokkos_Nums_ENABLE_TESTS}")
message(STATUS "Kokkos_Nums_ENABLE_INTERNAL_KOKKOS: ${Kokkos_Nums_ENABLE_INTERNAL_KOKKOS}")
message(STATUS "Kokkos version: ${Kokkos_VERSION}")
message(STATUS "Kokkos_Nums version major: ${Kokkos_Nums_VERSION_MAJOR}")
message(STATUS "Kokkos_Nums version minor: ${Kokkos_Nums_VERSION_MINOR}")
message(STATUS "Kokkos_Nums version patch: ${Kokkos_Nums_VERSION_PATCH}")
add_library(kokkos_num INTERFACE)
target_link_libraries(kokkos_num INTERFACE Kokkos::kokkos)
target_include_directories(kokkos_num INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
if(Kokkos_Nums_ENABLE_TESTS)
include(CTest)
find_package(GTest CONFIG)
if(NOT GTest_FOUND)
add_subdirectory(tpls/googletest)
endif()
endif()
add_subdirectory(Tests)
add_subdirectory(src)

8 changes: 8 additions & 0 deletions Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
enable_testing()
add_executable(Kokkos_qun_test test_dyn_rank.cpp)
target_link_libraries(Kokkos_qun_test PRIVATE Kokkos::kokkos GTest::gtest)

add_test(
NAME Kokkos_qun_test
COMMAND Kokkos_qun_test
)
File renamed without changes.
29 changes: 29 additions & 0 deletions Tests/kokkos_core/AnalyzeExecPolicyUserMatch.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <Kokkos_Core.hpp>
#include <traits/Kokkos_ExecutionSpaceTrait.hpp>
#include <traits/Kokkos_TeamHandleTrait.hpp>
#include <traits/Kokkos_GraphKernelTrait.hpp>
#include <traits/Kokkos_IndexTypeTrait.hpp>
#include <traits/Kokkos_IterationPatternTrait.hpp>
#include <traits/Kokkos_LaunchBoundsTrait.hpp>
#include <traits/Kokkos_StaticBatchSizeTrait.hpp>
#include <traits/Kokkos_OccupancyControlTrait.hpp>
#include <traits/Kokkos_ScheduleTrait.hpp>
#include <traits/Kokkos_WorkItemPropertyTrait.hpp>
#include <traits/Kokkos_WorkTagTrait.hpp>
#include <impl/Kokkos_AnalyzePolicy.hpp>
#include <traits/Kokkos_Traits_fwd.hpp>
#include <iostream>
using Policy = Kokkos::Impl::AnalyzeExecPolicy<void,Kokkos::Cuda>; //searching ExecutionSpaceTrait
namespace Test{
TEST(AnalyzeExecPolicyUserMatch,line_52_AnalyzeP_file){
using analyzeExecPolicyVoid = Kokkos::Impl::AnalyzeExecPolicy<void>;
static_assert(analyzeExecPolicyVoid::execution_space_is_defaulted, "Not Ok");
using analyzedPolicyExec = Kokkos::Impl::AnalyzeExecPolicy<void,Kokkos::Cuda>;
//auto recv = analyzedPolicyExec::show_execution_space_error_in_compilation_message;
static_assert(std::is_same_v<analyzedPolicyExec::execution_space,Kokkos::Cuda>,"NOT SAME");
using analyzedPolicyExecSch = Kokkos::Impl::AnalyzeExecPolicy<void,Kokkos::Cuda,Kokkos::Schedule<Kokkos::Dynamic>>;
static_assert(std::is_same_v<analyzedPolicyExecSch::base_t::base_t::schedule_type,Kokkos::Schedule<Kokkos::Dynamic>>,"NOT SAME");

}

}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ TEST(mdspan_static_array_impl, line_79_100) {
using Stat_arr = mdspan_detail::static_array_impl<0, size_t, 10, 20, 30>;
static_assert(Stat_arr::get(0) == 10, "Should be 10"); // It's for runtime
static_assert(Stat_arr::get(1) == 20, "Should be 20"); // same for this;
static_assert(Stat_arr::get<2>() == 30, "Should be 30");
//static_assert(Stat_arr::get<2>() == 30, "Should be 30");
using Stat_arr2 = mdspan_detail::static_array_impl<2, size_t, 1, 2, 3>;
static_assert(Stat_arr2::get<2>() == 1, "Should be 1");
//static_assert(Stat_arr2::get<2>() == 1, "Should be 1");
// static_assert(Stat_arr2::get<1>()==1,"Should be 1");
auto val = Stat_arr2::get(2);
std::cout << val << std::endl;
Expand All @@ -42,7 +42,7 @@ TEST(mdspan_static_array_impl, line_79_100) {
using stat_arr = mdspan_detail::static_array<int, 10, 20, 30>;
constexpr auto va = stat_arr::size();
static_assert(va == 3, "Should match 3");
EXPECT_EQ(stat_arr::get<2>(), 30);
//EXPECT_EQ(stat_arr::get<2>(), 30);
using ind_seq = mdspan_detail::index_sequence_scan_impl<0, 1, 2, 3>;
auto constexpr val_in = ind_seq::get(2);
EXPECT_EQ(val_in, 3);
Expand All @@ -62,8 +62,8 @@ TEST(maybe_static_array, line_206_start) {
mdspan_detail::maybe_static_array<size_t, size_t, dynamic_extent, 10,
dynamic_extent, 30>;
using static_array_impl_may_bug = mdspan_detail::static_array_impl<0,int,15,25,35>;
auto constexpr val = static_array_impl_may_bug::get<1>();
EXPECT_EQ(val, 25);
// auto constexpr val = static_array_impl_may_bug::get<1>();
//EXPECT_EQ(val, 25);
// HybridArray my_extents{50};
// using static_val_type = HybridArray::static_vals_t;
// using value_type = static_val_type::value_type; inaccessible as private
Expand Down
2 changes: 1 addition & 1 deletion kokkos_tree/test_dyn_rank.cpp → Tests/test_dyn_rank.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "desul/desul_test.hpp"
#include "kokkos_core/kokkos_pair_investigation.hpp"
#include "mdspan/kokkos_raw_mdspan.hpp"
//#include "mdspan/kokkos_raw_mdspan.hpp"
#include "kokkos_core/test_drank.hpp"
#include "kokkos_core/View_data_analysis_kokkos_investigation.hpp"
#include "mdspan/kokkos_extent_inv.hpp"
Expand Down
17 changes: 0 additions & 17 deletions kokkos_tree/CMakeLists.txt

This file was deleted.

2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_subdirectory(vector)
add_subdirectory(View)
5 changes: 5 additions & 0 deletions src/View/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

add_executable(kokkos_num_exe1 view.cpp)
target_compile_features(kokkos_num_exe1 PUBLIC cxx_std_20)
#target_compile_definitions(kokkos_num_exe1 PUBLIC KOKKOS_NUMS_ENABLE_TESTS)
target_link_libraries(kokkos_num_exe1 PRIVATE kokkos_num)
8 changes: 8 additions & 0 deletions src/View/view.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "view.hpp"

int main(int argc,char* argv[]){
Kokkos::initialize(argc,argv);
create_required_span_rank<Kokkos::View<double*>> (1000000*8,"view1",1000000);
Kokkos::finalize();
return 0;
}
86 changes: 86 additions & 0 deletions src/View/view.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include <Kokkos_Core.hpp>
#include <utility>
template <class ViewType>
KOKKOS_FUNCTION void launch_parallel_kernel(ViewType& view)
{
Kokkos::parallel_for("",Kokkos::RangePolicy<>(0, view.size()), KOKKOS_LAMBDA(int i){
view(i) = static_cast<typename ViewType::value_type>(i);
});
auto host_view = Kokkos::create_mirror_view(view);
Kokkos::deep_copy(host_view, view);
for(size_t i = 0; i < host_view.size(); i++)
{
if(i%20 == 0){
printf("view(%zu) = %f\n", i, static_cast<double>(host_view(i)));
}
}
}
template <class ViewType, std::integral... Sizes>
void create_required_span_rank(size_t expected_size, std::string label, Sizes... sizes)
{
ViewType view(label,sizes...);
size_t req_allocation_size = ViewType::required_allocation_size(sizes...); //this goes to Kokkos::mdspan
//printf("View %s: expected size = %zu, required allocation size = %zu\n", label.c_str(), expected_size, req_allocation_size);
if(expected_size == req_allocation_size)
{
launch_parallel_kernel(view);
}
}
template<class ExecutionSpace, class ExtentsType>
auto make_mdrange_from_extents(const ExtentsType &extents,std::index_sequence<0>)
{
return Kokkos::RangePolicy<ExecutionSpace>{0,static_cast<ExtentsType::index_type>(extents.extent(0))};
}

template<class ExecutionSpace, class ExtentsType, std::size_t... Indices>
auto make_mdrange_from_extents(const ExtentsType &extents, std::index_sequence<Indices...>)
{
using index_type = typename ExtentsType::index_type;
using rank_type = ExtentsType::rank_type;
rank_type rank = ExtentsType::rank();
return Kokkos::MDRangePolicy<ExecutionSpace,Kokkos::Rank<rank>,Kokkos::IndexType<index_type>>{{static_cast<index_type>(0*Indices)...}, {static_cast<index_type>(extents.extent(Indices))...}};
}
template<class T, class ExtentsType,class LayoutType>
auto make_Bview_from_checked_accessor(const ExtentsType &extents){
using extents_type = ExtentsType;
using layout_type = LayoutType;
using accessor_type = Kokkos::Impl::CheckedReferenceCountedAccessor<T, typename ExecutionSpace::memory_space>;
using view_type = Kokkos::Impl::BV::BasicView<T,extents_type, layout_type, accessor_type>;
view_type view("Test View", extents);
for (int r = 0; r<static_cast<int>(view_type::rank()); r++){
expected_size *= extents.extent(r);
}
auto size = view.size();
return std::pair(view, size, expected_size);
}
template<class T, class ExtentsType, class LayoutType>
auto make_BView_from_mapping_and_padding(const ExtentsType &extents, std::size_t padding){
using extents_type = ExtentsType;
using layout_type = LayoutType;
mapping_type = typename layout_type::template mapping_type<ExtentsType>;
using accessor_type = Kokkos::Impl::CheckedReferenceCountedAccessor<T,typename ExecutionSpace::memory_space>;
using view_type = Kokkos::Impl::BV::BasicView<T,extents_type,layout_type, accessor_type>;
auto mapping = mappint_type(extents, padding);
view_type("Bview", mapping);
for (int r =0; r<static_cast<int>(view_type::rank()); r++){
expected_size *= view.extent(r);
}
std::size_t size = view.size();
return std::pair(view, size, expected_size);
}
template <class ExecutionSpace, class FunctorType,class T, class ExtentsType, class LayoutType>
auto make_parallel_run_from_extents(const ExtentsType &extents){
using extents_type = ExtentsType;
using layout_type = LayoutType;
//using mapping_type = typename layout_type::mapping_type<ExtentsType>;
using accessor_type = Kokkos::Impl::CheckedReferenceCountedAccessor<T,typename ExecutionSpace::memory_space>;
using view_type = Kokkos::Impl::BV::BasicView<T,extents_type,layout_type,accessor_type>;
auto view = view_type("Bview", extents);
auto mdrange = make_mdrange_from_extents<ExecutionSpace>(extents,std::make_index_sequence<ExtentsType::rank()>{});
Kokkos::parallel_for("Label", mdrange_policy, mdrange, FuntorType{});
auto host_view = create_mirror_view(view);
Kokkos::deep_copy(host_view,view);
return host_view;
}


5 changes: 5 additions & 0 deletions src/vector/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

add_executable(kokkos_num_exe2 vec_perp.cpp)
target_compile_features(kokkos_num_exe2 PUBLIC cxx_std_20)
#target_compile_definitions(kokkos_num_exe2 PUBLIC KOKKOS_NUMS_ENABLE_TESTS)
target_link_libraries(kokkos_num_exe2 PRIVATE kokkos_num)
13 changes: 13 additions & 0 deletions src/vector/vec_perp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "vec_perp.hpp"
#include <iostream>

int main(int argc, char* argv[]){
Kokkos::initialize(argc, argv);
std::vector<double> A = {1.0,2.0};
std::vector<double> B = {3.0,4.0};
auto result = vector_approach::dot_product<double>(A, B);
std::cout << "Dot product: " << result << std::endl;

Kokkos::finalize();
return 0;
}
42 changes: 42 additions & 0 deletions src/vector/vec_perp.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <Kokkos_Core.hpp>
#include <array>
#include <vector>


namespace vector_prep{
template <class ValueType>
using KokkosView = Kokkos::View<ValueType*,Kokkos::LayoutLeft, Kokkos::CudaSpace>;
template<class ValueType>
using Vector = std::vector<ValueType>;

}

namespace vector_approach{
template<class ValueType>
ValueType dot_product(vector_prep::Vector<ValueType> const& A, vector_prep::Vector<ValueType> const& B){
if(A.size() != B.size())
{
throw std::invalid_argument("Vectors must be of the same size for dot product.");
}
const size_t size = A.size();
vector_prep::KokkosView<ValueType> A_("A", size);
vector_prep::KokkosView<ValueType> B_("B", size);
vector_prep::KokkosView<ValueType> C_("C", size);
auto host_A = Kokkos::create_mirror_view(A_);
auto host_B = Kokkos::create_mirror_view(B_);
for (size_t i = 0; i < size; ++i) {
host_A(i) = A[i];
host_B(i) = B[i];
}
Kokkos::deep_copy(A_,host_A);
Kokkos::deep_copy(B_, host_B);
double sum = 0;
Kokkos::parallel_reduce(Kokkos::RangePolicy<>(0, size), KOKKOS_LAMBDA(int i, double& lsum){
lsum += A_(i) * B_(i);
}, sum);
Kokkos::fence();

return sum;
}
}

1 change: 1 addition & 0 deletions tpls/googletest
Submodule googletest added at f8d7d7
1 change: 1 addition & 0 deletions tpls/kokkos
Submodule kokkos added at d9397f
Loading