ConstantTensorDescriptor.hip.hpp 23.2 KB
Newer Older
Chao Liu's avatar
Chao Liu committed
1
#pragma once
2
#include "common.hip.hpp"
Chao Liu's avatar
Chao Liu committed
3

4
template <class Lengths>
5
__host__ __device__ constexpr auto calculate_packed_tensor_strides(Lengths)
6
{
7
8
    return reverse_inclusive_scan_sequence(Lengths{}.PopFront(), std::multiplies<index_t>{})
        .PushBack(Number<1>{});
9
10
}

11
12
13
template <class Lengths, index_t Align>
__host__ __device__ constexpr auto
    calculate_rank_tensor_default_strides_with_alignment(Lengths, Number<Align>)
Chao Liu's avatar
Chao Liu committed
14
{
15
16
    constexpr index_t L_back_align =
        Align * mod_conv::integer_divide_ceiler<index_t>{}(Lengths{}.Back(), Align);
Chao Liu's avatar
Chao Liu committed
17

18
19
    return calculate_packed_tensor_strides(
        Lengths{}.Modify(Number<Lengths{}.GetSize() - 1>{}, Number<L_back_align>{}));
20
21
}

22
23
// MemoryRanks of dimensions is for conversion from offset to multi-index
template <class Lengths, class Strides, class MemoryRanks>
Chao Liu's avatar
Chao Liu committed
24
25
struct ConstantTensorDescriptor
{
Chao Liu's avatar
Chao Liu committed
26
27
    using Type = ConstantTensorDescriptor;

28
    static constexpr index_t nDim = Lengths::GetSize();
Chao Liu's avatar
Chao Liu committed
29
30
31

    __host__ __device__ constexpr ConstantTensorDescriptor()
    {
32
33
34
35
36
37
38
39
40
        static_assert(Lengths::GetSize() == Strides::GetSize() &&
                          Lengths::GetSize() == MemoryRanks::GetSize(),
                      "nDim not consistent");

#if 0 // require sequence_sort, but it's not implemented yet
        static_assert(is_same<typename sequence_sort<MemoryRanks>::SortedSeqType,
                              typename arithmetic_sequence_gen<0, nDim, 1>::SeqType>::value,
                      "wrong! invalid MemoryRanks");
#endif
Chao Liu's avatar
Chao Liu committed
41
42
    }

Chao Liu's avatar
Chao Liu committed
43
    __host__ __device__ static constexpr index_t GetNumOfDimension() { return nDim; }
Chao Liu's avatar
Chao Liu committed
44

45
    __host__ __device__ static constexpr auto GetLengths() { return Lengths{}; }
Chao Liu's avatar
Chao Liu committed
46

47
48
49
    __host__ __device__ static constexpr auto GetStrides() { return Strides{}; }

