Skip to content

Commit 1c25d07

Browse files
alexeyvoronov-intelvladimirlaz
authored andcommitted
[SYCL] Add floor and ceil math built-in's
Signed-off-by: Voronov, Alexey <[email protected]> Signed-off-by: Vladimir Lazarev <[email protected]>
1 parent 0c35456 commit 1c25d07

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

sycl/include/CL/sycl/math.hpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,21 @@ GEN_FUNC_OF_THREE_ARG(mad, double, double, double, double)
175175
// genfloatf exp (genfloatf x)
176176
GEN_FUNC_OF_ONE_ARG(native_exp, float, float)
177177

178-
// genfloatf fabs (genfloatf x)
178+
// genfloat fabs (genfloatf x)
179179
GEN_FUNC_OF_ONE_ARG(fabs, float, float)
180180
GEN_FUNC_OF_ONE_ARG(fabs, double, double)
181181
// GEN_FUNC_OF_ONE_ARG(fabs, half, half)
182182

183+
// genfloat floor (genfloat x)
184+
GEN_FUNC_OF_ONE_ARG(floor, float, float)
185+
GEN_FUNC_OF_ONE_ARG(floor, double, double)
186+
// GEN_FUNC_OF_ONE_ARG(floor, half, half)
187+
188+
// genfloat ceil (genfloat x)
189+
GEN_FUNC_OF_ONE_ARG(ceil, float, float)
190+
GEN_FUNC_OF_ONE_ARG(ceil, double, double)
191+
// GEN_FUNC_OF_ONE_ARG(ceil, half, half)
192+
183193
/* --------------- 4.13.4 Integer functions. Device version -----------------*/
184194
// geninteger max (geninteger x, geninteger y)
185195
GEN_FUNC_OF_TWO_ARG(max, char, char, char)
@@ -293,6 +303,12 @@ template <typename T> T sqrt(T x) {
293303
template <typename T> T fabs(T x) {
294304
return __sycl_std::fabs(x);
295305
}
306+
template <typename T> T floor(T x) {
307+
return __sycl_std::floor(x);
308+
}
309+
template <typename T> T ceil(T x) {
310+
return __sycl_std::ceil(x);
311+
}
296312
namespace native {
297313
template <typename T> T exp(T x) {
298314
#ifdef __SYCL_DEVICE_ONLY__

sycl/test/math/math.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,15 @@ int main() {
5151
resultAccessor[wiID.get(0)] += cl::sycl::native::exp(2.f);
5252
resultAccessor[wiID.get(0)] += cl::sycl::fabs(-2.f);
5353
resultAccessor[wiID.get(0)] += cl::sycl::fabs(1.0);
54+
resultAccessor[wiID.get(0)] += cl::sycl::floor(-3.4);
55+
resultAccessor[wiID.get(0)] += cl::sycl::ceil(2.4);
5456
});
5557
});
5658
}
57-
5859
for (size_t i = 0; i < 10; ++i) {
59-
/* Result of addition of 2 + 1 + 7.389... + 2 + 1*/
60-
assert(result[i] > 13 && result[i] < 14 &&
61-
"Expected result[i] > 13 && result[i] < 14");
60+
/* Result of addition of 2 + 1 + 7.389... + 2 + 1 -4 + 3*/
61+
assert(result[i] > 12 && result[i] < 13 &&
62+
"Expected result[i] > 12 && result[i] < 13");
6263
}
6364

6465
return 0;

0 commit comments

Comments
 (0)