mirror of
https://github.com/ROCm/composable_kernel.git
synced 2026-05-19 20:40:07 +00:00
Use ck::half_t for Host Reduction (#195)
* Add math functions for host
* Change to host reduction to use ck::math:
* Remove the using of half_float::half and half.hpp from reduction example/profiler/ctest
[ROCm/composable_kernel commit: c1ef73192e]
This commit is contained in:
@@ -1,14 +1,64 @@
|
||||
#ifndef CK_MATH_V2_HPP
|
||||
#define CK_MATH_V2_HPP
|
||||
|
||||
#include <cmath>
|
||||
#include "data_type.hpp"
|
||||
#include "half.hpp"
|
||||
|
||||
namespace ck {
|
||||
namespace math {
|
||||
|
||||
static inline __device__ half_t abs(half_t x) { return __habs(x); };
|
||||
static inline __device__ half_t sqrtf(half_t x) { return hsqrt(x); };
|
||||
static inline __device__ bool isnan(half_t x) { return __hisnan(x); };
|
||||
static inline __host__ float abs(float x) { return std::abs(x); };
|
||||
|
||||
static inline __host__ double abs(double x) { return std::abs(x); };
|
||||
|
||||
static inline __host__ int8_t abs(int8_t x)
|
||||
{
|
||||
int8_t sgn = x >> (8 - 1);
|
||||
|
||||
return (x ^ sgn) - sgn;
|
||||
};
|
||||
|
||||
static inline __host__ int32_t abs(int32_t x)
|
||||
{
|
||||
int32_t sgn = x >> (32 - 1);
|
||||
|
||||
return (x ^ sgn) - sgn;
|
||||
};
|
||||
|
||||
static inline __host__ half_t abs(half_t x)
|
||||
{
|
||||
half_float::half xx = *reinterpret_cast<half_float::half*>(&x);
|
||||
|
||||
half_float::half abs_xx = half_float::abs(xx);
|
||||
|
||||
half_t abs_x = *reinterpret_cast<half_t*>(&abs_xx);
|
||||
|
||||
return abs_x;
|
||||
};
|
||||
|
||||
static inline __host__ float isnan(float x) { return std::isnan(x); };
|
||||
|
||||
static inline __host__ double isnan(double x) { return std::isnan(x); };
|
||||
|
||||
static inline __host__ int8_t isnan(int8_t x)
|
||||
{
|
||||
(void)x;
|
||||
return false;
|
||||
};
|
||||
|
||||
static inline __host__ int32_t isnan(int32_t x)
|
||||
{
|
||||
(void)x;
|
||||
return false;
|
||||
};
|
||||
|
||||
static inline __host__ bool isnan(half_t x)
|
||||
{
|
||||
half_float::half xx = *reinterpret_cast<half_float::half*>(&x);
|
||||
|
||||
return half_float::isnan(xx);
|
||||
};
|
||||
|
||||
} // namespace math
|
||||
} // namespace ck
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace ck {
|
||||
struct float_equal_one
|
||||
{
|
||||
template <class T>
|
||||
__device__ inline bool operator()(T x)
|
||||
__host__ __device__ inline bool operator()(T x)
|
||||
{
|
||||
return x <= static_cast<T>(1.0f) and x >= static_cast<T>(1.0f);
|
||||
};
|
||||
@@ -42,7 +42,7 @@ struct float_equal_one
|
||||
struct float_equal_zero
|
||||
{
|
||||
template <class T>
|
||||
__device__ inline bool operator()(T x)
|
||||
__host__ __device__ inline bool operator()(T x)
|
||||
{
|
||||
return x <= static_cast<T>(0.0f) and x >= static_cast<T>(0.0f);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user