| 700 | // Useful for debugging |
| 701 | template<typename VT, typename ST> |
| 702 | inline void PrintBuffer(const std::vector<uint8_t> &vec, const ST &strides, const ST &shape, const char *name = "", |
| 703 | uint32_t endls = 0b1111) |
| 704 | { |
| 705 | using BT = nvcv::cuda::BaseType<ST>; |
| 706 | using BT4 = nvcv::cuda::MakeType<BT, 4>; |
| 707 | using CVT = std::conditional_t<sizeof(VT) == 1, int, VT>; |
| 708 | |
| 709 | std::cout << "I Printing buffer " << name << " with:\nI\tSize = " << vec.size() << " Bytes\nI\tShape = " << shape |
| 710 | << "\nI\tStrides = " << strides << "\nI\tValues = " << std::endl; |
| 711 | |
| 712 | for (BT x = 0; x < (nvcv::cuda::NumElements<ST> >= 1 ? nvcv::cuda::GetElement(shape, 0) : 1); ++x) |
| 713 | { |
| 714 | if (endls & 0b1000) |
| 715 | std::cout << "{" << std::endl; |
| 716 | else |
| 717 | std::cout << "{" << std::flush; |
| 718 | for (BT y = 0; y < (nvcv::cuda::NumElements<ST> >= 2 ? nvcv::cuda::GetElement(shape, 1) : 1); ++y) |
| 719 | { |
| 720 | if (endls & 0b0100) |
| 721 | std::cout << " [" << std::endl; |
| 722 | else |
| 723 | std::cout << " [" << std::flush; |
| 724 | for (BT z = 0; z < (nvcv::cuda::NumElements<ST> >= 3 ? nvcv::cuda::GetElement(shape, 2) : 1); ++z) |
| 725 | { |
| 726 | std::cout << " " << std::flush; |
| 727 | for (BT w = 0; w < (nvcv::cuda::NumElements<ST> >= 4 ? nvcv::cuda::GetElement(shape, 3) : 1); ++w) |
| 728 | { |
| 729 | ST coord = nvcv::cuda::DropCast<nvcv::cuda::NumElements<ST>>(BT4{x, y, z, w}); |
| 730 | |
| 731 | std::cout << " " << static_cast<CVT>(ValueAt<VT>(vec, strides, coord)) << std::flush; |
| 732 | } |
| 733 | if (endls & 0b0010) |
| 734 | std::cout << std::endl; |
| 735 | else |
| 736 | std::cout << std::flush; |
| 737 | } |
| 738 | if (endls & 0b0001) |
| 739 | std::cout << " ]" << std::endl; |
| 740 | else |
| 741 | std::cout << " ]" << std::flush; |
| 742 | } |
| 743 | std::cout << "}" << std::endl; |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | // Write images in *HW tensor buffer vec to PGM files. |
| 748 | // The file name provided should have two (one) "%ld" format substr to place the first two (one) indices. |