Skip to content

Commit

Permalink
make hipFFT dependency optional
Browse files Browse the repository at this point in the history
  • Loading branch information
upsj committed Sep 17, 2021
1 parent f44111e commit 4242fd0
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 47 deletions.
2 changes: 1 addition & 1 deletion cmake/GinkgoConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ endif()
if((NOT GINKGO_BUILD_SHARED_LIBS) AND GINKGO_BUILD_HIP)
find_package(HIP REQUIRED)
find_package(hipblas REQUIRED)
find_package(hipfft REQUIRED)
find_package(hipfft) # optional
find_package(hiprand REQUIRED)
find_package(hipsparse REQUIRED)
find_package(rocrand REQUIRED)
Expand Down
2 changes: 2 additions & 0 deletions dev_tools/scripts/config
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
- FixInclude: "ginkgo/core/base/executor.hpp"
- "hip/base/config.hip.hpp"
- FixInclude: "hip/hip_runtime.h"
- "hip/matrix/fft_kernels_stub"
- FixInclude: "core/matrix/fft_kernels.hpp"
- "(cuda|hip|omp|dpcpp)/test/factorization/par_ilu_kernels"
- FixInclude: "core/factorization/par_ilu_kernels.hpp"
- "(cuda|hip|omp|dpcpp)/test/factorization/par_ilut_kernels"
Expand Down
14 changes: 11 additions & 3 deletions hip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ set(HIP_HIPCC_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}" CACHE STR

find_package(HIP REQUIRED)
find_package(hipblas REQUIRED)
find_package(hipfft REQUIRED)
find_package(hipfft) # optional dependency
find_package(hiprand REQUIRED)
find_package(hipsparse REQUIRED)
# At the moment, for hiprand to work also rocrand is required.
Expand Down Expand Up @@ -178,7 +178,6 @@ set(GINKGO_HIP_SOURCES
matrix/diagonal_kernels.hip.cpp
matrix/ell_kernels.hip.cpp
matrix/fbcsr_kernels.hip.cpp
matrix/fft_kernels.hip.cpp
matrix/hybrid_kernels.hip.cpp
matrix/sellp_kernels.hip.cpp
matrix/sparsity_csr_kernels.hip.cpp
Expand Down Expand Up @@ -211,6 +210,12 @@ set(GINKGO_HIP_SOURCES
../common/unified/solver/ir_kernels.cpp
)

if(hipfft_FOUND)
list(APPEND GINKGO_HIP_SOURCES matrix/fft_kernels.hip.cpp)
else()
list(APPEND GINKGO_HIP_SOURCES matrix/fft_kernels_stub.hip.cpp)
endif()

if (GINKGO_HIP_PLATFORM MATCHES "${HIP_PLATFORM_NVIDIA_REGEX}")
set(GKO_HIP_JACOBI_MAX_BLOCK_SIZE 32)
else()
Expand Down Expand Up @@ -306,7 +311,10 @@ target_include_directories(ginkgo_hip
$<BUILD_INTERFACE:${ROCPRIM_INCLUDE_DIRS}>)

target_link_libraries(ginkgo_hip PUBLIC ginkgo_device)
target_link_libraries(ginkgo_hip PRIVATE roc::hipblas roc::hipsparse hip::hiprand roc::rocrand hip::hipfft)
target_link_libraries(ginkgo_hip PRIVATE roc::hipblas roc::hipsparse hip::hiprand roc::rocrand)
if (hipfft_FOUND)
target_link_libraries(ginkgo_hip PRIVATE hip::hipfft)
endif()

target_compile_options(ginkgo_hip PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${GINKGO_COMPILER_FLAGS}>)

Expand Down
29 changes: 0 additions & 29 deletions hip/base/exception.hip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <hip/hip_runtime.h>
#include <hipblas.h>
#include <hipfft.h>
#include <hiprand.h>
#include <hipsparse.h>

Expand Down Expand Up @@ -125,32 +124,4 @@ std::string HipsparseError::get_error(int64 error_code)
}


std::string HipfftError::get_error(int64 error_code)
{
#define GKO_REGISTER_HIPFFT_ERROR(error_name) \
if (error_code == int64(error_name)) { \
return #error_name; \
}
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_SUCCESS)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_INVALID_PLAN)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_ALLOC_FAILED)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_INVALID_TYPE)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_INVALID_VALUE)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_INTERNAL_ERROR)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_EXEC_FAILED)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_SETUP_FAILED)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_INVALID_SIZE)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_UNALIGNED_DATA)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_INCOMPLETE_PARAMETER_LIST)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_INVALID_DEVICE)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_PARSE_ERROR)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_NO_WORKSPACE)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_NOT_IMPLEMENTED)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_NOT_SUPPORTED)
return "Unknown error";

#undef GKO_REGISTER_HIPFFT_ERROR
}


} // namespace gko
34 changes: 34 additions & 0 deletions hip/matrix/fft_kernels.hip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,36 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