    __host__ __device__ static constexpr auto GetMemoryRanks() { return MemoryRanks{}; }
Chao Liu's avatar
Chao Liu committed
50

Chao Liu's avatar
Chao Liu committed
51
    template <index_t I>
52
    __host__ __device__ static constexpr index_t GetLength(Number<I>)
Chao Liu's avatar
Chao Liu committed
53
    {
Chao Liu's avatar
Chao Liu committed
54
        return Lengths{}.Get(Number<I>{});
Chao Liu's avatar
Chao Liu committed
55
56
    }

Chao Liu's avatar
Chao Liu committed
57
    template <index_t I>
58
    __host__ __device__ static constexpr index_t GetStride(Number<I>)
Chao Liu's avatar
Chao Liu committed
59
    {
Chao Liu's avatar
Chao Liu committed
60
        return Strides{}.Get(Number<I>{});
Chao Liu's avatar
Chao Liu committed
61
62
    }

63
64
65
66
67
68
    template <index_t I>
    __host__ __device__ static constexpr index_t GetMemoryRank(Number<I>)
    {
        return MemoryRanks{}.Get(Number<I>{});
    }

69
    __host__ __device__ static constexpr index_t GetElementSize()
Chao Liu's avatar
Chao Liu committed
70
    {
Chao Liu's avatar
Chao Liu committed
71
        return accumulate_on_sequence(Lengths{}, std::multiplies<index_t>{}, Number<1>{});
72
    }
73

74
    // WRONG! ReorderGivenOld2New is broken
Chao Liu's avatar
Chao Liu committed
75
    template <class Align = Number<1>>
76
    __host__ __device__ static constexpr index_t GetElementSpace(Align align = Align{})
Chao Liu's avatar
Chao Liu committed
77
    {
78
79
80
81
82
83
84
#if 0
        constexpr auto lengths_in_rank = GetLengths().ReorderGivenOld2New(MemoryRank{});
        constexpr auto strides_in_rank = GetStrides().ReorderGivenOld2new(MemoryRank{});

        constexpr index_t element_space_unaligned = accumulate_on_sequence(
            (lengths_in_rank - Number<1>{}) * strides_in_rank, std::plus<index_t>{}, Number<1>{});
#else // WRONG! align shouldbe applied to the last memory rank, not the last tensor dimension
Chao Liu's avatar
Chao Liu committed
85
86
        constexpr index_t element_space_unaligned = accumulate_on_sequence(
            (GetLengths() - Number<1>{}) * GetStrides(), std::plus<index_t>{}, Number<1>{});
87
#endif
Chao Liu's avatar
Chao Liu committed
88
89

        return align.Get() * ((element_space_unaligned + align.Get() - 1) / align.Get());
Chao Liu's avatar
Chao Liu committed
90
    }
Chao Liu's avatar
Chao Liu committed
91

92
    template <index_t NSize>
93
    __host__ __device__ static index_t GetOffsetFromMultiIndex(Array<index_t, NSize> multi_id)
Chao Liu's avatar
Chao Liu committed
94
    {
95
        static_assert(NSize == nDim, "wrong! Dimension not consistent");
Chao Liu's avatar
Chao Liu committed
96

97
        index_t offset = 0;
Chao Liu's avatar
Chao Liu committed
98

99
        static_for<0, nDim, 1>{}([&](auto IDim) {
Chao Liu's avatar
Chao Liu committed
100
            constexpr index_t idim = IDim.Get();
101
            offset += multi_id[idim] * GetStride(IDim);
102
        });
Chao Liu's avatar
Chao Liu committed
103

104
        return offset;
105
106
    }

107
    template <class... Is>
108
    __host__ __device__ static index_t GetOffsetFromMultiIndex(Is... is)
109
    {
110
        return GetOffsetFromMultiIndex(Array<index_t, sizeof...(Is)>{is...});
111
112
    }

113
    template <index_t... Is>
114
    __host__ __device__ static constexpr index_t GetOffsetFromMultiIndex(Sequence<Is...>)
115
116
117
    {
        static_assert(sizeof...(Is) == nDim, "wrong! Dimension not consistent");

Chao Liu's avatar
Chao Liu committed
118
119
        constexpr auto multi_id = Sequence<Is...>{};

Chao Liu's avatar
Chao Liu committed
120
        return accumulate_on_sequence(multi_id * GetStrides(), std::plus<index_t>{}, Number<0>{});
121
122
    }

123
124
#if 0 // ReorderGivenOld2new is broken
    __host__ __device__ static Array<index_t, nDim> GetMultiIndexFromOffset(index_t offset)
Chao Liu's avatar
Chao Liu committed
125
    {
126
127
128
129
        Array<index_t, nDim> ranked_multi_id;

        constexpr auto ranked_strides =
            GetStrides().ReorderGivenOld2new(MemoryRanks{}); // check this
130

131
        // calculate index in each of the dimensions in the order of their rank (not dimension)
132
        static_for<0, nDim - 1, 1>{}([&](auto IDim) {
133
134
135
136
            constexpr index_t idim   = IDim.Get();
            constexpr index_t stride = ranked_strides.Get(Number<idim>{});
            ranked_multi_id[idim]    = offset / stride;
            offset -= ranked_multi_id[idim] * stride;
137
138
        });

139
        ranked_multi_id[nDim - 1] = offset / ranked_strides.Get(Number<nDim - 1>{});
140

141
        return reorder_array_given_new2old(ranked_multi_id, MemoryRanks{}); // check this
Chao Liu's avatar
Chao Liu committed
142
    }
143
#endif
144

145
    __host__ __device__ static Array<index_t, nDim> GetMultiIndexFrom1dIndex(index_t id)
146
    {
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
        Array<index_t, nDim> multi_id;

        constexpr auto dummy_strides = calculate_packed_tensor_strides(GetLengths());

        // calculate index in each of the dimensions in the order of their dimension (not rank)
        static_for<0, nDim - 1, 1>{}([&](auto IDim) {
            constexpr index_t idim   = IDim.Get();
            constexpr index_t stride = dummy_strides.Get(Number<idim>{});
            multi_id[idim]           = id / stride;
            id -= multi_id[idim] * stride;
        });

        multi_id[nDim - 1] = id / dummy_strides.Get(Number<nDim - 1>{});

        return multi_id;
162
    }
Chao Liu's avatar
Chao Liu committed
163

164
    // WRONG! Ranks is broken
Chao Liu's avatar
Chao Liu committed
165
    template <index_t... IDims>
Chao Liu's avatar
Chao Liu committed
166
    __host__ __device__ static constexpr auto Extract(Number<IDims>... extract_dims)
Chao Liu's avatar
Chao Liu committed
167
    {
Chao Liu's avatar
Chao Liu committed
168
169
        static_assert(sizeof...(IDims) <= GetNumOfDimension(),
                      "wrong! too many number of dimensions to be extracted");
Chao Liu's avatar
Chao Liu committed
170

171
172
173
174
175
176
177
178
179
180
181
        using extract_lengths = decltype(Lengths{}.Extract(extract_dims...));
        using extract_strides = decltype(Strides{}.Extract(extract_dims...));
        using extract_ranks   = decltype(MemoryRanks{}.Extract(extract_dims...));

#if 0
        using new_ranks = typename sequence_sort<extract_ranks>::Original2SortedType;
#else // WRONG! TODO:: implement sequence_sort
        using new_ranks = typename arithmetic_sequence_gen<0, sizeof...(IDims), 1>::SeqType;
#endif

        return ConstantTensorDescriptor<extract_lengths, extract_strides, new_ranks>{};
Chao Liu's avatar
Chao Liu committed
182
183
184
185
186
    }

