From 7475c318becac020a15c657f4667e59918e2fc8b Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Wed, 16 Sep 2020 09:57:54 -0400 Subject: [PATCH] VTK-m now uses CMake's future HIP lang for Kokkos+HIP --- CMake/VTKmDeviceAdapters.cmake | 6 ++++++ CMake/VTKmWrappers.cmake | 7 ++++++- CMake/testing/VTKmTestWrappers.cmake | 10 ++++++++-- vtkm/cont/kokkos/internal/CMakeLists.txt | 3 +++ vtkm/cont/kokkos/testing/CMakeLists.txt | 2 ++ vtkm/internal/CMakeLists.txt | 2 ++ vtkm/internal/Configure.h.in | 4 ++++ 7 files changed, 31 insertions(+), 3 deletions(-) diff --git a/CMake/VTKmDeviceAdapters.cmake b/CMake/VTKmDeviceAdapters.cmake index 050ff3190..200cc3dbf 100644 --- a/CMake/VTKmDeviceAdapters.cmake +++ b/CMake/VTKmDeviceAdapters.cmake @@ -344,6 +344,12 @@ if(VTKm_ENABLE_KOKKOS AND NOT TARGET vtkm::kokkos) message(STATUS "Detected Cuda arch from Kokkos: ${cuda_arch}") add_library(vtkm::kokkos_cuda INTERFACE IMPORTED GLOBAL) + elseif(HIP IN_LIST Kokkos_DEVICES) + cmake_minimum_required(VERSION 3.18 FATAL_ERROR) + enable_language(HIP) + add_library(vtkm::kokkos_hip INTERFACE IMPORTED GLOBAL) + set_property(TARGET Kokkos::kokkoscore PROPERTY INTERFACE_COMPILE_OPTIONS "") + set_property(TARGET Kokkos::kokkoscore PROPERTY INTERFACE_LINK_OPTIONS "") endif() add_library(vtkm::kokkos INTERFACE IMPORTED GLOBAL) diff --git a/CMake/VTKmWrappers.cmake b/CMake/VTKmWrappers.cmake index 4afbe114b..a6cbb12d9 100644 --- a/CMake/VTKmWrappers.cmake +++ b/CMake/VTKmWrappers.cmake @@ -327,6 +327,12 @@ function(vtkm_add_target_information uses_vtkm_target) endforeach() endif() + if((TARGET vtkm::cuda) OR (TARGET vtkm::kokkos_cuda)) + set_source_files_properties(${VTKm_TI_DEVICE_SOURCES} PROPERTIES LANGUAGE "CUDA") + elseif(TARGET vtkm::kokkos_hip) + set_source_files_properties(${VTKm_TI_DEVICE_SOURCES} PROPERTIES LANGUAGE "HIP") + endif() + # Validate that following: # - We are building with CUDA enabled. # - We are building a VTK-m library or a library that wants cross library @@ -335,7 +341,6 @@ function(vtkm_add_target_information uses_vtkm_target) # This is required as CUDA currently doesn't support device side calls across # dynamic library boundaries. if((TARGET vtkm::cuda) OR (TARGET vtkm::kokkos_cuda)) - set_source_files_properties(${VTKm_TI_DEVICE_SOURCES} PROPERTIES LANGUAGE "CUDA") foreach(target IN LISTS targets) get_target_property(lib_type ${target} TYPE) if (TARGET vtkm::cuda) diff --git a/CMake/testing/VTKmTestWrappers.cmake b/CMake/testing/VTKmTestWrappers.cmake index 2be20a6ee..cd736276d 100644 --- a/CMake/testing/VTKmTestWrappers.cmake +++ b/CMake/testing/VTKmTestWrappers.cmake @@ -47,9 +47,15 @@ function(vtkm_create_test_executable vtkm_add_drop_unused_function_flags(${prog}) target_compile_definitions(${prog} PRIVATE ${defines}) - #if all backends are enabled, we can use cuda compiler to handle all possible backends. + #determine if we have a device that requires a separate compiler enabled + set(device_lang_enabled FALSE) + if( (TARGET vtkm::cuda) OR (TARGET vtkm::kokkos_cuda) OR (TARGET vtkm::kokkos_hip)) + set(device_lang_enabled TRUE) + endif() + + #if all backends are enabled, we can use the device compiler to handle all possible backends. set(device_sources) - if(((TARGET vtkm::cuda) OR (TARGET vtkm::kokkos_cuda)) AND enable_all_backends) + if(device_lang_enabled AND enable_all_backends) set(device_sources ${sources}) endif() vtkm_add_target_information(${prog} DEVICE_SOURCES ${device_sources}) diff --git a/vtkm/cont/kokkos/internal/CMakeLists.txt b/vtkm/cont/kokkos/internal/CMakeLists.txt index adaf922dd..8cc5382aa 100644 --- a/vtkm/cont/kokkos/internal/CMakeLists.txt +++ b/vtkm/cont/kokkos/internal/CMakeLists.txt @@ -32,7 +32,10 @@ if (TARGET vtkm::kokkos) if (TARGET vtkm::kokkos_cuda) set_source_files_properties(${sources} TARGET_DIRECTORY vtkm_cont PROPERTIES LANGUAGE CUDA) + elseif(TARGET vtkm::kokkos_hip) + set_source_files_properties(${sources} TARGET_DIRECTORY vtkm_cont PROPERTIES LANGUAGE HIP) endif() + else() target_sources(vtkm_cont PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/DeviceAdapterRuntimeDetectorKokkos.cxx) diff --git a/vtkm/cont/kokkos/testing/CMakeLists.txt b/vtkm/cont/kokkos/testing/CMakeLists.txt index 2377a9703..2921f825c 100644 --- a/vtkm/cont/kokkos/testing/CMakeLists.txt +++ b/vtkm/cont/kokkos/testing/CMakeLists.txt @@ -29,4 +29,6 @@ vtkm_unit_tests(SOURCES ${unit_tests} LABEL "KOKKOS" LIBRARIES vtkm_worklet) if (TARGET vtkm::kokkos_cuda) set_source_files_properties(${unit_tests} PROPERTIES LANGUAGE CUDA) +elseif(TARGET vtkm::kokkos_hip) + set_source_files_properties(${unit_tests} PROPERTIES LANGUAGE HIP) endif() diff --git a/vtkm/internal/CMakeLists.txt b/vtkm/internal/CMakeLists.txt index 0a9ef5499..cb537f342 100755 --- a/vtkm/internal/CMakeLists.txt +++ b/vtkm/internal/CMakeLists.txt @@ -33,6 +33,8 @@ endif() if (TARGET vtkm::kokkos_cuda) set(VTKM_KOKKOS_CUDA ON) +elseif(TARGET vtkm::kokkos_hip) + set(VTKM_KOKKOS_HIP ON) endif() set(VTKM_ENABLE_LOGGING ${VTKm_ENABLE_LOGGING}) diff --git a/vtkm/internal/Configure.h.in b/vtkm/internal/Configure.h.in index 06dd2b676..1725671bb 100644 --- a/vtkm/internal/Configure.h.in +++ b/vtkm/internal/Configure.h.in @@ -287,6 +287,10 @@ #ifndef VTKM_KOKKOS_CUDA #cmakedefine VTKM_KOKKOS_CUDA #endif +//Mark if Kokkos has HIP backend enabled +#ifndef VTKM_KOKKOS_HIP +#cmakedefine VTKM_KOKKOS_HIP +#endif //Mark if we are building with MPI enabled. #cmakedefine VTKM_ENABLE_MPI