-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…1949) * Add implementation of dpnp.degrees() and dpnp.rad2deg() * Updated note to get rid of invalid link * Adds more tests
- Loading branch information
1 parent
aa534f8
commit 264ecb6
Showing
15 changed files
with
437 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
dpnp/backend/extensions/ufunc/elementwise_functions/degrees.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
//***************************************************************************** | ||
// Copyright (c) 2024, Intel Corporation | ||
// All rights reserved. | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions are met: | ||
// - Redistributions of source code must retain the above copyright notice, | ||
// this list of conditions and the following disclaimer. | ||
// - Redistributions in binary form must reproduce the above copyright notice, | ||
// this list of conditions and the following disclaimer in the documentation | ||
// and/or other materials provided with the distribution. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
// THE POSSIBILITY OF SUCH DAMAGE. | ||
//***************************************************************************** | ||
|
||
#include <sycl/sycl.hpp> | ||
|
||
#include "dpctl4pybind11.hpp" | ||
|
||
#include "degrees.hpp" | ||
#include "kernels/elementwise_functions/degrees.hpp" | ||
#include "populate.hpp" | ||
|
||
// include a local copy of elementwise common header from dpctl tensor: | ||
// dpctl/tensor/libtensor/source/elementwise_functions/elementwise_functions.hpp | ||
// TODO: replace by including dpctl header once available | ||
#include "../../elementwise_functions/elementwise_functions.hpp" | ||
|
||
// dpctl tensor headers | ||
#include "kernels/elementwise_functions/common.hpp" | ||
#include "utils/type_dispatch.hpp" | ||
|
||
namespace dpnp::extensions::ufunc | ||
{ | ||
namespace py = pybind11; | ||
namespace py_int = dpnp::extensions::py_internal; | ||
|
||
namespace impl | ||
{ | ||
namespace ew_cmn_ns = dpctl::tensor::kernels::elementwise_common; | ||
namespace td_ns = dpctl::tensor::type_dispatch; | ||
|
||
/** | ||
* @brief A factory to define pairs of supported types for which | ||
* sycl::degrees<T> function is available. | ||
* | ||
* @tparam T Type of input vector `a` and of result vector `y`. | ||
*/ | ||
template <typename T> | ||
struct OutputType | ||
{ | ||
using value_type = | ||
typename std::disjunction<td_ns::TypeMapResultEntry<T, sycl::half>, | ||
td_ns::TypeMapResultEntry<T, float>, | ||
td_ns::TypeMapResultEntry<T, double>, | ||
td_ns::DefaultResultEntry<void>>::result_type; | ||
}; | ||
|
||
using dpnp::kernels::degrees::DegreesFunctor; | ||
|
||
template <typename argT, | ||
typename resT = argT, | ||
unsigned int vec_sz = 4, | ||
unsigned int n_vecs = 2, | ||
bool enable_sg_loadstore = true> | ||
using ContigFunctor = ew_cmn_ns::UnaryContigFunctor<argT, | ||
resT, | ||
DegreesFunctor<argT, resT>, | ||
vec_sz, | ||
n_vecs, | ||
enable_sg_loadstore>; | ||
|
||
template <typename argTy, typename resTy, typename IndexerT> | ||
using StridedFunctor = ew_cmn_ns:: | ||
UnaryStridedFunctor<argTy, resTy, IndexerT, DegreesFunctor<argTy, resTy>>; | ||
|
||
using ew_cmn_ns::unary_contig_impl_fn_ptr_t; | ||
using ew_cmn_ns::unary_strided_impl_fn_ptr_t; | ||
|
||
static unary_contig_impl_fn_ptr_t | ||
degrees_contig_dispatch_vector[td_ns::num_types]; | ||
static int degrees_output_typeid_vector[td_ns::num_types]; | ||
static unary_strided_impl_fn_ptr_t | ||
degrees_strided_dispatch_vector[td_ns::num_types]; | ||
|
||
MACRO_POPULATE_DISPATCH_VECTORS(degrees); | ||
} // namespace impl | ||
|
||
void init_degrees(py::module_ m) | ||
{ | ||
using arrayT = dpctl::tensor::usm_ndarray; | ||
using event_vecT = std::vector<sycl::event>; | ||
{ | ||
impl::populate_degrees_dispatch_vectors(); | ||
using impl::degrees_contig_dispatch_vector; | ||
using impl::degrees_output_typeid_vector; | ||
using impl::degrees_strided_dispatch_vector; | ||
|
||
auto degrees_pyapi = [&](const arrayT &src, const arrayT &dst, | ||
sycl::queue &exec_q, | ||
const event_vecT &depends = {}) { | ||
return py_int::py_unary_ufunc(src, dst, exec_q, depends, | ||
degrees_output_typeid_vector, | ||
degrees_contig_dispatch_vector, | ||
degrees_strided_dispatch_vector); | ||
}; | ||
m.def("_degrees", degrees_pyapi, "", py::arg("src"), py::arg("dst"), | ||
py::arg("sycl_queue"), py::arg("depends") = py::list()); | ||
|
||
auto degrees_result_type_pyapi = [&](const py::dtype &dtype) { | ||
return py_int::py_unary_ufunc_result_type( | ||
dtype, degrees_output_typeid_vector); | ||
}; | ||
m.def("_degrees_result_type", degrees_result_type_pyapi); | ||
} | ||
} | ||
} // namespace dpnp::extensions::ufunc |
35 changes: 35 additions & 0 deletions
35
dpnp/backend/extensions/ufunc/elementwise_functions/degrees.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//***************************************************************************** | ||
// Copyright (c) 2024, Intel Corporation | ||
// All rights reserved. | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions are met: | ||
// - Redistributions of source code must retain the above copyright notice, | ||
// this list of conditions and the following disclaimer. | ||
// - Redistributions in binary form must reproduce the above copyright notice, | ||
// this list of conditions and the following disclaimer in the documentation | ||
// and/or other materials provided with the distribution. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
// THE POSSIBILITY OF SUCH DAMAGE. | ||
//***************************************************************************** | ||
|
||
#pragma once | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
namespace py = pybind11; | ||
|
||
namespace dpnp::extensions::ufunc | ||
{ | ||
void init_degrees(py::module_ m); | ||
} // namespace dpnp::extensions::ufunc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//***************************************************************************** | ||
// Copyright (c) 2024, Intel Corporation | ||
// All rights reserved. | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions are met: | ||
// - Redistributions of source code must retain the above copyright notice, | ||
// this list of conditions and the following disclaimer. | ||
// - Redistributions in binary form must reproduce the above copyright notice, | ||
// this list of conditions and the following disclaimer in the documentation | ||
// and/or other materials provided with the distribution. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
// THE POSSIBILITY OF SUCH DAMAGE. | ||
//***************************************************************************** | ||
|
||
#pragma once | ||
|
||
#include <sycl/sycl.hpp> | ||
|
||
namespace dpnp::kernels::degrees | ||
{ | ||
template <typename argT, typename resT> | ||
struct DegreesFunctor | ||
{ | ||
// is function constant for given argT | ||
using is_constant = typename std::false_type; | ||
// constant value, if constant | ||
// constexpr resT constant_value = resT{}; | ||
// is function defined for sycl::vec | ||
using supports_vec = typename std::true_type; | ||
// do both argT and resT support subgroup store/load operation | ||
using supports_sg_loadstore = typename std::true_type; | ||
|
||
resT operator()(const argT &x) const | ||
{ | ||
return sycl::degrees(x); | ||
} | ||
|
||
template <int vec_sz> | ||
sycl::vec<resT, vec_sz> operator()(const sycl::vec<argT, vec_sz> &x) const | ||
{ | ||
return sycl::degrees(x); | ||
} | ||
}; | ||
} // namespace dpnp::kernels::degrees |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.