    template <index_t IDim, index_t SliceLen>
    __host__ __device__ static constexpr auto Slice(Number<IDim>, Number<SliceLen>)
    {
187
188
189
        using slice_lengths = decltype(Lengths{}.Modify(Number<IDim>{}, Number<SliceLen>{}));

        return ConstantTensorDescriptor<slice_lengths, Strides, MemoryRanks>{};
Chao Liu's avatar
Chao Liu committed
190
191
    }

192
193
194
195
196
197
198
199
200
    template <index_t Threashold, index_t Delta>
    struct f_fold_impl
    {
        __host__ __device__ constexpr index_t operator()(index_t x) const
        {
            return x > Threashold ? x + Delta : x;
        }
    };

Chao Liu's avatar
Chao Liu committed
201
    template <index_t IDim, index_t... FoldIntervals>
Chao Liu's avatar
Chao Liu committed
202
    __host__ __device__ static constexpr auto Fold(Number<IDim>, Number<FoldIntervals>...)
Chao Liu's avatar
Chao Liu committed
203
    {
Chao Liu's avatar
Chao Liu committed
204
205
        constexpr auto fold_intervals = Sequence<FoldIntervals...>{};

Chao Liu's avatar
Chao Liu committed
206
        constexpr index_t fold_intervals_product =
Chao Liu's avatar
Chao Liu committed
207
208
209
210
            accumulate_on_sequence(fold_intervals, std::multiplies<index_t>{}, Number<1>{});

        constexpr auto unfold_length = GetLength(Number<IDim>{});
        constexpr auto unfold_stride = GetStride(Number<IDim>{});
211
        constexpr auto unfold_rank   = GetMemoryRank(Number<IDim>{});
Chao Liu's avatar
Chao Liu committed
212
213
214

        // length of the dimension to be folded needs to be dividable by fold_interval_product,
        // otherwise, folding is invalid
Chao Liu's avatar
Chao Liu committed
215
        static_assert(unfold_length % fold_intervals_product == 0,
Chao Liu's avatar
Chao Liu committed
216
217
218
219
                      "wrong! length on the dimension to be folded cannot be evenly divided!");

        // folded lengths
        constexpr auto fold_lengths =
Chao Liu's avatar
Chao Liu committed
220
            Sequence<unfold_length / fold_intervals_product>{}.Append(fold_intervals);
Chao Liu's avatar
Chao Liu committed
221
222

        // folded strides
Chao Liu's avatar
Chao Liu committed
223
224
        constexpr auto fold_strides =
            Number<unfold_stride>{} *
Chao Liu's avatar
Chao Liu committed
225
226
            reverse_inclusive_scan_sequence(fold_intervals.PushBack(Number<1>{}),
                                            std::multiplies<index_t>{});
Chao Liu's avatar
Chao Liu committed
227

228
229
230
231
232
        // folded_ranks
        constexpr auto fold_ranks =
            typename arithmetic_sequence_gen<unfold_rank,
                                             unfold_rank + fold_intervals.GetSize() + 1,
                                             1>::SeqType{};
Chao Liu's avatar
Chao Liu committed
233

234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
        // increase the ranks that are larger than unfold_rank
        constexpr auto tmp_ranks = transform_sequences(
            f_fold_impl<unfold_rank, fold_intervals.GetSize()>{}, GetMemoryRanks());

        // left and right
        constexpr auto left = typename arithmetic_sequence_gen<0, IDim, 1>::SeqType{};
        constexpr auto right =
            typename arithmetic_sequence_gen<IDim + 1, GetNumOfDimension(), 1>::SeqType{};

        constexpr auto new_lengths =
            GetLengths().Extract(left).Append(fold_lengths).Append(GetLengths().Extract(right));
        constexpr auto new_strides =
            GetStrides().Extract(left).Append(fold_strides).Append(GetStrides().Extract(right));
        constexpr auto new_ranks =
            tmp_ranks.Extract(left).Append(fold_ranks).Append(tmp_ranks.Extract(right));

        static_assert(new_ranks.GetSize() == new_lengths.GetSize(), "wrong!");
        static_assert(fold_ranks.GetSize() == fold_lengths.GetSize(), "wrong!");

        return ConstantTensorDescriptor<decltype(new_lengths),
                                        decltype(new_strides),
                                        decltype(new_ranks)>{};
Chao Liu's avatar
Chao Liu committed
256
257
    }

258
259
260
261
262
263
264
265
266
    template <index_t Threashold, index_t Delta>
    struct f_unfold_impl
    {
        __host__ __device__ constexpr index_t operator()(index_t x) const
        {
            return x > Threashold ? x - Delta : x;
        }
    };

Chao Liu's avatar
Chao Liu committed
267
268
269
    template <index_t FirstUnfoldDim, index_t LastUnfoldDim>
    __host__ __device__ static constexpr auto Unfold(Number<FirstUnfoldDim>, Number<LastUnfoldDim>)
    {
Chao Liu's avatar
Chao Liu committed
270
271
272
273
274
275
276
        static_assert(FirstUnfoldDim >= 0 && LastUnfoldDim < nDim &&
                          FirstUnfoldDim <= LastUnfoldDim,
                      "wrong! should have FirstUnfoldDim <= LastUnfoldDim!");

        // dimensions to be unfold need to be in descending order (w.r.t. strides), and need to be
        // packed in memory, otherwise, unfolding is invalid
        static_for<FirstUnfoldDim, LastUnfoldDim, 1>{}([&](auto IDim) {
277
278
279
            constexpr auto IDim_p1 = IDim + Number<1>{};

            // check stride
Chao Liu's avatar
Chao Liu committed
280
            static_assert(
281
                GetStride(IDim) >= GetStride(IDim_p1),
Chao Liu's avatar
Chao Liu committed
282
283
                "wrong! dimensions to be unfolded need to be in descending order w.r.t strides");

284
285
            // check if packed
            static_assert(GetStride(IDim_p1) * GetLength(IDim_p1) == GetStride(IDim),
Chao Liu's avatar
Chao Liu committed
286
                          "wrong! dimensions to be unfolded need to be packed");
287
288

            // checkt ranks
289
290
291
            static_assert(GetMemoryRank(IDim_p1) == GetMemoryRank(IDim) + 1,
                          "wrong! ranks of dimensions to be unfolded need to be in increasing and "
                          "continuous ranks");
Chao Liu's avatar
Chao Liu committed
292
293
        });

Chao Liu's avatar
Chao Liu committed
294
        // left and right
295
296
297
298
299
300
301
        constexpr auto left = typename arithmetic_sequence_gen<0, FirstUnfoldDim, 1>::SeqType{};
        constexpr auto middle =
            typename arithmetic_sequence_gen<FirstUnfoldDim, LastUnfoldDim + 1, 1>::SeqType{};
        constexpr auto right =
            typename arithmetic_sequence_gen<LastUnfoldDim + 1, GetNumOfDimension(), 1>::SeqType{};

        // unfolded length, stride and rank
Chao Liu's avatar
Chao Liu committed
302
303
304
305
306
        constexpr index_t unfold_length = accumulate_on_sequence(
            GetLengths().Extract(middle), std::multiplies<index_t>{}, Number<1>{});

        constexpr index_t unfold_stride = GetStride(Number<LastUnfoldDim>{});

307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
        constexpr index_t unfold_rank = GetMemoryRank(Number<FirstUnfoldDim>{});

        // decrease the ranks that are larger than the rank of LastUnfoldDim
        constexpr auto tmp_ranks =
            transform_sequences(GetMemoryRanks(),
                                f_unfold_impl<GetMemoryRank(Number<LastUnfoldDim>{}),
                                              LastUnfoldDim - FirstUnfoldDim + 1>{});

        // new lengths, strides and ranks
        constexpr auto new_lengths = GetLengths()
                                         .Extract(left)
                                         .PushBack(Number<unfold_length>{})
                                         .Append(GetLengths().Extract(right));

        constexpr auto new_strides = GetStrides()
                                         .Extract(left)
                                         .PushBack(Number<unfold_stride>{})
                                         .Append(GetStrides().Extract(right));

        constexpr auto new_ranks = tmp_ranks.Extract(left)
                                       .PushBack(Number<unfold_rank>{})
                                       .Append(tmp_ranks.Extract(right));

        return ConstantTensorDescriptor<decltype(new_lengths),
                                        decltype(new_strides),
                                        decltype(new_ranks)>{};
    }

