| 488 | } |
| 489 | |
| 490 | void TestTensorResize(daliStorageDevice_t storage_device) { |
| 491 | daliBufferPlacement_t placement{}; |
| 492 | placement.device_type = storage_device; |
| 493 | auto t = CreateTensor(placement); |
| 494 | int64_t shape[] = { |
| 495 | 1080, 1920, 3 |
| 496 | }; |
| 497 | daliDataType_t dtype = DALI_INT16; |
| 498 | |
| 499 | EXPECT_EQ(daliTensorResize(t, 3, nullptr, dtype, nullptr), DALI_ERROR_INVALID_ARGUMENT); |
| 500 | EXPECT_EQ(daliTensorResize(t, -1, shape, dtype, nullptr), DALI_ERROR_INVALID_ARGUMENT); |
| 501 | EXPECT_EQ(daliTensorResize(t, 3, shape, dtype, "ABCD"), DALI_ERROR_INVALID_ARGUMENT); |
| 502 | shape[0] = -1; |
| 503 | EXPECT_EQ(daliTensorResize(t, 3, shape, dtype, "HWC"), DALI_ERROR_INVALID_ARGUMENT); |
| 504 | shape[0] = 1; |
| 505 | CHECK_DALI(daliTensorResize(t, 3, shape, dtype, "HWC")); |
| 506 | |
| 507 | shape[0] = 1080; |
| 508 | CHECK_DALI(daliTensorResize(t, 3, shape, dtype, nullptr)); |
| 509 | |
| 510 | size_t element_size = dali::TypeTable::GetTypeInfo(dtype).size(); |
| 511 | |
| 512 | ptrdiff_t offset = 0; |
| 513 | daliTensorDesc_t desc{}; |
| 514 | CHECK_DALI(daliTensorGetDesc(t, &desc)); |
| 515 | ASSERT_EQ(desc.ndim, 3); |
| 516 | EXPECT_STREQ(desc.layout, "HWC"); |
| 517 | EXPECT_EQ(desc.dtype, dtype); |
| 518 | ASSERT_NE(desc.shape, nullptr); |
| 519 | for (int j = 0; j < 3; j++) |
| 520 | EXPECT_EQ(desc.shape[j], shape[j]); |
| 521 | size_t sample_bytes = volume(dali::make_cspan(desc.shape, desc.ndim)) * element_size; |
| 522 | size_t reported_byte_size = 0; |
| 523 | CHECK_DALI(daliTensorGetByteSize(t, &reported_byte_size)); |
| 524 | EXPECT_EQ(reported_byte_size, sample_bytes); |
| 525 | daliDataType_t reported_dtype = DALI_NO_TYPE; |
| 526 | CHECK_DALI(daliTensorGetDType(t, &reported_dtype)); |
| 527 | EXPECT_EQ(reported_dtype, dtype); |
| 528 | ASSERT_NE(desc.data, nullptr); |
| 529 | |
| 530 | if (storage_device == DALI_STORAGE_GPU) { |
| 531 | // Check that the data is accessible for the GPU |
| 532 | EXPECT_EQ(cudaMemset(desc.data, 0, sample_bytes), cudaSuccess); |
| 533 | } else { |
| 534 | // Check that the data is accessible for the CPU |
| 535 | memset(desc.data, 0, sample_bytes); // just not crashing is OK |
| 536 | } |
| 537 | if (storage_device == DALI_STORAGE_GPU) { |
| 538 | EXPECT_EQ(cudaDeviceSynchronize(), cudaSuccess); |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | TEST(CAPI2_TensorTest, ResizeCPU) { |
| 543 | TestTensorResize(DALI_STORAGE_CPU); |
no test coverage detected