Skip to content

Commit

Permalink
sorting: add to binsort support for strided views and reorg tests (ko…
Browse files Browse the repository at this point in the history
…kkos#6081)

* binsort: support strided views, reorg tests [skip ci]

* should be working for cuda

* cleanup sorting and random tests

* cleanup and reorg tests for random and sort

* fixes for CI, remove unused guards

* update

* fix integer type and makefile

* fix tests to use hpp, and fix template for windows

* formatting

* fix typo

* rename

* use assert_true

(sorry DLG for the CI troubles)

* fix for nvhpc

* address comments

* remove wrong closing bracket
  • Loading branch information
fnrizzi committed May 25, 2023
1 parent 2a5c949 commit b3f9f78
Show file tree
Hide file tree
Showing 13 changed files with 656 additions and 509 deletions.
16 changes: 9 additions & 7 deletions algorithms/src/Kokkos_Sort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,12 @@ class BinSort {
Kokkos::is_view<SrcViewType>::value,
Kokkos::View<typename SrcViewType::const_data_type,
typename SrcViewType::array_layout,
typename SrcViewType::device_type,
Kokkos::MemoryTraits<Kokkos::RandomAccess> >,
typename SrcViewType::device_type
#if !defined(KOKKOS_COMPILER_NVHPC) // FIXME_NVHPC
,
Kokkos::MemoryTraits<Kokkos::RandomAccess>
#endif
>,
typename SrcViewType::const_type>;

using perm_view_type = typename PermuteViewType::const_type;
Expand Down Expand Up @@ -348,18 +352,16 @@ class BinSort {
"The provided execution space must be able to access the memory space "
"of the View argument!");

using scratch_view_type =
Kokkos::View<typename ValuesViewType::data_type,
typename ValuesViewType::array_layout,
typename ValuesViewType::device_type>;

const size_t len = range_end - range_begin;
const size_t values_len = values_range_end - values_range_begin;
if (len != values_len) {
Kokkos::abort(
"BinSort::sort: values range length != permutation vector length");
}

using scratch_view_type =
Kokkos::View<typename ValuesViewType::data_type,
typename ValuesViewType::device_type>;
scratch_view_type sorted_values(
view_alloc(exec, WithoutInitializing,
"Kokkos::SortImpl::BinSortFunctor::sorted_values"),
Expand Down
81 changes: 50 additions & 31 deletions algorithms/unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,45 @@ foreach(Tag Threads;Serial;OpenMP;Cuda;HPX;HIP;SYCL;OpenMPTarget)
set(dir ${CMAKE_CURRENT_BINARY_DIR}/${dir})
file(MAKE_DIRECTORY ${dir})

# -------------------------
# Sort1d,3d, Random
# -------------------------
set(SOURCES_A)
if(Tag STREQUAL "OpenMP")
LIST(APPEND SOURCES_A
TestOpenMP_Sort1D.cpp
TestOpenMP_Sort3D.cpp
TestOpenMP_SortDynamicView.cpp
)
endif()

# ------------------------------------------
# Sort
# ------------------------------------------
# Each of these inputs is an .hpp file.
# Generate a .cpp file for each one that runs it on the current backend (Tag),
# and add this .cpp file to the sources for UnitTest_RandomAndSort.
foreach(SOURCES_A_Input
TestRandomCommon
TestSortCommon
TestNestedSort
)
set(file ${dir}/${SOURCES_A_Input}.cpp)
set(ALGO_SORT_SOURCES)
foreach(SOURCE_Input
TestSort
TestBinSortA
TestBinSortB
TestNestedSort
)
set(file ${dir}/${SOURCE_Input}.cpp)
# Write to a temporary intermediate file and call configure_file to avoid
# updating timestamps triggering unnecessary rebuilds on subsequent cmake runs.
file(WRITE ${dir}/dummy.cpp
"#include <Test${Tag}_Category.hpp>\n"
"#include <${SOURCES_A_Input}.hpp>\n"
"#include <${SOURCE_Input}.hpp>\n"
)
configure_file(${dir}/dummy.cpp ${file})
list(APPEND ALGO_SORT_SOURCES ${file})
endforeach()

# ------------------------------------------
# Random
# ------------------------------------------
# do as above
set(ALGO_RANDOM_SOURCES)
foreach(SOURCE_Input
TestRandom
)
set(file ${dir}/${SOURCE_Input}.cpp)
file(WRITE ${dir}/dummy.cpp
"#include <Test${Tag}_Category.hpp>\n"
"#include <${SOURCE_Input}.hpp>\n"
)
configure_file(${dir}/dummy.cpp ${file})
list(APPEND SOURCES_A ${file})
list(APPEND ALGO_RANDOM_SOURCES ${file})
endforeach()

# ------------------------------------------
Expand Down Expand Up @@ -145,6 +155,26 @@ foreach(Tag Threads;Serial;OpenMP;Cuda;HPX;HIP;SYCL;OpenMPTarget)
endif()
endforeach()

# FIXME_OPENMPTARGET This test causes internal compiler errors as of 09/01/22
# when compiling for Intel's Xe-HP GPUs.
# FRIZZI: 04/26/2023: not sure if the compilation error is still applicable
# but we conservatively leave this guard on
if(NOT (KOKKOS_ENABLE_OPENMPTARGET AND KOKKOS_CXX_COMPILER_ID STREQUAL IntelLLVM))
KOKKOS_ADD_EXECUTABLE_AND_TEST(
UnitTest_Sort
SOURCES
UnitTestMain.cpp
${ALGO_SORT_SOURCES}
)

KOKKOS_ADD_EXECUTABLE_AND_TEST(
UnitTest_Random
SOURCES
UnitTestMain.cpp
${ALGO_RANDOM_SOURCES}
)
endif()

# FIXME_OPENMPTARGET These tests cause internal compiler errors as of 09/01/22
# when compiling for Intel's Xe-HP GPUs.
if(KOKKOS_ENABLE_OPENMPTARGET AND KOKKOS_CXX_COMPILER_ID STREQUAL IntelLLVM)
Expand All @@ -160,17 +190,6 @@ if(KOKKOS_ENABLE_OPENMPTARGET AND KOKKOS_CXX_COMPILER_ID STREQUAL IntelLLVM)
)
endif()

# FIXME_OPENMPTARGET This test causes internal compiler errors as of 09/01/22
# when compiling for Intel's Xe-HP GPUs.
if(NOT (KOKKOS_ENABLE_OPENMPTARGET AND KOKKOS_CXX_COMPILER_ID STREQUAL IntelLLVM))
KOKKOS_ADD_EXECUTABLE_AND_TEST(
AlgorithmsUnitTest_RandomAndSort
SOURCES
UnitTestMain.cpp
${SOURCES_A}
)
endif()

foreach(ID A;B;C;D;E)
KOKKOS_ADD_EXECUTABLE_AND_TEST(
AlgorithmsUnitTest_StdSet_${ID}
Expand Down
8 changes: 3 additions & 5 deletions algorithms/unit_tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ TARGETS =

tmp := $(foreach device, $(KOKKOS_DEVICELIST), \
$(if $(filter Test$(device).cpp, $(shell ls Test$(device).cpp 2>/dev/null)),,\
$(shell echo "\#include <Test"${device}"_Category.hpp>" > Test$(device).cpp); \
$(shell echo "\#include <TestRandomCommon.hpp>" >> Test$(device).cpp); \
$(shell echo "\#include <TestSortCommon.hpp>" >> Test$(device).cpp); \
) \
$(shell echo "\#include <Test"${device}"_Category.hpp>" > Test$(device).cpp); \
) \
)

ifeq ($(KOKKOS_INTERNAL_USE_CUDA), 1)
Expand All @@ -52,7 +50,7 @@ ifeq ($(KOKKOS_INTERNAL_USE_THREADS), 1)
endif

ifeq ($(KOKKOS_INTERNAL_USE_OPENMP), 1)
OBJ_OPENMP = TestOpenMP.o TestOpenMP_Sort1D.o TestOpenMP_Sort3D.o TestOpenMP_SortDynamicView.o UnitTestMain.o gtest-all.o
OBJ_OPENMP = TestOpenMP.o UnitTestMain.o gtest-all.o
TARGETS += KokkosAlgorithms_UnitTest_OpenMP
TEST_TARGETS += test-openmp
endif
Expand Down

0 comments on commit b3f9f78

Please sign in to comment.