    template <class MapNew2Old>
    __host__ __device__ static constexpr auto ReorderGivenNew2Old(MapNew2Old)
    {
        return ConstantTensorDescriptor<decltype(Lengths{}.ReorderGivenNew2Old(MapNew2Old{})),
                                        decltype(Strides{}.ReorderGivenNew2Old(MapNew2Old{})),
                                        decltype(
                                            MemoryRanks{}.ReorderGivenNew2Old(MapNew2Old{}))>{};
Chao Liu's avatar
Chao Liu committed
342
343
    }

344
345
346
#if 0 // require sequence_sort, which is not implemented yet
    template <class MapOld2New>
    __host__ __device__ static constexpr auto ReorderGivenOld2New(MapOld2New)
Chao Liu's avatar
Chao Liu committed
347
    {
348
349
350
351
        return ConstantTensorDescriptor<decltype(Lengths{}.ReorderGivenOld2New(MapOld2New{})),
                                        decltype(Strides{}.ReorderGivenOld2New(MapOld2New{})),
                                        decltype(
                                            MemoryRanks{}.ReorderGivenOld2New(MapOld2New{}))>{};
Chao Liu's avatar
Chao Liu committed
352
    }
353
#endif
Chao Liu's avatar
Chao Liu committed
354
};
Chao Liu's avatar
Chao Liu committed
355
356

