Skip to content

Technical debt changes #1583

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 3 commits into from
Mar 6, 2024
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
74 changes: 38 additions & 36 deletions dpctl/tensor/libtensor/include/utils/strided_iters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ template <typename indT = std::ptrdiff_t> class CIndexer_vector
public:
CIndexer_vector(int dim) : nd(dim) {}

template <class ShapeTy> indT size(ShapeTy shape) const
template <class ShapeTy> indT size(const ShapeTy &shape) const
{
indT s = static_cast<indT>(1);
for (int i = 0; i < nd; ++i) {
Expand All @@ -83,8 +83,10 @@ template <typename indT = std::ptrdiff_t> class CIndexer_vector
}

template <class ShapeTy, class StridesTy>
void
get_displacement(indT i, ShapeTy shape, StridesTy stride, indT &disp) const
void get_displacement(const indT i,
const ShapeTy &shape,
const StridesTy &stride,
indT &disp) const
{
if (nd == 1) {
disp = i * stride[0];
Expand All @@ -104,10 +106,10 @@ template <typename indT = std::ptrdiff_t> class CIndexer_vector
}

template <class ShapeTy, class StridesTy>
void get_displacement(indT i,
ShapeTy shape,
StridesTy stride1,
StridesTy stride2,
void get_displacement(const indT i,
const ShapeTy &shape,
const StridesTy &stride1,
const StridesTy &stride2,
indT &disp1,
indT &disp2) const
{
Expand All @@ -133,11 +135,11 @@ template <typename indT = std::ptrdiff_t> class CIndexer_vector
}

template <class ShapeTy, class StridesTy>
void get_displacement(indT i,
ShapeTy shape,
StridesTy stride1,
StridesTy stride2,
StridesTy stride3,
void get_displacement(const indT i,
const ShapeTy &shape,
const StridesTy &stride1,
const StridesTy &stride2,
const StridesTy &stride3,
indT &disp1,
indT &disp2,
indT &disp3) const
Expand Down Expand Up @@ -167,12 +169,12 @@ template <typename indT = std::ptrdiff_t> class CIndexer_vector
}

template <class ShapeTy, class StridesTy>
void get_displacement(indT i,
ShapeTy shape,
StridesTy stride1,
StridesTy stride2,
StridesTy stride3,
StridesTy stride4,
void get_displacement(const indT i,
const ShapeTy &shape,
const StridesTy &stride1,
const StridesTy &stride2,
const StridesTy &stride3,
const StridesTy &stride4,
indT &disp1,
indT &disp2,
indT &disp3,
Expand Down Expand Up @@ -206,9 +208,9 @@ template <typename indT = std::ptrdiff_t> class CIndexer_vector
}

template <class ShapeTy, class StridesTy, int nstrides>
void get_displacement(indT i,
ShapeTy shape,
const std::array<StridesTy, nstrides> strides,
void get_displacement(const indT i,
const ShapeTy &shape,
const std::array<StridesTy, nstrides> &strides,
std::array<indT, nstrides> &disps) const
{
if (nd == 1) {
Expand Down Expand Up @@ -240,14 +242,14 @@ template <typename indT = std::ptrdiff_t> class CIndexer_vector
}

template <class ShapeTy, class StridesTy>
void get_left_rolled_displacement(indT i,
ShapeTy shape,
StridesTy stride,
StridesTy shifts,
void get_left_rolled_displacement(const indT i,
const ShapeTy &shape,
const StridesTy &stride,
const StridesTy &shifts,
indT &disp) const
{
indT i_ = i;
indT d = 0;
indT d(0);
for (int dim = nd; --dim > 0;) {
const indT si = shape[dim];
const indT q = i_ / si;
Expand Down Expand Up @@ -275,7 +277,7 @@ template <typename indT = std::ptrdiff_t> class CIndexer_vector

template <int _ndim, typename indT = std::ptrdiff_t> class CIndexer_array
{
static const int ndim = _ndim;
static constexpr int ndim = _ndim;

static_assert(std::is_integral<indT>::value, "Integral type is required");
static_assert(std::is_signed<indT>::value,
Expand All @@ -295,7 +297,7 @@ template <int _ndim, typename indT = std::ptrdiff_t> class CIndexer_array
explicit CIndexer_array(const index_t &input_shape)
: elem_count(0), shape{}, multi_index{}
{
indT s = static_cast<std::ptrdiff_t>(1);
indT s(1);
for (int i = 0; i < ndim; ++i) {
shape[i] = input_shape[i];
s *= input_shape[i];
Expand All @@ -312,7 +314,7 @@ template <int _ndim, typename indT = std::ptrdiff_t> class CIndexer_array
return ndim;
}

void set(indT i)
void set(const indT i)
{
if (ndim == 1) {
multi_index[0] = i;
Expand Down Expand Up @@ -366,7 +368,7 @@ int simplify_iteration_stride(const int nd,
StridesTy *strides,
StridesTy &disp)
{
disp = std::ptrdiff_t(0);
disp = StridesTy(0);
if (nd < 2)
return nd;

Expand Down Expand Up @@ -451,8 +453,8 @@ int simplify_iteration_two_strides(const int nd,
StridesTy &disp1,
StridesTy &disp2)
{
disp1 = std::ptrdiff_t(0);
disp2 = std::ptrdiff_t(0);
disp1 = StridesTy(0);
disp2 = StridesTy(0);
if (nd < 2)
return nd;

Expand Down Expand Up @@ -603,8 +605,8 @@ int simplify_iteration_three_strides(const int nd,
StridesTy &disp2,
StridesTy &disp3)
{
disp1 = std::ptrdiff_t(0);
disp2 = std::ptrdiff_t(0);
disp1 = StridesTy(0);
disp2 = StridesTy(0);
if (nd < 2)
return nd;

Expand Down Expand Up @@ -768,8 +770,8 @@ int simplify_iteration_four_strides(const int nd,
StridesTy &disp3,
StridesTy &disp4)
{
disp1 = std::ptrdiff_t(0);
disp2 = std::ptrdiff_t(0);
disp1 = StridesTy(0);
disp2 = StridesTy(0);
if (nd < 2)
return nd;

Expand Down
3 changes: 3 additions & 0 deletions dpctl/tensor/libtensor/source/clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ py_clip(const dpctl::tensor::usm_ndarray &src,
simplified_shape, simplified_src_strides, simplified_min_strides,
simplified_max_strides, simplified_dst_strides);
py::ssize_t *packed_shape_strides = std::get<0>(ptr_size_event_tuple);
if (!packed_shape_strides) {
throw std::runtime_error("USM-host memory allocation failure");
}
sycl::event copy_shape_strides_ev = std::get<2>(ptr_size_event_tuple);

std::vector<sycl::event> all_deps;
Expand Down
3 changes: 3 additions & 0 deletions dpctl/tensor/libtensor/source/where.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ py_where(const dpctl::tensor::usm_ndarray &condition,
simplified_shape, simplified_cond_strides, simplified_x1_strides,
simplified_x2_strides, simplified_dst_strides);
py::ssize_t *packed_shape_strides = std::get<0>(ptr_size_event_tuple);
if (!packed_shape_strides) {
throw std::runtime_error("USM-host memory allocation failure");
}
sycl::event copy_shape_strides_ev = std::get<2>(ptr_size_event_tuple);

std::vector<sycl::event> all_deps;
Expand Down