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
+
1
27
#pragma once
2
28
3
29
#include < CL/sycl.hpp>
10
36
11
37
namespace py = pybind11;
12
38
13
- namespace concat_impl
39
+ namespace dpctl
40
+ {
41
+ namespace tensor
42
+ {
43
+ namespace offset_utils
44
+ {
45
+
46
+ namespace detail
14
47
{
15
48
16
49
struct sink_t
@@ -30,14 +63,9 @@ template <class V, class U> sink_t __appender(V &lhs, U &&rhs)
30
63
return {};
31
64
}
32
65
33
- } // namespace concat_impl
34
-
35
66
template <typename T, typename A, typename ... Vs>
36
67
std::vector<T, A> concat (std::vector<T, A> lhs, Vs &&...vs)
37
68
{
38
- using concat_impl::__accumulate_size;
39
- using concat_impl::__appender;
40
- using concat_impl::sink_t ;
41
69
std::size_t s = lhs.size ();
42
70
{
43
71
// limited scope ensures array is freed
@@ -53,12 +81,7 @@ std::vector<T, A> concat(std::vector<T, A> lhs, Vs &&...vs)
53
81
return std::move (lhs); // prevent return-value optimization
54
82
}
55
83
56
- namespace dpctl
57
- {
58
- namespace tensor
59
- {
60
- namespace offset_utils
61
- {
84
+ } // namespace detail
62
85
63
86
template <typename indT, typename ... Vs>
64
87
std::tuple<indT *, size_t , sycl::event>
@@ -75,7 +98,7 @@ device_allocate_and_pack(sycl::queue q,
75
98
76
99
usm_host_allocatorT usm_host_allocator (q);
77
100
shT empty{0 , usm_host_allocator};
78
- shT packed_shape_strides = concat (empty, vs...);
101
+ shT packed_shape_strides = detail:: concat (empty, vs...);
79
102
80
103
auto packed_shape_strides_owner =
81
104
std::make_shared<shT>(std::move (packed_shape_strides));
@@ -269,11 +292,11 @@ struct NthStrideOffset
269
292
py::ssize_t const *shape_strides;
270
293
};
271
294
272
- template <int nd> struct StridedIndexerArray
295
+ template <int nd> struct FixedDimStridedIndexer
273
296
{
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)
277
300
: _ind(_shape), strides(_strides), starting_offset(_offset)
278
301
{
279
302
}
@@ -298,13 +321,14 @@ template <int nd> struct StridedIndexerArray
298
321
py::ssize_t starting_offset;
299
322
};
300
323
301
- template <int nd> struct TwoOffsets_StridedIndexerArray
324
+ template <int nd> struct TwoOffsets_FixedDimStridedIndexer
302
325
{
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)
308
332
: _ind(_shape), strides1(_strides1), strides2(_strides2),
309
333
starting_offset1 (_offset1), starting_offset2(_offset2)
310
334
{
0 commit comments