Skip to content

Add support of logical comparison operations #1280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 63 additions & 6 deletions dpnp/backend/include/dpnp_gen_1arg_1type_tbl.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//*****************************************************************************
// Copyright (c) 2016-2020, Intel Corporation
// Copyright (c) 2016-2023, Intel Corporation
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand All @@ -23,6 +23,8 @@
// THE POSSIBILITY OF SUCH DAMAGE.
//*****************************************************************************

#if defined(MACRO_1ARG_1TYPE_OP)

/*
* This header file contains single argument element wise functions definitions
*
Expand All @@ -35,10 +37,6 @@
*
*/

#ifndef MACRO_1ARG_1TYPE_OP
#error "MACRO_1ARG_1TYPE_OP is not defined"
#endif

#ifdef _SECTION_DOCUMENTATION_GENERATION_

#define MACRO_1ARG_1TYPE_OP(__name__, __operation1__, __operation2__) \
Expand Down Expand Up @@ -88,7 +86,7 @@
const shape_elem_type* input1_strides, \
const size_t* where);

#endif
#endif // _SECTION_DOCUMENTATION_GENERATION_

MACRO_1ARG_1TYPE_OP(dpnp_conjugate_c, std::conj(input_elem), q.submit(kernel_func))
MACRO_1ARG_1TYPE_OP(dpnp_copy_c, input_elem, q.submit(kernel_func))
Expand All @@ -107,3 +105,62 @@ MACRO_1ARG_1TYPE_OP(dpnp_square_c,
oneapi::mkl::vm::sqr(q, input1_size, input1_data, result))

#undef MACRO_1ARG_1TYPE_OP

#elif defined(MACRO_1ARG_1TYPE_LOGIC_OP)

/*
* This header file contains single argument element wise functions definitions
*
* Macro `MACRO_1ARG_1TYPE_LOGIC_OP` must be defined before usage
*
* Parameters:
* - public name of the function and kernel name
* - operation used to calculate the result
*
*/

#ifdef _SECTION_DOCUMENTATION_GENERATION_

#define MACRO_1ARG_1TYPE_LOGIC_OP(__name__, __operation__) \
/** @ingroup BACKEND_API */ \
/** @brief Per element operation function __name__ */ \
/** */ \
/** Function "__name__" executes operator "__operation__" over corresponding elements of input array */ \
/** */ \
/** @param[in] q_ref Reference to SYCL queue. */ \
/** @param[out] result_out Output array. */ \
/** @param[in] result_size Output array size. */ \
/** @param[in] result_ndim Number of output array dimensions. */ \
/** @param[in] result_shape Output array shape. */ \
/** @param[in] result_strides Output array strides. */ \
/** @param[in] input1_in Input array 1. */ \
/** @param[in] input1_size Input array 1 size. */ \
/** @param[in] input1_ndim Number of input array 1 dimensions. */ \
/** @param[in] input1_shape Input array 1 shape. */ \
/** @param[in] input1_strides Input array 1 strides. */ \
/** @param[in] where Where condition. */ \
/** @param[in] dep_event_vec_ref Reference to vector of SYCL events. */ \
template <typename _DataType_input1> \
DPCTLSyclEventRef __name__(DPCTLSyclQueueRef q_ref, \
void* result_out, \
const size_t result_size, \
const size_t result_ndim, \
const shape_elem_type* result_shape, \
const shape_elem_type* result_strides, \
const void* input1_in, \
const size_t input1_size, \
const size_t input1_ndim, \
const shape_elem_type* input1_shape, \
const shape_elem_type* input1_strides, \
const size_t* where, \
const DPCTLEventVectorRef dep_event_vec_ref);

#endif // _SECTION_DOCUMENTATION_GENERATION_

MACRO_1ARG_1TYPE_LOGIC_OP(dpnp_logical_not_c, !input1_elem)

#undef MACRO_1ARG_1TYPE_LOGIC_OP

#else
#error "MACRO_1ARG_1TYPE_OP or MACRO_1ARG_1TYPE_LOGIC_OP is not defined"
#endif // MACRO_1ARG_1TYPE_OP || MACRO_1ARG_1TYPE_LOGIC_OP
5 changes: 4 additions & 1 deletion dpnp/backend/include/dpnp_gen_2arg_2type_tbl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
/** @param[in] input2_strides Input array 2 strides. */ \
/** @param[in] where Where condition. */ \
/** @param[in] dep_event_vec_ref Reference to vector of SYCL events. */ \
template <typename _DataType_output, typename _DataType_input1, typename _DataType_input2> \
template <typename _DataType_input1, typename _DataType_input2> \
DPCTLSyclEventRef __name__(DPCTLSyclQueueRef q_ref, \
void* result_out, \
const size_t result_size, \
Expand All @@ -91,6 +91,9 @@ MACRO_2ARG_2TYPES_LOGIC_OP(dpnp_greater_c, input1_elem > input2_elem)
MACRO_2ARG_2TYPES_LOGIC_OP(dpnp_greater_equal_c, input1_elem >= input2_elem)
MACRO_2ARG_2TYPES_LOGIC_OP(dpnp_less_c, input1_elem < input2_elem)
MACRO_2ARG_2TYPES_LOGIC_OP(dpnp_less_equal_c, input1_elem <= input2_elem)
MACRO_2ARG_2TYPES_LOGIC_OP(dpnp_logical_and_c, input1_elem && input2_elem)
MACRO_2ARG_2TYPES_LOGIC_OP(dpnp_logical_or_c, input1_elem || input2_elem)
MACRO_2ARG_2TYPES_LOGIC_OP(dpnp_logical_xor_c, (!!input1_elem) != (!!input2_elem))
MACRO_2ARG_2TYPES_LOGIC_OP(dpnp_not_equal_c, input1_elem != input2_elem)

#undef MACRO_2ARG_2TYPES_LOGIC_OP
4 changes: 4 additions & 0 deletions dpnp/backend/include/dpnp_iface_fptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ enum class DPNPFuncName : size_t
DPNP_FN_LOG2_EXT, /**< Used in numpy.log2() impl, requires extra parameters */
DPNP_FN_LOG1P, /**< Used in numpy.log1p() impl */
DPNP_FN_LOG1P_EXT, /**< Used in numpy.log1p() impl, requires extra parameters */
DPNP_FN_LOGICAL_AND_EXT, /**< Used in numpy.logical_and() impl, requires extra parameters */
DPNP_FN_LOGICAL_NOT_EXT, /**< Used in numpy.logical_not() impl, requires extra parameters */
DPNP_FN_LOGICAL_OR_EXT, /**< Used in numpy.logical_or() impl, requires extra parameters */
DPNP_FN_LOGICAL_XOR_EXT, /**< Used in numpy.logical_xor() impl, requires extra parameters */
DPNP_FN_MATMUL, /**< Used in numpy.matmul() impl */
DPNP_FN_MATMUL_EXT, /**< Used in numpy.matmul() impl, requires extra parameters */
DPNP_FN_MATRIX_RANK, /**< Used in numpy.linalg.matrix_rank() impl */
Expand Down
Loading