template <class Lengths>
357
__host__ __device__ constexpr auto make_packed_ConstantTensorDescriptor(Lengths)
Chao Liu's avatar
Chao Liu committed
358
{
359
360
361
    using Strides     = decltype(calculate_packed_tensor_strides(Lengths{}));
    using MemoryRanks = typename arithmetic_sequence_gen<0, Lengths::GetSize(), 1>::SeqType;
    return ConstantTensorDescriptor<Lengths, Strides, MemoryRanks>{};
Chao Liu's avatar
Chao Liu committed
362
363
364
}

template <class Lengths, class Strides>
365
__host__ __device__ constexpr auto make_ranked_ConstantTensorDescriptor(Lengths, Strides)
Chao Liu's avatar
Chao Liu committed
366
{
367
368
    using MemoryRanks = typename arithmetic_sequence_gen<0, Lengths::GetSize(), 1>::SeqType;
    return ConstantTensorDescriptor<Lengths, Strides, MemoryRanks>{};
Chao Liu's avatar
Chao Liu committed
369
370
}

Chao Liu's avatar
Chao Liu committed
371
template <class Lengths, index_t Align>
372
373
__host__ __device__ constexpr auto
    make_ranked_ConstantTensorDescriptor_with_alignment(Lengths, Number<Align>)
