forked from alpaka-group/alpaka3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstCorrectness.cpp
More file actions
534 lines (424 loc) · 26.1 KB
/
constCorrectness.cpp
File metadata and controls
534 lines (424 loc) · 26.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
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
496
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
525
526
527
528
529
530
531
532
533
534
/* Copyright 2025 René Widera
* SPDX-License-Identifier: MPL-2.0
*/
#include <alpaka/alpaka.hpp>
#include <alpaka/mem/concepts/detail/CopyConstructableDataSource.hpp>
#include <catch2/catch_template_test_macros.hpp>
#include <catch2/catch_test_macros.hpp>
#include <concepts>
#include <iostream>
using namespace alpaka;
/** @file test the behaviour for constness of buffers/views/MdSpan
*
* We run two different test, one for access with 1D memory and the usage of scalars to access the memory and one for
* multidimensional memory, because there are specializations for 1D in our implementations.
*/
/** validate that the buffer is mutable
*
* If we use non-outer const buffers/views in the function signature it should be possible to call the function even if
* the buffer/view had an outer const before. The reason why we can not transform the outer const into an inner const
* is that we requires this within @c KernelBundle to forward the kernel user arguments in a tuple to the user kernel.
*/
void requiresMutableBufferMd(concepts::IMdSpan auto buffer)
{
static_assert(!std::is_const_v<std::remove_pointer_t<decltype(buffer.data())>>);
static_assert(!std::is_const_v<std::remove_reference_t<decltype(buffer[Vec{0, 0}])>>);
}
TEST_CASE("mdspan inner const copy constructor", "[mem][mdspan][correctness][copyConstruct]")
{
constexpr size_t size = 10;
int* ptr = nullptr;
int const* const_ptr = nullptr;
concepts::Vector auto extents = Vec<uint32_t, 3>{}.fill(size);
concepts::Vector auto pitches = alpaka::calculatePitchesFromExtents<int>(extents);
using MutMdSpan = MdSpan<int, decltype(extents), decltype(pitches)>;
using ConstMdSpan = MdSpan<int const, decltype(extents), decltype(pitches)>;
STATIC_REQUIRE(internal::CopyConstructableDataSource<MutMdSpan>::value);
STATIC_REQUIRE(internal::concepts::CopyConstructableDataSource<MutMdSpan>);
STATIC_REQUIRE(internal::concepts::CopyConstructableDataSource<ConstMdSpan>);
MutMdSpan mut_mdspan(ptr, extents, pitches);
ConstMdSpan const_mdspan(const_ptr, extents, pitches);
STATIC_REQUIRE(std::constructible_from<MutMdSpan, MutMdSpan&>);
[[maybe_unused]] MutMdSpan mut_mdspan_copy(mut_mdspan);
STATIC_REQUIRE(std::constructible_from<ConstMdSpan, ConstMdSpan&>);
[[maybe_unused]] ConstMdSpan const_mdspan_copy(const_mdspan);
STATIC_REQUIRE(std::constructible_from<ConstMdSpan, MutMdSpan&>);
[[maybe_unused]] ConstMdSpan mut_to_const_mdspan(mut_mdspan);
STATIC_REQUIRE_FALSE(std::constructible_from<MutMdSpan, ConstMdSpan&>);
// should not compile
// MdSpan const_to_mud_mdspan(const_mdspan);
}
TEST_CASE("mdspan inner const assignment operator", "[mem][mdspan][correctness][copyConstruct]")
{
constexpr size_t size = 10;
int* ptr = nullptr;
int const* const_ptr = nullptr;
concepts::Vector auto extents = Vec<uint32_t, 2>{}.fill(size);
concepts::Vector auto pitches = alpaka::calculatePitchesFromExtents<int>(extents);
using MutMdSpan = MdSpan<int, decltype(extents), decltype(pitches)>;
using ConstMdSpan = MdSpan<int const, decltype(extents), decltype(pitches)>;
MutMdSpan mut_mdspan(ptr, extents, pitches);
ConstMdSpan const_mdspan(const_ptr, extents, pitches);
STATIC_REQUIRE(std::assignable_from<MutMdSpan&, MutMdSpan>);
[[maybe_unused]] MutMdSpan mut_mdspan2 = mut_mdspan;
STATIC_REQUIRE(std::assignable_from<ConstMdSpan&, ConstMdSpan>);
[[maybe_unused]] ConstMdSpan const_mdspan2 = const_mdspan;
STATIC_REQUIRE(std::assignable_from<ConstMdSpan&, MutMdSpan>);
[[maybe_unused]] ConstMdSpan const_mdspan3 = mut_mdspan;
STATIC_REQUIRE_FALSE(std::assignable_from<MutMdSpan&, ConstMdSpan>);
// MutMdSpan mut_mdspan3 = const_mdspan;
}
TEST_CASE("mdspan inner const move operator", "[mem][mdspan][correctness][moveConstruct]")
{
constexpr size_t size = 10;
int* ptr = nullptr;
int const* const_ptr = nullptr;
concepts::Vector auto extents = Vec<uint32_t, 2>{}.fill(size);
concepts::Vector auto pitches = alpaka::calculatePitchesFromExtents<int>(extents);
using MutMdSpan = MdSpan<int, decltype(extents), decltype(pitches)>;
using ConstMdSpan = MdSpan<int const, decltype(extents), decltype(pitches)>;
MutMdSpan copy_mut_mdspan(ptr, extents, pitches);
ConstMdSpan copy_const_mdspan(const_ptr, extents, pitches);
[[maybe_unused]] MutMdSpan copy_mut_mdspan2(std::move(copy_mut_mdspan));
[[maybe_unused]] ConstMdSpan copy_const_mdspan2(std::move(copy_const_mdspan));
[[maybe_unused]] ConstMdSpan copy_const_mdspan3(std::move(copy_mut_mdspan2));
// should not compile
// MutMdSpan copy_mut_mdspan3(std::move(copy_const_mdspan3));
MutMdSpan assign_mut_mdspan(ptr, extents, pitches);
ConstMdSpan assign_const_mdspan(const_ptr, extents, pitches);
MutMdSpan assign_mut_mdspan2 = std::move(assign_mut_mdspan);
[[maybe_unused]] ConstMdSpan assign_const_mdspan2 = std::move(assign_const_mdspan);
[[maybe_unused]] ConstMdSpan assign_const_mdspan3 = std::move(assign_mut_mdspan2);
// should not compile
// MutMdSpan assign_mut_mdspan3 = std::move(assign_const_mdspan3);
}
template<typename TExpectedValueType, typename TExpectedReferenceType, typename TMdSpan>
requires internal::concepts::CopyConstructableDataSource<TMdSpan> && concepts::IMdSpan<TMdSpan>
void funcCopyByValue(TMdSpan mdspan)
{
STATIC_REQUIRE(std::same_as<typename decltype(mdspan)::value_type, TExpectedValueType>);
auto& val = mdspan[0];
STATIC_CHECK(std::same_as<decltype(val), TExpectedReferenceType&>);
}
template<typename TExpectedValueType, typename TExpectedReferenceType, typename TMdSpan>
requires internal::concepts::CopyConstructableDataSource<TMdSpan> && concepts::IMdSpan<TMdSpan>
void funcReference(TMdSpan& mdspan)
{
STATIC_REQUIRE(std::same_as<typename std::remove_reference_t<decltype(mdspan)>::value_type, TExpectedValueType>);
auto& val = mdspan[0];
STATIC_CHECK(std::same_as<decltype(val), TExpectedReferenceType&>);
}
template<typename TExpectedValueType, typename TExpectedReferenceType, typename TMdSpan>
requires internal::concepts::CopyConstructableDataSource<TMdSpan> && concepts::IMdSpan<TMdSpan>
void funcConstReference(TMdSpan const& mdspan)
{
STATIC_REQUIRE(std::same_as<typename std::remove_reference_t<decltype(mdspan)>::value_type, TExpectedValueType>);
auto& val = mdspan[0];
STATIC_CHECK(std::same_as<decltype(val), TExpectedReferenceType&>);
}
template<typename TExpectedValueType, typename TExpectedReferenceType, typename TMdSpan>
requires internal::concepts::CopyConstructableDataSource<TMdSpan> && concepts::IMdSpan<TMdSpan>
void funcUniversalRef(TMdSpan&& mdspan)
{
STATIC_REQUIRE(std::same_as<typename std::remove_reference_t<decltype(mdspan)>::value_type, TExpectedValueType>);
auto& val = mdspan[0];
STATIC_CHECK(std::same_as<decltype(val), TExpectedReferenceType&>);
}
TEST_CASE("function calls with mdspan object", "[mem][mdspan][correctness]")
{
constexpr size_t size = 10;
int* ptr = nullptr;
int const* const_ptr = nullptr;
concepts::Vector auto extents = Vec<uint32_t, 1>{}.fill(size);
concepts::Vector auto pitches = alpaka::calculatePitchesFromExtents<int>(extents);
MdSpan mdspan{ptr, extents, pitches};
funcCopyByValue<int, int&>(mdspan);
funcReference<int, int&>(mdspan);
funcConstReference<int, int const&>(mdspan);
funcUniversalRef<int, int&>(mdspan);
funcUniversalRef<int, int&>(MdSpan{ptr, extents, pitches});
MdSpan const const_mdspan{ptr, extents, pitches};
funcCopyByValue<int, int&>(const_mdspan);
funcReference<int, int const&>(const_mdspan);
funcConstReference<int, int const&>(const_mdspan);
MdSpan mdspan_inner_const{const_ptr, extents, pitches};
funcCopyByValue<int const, int const&>(mdspan_inner_const);
funcReference<int const, int const&>(mdspan_inner_const);
funcConstReference<int const, int const&>(mdspan_inner_const);
funcUniversalRef<int const, int const&>(mdspan_inner_const);
funcUniversalRef<int const, int const&>(MdSpan{const_ptr, extents, pitches});
MdSpan const const_mdspan_inner_const{const_ptr, extents, pitches};
funcCopyByValue<int const, int const&>(const_mdspan_inner_const);
funcReference<int const, int const&>(const_mdspan_inner_const);
funcConstReference<int const, int const&>(const_mdspan_inner_const);
funcUniversalRef<int const, int const&>(const_mdspan_inner_const);
}
TEST_CASE("MdSpanArray inner const copy constructor", "[mem][mdspanarray][correctness][copyConstruct]")
{
int static_data[2][2] = {{0, 0}, {0, 0}};
int const const_static_data[2][2] = {{0, 0}, {0, 0}};
using MutMdSpanArray = MdSpanArray<decltype(static_data), size_t, alpaka::Alignment<16>>;
using ConstMdSpanArray = MdSpanArray<decltype(const_static_data), size_t, alpaka::Alignment<16>>;
STATIC_REQUIRE(internal::CopyConstructableDataSource<MutMdSpanArray>::value);
STATIC_REQUIRE(internal::concepts::CopyConstructableDataSource<MutMdSpanArray>);
STATIC_REQUIRE(internal::concepts::CopyConstructableDataSource<ConstMdSpanArray>);
MutMdSpanArray mut_md_span_array(static_data);
ConstMdSpanArray const_md_span_array(const_static_data);
STATIC_REQUIRE(std::constructible_from<MutMdSpanArray, MutMdSpanArray&>);
[[maybe_unused]] MutMdSpanArray mut_md_span_array_copy(mut_md_span_array);
STATIC_REQUIRE(std::constructible_from<ConstMdSpanArray, ConstMdSpanArray&>);
[[maybe_unused]] ConstMdSpanArray const_md_span_array_copy(const_md_span_array);
STATIC_REQUIRE(std::constructible_from<ConstMdSpanArray, MutMdSpanArray&>);
[[maybe_unused]] ConstMdSpanArray mut_to_const_md_span_array(mut_md_span_array);
STATIC_REQUIRE_FALSE(std::constructible_from<MutMdSpanArray, ConstMdSpanArray&>);
// should not compile
// MutMdSpanArray const_to_mut_md_span_array(const_md_span_array);
}
TEST_CASE("MdSpanArray inner const assignment operator", "[mem][mdspanarray][correctness][copyConstruct]")
{
int static_data[2][2] = {{0, 0}, {0, 0}};
int const const_static_data[2][2] = {{0, 0}, {0, 0}};
using MutMdSpanArray = MdSpanArray<decltype(static_data), size_t, alpaka::Alignment<16>>;
using ConstMdSpanArray = MdSpanArray<decltype(const_static_data), size_t, alpaka::Alignment<16>>;
MutMdSpanArray mut_md_span_array(static_data);
ConstMdSpanArray const_md_span_array(const_static_data);
STATIC_REQUIRE(std::assignable_from<MutMdSpanArray&, MutMdSpanArray>);
[[maybe_unused]] MutMdSpanArray mut_md_span_arra2 = mut_md_span_array;
STATIC_REQUIRE(std::assignable_from<ConstMdSpanArray&, ConstMdSpanArray>);
[[maybe_unused]] ConstMdSpanArray const_md_span_array2 = const_md_span_array;
STATIC_REQUIRE(std::assignable_from<ConstMdSpanArray&, MutMdSpanArray>);
[[maybe_unused]] ConstMdSpanArray const_md_span_array3 = mut_md_span_array;
STATIC_REQUIRE_FALSE(std::assignable_from<MutMdSpanArray&, ConstMdSpanArray>);
// MutMdSpanArray mut_view3 = const_md_span_array;
}
TEST_CASE(
"MdSpanArray inner const move constructor and move assignment operator",
"[mem][mdspanarray][correctness][moveConstruct]")
{
int static_data[2][2] = {{0, 0}, {0, 0}};
int const const_static_data[2][2] = {{0, 0}, {0, 0}};
using MutMdSpanArray = MdSpanArray<decltype(static_data), size_t, alpaka::Alignment<16>>;
using ConstMdSpanArray = MdSpanArray<decltype(const_static_data), size_t, alpaka::Alignment<16>>;
MutMdSpanArray constr_mut_md(static_data);
ConstMdSpanArray constr_const_md(const_static_data);
MutMdSpanArray constr_mut_md2(std::move(constr_mut_md));
[[maybe_unused]] ConstMdSpanArray constr_const_md2(std::move(constr_const_md));
[[maybe_unused]] ConstMdSpanArray constr_const_md3(std::move(constr_mut_md2));
// should not compile
// MutMdSpanArray constr_mut_md3(std::move(constr_const_md3));
MutMdSpanArray assign_mut_md(static_data);
ConstMdSpanArray assign_const_md(const_static_data);
MutMdSpanArray assign_mut_md2 = std::move(assign_mut_md);
[[maybe_unused]] ConstMdSpanArray assign_const_md2 = std::move(assign_const_md);
[[maybe_unused]] ConstMdSpanArray assign_const_md3 = std::move(assign_mut_md2);
// should not compile
// MutMdSpanArray assign_mut_md3 = std::move(assign_const_md3);
}
TEST_CASE("View inner const copy constructor", "[mem][view][correctness][copyConstruct]")
{
constexpr size_t size = 10;
int* ptr = nullptr;
int const* const_ptr = nullptr;
concepts::Vector auto extents = Vec<uint32_t, 3>{}.fill(size);
concepts::Vector auto pitches = alpaka::calculatePitchesFromExtents<int>(extents);
using MutView = View<alpaka::api::Host, int, decltype(extents)>;
using ConstView = View<alpaka::api::Host, int const, decltype(extents)>;
STATIC_REQUIRE(internal::CopyConstructableDataSource<MutView>::value);
STATIC_REQUIRE(internal::concepts::CopyConstructableDataSource<MutView>);
STATIC_REQUIRE(internal::concepts::CopyConstructableDataSource<ConstView>);
MutView mut_view(api::host, ptr, extents, pitches);
ConstView const_view(api::host, const_ptr, extents, pitches);
STATIC_REQUIRE(std::constructible_from<MutView, MutView&>);
[[maybe_unused]] MutView mut_view_copy(mut_view);
STATIC_REQUIRE(std::constructible_from<ConstView, ConstView&>);
[[maybe_unused]] ConstView const_view_copy(const_view);
STATIC_REQUIRE(std::constructible_from<ConstView, MutView&>);
[[maybe_unused]] ConstView mut_to_const_view(mut_view);
STATIC_REQUIRE_FALSE(std::constructible_from<MutView, ConstView&>);
// should not compile
// MutView const_to_mud_view(const_view);
}
TEST_CASE("View inner const assignment operator", "[mem][view][correctness][copyConstruct]")
{
constexpr size_t size = 10;
int* ptr = nullptr;
int const* const_ptr = nullptr;
concepts::Vector auto extents = Vec<uint32_t, 2>{}.fill(size);
concepts::Vector auto pitches = alpaka::calculatePitchesFromExtents<int>(extents);
using MutView = View<alpaka::api::Host, int, decltype(extents)>;
using ConstView = View<alpaka::api::Host, int const, decltype(extents)>;
MutView mut_view(api::host, ptr, extents, pitches);
ConstView const_view(api::host, const_ptr, extents, pitches);
STATIC_REQUIRE(std::assignable_from<MutView&, MutView>);
[[maybe_unused]] MutView mut_view2 = mut_view;
STATIC_REQUIRE(std::assignable_from<ConstView&, ConstView>);
[[maybe_unused]] ConstView const_view2 = const_view;
STATIC_REQUIRE(std::assignable_from<ConstView&, MutView>);
[[maybe_unused]] ConstView const_view3 = mut_view;
STATIC_REQUIRE_FALSE(std::assignable_from<MutView&, ConstView>);
// MutView mut_view3 = const_view;
}
TEST_CASE("View inner const move constructor and move assignment operator", "[mem][view][correctness][moveConstruct]")
{
constexpr size_t size = 10;
int* ptr = nullptr;
int const* const_ptr = nullptr;
concepts::Vector auto extents = Vec<uint32_t, 3>{}.fill(size);
concepts::Vector auto pitches = alpaka::calculatePitchesFromExtents<int>(extents);
using MutView = View<alpaka::api::Host, int, decltype(extents)>;
using ConstView = View<alpaka::api::Host, int const, decltype(extents)>;
MutView construct_mut_view(api::host, ptr, extents, pitches);
ConstView construct_const_view(api::host, const_ptr, extents, pitches);
MutView construct_mut_view2(std::move(construct_mut_view));
[[maybe_unused]] ConstView construct_const_view2(std::move(construct_const_view));
[[maybe_unused]] ConstView construct_const_view3(std::move(construct_mut_view2));
// should not compile
// MutView construct_mut_view3(std::move(construct_const_view3));
MutView assign_mut_view(api::host, ptr, extents, pitches);
ConstView assign_const_view(api::host, const_ptr, extents, pitches);
MutView assign_mut_view2 = std::move(assign_mut_view);
[[maybe_unused]] ConstView assign_const_view2 = std::move(assign_const_view);
[[maybe_unused]] ConstView assign_const_view3 = std::move(assign_mut_view2);
// should not compile
// MutView assign_mut_view3 = std::move(assign_const_view3);
}
TEST_CASE("sharedBuffer inner const copy constructor", "[mem][sharedBuffer][correctness][copyConstruct]")
{
constexpr size_t size = 10;
int* ptr = nullptr;
int const* const_ptr = nullptr;
concepts::Vector auto extents = Vec<uint32_t, 3>{}.fill(size);
concepts::Vector auto pitches = alpaka::calculatePitchesFromExtents<int>(extents);
using MutSharedBuffer = onHost::SharedBuffer<alpaka::api::Host, int, decltype(extents)>;
using ConstSharedBuffer = onHost::SharedBuffer<alpaka::api::Host, int const, decltype(extents)>;
STATIC_REQUIRE(internal::CopyConstructableDataSource<MutSharedBuffer>::value);
STATIC_REQUIRE(internal::concepts::CopyConstructableDataSource<MutSharedBuffer>);
STATIC_REQUIRE(internal::concepts::CopyConstructableDataSource<ConstSharedBuffer>);
MutSharedBuffer mut_shared_buffer(api::host, ptr, extents, pitches, [] {});
ConstSharedBuffer const_shared_buffer(api::host, const_ptr, extents, pitches, [] {});
STATIC_REQUIRE(std::constructible_from<MutSharedBuffer, MutSharedBuffer&>);
[[maybe_unused]] MutSharedBuffer mut_shared_buffer_copy(mut_shared_buffer);
STATIC_REQUIRE(std::constructible_from<ConstSharedBuffer, ConstSharedBuffer&>);
[[maybe_unused]] ConstSharedBuffer const_shared_buffer_copy(const_shared_buffer);
STATIC_REQUIRE(std::constructible_from<ConstSharedBuffer, MutSharedBuffer&>);
[[maybe_unused]] ConstSharedBuffer mut_to_const_shared_buffer(mut_shared_buffer);
STATIC_REQUIRE_FALSE(std::constructible_from<MutSharedBuffer, ConstSharedBuffer&>);
// should not compile
// MutSharedBuffer const_to_mud_shared_buffer(const_shared_buffer);
}
TEST_CASE("sharedBuffer inner const assignment operator", "[mem][sharedBuffer][correctness][copyConstruct]")
{
constexpr size_t size = 10;
int* ptr = nullptr;
int const* const_ptr = nullptr;
concepts::Vector auto extents = Vec<uint32_t, 2>{}.fill(size);
concepts::Vector auto pitches = alpaka::calculatePitchesFromExtents<int>(extents);
using MutSharedBuffer = onHost::SharedBuffer<alpaka::api::Host, int, decltype(extents)>;
using ConstSharedBuffer = onHost::SharedBuffer<alpaka::api::Host, int const, decltype(extents)>;
MutSharedBuffer mut_shared_buffer(api::host, ptr, extents, pitches, [] {});
ConstSharedBuffer const_shared_buffer(api::host, const_ptr, extents, pitches, [] {});
STATIC_REQUIRE(std::assignable_from<MutSharedBuffer&, MutSharedBuffer>);
[[maybe_unused]] MutSharedBuffer mut_shared_buffer2 = mut_shared_buffer;
STATIC_REQUIRE(std::assignable_from<ConstSharedBuffer&, ConstSharedBuffer>);
[[maybe_unused]] ConstSharedBuffer const_shared_buffer2 = const_shared_buffer;
STATIC_REQUIRE(std::assignable_from<ConstSharedBuffer&, MutSharedBuffer>);
[[maybe_unused]] ConstSharedBuffer const_shared_buffer3 = mut_shared_buffer;
STATIC_REQUIRE_FALSE(std::assignable_from<MutSharedBuffer&, ConstSharedBuffer>);
// MutSharedBuffer mut_shared_buffer3 = const_shared_buffer;
}
TEST_CASE("sharedBuffer inner const move operator", "[mem][sharedBuffer][correctness][moveConstruct]")
{
constexpr size_t size = 10;
int* ptr = nullptr;
int const* const_ptr = nullptr;
concepts::Vector auto extents = Vec<uint32_t, 3>{}.fill(size);
concepts::Vector auto pitches = alpaka::calculatePitchesFromExtents<int>(extents);
using MutSharedBuffer = onHost::SharedBuffer<alpaka::api::Host, int, decltype(extents)>;
using ConstSharedBuffer = onHost::SharedBuffer<alpaka::api::Host, int const, decltype(extents)>;
MutSharedBuffer copy_mut_shared_buffer(api::host, ptr, extents, pitches, [] {});
ConstSharedBuffer copy_const_shared_buffer(api::host, const_ptr, extents, pitches, [] {});
MutSharedBuffer copy_mut_shared_buffer2(std::move(copy_mut_shared_buffer));
ConstSharedBuffer copy_const_shared_buffer2(std::move(copy_const_shared_buffer));
[[maybe_unused]] ConstSharedBuffer copy_const_shared_buffer3(std::move(copy_mut_shared_buffer2));
// should not compile
// MutSharedBuffer copy_mut_shared_buffer3(std::move(copy_const_shared_buffer3));
MutSharedBuffer assign_mut_shared_buffer(api::host, ptr, extents, pitches, [] {});
ConstSharedBuffer assign_const_shared_buffer(api::host, const_ptr, extents, pitches, [] {});
MutSharedBuffer assign_mut_shared_buffer2 = std::move(assign_mut_shared_buffer);
ConstSharedBuffer assign_const_shared_buffer2 = std::move(assign_const_shared_buffer);
[[maybe_unused]] ConstSharedBuffer assign_const_shared_buffer3 = std::move(assign_mut_shared_buffer2);
// should not compile
// MutSharedBuffer assign_mut_shared_buffer3 = std::move(assign_const_shared_buffer3);
}
TEST_CASE("buffer const correctness MD", "[mem][sharedBuffer][correctness]")
{
auto buffer0 = onHost::allocHost<int>(Vec{10, 10});
requiresMutableBufferMd(buffer0);
static_assert(!std::is_const_v<std::remove_pointer_t<decltype(buffer0.data())>>);
SECTION("getSubView/getSubBuffer from mutable DataStorage object")
{
[[maybe_unused]] auto subBuffer0 = buffer0.getSubSharedBuffer(Vec{2, 2});
static_assert(!std::is_const_v<std::remove_pointer_t<decltype(subBuffer0.data())>>);
static_assert(!std::is_const_v<std::remove_reference_t<decltype(subBuffer0[Vec{0, 0}])>>);
[[maybe_unused]] auto subOffsetBuffer0 = buffer0.getSubSharedBuffer(Vec{1, 1}, Vec{2, 2});
static_assert(!std::is_const_v<std::remove_pointer_t<decltype(subOffsetBuffer0.data())>>);
static_assert(!std::is_const_v<std::remove_reference_t<decltype(subOffsetBuffer0[Vec{0, 0}])>>);
[[maybe_unused]] auto subView0 = buffer0.getSubView(Vec{2, 2});
static_assert(!std::is_const_v<std::remove_pointer_t<decltype(subView0.data())>>);
static_assert(!std::is_const_v<std::remove_reference_t<decltype(subView0[Vec{0, 0}])>>);
[[maybe_unused]] auto subOffsetView0 = buffer0.getSubView(Vec{1, 1}, Vec{2, 2});
static_assert(!std::is_const_v<std::remove_pointer_t<decltype(subOffsetView0.data())>>);
static_assert(!std::is_const_v<std::remove_reference_t<decltype(subOffsetView0[Vec{0, 0}])>>);
[[maybe_unused]] View view = buffer0.getView();
static_assert(!std::is_const_v<std::remove_pointer_t<decltype(view.data())>>);
static_assert(!std::is_const_v<std::remove_reference_t<decltype(view[Vec{0, 0}])>>);
[[maybe_unused]] MdSpan mdSpan = buffer0.getMdSpan();
static_assert(!std::is_const_v<std::remove_pointer_t<decltype(mdSpan.data())>>);
static_assert(!std::is_const_v<std::remove_reference_t<decltype(mdSpan[Vec{0, 0}])>>);
}
SECTION("getSubView/getSubBuffer from non-mutable DataStorage object (inner const)")
{
onHost::SharedBuffer innerConstBuffer0 = buffer0.getConstSharedBuffer();
[[maybe_unused]] auto subBuffer0 = innerConstBuffer0.getSubSharedBuffer(Vec{2, 2});
static_assert(std::is_const_v<std::remove_pointer_t<decltype(subBuffer0.data())>>);
static_assert(std::is_const_v<std::remove_reference_t<decltype(subBuffer0[Vec{0, 0}])>>);
[[maybe_unused]] auto subOffsetBuffer0 = innerConstBuffer0.getSubSharedBuffer(Vec{1, 1}, Vec{2, 2});
static_assert(std::is_const_v<std::remove_pointer_t<decltype(subOffsetBuffer0.data())>>);
static_assert(std::is_const_v<std::remove_reference_t<decltype(subOffsetBuffer0[Vec{0, 0}])>>);
[[maybe_unused]] auto subView0 = innerConstBuffer0.getSubView(Vec{2, 2});
static_assert(std::is_const_v<std::remove_pointer_t<decltype(subView0.data())>>);
static_assert(std::is_const_v<std::remove_reference_t<decltype(subView0[Vec{0, 0}])>>);
[[maybe_unused]] auto subOffsetView0 = innerConstBuffer0.getSubView(Vec{1, 1}, Vec{2, 2});
static_assert(std::is_const_v<std::remove_pointer_t<decltype(subOffsetView0.data())>>);
static_assert(std::is_const_v<std::remove_reference_t<decltype(subOffsetView0[Vec{0, 0}])>>);
[[maybe_unused]] View view = innerConstBuffer0.getView();
static_assert(std::is_const_v<std::remove_pointer_t<decltype(view.data())>>);
static_assert(std::is_const_v<std::remove_reference_t<decltype(view[Vec{0, 0}])>>);
[[maybe_unused]] MdSpan mdSpan = innerConstBuffer0.getMdSpan();
static_assert(std::is_const_v<std::remove_pointer_t<decltype(mdSpan.data())>>);
static_assert(std::is_const_v<std::remove_reference_t<decltype(mdSpan[Vec{0, 0}])>>);
}
SECTION("getSubView/getSubBuffer from non-mutable DataStorage object (outer const)")
{
onHost::SharedBuffer const outerConstBuffer0 = buffer0;
requiresMutableBufferMd(outerConstBuffer0);
[[maybe_unused]] auto subBuffer0 = outerConstBuffer0.getSubSharedBuffer(Vec{2, 2});
static_assert(std::is_const_v<std::remove_pointer_t<decltype(subBuffer0.data())>>);
static_assert(std::is_const_v<std::remove_reference_t<decltype(subBuffer0[Vec{0, 0}])>>);
[[maybe_unused]] auto subOffsetBuffer0 = outerConstBuffer0.getSubSharedBuffer(Vec{1, 1}, Vec{2, 2});
static_assert(std::is_const_v<std::remove_pointer_t<decltype(subOffsetBuffer0.data())>>);
static_assert(std::is_const_v<std::remove_reference_t<decltype(subOffsetBuffer0[Vec{0, 0}])>>);
[[maybe_unused]] auto subView0 = outerConstBuffer0.getSubView(Vec{2, 2});
static_assert(std::is_const_v<std::remove_pointer_t<decltype(subView0.data())>>);
static_assert(std::is_const_v<std::remove_reference_t<decltype(subView0[Vec{0, 0}])>>);
[[maybe_unused]] auto subOffsetView0 = outerConstBuffer0.getSubView(Vec{1, 1}, Vec{2, 2});
static_assert(std::is_const_v<std::remove_pointer_t<decltype(subOffsetView0.data())>>);
static_assert(std::is_const_v<std::remove_reference_t<decltype(subOffsetView0[Vec{0, 0}])>>);
[[maybe_unused]] View view = outerConstBuffer0.getView();
static_assert(std::is_const_v<std::remove_pointer_t<decltype(view.data())>>);
static_assert(std::is_const_v<std::remove_reference_t<decltype(view[Vec{0, 0}])>>);
[[maybe_unused]] MdSpan mdSpan = outerConstBuffer0.getMdSpan();
static_assert(std::is_const_v<std::remove_pointer_t<decltype(mdSpan.data())>>);
static_assert(std::is_const_v<std::remove_reference_t<decltype(mdSpan[Vec{0, 0}])>>);
}
}