namespace gko {


std::string HipfftError::get_error(int64 error_code)
{
#define GKO_REGISTER_HIPFFT_ERROR(error_name) \
if (error_code == int64(error_name)) { \
return #error_name; \
}
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_SUCCESS)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_INVALID_PLAN)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_ALLOC_FAILED)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_INVALID_TYPE)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_INVALID_VALUE)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_INTERNAL_ERROR)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_EXEC_FAILED)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_SETUP_FAILED)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_INVALID_SIZE)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_UNALIGNED_DATA)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_INCOMPLETE_PARAMETER_LIST)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_INVALID_DEVICE)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_PARSE_ERROR)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_NO_WORKSPACE)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_NOT_IMPLEMENTED)
GKO_REGISTER_HIPFFT_ERROR(HIPFFT_NOT_SUPPORTED)
return "Unknown error";

#undef GKO_REGISTER_HIPFFT_ERROR
}


namespace kernels {
namespace hip {
/**
Expand All @@ -55,6 +85,10 @@ namespace hip {
namespace fft {


template <typename InValueType, typename OutValueType>
struct hipfft_type_impl {};


template <>
struct hipfft_type_impl<std::complex<float>, std::complex<float>> {
constexpr static auto value = HIPFFT_C2C;
Expand Down
84 changes: 84 additions & 0 deletions hip/matrix/fft_kernels_stub.hip.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*******************************<GINKGO LICENSE>******************************
Copyright (c) 2017-2021, the Ginkgo authors
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************<GINKGO LICENSE>*******************************/

#include "core/matrix/fft_kernels.hpp"


#include <ginkgo/core/base/exception_helpers.hpp>
#include <ginkgo/core/base/math.hpp>
#include <ginkgo/core/matrix/dense.hpp>


namespace gko {
namespace kernels {
namespace hip {
/**
* @brief The FFT matrix format namespace.
* @ref Fft
* @ingroup fft
*/
namespace fft {


template <typename ValueType>
void fft(std::shared_ptr<const DefaultExecutor> exec,
const matrix::Dense<std::complex<ValueType>>* b,
matrix::Dense<std::complex<ValueType>>* x, bool inverse,
Array<char>& buffer) GKO_NOT_IMPLEMENTED;

GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE(GKO_DECLARE_FFT_KERNEL);


template <typename ValueType>
void fft2(std::shared_ptr<const DefaultExecutor> exec,
const matrix::Dense<std::complex<ValueType>>* b,
matrix::Dense<std::complex<ValueType>>* x, size_type size1,
size_type size2, bool inverse,
Array<char>& buffer) GKO_NOT_IMPLEMENTED;

GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE(GKO_DECLARE_FFT2_KERNEL);


template <typename ValueType>
void fft3(std::shared_ptr<const DefaultExecutor> exec,
const matrix::Dense<std::complex<ValueType>>* b,
matrix::Dense<std::complex<ValueType>>* x, size_type size1,
size_type size2, size_type size3, bool inverse,
Array<char>& buffer) GKO_NOT_IMPLEMENTED;

GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE(GKO_DECLARE_FFT3_KERNEL);


} // namespace fft
} // namespace hip
} // namespace kernels
} // namespace gko
13 changes: 0 additions & 13 deletions hip/test/base/exception_helpers.hip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <hip/hip_runtime.h>
#include <hipblas.h>
#include <hipfft.h>
#include <hiprand.h>
#include <hipsparse.h>

Expand Down Expand Up @@ -94,16 +93,4 @@ TEST(AssertNoHipsparseErrors, DoesNotThrowOnSuccess)
}


TEST(AssertNoHipfftErrors, ThrowsOnError)
{
ASSERT_THROW(GKO_ASSERT_NO_HIPFFT_ERRORS(1), gko::HipfftError);
}


TEST(AssertNoHipfftErrors, DoesNotThrowOnSuccess)
{
ASSERT_NO_THROW(GKO_ASSERT_NO_HIPFFT_ERRORS(HIPFFT_SUCCESS));
}


} // namespace
4 changes: 3 additions & 1 deletion hip/test/matrix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ ginkgo_create_hip_test(dense_kernels)
ginkgo_create_hip_test(diagonal_kernels)
ginkgo_create_hip_test(ell_kernels)
ginkgo_create_hip_test(fbcsr_kernels)
ginkgo_create_hip_test(fft_kernels)
if (hipfft_FOUND)
ginkgo_create_hip_test(fft_kernels)
endif()
ginkgo_create_hip_test(hybrid_kernels)
ginkgo_create_hip_test(sellp_kernels)
16 changes: 16 additions & 0 deletions hip/test/matrix/fft_kernels.hip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <random>


#include <hipfft.h>


#include <gtest/gtest.h>


Expand Down Expand Up @@ -277,4 +280,17 @@ TYPED_TEST(Fft, ApplyStrided3DInverseIsEqualToReference)
}


// since hipFFT is optional, we test the exception behavior here
TEST(AssertNoHipfftErrors, ThrowsOnError)
{
ASSERT_THROW(GKO_ASSERT_NO_HIPFFT_ERRORS(1), gko::HipfftError);
}


TEST(AssertNoHipfftErrors, DoesNotThrowOnSuccess)
{
ASSERT_NO_THROW(GKO_ASSERT_NO_HIPFFT_ERRORS(HIPFFT_SUCCESS));
}


} // namespace

0 comments on commit 4242fd0

Please sign in to comment.