Skip to content

Commit 1a0081b

Browse files
authored
ELEMWISE 1arg_1types add 1 MKL kernel (#137)
* ELEMWISE 1arg_1types add MKL kernels
1 parent 729592c commit 1a0081b

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

dpnp/backend/backend_iface.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ INP_DLLEXPORT void custom_var_c(
396396
* @param [in] size Number of elements in the input array.
397397
*
398398
*/
399-
#define MACRO_CUSTOM_1ARG_1TYPE_OP(__name__, __operation__) \
399+
#define MACRO_CUSTOM_1ARG_1TYPE_OP(__name__, __operation1__, __operation2__) \
400400
template <typename _DataType> \
401401
INP_DLLEXPORT void __name__(void* array1, void* result1, size_t size);
402402

dpnp/backend/custom_1arg_1type_tbl.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,19 @@
3131
* Parameters:
3232
* - public name of the function and kernel name
3333
* - operation used to calculate the result
34+
* - mkl operation used to calculate the result
3435
*
3536
*/
3637

3738
#ifndef MACRO_CUSTOM_1ARG_1TYPE_OP
3839
#error "MACRO_CUSTOM_1ARG_1TYPE_OP is not defined"
3940
#endif
4041

41-
MACRO_CUSTOM_1ARG_1TYPE_OP(dpnp_recip_c,
42-
_DataType(1) / input_elem) // error: no member named 'recip' in namespace 'cl::sycl'
43-
MACRO_CUSTOM_1ARG_1TYPE_OP(dpnp_sign_c, cl::sycl::sign((double)input_elem)) // no sycl::sign for int and long
44-
MACRO_CUSTOM_1ARG_1TYPE_OP(dpnp_square_c, input_elem* input_elem)
42+
MACRO_CUSTOM_1ARG_1TYPE_OP(dpnp_recip_c, _DataType(1) / input_elem,
43+
DPNP_QUEUE.submit(kernel_func)) // error: no member named 'recip' in namespace 'cl::sycl'
44+
MACRO_CUSTOM_1ARG_1TYPE_OP(dpnp_sign_c, cl::sycl::sign((double)input_elem),
45+
DPNP_QUEUE.submit(kernel_func)) // no sycl::sign for int and long
46+
MACRO_CUSTOM_1ARG_1TYPE_OP(dpnp_square_c, input_elem * input_elem,
47+
oneapi::mkl::vm::sqr(DPNP_QUEUE, size, array1, result))
4548

4649
#undef MACRO_CUSTOM_1ARG_1TYPE_OP

dpnp/backend/custom_kernels_elemwise.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,15 @@ static void func_map_init_elemwise_1arg_2type(func_map_t& fmap)
202202
return;
203203
}
204204

205-
#define MACRO_CUSTOM_1ARG_1TYPE_OP(__name__, __operation__) \
205+
#define MACRO_CUSTOM_1ARG_1TYPE_OP(__name__, __operation1__, __operation2__) \
206206
template <typename _KernelNameSpecialization> \
207207
class __name__##_kernel; \
208208
\
209209
template <typename _DataType> \
210210
void __name__(void* array1_in, void* result1, size_t size) \
211211
{ \
212212
cl::sycl::event event; \
213+
\
213214
_DataType* array1 = reinterpret_cast<_DataType*>(array1_in); \
214215
_DataType* result = reinterpret_cast<_DataType*>(result1); \
215216
\
@@ -218,15 +219,22 @@ static void func_map_init_elemwise_1arg_2type(func_map_t& fmap)
218219
size_t i = global_id[0]; /*for (size_t i = 0; i < size; ++i)*/ \
219220
{ \
220221
_DataType input_elem = array1[i]; \
221-
result[i] = __operation__; \
222+
result[i] = __operation1__; \
222223
} \
223224
}; \
224225
\
225226
auto kernel_func = [&](cl::sycl::handler& cgh) { \
226227
cgh.parallel_for<class __name__##_kernel<_DataType>>(gws, kernel_parallel_for_func); \
227228
}; \
228229
\
229-
event = DPNP_QUEUE.submit(kernel_func); \
230+
if constexpr (std::is_same<_DataType, double>::value) \
231+
{ \
232+
event = __operation2__; \
233+
} \
234+
else \
235+
{ \
236+
event = DPNP_QUEUE.submit(kernel_func); \
237+
} \
230238
\
231239
event.wait(); \
232240
}

0 commit comments

Comments
 (0)