Chao Liu's avatar
Chao Liu committed
374
{
375
376
377
378
    using Strides =
        decltype(calculate_rank_tensor_default_strides_with_alignment(Lengths{}, Number<Align>{}));
    using MemoryRanks = typename arithmetic_sequence_gen<0, Lengths::GetSize(), 1>::SeqType;
    return ConstantTensorDescriptor<Lengths, Strides, MemoryRanks>{};
Chao Liu's avatar
Chao Liu committed
379
380
}

Chao Liu's avatar
Chao Liu committed
381
template <class TDesc>
Chao Liu's avatar
Chao Liu committed
382
__host__ __device__ void print_ConstantTensorDescriptor(TDesc, const char* s)
Chao Liu's avatar
Chao Liu committed
383
{
Chao Liu's avatar
Chao Liu committed
384
    constexpr auto desc    = TDesc{};
Chao Liu's avatar
Chao Liu committed
385
    constexpr index_t ndim = desc.GetNumOfDimension();
Chao Liu's avatar
Chao Liu committed
386

Chao Liu's avatar
Chao Liu committed
387
    static_assert(ndim >= 2 && ndim <= 10, "wrong!");
Chao Liu's avatar
Chao Liu committed
388
389
390
391
392
393
394
395

    if(ndim == 2)
    {
        constexpr auto I0 = Number<0>{};
        constexpr auto I1 = Number<1>{};

        printf("%s dim %u, lengths {%u %u}, strides {%u %u}\n",
               s,
Chao Liu's avatar
Chao Liu committed
396
               desc.GetNumOfDimension(),
Chao Liu's avatar
Chao Liu committed
397
398
399
400
401
               desc.GetLength(I0),
               desc.GetLength(I1),
               desc.GetStride(I0),
               desc.GetStride(I1));
    }
402
403
404
405
406
407
408
409
    else if(ndim == 3)
    {
        constexpr auto I0 = Number<0>{};
        constexpr auto I1 = Number<1>{};
        constexpr auto I2 = Number<2>{};

        printf("%s dim %u, lengths {%u %u %u}, strides {%u %u %u}\n",
               s,
Chao Liu's avatar
Chao Liu committed
410
               desc.GetNumOfDimension(),
411
412
413
414
415
416
417
               desc.GetLength(I0),
               desc.GetLength(I1),
               desc.GetLength(I2),
               desc.GetStride(I0),
               desc.GetStride(I1),
               desc.GetStride(I2));
    }
Chao Liu's avatar
Chao Liu committed
418
419
420
421
422
423
424
425
426
    else if(ndim == 4)
    {
        constexpr auto I0 = Number<0>{};
        constexpr auto I1 = Number<1>{};
        constexpr auto I2 = Number<2>{};
        constexpr auto I3 = Number<3>{};

        printf("%s dim %u, lengths {%u %u %u %u}, strides {%u %u %u %u}\n",
               s,
Chao Liu's avatar
Chao Liu committed
427
               desc.GetNumOfDimension(),
Chao Liu's avatar
Chao Liu committed
428
429
430
431
432
433
434
435
436
               desc.GetLength(I0),
               desc.GetLength(I1),
               desc.GetLength(I2),
               desc.GetLength(I3),
               desc.GetStride(I0),
               desc.GetStride(I1),
               desc.GetStride(I2),
               desc.GetStride(I3));
    }
437
438
439
440
441
442
443
444
445
446
    else if(ndim == 5)
    {
        constexpr auto I0 = Number<0>{};
        constexpr auto I1 = Number<1>{};
        constexpr auto I2 = Number<2>{};
        constexpr auto I3 = Number<3>{};
        constexpr auto I4 = Number<4>{};

        printf("%s dim %u, lengths {%u %u %u %u %u}, strides {%u %u %u %u %u}\n",
               s,
Chao Liu's avatar
Chao Liu committed
447
               desc.GetNumOfDimension(),
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
               desc.GetLength(I0),
               desc.GetLength(I1),
               desc.GetLength(I2),
               desc.GetLength(I3),
               desc.GetLength(I4),
               desc.GetStride(I0),
               desc.GetStride(I1),
               desc.GetStride(I2),
               desc.GetStride(I3),
               desc.GetStride(I4));
    }
    else if(ndim == 6)
    {
        constexpr auto I0 = Number<0>{};
        constexpr auto I1 = Number<1>{};
        constexpr auto I2 = Number<2>{};
        constexpr auto I3 = Number<3>{};
        constexpr auto I4 = Number<4>{};
        constexpr auto I5 = Number<5>{};

        printf("%s dim %u, lengths {%u %u %u %u %u %u}, strides {%u %u %u %u %u %u}\n",
               s,
Chao Liu's avatar
Chao Liu committed
470
               desc.GetNumOfDimension(),
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
               desc.GetLength(I0),
               desc.GetLength(I1),
               desc.GetLength(I2),
               desc.GetLength(I3),
               desc.GetLength(I4),
               desc.GetLength(I5),
               desc.GetStride(I0),
               desc.GetStride(I1),
               desc.GetStride(I2),
               desc.GetStride(I3),
               desc.GetStride(I4),
               desc.GetStride(I5));
    }
    else if(ndim == 7)
    {
        constexpr auto I0 = Number<0>{};
        constexpr auto I1 = Number<1>{};
        constexpr auto I2 = Number<2>{};
        constexpr auto I3 = Number<3>{};
        constexpr auto I4 = Number<4>{};
        constexpr auto I5 = Number<5>{};
        constexpr auto I6 = Number<6>{};

        printf("%s dim %u, lengths {%u %u %u %u %u %u %u}, strides {%u %u %u %u %u %u %u}\n",
               s,
Chao Liu's avatar
Chao Liu committed
496
               desc.GetNumOfDimension(),
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
               desc.GetLength(I0),
               desc.GetLength(I1),
               desc.GetLength(I2),
               desc.GetLength(I3),
               desc.GetLength(I4),
               desc.GetLength(I5),
               desc.GetLength(I6),
               desc.GetStride(I0),
               desc.GetStride(I1),
               desc.GetStride(I2),
               desc.GetStride(I3),
               desc.GetStride(I4),
               desc.GetStride(I5),
               desc.GetStride(I6));
    }
    else if(ndim == 8)
    {
        constexpr auto I0 = Number<0>{};
        constexpr auto I1 = Number<1>{};
        constexpr auto I2 = Number<2>{};
        constexpr auto I3 = Number<3>{};
        constexpr auto I4 = Number<4>{};
        constexpr auto I5 = Number<5>{};
        constexpr auto I6 = Number<6>{};
        constexpr auto I7 = Number<7>{};

        printf("%s dim %u, lengths {%u %u %u %u %u %u %u %u}, strides {%u %u %u %u %u %u %u %u}\n",
               s,
Chao Liu's avatar
Chao Liu committed
525
               desc.GetNumOfDimension(),
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
               desc.GetLength(I0),
               desc.GetLength(I1),
               desc.GetLength(I2),
               desc.GetLength(I3),
               desc.GetLength(I4),
               desc.GetLength(I5),
               desc.GetLength(I6),
               desc.GetLength(I7),
               desc.GetStride(I0),
               desc.GetStride(I1),
               desc.GetStride(I2),
               desc.GetStride(I3),
               desc.GetStride(I4),
               desc.GetStride(I5),
               desc.GetStride(I6),
               desc.GetStride(I7));
    }
Chao Liu's avatar
Chao Liu committed
543
544
545
546
547
548
549
550
551
552
553
554
    else if(ndim == 9)
    {
        constexpr auto I0 = Number<0>{};
        constexpr auto I1 = Number<1>{};
        constexpr auto I2 = Number<2>{};
        constexpr auto I3 = Number<3>{};
        constexpr auto I4 = Number<4>{};
        constexpr auto I5 = Number<5>{};
        constexpr auto I6 = Number<6>{};
        constexpr auto I7 = Number<7>{};
        constexpr auto I8 = Number<8>{};

Chao Liu's avatar
tidy yp  
Chao Liu committed
555
556
        printf("%s dim %u, lengths {%u %u %u %u %u %u %u %u %u}, strides {%u %u %u %u %u %u %u %u "
               "%u}\n",
Chao Liu's avatar
Chao Liu committed
557
               s,
Chao Liu's avatar
Chao Liu committed
558
               desc.GetNumOfDimension(),
Chao Liu's avatar
Chao Liu committed
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
               desc.GetLength(I0),
               desc.GetLength(I1),
               desc.GetLength(I2),
               desc.GetLength(I3),
               desc.GetLength(I4),
               desc.GetLength(I5),
               desc.GetLength(I6),
               desc.GetLength(I7),
               desc.GetLength(I8),
               desc.GetStride(I0),
               desc.GetStride(I1),
               desc.GetStride(I2),
               desc.GetStride(I3),
               desc.GetStride(I4),
               desc.GetStride(I5),
               desc.GetStride(I6),
               desc.GetStride(I7),
               desc.GetStride(I8));
    }
    else if(ndim == 10)
    {
        constexpr auto I0 = Number<0>{};
        constexpr auto I1 = Number<1>{};
        constexpr auto I2 = Number<2>{};
        constexpr auto I3 = Number<3>{};
        constexpr auto I4 = Number<4>{};
        constexpr auto I5 = Number<5>{};
        constexpr auto I6 = Number<6>{};
        constexpr auto I7 = Number<7>{};
        constexpr auto I8 = Number<8>{};
        constexpr auto I9 = Number<9>{};

Chao Liu's avatar
tidy yp  
Chao Liu committed
591
592
        printf("%s dim %u, lengths {%u %u %u %u %u %u %u %u %u %u}, strides {%u %u %u %u %u %u %u "
               "%u %u %u}\n",
Chao Liu's avatar
Chao Liu committed
593
               s,
Chao Liu's avatar
Chao Liu committed
594
               desc.GetNumOfDimension(),
Chao Liu's avatar
Chao Liu committed
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
               desc.GetLength(I0),
               desc.GetLength(I1),
               desc.GetLength(I2),
               desc.GetLength(I3),
               desc.GetLength(I4),
               desc.GetLength(I5),
               desc.GetLength(I6),
               desc.GetLength(I7),
               desc.GetLength(I8),
               desc.GetLength(I9),
               desc.GetStride(I0),
               desc.GetStride(I1),
               desc.GetStride(I2),
               desc.GetStride(I3),
               desc.GetStride(I4),
               desc.GetStride(I5),
               desc.GetStride(I6),
               desc.GetStride(I7),
               desc.GetStride(I8),
               desc.GetStride(I9));
    }
Chao Liu's avatar
Chao Liu committed
616
}