Skip to content

Commit 55045c0

Browse files
committed
Change unops to use *f functions for single precision
1 parent 3810ae6 commit 55045c0

3 files changed

Lines changed: 46 additions & 6 deletions

File tree

‎include/kernel_float/unops.h‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,26 @@ KERNEL_FLOAT_DEFINE_UNARY_OP(logical_not, !, (ops::cast<bool, T> {}(!ops::cast<T
135135
}; \
136136
\
137137
template<> \
138+
struct NAME<float> { \
139+
KERNEL_FLOAT_INLINE float operator()(float input) { \
140+
return ops::cast<decltype(EXPR_F32), float> {}(EXPR_F32); \
141+
} \
142+
}; \
143+
\
144+
template<> \
138145
struct NAME<double> { \
139146
KERNEL_FLOAT_INLINE double operator()(double input) { \
140147
return double(EXPR_F64); \
141148
} \
142149
}; \
143150
}
144151

145-
#define KERNEL_FLOAT_DEFINE_UNARY_MATH(NAME) \
152+
#define KERNEL_FLOAT_DEFINE_UNARY_MATH_FUN(NAME, FUN_F64, FUN_F32) \
146153
KERNEL_FLOAT_DEFINE_UNARY_STRUCT(NAME, ::NAME(input), ::NAME(input)) \
147154
KERNEL_FLOAT_DEFINE_UNARY_FUN(NAME)
148155

156+
#define KERNEL_FLOAT_DEFINE_UNARY_MATH(NAME) KERNEL_FLOAT_DEFINE_UNARY_MATH_FUN(NAME, NAME, NAME##f)
157+
149158
KERNEL_FLOAT_DEFINE_UNARY_MATH(sin)
150159
KERNEL_FLOAT_DEFINE_UNARY_MATH(cos)
151160
KERNEL_FLOAT_DEFINE_UNARY_MATH(tan)
@@ -177,7 +186,7 @@ KERNEL_FLOAT_DEFINE_UNARY_MATH(tgamma)
177186
KERNEL_FLOAT_DEFINE_UNARY_MATH(sqrt)
178187
KERNEL_FLOAT_DEFINE_UNARY_MATH(cbrt)
179188

180-
KERNEL_FLOAT_DEFINE_UNARY_MATH(abs)
189+
KERNEL_FLOAT_DEFINE_UNARY_MATH_FUN(abs, fabs, fabsf)
181190
KERNEL_FLOAT_DEFINE_UNARY_MATH(floor)
182191
KERNEL_FLOAT_DEFINE_UNARY_MATH(round)
183192
KERNEL_FLOAT_DEFINE_UNARY_MATH(ceil)

‎single_include/kernel_float.h‎

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
//================================================================================
1818
// this file has been auto-generated, do not modify its contents!
19-
// date: 2026-06-08 12:00:54.978716
20-
// git hash: d47bafcb5d8554b5eb1a4618a883f85d6411b24e
19+
// date: 2026-06-18 10:19:56.606511
20+
// git hash: 3810ae656e2763c17aa31fa5d86fb24b7c3200ef
2121
//================================================================================
2222

2323
#ifndef KERNEL_FLOAT_MACROS_H
@@ -1355,17 +1355,26 @@ KERNEL_FLOAT_DEFINE_UNARY_OP(logical_not, !, (ops::cast<bool, T> {}(!ops::cast<T
13551355
}; \
13561356
\
13571357
template<> \
1358+
struct NAME<float> { \
1359+
KERNEL_FLOAT_INLINE float operator()(float input) { \
1360+
return ops::cast<decltype(EXPR_F32), float> {}(EXPR_F32); \
1361+
} \
1362+
}; \
1363+
\
1364+
template<> \
13581365
struct NAME<double> { \
13591366
KERNEL_FLOAT_INLINE double operator()(double input) { \
13601367
return double(EXPR_F64); \
13611368
} \
13621369
}; \
13631370
}
13641371

1365-
#define KERNEL_FLOAT_DEFINE_UNARY_MATH(NAME) \
1372+
#define KERNEL_FLOAT_DEFINE_UNARY_MATH_FUN(NAME, FUN_F64, FUN_F32) \
13661373
KERNEL_FLOAT_DEFINE_UNARY_STRUCT(NAME, ::NAME(input), ::NAME(input)) \
13671374
KERNEL_FLOAT_DEFINE_UNARY_FUN(NAME)
13681375

1376+
#define KERNEL_FLOAT_DEFINE_UNARY_MATH(NAME) KERNEL_FLOAT_DEFINE_UNARY_MATH_FUN(NAME, NAME, NAME##f)
1377+
13691378
KERNEL_FLOAT_DEFINE_UNARY_MATH(sin)
13701379
KERNEL_FLOAT_DEFINE_UNARY_MATH(cos)
13711380
KERNEL_FLOAT_DEFINE_UNARY_MATH(tan)
@@ -3427,7 +3436,26 @@ struct is_vector_impl<vector_ref<T, N, Policy>> {
34273436
};
34283437

34293438
/**
3430-
* Creates a `vector_ptr<T, N, U>` from a raw pointer `U*`.
3439+
* Creates a `vector_ptr` from a raw pointer `U*`.
3440+
*
3441+
* This name resolves to one of four overloads depending on how it is called:
3442+
*
3443+
* 1. No template arguments: `make_vec_ptr(ptr)`.
3444+
* Returns `vec_ptr<U, 1, U, KERNEL_FLOAT_MAX_ALIGNMENT>`.
3445+
* The pointer is assumed to be aligned to `KERNEL_FLOAT_MAX_ALIGNMENT`.
3446+
*
3447+
* 2. Integer template argument: `make_vec_ptr<N>(ptr)`.
3448+
* Returns `vec_ptr<U, N, U, N>`.
3449+
* The pointer is assumed to be aligned for `N` consecutive elements.
3450+
*
3451+
* 3. Type template argument: `make_vec_ptr<T>(ptr)`.
3452+
* Returns `vector_ptr<T, 1, U, 1>`.
3453+
* Elements are stored as `U` but viewed as `T`, with element-aligned access.
3454+
*
3455+
* 4. Type and size template arguments: `make_vec_ptr<T, N>(ptr)`.
3456+
* Returns `vector_ptr<T, N, U, N>`.
3457+
* Elements are stored as `U` but viewed as `T`, assuming alignment for `N` elements.
3458+
*
34313459
*
34323460
* @tparam T The type of the elements as viewed by the user.
34333461
* @tparam N The vector size in number of elements.

‎tests/unops.cu‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ struct unops_float_tests {
7878
b = rcp(a);
7979
ASSERT_EQ_ALL(b[I], T(1.0 / items[I]));
8080

81+
b = erf(a);
82+
ASSERT_EQ_ALL(b[I], erf(T(items[I])));
83+
8184
// seems that rsqrt does not match bitwise on GPU
8285
b = rsqrt(a);
8386
ASSERT_APPROX_ALL(b[I], T(1.0 / sqrt(double(items[I]))));

0 commit comments

Comments
 (0)