Skip to content

Commit bcd2c98

Browse files
Added license headers, renamed *StridedIndexerArray-> *FixedDimIndexer
Removed empty constructor for MemoryOverlap (rule of five), leave it up to compiler.
1 parent 5de411a commit bcd2c98

File tree

3 files changed

+80
-31
lines changed

3 files changed

+80
-31
lines changed

dpctl/tensor/libtensor/include/kernels/copy_and_cast.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,16 +273,16 @@ copy_and_cast_nd_specialized_impl(sycl::queue q,
273273
dpctl::tensor::type_utils::validate_type_for_device<srcTy>(q);
274274

275275
sycl::event copy_and_cast_ev = q.submit([&](sycl::handler &cgh) {
276-
TwoOffsets_StridedIndexerArray<nd> indexer{
277-
shape, src_strides, dst_strides, src_offset, dst_offset};
276+
using IndexerT = TwoOffsets_FixedDimStridedIndexer<nd>;
277+
IndexerT indexer{shape, src_strides, dst_strides, src_offset,
278+
dst_offset};
278279

279280
cgh.depends_on(depends);
280-
cgh.parallel_for<class copy_cast_generic_kernel<
281-
srcTy, dstTy, TwoOffsets_StridedIndexerArray<nd>>>(
281+
cgh.parallel_for<
282+
class copy_cast_generic_kernel<srcTy, dstTy, IndexerT>>(
282283
sycl::range<1>(nelems),
283-
GenericCopyFunctor<Caster<srcTy, dstTy>,
284-
TwoOffsets_StridedIndexerArray<nd>>(src_p, dst_p,
285-
indexer));
284+
GenericCopyFunctor<Caster<srcTy, dstTy>, IndexerT>(src_p, dst_p,
285+
indexer));
286286
});
287287

288288
return copy_and_cast_ev;

dpctl/tensor/libtensor/include/utils/memory_overlap.hpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
//===-- memory_overlap.hpp - Array memory overlap determination ---*-C++-*-//
2+
// ===//
3+
//
4+
// Data Parallel Control (dpctl)
5+
//
6+
// Copyright 2020-2022 Intel Corporation
7+
//
8+
// Licensed under the Apache License, Version 2.0 (the "License");
9+
// you may not use this file except in compliance with the License.
10+
// You may obtain a copy of the License at
11+
//
12+
// http://www.apache.org/licenses/LICENSE-2.0
13+
//
14+
// Unless required by applicable law or agreed to in writing, software
15+
// distributed under the License is distributed on an "AS IS" BASIS,
16+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
// See the License for the specific language governing permissions and
18+
// limitations under the License.
19+
//
20+
//===----------------------------------------------------------------------===//
21+
///
22+
/// \file
23+
/// This file defines utility to determine whether two arrays have memory
24+
/// overlap.
25+
//===----------------------------------------------------------------------===//
26+
127
#pragma once
228
#include "dpctl4pybind11.hpp"
329
#include <pybind11/pybind11.h>
@@ -20,7 +46,6 @@ namespace overlap
2046

2147
struct MemoryOverlap
2248
{
23-
MemoryOverlap() {}
2449

2550
bool operator()(dpctl::tensor::usm_ndarray ar1,
2651
dpctl::tensor::usm_ndarray ar2) const

dpctl/tensor/libtensor/include/utils/offset_utils.hpp

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
//===-- offset_utils.hpp - Indexer classes for strided iteration ---*-C++-*-//
2+
// ===//
3+
//
4+
// Data Parallel Control (dpctl)
5+
//
6+
// Copyright 2020-2022 Intel Corporation
7+
//
8+
// Licensed under the Apache License, Version 2.0 (the "License");
9+
// you may not use this file except in compliance with the License.
10+
// You may obtain a copy of the License at
11+
//
12+
// http://www.apache.org/licenses/LICENSE-2.0
13+
//
14+
// Unless required by applicable law or agreed to in writing, software
15+
// distributed under the License is distributed on an "AS IS" BASIS,
16+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
// See the License for the specific language governing permissions and
18+
// limitations under the License.
19+
//
20+
//===----------------------------------------------------------------------===//
21+
///
22+
/// \file
23+
/// This file defines Indexer callable operator to compute element offset in
24+
/// an array addressed by gloabl_id.
25+
//===----------------------------------------------------------------------===//
26+
127
#pragma once
228

329
#include <CL/sycl.hpp>
@@ -10,7 +36,14 @@
1036

1137
namespace py = pybind11;
1238

13-
namespace concat_impl
39+
namespace dpctl
40+
{
41+
namespace tensor
42+
{
43+
namespace offset_utils
44+
{
45+
46+
namespace detail
1447
{
1548

1649
struct sink_t
@@ -30,14 +63,9 @@ template <class V, class U> sink_t __appender(V &lhs, U &&rhs)
3063
return {};
3164
}
3265

33-
} // namespace concat_impl
34-
3566
template <typename T, typename A, typename... Vs>
3667
std::vector<T, A> concat(std::vector<T, A> lhs, Vs &&...vs)
3768
{
38-
using concat_impl::__accumulate_size;
39-
using concat_impl::__appender;
40-
using concat_impl::sink_t;
4169
std::size_t s = lhs.size();
4270
{
4371
// limited scope ensures array is freed
@@ -53,12 +81,7 @@ std::vector<T, A> concat(std::vector<T, A> lhs, Vs &&...vs)
5381
return std::move(lhs); // prevent return-value optimization
5482
}
5583

56-
namespace dpctl
57-
{
58-
namespace tensor
59-
{
60-
namespace offset_utils
61-
{
84+
} // namespace detail
6285

6386
template <typename indT, typename... Vs>
6487
std::tuple<indT *, size_t, sycl::event>
@@ -75,7 +98,7 @@ device_allocate_and_pack(sycl::queue q,
7598

7699
usm_host_allocatorT usm_host_allocator(q);
77100
shT empty{0, usm_host_allocator};
78-
shT packed_shape_strides = concat(empty, vs...);
101+
shT packed_shape_strides = detail::concat(empty, vs...);
79102

80103
auto packed_shape_strides_owner =
81104
std::make_shared<shT>(std::move(packed_shape_strides));
@@ -269,11 +292,11 @@ struct NthStrideOffset
269292
py::ssize_t const *shape_strides;
270293
};
271294

272-
template <int nd> struct StridedIndexerArray
295+
template <int nd> struct FixedDimStridedIndexer
273296
{
274-
StridedIndexerArray(const std::array<py::ssize_t, nd> _shape,
275-
const std::array<py::ssize_t, nd> _strides,
276-
py::ssize_t _offset)
297+
FixedDimStridedIndexer(const std::array<py::ssize_t, nd> _shape,
298+
const std::array<py::ssize_t, nd> _strides,
299+
py::ssize_t _offset)
277300
: _ind(_shape), strides(_strides), starting_offset(_offset)
278301
{
279302
}
@@ -298,13 +321,14 @@ template <int nd> struct StridedIndexerArray
298321
py::ssize_t starting_offset;
299322
};
300323

301-
template <int nd> struct TwoOffsets_StridedIndexerArray
324+
template <int nd> struct TwoOffsets_FixedDimStridedIndexer
302325
{
303-
TwoOffsets_StridedIndexerArray(const std::array<py::ssize_t, nd> _shape,
304-
const std::array<py::ssize_t, nd> _strides1,
305-
const std::array<py::ssize_t, nd> _strides2,
306-
py::ssize_t _offset1,
307-
py::ssize_t _offset2)
326+
TwoOffsets_FixedDimStridedIndexer(
327+
const std::array<py::ssize_t, nd> _shape,
328+
const std::array<py::ssize_t, nd> _strides1,
329+
const std::array<py::ssize_t, nd> _strides2,
330+
py::ssize_t _offset1,
331+
py::ssize_t _offset2)
308332
: _ind(_shape), strides1(_strides1), strides2(_strides2),
309333
starting_offset1(_offset1), starting_offset2(_offset2)
310334
{

0 commit comments

Comments
 (0)