|
9 | 9 |
|
10 | 10 | class AccessorIteratorTest : public ::testing::Test {
|
11 | 11 | public:
|
| 12 | + template <int Dimensions, typename T = int> |
| 13 | + void checkWriteThroughIterator(const sycl::range<Dimensions> &fullShape, |
| 14 | + const sycl::range<Dimensions> &fillShape, |
| 15 | + const sycl::id<Dimensions> &offset) { |
| 16 | + std::vector<T> data(fullShape.size(), T{}); |
| 17 | + sycl::buffer buffer(data.data(), fullShape); |
| 18 | + { |
| 19 | + auto accessor = buffer.template get_access<sycl::access_mode::write>( |
| 20 | + fillShape, offset); |
| 21 | + T linear_id = 1; |
| 22 | + for (auto it = accessor.begin(), e = accessor.end(); it != e; ++it) { |
| 23 | + *it = linear_id; |
| 24 | + linear_id += 1; |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + sycl::id<3> offsetToUse(Dimensions > 2 ? offset[Dimensions - 3] : 0, |
| 29 | + Dimensions > 1 ? offset[Dimensions - 2] : 0, |
| 30 | + offset[Dimensions - 1]); |
| 31 | + |
| 32 | + sycl::id<3> shapeToCheck( |
| 33 | + (Dimensions > 2 ? fillShape[Dimensions - 3] : 1) + offsetToUse[0], |
| 34 | + (Dimensions > 1 ? fillShape[Dimensions - 2] : 1) + offsetToUse[1], |
| 35 | + fillShape[Dimensions - 1] + offsetToUse[2]); |
| 36 | + |
| 37 | + auto fullAccessor = buffer.template get_access<sycl::access_mode::read>(); |
| 38 | + T linear_id = 1; |
| 39 | + for (size_t z = offsetToUse[0]; z < shapeToCheck[0]; ++z) { |
| 40 | + for (size_t y = offsetToUse[1]; y < shapeToCheck[1]; ++y) { |
| 41 | + for (size_t x = offsetToUse[2]; x < shapeToCheck[2]; ++x) { |
| 42 | + auto value = accessHelper<Dimensions>(fullAccessor, z, y, x); |
| 43 | + ASSERT_EQ(linear_id, value); |
| 44 | + linear_id += 1; |
| 45 | + } |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + sycl::id<3> adjustedFullShape( |
| 50 | + Dimensions > 2 ? fullShape[Dimensions - 3] : 1, |
| 51 | + Dimensions > 1 ? fullShape[Dimensions - 2] : 1, |
| 52 | + fullShape[Dimensions - 1]); |
| 53 | + |
| 54 | + for (size_t z = 0; z < adjustedFullShape[0]; ++z) { |
| 55 | + for (size_t y = 0; y < adjustedFullShape[1]; ++y) { |
| 56 | + for (size_t x = 0; x < adjustedFullShape[2]; ++x) { |
| 57 | + // Skip elements which we previously checked |
| 58 | + if (z >= offsetToUse[0] && z < shapeToCheck[0] && |
| 59 | + y >= offsetToUse[1] && y < shapeToCheck[1] && |
| 60 | + x >= offsetToUse[2] && x < shapeToCheck[2]) |
| 61 | + continue; |
| 62 | + auto value = accessHelper<Dimensions>(fullAccessor, z, y, x); |
| 63 | + ASSERT_EQ(T{}, value) << "at (" << z << "; " << y << "; " << x << ")"; |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | + |
12 | 69 | template <int Dimensions, typename T = int>
|
13 | 70 | void checkFullCopyThroughIterator(const sycl::range<Dimensions> &shape) {
|
14 | 71 | std::vector<T> reference(shape.size());
|
@@ -373,3 +430,84 @@ TEST_F(AccessorIteratorTest, PartialCopyWithOffset3D) {
|
373 | 430 | ASSERT_NO_FATAL_FAILURE(checkPartialCopyThroughIterator(
|
374 | 431 | sycl::range<3>{9, 8, 7}, sycl::range<3>{3, 4, 5}, sycl::id<3>{3, 2, 1}));
|
375 | 432 | }
|
| 433 | + |
| 434 | +TEST_F(AccessorIteratorTest, FullWrite1D) { |
| 435 | + ASSERT_NO_FATAL_FAILURE(checkWriteThroughIterator( |
| 436 | + sycl::range<1>{10}, sycl::range<1>{10}, sycl::id<1>{0})); |
| 437 | +} |
| 438 | + |
| 439 | +TEST_F(AccessorIteratorTest, FullWrite2D) { |
| 440 | + ASSERT_NO_FATAL_FAILURE(checkWriteThroughIterator( |
| 441 | + sycl::range<2>{5, 5}, sycl::range<2>{5, 5}, sycl::id<2>{0, 0})); |
| 442 | + ASSERT_NO_FATAL_FAILURE(checkWriteThroughIterator( |
| 443 | + sycl::range<2>{2, 5}, sycl::range<2>{2, 5}, sycl::id<2>{0, 0})); |
| 444 | + ASSERT_NO_FATAL_FAILURE(checkWriteThroughIterator( |
| 445 | + sycl::range<2>{5, 2}, sycl::range<2>{5, 2}, sycl::id<2>{0, 0})); |
| 446 | +} |
| 447 | + |
| 448 | +TEST_F(AccessorIteratorTest, FullWrite3D) { |
| 449 | + ASSERT_NO_FATAL_FAILURE(checkWriteThroughIterator( |
| 450 | + sycl::range<3>{5, 5, 5}, sycl::range<3>{5, 5, 5}, sycl::id<3>{0, 0, 0})); |
| 451 | + ASSERT_NO_FATAL_FAILURE(checkWriteThroughIterator( |
| 452 | + sycl::range<3>{1, 5, 5}, sycl::range<3>{1, 5, 5}, sycl::id<3>{0, 0, 0})); |
| 453 | + ASSERT_NO_FATAL_FAILURE(checkWriteThroughIterator( |
| 454 | + sycl::range<3>{5, 1, 5}, sycl::range<3>{5, 1, 5}, sycl::id<3>{0, 0, 0})); |
| 455 | + ASSERT_NO_FATAL_FAILURE(checkWriteThroughIterator( |
| 456 | + sycl::range<3>{5, 5, 1}, sycl::range<3>{5, 5, 1}, sycl::id<3>{0, 0, 0})); |
| 457 | + ASSERT_NO_FATAL_FAILURE(checkWriteThroughIterator( |
| 458 | + sycl::range<3>{3, 6, 4}, sycl::range<3>{3, 6, 4}, sycl::id<3>{0, 0, 0})); |
| 459 | +} |
| 460 | + |
| 461 | +TEST_F(AccessorIteratorTest, PartialWriteWithoutOffset1D) { |
| 462 | + ASSERT_NO_FATAL_FAILURE(checkWriteThroughIterator( |
| 463 | + sycl::range<1>{10}, sycl::range<1>{5}, sycl::id<1>{0})); |
| 464 | +} |
| 465 | + |
| 466 | +TEST_F(AccessorIteratorTest, PartialWriteWithoutOffset2D) { |
| 467 | + ASSERT_NO_FATAL_FAILURE(checkWriteThroughIterator( |
| 468 | + sycl::range<2>{5, 5}, sycl::range<2>{3, 3}, sycl::id<2>{0, 0})); |
| 469 | + ASSERT_NO_FATAL_FAILURE(checkWriteThroughIterator( |
| 470 | + sycl::range<2>{2, 5}, sycl::range<2>{1, 3}, sycl::id<2>{0, 0})); |
| 471 | + ASSERT_NO_FATAL_FAILURE(checkWriteThroughIterator( |
| 472 | + sycl::range<2>{5, 2}, sycl::range<2>{3, 1}, sycl::id<2>{0, 0})); |
| 473 | +} |
| 474 | + |
| 475 | +TEST_F(AccessorIteratorTest, PartialWriteWithoutOffset3D) { |
| 476 | + ASSERT_NO_FATAL_FAILURE(checkWriteThroughIterator( |
| 477 | + sycl::range<3>{5, 5, 5}, sycl::range<3>{3, 3, 3}, sycl::id<3>{0, 0, 0})); |
| 478 | + ASSERT_NO_FATAL_FAILURE(checkWriteThroughIterator( |
| 479 | + sycl::range<3>{1, 5, 5}, sycl::range<3>{0, 3, 3}, sycl::id<3>{0, 0, 0})); |
| 480 | + ASSERT_NO_FATAL_FAILURE(checkWriteThroughIterator( |
| 481 | + sycl::range<3>{5, 1, 5}, sycl::range<3>{3, 1, 3}, sycl::id<3>{0, 0, 0})); |
| 482 | + ASSERT_NO_FATAL_FAILURE(checkWriteThroughIterator( |
| 483 | + sycl::range<3>{5, 5, 1}, sycl::range<3>{3, 3, 1}, sycl::id<3>{0, 0, 0})); |
| 484 | + ASSERT_NO_FATAL_FAILURE(checkWriteThroughIterator( |
| 485 | + sycl::range<3>{3, 6, 4}, sycl::range<3>{1, 3, 2}, sycl::id<3>{0, 0, 0})); |
| 486 | +} |
| 487 | + |
| 488 | +TEST_F(AccessorIteratorTest, PartialWriteWithOffset1D) { |
| 489 | + ASSERT_NO_FATAL_FAILURE(checkWriteThroughIterator( |
| 490 | + sycl::range<1>{10}, sycl::range<1>{5}, sycl::id<1>{3})); |
| 491 | +} |
| 492 | + |
| 493 | +TEST_F(AccessorIteratorTest, PartialWriteWithOffset2D) { |
| 494 | + ASSERT_NO_FATAL_FAILURE(checkWriteThroughIterator( |
| 495 | + sycl::range<2>{5, 5}, sycl::range<2>{3, 3}, sycl::id<2>{1, 1})); |
| 496 | + ASSERT_NO_FATAL_FAILURE(checkWriteThroughIterator( |
| 497 | + sycl::range<2>{3, 5}, sycl::range<2>{1, 3}, sycl::id<2>{1, 2})); |
| 498 | + ASSERT_NO_FATAL_FAILURE(checkWriteThroughIterator( |
| 499 | + sycl::range<2>{5, 3}, sycl::range<2>{3, 1}, sycl::id<2>{1, 1})); |
| 500 | +} |
| 501 | + |
| 502 | +TEST_F(AccessorIteratorTest, PartialWriteWithOffset3D) { |
| 503 | + ASSERT_NO_FATAL_FAILURE(checkWriteThroughIterator( |
| 504 | + sycl::range<3>{5, 5, 5}, sycl::range<3>{3, 3, 3}, sycl::id<3>{1, 1, 1})); |
| 505 | + ASSERT_NO_FATAL_FAILURE(checkWriteThroughIterator( |
| 506 | + sycl::range<3>{3, 5, 5}, sycl::range<3>{0, 3, 3}, sycl::id<3>{1, 2, 2})); |
| 507 | + ASSERT_NO_FATAL_FAILURE(checkWriteThroughIterator( |
| 508 | + sycl::range<3>{5, 2, 5}, sycl::range<3>{3, 1, 3}, sycl::id<3>{1, 1, 2})); |
| 509 | + ASSERT_NO_FATAL_FAILURE(checkWriteThroughIterator( |
| 510 | + sycl::range<3>{5, 5, 3}, sycl::range<3>{3, 3, 1}, sycl::id<3>{1, 1, 1})); |
| 511 | + ASSERT_NO_FATAL_FAILURE(checkWriteThroughIterator( |
| 512 | + sycl::range<3>{3, 6, 4}, sycl::range<3>{1, 3, 2}, sycl::id<3>{1, 3, 2})); |
| 513 | +} |
0 commit comments