Skip to content

Commit

Permalink
WIP fix complex issue but the sqrt of hip has some issue
Browse files Browse the repository at this point in the history
  • Loading branch information
yhmtsai committed Feb 6, 2023
1 parent a695ef0 commit 8357af3
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 27 deletions.
3 changes: 3 additions & 0 deletions common/cuda_hip/factorization/par_ic_kernels.hpp.inc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ __global__ __launch_bounds__(default_block_size) void ic_init(
}
auto l_nz = l_row_ptrs[row + 1] - 1;
auto diag = sqrt(l_vals[l_nz]);
printf("%d %lf %lf \n", static_cast<int>(row),
static_cast<double>(real(l_vals[l_nz])),
static_cast<double>(real(diag)));
if (is_finite(diag)) {
l_vals[l_nz] = diag;
} else {
Expand Down
22 changes: 12 additions & 10 deletions core/base/extended_float.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <hip/hip_fp16.h>


#else
class __half;
#endif // __CUDA_ARCH__


Expand Down Expand Up @@ -101,7 +103,7 @@ struct basic_float_traits<float16> {
static constexpr bool rounds_to_nearest = true;
};

#if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__)
// #if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__)
template <>
struct basic_float_traits<__half> {
using type = __half;
Expand All @@ -110,7 +112,7 @@ struct basic_float_traits<__half> {
static constexpr int exponent_bits = 5;
static constexpr bool rounds_to_nearest = true;
};
#endif
// #endif

template <>
struct basic_float_traits<float32> {
Expand Down Expand Up @@ -598,17 +600,17 @@ class complex<gko::half> {
value_type imag() const noexcept { return imag_; }


operator std::complex<gko::float32>() const noexcept
operator std::complex<float>() const noexcept
{
return std::complex<gko::float32>(static_cast<gko::float32>(real_),
static_cast<gko::float32>(imag_));
return std::complex<float>(static_cast<float>(real_),
static_cast<float>(imag_));
}

operator std::complex<double>() const noexcept
{
return std::complex<double>(static_cast<double>(real_),
static_cast<double>(imag_));
}
// operator std::complex<double>() const noexcept
// {
// return std::complex<double>(static_cast<double>(real_),
// static_cast<double>(imag_));
// }

template <typename V>
complex& operator=(const V& val)
Expand Down
4 changes: 3 additions & 1 deletion core/preconditioner/jacobi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,9 @@ void Jacobi<ValueType, IndexType>::generate(const LinOp* system_matrix,
->extract_diagonal_linop());
auto diag_vt =
::gko::detail::temporary_conversion<matrix::Diagonal<ValueType>>::
template create<matrix::Diagonal<previous_precision<ValueType>>>(
template create<matrix::Diagonal<previous_precision<ValueType>>,
matrix::Diagonal<previous_precision<
previous_precision<ValueType>>>>(
diag.get());
if (!diag_vt) {
GKO_NOT_SUPPORTED(system_matrix);
Expand Down
6 changes: 3 additions & 3 deletions hip/base/types.hip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ __device__ __forceinline__ __half abs(const __half& val) { return __habs(val); }

#endif

#if defined(__HIPCC__)
// #if defined(__HIPCC__)
__device__ __forceinline__ float sqrt(float val) { return sqrtf(val); }
__device__ __forceinline__ double sqrt(double val) { return sqrt(val); }
// __device__ __forceinline__ double sqrt(double val) { return sqrt(val); }
__device__ __forceinline__ thrust::complex<float> sqrt(
thrust::complex<float> val)
{
Expand All @@ -144,7 +144,7 @@ __device__ __forceinline__ __half sqrt(__half val)
#else
__device__ __forceinline__ __half sqrt(__half val) { return hsqrt(val); }
#endif
#endif
// #endif


namespace kernels {
Expand Down
24 changes: 12 additions & 12 deletions hip/preconditioner/jacobi_generate_instantiate.inc.hip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


namespace gko {
namespace detail {
#if !defined(__HIP_DEVICE_COMPILE__)
template <>
struct basic_float_traits<__half> {
using type = __half;
static constexpr int sign_bits = 1;
static constexpr int significand_bits = 10;
static constexpr int exponent_bits = 5;
static constexpr bool rounds_to_nearest = true;
};
#endif
} // namespace detail
// namespace detail {
// #if !defined(__HIP_DEVICE_COMPILE__)
// template <>
// struct basic_float_traits<__half> {
// using type = __half;
// static constexpr int sign_bits = 1;
// static constexpr int significand_bits = 10;
// static constexpr int exponent_bits = 5;
// static constexpr bool rounds_to_nearest = true;
// };
// #endif
// } // namespace detail
namespace kernels {
namespace hip {
/**
Expand Down
24 changes: 24 additions & 0 deletions include/ginkgo/core/base/half.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef GKO_BASE_HALF_HPP_
#define GKO_BASE_HALF_HPP_
#include <complex>
#include <type_traits>


#ifdef __CUDA_ARCH__


#include <cuda_fp16.h>


#elif defined(__HIP_DEVICE_COMPILE__)


#include <hip/hip_fp16.h>


#endif // __CUDA_ARCH__


namespace gko {}

#endif // GKO_BASE_HALF_HPP_
3 changes: 2 additions & 1 deletion reference/matrix/ell_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ void advanced_spmv(std::shared_ptr<const ReferenceExecutor> exec,

for (size_type j = 0; j < c->get_size()[1]; j++) {
for (size_type row = 0; row < a->get_size()[0]; row++) {
arithmetic_type result = c->at(row, j);
arithmetic_type result =
static_cast<arithmetic_type>(c->at(row, j));
result *= beta_val;
for (size_type i = 0; i < num_stored_elements_per_row; i++) {
auto val = a_vals(row + i * stride);
Expand Down

0 comments on commit 8357af3

Please sign in to comment.